Image rendering method, device, electronic device and storage medium
By determining the refraction, reflection, and texture colors of virtual objects in image rendering, and selecting rendering colors based on normal relationships, the problem of large amounts of calculations in virtual object rendering is solved, and efficient rendering and effect improvement are achieved.
Patent Information
- Application Number
- CN202011069636.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-30
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2040-09-30
AI Technical Summary
The existing technology requires a large amount of calculations when rendering virtual objects with transparency, especially the iterative calculations caused by the complexity of ray tracing, which increases the burden of rendering.
By determining the refraction color, reflection color and texture color of the target pixel in the three-dimensional model, and selecting the rendering color based on the relationship between these colors and normals, the calculation amount of ray tracing is reduced, and weighted calculation and correction technology are used to improve the rendering effect. .
It effectively reduces the amount of calculation in the rendering process, while improving the image display effect of virtual objects, avoiding the problem of inconspicuous inherent colors caused by transparency parameters, and saving memory and time costs in making textures.
Smart Images

Figure CN112200902B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of graphics processing, and in particular to an image rendering method, device, electronic device and storage medium. Background Art
[0002] With the development of digital graphics technology, the number of virtual objects that can be displayed on the screens of various electronic devices has increased and become increasingly complex.
[0003] Some virtual objects have a certain degree of transparency, such as virtual crystals. In the relevant technical solution, real-time ray tracing is performed using real physical theories, and the color of each pixel on the surface of the model is obtained strictly according to the reflection, refraction and absorption effects of the light emitted from the eye after entering the model.
[0004] The optical properties of this virtual object with a certain degree of transparency are relatively complex. For example, ray tracing is repeated iterations, and the outgoing light after the incident light is refracted becomes the incident light of the next link. Therefore, it requires multiple iterative calculations, which is computationally intensive.
[0005] It can be seen that it is particularly important to reduce the amount of calculation required by electronic devices to render such virtual objects while reflecting their optical properties. Summary of the invention
[0006] The present disclosure provides an image rendering method, device, electronic device and storage medium to at least solve the problem of large amount of calculation in related technologies. The technical solution of the present disclosure is as follows:
[0007] According to a first aspect of an embodiment of the present disclosure, there is provided an image rendering method, comprising:
[0008] Determine the refraction color, reflection color and mapping color of a target pixel point in a three-dimensional model of an object to be rendered, wherein the target pixel point represents a pixel point in the three-dimensional model to be displayed on a screen;
[0009] Selecting at least one of the refraction color and the reflection color according to a spatial relationship between a normal line of the target pixel point on the three-dimensional model and a preset coordinate axis in a world space, and determining a rendering color of the target pixel point according to the selected color and the map color;
[0010] The target pixel is rendered according to the rendering color.
[0011] In a possible implementation manner of the first aspect, the process of determining the refraction color includes:
[0012] Determine a first intersection point between a light ray starting from a preset observation point and a background picture after passing through the target pixel point and the three-dimensional model, wherein the light ray enters the three-dimensional model through the target pixel point, is refracted, and exits the three-dimensional model, and the background picture is a preset picture or a currently captured picture;
[0013] The refraction color of the target pixel is determined according to the color of the first intersection point on the background image.
[0014] In a possible implementation manner of the first aspect, determining a first intersection point between a light ray starting from a preset observation point and the background image after passing through the target pixel point and the three-dimensional model includes:
[0015] Determine the refraction direction of the light after it passes through the target pixel point and enters the three-dimensional model and is refracted according to the direction of the line connecting the preset observation point to the target pixel point, the normal direction of the target pixel point on the three-dimensional model, and the refractive index of the three-dimensional model;
[0016] Determining the direction in which the light exits the three-dimensional model according to the refraction direction, the normal direction of the intersection of the light with the surface of the three-dimensional model when the light exits the three-dimensional model, and the refractive index of the three-dimensional model;
[0017] According to the emission direction, a first intersection point between the light ray and the background image after the light ray passes through the target pixel point and the three-dimensional model is determined.
[0018] In a possible implementation manner of the first aspect, the process of determining the reflection color includes:
[0019] Determine a second intersection point between the light rays starting from the preset observation point and the background image after being reflected by the target pixel point, wherein the background image is a preset image or a current captured image;
[0020] The reflection color of the target pixel is determined according to the color of the second intersection point on the background image.
[0021] In a possible implementation manner of the first aspect, the process of determining the color of the map includes:
[0022] Get a multi-frame texture sequence;
[0023] Determine the mapping point corresponding to the target pixel point;
[0024] The texture color of the target pixel is determined according to the color of the texture point in the texture sequence.
[0025] In a possible implementation manner of the first aspect, selecting at least one from the refraction color and the reflection color according to a spatial relationship between a normal line of the target pixel point on the three-dimensional model and a preset coordinate axis in a world space, and determining a rendering color of the target pixel point according to the selected color and the map color, includes:
[0026] Determine the angle between the normal line of the target pixel point on the three-dimensional model and the preset coordinate axis of the world space;
[0027] According to the relationship between the absolute value of the angle and the threshold, one is selected from the refraction color and the reflection color, and the rendering color of the target pixel is determined according to the selected color and the map color.
[0028] In a possible implementation manner of the first aspect, selecting one of the refraction color and the reflection color according to a magnitude relationship between the absolute value of the angle and a threshold value includes:
[0029] When the absolute value of the angle is less than the threshold, selecting the refraction color;
[0030] When the absolute value of the angle is not less than the threshold, the reflection color is selected.
[0031] In a possible implementation manner of the first aspect, selecting at least one from the refraction color and the reflection color according to a spatial relationship between a normal line of the target pixel point on the three-dimensional model and a preset coordinate axis in a world space, and determining a rendering color of the target pixel point according to the selected color and the map color, includes:
[0032] Determine the angle between the normal line of the target pixel point on the three-dimensional model and the preset coordinate axis of the world space;
[0033] The refraction weight and the reflection weight are determined according to the angle, and the refraction color, the reflection color and the map color are weightedly calculated using the refraction weight, the reflection weight and the preset map weight to determine the rendering color of the target pixel.
[0034] In a possible implementation manner of the first aspect, the method further includes:
[0035] Correcting the reflected color of the target pixel and / or the refracted color of the target pixel,
[0036] The correction coefficient used when correcting the reflected color of the target pixel is a first coefficient, and the correction coefficient used when correcting the refracted color of the target pixel is a second coefficient, and the first coefficient is different from the second coefficient.
[0037] According to a second aspect of an embodiment of the present disclosure, there is provided an image rendering device, including:
[0038] A first color determination unit is configured to determine the refraction color, reflection color and mapping color of a target pixel point in a three-dimensional model of an object to be rendered, wherein the target pixel point represents a pixel point in the three-dimensional model to be displayed on a screen;
[0039] A second color determination unit is configured to select at least one of the refraction color and the reflection color according to a spatial relationship between a normal line of the target pixel point on the three-dimensional model and a preset coordinate axis in a world space, and determine a rendering color of the target pixel point according to the selected color and the map color;
[0040] The rendering unit is configured to render the target pixel point according to the rendering color.
[0041] In a possible implementation manner of the second aspect, the process in which the first color determination unit determines the refraction color is configured to execute:
[0042] Determine a first intersection point between a light ray starting from a preset observation point and a background image after passing through the target pixel point and the three-dimensional model, wherein the light ray enters the three-dimensional model through the target pixel point, is refracted and exits the three-dimensional model, and the background image is a preset image or a currently captured image; determine the refracted color of the target pixel point based on the color of the first intersection point on the background image.
[0043] In a possible implementation manner of the second aspect, the process in which the first color determination unit determines a first intersection point between a light ray starting from a preset observation point and the background image after passing through the target pixel point and the three-dimensional model is configured to execute:
[0044] According to the direction of the line from the preset observation point to the target pixel point, the normal direction of the target pixel point on the three-dimensional model, and the refractive index of the three-dimensional model, the refraction direction of the light after it enters the three-dimensional model through the target pixel point and is refracted is determined; according to the refraction direction, the normal direction of the intersection of the light with the surface of the three-dimensional model when the light exits the three-dimensional model, and the refractive index of the three-dimensional model, the emission direction of the light exiting the three-dimensional model is determined; according to the emission direction, the first intersection point of the light with the background image after the light passes through the three-dimensional model through the target pixel point is determined.
[0045] In a possible implementation manner of the second aspect, the process in which the first color determination unit determines the reflection color is configured to execute:
[0046] Determine a second intersection point between the light starting from a preset observation point and the background image after being reflected by the target pixel point, where the background image is a preset image or a current shooting image; determine the reflection color of the target pixel point based on the color of the second intersection point on the background image.
[0047] In a possible implementation manner of the second aspect, the process in which the first color determination unit determines the color of the map is configured to execute:
[0048] Obtain a multi-frame texture sequence; determine the texture point corresponding to the target pixel point; and determine the texture color of the target pixel point according to the color of the texture point in the texture sequence.
[0049] In a possible implementation manner of the second aspect, the second color determination unit is specifically configured to execute:
[0050] Determine the angle between the normal of the target pixel point on the three-dimensional model and the preset coordinate axis of the world space; select one from the refraction color and the reflection color according to the relationship between the absolute value of the angle and the threshold, and determine the rendering color of the target pixel point according to the selected color and the map color.
[0051] In a possible implementation manner of the second aspect, the second color determination unit selects one of the refraction color and the reflection color according to a magnitude relationship between the absolute value of the angle and a threshold, and is specifically configured to execute:
[0052] When the absolute value of the angle is less than the threshold, the refraction color is selected; when the absolute value of the angle is not less than the threshold, the reflection color is selected.
[0053] In a possible implementation manner of the second aspect, the second color determination unit is specifically configured to execute:
[0054] Determine the angle between the normal of the target pixel point on the three-dimensional model and the preset coordinate axis of the world space; determine the refraction weight and the reflection weight according to the angle, and use the refraction weight, the reflection weight and the preset mapping weight to perform weighted calculation on the refraction color, the reflection color and the mapping color to determine the rendering color of the target pixel point.
[0055] In a possible implementation manner of the second aspect, the method further includes:
[0056] a correction unit, configured to correct the reflected color of the target pixel and / or the refracted color of the target pixel,
[0057] The correction coefficient used when correcting the reflected color of the target pixel is a first coefficient, and the correction coefficient used when correcting the refracted color of the target pixel is a second coefficient, and the first coefficient is different from the second coefficient.
[0058] According to a third aspect of an embodiment of the present disclosure, there is provided an electronic device, including:
[0059] processor;
[0060] a memory for storing instructions executable by the processor;
[0061] The processor is configured to execute the instructions to implement any image rendering method provided in the first aspect.
[0062] According to a fourth aspect of an embodiment of the present disclosure, a storage medium is provided. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute any one of the image rendering methods provided in the first aspect.
[0063] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, which, when executed on an electronic device, is suitable for executing a program that initializes the steps of the image rendering method provided by the first aspect.
[0064] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects:
[0065] The present disclosure can make the object to be rendered have the optical properties of reflection and / or refraction through the determination process of the reflection color and the refraction color. At the same time, the present disclosure does not consider the light absorption effect of the object to be rendered, thereby effectively reducing the amount of calculation in the rendering process. Moreover, the present disclosure adds a map color to the object to be rendered on the premise of the reflection color and the refraction color, and the image display effect of the object can be effectively improved through the map color.
[0066] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0067] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.
[0068] Figure 1 is a flowchart of an image rendering method according to an exemplary embodiment;
[0069] Figure 2is a schematic diagram showing reflection and refraction phenomena of a three-dimensional model according to an exemplary embodiment;
[0070] Figure 3 is a schematic diagram of a mapping sequence according to an exemplary embodiment;
[0071] Figure 4 is a block diagram of an image rendering device according to an exemplary embodiment;
[0072] Figure 5 It is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0073] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.
[0074] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0075] Optionally, the image rendering method provided by the present disclosure can be applied to various electronic devices, such as computers, tablet computers, mobile phones, projection devices, smart wearable devices, etc. For convenience, in the subsequent embodiments, the present disclosure will use a mobile phone as an example for explanation.
[0076] Figure 1 is a flowchart of an image rendering method according to an exemplary embodiment. Figure 1 As shown, the method may include the following steps.
[0077] In step S11, the refraction color, reflection color and mapping color of a target pixel point in the three-dimensional model of the object to be rendered are determined, and the target pixel point represents a pixel point in the three-dimensional model to be displayed on the screen.
[0078] Optionally, the object to be rendered in the present disclosure may be an object with transparency, which may be a virtual object or a physical object. Optionally, the object to be rendered in the present disclosure may be a three-dimensional object with multiple surfaces. Optionally, at least one of the multiple surfaces has a reflective effect. For example: a virtual animal made of crystal material or a virtual item made of crystal material, etc. It is understandable that crystal has multiple smooth surfaces that can reflect light; at the same time, crystal has a certain degree of transparency, and light can pass through the crystal through refraction. It is understandable that the object to be rendered in the present disclosure, such as crystal, may have reflection and refraction phenomena. Optionally, the object to be rendered in the present disclosure may be an object with transparency composed of multiple edges and planes. For example: a regular cube is composed of six planes and twelve edges. Of course, the object to be rendered in the present disclosure may be an asymmetric structure, for example: an irregular three-dimensional model. In the field of image rendering, because an object composed of multiple edges and planes can be understood as a three-dimensional object with sharp edges obtained by hard cutting, those skilled in the art often refer to such three-dimensional objects as hard-edge polygons. In the field of image rendering, each plane in a hard-edge polygon is generally a triangle.
[0079] The object to be rendered in the present disclosure may be a magic expression, which is a virtual decoration added to the picture by computer graphics when the camera is used to shoot the picture. For example, when a user uses a camera to take a selfie, the picture displayed on the screen includes a "crystal crown" displayed on the user's head in addition to the picture shot by the camera. The "crystal crown" is the magic expression.
[0080] At the same time, in order to improve the display effect of the object to be rendered in the present disclosure, such as crystal, the present disclosure can also set a map for the three-dimensional model of the object to be rendered. Optionally, the map can be a map that can increase the brightness of at least one pixel in the object to be rendered in the present disclosure. For convenience, the present disclosure refers to this map as a highlight map. The highlight map can effectively restore and simulate the highlight phenomenon caused by the concentration of light in a partial area of the object to be rendered in the present disclosure, such as crystal.
[0081] Optionally, the process of determining the refraction color in step S11 may include:
[0082] Determine the first intersection point between the light from the preset observation point and the background image after passing through the target pixel point through the 3D model. The light enters the 3D model through the target pixel point, is refracted, and exits the 3D model. The background image is a preset image or a currently captured image.
[0083] The refraction color of the target pixel is determined according to the color of the first intersection point on the background image.
[0084] It is understandable that since different areas can be seen when observing the 3D model from different positions, each pixel point to be displayed on the screen in the 3D model of the object to be rendered, i.e., each target pixel point, can be determined by presetting the observation point. The preset observation point can be the lens position of the virtual camera.
[0085] like Figure 2 As shown in FIG. 1 , assuming that the three-dimensional model is a crystal model, the position of the human eye is the preset observation point, and the first pixel point is the target pixel point, then due to the refraction phenomenon, the color of the first pixel point observed by the human is affected by Figure 2 The effect of the first intersection is shown. Figure 2 The arrow of the refracted light shows that the light emitted from the human eye is refracted through the first pixel point and enters Figure 2 The crystal model shown intersects with the background image at the first intersection after being refracted again at the third intersection of the crystal model. The second normal line is the normal line of the third intersection of the surface of the crystal model. Accordingly, for other target pixel points observed by the human eye, the positions of the corresponding intersection points related to refraction can be determined.
[0086] Among them, the background image can be the picture currently captured by the camera of the electronic device. For example, when a user takes a picture or video through a mobile phone, the present disclosure can display the virtual crystal on the screen of the electronic device. At this time, at least part of the image captured by the user will be reflected on the virtual crystal through reflection and / or refraction. It can be seen that the background image is the picture currently captured by the camera of the electronic device, which can make the object to be rendered rendered by the present disclosure better integrate with the surrounding environment and enhance the immersion brought by the object to be rendered to the viewer.
[0087] The present disclosure can set a corresponding spatial position for each pixel of the background image. For example: the distance between each pixel of the background image and the preset observation point is the first preset distance. Another example: the line connecting the center point of the background image and the preset observation point is perpendicular to the background image and the distance between the line is the second preset distance. Among them, the second preset distance and the first preset distance can be the same or different. Of course, the present disclosure can also actually measure or predict the distance between each pixel of the background image and the preset observation point (that is, the position of the lens of the electronic device). For example: the distance between each pixel in the background image and the preset observation point is collected by a depth camera, or the depth of each pixel in the background image is predicted by depth analysis technology.
[0088] In other embodiments, the process of determining the first intersection point between the light ray starting from the preset observation point and the background image after passing through the target pixel point and the three-dimensional model provided by the present disclosure may specifically include:
[0089] According to the direction of the line from the preset observation point to the target pixel point, the normal direction of the target pixel point on the three-dimensional model, and the refractive index of the three-dimensional model, the refraction direction of the light after it passes through the target pixel point and enters the three-dimensional model is determined;
[0090] Determine the direction in which the light exits the three-dimensional model according to the refraction direction, the normal direction of the intersection of the light with the surface of the three-dimensional model when the light exits the three-dimensional model, and the refractive index of the three-dimensional model;
[0091] According to the emission direction, the first intersection point between the light ray and the background image after the light ray passes through the target pixel point and the three-dimensional model is determined.
[0092] The following are three specific methods for determining the first intersection point (i.e., method 1, method 2, and method 3 below):
[0093] Method 1, comprising: steps 1.1 to 1.3.
[0094] Step 1.1. Take the direction of the line from the preset observation point to the target pixel point as the incident direction. According to the law of refraction, the refraction direction of the light after it passes through the target pixel point and enters the three-dimensional model is determined based on the incident direction, the normal direction of the target pixel point on the three-dimensional model, and the refractive index of the three-dimensional model.
[0095] Among them, in the law of refraction, the incident angle θ0, the refraction angle θ1, the refractive index n0 of the medium 0 through which the incident light passes, and the refractive index n1 of the medium 1 through which the refracted light passes have the following relationship:
[0096] n0×sinθ0=n1×sinθ1
[0097] Among them, the incident angle is the angle between the incident light and the normal line, and the refraction angle is the angle between the refracted light and the refracted light.
[0098] The direction of the line connecting the preset observation point to the target pixel in the embodiment of the present disclosure is the incident direction of the incident light, and the normal direction of the target pixel on the three-dimensional model is the normal line. The incident angle θ0 can be obtained according to the incident direction and the normal line. Since the medium through which the incident light passes is air, its refractive index n0 can be known in the present disclosure. The refractive index of the three-dimensional model is the refractive index n1 of the medium 1 through which the refracted light passes. The refraction angle θ1 can be obtained by the above equation, and then the refraction direction of the light after it passes through the target pixel and enters the three-dimensional model and is refracted can be determined according to the normal light.
[0099] Optionally, the present disclosure can determine the refraction direction of light after it enters the interior of the three-dimensional model through the target pixel point and is refracted through function 1: ray0 = normalize(refract(-V, N1, n0 / n1)), wherein ray0 represents the refraction direction of light from medium 0 through the target pixel point on the surface of the three-dimensional model into medium 1, V represents the direction from the target pixel point on the surface of the three-dimensional model to a preset observation point (such as the position of the virtual camera), -V is the incident direction of the light, N1 represents the normal direction of the target pixel point on the surface of the three-dimensional model, and n0 / n1 represents the ratio of the refractive index of medium 0 to the refractive index of medium 1. Among them, medium 0 represents air, and medium 1 represents the material of the three-dimensional model. refract(-V, N1, n0 / n1) represents the refraction direction calculated according to the law of refraction, and normalize represents normalization processing.
[0100] Step 1.2, determine the point where the light travels from the target pixel point along the refraction direction and intersects with the surface of the three-dimensional model as the third intersection point; determine the normal direction of the third intersection point as the normal direction of the intersection of the light ray with the surface of the three-dimensional model when it exits the three-dimensional model, and according to the law of refraction, based on the refraction direction determined in step 1.1, the normal direction of the intersection of the light ray with the surface of the three-dimensional model when it exits the three-dimensional model, and the refractive index of the three-dimensional model, determine the exit direction of the light ray exiting the three-dimensional model.
[0101] It is understandable that refraction may still occur when the light is emitted from the three-dimensional model (when the refracted light is emitted vertically from the surface of the three-dimensional model, there is no refraction), so the emission direction of the light emitting from the three-dimensional model can still be determined by the above equation. Since the normal directions of different points on the surface of the three-dimensional model may be different, when determining the emission direction of the light emitting from the three-dimensional model, it is necessary to determine the intersection point of the light emitting from the three-dimensional model with the surface of the three-dimensional model when emitting the three-dimensional model, and then determine the emission direction of the light emitting from the three-dimensional model according to the normal direction of the intersection point.
[0102] The first method disclosed in the present invention can determine the intersection point of the light ray with the surface of the three-dimensional model when it exits the three-dimensional model according to strict optical principles. For example: to obtain the three-dimensional size parameters of the three-dimensional model, the light ray starts from the target pixel point and travels along the determined refraction direction, and it will inevitably intersect with a point on the surface of the three-dimensional model. This point is the intersection point of the light ray with the surface of the three-dimensional model when it exits the three-dimensional model according to the optical principle. It can be understood that determining the intersection point according to strict optical principles can make the optical effect of the three-dimensional model more realistic, but the amount of calculation is large.
[0103] The present disclosure can determine the emission direction of the light ray from the three-dimensional model through the target pixel point through function 2: ray1 = normalize (refract (ray0, N2, n1 / n2)). Wherein, ray1 represents the emission direction of the light ray when it is emitted from medium 1 to medium 2, N2 represents the normal direction of the third intersection of the light ray with the surface of the three-dimensional model when it is emitted, and n1 / n2 represents the ratio of the refractive index of medium 1 to the refractive index of medium 2. Wherein, medium 1 represents the material of the three-dimensional model. Medium 2 can be the same as medium 0, that is, both are air. Therefore, n2 can be equal to n0.
[0104] Step 1.3: According to the position and emission direction of the third intersection point, determine the first intersection point of the light ray with the background image after passing through the target pixel point and the three-dimensional model.
[0105] After the position of the third intersection point is determined, the intersection point of the light ray starting from the third intersection point and traveling along the emission direction with the background image is the first intersection point.
[0106] The first method disclosed in the present invention can determine the first intersection point according to strict optical principles, so that the refraction effect can be more realistic, but the amount of calculation is relatively large.
[0107] Let's take crystal as an example: Figure 2 As shown, according to the direction of the line from the first pixel point to the preset observation point, Figure 2 The first normal direction and the refractive index of the crystal shown can be used to determine the refraction direction of the light after it enters the three-dimensional model through the first pixel point and is refracted through optical principles. After the light travels along the refraction direction inside the crystal, it will encounter the surface of the crystal again, and then be emitted from the crystal again through the refraction phenomenon. At this time, the present disclosure can determine the emission direction of the light from the three-dimensional model based on the refraction direction, the normal direction of the intersection of the light with the surface of the three-dimensional model when the light emits the three-dimensional model, and the refractive index of the crystal. Furthermore, the present disclosure can determine the first intersection of the light with the background image after the light emits the crystal through the emission direction and the third intersection.
[0108] It is understandable that after placing the three-dimensional model into the three-dimensional coordinate system, the present disclosure can obtain the coordinates of each point on the three-dimensional model and the size of the three-dimensional model. On this basis, the present disclosure can determine the coordinates of the intersection of the light ray passing through the first pixel point and the surface of the three-dimensional model after traveling along the refraction direction inside the three-dimensional model through the coordinates of the first pixel point and the refraction direction. The coordinates are the intersection of the light ray with the surface of the three-dimensional model when it exits the three-dimensional model.
[0109] Method 2, comprising: step 2.1 to step 2.3.
[0110] Step 2.1. Take the direction of the line from the preset observation point to the target pixel point as the incident direction. According to the law of refraction, based on the incident direction, the normal direction of the target pixel point on the three-dimensional model, and the refractive index of the three-dimensional model, determine the refraction direction of the light after it passes through the target pixel point and enters the three-dimensional model.
[0111] Step 2.1 is the same as step 1.1 in method 1 and will not be repeated here.
[0112] Step 2.2, determine the opposite direction of the normal direction of the target pixel point on the three-dimensional model as: the normal direction of the intersection of the light ray with the surface of the three-dimensional model when it exits the three-dimensional model. According to the law of refraction, the direction in which the light ray exits the three-dimensional model is determined based on the refraction direction determined in step 1.1, the opposite direction of the normal direction of the intersection of the light ray with the surface of the three-dimensional model when it exits the three-dimensional model, and the refractive index of the three-dimensional model.
[0113] The present disclosure can determine the emission direction of the light ray from the three-dimensional model through the target pixel point through function 3: ray1 = normalize(refract(ray0, -N1, n1 / n2)). Among them, ray1 represents the emission direction of the light ray when it is emitted from medium 1 to medium 2, -N1 represents the normal direction of the third intersection of the light ray with the surface of the three-dimensional model when it is emitted (-N1 is the opposite direction of N1), and n1 / n2 represents the ratio of the refractive index of medium 1 to the refractive index of medium 2. Among them, medium 1 represents the material of the three-dimensional model. Medium 2 can be the same as medium 0, that is, both are air. Therefore, n2 can be equal to n0.
[0114] In step 2.2, there is no need to determine the actual position of the third intersection point according to the size parameters of the three-dimensional model, thus effectively reducing the amount of calculation.
[0115] Step 2.3, after the light starts from the target pixel point and travels a first preset distance along the refraction direction determined in step 2.1, and then travels along the emission direction determined in step 2.2, the intersection point with the background image is determined as the first intersection point of the light ray with the background image after passing through the three-dimensional model through the target pixel point.
[0116] Step 2.3 can further simulate the thickness of the three-dimensional model in the refraction direction through the first preset distance, effectively reducing the amount of calculation.
[0117] Further, in other embodiments, step 2.3 may include: determining the point reached by the light after it starts from the target pixel point and travels a first preset distance along the refraction direction determined in step 2.1, and then travels a second preset distance along the emission direction determined in step 2.2, as the first intersection point of the light with the background image after the light passes through the target pixel point and the three-dimensional model.
[0118] The present disclosure can calculate the coordinates of the first intersection point between the light ray passing through the target pixel point and the background image through the three-dimensional model through function 4: intersection = position + ray0 * step_length1 + ray1 * step_length2, where intersection represents the coordinates of the first intersection point in the world coordinate system, and position represents the target pixel point (such as Figure 2 ray0*step_length1 represents the coordinates of the first pixel point shown in the figure, step_length1 represents the first preset distance, and step_length2 represents the second preset distance. ray0*step_length1 represents the distance along ray0 for step_length1, and ray1*step_length2 represents the distance along ray1 for step_length2. position+ray0*step_length1+ray1*step_length2 represents the point reached by the light after the light starts from position and travels along ray0 for step_length1, and then travels along ray1 for step_length2.
[0119] This method of simulating the distance between the three-dimensional model and the background image by using the second preset distance further effectively reduces the amount of calculation.
[0120] Optionally, the first preset distance and the second preset distance may be equal or unequal.
[0121] Method three, comprising: step 3.1 to step 3.3.
[0122] Step 3.1. Take the direction of the line from the preset observation point to the target pixel point as the incident direction. According to the law of refraction, based on the incident direction, the normal direction of the target pixel point on the three-dimensional model, and the refractive index of the three-dimensional model, determine the refraction direction of the light after it passes through the target pixel point and enters the three-dimensional model.
[0123] Step 3.1 is the same as step 1.1 in method 1 and will not be repeated here.
[0124] Step 3.2: Determine the opposite direction of the normal direction of the target pixel point on the three-dimensional model as: the normal direction of the intersection of the light ray with the surface of the three-dimensional model when it exits the three-dimensional model. According to the law of refraction, the direction in which the light ray exits the three-dimensional model is determined based on the refraction direction determined in step 1.1, the opposite direction of the normal direction of the intersection of the light ray with the surface of the three-dimensional model when it exits the three-dimensional model, and the refractive index of the three-dimensional model.
[0125] Step 3.2 is the same as step 2.2 in method 2 and will not be repeated here.
[0126] Step 3.3, after the light starts from the target pixel point and travels a first preset distance along the normal direction of the target pixel point on the three-dimensional model, and then travels a second preset distance along the emission direction determined in step 3.2, the point reached is determined as the first intersection point of the light ray with the background image after passing through the three-dimensional model through the target pixel point.
[0127] Step 3.3 can further replace the refraction direction with the normal direction, effectively reducing the amount of calculation.
[0128] The present disclosure can calculate the coordinates of the first intersection point between the ray passing through the target pixel point and the background image through the three-dimensional model through function 5: intersection = position + N1 * step_length1 + ray1 * step_length2, where intersection represents the coordinates of the first intersection point in the world coordinate system, and position represents the target pixel point (such as Figure 2 The coordinates of the first pixel point shown in the figure, step_length1 represents the first preset distance, step_length2 represents the second preset distance, and N1 represents the normal direction of the target pixel point on the surface of the three-dimensional model.
[0129] Optionally, the first preset distance and the second preset distance may be equal or unequal.
[0130] Among them, the refractive index of the three-dimensional model can be a preset refractive index, for example: the refractive index of a real crystal is in the range of 1.544 to 1.553, then the present disclosure can set the refractive index of the three-dimensional model of the crystal to 1.55. When the external environment of the three-dimensional model is an air medium, the present disclosure can be processed only according to the refractive index of the three-dimensional model. When the external environment of the three-dimensional model is other media (such as water), the present disclosure can be processed according to the refractive index of the three-dimensional model and the refractive index of the external environment. It can be understood that the external environment of the three-dimensional model can contain multiple media, for example: the medium of the external environment in a certain direction of the three-dimensional model is water, and the medium of the external environment in another direction of the three-dimensional model is ice.
[0131] Optionally, the present disclosure may first obtain the coordinates of the first intersection point in the world coordinate system, and then convert them into coordinates in the screen space coordinate system, thereby determining the color of the first intersection point.
[0132] Optionally, each parameter in the above functions 1 to 5 is a parameter in the world coordinate system.
[0133] Optionally, the present disclosure may convert the coordinates of the first intersection point in the world coordinate system into coordinates in the screen space coordinate system according to function 6: screen_pos=MpMv*intersection, wherein screen_pos represents the coordinates of the first intersection point in the screen space coordinate system, Mp represents the projection matrix, and Mv represents the camera matrix.
[0134] Optionally, the present disclosure may determine the coordinates of the first intersection in the texture space according to function 7: uv=screen_pos.xy / screen_pos.w*0.5+0.5. Wherein, uv represents the coordinates of the first intersection in the texture space. screen_pos.xy represents the X-axis coordinate and the Y-axis coordinate of the first intersection in the screen space coordinate system, and screen_pos.w represents the coordinate of the first intersection in the last dimension of the 4x4 matrix of the homogeneous coordinate system. Optionally, the value range of uv may be 0 to 1. Optionally, the value range of screen_pos.xy may be -1 to 1. The present disclosure may transform the coordinates in the range of -1 to 1 to the coordinates in the range of 0 to 1 through function 7.
[0135] In an alternative embodiment, Figure 1 The method may further include:
[0136] The reflected color of the target pixel and / or the refracted color of the target pixel is corrected, wherein the correction coefficient used when correcting the reflected color of the target pixel is a first coefficient, and the correction coefficient used when correcting the refracted color of the target pixel is a second coefficient, and the first coefficient is different from the second coefficient.
[0137] Optionally, the first coefficient may be greater than the second coefficient. For example, the first coefficient is greater than a preset correction coefficient, and the second coefficient is less than the preset correction coefficient.
[0138] When the 3D model is a crystal, a smaller second coefficient can reduce the color contrast and light transmittance of the crystal, creating a hazy feeling. For example, the second coefficient can use a value less than 2.2.
[0139] When the three-dimensional model is a crystal, a larger first coefficient can improve the color contrast and reflection intensity of the crystal, creating a feeling of strong reflection. For example, the first coefficient can use a value not less than 2.2.
[0140] By correcting the reflected color and / or the refracted color, the refraction effect and / or the reflection effect can be effectively improved. At the same time, since the correction coefficient of the reflected color is different from the correction coefficient of the refracted color, the optical characteristics of the material of the three-dimensional model can be better expressed. For example, when the material of the three-dimensional model is crystal, the crystal's sharp edges and corners, hazy internal volume and strong external reflection can be better reflected.
[0141] Optionally, the first coefficient and the second coefficient may be correction coefficients of gamma correction. Optionally, the first coefficient is not less than 2.2. Optionally, the second coefficient is less than 2.2.
[0142] In an alternative embodiment, Figure 1 The method may further include:
[0143] Correct the reflected color of the target pixel and / or the refracted color of the target pixel.
[0144] Optionally, the correction coefficients used when correcting the refraction colors of different target pixels are the same or different.
[0145] Optionally, the correction coefficients used when correcting the reflected colors of different target pixels are the same or different.
[0146] By using different correction coefficients for different target pixels, different positions of the three-dimensional model can have different optical characteristics, which can well reflect the optical phenomena at different positions of the three-dimensional model.
[0147] When the correction coefficients of the refraction color and the reflection color in the present disclosure are different, and different correction coefficients are used for different target pixels, the present disclosure can better express the sharp edges and corners, hazy inner volume and strong external reflection of the object to be rendered (such as crystal).
[0148] Optionally, the present disclosure can determine the refraction color of the target pixel point on the three-dimensional model according to function 8: refraction_color = pow(texture2d(photo_tex, uv), power_refr), wherein refraction_color represents the refraction color of the target pixel point on the three-dimensional model, photo_tex represents the texture of the background image, texture2d(photo_tex, uv) represents the color of the point with texture coordinate uv on photo_tex, power_refr is the second coefficient of gamma correction, and pow(texture2d(photo_tex, uv), power_refr) represents obtaining the color of the point with texture coordinate uv on the background image and performing gamma correction on it through power_refr. For crystal, in order to reduce the light transmittance of crystal and create a hazy feeling. The second coefficient can use a value less than 2.2 to reduce the color contrast and improve the crystal display effect.
[0149] Optionally, the process of determining the reflection color in step S11 may include:
[0150] Determine the second intersection point between the light rays starting from the preset observation point and the background image after being reflected by the target pixel point;
[0151] The reflection color of the target pixel is determined according to the color of the second intersection point on the background image.
[0152] The process of determining the second intersection point between the light rays starting from the preset observation point and the background image after being reflected by the target pixel point may specifically include:
[0153] Determine the reflection direction of the light from the preset observation point after being reflected by the target pixel point according to the direction of the line connecting the preset observation point to the target pixel point and the normal direction of the target pixel point on the three-dimensional model;
[0154] The second intersection point of the light ray with the background image after being reflected by the target pixel is determined according to the reflection direction.
[0155] like Figure 2 As shown, after the light rays starting from the preset observation point reach the first pixel point, the light rays are reflected as reflected light rays and intersect with the background image at the second intersection point.
[0156] Optionally, the present disclosure can determine the reflection direction of the light from the preset observation point after reaching the target pixel point through function 9: ray2 = normalize (reflect (-V, N1)). Wherein, ray2 represents the reflection direction of the light from the preset observation point after reaching the first pixel point, -V is the incident direction of the light, and N1 represents the normal direction of the target pixel point on the surface of the three-dimensional model.
[0157] Optionally, similar to refraction, after determining the reflection direction, the second intersection point of the reflected light and the background image can be determined, and then the X-axis coordinate and the Y-axis coordinate in the screen space coordinate system can be obtained through coordinate system transformation.
[0158] Optionally, the present disclosure can determine the coordinates of the second intersection of the reflected light and the background image in the texture space by function 10: uv2=ray2.xy*0.5+0.5. Wherein, uv2 represents the coordinates of the second intersection of the reflected light and the background image in the texture space. ray2.xy represents the X-axis coordinate and the Y-axis coordinate of the second intersection in the screen space coordinate system.
[0159] Optionally, the present disclosure can determine the reflection color of the target pixel on the three-dimensional model through function 11: reflection_color = pow(texture2d(photo_tex,uv2),power_refl). Wherein, reflection_color represents the reflection color of the target pixel on the three-dimensional model. pow(texture2d(photo_tex,uv2),power_refl) represents obtaining the color of the point with texture coordinate uv2 on photo_tex, and performing a gamma correction on the color. power_refl is the first coefficient of gamma correction. For the crystal effect, in order to increase the reflection intensity of the crystal and create a feeling of strong reflection, power_refl can use a value of not less than 2.2 to increase the color contrast.
[0160] Optionally, the present disclosure may determine the refraction colors corresponding to some or all of the pixels in the three-dimensional model of the object to be rendered to be displayed on the screen. Optionally, the present disclosure may determine the refraction colors corresponding to some or all of the pixels in the three-dimensional model of the object to be rendered.
[0161] Optionally, the present disclosure may determine the reflection colors corresponding to some or all pixels in the three-dimensional model of the object to be rendered to be displayed on the screen. Optionally, the present disclosure may determine the reflection colors corresponding to some or all pixels in the three-dimensional model of the object to be rendered.
[0162] Optionally, the process of determining the color of the map in step S110 may include:
[0163] Get a multi-frame texture sequence;
[0164] Determine the mapping point corresponding to the target pixel;
[0165] The texture color of the target pixel is determined according to the color of the texture point in the texture sequence.
[0166] The above multi-frame texture sequence can be arranged in a matrix manner, such as Figure 3 As shown, the texture sequence consists of 16 frames of textures. Figure 3 Each small square where the numbers 0 to 15 are located is a frame of texture. Of course, in practical applications, the texture can be determined by the position (row and column) of each frame of texture in the matrix. For example: a frame of texture in the second row and third column.
[0167] Optionally, the coordinates of the mapping point corresponding to the target pixel point may be the texture coordinates of the target pixel point after being transformed through sequence frame arrangement.
[0168] Among them, the texture used in the present disclosure may be a highlight texture that can improve the brightness of a part or all of a three-dimensional model. The present disclosure adds a highlight texture decorated with a texture sequence frame, which can make the object to be rendered (such as a crystal) more sparkling and more visually impactful. In addition, more diverse display effects can be achieved by adjusting the texture.
[0169] Optionally, the present disclosure can determine the texture coordinates of the target pixel points to be displayed on the screen in the three-dimensional model after the sequence frame arrangement conversion through function 12: uv3 = GetUVAnimTexCoord (uv, row, col, frame_count, speed), wherein uv3 represents the texture coordinates of the target pixel points to be displayed on the screen in the three-dimensional model after the sequence frame arrangement conversion. row represents the number of rows of the texture in the matrix, col represents the number of columns of the texture in the matrix, frame_count represents the number of frames of the texture sequence, and speed represents the playback speed of the texture sequence.
[0170] Optionally, the present disclosure can determine the texture color of the target pixel point in the 3D model to be displayed on the screen through function 13: deco_color=texture2d(deco_tex,uv3), wherein deco_color represents the texture color of the pixel point in the 3D model to be displayed on the screen, and deco_tex represents a multi-frame texture sequence.
[0171] Since it is a multi-frame texture sequence, when the texture colors of the pixels are sequentially controlled to control the display effect of the pixels according to the present disclosure, flickering points that change with time can be presented on the three-dimensional model.
[0172] In step S12, at least one of the refraction color and the reflection color is selected according to the spatial relationship between the normal of the target pixel point on the three-dimensional model and the preset coordinate axis of the world space, and the rendering color of the target pixel point is determined according to the selected color and the map color.
[0173] Step S12 may specifically include:
[0174] Determine the angle between the normal line of the target pixel point on the three-dimensional model and the preset coordinate axis of the world space;
[0175] The refraction weight and reflection weight are determined according to the angle. The refraction weight, reflection weight and preset map weight are used to perform weighted calculation on the refraction color, reflection color and map color to determine the rendering color of the target pixel.
[0176] The preset coordinate axis may be a Y axis, an X axis or a Z axis. Optionally, the preset coordinate axis may be a Y axis.
[0177] Optionally, the refraction weight and the reflection weight may have a preset corresponding relationship with the value of the above-mentioned angle, so that the refraction weight and the reflection weight may be determined according to the value of the angle. Of course, the present disclosure may also first compare the value with the threshold, and determine the refraction weight and the reflection weight according to the comparison result. For example: when the absolute value of the angle is less than the threshold, the refraction weight is determined to be m1, and the reflection weight is m2. When the absolute value of the angle is not less than the threshold, the refraction weight is determined to be m2, and the reflection weight is m1. Among them, the value range of m1 can be [0,1], and the value range of m2 can be [0,1]. Optionally, m1 is 1, and m2 is 0. Optionally, the sum of the reflection weight and the refraction weight is 1.
[0178] Optionally, the preset texture weight can be 1 or other values, and those skilled in the art can set and modify the preset texture weight as needed. The larger the preset texture weight, the higher the texture effect of the target pixel point, for example: when the texture is a highlight texture, the brightness of the target pixel point is higher.
[0179] Optionally, by setting a threshold, the present disclosure can divide the three-dimensional model into three parts: upper, middle and lower, wherein the absolute value of the angle between the normal of the middle pixel point on the three-dimensional model and the preset coordinate axis of the world space is less than the threshold, and the absolute value of the angle between the normal of the upper and lower pixel points on the three-dimensional model and the preset coordinate axis of the world space is not less than the threshold. In this way, when m1 is 1 and m2 is 0, the present disclosure can make the three-dimensional model reflect the reflection effect in the upper and lower parts, and the refraction effect in the middle part. This makes it unnecessary for the present disclosure to reflect reflection and refraction in all target pixel points, saving the amount of calculation. At the same time, the upper and lower parts reflect the reflection effect, and the middle part reflects the refraction effect, which also makes the three-dimensional model well retain its material optical properties with transparency. By comparing the above angles and thresholds, the present disclosure can make different areas in the object to be rendered have different display effects and obvious interfaces, and can make the object to be rendered have clear and definite boundaries, avoiding mixed and turbid transitions.
[0180] Of course, the present disclosure can also enable the three-dimensional model to achieve a stronger reflection effect and a weaker refraction effect in the upper and lower parts, and a stronger refraction effect and a weaker reflection effect in the middle part. The strength of the above-mentioned reflection effect and refraction effect is controlled by their corresponding weights. When the value range of the reflection weight and the refraction weight are both [0,1], the strength of the refraction effect and the reflection effect presented by the target pixel point can be controlled by the values of the reflection weight and the refraction weight.
[0181] Optionally, the present disclosure may determine the comparison result of the absolute value of the angle between the normal of the target pixel point on the three-dimensional model and the preset coordinate axis of the world space with the threshold through function 14: yon_factor = step(ref_factor, abs(dot(axis_y, N1))), wherein yon_factor represents the comparison result of the absolute value of the angle between the normal of the target pixel point on the three-dimensional model and the preset coordinate axis of the world space with the threshold. axis_y represents the preset coordinate axis of the world space, and N1 represents the normal of the target pixel point on the three-dimensional model. When the absolute value of the above angle is less than the threshold, yon_factor is 1, and when the absolute value of the above angle is not less than the threshold, yon_factor is 0. Of course, yon_factor can represent the ratio of the absolute value of the angle between the normal of the target pixel point on the three-dimensional model and the preset coordinate axis of the world space to the threshold.
[0182] The present disclosure can determine the refraction weight and the reflection weight according to the yon_factor. For example, when the yon_factor is 1, the refraction weight is determined to be 1 and the reflection weight is 0; when the yon_factor is 0, the refraction weight is determined to be 0 and the reflection weight is 1.
[0183] Of course, in other embodiments of the present disclosure, it is also possible not to use weights, but to select one from the refraction color and the reflection color. For example: step S12 may specifically include:
[0184] Determine the angle between the normal line of the target pixel point on the three-dimensional model and the preset coordinate axis of the world space;
[0185] According to the relationship between the absolute value of the angle and the threshold, one is selected from the refraction color and the reflection color, and the rendering color of the target pixel is determined according to the selected color and the map color.
[0186] It is easier to select a color scheme from the refraction color and reflection color without using the refraction weight and reflection weight, or performing weighted calculations.
[0187] Optionally, the above selecting one of the refraction color and the reflection color according to the relationship between the absolute value of the angle and the threshold may specifically include:
[0188] When the absolute value of the angle is less than the threshold, the refraction color is selected;
[0189] When the absolute value of the angle is not less than the threshold, the reflection color is selected.
[0190] Although weights are not used, the embodiments of the present disclosure can still enable the three-dimensional model to achieve a reflection effect in the upper and lower parts, and a refraction effect in the middle part. This means that the present disclosure does not need to reflect reflection and refraction at all target pixels, saving the amount of calculation. At the same time, the upper and lower parts reflect the reflection effect, and the middle part reflects the refraction effect, which also allows the three-dimensional model to well retain its material optical properties of transparency. Through the comparison of the above-mentioned angle and threshold, the present disclosure can enable different areas in the object to be rendered to have different display effects and a clear interface, and can enable the object to be rendered to have clear and definite boundaries, avoiding mixed and turbid transitions. Of course, the present disclosure can also enable the three-dimensional model to achieve a stronger reflection effect and a weaker refraction effect in the upper and lower parts, and a stronger refraction effect and a weaker reflection effect in the middle part.
[0191] Optionally, the present disclosure can determine the rendering color corresponding to the pixel point through function 15: final_color=mix(refraction_color, reflection_color, yon_factor)+deco_color, wherein final_color represents the rendering color corresponding to the pixel point, and mix(refraction_color, reflection_color, yon_factor)+deco_color represents using yon_factor to weightedly sum refraction_color and reflection_color, and then add it to deco_color.
[0192] Optional, Figure 1 Each step may be performed by a device for performing graphics processing in an electronic device, such as a graphics processing unit (GPU).
[0193] In step S13, the target pixel is rendered according to the rendering color.
[0194] It is understandable that there may be multiple target pixel points in the present disclosure. After the present disclosure renders each target pixel point, each target pixel point will be displayed on the screen and the color will be the rendering color determined by the present disclosure.
[0195] The present disclosure can make the object to be rendered have the optical characteristics of reflection and refraction through the determination process of reflection color and refraction color. At the same time, the present disclosure does not consider the light absorption effect of the object to be rendered, so the amount of calculation in the rendering process is effectively reduced. Moreover, the present disclosure adds a map color to the object to be rendered on the premise of reflection color and refraction color, and the image display effect of the object can be effectively improved by the map color. For the object to be rendered with transparency, if the transparency parameter is used to render it, the performance overhead of mixed calculation in the rendering process is large and the problem of unclear inherent color of the object to be rendered will appear. In this case, more hand-painted maps need to be used to enhance the material effect of the object to be rendered. The present disclosure reflects the transparent effect and optical characteristics of the object to be rendered through reflection and refraction. Compared with the use of transparency parameters, the performance overhead of mixed calculation in the rendering process is small. At the same time, the present disclosure avoids the problem of unclear inherent color of the object to be rendered caused by transparency parameters, and there is no need to use more hand-painted maps to enhance the material effect of the object to be rendered. It can be seen that the present disclosure saves memory overhead and time cost of making maps.
[0196] Figure 4 is a block diagram of an image rendering device according to an exemplary embodiment. Figure 4 The device includes: a first color determination unit 121, a second color determination unit 122 and a rendering unit 123.
[0197] The first color determination unit 121 is configured to determine the refraction color, reflection color and mapping color of a target pixel point in the three-dimensional model of the object to be rendered, where the target pixel point represents a pixel point in the three-dimensional model to be displayed on the screen;
[0198] The second color determination unit 122 is configured to select at least one of the refraction color and the reflection color according to the spatial relationship between the normal line of the target pixel point on the three-dimensional model and the preset coordinate axis of the world space, and determine the rendering color of the target pixel point according to the selected color and the map color;
[0199] The rendering unit 123 is configured to render the target pixel according to the rendering color.
[0200] Optionally, the process of determining the refraction color by the first color determining unit 121 is configured to execute:
[0201] Determine the first intersection point between the light starting from the preset observation point and the background image after passing through the target pixel point through the three-dimensional model. The light enters the three-dimensional model through the target pixel point, refracts and exits the three-dimensional model. The background image is a preset image or the current shooting image. Determine the refracted color of the target pixel point based on the color of the first intersection point on the background image.
[0202] Optionally, the process of determining the first intersection point between the light rays starting from the preset observation point and the background image after passing through the target pixel point and the three-dimensional model by the first color determination unit 121 is configured to perform:
[0203] According to the direction of the line from the preset observation point to the target pixel point, the normal direction of the target pixel point on the three-dimensional model and the refractive index of the three-dimensional model, the refraction direction of the light after it enters the three-dimensional model through the target pixel point and is refracted is determined; according to the refraction direction, the normal direction of the intersection of the light with the surface of the three-dimensional model when the light exits the three-dimensional model and the refractive index of the three-dimensional model, the emission direction of the light exiting the three-dimensional model is determined; according to the emission direction, the first intersection point of the light with the background image after passing through the three-dimensional model through the target pixel point is determined.
[0204] Optionally, the process of determining the reflection color by the first color determining unit 121 is configured to execute:
[0205] Determine the second intersection point of the light starting from the preset observation point and the background image after being reflected by the target pixel point, where the background image is a preset image or the current shooting image; determine the reflection color of the target pixel point based on the color of the second intersection point on the background image.
[0206] Optionally, the process of determining the color of the map by the first color determining unit 121 is configured to execute:
[0207] Obtain a multi-frame texture sequence; determine the texture point corresponding to the target pixel point; and determine the texture color of the target pixel point according to the color of the texture point in the texture sequence.
[0208] Optionally, the second color determination unit 122 is specifically configured to execute:
[0209] Determine the angle between the normal of the target pixel point on the three-dimensional model and the preset coordinate axis of the world space; select one from the refraction color and the reflection color according to the relationship between the absolute value of the angle and the threshold, and determine the rendering color of the target pixel point according to the selected color and the map color.
[0210] Optionally, the second color determination unit 122 selects one of the refraction color and the reflection color according to the relationship between the absolute value of the angle and the threshold, and is specifically configured to execute:
[0211] When the absolute value of the angle is less than the threshold, the refraction color is selected; when the absolute value of the angle is not less than the threshold, the reflection color is selected.
[0212] Optionally, the second color determination unit 122 is specifically configured to execute:
[0213] Determine the angle between the normal of the target pixel on the 3D model and the preset coordinate axis of the world space; determine the refraction weight and reflection weight based on the angle, use the refraction weight, reflection weight and preset mapping weight to perform weighted calculation on the refraction color, reflection color and mapping color to determine the rendering color of the target pixel.
[0214] Optionally, an image rendering device shown in another exemplary embodiment of the present disclosure may further include:
[0215] a correction unit, configured to correct the reflected color of the target pixel and / or the refracted color of the target pixel,
[0216] The correction coefficient used when correcting the reflected color of the target pixel is the first coefficient, and the correction coefficient used when correcting the refracted color of the target pixel is the second coefficient, and the first coefficient is different from the second coefficient.
[0217] Optionally, an image rendering device shown in another exemplary embodiment of the present disclosure may further include:
[0218] The correction unit is configured to correct the reflection color of the target pixel point and / or the refraction color of the target pixel point.
[0219] Optionally, the correction coefficients used when correcting the refraction colors of different target pixels are the same or different.
[0220] Optionally, the correction coefficients used when correcting the reflected colors of different target pixels are the same or different.
[0221] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0222] Another exemplary embodiment of the present disclosure shows an electronic device that can be Figure 5 As shown, including:
[0223] Processor 501;
[0224] A memory 502 for storing instructions executable by the processor 501;
[0225] The processor 501 is configured to execute instructions to implement any image rendering method provided in the present disclosure.
[0226] Another exemplary embodiment of the present disclosure shows a storage medium including instructions, such as Figure 5 The memory 502 including the instructions, when the instructions in the storage medium are Figure 5When the processor 501 of the electronic device shown is executed, the electronic device can execute any image rendering method provided by the present disclosure. Optionally, the storage medium can be a non-temporary computer-readable storage medium, for example, the non-temporary computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, and an optical data storage device.
[0227] Another exemplary embodiment of the present disclosure shows a computer program product, which, when executed on an electronic device, is suitable for executing a program that initiates the steps of the image rendering method provided by the present disclosure.
[0228] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0229] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. An image rendering method, characterized in that: include: Determine a refraction color, a reflection color, and a texture color of a target pixel point in a three-dimensional model of an object to be rendered, wherein the target pixel point represents a pixel point in the three-dimensional model to be displayed on a screen, and the texture is a texture that can increase the brightness of at least one pixel point in the object to be rendered; Selecting at least one of the refraction color and the reflection color according to a spatial relationship between a normal line of the target pixel point on the three-dimensional model and a preset coordinate axis in a world space, and determining a rendering color of the target pixel point according to the selected color and the map color; Rendering the target pixel point according to the rendering color; Also includes: gamma correction is performed on the reflection color of the target pixel and / or the refraction color of the target pixel, The correction coefficient used when performing gamma correction on the reflected color of the target pixel is a first coefficient, and the correction coefficient used when performing gamma correction on the refracted color of the target pixel is a second coefficient, the first coefficient is different from the second coefficient, the first coefficient is greater than the second coefficient, and different correction coefficients are used for different target pixels; Also includes: The three-dimensional model is divided into three parts: upper, middle and lower parts, wherein the absolute value of the angle between the normal of the pixel point in the middle on the three-dimensional model and the preset coordinate axis of the world space is set to be less than a threshold, and the absolute value of the angle between the normal of the pixel point in the upper and lower parts on the three-dimensional model and the preset coordinate axis of the world space is not less than a threshold; so that the upper and lower parts of the three-dimensional model show reflection effect, and the middle part shows refraction effect.
2. The image rendering method according to claim 1, characterized in that: The process of determining the refraction color includes: Determine a first intersection point between a light ray starting from a preset observation point and a background picture after passing through the target pixel point and the three-dimensional model, wherein the light ray enters the three-dimensional model through the target pixel point, is refracted, and exits the three-dimensional model, and the background picture is a preset picture or a currently captured picture; The refraction color of the target pixel is determined according to the color of the first intersection point on the background image.
3. The image rendering method according to claim 2, characterized in that: The step of determining a first intersection point between a light ray starting from a preset observation point and the background image after passing through the target pixel point and the three-dimensional model comprises: Determine the refraction direction of the light after it passes through the target pixel point and enters the three-dimensional model and is refracted according to the direction of the line connecting the preset observation point to the target pixel point, the normal direction of the target pixel point on the three-dimensional model, and the refractive index of the three-dimensional model; Determining the direction in which the light exits the three-dimensional model according to the refraction direction, the normal direction of the intersection of the light with the surface of the three-dimensional model when the light exits the three-dimensional model, and the refractive index of the three-dimensional model; According to the emission direction, a first intersection point between the light ray and the background image after the light ray passes through the target pixel point and the three-dimensional model is determined.
4. The image rendering method according to claim 1, characterized in that: The process of determining the reflected color includes: Determine a second intersection point between the light rays starting from the preset observation point and the background image after being reflected by the target pixel point, wherein the background image is a preset image or a current captured image; The reflection color of the target pixel is determined according to the color of the second intersection point on the background image.
5. The image rendering method according to claim 1, characterized in that: The process of determining the color of the map includes: Get a multi-frame texture sequence; Determine the mapping point corresponding to the target pixel point; The texture color of the target pixel is determined according to the color of the texture point in the texture sequence.
6. The image rendering method according to any one of claims 1 to 5, characterized in that: The step of selecting at least one of the refraction color and the reflection color according to a spatial relationship between a normal line of the target pixel point on the three-dimensional model and a preset coordinate axis in a world space, and determining a rendering color of the target pixel point according to the selected color and the map color comprises: Determine the angle between the normal line of the target pixel point on the three-dimensional model and the preset coordinate axis of the world space; According to the relationship between the absolute value of the angle and the threshold, one is selected from the refraction color and the reflection color, and the rendering color of the target pixel is determined according to the selected color and the map color.
7. The image rendering method according to claim 6, characterized in that: The selecting one of the refraction color and the reflection color according to the relationship between the absolute value of the angle and the threshold value comprises: When the absolute value of the angle is less than the threshold, selecting the refraction color; When the absolute value of the angle is not less than the threshold, the reflection color is selected.
8. The image rendering method according to any one of claims 1 to 5, characterized in that: The step of selecting at least one of the refraction color and the reflection color according to a spatial relationship between a normal line of the target pixel point on the three-dimensional model and a preset coordinate axis in a world space, and determining a rendering color of the target pixel point according to the selected color and the map color comprises: Determine the angle between the normal line of the target pixel point on the three-dimensional model and the preset coordinate axis of the world space; The refraction weight and the reflection weight are determined according to the angle, and the refraction color, the reflection color and the map color are weightedly calculated using the refraction weight, the reflection weight and the preset map weight to determine the rendering color of the target pixel.
9. An image rendering device, characterized in that: include: A first color determination unit is configured to determine a refraction color, a reflection color, and a texture color of a target pixel point in a three-dimensional model of an object to be rendered, wherein the target pixel point represents a pixel point in the three-dimensional model to be displayed on a screen, and the texture is a texture that can increase the brightness of at least one pixel point in the object to be rendered; A second color determination unit is configured to select at least one of the refraction color and the reflection color according to a spatial relationship between a normal line of the target pixel point on the three-dimensional model and a preset coordinate axis in a world space, and determine a rendering color of the target pixel point according to the selected color and the map color; A rendering unit, configured to render the target pixel point according to the rendering color; The device is also used for: gamma correction is performed on the reflection color of the target pixel and / or the refraction color of the target pixel, The correction coefficient used when performing gamma correction on the reflected color of the target pixel is a first coefficient, and the correction coefficient used when performing gamma correction on the refracted color of the target pixel is a second coefficient, the first coefficient is different from the second coefficient, the first coefficient is greater than the second coefficient, and different correction coefficients are used for different target pixels; The device is also used for: The three-dimensional model is divided into three parts: upper, middle and lower parts, wherein the absolute value of the angle between the normal of the pixel point in the middle on the three-dimensional model and the preset coordinate axis of the world space is set to be less than a threshold, and the absolute value of the angle between the normal of the pixel point in the upper and lower parts on the three-dimensional model and the preset coordinate axis of the world space is not less than a threshold; so that the upper and lower parts of the three-dimensional model show reflection effect, and the middle part shows refraction effect.
10. The image rendering device according to claim 9, characterized in that: The process of determining the refraction color by the first color determination unit is configured to execute: Determine a first intersection point between a light ray starting from a preset observation point and a background image after passing through the target pixel point and the three-dimensional model, wherein the light ray enters the three-dimensional model through the target pixel point, is refracted and exits the three-dimensional model, and the background image is a preset image or a currently captured image; determine the refracted color of the target pixel point based on the color of the first intersection point on the background image.
11. The image rendering device according to claim 10, characterized in that: The process in which the first color determination unit determines the first intersection point between the light rays starting from the preset observation point and the background image after passing through the target pixel point and the three-dimensional model is configured to execute: According to the direction of the line from the preset observation point to the target pixel point, the normal direction of the target pixel point on the three-dimensional model, and the refractive index of the three-dimensional model, the refraction direction of the light after it enters the three-dimensional model through the target pixel point and is refracted is determined; according to the refraction direction, the normal direction of the intersection of the light with the surface of the three-dimensional model when the light exits the three-dimensional model, and the refractive index of the three-dimensional model, the emission direction of the light exiting the three-dimensional model is determined; according to the emission direction, the first intersection point of the light with the background image after the light passes through the three-dimensional model through the target pixel point is determined.
12. The image rendering device according to claim 9, characterized in that: The process of determining the reflection color by the first color determination unit is configured to execute: Determine a second intersection point between the light starting from a preset observation point and the background image after being reflected by the target pixel point, where the background image is a preset image or a current shooting image; determine the reflection color of the target pixel point based on the color of the second intersection point on the background image.
13. The image rendering device according to claim 9, characterized in that: The process of determining the color of the map by the first color determination unit is configured to execute: Obtain a multi-frame texture sequence; determine the texture point corresponding to the target pixel point; and determine the texture color of the target pixel point according to the color of the texture point in the texture sequence.
14. The image rendering device according to any one of claims 9 to 13, characterized in that: The second color determination unit is specifically configured to execute: Determine the angle between the normal of the target pixel point on the three-dimensional model and the preset coordinate axis of the world space; select one from the refraction color and the reflection color according to the relationship between the absolute value of the angle and the threshold, and determine the rendering color of the target pixel point according to the selected color and the map color.
15. The image rendering device according to claim 14, characterized in that: The second color determination unit selects one of the refraction color and the reflection color according to the magnitude relationship between the absolute value of the angle and the threshold, and is specifically configured to execute: When the absolute value of the angle is less than the threshold, the refraction color is selected; when the absolute value of the angle is not less than the threshold, the reflection color is selected.
16. The image rendering device according to any one of claims 9 to 13, characterized in that: The second color determination unit is specifically configured to execute: Determine the angle between the normal of the target pixel point on the three-dimensional model and the preset coordinate axis of the world space; determine the refraction weight and the reflection weight according to the angle, and use the refraction weight, the reflection weight and the preset mapping weight to perform weighted calculation on the refraction color, the reflection color and the mapping color to determine the rendering color of the target pixel point.
17. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the image rendering method according to any one of claims 1 to 8.
18. A storage medium, when instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the image rendering method according to any one of claims 1 to 8.
