Rendering Method, Device, Electronic Device and Storage Medium of 3D Model
By calculating diffuse, scattering and specular reflected light color information using the relationship between the vertex normal and the light source and the observation line of sight in the three-dimensional model, and combining background map and grayscale information for rendering, the complex modeling and large calculations in the existing technology are solved, and the rendering effect is achieved with rich and natural light effects.
Patent Information
- Application Number
- CN202010831872.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-08-18
- Publication Date
- 2025-07-04
- Estimated Expiration
- 2040-08-18
AI Technical Summary
When simulating the subsurface scattering effect, the prior art has complex modeling and large calculation amounts, making it difficult to implement on terminals with small computing power, and the results are difficult to conform to physical laws and artificial adjustments.
By constructing a three-dimensional model and lighting model, diffuse, scattering and specular light color information are calculated by using the relationship between the vertex normal and the light source direction and the observation line of sight direction, and rendering it in combination with background map and grayscale information.
It achieves a relatively consistent full light feeling in different directions, avoiding the problem of some angles being too dark or too bright, and the calculation results are naturally fused with the background, which conforms to the physical real situation.
Smart Images

Figure CN114155335B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of image processing technologies, and in particular, to a method, apparatus, electronic device, and storage medium for rendering a three-dimensional model. Background Art
[0002] Subsurface scattering is a physical phenomenon caused by the inherent material properties of some common objects in nature. There are many objects with subsurface scattering properties, such as milk, skin, wax, jelly, etc. Therefore, the simulation of subsurface scattering effects is one of the more common and important technologies in computer three-dimensional rendering.
[0003] In the related art, to determine the pixel color under the subsurface scattering effect, the most direct solution is to use real physical theories to perform real-time ray tracing, calculate the reflection, refraction, and absorption effects after the light rays emitted from the observer's eyes enter the model, and through the simulation of these three possible movement forms of the light rays and the application of the principle of energy conservation, after performing simulation calculations, obtain the color of each pixel on the surface of the object with the subsurface scattering effect.
[0004] However, in the above method, the modeling is complex. It is necessary to establish the mapping relationship between the physical properties of the model material and the light ray movement trajectory. The parameters are complex and large in number, and it is difficult to model relatively accurately. Second, ray tracing is iterative. The outgoing light formed after the incident light is refracted becomes the incident light in the next link. Therefore, it is necessary to limit the number of iterations, and the calculation amount is large. When applied to terminals with relatively low computing power, problems are likely to occur. Third, the final calculation effect conforms to the physical state, but due to the overly rigorous model, it is not convenient to introduce artificially controllable variables, so it is not easy to adjust the obtained results manually.
[0005] In addition to the above method, the related art also proposes a method for simulating physical subsurface scattering, which simplifies the modeling process compared to the above method, weakens the pursuit of accurate results, no longer uses complex and delicate physical parameters for calculation, but instead defines parameters from a visual sense by observing the subsurface scattering material, and performs a perceptual simulation of the model. This not only reduces the number and definition difficulty of the parameters but also reduces the calculation amount.
[0006] However, since the parameters involved in this solution are all artificially defined after manual observation, it has strong subjectivity, cannot ensure that the effect completely conforms to the physical laws, and is difficult to ensure that the calculation results reflect a good sense of realism of the material effect. And currently, there are many simulation algorithms used manually, but it is difficult to achieve good expected effects when used alone. Summary of the Invention
[0007] The present disclosure provides a method, apparatus, electronic device, and storage medium for rendering a three-dimensional model to at least solve the technical problems in the related art. The technical solutions of the present disclosure are as follows:
[0008] According to a first aspect of an embodiment of the present disclosure, a method for rendering a three-dimensional model is provided, including:
[0009] Construct a three-dimensional model and a lighting model of an object;
[0010] Calculate the diffuse light color information of the object according to a first relationship between the vertex normal in the three-dimensional model and the light source direction in the lighting model;
[0011] Calculate the scattered light color information of the object according to a second relationship between the vertex normal and a preset viewing line-of-sight direction in the lighting model;
[0012] Normalize the sum of the preset viewing line-of-sight direction and the light source direction, and calculate the specular reflection light color information of the object according to a third relationship between the normalized result and the vertex normal;
[0013] Render the three-dimensional model of the object according to the diffuse light color information, the scattered light color information, and the specular reflection light color information.
[0014] Optionally, the method further includes:
[0015] Construct a texture map of the object;
[0016] Calculate the refraction direction after the line of sight enters the object from a vertex in the three-dimensional model;
[0017] Calculate a first exit position after the line of sight enters the object according to the vertex in the three-dimensional model, the refraction direction, and the background distortion degree in the lighting model;
[0018] Calculate a second exit position of the first exit position in the coordinate system of the screen;
[0019] Convert the second exit position to the coordinate system of the texture space of the background texture map in the texture map to obtain a third exit position;
[0020] Determine the background color of the texture map seen at the vertex in the three-dimensional model according to the third exit position and the color of the background texture map.
[0021] Optionally, before calculating the diffuse light color information of the object according to the first relationship between the vertex normal in the three-dimensional model and the light source direction in the lighting model, and after determining the background color of the texture map seen at the vertex in the three-dimensional model according to the third exit position and the color of the background texture map, the method further includes:
[0022] Calculate the grayscale information of the object according to the color values of each color channel corresponding to the background color and the preset weight values corresponding to each color channel.
[0023] Optionally, the calculating the diffuse light color information of the object according to the first relationship between the vertex normal in the 3D model and the light source direction in the lighting model includes:
[0024] Calculate the first relationship according to the lighting wrap intensity in the lighting model and the angle between the vertex normal and the light source direction;
[0025] Calculate the diffuse light color information of the object according to the first relationship, the intrinsic color information of the material of the object in the texture map, and the grayscale information of the object.
[0026] Optionally, the calculating the diffuse light color information of the object according to the first relationship, the intrinsic color information of the material of the object in the texture map, and the grayscale information of the object includes:
[0027] diffuse = albedo * max(1.0 - NoL_wrap, 0.0) * (0.5 + grayscale);
[0028] Wherein, diffuse is the diffuse light color information of the object, NoL_wrap is the first relationship, albedo is the intrinsic color information of the material, grayscale is the grayscale information of the object, and max represents taking the maximum value.
[0029] Optionally, the calculating the scattered light color information of the object according to the second relationship between the vertex normal and the preset viewing line-of-sight direction in the lighting model includes:
[0030] Calculate the second relationship according to the lighting wrap intensity in the lighting model and the angle between the vertex normal and the preset viewing line-of-sight direction;
[0031] Calculate the scattered light color information of the object according to the second relationship, the intrinsic color of the material of the object in the texture map and the thickness map on the surface of the 3D model, the overflow light color information in the lighting model, and the background color in the texture map.
[0032] Optionally, the calculating the scattered light color information of the object according to the second relationship, the intrinsic color of the material of the object in the texture map and the thickness map on the surface of the 3D model, the overflow light color information in the lighting model, and the background color of the texture map seen by the vertex in the 3D model includes:
[0033] Calculate the scattered light color of the object according to the second relationship, the background color, the thickness map, and the overflow light color information;
[0034] Calculate the scattering intensity of the non-edge part of the object and the scattering intensity of the edge part of the object;
[0035] Calculate the scattering intensity of the scattered light of the object according to the scattering intensity of the non-edge part of the object and the scattering intensity of the edge part of the object;
[0036] Calculate the scattered light color information according to the scattered light color, the scattering intensity of the scattered light of the object, and the intrinsic color of the material.
[0037] Optionally, the calculating the specular reflection light color information of the object according to the third relationship between the normalization result and the vertex normal includes:
[0038] specular = pow((max(NoH_wrap, 0.0), shininess);
[0039] Where specular is the specular reflection light color information of the object, NoH_wrap is the third relationship, shininess is the specular intensity in the lighting model, max represents taking the maximum value, and pow represents the power function.
[0040] Optionally, before rendering the three-dimensional model of the object according to the diffuse light color information, the scattered light color information, and the specular reflection light color information, the method further includes:
[0041] Calculate the ambient light color information of the object according to the thickness map and the surface roughness in the lighting model;
[0042] Where the rendering the three-dimensional model of the object according to the diffuse light color information, the scattered light color information, and the specular reflection light color information includes:
[0043] Render the three-dimensional model of the object according to the diffuse light color information, the scattered light color information, the specular reflection light color information, and the ambient light color information of the object.
[0044] According to a second aspect of the embodiments of the present disclosure, a three-dimensional model rendering device is provided, including:
[0045] A construction module configured to execute constructing a three-dimensional model of an object and a lighting model;
[0046] A diffuse reflection calculation module, configured to calculate the diffuse reflection light color information of the object according to a first relationship between the vertex normal in the three-dimensional model and the light source direction in the lighting model;
[0047] A scattering light calculation module, configured to calculate the scattered light color information of the object according to a second relationship between the vertex normal and a preset viewing line-of-sight direction in the lighting model;
[0048] A specular reflection calculation module, configured to normalize the sum of the preset viewing line-of-sight direction and the light source direction, and calculate the specular reflection light color information of the object according to a third relationship between the normalized result and the vertex normal;
[0049] A three-dimensional rendering module, configured to render the three-dimensional model of the object according to the diffuse reflection light color information, the scattered light color information, and the specular reflection light color information.
[0050] Optionally, the construction module is further configured to construct a texture map of the object, and the device further includes:
[0051] A direction calculation module, configured to calculate the refraction direction after the line of sight enters the object from a vertex in the three-dimensional model;
[0052] A position calculation module, configured to calculate a first exit position after the line of sight enters the object according to the vertex in the three-dimensional model, the refraction direction, and the background distortion degree in the lighting model; and calculate a second exit position of the first exit position in the coordinate system of the screen;
[0053] A position conversion module, configured to convert the second exit position into the coordinate system of the texture space where the background texture map is located in the texture map, to obtain a third exit position;
[0054] A color determination module, configured to determine the background color of the texture map seen at the vertex in the three-dimensional model according to the third exit position and the color of the background texture map.
[0055] Optionally, the device further includes:
[0056] A grayscale calculation module, configured to calculate the grayscale information of the object according to the color values of each color channel corresponding to the background color and preset weight values corresponding to each color channel.
[0057] Optionally, the diffuse reflection calculation module is configured to perform calculations as follows: calculate the first relationship according to the light wrapping intensity in the lighting model and the angle between the vertex normal and the light source direction; calculate the diffuse light color information of the object according to the first relationship, the material intrinsic color information of the object in the texture map, and the grayscale information of the object.
[0058] Optionally, the diffuse reflection calculation module is configured to perform the calculation:
[0059] diffuse = albedo * max(1.0 - NoL_wrap, 0.0) * (0.5 + grayscale);
[0060] where diffuse is the diffuse light color information of the object, NoL_wrap is the first relationship, albedo is the material intrinsic color information, grayscale is the grayscale information of the object, and max represents taking the maximum value.
[0061] Optionally, the scattering calculation module is configured to perform calculations as follows: calculate the second relationship according to the light wrapping intensity in the lighting model and the angle between the vertex normal and the preset viewing line-of-sight direction; and calculate the scattered light color information of the object according to the second relationship, the material intrinsic color of the object in the texture map, the thickness map of the three-dimensional model surface, the overflow light color information in the lighting model, and the background color in the texture map.
[0062] Optionally, the scattering calculation module includes:
[0063] A color calculation sub-module, configured to perform calculations to calculate the scattered light color of the object according to the second relationship, the background color, the thickness map, and the overflow light color information;
[0064] An intensity calculation sub-module, configured to perform calculations to calculate the scattering intensity of the non-edge part of the object and the scattering intensity of the edge part of the object; and calculate the scattering intensity of the scattered light of the object according to the scattering intensity of the non-edge part of the object and the scattering intensity of the edge part of the object;
[0065] An information calculation sub-module, configured to perform calculations to calculate the scattered light color information according to the scattered light color, the scattering intensity of the scattered light of the object, and the material intrinsic color.
[0066] Optionally, the specular reflection calculation module is configured to perform the calculation:
[0067] specular = pow((max(NoH_wrap, 0.0), shininess);
[0068] Wherein, specular is the specular reflection light color information of the object, NoH_wrap is the third relationship, shininess is the specular intensity in the lighting model, max represents taking the maximum value, and pow represents the power function.
[0069] Optionally, the device further includes:
[0070] An ambient light calculation module configured to calculate the ambient light color information of the object according to the thickness map and the surface roughness in the lighting model;
[0071] Wherein, the 3D rendering module is configured to perform rendering on the 3D model of the object according to the diffuse light color information, the scattered light color information, the specular reflection light color information, and the ambient light color information of the object.
[0072] According to a third aspect of the embodiments of the present disclosure, an electronic device is provided, including:
[0073] A processor;
[0074] A memory for storing instructions executable by the processor;
[0075] Wherein, the processor is configured to execute the instructions to implement the 3D model rendering method as described in the first aspect above.
[0076] According to a fourth aspect of the embodiments of the present disclosure, a storage medium is provided. When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute the 3D model rendering method as described in the first aspect above.
[0077] According to a fifth aspect of the embodiments of the present disclosure, a computer program product is provided, and the computer program product is configured to execute the 3D model rendering method as described in the first aspect above.
[0078] The technical solutions provided by the embodiments of the present disclosure at least bring the following beneficial effects:
[0079] According to the embodiments of the present disclosure, since the three relationships are respectively used to participate in the calculation of the diffuse light color information, the scattered light color information, and the specular reflection light color information, and the three relationships respectively characterize the relationships between different directions, it helps to make the calculation results have a relatively consistent and full light sense in different directions. Based on this result for coloring, the light effect levels displayed by the object can be made richer, and it can be avoided that some angles appear too dark or too bright.
[0080] Moreover, the gray-scale information of the object is used in the process of calculating the diffuse light color information, and the background color of the texture map seen by the vertex in the three-dimensional model is used in the process of calculating the scattered light color information. The gray-scale information of the object can be determined according to the background color of the texture map seen by the vertex in the three-dimensional model. Therefore, in the process of calculating the diffuse light color information and the scattered light color information, the background color of the texture map seen by the vertex in the three-dimensional model is used.
[0081] By calculating with reference to the background color of the texture map seen by the vertex in the three-dimensional model, the calculation result can match the background texture map to a certain extent, making the colored object and the background blend more naturally and more in line with the physical reality.
[0082] In addition, in the pre-constructed lighting model, the thickness texture map on the surface of the three-dimensional model can be equivalent to the depth map to a certain extent. Therefore, there is no need to recalculate the depth map through hardware during the calculation process, reducing the hardware overhead.
[0083] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and do not limit the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0084] The accompanying drawings herein are incorporated into the specification and form a part of the specification, showing embodiments consistent with the present disclosure, and are used together with the specification to explain the principles of the present disclosure and do not constitute an improper limitation of the present disclosure.
[0085] Figure 1 is a schematic flow chart of a method for rendering a three-dimensional model according to an embodiment of the present disclosure.
[0086] Figure 2 is a schematic flow chart of another method for rendering a three-dimensional model according to an embodiment of the present disclosure.
[0087] Figure 3 is a schematic flow chart of yet another method for rendering a three-dimensional model according to an embodiment of the present disclosure.
[0088] Figure 4 is a schematic flow chart of a method for calculating diffuse light color information according to an embodiment of the present disclosure.
[0089] Figure 5 is a schematic flow chart of a method for calculating scattered light color information according to an embodiment of the present disclosure.
[0090] Figure 6 is a specific schematic flow chart of a method for calculating scattered light color information according to an embodiment of the present disclosure.
[0091] Figure 7 It is a schematic flowchart showing a method for calculating the color information of specularly reflected light according to an embodiment of the present disclosure.
[0092] Figure 8 It is a schematic flowchart showing another method for rendering a three-dimensional model according to an embodiment of the present disclosure.
[0093] Figure 9 It is a schematic block diagram showing a device for rendering a three-dimensional model according to an embodiment of the present disclosure.
[0094] Figure 10 It is a schematic block diagram showing another device for rendering a three-dimensional model according to an embodiment of the present disclosure.
[0095] Figure 11 It is a schematic block diagram showing yet another device for rendering a three-dimensional model according to an embodiment of the present disclosure.
[0096] Figure 12 It is a schematic block diagram showing a scattering calculation module according to an embodiment of the present disclosure.
[0097] Figure 13 It is a schematic block diagram showing yet another device for rendering a three-dimensional model according to an embodiment of the present disclosure.
[0098] Figure 14 It is a schematic block diagram showing an electronic device according to an embodiment of the present disclosure. Detailed implementation manners
[0099] In order to enable those of ordinary skill 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 with reference to the accompanying drawings.
[0100] 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 do not necessarily need to be used to describe a specific order or sequence. It should be understood that such used data may be interchanged under appropriate circumstances so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The implementation manners described in the following exemplary embodiments do not represent all implementation manners consistent with the present disclosure. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0101] Figure 1 It is a schematic flowchart showing a method for rendering a three-dimensional model according to an embodiment of the present disclosure. The method shown in this embodiment can be applicable to terminals, such as electronic devices like mobile phones, tablet computers, wearable devices, etc., and can also be applicable to servers, such as local servers, cloud servers, etc.
[0102] Specifically, taking the application of this method to a mobile phone as an example, a shader application can be set in the mobile phone, and the calculation result of this solution can be used by the shader application to color an object.
[0103] Specific application scenarios include, but are not limited to, rendering a three-dimensional model of an object. The object can be a virtual object. For example, the virtual object can be virtual cat ears added above a person's face during the shooting process. Then, the object in the following embodiments is the virtual cat ears, and the calculated color can be used by the shader to render the virtual cat ears.
[0104] As Figure 1 shown, the method for rendering the three-dimensional model may include the following steps:
[0105] In step S101, construct a three-dimensional model and a lighting model of the object;
[0106] In step S102, calculate the diffuse light color information of the object according to the first relationship between the vertex normal in the three-dimensional model and the light source direction in the lighting model;
[0107] In step S103, calculate the scattered light color information of the object according to the second relationship between the vertex normal and the preset viewing line-of-sight direction in the lighting model;
[0108] In step S104, normalize the sum of the preset viewing line-of-sight direction and the light source direction, and calculate the specular light color information of the object according to the third relationship between the normalized result and the vertex normal;
[0109] In step S105, render the three-dimensional model of the object according to the diffuse light color information, the scattered light color information, and the specular light color information.
[0110] In one embodiment, the object for which a three-dimensional model needs to be constructed can be set as needed. For example, it can be the above-mentioned virtual cat ears or other objects.
[0111] For the set object, a three-dimensional model of the object can be pre-constructed. The three-dimensional model can include vertex position (position), texture coordinates (u0v0), and vertex normal (N). Among them, there can be multiple vertices on the three-dimensional model, and multiple vertices are connected to form multiple polygons (such as triangles), and multiple polygons can piece together the three-dimensional model.
[0112] In addition to pre - constructing a three - dimensional model of an object, a lighting model can also be constructed. The lighting model includes: light intensity (light_intensity), lighting direction (L), refractive index of the material (IOR, which can also be expressed as n1), surface roughness (Ir), background distortion degree (twist), preset viewing line - of - sight direction (w2c, which can also be expressed as V), bleeding color (bleeding_color), Gaussian blur parameter, lighting wrap intensity (wrap_intensity), scatter intensity (scatter_width), and shininess. Among them, the lighting wrap intensity can be understood as a rough simulation of the diffuse reflection lighting on a rough surface.
[0113] It should be noted that the above - mentioned preset viewing line - of - sight direction can refer to the direction of the light rays emitted from a virtual camera (not a real camera, but a camera assumed to exist for calculating the line - of - sight direction) at a preset position.
[0114] According to an embodiment of the present disclosure, when calculating the diffuse - reflection light color information, it can be calculated according to the first relationship between the vertex normal in the three - dimensional model and the light source direction in the lighting model; when calculating the scattered - light color information of the object, it can be calculated according to the second relationship between the vertex normal and the preset viewing line - of - sight direction in the lighting model; when calculating the specular - reflection light color information of the object, the sum of the preset viewing line - of - sight direction and the light source direction can be normalized, and calculated according to the third relationship between the normalized result and the vertex normal.
[0115] In the related art, when calculating the diffuse - reflection light color information, the scattered - light color information of the object, and the specular - reflection light color information of the object, only one of the above - mentioned three relationships is used for calculation.
[0116] Since this solution uses the above - mentioned three relationships to participate in the calculation of the diffuse - reflection light color information, the scattered - light color information, and the specular - reflection light color information respectively, and the three relationships respectively represent the relationships between different directions, it helps to make the calculation results have a more consistent and full light sense in different directions. Based on this result for coloring, the light effect levels displayed by the object can be made more abundant, avoiding being too dark or too bright at certain angles.
[0117] Figure 2 It is a schematic flowchart of another three - dimensional model rendering method shown according to an embodiment of the present disclosure. As Figure 2 shown, before calculating the diffuse - reflection light color information of the object according to the first relationship between the vertex normal in the three - dimensional model and the light source direction in the lighting model, the method further includes:
[0118] In step S106, a texture map of the object is constructed; for example, the texture map of the object can be constructed when constructing the three-dimensional model and the lighting model of the object;
[0119] In step S107, calculate the refraction direction after the line of sight enters the object from a vertex in the three-dimensional model;
[0120] In step S108, calculate the first exit position after the line of sight enters the object according to the vertex in the three-dimensional model, the refraction direction, and the background distortion degree in the lighting model;
[0121] In step S109, calculate the second exit position of the first exit position in the coordinate system of the screen;
[0122] In step S110, convert the second exit position to the coordinate system of the texture space where the background texture map in the texture map is located to obtain a third exit position;
[0123] In step S111, determine the background color of the texture map seen at the vertex in the three-dimensional model according to the third exit position and the color of the background texture map.
[0124] In one embodiment, in addition to pre-constructing the three-dimensional model of the object, when constructing the three-dimensional model and the lighting model of the object, a texture map of the object can also be constructed.
[0125] The texture map can include a basic color map (albedo), which can also be called a diffuse reflection map, and this color map can reflect the texture and color of the three-dimensional model; a thickness map (thickness) on the surface of the three-dimensional model, and the thickness of each position of the three-dimensional model can be determined according to the thickness map; a background texture map (bg_tex) used as the background, and according to the background texture map, the ratio of the linear mixture of the background color and the inherent color of the object itself can be determined. For a certain position in the image, the linear mixture of the background color at that position and the inherent color of the object at that position can obtain a new color, which is used as the color of the pixel at that position in the image.
[0126] In order to use the background color of the texture map seen at the vertex in the three-dimensional model during the process of calculating the diffuse light color information and the scattered light color information, the background color of the texture map seen at the vertex in the three-dimensional model can be calculated first.
[0127] First, the refraction direction after the line of sight enters the interior of the object from a vertex in the three-dimensional model can be calculated. Specifically, according to the ratio n0 / n1 of the preset observation line-of-sight direction V, the vertex normal N, the refractive index n0 of air, and the refractive index n1 of the object, the refraction direction ray_refract = normalize(refract(-V, N, n0 / n1)) can be calculated. refract represents a function for calculating the direction, and normalize represents normalization, that is, converting the vector obtained by the refract function into a vector with a length of 1.
[0128] Then, the refraction direction after the line of sight enters the interior of the object from a vertex in the three-dimensional model can be calculated. Specifically, according to the vertex position position in the three-dimensional model, the background distortion degree twist in the lighting model, the vertex normal N, and the refraction direction ray_refract, the first exit position point_in_line = position + ray_refract * (twist / dot(-N, ray_refract)) can be calculated. Where dot represents calculating the cosine value of the included angle, and twist, as the background distortion degree, can represent the travel distance of light in the case of scattering and is an empirical simulation value.
[0129] Next, the second exit position of the first exit position in the coordinate system of the screen can be calculated. Specifically, according to the first transformation matrix Mv from the coordinate system where the three-dimensional model is located to the coordinate system of the observer who emits the observation line of sight, the second transformation matrix Mp from the coordinate system of the observer to the coordinate system of the screen where the object is displayed, and the first exit position point_in_line, the second exit position screen_pos = Mp * Mv * point_in_line of the exit position in the coordinate system of the screen can be calculated. That is, the exit position in the three-dimensional object is mapped to the coordinate system of the screen where the object is displayed, and the coordinate system of the screen is a two-dimensional coordinate system.
[0130] Then, convert the second emission position to the coordinate system of the texture space where the background texture is located in the texture map to obtain a third emission position. Specifically, the second emission position screen_pos can be converted to the coordinate system of the texture space where the background texture is located in the texture map to obtain the third emission position uv = screen_pos.(x,y) / screen_pos.w*0.5 + 0.5. Here, (x,y) represents the second emission position. Since the coordinate range of the screen coordinate system (e.g., [-1,1]) and the coordinate range of the background texture coordinate system (e.g., [0,1]) can be different, according to the above formula, the coordinate ranges of the two can be converted to be the same. The value of w can be set as needed. For example, when the virtual camera is an orthographic camera, the value of w is generally equal to 1. For example, when the virtual camera is a perspective camera, the value of w is generally not equal to 1.
[0131] Finally, according to the third emission position (u,v) and the color bg_tex of the background texture, determine the background color bg_color of the texture seen by the vertex in the three-dimensional model, bg_color = texture2d(bg_tex,uv), where texture2d represents the sampling function.
[0132] Accordingly, the background color of the texture seen by the vertex in the three-dimensional model can be obtained for use in the process of calculating the diffuse light color information and the scattered light color information.
[0133] In one embodiment, before using bg_color subsequently, Gaussian blur can be performed on the obtained bg_color, which is beneficial to achieving soft lighting and weakening details.
[0134] Among them, the Gaussian blur can refer to the following two operators:
[0135] (0.227, 0.195, 0.122, 0.054, 0.016) and (0.383, 0.242, 0.061, 0.006, 0.0);
[0136] The first operator has a greater blur intensity, and the second operator has a smaller blur intensity, which can be specifically selected according to needs.
[0137] Figure 3 It is a schematic flowchart of another rendering method for a three-dimensional model shown according to an embodiment of the present disclosure. As Figure 3As shown, before calculating the diffuse light color information of the object according to the first relationship between the vertex normal in the three-dimensional model and the light source direction in the lighting model, and after determining the background color of the texture seen by the vertex in the three-dimensional model according to the third exit position and the color of the background texture, the method further includes:
[0138] In step S112, according to the color values of each color channel corresponding to the background color, and the preset weight values corresponding to each color channel, calculate the gray-scale information of the object.
[0139] In one embodiment, the gray-scale information of the object can be further calculated according to the color values of each color channel corresponding to the background color of the texture seen by the vertex in the three-dimensional model (for example, including the rgb three channels, then the corresponding color values can be bg_color.r, bg_color.g, bg_color.b respectively), and the preset weight values corresponding to each color channel, where grayscale = bg_color.r * 0.299 + bg_color.g * 0.587 + bg_color.b * 0.114. The preset weight values 0.299, 0.587, 0.114, etc. can be set as needed and are not limited to the situation described in this embodiment.
[0140] Among them, the gray-scale information of the object is used in the process of calculating the diffuse light color information, and the gray-scale information of the object can be determined according to the background color of the texture seen by the vertex in the three-dimensional model. Therefore, in the process of calculating the diffuse light color information, the background color of the texture seen by the vertex in the three-dimensional model is used.
[0141] By calculating with reference to the background color of the texture seen by the vertex in the three-dimensional model, the calculation result can be made to fit the background texture to a certain extent, making the colored object and the background blend more naturally and also more in line with the physical reality.
[0142] In addition, in the pre-constructed lighting model, the thickness map on the surface of the three-dimensional model can be equivalent to the depth map to a certain extent. Therefore, there is no need to calculate the depth map through hardware during the calculation process, reducing the hardware overhead.
[0143] And in the pre-constructed content, except that the three-dimensional model and the texture are relatively fixed, the parameters in the lighting model are adjustable. This makes the calculation result no longer limited to the actual scene, but different results can be obtained according to the parameters in the lighting model adjusted by the user, facilitating the user's artistic processing.
[0144] Figure 4A schematic flowchart showing the calculation of the diffuse light color information according to an embodiment of the present disclosure. As Figure 4 shown, calculating the diffuse light color information of the object according to a first relationship between the vertex normal in the three-dimensional model and the light source direction in the lighting model includes:
[0145] In step S1021, calculate the first relationship according to the lighting wrap intensity in the lighting model and the angle between the vertex normal and the light source direction;
[0146] In step S1022, calculate the diffuse light color information of the object according to the first relationship, the inherent color information of the material of the object in the texture map, and the gray scale information of the object.
[0147] Optionally, the first relationship NoL_wrap can be specifically calculated in the following manner:
[0148] NoL_wrap = (dot(N, L) + wrap) / (1.0 + wrap);
[0149] where wrap is the lighting wrap intensity in the lighting model, N is the vertex normal, L is the light source direction, and dot(N, L) represents the cosine value of the angle between N and L.
[0150] Optionally, calculating the diffuse light color information of the object according to the first relationship, the inherent color information of the material of the object in the texture map, and the gray scale information of the object includes:
[0151] diffuse = albedo * max(1.0 - NoL_wrap, 0.0) * (0.5 + grayscale);
[0152] where, diffuse is the diffuse light color information of the object, NoL_wrap is the first relationship, albedo is the inherent color information of the material, grayscale is the gray scale information of the object, and max represents taking the maximum value.
[0153] In one embodiment, calculating the diffuse light color information diffuse according to the above formula, the smaller the angle between the vertex normal N and the light source direction L, the more the object is facing the light source directly, and the more likely the surface of the object is a bright surface, while the larger the angle, the less the object is facing the light source, and the more likely it is a dark surface (such as 90°)
[0154] In the formula for calculating the first relationship, NoL_wrap = (dot(N, L) + wrap) / (1.0 + wrap). Assuming wrap = 0, then NoL_wrap = dot(N, L). Assuming the angle between N and L is 90°, then NoL_wrap = cos(90°) = 0.0. So, max(1.0 - NoL_wrap, 0.0) = max(1.0 - 0.0, 0.0) = 1.0. Then the diffuse light color information diffuse = albedo * max(1.0 - NoL_wrap, 0.0) * (0.5 + grayscale) = albedo * 1.0 * (0.5 + grayscale). Thus, the coefficient when the object is on the dark side (the angle between N and L is 90°) is 1.
[0155] Assume again that the angle between N and L is 30° (smaller than 90°, so the object is more towards the light source and belongs to the bright side). Still assuming wrap = 0, then NoL_wrap = dot(N, L) = cos(30°) = 0.866. So, max(1.0 - NoL_wrap, 0.0) = max(1.0 - 0.866, 0.0) = 0.134. Then the diffuse light color information diffuse = albedo * max(1.0 - NoL_wrap, 0.0) * (0.5 + grayscale) = albedo * 0.134 * (0.5 + grayscale). Thus, the coefficient when the object is on the bright side (the angle between N and L is 30°) is 0.134.
[0156] Comparing with the coefficient 1 when the object is on the dark side, 1 > 0.134. So, the coefficient of the dark part in the calculation formula is larger than that of the bright part, which can make the dark part brighter and thus improve the brightness of the dark side to a certain extent. Therefore, calculating the diffuse light color information in the manner shown in this embodiment can, to a certain extent, avoid some areas in the obtained diffuse light color information from being too dark.
[0157] Figure 5 It is a schematic flowchart showing a method for calculating the scattered light color information according to an embodiment of the present disclosure. As Figure 5 shown, calculating the scattered light color information of the object according to the second relationship between the vertex normal and the preset viewing line-of-sight direction in the lighting model includes:
[0158] In step S1031, calculate the second relationship according to the lighting wrap intensity in the lighting model and the angle between the vertex normal and the preset viewing line-of-sight direction;
[0159] In step S1032, calculate the scattered light color information of the object according to the second relationship, the inherent color of the material of the object in the texture map, the thickness texture map on the surface of the 3D model, the overflow light color information in the lighting model, and the background color in the texture map.
[0160] Optionally, the second relationship NoV_wrap is calculated in the following way:
[0161] NoV_wrap = (dot(N, V) + wrap) / (1.0 + wrap);
[0162] where wrap is the lighting wrap intensity in the lighting model, N is the vertex normal, V is the preset viewing line-of-sight direction, and dot(N, V) represents the cosine value of the angle between N and V.
[0163] The background color of the texture map seen by the vertex in the 3D model is used in the process of calculating the scattered light color information, and the gray-scale information of the object can be determined according to the background color of the texture map seen by the vertex in the 3D model. Therefore, the background color of the texture map seen by the vertex in the 3D model is used in the process of calculating the scattered light color information.
[0164] By calculating with reference to the background color of the texture map seen by the vertex in the 3D model, the calculation result can fit the background texture map to a certain extent, making the colored object and the background blend more naturally and more in line with the physical reality.
[0165] Figure 6 It is a specific schematic flowchart of calculating the scattered light color information shown according to an embodiment of the present disclosure. As Figure 6 shown, calculating the scattered light color information of the object according to the second relationship, the inherent color of the material of the object in the texture map, the thickness texture map on the surface of the 3D model, the overflow light color information in the lighting model, and the background color of the texture map seen by the vertex in the 3D model includes:
[0166] In step S10321, calculate the scattered light color of the object according to the second relationship, the background color, the thickness texture map, and the overflow light color information;
[0167] In step S10322, calculate the scattering intensity of the non-edge part of the object and the scattering intensity of the edge part of the object;
[0168] In step S10323, calculate the scattering intensity of the scattered light of the object according to the scattering intensity of the non-edge part of the object and the scattering intensity of the edge part of the object;
[0169] In step S10324, calculate the scattered light color information according to the scattered light color, the scattering intensity of the scattered light of the object, and the material inherent color.
[0170] In one embodiment, the scattered light color scatter is calculated as follows:
[0171] scatter = mix(albedo, bg_color * NoV_wrap + albedo, thickness) * mix(bleeding_color, 1.0, abs(NoV_wrap)); or
[0172] scatter = mix(bg_color * (1.0 - NoV_wrap) + albedo, albedo, thickness) * mix(1.0, bleeding_color, abs(NoV_wrap)));
[0173] Wherein, albedo is the material inherent color, bg_color is the background color of the texture seen at the vertex in the 3D model, thickness is the thickness texture, bleeding_color is the overflow light color information, mix represents a linear mixing function, and abs represents taking the absolute value.
[0174] In one embodiment, the scattering intensity of the non-edge part scatter_main of the object is calculated as follows:
[0175] scatter_main = smoothstep(0.0, scatter_width, NoV_wrap) * max(smoothstep(scatter_width, scatter_width * 2.0, NoV_wrap), 0.5);
[0176] Wherein, scatter_width is the scattering intensity in the lighting model, and smoothstep represents a smooth transition function;
[0177] In one embodiment, the scattering intensity of the edge part scatter_rim of the object is calculated as follows:
[0178] scatter_rim = smoothstep(0.0, scatter_width, NoV_wrap) * smoothstep(scatter_width * 2.0, scatter_width, NoV_wrap) * light_intensity;
[0179] Among them, light_intensity is the light source intensity in the light model.
[0180] In one embodiment, the scattering intensity scatter_intensity of the scattered light is calculated as follows:
[0181] scatter_intensity = scatter_main * (0.5 + grayscale) + scatter_rim * (1.0 - grayscale);
[0182] Among them, grayscale is the gray-scale information of the object.
[0183] In one embodiment, the scattering color can be calculated by referring to the base color of the object material, that is, the color map albedo, and the background color, that is, the background color bg_color of the map seen at the vertices in the 3D model, and the bleeding color, that is, the bleeding light color information bleeding_color.
[0184] When the background color brightness is higher than the base color brightness, the formula can be used to calculate scatter:
[0185] scatter = mix(albedo, bg_color * NoV_wrap + albedo, thickness) * mix(bleeding_color, 1.0, abs(NoV_wrap));
[0186] Since the background color is referred to, when the thick part has a background color brightness higher than the base color, the background color will be presented more.
[0187] When the background color brightness is lower than the base color brightness, the formula can be used to calculate scatter:
[0188] scatter = mix(bg_color * (1.0 - NoV_wrap) + albedo, albedo, thickness) * mix(1.0, bleeding_color, abs(NoV_wrap)));
[0189] Due to the reference to the background color, the overall color of the object will become darker, presenting more of its inherent color, but the edges will be brighter.
[0190] The overflow light color information can be related to the viewing angle (such as the preset viewing line-of-sight direction V mentioned above), showing an obvious trend of edge overflow phenomenon.
[0191] The scattering intensity is crucial for presenting the sense of volume of the object and can simulate the light and dark areas on the surface. In this embodiment, when calculating the scattering intensity scatter_intensity, scatter_main and scatter_rim are referred to. scatter_main represents the scattering intensity of the main part of the object, showing a smooth spherical wrapping trend, while scatter_rim represents the scattering intensity of the edge of the object. During the calculation process, the light source intensity in the lighting model is referred to, enabling the object to blend more naturally into the environment. grayscale indicates that the scattering intensity is related to the light and dark of the background color. Calculating with reference to grayscale can make the darker the background, the darker the main body of the material, and the edges appear brighter due to backlight overflow and enhanced contrast.
[0192] Figure 7 It is a schematic flowchart showing a method for calculating the specular reflection light color information according to an embodiment of the present disclosure. As Figure 7 shown, calculating the specular reflection light color information of the object according to the third relationship between the normalized result and the vertex normal includes:
[0193] In step S1041, according to the third relationship and the specular intensity in the lighting model, calculate the specular reflection light color information of the object.
[0194] Optionally, the third relationship NoH_wrap is calculated in the following way:
[0195] NoH_wrap = (dot(N, normalize(V + L)) + wrap) / (1.0 + wrap);
[0196] where wrap is the lighting wrap intensity, N is the vertex normal, V is the viewing line-of-sight vector, L is the light source direction, normalize represents normalization, and dot represents calculating the cosine value of the angle between vectors.
[0197] Optionally, the specular reflection light color information specular is calculated in the following way:
[0198] specular = pow((max(NoH_wrap, 0.0), shininess);
[0199] where specular is the specular reflection light color information of the object, NoH_wrap is the third relationship, shininess is the specular intensity in the lighting model, max means taking the maximum value, and pow means the power function.
[0200] The surface roughness in the lighting model can be used as a supplement to the main lighting part to enhance the overall texture of the material. The surface roughness will determine the clarity of the display of the environment map, and thus affect the smoothness of the object surface texture. The method of calculating the ambient light color information in this way is conducive to obtaining relatively accurate reflected light color information.
[0201] Figure 8 is a schematic flowchart of another rendering method of a three-dimensional model shown according to an embodiment of the present disclosure. As Figure 8 shown, before rendering the three-dimensional model of the object according to the diffuse light color information, the scattered light color information, and the specular reflection light color information, the method further includes:
[0202] In step S113, calculate the ambient light color information of the object according to the thickness map and the surface roughness in the lighting model;
[0203] wherein, rendering the three-dimensional model of the object according to the diffuse light color information, the scattered light color information, and the specular reflection light color information includes:
[0204] In step S1051, render the three-dimensional model of the object according to the diffuse light color information, the scattered light color information, the specular reflection light color information, and the ambient light color information of the object.
[0205] In one embodiment, when rendering the three-dimensional model of an object, in addition to considering the diffuse light color information, the scattered light color information, and the specular reflection light color information, the ambient light color information of the object can also be considered.
[0206] Specifically, the surface color final_color of the object can be calculated in the following way:
[0207] final_color = diffuse + scatter_intensity * scatter * albedo + specular + ambient light color;
[0208] Furthermore, the three-dimensional model of the object is rendered based on the calculated surface color of the object. Since the ambient light color is considered, the calculated surface color of the object is consistent with the actual environment. And by considering the diffuse light color information, the scattered light color information, and the specular reflection light color information, and combining multiple subsurface scattering simulation algorithms, the calculated result makes the object have a stronger sense of volume and improves the expressiveness of the material.
[0209] Corresponding to the embodiment of the three-dimensional model rendering method described above, the present disclosure also proposes an embodiment of a three-dimensional model rendering device.
[0210] Figure 9 FIG. is a schematic block diagram of a three-dimensional model rendering device shown according to an embodiment of the present disclosure. The device shown in this embodiment can be applicable to a terminal, such as electronic devices like mobile phones, tablet computers, wearable devices, etc., and can also be applicable to a server, such as a local server, a cloud server, etc.
[0211] Specifically, taking the application of this device in a mobile phone as an example, a shader application can be set in the mobile phone, and the calculation result of this solution can be used by the shader application to color the object.
[0212] Specific application scenarios include, but are not limited to, rendering the three-dimensional model of an object. The object can be a virtual object. For example, in the shooting process, virtual cat ears added above a person's face can be a virtual object. Then the object in the following embodiments is the virtual cat ears, and the calculated color can be used by the shader to render the virtual cat ears.
[0213] As Figure 9 shown, the device includes:
[0214] A construction module 101, configured to construct a three-dimensional model of an object and a lighting model;
[0215] A diffuse reflection calculation module 102, configured to calculate the diffuse reflection light color information of the object according to a first relationship between the vertex normal in the three-dimensional model and the light source direction in the lighting model;
[0216] A scattered light calculation module 103, configured to calculate the scattered light color information of the object according to a second relationship between the vertex normal and a preset viewing line-of-sight direction in the lighting model;
[0217] A specular reflection calculation module 104, configured to normalize the sum of the preset viewing line-of-sight direction and the light source direction, and calculate the specular reflection light color information of the object according to a third relationship between the normalized result and the vertex normal;
[0218] The 3D rendering module 105 is configured to perform rendering of the 3D model of the object according to the diffuse light color information, the scattered light color information, and the specular light color information.
[0219] Figure 10 FIG. 4 is a schematic block diagram of another 3D model rendering device shown according to an embodiment of the present disclosure. The construction module 101 is further configured to perform construction of a texture map of the object. The device further includes:
[0220] The direction calculation module 106 is configured to perform calculation of the refraction direction after the line of sight enters the interior of the object from a vertex in the 3D model.
[0221] The position calculation module 107 is configured to perform calculation of a first exit position after the line of sight enters the object according to the vertex in the 3D model, the refraction direction, and the background distortion degree in the lighting model; and calculation of a second exit position of the first exit position in the coordinate system of the screen.
[0222] The position conversion module 108 is configured to perform conversion of the second exit position into the coordinate system of the texture space where the background texture map is located in the texture map to obtain a third exit position.
[0223] The color determination module 109 is configured to perform determination of the background color of the texture map seen at the vertex in the 3D model according to the third exit position and the color of the background texture map.
[0224] Figure 11 FIG. 5 is a schematic block diagram of yet another 3D model rendering device shown according to an embodiment of the present disclosure. As shown in FIG. 5, the device further includes: Figure 11 As shown, the device further includes:
[0225] The grayscale calculation module 110 is configured to perform calculation of the grayscale information of the object according to the color values of each color channel corresponding to the background color and the preset weight values corresponding to each color channel.
[0226] Optionally, the diffuse calculation module is configured to perform calculation of the first relationship according to the light wrapping intensity in the lighting model and the angle between the vertex normal and the light source direction; and calculation of the diffuse light color information of the object according to the first relationship, the material inherent color information of the object in the texture map, and the grayscale information of the object.
[0227] Optionally, the diffuse calculation module is configured to perform calculation of:
[0228] diffuse = albedo * max(1.0 - NoL_wrap, 0.0) * (0.5 + grayscale);
[0229] Wherein, diffuse is the diffuse light color information of the object, NoL_wrap is the first relationship, albedo is the inherent color information of the material, grayscale is the grayscale information of the object, and max represents taking the maximum value.
[0230] Optionally, the astigmatism calculation module is configured to calculate the second relationship according to the light wrapping intensity in the light model and the angle between the vertex normal and the preset viewing line of sight direction; and calculate the scattered light color information of the object according to the second relationship, the inherent color of the material of the object in the texture map, the thickness texture map on the surface of the 3D model, the overflow light color information in the light model, and the background color in the texture map.
[0231] Figure 12 It is a schematic block diagram of an astigmatism calculation module shown according to an embodiment of the present disclosure. As Figure 12 shown, the astigmatism calculation module 103 includes:
[0232] A color calculation sub-module 1031, configured to calculate the scattered light color of the object according to the second relationship, the background color, the thickness texture map, and the overflow light color information;
[0233] An intensity calculation sub-module 1032, configured to calculate the scattering intensity of the non-edge part of the object and the scattering intensity of the edge part of the object; and calculate the scattering intensity of the scattered light of the object according to the scattering intensity of the non-edge part of the object and the scattering intensity of the edge part of the object;
[0234] An information calculation sub-module 1033, configured to calculate the scattered light color information according to the scattered light color, the scattering intensity of the scattered light of the object, and the inherent color of the material.
[0235] Optionally, the specular reflection calculation module is configured to calculate the specular reflection light color information of the object according to the third relationship and the specular intensity in the light model.
[0236] Optionally, the specular reflection calculation module is configured to perform the calculation:
[0237] specular = pow((max(NoH_wrap, 0.0), shininess);
[0238] Where specular is the specular reflection light color information of the object, NoH_wrap is the third relationship, shininess is the highlight intensity in the lighting model, max represents taking the maximum value, and pow represents the power function.
[0239] Figure 13 is a schematic block diagram of another three-dimensional model rendering device shown according to an embodiment of the present disclosure. As Figure 13 shown, the device further includes:
[0240] An ambient light calculation module 111, configured to calculate the ambient light color information of the object according to the thickness map and the surface roughness in the lighting model;
[0241] Wherein, the three-dimensional rendering module 105 is configured to perform rendering of the three-dimensional model of the object according to the diffuse light color information, the scattered light color information, the specular reflection light color information, and the ambient light color information of the object.
[0242] Regarding the device in the above embodiments, the specific manners in which each module / unit performs operations have been described in detail in the embodiments related to the method, and will not be elaborated herein.
[0243] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can refer to the partial descriptions of the method embodiments. The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of the present disclosure. Those of ordinary skill in the art can understand and implement it without creative efforts.
[0244] An embodiment of the present disclosure also proposes an electronic device, including:
[0245] A processor;
[0246] A memory for storing executable instructions of the processor;
[0247] Wherein, the processor is configured to execute the instructions to implement the three-dimensional model rendering method as described in any of the above embodiments.
[0248] An embodiment of the present disclosure also proposes a storage medium, when the instructions in the storage medium are executed by a processor of an electronic device, enabling the electronic device to execute the three-dimensional model rendering method as described in any of the above embodiments.
[0249] Embodiments of the present disclosure also propose a computer program product, which is configured to execute the rendering method of the three-dimensional model described in any of the above embodiments.
[0250] Figure 14 FIG. 5 is a schematic block diagram of an electronic device shown according to an embodiment of the present disclosure. For example, the electronic device 1400 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0251] Referring to Figure 14 FIG. 5, the electronic device 1400 may include one or more of the following components: a processing component 1402, a memory 1404, a power component 1406, a multimedia component 1408, an audio component 1410, an input / output (I / O) interface 1412, a sensor component 1414, and a communication component 1416.
[0252] The processing component 1402 generally controls the overall operation of the electronic device 1400, such as operations associated with display, telephone calls, data communication, camera operations, and recording operations. The processing component 1402 may include one or more processors 1420 to execute instructions to complete all or part of the steps of the above-described rendering method of the three-dimensional model. In addition, the processing component 1402 may include one or more modules to facilitate the interaction between the processing component 1402 and other components. For example, the processing component 1402 may include a multimedia module to facilitate the interaction between the multimedia component 1408 and the processing component 1402.
[0253] The memory 1404 is configured to store various types of data to support the operation of the electronic device 1400. Examples of these data include instructions for any application or method operating on the electronic device 1400, contact data, phone book data, messages, pictures, videos, etc. The memory 1404 may be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, a magnetic disk, or an optical disk.
[0254] The power component 1406 provides power to various components of the electronic device 1400. The power component 1406 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the electronic device 1400.
[0255] The multimedia component 1408 includes a screen that provides an output interface between the electronic device 1400 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors can sense not only the boundaries of the touch or swipe actions but also detect the duration and pressure associated with the touch or swipe operations. In some embodiments, the multimedia component 1408 includes a front camera and / or a rear camera. When the electronic device 1400 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera can receive external multimedia data. Each of the front camera and the rear camera can be a fixed optical lens system or have a focal length and optical zoom capabilities.
[0256] The audio component 1410 is configured to output and / or input audio signals. For example, the audio component 1410 includes a microphone (MIC) that is configured to receive external audio signals when the electronic device 1400 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals can be further stored in the memory 1404 or transmitted via the communication component 1416. In some embodiments, the audio component 1410 further includes a speaker for outputting audio signals.
[0257] The I / O interface 1412 provides an interface between the processing component 1402 and a peripheral interface module, and the peripheral interface module can be a keyboard, a click wheel, buttons, etc. These buttons can include but are not limited to: a home button, a volume button, a power button, and a lock button.
[0258] The sensor assembly 1414 includes one or more sensors for providing status assessments of various aspects for the electronic device 1400. For example, the sensor assembly 1414 can detect the on / off state of the electronic device 1400, the relative positioning of components, such as the display and keypad of the electronic device 1400. The sensor assembly 1414 can also detect a change in the position of the electronic device 1400 or a component of the electronic device 1400, the presence or absence of user contact with the electronic device 1400, the orientation or acceleration / deceleration of the electronic device 1400, and the temperature change of the electronic device 1400. The sensor assembly 1414 can include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 1414 can also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 1414 can further include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0259] The communication component 1416 is configured to facilitate communication, either wired or wirelessly, between the electronic device 1400 and other devices. The electronic device 1400 can access a wireless network based on communication standards, such as WiFi, a carrier network (such as 2G, 3G, 4G, or 5G), or a combination thereof. In an exemplary embodiment, the communication component 1416 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 1416 further includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0260] In an embodiment of the present disclosure, the electronic device 1400 can be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components for performing the above-described three-dimensional model rendering method.
[0261] In an embodiment of the present disclosure, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 1404 including instructions, and the above instructions can be executed by the processor 1420 of the electronic device 1400 to complete the above-described three-dimensional model rendering method. For example, the non-transitory 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, etc.
[0262] Other embodiments of the present disclosure will be readily apparent to those skilled in the art in view of the specification and practice of the disclosure herein. The present disclosure is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include known common knowledge or conventional technical means in the technical field not disclosed in the present disclosure. The specification and examples are only illustrative, and the true scope and spirit of the present disclosure are pointed out by the following claims.
[0263] It should be understood that the present disclosure is not limited to the exact structures described above and shown in the drawings, and various modifications and changes can be made without departing from its scope. The scope of the present disclosure is only limited by the appended claims.
[0264] It should be noted that, in this document, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. The term "comprising", "including" or any other variation thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising a..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the element.
[0265] The methods and devices provided by the embodiments of the present disclosure have been introduced in detail above. Specific examples are used herein to elaborate on the principles and implementation manners of the present disclosure. The description of the above embodiments is only used to help understand the method and its core idea of the present disclosure; at the same time, for those of ordinary skill in the art, according to the idea of the present disclosure, there will be changes in the specific implementation manners and application scopes. In summary, the content of this specification should not be construed as a limitation to the present disclosure.
Claims
1. A rendering method for a three-dimensional model, characterized in that, Including: Constructing a three-dimensional model and a lighting model of an object; Calculating the diffuse light color information of the object according to a first relationship between the vertex normal in the three-dimensional model and the light source direction in the lighting model; the first relationship NoL_wrap = (dot(N, L)+wrap) / (1.0+wrap); the diffuse light color information diffuse = albedo*max(1.0 - NoL_wrap, 0.0)*(0.5+grayscale); where wrap is the light wrapping intensity in the lighting model, N is the vertex normal, L is the light source direction, dot(N, L) represents the cosine value of the angle between N and L, albedo is the inherent color information of the material of the object, grayscale is the grayscale information of the object, and max is to take the maximum value; Calculating the scattered light color information of the object according to a second relationship between the vertex normal and a preset viewing line-of-sight direction in the lighting model; the second relationship NoV_wrap = (dot(N, V)+wrap) / (1.0+wrap); the scattered light color information scatter: scatter = mix(albedo, bg_color*NoV_wrap+albedo, thickness)*mix(bleeding_color, 1.0, abs(NoV_wrap)); or scatter = mix(bg_color*(1.0 - NoV_wrap)+albedo, albedo, thickness)*mix(1.0, bleeding_color, abs(NoV_wrap)); where V is the preset viewing line-of-sight direction, bg_color is the background color of the texture map of the object seen at the vertex in the three-dimensional model, thickness is the thickness map of the surface of the three-dimensional model, bleeding_color is the overflow light color information in the lighting model, mix is a linear mixing function, and abs is to take the absolute value; Normalizing the sum of the preset viewing line-of-sight direction and the light source direction, and calculating the specular reflection light color information of the object according to a third relationship between the normalized result and the vertex normal; the third relationship NoH_wrap = (dot(N, normalize(V+L))+wrap) / (1.0+wrap); the specular reflection light color information specular = pow((max(NoH_wrap, 0.0), shininess); where normalize is normalization, shininess is the highlight intensity in the lighting model, and pow represents the power function; Rendering the three-dimensional model of the object according to the diffuse light color information, the scattered light color information, and the specular reflection light color information.
2. The method according to claim 1, wherein Before calculating the diffuse light color information according to the first relationship, the method further includes: Constructing a texture map of the object; Calculating the refraction direction after the line of sight enters the object from a vertex in the 3D model; Calculating a first exit position after the line of sight enters the object according to the vertex in the 3D model, the refraction direction, and the background distortion degree in the lighting model; Calculating a second exit position of the first exit position in the coordinate system of the screen where the object is displayed; Converting the second exit position into the coordinate system of the texture space where the background texture map in the texture map is located to obtain a third exit position; Determining the background color of the texture map seen at the vertex in the 3D model according to the third exit position and the color of the background texture map; 3. The method according to claim 2, characterized in that Before calculating the diffuse light color information according to the first relationship and after determining the background color of the texture map seen at the vertex in the 3D model according to the third exit position and the color of the background texture map, the method further includes: Calculating the grayscale information of the object according to the color value of each color channel corresponding to the background color and the preset weight value corresponding to each color channel; 4. The method according to claim 3, wherein Calculating the diffuse light color information of the object according to the first relationship includes: diffuse = albedo * max(1.0 - NoL_wrap, 0.0) * (0.5 + grayscale); where diffuse is the diffuse light color information of the object, NoL_wrap is the first relationship, albedo is the inherent color information of the material of the object, grayscale is the grayscale information of the object, and max represents taking the maximum value; 5. The method according to claim 2, characterized in that Calculating the scattered light color information of the object according to the second relationship includes: Calculating the second relationship according to the light wrapping intensity in the lighting model and the angle between the vertex normal and the preset viewing line of sight direction; Calculating the scattered light color information of the object according to the second relationship, the inherent color of the material of the object in the texture map, the thickness map on the surface of the 3D model, the overflow light color information in the lighting model, and the background color in the texture map; 6. The method according to claim 5, characterized in that, Calculating the scattered light color information of the object according to the second relationship, the inherent color of the material of the object in the texture map, the thickness map on the surface of the 3D model, the overflow light color information in the lighting model, and the background color of the texture map seen at the vertex in the 3D model includes: Calculating the scattered light color of the object according to the second relationship, the background color, the thickness map, and the overflow light color information; Calculating the scattering intensity of the non-edge part of the object and the scattering intensity of the edge part of the object; Calculating the scattering intensity of the scattered light of the object according to the scattering intensity of the non-edge part of the object and the scattering intensity of the edge part of the object; Calculating the scattered light color information according to the scattered light color, the scattering intensity of the scattered light of the object, and the inherent color of the material; 7. The method according to claim 1, characterized in that, Calculating the specular reflection light color information of the object according to a third relationship between the normalization result and the vertex normal includes: specular = pow((max(NoH_wrap, 0.0), shininess); where specular is the specular reflection light color information of the object, NoH_wrap is the third relationship, shininess is the specular intensity in the lighting model, max represents taking the maximum value, and pow represents the power function.
8. The method according to any one of claims 1 to 7, characterized in that, Before rendering the three-dimensional model of the object according to the diffuse reflection light color information, the scattered light color information, and the specular reflection light color information, the method further includes: Calculating the ambient light color information of the object according to the thickness map on the surface of the three-dimensional model and the surface roughness in the lighting model; where rendering the three-dimensional model of the object according to the diffuse reflection light color information, the scattered light color information, and the specular reflection light color information includes: Rendering the three-dimensional model of the object according to the diffuse reflection light color information, the scattered light color information, the specular reflection light color information, and the ambient light color information of the object.
9. A rendering device for a three-dimensional model, characterized in that, Includes: A construction module configured to execute constructing a three-dimensional model of an object and a lighting model; A diffuse reflection calculation module configured to execute calculating the diffuse reflection light color information of the object according to a first relationship between the vertex normal in the three-dimensional model and the light source direction in the lighting model; the first relationship NoL_wrap = (dot(N, L) + wrap) / (1.0 + wrap); the diffuse reflection light color information diffuse = albedo * max(1.0 - NoL_wrap, 0.0) * (0.5 + grayscale); where wrap is the light wrapping intensity in the lighting model, N is the vertex normal, L is the light source direction, dot(N, L) represents calculating the cosine value of the angle between N and L, albedo is the inherent color information of the material of the object, grayscale is the grayscale information of the object, and max is taking the maximum value; The specular light calculation module is configured to calculate the specular light color information of the object according to a second relationship between the vertex normal and a preset viewing line-of-sight direction in the lighting model; the second relationship is NoV_wrap = (dot(N, V) + wrap) / (1.0 + wrap); the specular light color information scatter: scatter = mix(albedo, bg_color * NoV_wrap + albedo, thickness) * mix(bleeding_color, 1.0, abs(NoV_wrap)); or scatter = mix(bg_color * (1.0 - NoV_wrap) + albedo, albedo, thickness) * mix(1.0, bleeding_color, abs(NoV_wrap)); where V is the preset viewing line-of-sight direction, bg_color is the background color of the texture map of the object seen at the vertex in the three-dimensional model, thickness is the thickness map of the surface of the three-dimensional model, bleeding_color is the specular light color information in the lighting model, mix is a linear mixing function, and abs is the absolute value function; The specular reflection calculation module is configured to perform normalization on the sum of the preset viewing line-of-sight direction and the light source direction, and calculate the specular reflection light color information of the object according to a third relationship between the normalized result and the vertex normal; the third relationship is NoH_wrap = (dot(N, normalize(V + L)) + wrap) / (1.0 + wrap); the specular reflection light color information specular = pow((max(NoH_wrap, 0.0), shininess); where normalize is normalization, shininess is the specular intensity in the lighting model, and pow represents the power function; The three-dimensional rendering module is configured to perform rendering on the three-dimensional model of the object according to the diffuse light color information, the specular light color information, and the specular reflection light color information.
10. The device according to claim 9, characterized in that, The construction module is further configured to perform construction of the texture map of the object, and the device further includes: The direction calculation module is configured to calculate the refraction direction after the line of sight enters the object from the vertex in the three-dimensional model. The position calculation module is configured to calculate the first exit position after the line of sight enters the object according to the vertex in the three-dimensional model, the refraction direction, and the background distortion degree in the lighting model; and calculate the second exit position of the first exit position in the coordinate system of the screen on which the object is displayed. The position conversion module is configured to convert the second exit position into the coordinate system of the texture space where the background texture map in the texture map is located to obtain the third exit position; A color determination module, configured to determine the background color of the texture seen by the vertex in the three-dimensional model according to the third emission position and the color of the background texture.
11. The device according to claim 10, characterized in that, The device further includes: A grayscale calculation module, configured to calculate the grayscale information of the object according to the color values of each color channel corresponding to the background color and the preset weight values corresponding to each color channel.
12. The device according to claim 11, characterized in that, The diffuse reflection calculation module is configured to perform the calculation: diffuse = albedo * max(1.0 - NoL_wrap, 0.0) * (0.5 + grayscale); where diffuse is the diffuse light color information of the object, NoL_wrap is the first relationship, albedo is the inherent color information of the material of the object, grayscale is the grayscale information of the object, and max represents taking the maximum value.
13. The device according to claim 10, characterized in that, The scattering light calculation module is configured to calculate the second relationship according to the light wrapping intensity in the lighting model and the angle between the vertex normal and the preset viewing line-of-sight direction; and calculate the scattering light color information of the object according to the second relationship, the inherent color of the material of the object in the texture, the thickness texture on the surface of the three-dimensional model, the overflow light color information in the lighting model, and the background color in the texture.
14. The device according to claim 13, characterized in that, The scattering light calculation module includes: A color calculation sub-module, configured to calculate the scattering light color of the object according to the second relationship, the background color, the thickness texture, and the overflow light color information; An intensity calculation sub-module, configured to calculate the scattering intensity of the non-edge part of the object and the scattering intensity of the edge part of the object; and calculate the scattering intensity of the scattering light of the object according to the scattering intensity of the non-edge part of the object and the scattering intensity of the edge part of the object; An information calculation sub-module, configured to calculate the scattering light color information according to the scattering light color, the scattering intensity of the scattering light of the object, and the inherent color of the material.
15. The device according to claim 9, characterized in that The specular reflection calculation module is configured to perform the calculation: specular = pow((max(NoH_wrap, 0.0), shininess); where specular is the specular reflection light color information of the object, NoH_wrap is the third relationship, shininess is the specular intensity in the lighting model, max represents taking the maximum value, and pow represents the power function.
16. The device according to any one of claims 9 to 15, characterized in that, The device further includes: An ambient light calculation module, configured to calculate the ambient light color information of the object according to the thickness texture on the surface of the three-dimensional model and the surface roughness in the lighting model; wherein, the three-dimensional rendering module is configured to render the three-dimensional model of the object according to the diffuse light color information, the scattering light color information, the specular reflection light color information, and the ambient light color information of the object.
17. An electronic device, characterized in that, Includes: A processor; A memory for storing instructions executable by the processor; Among them, the processor is configured to execute the instructions to implement the three-dimensional model rendering method according to any one of claims 1 to 8.
18. A storage medium, characterized in that, When the instructions in the storage medium are executed by the processor of the electronic device, the electronic device is enabled to execute the three-dimensional model rendering method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Realistic rendering method for face model of layered structure
CN107170036A
Rendering method and device
CN107204029A