Rendering Method and Device for Virtual Model, Storage Medium, and Electronic Device
By obtaining the normal map of the virtual model and rendering based on the normal vector of the vertex, the problem of uneven shadow transition in cartoon rendering is solved, and the uniformity of shadow transition and the improvement of light and shadow effect is achieved.
Patent Information
- Application Number
- CN202111124242.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-24
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2041-09-24
AI Technical Summary
In the prior art, when rendering a virtual model using cartoon rendering method, there is a problem of uneven shadow transitions.
By obtaining the normal map of the virtual model, determining the normal vector of the vertex based on the normal map, and rendering it based on the normal vector of the vertex, including mapping the color value from the first preset interval to the second preset interval to determine the normal vector, generating the normal map, and rendering it in combination with the gradient diffuse reflection coefficient.
The uniformity of shadow transition is achieved, the time and difficulty of normal vector adjustment are reduced, and the light and shadow effect of the virtual model is improved.
Smart Images

Figure CN113936080B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular, to a method and device for rendering a virtual model, a storage medium, and an electronic device. Background Art
[0002] Currently, in some games, a cartoon rendering method is used to render virtual models, which can compress the original natural light and shadow transition into a binary effect. Since the effect of the light and shadow transition depends on the light vector and the normal vector of the model vertex, there is a problem of uneven shadow transition in the rendered virtual model.
[0003] In view of the above problems, no effective solution has been proposed yet. Summary of the Invention
[0004] Embodiments of the present invention provide a method and device for rendering a virtual model, a storage medium, and an electronic device, so as to at least solve the technical problem of uneven shadow transition in the related art when using a cartoon rendering method to render a virtual model.
[0005] According to an aspect of an embodiment of the present invention, a method for rendering a virtual model is provided, including: obtaining a normal map corresponding to the virtual model, where the color in the normal map is used to represent the normal vector of the vertex of the virtual model; determining the normal vector of the vertex based on the normal map; and rendering the virtual model based on the normal vector of the vertex.
[0006] Optionally, determining the normal vector of the vertex based on the normal map includes: obtaining the color value in the normal map; mapping the color value from a first preset interval to a second preset interval to obtain a mapped color value; and determining the normal vector of the vertex based on the mapped color value.
[0007] Optionally, obtaining the normal map corresponding to the virtual model includes: dividing the virtual model into multiple regions and determining the colors of the multiple regions; determining the colors of preset regions on the virtual model, where the preset regions include: the highlight region and the shadow region of the virtual model; and generating a normal map based on the colors of the multiple regions and the colors of the preset regions.
[0008] Optionally, the colors of the multiple regions are determined by the colors in an angular color ring, where different colors in the angular color ring are used to represent different normal directions.
[0009] Optionally, the colors of the preset regions are determined by the colors in an angular color ring, where different colors in the angular color ring are used to represent different normal directions.
[0010] Optionally, the method further includes: creating a semi-circular ring, where different positions of the semi-circular ring correspond to different normal vectors; adding colors to the semi-circular ring based on a preset correspondence to obtain an angular color ring, where the preset correspondence is used to represent the correspondence between different normal vectors and different colors.
[0011] Optionally, rendering the virtual model based on the normal vector of the vertex includes: determining the gradient diffuse reflection coefficient of the virtual model based on the normal vector of the vertex; rendering the virtual model based on the gradient diffuse reflection coefficient.
[0012] Optionally, determining the gradient diffuse reflection coefficient of the virtual model based on the normal vector of the vertex includes: obtaining the light vector corresponding to the virtual model; performing a dot product on the normal vector of the vertex and the light vector to obtain the diffuse reflection coefficient; performing a binarization process on the diffuse reflection coefficient to obtain the gradient diffuse reflection coefficient.
[0013] Optionally, rendering the virtual model based on the gradient diffuse reflection coefficient includes: obtaining the color map of the virtual model; mixing the color map and the gradient diffuse reflection coefficient to obtain the mixed color; rendering the virtual model based on the mixed color.
[0014] According to another aspect of the embodiments of the present invention, there is also provided a rendering device for a virtual model, including: a texture acquisition module for acquiring a normal map corresponding to the virtual model, where the color in the normal map is used to represent the normal vector of the vertex on the virtual model; a normal determination module for determining the normal vector of the vertex based on the normal map; and a character rendering module for rendering the virtual model based on the normal vector of the vertex.
[0015] Optionally, the normal determination module includes: a color acquisition unit for acquiring the color value in the normal map; a color mapping unit for mapping the color value from a first preset interval to a second preset interval to obtain the mapped color value; and a normal determination unit for determining the normal vector of the vertex based on the mapped color value.
[0016] Optionally, the texture acquisition module includes: a first color determination unit for dividing the virtual model into multiple regions and determining the colors of the multiple regions; a second color determination unit for determining the colors of preset regions on the virtual model, where the preset regions include: the highlight region and the shadow region of the virtual model; and a texture generation unit for generating a normal map based on the colors of the multiple regions and the colors of the preset regions.
[0017] Optionally, the first color determination unit is further configured to determine the colors of the multiple regions through the colors in the angular color ring, where different colors in the angular color ring are used to represent different normal directions.
[0018] Optionally, the second color determination unit is further configured to determine the color of a preset area through the colors in the angular color ring, where different colors in the angular color ring are used to represent different normal directions.
[0019] Optionally, the device further includes: a ring creation module, configured to create a semi-circular ring, where different positions of the semi-circular ring correspond to different normal vectors; a color ring creation module, configured to add colors to the semi-circular ring based on a preset correspondence relationship to obtain an angular color ring, where the preset correspondence relationship is used to represent the correspondence relationship between different normal vectors and different colors.
[0020] Optionally, the character rendering module includes: a coefficient determination unit, configured to determine the gradient diffuse coefficient of the virtual model based on the normal vector of the vertex; a character rendering unit, configured to render the virtual model based on the gradient diffuse coefficient.
[0021] Optionally, the coefficient determination unit is further configured to: obtain the light vector corresponding to the virtual model; perform a dot product on the normal vector of the vertex and the light vector to obtain the diffuse coefficient; perform a binarization process on the diffuse coefficient to obtain the gradient diffuse coefficient.
[0022] Optionally, the character rendering unit is further configured to: obtain the color map of the virtual model; mix the color map and the gradient diffuse coefficient to obtain the mixed color; render the virtual model based on the mixed color.
[0023] According to another aspect of the embodiments of the present invention, there is also provided a computer-readable storage medium, where the computer-readable storage medium includes a stored program, and when the program runs, it controls the device where the computer-readable storage medium is located to execute the rendering method of the virtual model in the above embodiments.
[0024] According to another aspect of the embodiments of the present invention, there is also provided an electronic device, including: a processor and a memory, where the processor is configured to run the program stored in the memory, and when the program runs, it executes the rendering method of the virtual model in the above embodiments.
[0025] In the embodiments of the present invention, by obtaining the normal map corresponding to the virtual model, determining the normal vector of the vertex based on the normal map, and then rendering the virtual model based on the normal vector of the vertex, the purpose of cartoon rendering is achieved. Compared with the related art, by changing the color value in the normal map, the purpose of normal adjustment can be achieved without manually adjusting the normal vector of the vertex, and there are no restrictions on the wiring of the virtual model, which speeds up the adjustment time of the normal vector, reduces the time and production difficulty in the model stage, improves the lighting effect of the virtual model, and further solves the technical problem of uneven shadow transition in the related art when using the cartoon rendering method to render the virtual model. Description of the Drawings
[0026] The accompanying drawings described herein are used to provide a further understanding of the present invention, and constitute a part of this application. The schematic embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0027] Figure 1 is a schematic diagram of a cartoon rendering effect according to the prior art;
[0028] Figure 2 is a flowchart of a rendering method for a virtual model according to an embodiment of the present invention;
[0029] Figure 3a is a schematic diagram of an optional default normal vector corresponding color according to an embodiment of the present invention;
[0030] Figure 3b is a schematic diagram of an optional color change after modifying the normal vector according to an embodiment of the present invention;
[0031] Figure 4 is a schematic diagram of an optional color mapping relationship according to an embodiment of the present invention;
[0032] Figure 5 is a schematic diagram of an optional color corresponding to different normal vectors according to an embodiment of the present invention;
[0033] Figure 6a is a schematic diagram of an optional face according to an embodiment of the present invention;
[0034] Figure 6b is a schematic diagram of an optional color of different regions of the face according to an embodiment of the present invention;
[0035] Figure 6c is a schematic diagram of an optional face normal map according to an embodiment of the present invention;
[0036] Figure 7 is a schematic diagram of an optional setting of the color of different regions of the face according to an embodiment of the present invention;
[0037] Figure 8a is a schematic diagram of an optional horizontal angle color ring according to an embodiment of the present invention;
[0038] Figure 8b is a schematic diagram of an optional vertical angle color ring according to an embodiment of the present invention;
[0039] Figure 9 is a schematic diagram of an optional face rendering effect corresponding to the default normal vector according to an embodiment of the present invention;
[0040] Figure 10Schematic diagram of a facial rendering effect corresponding to an adjusted normal vector according to an embodiment of the present invention;
[0041] Figure 11 Schematic diagram of a rendering device for a virtual model according to an embodiment of the present invention. Detailed implementation manners
[0042] In order to enable those skilled in the art to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0043] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above drawings are used to distinguish similar objects, and do not necessarily need to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device including a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0044] First, the technical terms appearing in the embodiments of the present invention are explained as follows:
[0045] 3D model: The mathematical representation of the surface of an object in three dimensions.
[0046] Vertex: A point in 3D space that contains information about the normal vector, texture coordinates, and other mesh attributes.
[0047] Dot product / dot: In mathematics, the dot product or scalar product is an algebraic operation that refers to a binary operation that accepts two vectors over the real numbers R and returns a real-valued scalar.
[0048] Normal: The normal is a vector that describes the surface and curvature of a 3D model. In real-time rendering, normal vectors are required for lighting and shading calculations on 3D models. The normal vector is stored at each vertex (point) of the 3D model, and the vertex defines the position, and the normal vector defines the direction of the surface.
[0049] Shader: A technology used to render graphics. It uses code to customize the graphics card's rendering algorithm and use code to tell the GPU how to draw the vertex or pixel color of the model to achieve the desired effect.
[0050] Stylized / Cell Shading: Relies on real-time lighting but simplifies and flattens lighting feedback to create a more recognizable effect. The shading model is primarily inspired by animation, manga, and cartoons. While there are different styles of cel shading, they all share a common characteristic of reduced surface detail in texturing and shading. Instead of a smooth gradient of brightness from light to shadow, there are single or multiple hard cuts between lights and shadows.
[0051] NPR (Non-Photorealistic Rendering): Non-photorealistic rendering, using shaders to simulate comics, illustrations, sketches, watercolors, oil paintings, and other styles in 3D scenes
[0052] The Lambert diffuse reflection model is an ideal diffuse reflection model where light is reflected in all directions after hitting the surface of an object. The Lambert lighting model is implemented primarily through the dot product of the light vector and the normal vector.
[0053] In order to solve the above problems, the related art provides the following solutions:
[0054] The core principle of the first solution is to manually modify the orientation of each vertex to ensure that the light presents a good lighting effect at different angles. The lighting effect without any normal editing is as follows: Figure 1 As shown on the left, there are many unnatural shadow effects. The lighting effect after manually adjusting the vertex normals of the face is as follows Figure 1 As shown on the right, the normal shadows are very clean.
[0055] However, the above solution has the following disadvantages: special treatment is required for model wiring, and wiring is needed to open the shape of the boundary line at the intersection of light and shadow. If the light and shadow shape is not good, the wiring needs to be readjusted, which places high demands on the art production personnel and the production cycle will be relatively long; the smoothness or sharpness of the light and shadow transition depends on the width, density and normal angle of the boundary line wiring. If adjustment is required, the workload is very large; if the wiring needs to be modified due to model problems, this will cause the vertex ID to change, and the entire normal modification will be messed up; to view the engine effect, the model with the modified normal needs to be re-exported.
[0056] The core principle of the second solution is to draw the illumination information at different angles and then mix them into a shadow threshold map with a linear gradient value from 0 to 1 using the distance field method. Then, shadow effects are generated according to different angles, which can avoid the influence of model wiring on the light and shadow changes and has no special requirements for the model wiring.
[0057] However, the above solutions have the following disadvantages: The production of the light and shadow map is relatively complex and requires pre-calculating (or drawing) the shadow information at multiple light angles; Since the light and shadow map records the light and shadow information in one direction, when the light source direction rotates to the other side, the same map is used for left-right flipping, so only structures that are completely symmetrical left and right can be made; The light and shadow information is only affected by the Y-axis rotation of the light and not by the height of the light.
[0058] According to an embodiment of the present invention, a method for rendering a virtual model is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. And although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.
[0059] Figure 2 is a flowchart of a method for rendering a virtual model according to an embodiment of the present invention. As Figure 2 shown, the method includes the following steps:
[0060] Step S202, obtaining a normal map corresponding to the virtual model, where the color in the normal map is used to represent the normal vector of the vertex of the virtual model.
[0061] The virtual model in the above steps can be a three-dimensional model that needs to be rendered cartoonishly at present. For example, in a game scene, the virtual model can be a character model operated by a player or other models in the background, such as stones, trees, etc., but not limited to this.
[0062] It should be noted that create a sphere and add an EditNormals modifier. As Figure 3a shown, the normals of the model are evenly distributed by default. Among them, each line on the model represents the normal of a point, and the color on the model represents the normal vector. Among them, red corresponds to the X direction, green corresponds to the Y direction, and blue corresponds to the Z direction. Manually edit the normals through EditNormals, select some normals and adjust them to the Z direction. As Figure 3b shown, adjust the circled normal vector to the Z direction, and the color on the model becomes blue. At this time, the RGB value is (0, 0, 1). If it is adjusted to the negative Z direction, the RGB value is negative. Among them, the RGB value corresponding to the negative Z direction is (0, 0, -1), and the color on the model becomes black.
[0063] As can be seen from the above analysis, the normal vector can be represented by RGB values. Therefore, in the embodiments of the present invention, the normal vector can be represented by drawing a texture map, so that the light and shadow transition of the virtual model can be controlled by color filtering. The wider the transition range between two colors, the softer the light and shadow transition.
[0064] Step S204, determining the normal vector of the vertex based on the normal map.
[0065] In the embodiments of the present invention, since different colors of the normal map can represent different normal vectors, after the obtained normal map, the color value in the normal map can be directly read as the normal vector of the vertex.
[0066] Step S206, rendering the virtual model based on the normal vector of the vertex.
[0067] In the embodiments of the present invention, the virtual model can be rendered cartoonishly based on the determined normal vector, and the rendered virtual model is displayed in the interaction interface for the user to view.
[0068] Through the above steps, by obtaining the normal map corresponding to the virtual model, determining the normal vector of the vertex based on the normal map, and then rendering the virtual model based on the normal vector of the vertex, the purpose of cartoon rendering is achieved. Compared with the related art, by changing the color value in the normal map, the purpose of normal adjustment can be achieved without manually adjusting the normal vector of the vertex, and there is no restriction on the virtual model wiring, which speeds up the adjustment time of the normal vector, reduces the time and production difficulty in the model stage, improves the light and shadow effect of the virtual model, and further solves the technical problem of uneven shadow transition in the related art when using the cartoon rendering method to render the virtual model.
[0069] Optionally, determining the normal vector of the vertex based on the normal map includes: obtaining the color value in the normal map; mapping the color value from the first preset interval to the second preset interval to obtain the mapped color value; determining the normal vector of the vertex based on the mapped color value.
[0070] The first preset interval in the above steps can be the value range of the color values of the RGB three channels in the normal map. For example, the first preset interval can be (0,1); the second preset interval can be the value range of the color values of the RGB three channels corresponding to the normal vector. For example, the second preset interval can be (0,1).
[0071] It should be noted that the RGB three channels of a common 8-bit image can only store values from 0 to 1 and cannot store negative values. Therefore, after the normal map is drawn, the colors in the range of (0, 1) in the normal map can be mapped to the range of (-1, 1). As Figure 4 shown, the value of 0.5 in the normal map can be mapped to 0. The Shader code is as follows: nDirP = e_p * 2 - 1, where e_p is the value in the normal map and nDirP is the normal vector. Through the above correspondence relationship, the color values in different directions as shown in Figure 5 can be obtained, which can be specifically divided into the color values in different directions in the vertical direction and the color values in different directions in the horizontal direction.
[0072] Optionally, obtaining the normal map corresponding to the virtual model includes: dividing the virtual model into multiple regions and determining the colors of the multiple regions; determining the colors of the preset regions on the virtual model, where the preset regions include: the highlight region and the shadow region of the virtual model; generating a normal map based on the colors of the multiple regions and the colors of the preset regions.
[0073] In the embodiments of the present invention, different regions of the virtual model face different directions. Therefore, the virtual model can be divided into different regions according to different directions, and different colors can be drawn for different regions. In addition, in order to make the lighting effect of the rendered virtual model better, it is necessary to draw the highlight region and the shadow region on the virtual model. Finally, by summarizing the colors of the multiple regions, the colors of the highlight region and the colors of the shadow region, the final normal map can be obtained.
[0074] For example, taking the drawing of the facial normal map as an example, for the face as shown in Figure 6a , it can be roughly divided into 6 directions, and each region is drawn, as shown in Figure 6b . Then draw the triangular highlight region on the cheeks, the shadows under the nose, the chin, the lips, and the shadow region at the inner corner of the eye socket. The final normal map obtained is as shown in Figure 6c .
[0075] Optionally, the colors of the multiple regions are determined by the colors in the angular color ring, where different colors in the angular color ring are used to represent different normal directions.
[0076] In the embodiments of the invention, the Sbustance Painter software can be used to directly draw the normal color based on the model.
[0077] In an embodiment of the invention, first, an Emissive channel can be added under the Texture set - Channels panel of Substance Painter (because the hand - painted Normal defined in the Shader is drawn on the Emissive channel). As Figure 7 shown, the face is roughly divided into 6 directions, and colors are selected from the corresponding angular color ring below for drawing. Then, an empty layer is added and named Face to draw the face normal map.
[0078] Optionally, the color of a preset area is determined by the color in the angular color ring, where different colors in the angular color ring are used to represent different normal directions.
[0079] In an embodiment of the invention, first, another empty layer is added and named Detail, and then colors are selected from the angular color ring to draw the highlight area of the cheek triangle, the shadows under the nose, chin, and lips, and the shadow area at the inner corner of the eye socket.
[0080] Optionally, the method further includes: creating a semi - circle ring, where different positions of the semi - circle ring correspond to different normal vectors; adding colors to the semi - circle ring based on a preset correspondence relationship to obtain an angular color ring, where the preset correspondence relationship is used to represent the correspondence relationship between different normal vectors and different colors.
[0081] In an embodiment of the present invention, first, a semi - circle ring in the horizontal direction is created with the origin of the three - dimensional coordinate as the center, and the semi - circle ring is created on the plane of Y = 0, where different positions on the semi - circle ring correspond to different X and Z coordinates; then, a semi - circle ring in the vertical direction is created with the origin of the three - dimensional coordinate as the center, and the semi - circle ring is created on the plane of X = 0, where different positions on the semi - circle ring correspond to different Y and Z coordinates. Then, based on the correspondence relationship between different colors and normal vectors, a Gradient Ramp is added to the material of the created semi - circle ring and the corresponding colors are set, as Figure 8a and Figure 8b shown.
[0082] Optionally, rendering the virtual model based on the normal vector of the vertex includes: determining the gradient diffuse coefficient of the virtual model based on the normal vector of the vertex; rendering the virtual model based on the gradient diffuse coefficient.
[0083] In an embodiment of the present invention, for the purpose of achieving cartoon rendering, the normal vector of the vertex can be determined based on the normal map drawn by the user, and then the gradient diffuse coefficient can be determined based on the normal vector determined by the user, that is, calculating Lambert illumination, and then performing binarization processing on the Lambert illumination to obtain a value of either 0 or 1, that is, the above - mentioned gradient diffuse coefficient stepNdotL. Finally, rendering is performed based on the gradient diffuse coefficient stepNdotL.
[0084] Optionally, determining the gradient diffuse reflection coefficient of the virtual model based on the normal vector of the vertex includes: obtaining the illumination vector corresponding to the virtual model; performing dot product on the normal vector of the vertex and the illumination vector to obtain the diffuse reflection coefficient; and binarizing the diffuse reflection coefficient to obtain the gradient diffuse reflection coefficient.
[0085] In an optional embodiment, the current lighting vector in the game scene can be obtained, and then the normal vector and the lighting vector are dot-producted to obtain Lambert lighting NdotL. The shader code is as follows: NdotL = dot(nDirP, lDir), where nDirP represents the normal vector determined based on the user-drawn normal map, and lDir represents the lighting vector. Alternatively, nDir can represent the model's own normal vector. Binarization can be performed using the step(x, y) function. The shader code is as follows: stepNdotL = step(0.5, NdotL).
[0086] For example, still taking facial normal map drawing as an example, for Figure 6a When the Shader code is as follows: NdotL = dot (nDir, lDir), the final rendered face is as follows Figure 9 As shown in the figure, the shadow effect has problems because the model's default normal vector is used. When the Shader code is as follows: NdotL=dot(nDirP,lDir), the final rendered face is as follows Figure 10 As shown, since the normal vector is determined based on the normal map drawn by the user, there is no problem with the shadow effect.
[0087] Optionally, rendering the virtual model based on the gradient diffuse reflection coefficient includes: obtaining a color map of the virtual model; mixing the color map and the gradient diffuse reflection coefficient to obtain a mixed color; and rendering the virtual model based on the mixed color.
[0088] The color map in the above steps can be the base color of the virtual model without the superimposed light and shadow effects.
[0089] In an embodiment of the present invention, in order to achieve cartoon rendering, it is necessary to mix and superimpose the gradient diffuse reflection coefficient stepNdotL, the color map c_p, the light color col and the shadow color shadow_col to obtain the mixed color final, and then the virtual model can be rendered based on the mixed color. The final Shader code is as follows: final = mix(shadow_col*c_p,col*c_p,stepNdotL).
[0090] Through the above embodiments of the present invention, the adjustment of the light and shadow effects of the cartoon face can be completed in Substance Painter, which avoids adjusting the vertex normal vectors one by one in DCC tools and has no restrictions on the model wiring. This can greatly reduce the time and production difficulty in the model stage and can also speed up the adjustment time of the normal vectors. By writing a Shader in Substance Painter, the vertex normal vector map can be drawn in Substance Painter in real time and the light and shadow effects of the adjusted normals can be directly viewed, so as to make real-time adjustments until the effect is satisfactory and then imported into the engine. This greatly reduces the frequency of switching back and forth between DCC software and the engine.
[0091] According to an embodiment of the present invention, there is also provided a rendering device for a virtual model. This device can execute the rendering method of the virtual model in the above embodiment. The specific implementation scheme and application scenario are the same as those in the above embodiment and will not be elaborated here. Moreover, this device can be built into an electronic device.
[0092] Figure 11 is a schematic diagram of a rendering device for a virtual model according to an embodiment of the present invention, as Figure 11 shown. This device includes:
[0093] A texture map acquisition module 112, configured to acquire a normal map corresponding to the virtual model, where the color in the normal map is used to represent the normal vector of the vertex on the virtual model.
[0094] A normal determination module 114, configured to determine the normal vector of the vertex based on the normal map.
[0095] A character rendering module 116, configured to render the virtual model based on the normal vector of the vertex.
[0096] Optionally, the normal determination module includes: a color acquisition unit, configured to acquire the color value in the normal map; a color mapping unit, configured to map the color value from a first preset interval to a second preset interval to obtain the mapped color value; a normal determination unit, configured to determine the normal vector of the vertex based on the mapped color value.
[0097] Optionally, the texture map acquisition module includes: a first color determination unit, configured to divide the virtual model into multiple regions and determine the colors of the multiple regions; a second color determination unit, configured to determine the colors of preset regions on the virtual model, where the preset regions include: the highlight region and the shadow region of the virtual model; a texture map generation unit, configured to generate a normal map based on the colors of the multiple regions and the colors of the preset regions.
[0098] Optionally, the first color determination unit is further configured to determine the colors of multiple regions through the colors in the angular color ring, where different colors in the angular color ring are used to represent different normal directions.
[0099] Optionally, the second color determination unit is further configured to determine the color of a preset region through the colors in the angular color ring, where different colors in the angular color ring are used to represent different normal directions.
[0100] Optionally, the apparatus further includes: a circular ring creation module, configured to create a semi-circular ring, where different positions of the semi-circular ring correspond to different normal vectors; a color ring creation module, configured to add colors to the semi-circular ring based on a preset correspondence relationship to obtain an angular color ring, where the preset correspondence relationship is used to represent the correspondence relationship between different normal vectors and different colors.
[0101] Optionally, the character rendering module includes: a coefficient determination unit, configured to determine the gradient diffuse coefficient of the virtual model based on the normal vector of the vertex; a character rendering unit, configured to render the virtual model based on the gradient diffuse coefficient.
[0102] Optionally, the coefficient determination unit is further configured to: obtain the light vector corresponding to the virtual model; perform a dot product on the normal vector of the vertex and the light vector to obtain the diffuse coefficient; perform a binarization process on the diffuse coefficient to obtain the gradient diffuse coefficient.
[0103] Optionally, the character rendering unit is further configured to: obtain the color map of the virtual model; mix the color map and the gradient diffuse coefficient to obtain the mixed color; render the virtual model based on the mixed color.
[0104] According to an embodiment of the present invention, there is also provided a computer-readable storage medium, where the computer-readable storage medium includes a stored program, and when the program runs, it controls the device where the computer-readable storage medium is located to execute the rendering method of the virtual model in the above embodiment.
[0105] According to an embodiment of the present invention, there is also provided an electronic device, including: a processor and a memory, where the processor is configured to run the program stored in the memory, and when the program runs, it executes the rendering method of the virtual model in the above embodiment.
[0106] In the above embodiments of the present invention, the descriptions of the respective embodiments have their own focuses. For the parts not detailed in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.
[0107] In several embodiments provided in the present application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are merely illustrative. For example, the division of the units can be a logical function division. In actual implementation, there can be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces. The indirect couplings or communication connections of units or modules can be in electrical or other forms.
[0108] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place or distributed to multiple units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0109] In addition, in each embodiment of the present invention, the functional units can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.
[0110] If the above-mentioned integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in each embodiment of the present invention. The foregoing storage medium includes: various media such as USB flash drives, read-only memories (ROMs), random access memories (RAMs), mobile hard disks, magnetic disks, or optical discs that can store program codes.
[0111] The above is only the preferred embodiment of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and refinements can be made, and these improvements and refinements should also be regarded as the protection scope of the present invention.
Claims
1. A rendering method for a virtual model, the method comprising: Obtaining a normal map corresponding to the virtual model, wherein the color in the normal map is used to represent the normal vector of the vertex of the virtual model; Determining the normal vector of the vertex based on the normal map; Rendering the virtual model based on the normal vector of the vertex; Wherein, obtaining the normal map corresponding to the virtual model includes: Dividing the virtual model into multiple regions and determining the colors of the multiple regions; Determining the colors of preset regions on the virtual model, wherein the preset regions include: the highlight region and the shadow region of the virtual model; Generating the normal map based on the colors of the multiple regions and the colors of the preset regions.
2. The method according to claim 1, wherein Determining the normal vector of the vertex based on the normal map includes: Obtaining the color value in the normal map; Mapping the color value from a first preset interval to a second preset interval to obtain a mapped color value; Determining the normal vector of the vertex based on the mapped color value.
3. The method according to claim 1, wherein Determining the colors of the multiple regions through the colors in the angular color ring, wherein different colors in the angular color ring are used to represent different normal directions.
4. The method according to claim 1, wherein Determining the colors of the preset regions through the colors in the angular color ring, wherein different colors in the angular color ring are used to represent different normal directions.
5. The method according to claim 3 or 4, characterized in that, The method further comprises: Creating a semi-circular ring, wherein different positions of the semi-circular ring correspond to different normal vectors; Adding colors to the semi-circular ring based on a preset correspondence relationship to obtain the angular color ring, wherein the preset correspondence relationship is used to represent the correspondence relationship between different normal vectors and different colors.
6. The method according to any one of claims 1 to 4, characterized in that Rendering the virtual model based on the normal vector of the vertex includes: Determining the gradient diffuse reflection coefficient of the virtual model based on the normal vector of the vertex; Rendering the virtual model based on the gradient diffuse reflection coefficient.
7. The method according to claim 6, characterized in that Determining the gradient diffuse reflection coefficient of the virtual model based on the normal vector of the vertex includes: Obtaining the illumination vector corresponding to the virtual model; Performing a dot product on the normal vector of the vertex and the illumination vector to obtain a diffuse reflection coefficient; Performing a binarization process on the diffuse reflection coefficient to obtain the gradient diffuse reflection coefficient.
8. The method according to claim 6, characterized in that, Rendering the virtual model based on the gradient diffuse reflection coefficient includes: Obtaining the color map of the virtual model; Mixing the color map and the gradient diffuse reflection coefficient to obtain a mixed color; Rendering the virtual model based on the mixed color.
9. A rendering device for a virtual model, characterized in that, The device comprises: A texture map acquisition module, configured to acquire a normal map corresponding to a virtual model, wherein the color in the normal map is used to represent the normal vector of the vertex on the virtual model; A normal determination module, configured to determine the normal vector of the vertex based on the normal map; A character rendering module, configured to render the virtual model based on the normal vector of the vertex; Among them, the texture map acquisition module is further configured to: divide the virtual model into multiple regions and determine the colors of the multiple regions; determine the colors of preset regions on the virtual model, where the preset regions include: the highlight region and the shadow region of the virtual model; generate the normal map based on the colors of the multiple regions and the colors of the preset regions.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, where, when the program runs, it controls the device where the computer-readable storage medium is located to execute the virtual model rendering method according to any one of claims 1 to 8.
11. An electronic device, characterized in that, Including: A processor and a memory, the processor is configured to run the program stored in the memory, where, when the program runs, it executes the virtual model rendering method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Virtual object eyeball simulation method and device and storage medium
CN109903374A
Model rendering method and device, computer readable medium and electronic equipment
CN111210497A