Rendering method and device, electronic equipment and readable storage medium
By mapping the vertex normals of the virtual object model to the texture space, the generation of stroke texture maps and tangent space conversion is solved, and the workload and resource overhead of rendering the hand-painted style brushstroke effect in the game engine is solved, achieving efficient brushstroke effect rendering.
Patent Information
- Application Number
- CN202411692831.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-22
- Publication Date
- 2025-04-11
AI Technical Summary
The hand-painted brushstroke effect of the virtual object model increases workload and resource overhead when rendering game graphics in the game engine.
By obtaining the vertex normal of the virtual object model, mapping it from the model space to the texture space, extracting the color information in the normal texture map and smearing it, generating a stroke texture map, and converting it to a tangent space for rendering the virtual object model.
The hand-drawn style stroke effect of rendering virtual object models in the game engine is realized without modifying or increasing the number of grids of virtual object models, avoiding the increase in rendering workload and resource overhead.
Smart Images

Figure CN119810291A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer graphics technology, and in particular to a rendering method, device, electronic device and readable storage medium. Background Art
[0002] In the field of game graphics rendering, in order to enhance the artistic sense and realism of the game screen, the brushstroke effect of hand-painting or painting is usually imitated. For example, the normal of the virtual object model can be fine-tuned to simulate the surface structure of the brushstroke and increase the stylization of the virtual object model.
[0003] At present, the hand-painted style brush stroke effect of the virtual object model is achieved by scattering brush stroke morphological patches on the surface of the virtual object model. The specific implementation process is: scattering coordinate points on the surface of the virtual object model, and determining the position of the brush stroke morphological patches by the coordinate points. Generate brush stroke morphological patches perpendicular to the surface normal at the scattered coordinate points. Use Gaussian noise function to twist the angle of the brush stroke morphological patch perpendicular to the surface normal, so that the angle of the brush stroke morphological patch perpendicular to the surface normal is random.
[0004] However, when producing the hand-painted brush stroke effect of the virtual object model, the mesh of the virtual object model is modified, the number of meshes of the virtual object model is increased, the workload of rendering game graphics in the game engine is increased, and the overhead of various resources in the game engine is high. Summary of the invention
[0005] The present application provides a rendering method, device, electronic device and readable storage medium, which solves the problem that when the hand-painted brush stroke effect of a virtual object model is used to render game graphics in a game engine, the workload increases, resulting in high overhead of various resources.
[0006] In a first aspect, an embodiment of the present application provides a rendering method, the method comprising:
[0007] Get the virtual object model;
[0008] Mapping the vertex normals of the virtual object model from the model space to the texture space to obtain a normal texture map;
[0009] Extracting color information of a first pixel in the normal texture map, and applying the color information of the first pixel to the normal texture map to obtain a first normal brushstroke texture map;
[0010] Converting the first normal stroke texture map to a tangent space to obtain a second normal stroke texture map;
[0011] The virtual object model is rendered using the second normal brush stroke texture map in the tangent space to obtain a virtual object model with a brush stroke effect.
[0012] In some embodiments, applying the color information of the first pixel on the normal texture map includes:
[0013] Determine, for the first pixel point, a corresponding smearing direction and a second pixel point in the smearing direction;
[0014] In the smearing direction, the color information of the second pixel is updated by using the color information of the first pixel to obtain the updated color information of the second pixel.
[0015] In some embodiments, the updating the color information of the second pixel point by using the color information of the first pixel point includes:
[0016] The color information of the second pixel is overwritten with the color information of the first pixel to update the color information of the second pixel.
[0017] In some embodiments, the updating the color information of the second pixel point by using the color information of the first pixel point includes:
[0018] The color information of the first pixel is superimposed with the color information of the second pixel to obtain updated color information of the second pixel.
[0019] In some embodiments, converting the first normal stroke texture map to a tangent space to obtain a second normal stroke texture map includes:
[0020] Construct TBN matrix;
[0021] The first normal stroke texture map in the model space is multiplied by the inverse matrix of the TBN matrix to obtain a second normal stroke texture map in the tangent space.
[0022] In some embodiments, constructing a TBN matrix includes:
[0023] Obtaining a tangent line of the virtual object model in the model space;
[0024] Cross-product the tangent of the virtual object model in the model space with the vertex normal to obtain a secondary tangent of the virtual object model in the model space;
[0025] A TBN matrix is constructed based on the vertex normals, the tangents and the bitangents of the virtual object model in the model space.
[0026] In some embodiments, rendering the virtual object model using the second normal brush stroke texture map in the tangent space to obtain the virtual object model with a brush stroke effect includes:
[0027] determining a lighting effect of the virtual object model based on the second normal stroke texture map in the tangent space;
[0028] Based on the lighting effect of the virtual object model, the virtual object model is rendered to obtain a virtual object model with a brushstroke effect.
[0029] In some embodiments, mapping the vertex normals of the virtual object model from the model space to the texture space to obtain a normal texture map includes:
[0030] Normalizing the vertex normals of the virtual object model to obtain normalized vertex normals;
[0031] The normalized vertex normals are mapped from the model space to the texture space to obtain a normal texture map.
[0032] In a second aspect, an embodiment of the present application further provides a rendering device, the device comprising:
[0033] An acquisition module, used for acquiring a virtual object model;
[0034] A mapping module, used for mapping the vertex normals of the virtual object model from the model space to the texture space to obtain a normal texture map;
[0035] A smearing module, used for extracting color information of a first pixel in the normal texture map, and smearing the normal texture map with the color information of the first pixel to obtain a first normal brushstroke texture map;
[0036] A conversion module, used for converting the first normal stroke texture map into a tangent space to obtain a second normal stroke texture map;
[0037] A rendering module is used to render the virtual object model using the second normal brush stroke texture map in the tangent space to obtain a virtual object model with a brush stroke effect.
[0038] In a third aspect, an embodiment of the present application further provides an electronic device, including:
[0039] Processor; and
[0040] The memory is used to store a data processing program. After the electronic device is powered on and the program is run by the processor, the following steps are performed:
[0041] Get the virtual object model;
[0042] Mapping the vertex normals of the virtual object model from the model space to the texture space to obtain a normal texture map;
[0043] Extracting color information of a first pixel in the normal texture map, and applying the color information of the first pixel to the normal texture map to obtain a first normal brushstroke texture map;
[0044] Converting the first normal stroke texture map to a tangent space to obtain a second normal stroke texture map;
[0045] The virtual object model is rendered using the second normal brush stroke texture map in the tangent space to obtain a virtual object model with a brush stroke effect.
[0046] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium storing a data processing program, which is executed by a processor to perform the following steps:
[0047] Get the virtual object model;
[0048] Mapping the vertex normals of the virtual object model from the model space to the texture space to obtain a normal texture map;
[0049] Extracting color information of a first pixel in the normal texture map, and applying the color information of the first pixel to the normal texture map to obtain a first normal brushstroke texture map;
[0050] Converting the first normal stroke texture map to a tangent space to obtain a second normal stroke texture map;
[0051] The virtual object model is rendered using the second normal brush stroke texture map in the tangent space to obtain a virtual object model with a brush stroke effect.
[0052] Compared with the prior art, this application has the following advantages:
[0053] The rendering method provided by the embodiment of the present application obtains a virtual object model; maps the vertex normal of the virtual object model from the model space to the texture space to obtain a normal texture map; extracts the color information of the first pixel in the normal texture map, and uses the color information of the first pixel to smear on the normal texture map to obtain a first normal brushstroke texture map; that is, the color information of other pixels on the normal texture map except the first pixel is changed with the color information of the first pixel. The changed color information of other pixels on the normal texture map except the first pixel is converted into corresponding normal information, and the direction of the normal information after the conversion is changed relative to the original normal information. That is, the drawing of the hand-painted style brushstroke texture is achieved by changing the normal information. The first normal brushstroke texture map is converted to the tangent space to obtain the second normal brushstroke texture map; the virtual object model is rendered using the second normal brushstroke texture map in the tangent space to obtain a virtual object model with a brushstroke effect. When obtaining the brush stroke effect of the virtual object model, this method does not need to modify the mesh of the virtual object model, and does not need to increase the number of meshes of the virtual object model. Therefore, when rendering in the game engine, the rendering workload does not increase, and the overhead of various resources will not increase. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 is a schematic diagram of a virtual object model provided in an embodiment of the present application;
[0055] Figure 2 is a schematic diagram of the brush stroke effect of the virtual object model produced in an embodiment of the present application;
[0056] Figure 3 is a schematic diagram of a virtual object model with a brushstroke effect rendered using vertex normals provided in an embodiment of the present application;
[0057] Figure 4 It is a flowchart of a rendering method provided in an embodiment of the present application;
[0058] Figure 5 is a schematic diagram of another virtual object model provided in an embodiment of the present application;
[0059] Figure 6 It is a schematic diagram of mapping a vertex normal from a model space to a texture space provided by an embodiment of the present application;
[0060] Figure 7 is a schematic diagram of a normal texture map provided in an embodiment of the present application;
[0061] Figure 8 is a schematic diagram of vertex normals of a virtual object model provided in an embodiment of the present application;
[0062] Fig. 9 is a schematic diagram of a first normal stroke texture map provided in an embodiment of the present application;
[0063] Fig.10 is a schematic diagram of a second normal stroke texture map provided in an embodiment of the present application;
[0064] Fig.11 is a schematic diagram of a rendering result of a virtual object model provided in an embodiment of the present application;
[0065] Fig.12 is a structural block diagram of a rendering device provided in an embodiment of the present application;
[0066] Fig.13 It is a structural block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0067] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0068] It should be noted that the terms "first", "second", "third", etc. in the claims, description and drawings of the present application are used to distinguish similar objects and are not used to describe a specific order or sequence. The data used in this way are interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including", "having" and their variants are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0069] To facilitate understanding, the technical terms that may be involved in the embodiments of the present application are first briefly introduced.
[0070] (1) The virtual object model is a mesh model that uses a series of meshes (polygons, such as triangles) of similar size and shape to approximate a three-dimensional object.
[0071] (2) Model space: A coordinate system shared by all vertices of a virtual object model. The origin of the model space coordinate system is the origin of the model. The directions and unit lengths of the x, y, and z axis vectors are based on the model creation standard.
[0072] (3) Vertex: The basic building block of the mesh of a virtual object model. Each vertex represents a three-dimensional coordinate point in the model space.
[0073] (4) Vertex normal: It is a vector perpendicular to the vertex of the mesh, pointing to the outside or inside of the surface of the virtual object model.
[0074] (5) Texture space: Also known as "UV texture space", it is a 2D space, that is, a two-dimensional texture coordinate with vertex component information of polygons and subdivision surface meshes, using the letters u and v to indicate the x-axis and y-axis in the two-dimensional space.
[0075] (6) Tangent space: A local coordinate system based on the vertex normal as the Z axis and the tangent vector, sub-tangent vector or sub-normal vector of the surface where the vertex is located. The tangent vector, sub-tangent vector or sub-normal vector and normal vector are mutually orthogonal and together constitute a local coordinate system. The normal vectors in the normal texture are all defined in the tangent space, and the vertex normal always points to the z-axis (0, 0, 1). The tangent space can be understood as the u, v directions of the texture space and the normal vector n. These three directions constitute the tangent space.
[0076] (7) Interpolation: The intermediate value between two discrete values is calculated using some algorithm.
[0077] (8) Normalization: It is a technique used to scale data to a specific range, aiming to eliminate the impact of different dimensions in the data set, so that different indicators are comparable and have unified dimensions. In the normalization process, the data is mapped to a new interval or distribution by linear transformation. Specifically, the goal of normalization is to convert the original data into values between [0, 1] or [-1, 1]. For vectors, normalization is to make the sum of the squares of all elements of the vector equal to 1, that is, to convert the vector into a unit vector.
[0078] In the field of game graphics rendering, in order to enhance the artistic sense and realism of the game screen, the brushstroke effect of hand-painting or painting is usually imitated. For example, the normal of the virtual object model can be fine-tuned to simulate the surface structure of the brushstroke and increase the stylization of the virtual object model.
[0079] At present, the hand-painted style brush stroke effect of the virtual object model is achieved by scattering brush stroke patches on the surface of the virtual object model. The specific implementation process is: scatter coordinate points on the surface of the virtual object model, and determine the position of the brush stroke patch by the coordinate points. Generate a brush stroke patch perpendicular to the surface normal at the scattered coordinate points. Use a Gaussian noise function to twist the angle of the brush stroke patch perpendicular to the surface normal, so that the angle of the brush stroke patch perpendicular to the surface normal is random. Figure 1 FIG. 1 is a schematic diagram of a virtual object model provided in an embodiment of the present application. Figure 1 The virtual object model shown in the figure creates a hand-painted style brushstroke effect, which can be Figure 1 The virtual object model shown in the figure has scattered coordinate points on its surface, and the position of the brush stroke patch is determined by the coordinate points. The brush stroke patch perpendicular to the surface normal is generated at the scattered coordinate points. The angle of the brush stroke patch perpendicular to the surface normal is twisted using a Gaussian noise function, so that the angle of the brush stroke patch perpendicular to the surface normal is random. Figure 2 As shown, it is a schematic diagram of the brushstroke effect of the virtual object model produced by the embodiment of the present application. Figure 1 One of the brush stroke effects produced by the virtual object model shown is as follows Figure 2 shown.
[0080] However, when producing the brush stroke effect of the normal of the virtual object model, the mesh of the virtual object model is modified, the number of meshes of the virtual object model is increased, the workload of rendering game graphics in the game engine is increased, and the overhead of various resources in the game engine is high.
[0081] In order to solve the above problems in the related art, the embodiment of the present application provides a rendering method. The execution subject of the solution provided by the present application can be an electronic device, which can be a desktop computer, a laptop computer, a mobile device, a smart watch, a smart TV, a tablet computer, a server, etc., or other devices with data processing and display functions.
[0082] The rendering method provided in the embodiment of the present application can be used to produce hand-painted style brush stroke effects for virtual object models. In the game engine, when the hand-painted style brush stroke effects for the virtual object model are rendered graphically, the rendering workload and the overhead of various resources will not be increased.
[0083] The rendering method provided in the embodiment of the present application uses the vertex normals of the virtual object model to achieve the following Figure 3 The virtual object model with brushstroke effect shown in FIG. That is, by changing the vertex normal of the virtual object model, the concave and convex performance on the surface of the virtual object model changes, thereby achieving the characteristic of brushstroke effect. Figure 3, which is a schematic diagram of a virtual object model with a brush stroke effect rendered using vertex normals provided in an embodiment of the present application.
[0084] The rendering method, device, electronic device, and computer-readable storage medium described in the present application are further described in detail below in conjunction with specific embodiments and drawings.
[0085] like Figure 4 As shown, it is a flowchart of a rendering method provided in an embodiment of the present application. A rendering method provided in an embodiment of the present application includes the following steps S401 to S405.
[0086] Step S401: obtaining a virtual object model;
[0087] In the embodiment of the present application, the virtual object model is a role model that the player can control to move in the game, and the role model can be a model used to represent the player's image, and the model can be a three-dimensional virtual model. The virtual object includes but is not limited to at least one of a virtual person, a virtual animal, a virtual machine, a virtual building, and a virtual plant.
[0088] You can use 3D modeling software to create virtual object models. For example, you can use 3DSmax to create a corresponding virtual object model for a character, such as Figure 5 FIG. 1 is a schematic diagram of another virtual object model provided in an embodiment of the present application. After the virtual object model is made, the made virtual object model can be displayed to the user through a graphical user interface.
[0089] Step S402: Mapping the vertex normals of the virtual object model from the model space to the texture space to obtain a normal texture map;
[0090] In an embodiment of the present application, after the virtual object model is made, the vertex normals of the virtual object model are obtained. When obtaining the vertex normals of the virtual object model, the vertex normals of each vertex can be directly calculated in the 3D modeling software. For example, after the virtual object model is made in Blender, all vertices of the virtual object model can be traversed to obtain the vertex normals of each vertex. When obtaining the vertex normals of the virtual object model, the vertex normals of the virtual object model can be determined with the coordinate origin of the model space as the center. After obtaining the vertex normals of each vertex, the vertex normals of each vertex can be recorded as corresponding vectors.
[0091] After obtaining the vertex normals of the virtual object model, the vertex normals of the virtual object model are mapped from the model space to the texture space, that is, the vectors of the vertex normals are converted into color values corresponding to the vertex normals, and the converted color values are stored in the color channel of the texture space.
[0092] For example, Figure 6 As shown, a schematic diagram of mapping a vertex normal from a model space to a texture space provided by an embodiment of the present application is provided. Assuming that the vector of the vertex normal in the model space is (Nx, Ny, Nz), when mapping it to the texture space, the Nx value of the vertex normal can be mapped to the blue channel, the Ny value of the vertex normal can be mapped to the red channel, and the Nz value of the vertex normal can be mapped to the green channel. After mapping, the color value (R, G, B) corresponding to the vector of the vertex normal in the texture space is obtained.
[0093] Through the above method, Figure 5 All vertex normals of the virtual object model shown are mapped to corresponding color values, and all color values are stored in the color channel of the texture space. The obtained normal texture map is as follows Figure 7 As shown, Figure 7 A schematic diagram of a normal texture map provided in an embodiment of the present application. Figure 7 The normal texture map shown is overlaid on Figure 5 On the virtual object model shown in Figure 8 The vertex normals of a virtual object model are shown as Figure 8 , which is a schematic diagram of vertex normals of a virtual object model provided in an embodiment of the present application.
[0094] It should be noted that when mapping the vertex normals of the virtual object model from the model space to the texture space, interpolation calculations can be used between all vertex normals of each mesh to obtain the interpolation between two adjacent vertex normals, so that the normals of two adjacent vertices in each mesh can be smoothly transitioned. That is, an intermediate value can be inserted between the two adjacent vertex normals of each mesh through interpolation calculations, thereby obtaining the normal information at a certain coordinate between the two vertices. All vertices of the mesh and the normal information at a certain coordinate between two adjacent vertices are mapped to corresponding color values, and the mapped color values are stored in the color channel of the texture space to obtain a normal texture map.
[0095] In an optional embodiment, when mapping the vertex normals of the virtual object model from the model space to the texture space, the normal corresponding to each point in each mesh can be determined using methods such as barycentric coordinate interpolation or bilinear interpolation. Taking a triangle as the mesh of the virtual object model, the normal corresponding to all points in each triangle is determined using barycentric coordinate interpolation. The barycentric coordinates can be used as the relative weights corresponding to the three vertex normals of the triangle, and the three vertex normals of the triangle are weighted averaged to obtain the normal information at the barycentric coordinates. The barycentric coordinates are any point in the triangle.
[0096] Step S403: extracting color information of a first pixel in the normal texture map, and applying the color information of the first pixel to the normal texture map to obtain a first normal brushstroke texture map;
[0097] In an embodiment of the present application, after obtaining the above-mentioned normal texture map, a hand-painted style brushstroke texture can be drawn on the normal texture map. When drawing a hand-painted style brushstroke texture on the normal texture map, the color information of the first pixel can be extracted on the normal texture map, and the color information of the extracted first pixel can be used to smear the other pixels on the normal texture map except the first pixel. That is, the color information of the other pixels on the normal texture map except the first pixel is changed with the color information of the first pixel. The changed color information of the other pixels on the normal texture map except the first pixel is converted into new normal information, and the direction of the normal of the converted new normal information is changed relative to the original normal information. By changing the normal information, the concave and convex characteristics finally displayed by the virtual object model are changed, thereby realizing the drawing of the brushstroke texture.
[0098] It should be noted that when the color information of the first pixel is extracted from the normal texture map, the color information of any pixel on the normal texture map can be used. After the color information of the first pixel is extracted, the color information of the first pixel is used to smear in any direction, and the number of pixels smeared can also be random.
[0099] The color information of the pixels in the normal texture map may be extracted multiple times, and the above steps may be repeated using the color information of the pixels in the normal texture map extracted each time to obtain the first normal brushstroke texture map. Figure 7 The normal texture map shown in FIG. 9 is drawn by drawing the hand-painted style brush stroke texture in the above manner, and the first normal brush stroke texture map obtained is shown in FIG. 9 . Fig. 9 A schematic diagram of a first normal stroke texture map provided in an embodiment of the present application.
[0100] Step S404: converting the first normal stroke texture map into a tangent space to obtain a second normal stroke texture map;
[0101] In the embodiment of the present application, after obtaining the first normal stroke texture map, the first normal stroke texture map is converted to the tangent space to obtain the second normal stroke texture map. During the conversion, the second normal stroke texture map can be obtained by multiplying the first normal stroke texture map by the inverse matrix of the TBN matrix. Fig.10 FIG. 1 is a schematic diagram of a second normal stroke texture map provided by an embodiment of the present application. That is, through the above conversion method, Fig. 9 The first normal stroke texture map shown can be converted to Fig.10The second normal stroke texture map.
[0102] It should be noted that the first normal stroke texture map is converted into the second normal stroke texture map to facilitate rendering.
[0103] Step S405: Rendering the virtual object model using the second normal brush stroke texture map in the tangent space to obtain a virtual object model with a brush stroke effect.
[0104] In an embodiment of the present application, after the virtual object model is made, it can be rendered by a game engine. The made virtual object model can be imported into the game engine, and the made virtual object model can be placed in a suitable position in the editing environment. After the virtual object model is placed in the editing environment, the size, position, rotation, etc. of the virtual object model can be adjusted. In the editing environment, a light source and a material can be set for the virtual object model, and the material properties, such as color, reflectivity, transparency, etc., can be set. After determining the light source and material of the virtual object model, the virtual object model is rendered based on the second normal stroke texture map in the tangent space mentioned above to obtain Figure 3 A virtual object model with brush stroke effect is shown.
[0105] It should be noted that when rendering a virtual object model, in addition to the above-mentioned second normal stroke texture map, it also includes a diffuse map, a highlight map, a metalness map, a roughness map, and the like.
[0106] If the normal map is not processed as above, and the normal map, the diffuse map, the specular map, the metalness map, and the roughness map are directly used to render the virtual object model with the same light source and material, the rendering result of the virtual object model is as follows: Fig.11 As shown, Fig.11 A schematic diagram of a rendering result of a virtual object model provided in an embodiment of the present application. Fig.11 The rendering results shown are relative to Figure 3 The rendering result shown does not have a hand-painted style brush stroke effect. However, the normal map is first mapped from the model space to the texture space to obtain a normal texture map; the color information of the first pixel in the normal texture map is extracted, and the color information of the first pixel is used to paint on the normal texture map to obtain a first normal brush stroke texture map; the first normal brush stroke texture map is converted to the tangent space to obtain a second normal brush stroke texture map. By replacing the original normal texture map with the second normal brush stroke texture map in the tangent space for rendering, the virtual object model can have a hand-painted style brush stroke effect.
[0107] The rendering method provided by the embodiment of the present application is as follows: obtaining a virtual object model; mapping the vertex normal of the virtual object model from the model space to the texture space to obtain a normal texture map; extracting the color information of the first pixel in the normal texture map, and applying the color information of the first pixel on the normal texture map to obtain a first normal brushstroke texture map; that is, using the color information of the first pixel to change the color information of other pixels on the normal texture map except the first pixel. The changed color information of other pixels on the normal texture map except the first pixel is converted into normal information, and the normal direction of the converted normal information is changed relative to the original normal information. The drawing of the hand-painted style brushstroke texture is achieved by changing the normal information. The first normal brushstroke texture map is converted to the tangent space to obtain the second normal brushstroke texture map; the second normal brushstroke texture map in the tangent space is used to render the virtual object model to obtain a virtual object model with a brushstroke effect. When obtaining the brush stroke effect of the virtual object model, this method does not need to modify the mesh of the virtual object model, and does not need to increase the number of meshes of the virtual object model. Therefore, when rendering in the game engine, the rendering workload does not increase, and the overhead of various resources will not increase.
[0108] In some embodiments, applying the color information of the first pixel on the normal texture map includes:
[0109] Determine, for the first pixel point, a corresponding smearing direction and a second pixel point in the smearing direction;
[0110] In the smearing direction, the color information of the second pixel is updated by using the color information of the first pixel to obtain the updated color information of the second pixel.
[0111] In an embodiment of the present application, after determining the first pixel point whose color information needs to be extracted in the normal texture map, the smearing direction and the second pixel point in the smearing direction are determined for the first pixel point. After the smearing direction is determined, the second pixel point is smeared with the color information of the first pixel point extracted in the smearing direction. That is, the color information of the second pixel point is updated by the color information of the first pixel point extracted to obtain the updated color information of the second pixel point. The updated color information of the second pixel point is converted into new normal information. The normal direction of the converted new normal information is changed relative to the original normal information, and the brushstroke effect of the hand-painted style is achieved by modifying the normal information.
[0112] It should be noted that, in order to determine the smearing direction and the second pixel point in the smearing direction for a pixel point, the smearing direction and the second pixel point in the smearing direction and the number of the second pixel points corresponding to the pixel point can be directly preset, or an algorithm can be set to calculate the smearing direction and the second pixel point in the smearing direction and the number of the second pixel points corresponding to the pixel point.
[0113] As shown in Table 1, an example of a first pixel point for extracting color information, a smearing direction corresponding to the first pixel point, and a second pixel point in the smearing direction provided in an embodiment of the present application is as follows:
[0114] Table 1 Examples of extracting the first pixel point of color information, the smearing direction corresponding to the first pixel point, and the second pixel point in the smearing direction
[0115]
[0116]
[0117] That is, the color information of pixel 1 can be extracted from the normal texture map, and the color information of pixels a1, a2, a3, a4 and a5 in direction 1 can be updated using the color information of pixel 1 starting from pixel 1, to obtain the changed color information of pixels a1, a2, a3, a4 and a5 in direction 1. The color information of pixel 2 can be extracted from the normal texture map, and the color information of pixels b1 and b2 in direction 2 can be updated using the color information of pixel 2 starting from pixel 2, to obtain the changed color information of pixels b1 and b2 in direction 2. The color information of pixel 3 can be extracted from the normal texture map, and the color information of pixels c1, c2, c3 and c4 in direction 3 can be updated using the color information of pixel 3 starting from pixel 3, to obtain the changed color information of pixels c1, c2, c3 and c4 in direction 3. The color information of pixel 4 is extracted from the normal texture map, and the color information of pixel d1, d2 and d3 in direction 4 is updated using the color information of pixel 4 starting from pixel 4, to obtain the changed color information of pixel d1, d2 and d3 in direction 4. The color information of pixel 5 is extracted from the normal texture map, and the color information of pixel e1 and e2 in direction 5 is updated using the color information of pixel 5 starting from pixel 5, to obtain the changed color information of pixel e1 and e2 in direction 5. The color information of pixel 6 is extracted from the normal texture map, and the color information of pixel f1 in direction 6 is updated using the color information of pixel 6 starting from pixel 6, to obtain the changed color information of pixel f1 in direction 6.
[0118] For extracting the color information of the first pixel on the normal texture map, the color information may be extracted for all the pixels on the normal texture map, and after determining the smearing direction of each pixel and the second pixel in the smearing direction, the color information of the second pixel in the smearing direction is updated by the color information of the first pixel in the smearing direction. The above operation may also be performed on some of the pixels on the normal texture map.
[0119] It should be noted that if the color information of a pixel is updated based on the color information of other pixels except the pixel in the normal texture map, when the color information of the pixel is extracted, the extracted color information is the updated color information.
[0120] In some embodiments, the updating the color information of the second pixel point by using the color information of the first pixel point includes:
[0121] The color information of the second pixel is overwritten with the color information of the first pixel to update the color information of the second pixel.
[0122] In the embodiment of the present application, when the color information of the second pixel is updated with the color information of the first pixel extracted, the color information of the second pixel in the smearing direction may be overwritten with the color information of the first pixel. That is, the color information of the first pixel is transferred to the second pixel in the smearing direction. In essence, the normal information of the position in the model space corresponding to the first pixel is transferred to the position in the model space corresponding to the second pixel in the smearing direction.
[0123] In some embodiments, the updating the color information of the second pixel point by using the color information of the first pixel point includes:
[0124] The color information of the first pixel is superimposed with the color information of the second pixel to obtain updated color information of the second pixel.
[0125] In the embodiment of the present application, when the color information of the second pixel is updated with the color information of the first pixel extracted, the color information of the first pixel extracted can be superimposed with the color information of the second pixel in the smearing direction, and the superposition result is used as the color information of the second pixel after the update. That is, the color information of the first pixel is superimposed on the second pixel in the smearing direction. In essence, the normal information of the position in the model space corresponding to the first pixel is superimposed with the normal information in the model space corresponding to the second pixel in the smearing direction, and the normal superposition result is the normal information of the position in the model space corresponding to the second pixel.
[0126] It should be noted that, when superimposing, the color information of the first pixel point and the color information of the second pixel point can be directly superimposed, or weights can be assigned to the color information of the first pixel point and the color information of the second pixel point, and the color information of the first pixel point and the color information of the second pixel point in the smearing direction can be multiplied with the corresponding weights, and the multiplication results can be superimposed.
[0127] In some embodiments, converting the first normal stroke texture map to a tangent space to obtain a second normal stroke texture map includes:
[0128] Construct TBN matrix;
[0129] The first normal stroke texture map in the model space is multiplied by the inverse matrix of the TBN matrix to obtain a second normal stroke texture map in the tangent space.
[0130] In some embodiments, constructing a TBN matrix includes:
[0131] Obtaining a tangent line of the virtual object model in the model space;
[0132] Cross-product the tangent of the virtual object model in the model space with the vertex normal to obtain a secondary tangent of the virtual object model in the model space;
[0133] A TBN matrix is constructed based on the vertex normals, the tangents and the bitangents of the virtual object model in the model space.
[0134] In an embodiment of the present application, when converting the first normal stroke texture map to the tangent space, a TBN matrix is first constructed. The process of constructing the TBN matrix is: obtain the normal InputT and tangent InputN of the virtual character model in the model space. Among them, the tangent of the virtual character model in the model space is a direction vector along the surface at the vertex of the virtual character model. The normal and the normal are cross-multiplied to obtain the secondary tangent InputB of the virtual character model in the model space, wherein the secondary tangent of the virtual character model in the model space is a direction vector along the surface at the vertex of the virtual character model and perpendicular to the tangent. The specific calculation of the secondary tangent of the virtual character model in the model space is:
[0135] InputB=(InputT*2–1)*(InputN*2–1)
[0136] Since the normal InputT and tangent InputN of the virtual character model are normalized during the calculation process, the normal InputT and tangent InputN are multiplied by 2 and then subtracted by 1 to convert them from the [0,1] interval to the [-1,1] interval, and then the calculation is performed to obtain the secondary tangent InputB.
[0137] After obtaining the normal InputT, tangent InputN and bitangent InputB of the virtual character model in the model space, the TBN matrix is constructed using the normal InputT, tangent InputN and bitangent InputB of the virtual character model in the model space:
[0138] MatrixTBN=[InputT,InputB,InputN]
[0139] The first normal stroke texture map can be recorded as InputDN. By multiplying the first normal stroke texture map InputDN with the inverse matrix MatrixTBN^(-1) of the TBN matrix, the first normal stroke texture map can be converted to the tangent space to obtain the second normal stroke texture map.
[0140] It should be noted that, when constructing the TBN matrix, the normal InputT, tangent InputN and bitangent InputB of the virtual character model may be sampled respectively, and the TBN matrix may be constructed using the normal InputT, tangent InputN and bitangent InputB corresponding to the sampled results.
[0141] In some embodiments, rendering the virtual object model using the second normal brush stroke texture map in the tangent space to obtain the virtual object model with a brush stroke effect includes:
[0142] determining a lighting effect of the virtual object model based on the second normal stroke texture map in the tangent space;
[0143] Based on the lighting effect of the virtual object model, the virtual object model is rendered to obtain a virtual object model with a brushstroke effect.
[0144] In an embodiment of the present application, after obtaining the second normal stroke texture map, the lighting effect of the virtual object model can be determined based on the second normal stroke texture map. The lighting effect of the virtual object model can be determined based on the second normal stroke texture map by performing a dot product of the second normal stroke texture map and the lighting direction, and the result of the dot product is the lighting intensity. That is, the closer the normal line in the second normal stroke texture map is to the lighting direction, the stronger the lighting intensity corresponding to the normal line on the virtual character model, and if the normal line in the second normal stroke texture map is farther from the lighting direction, the weaker the lighting intensity corresponding to the normal line on the virtual character model.
[0145] In an optional embodiment, after determining the light intensity based on the second normal stroke texture map and the light direction, the light intensity is multiplied by the color of the virtual character model itself, the color of the light source, the brightness of the light source, and the distance attenuation value of the light source to determine the rendering information of the virtual character model. The virtual character model is rendered using the rendering information, and the rendered virtual object model is displayed in a graphical user interface. The rendered virtual object model has a hand-painted style brushstroke effect.
[0146] It should be noted that the lighting direction in the virtual character model can be any lighting direction in the model space. The color, position and intensity of the lighting can also be set according to actual needs.
[0147] In some embodiments, mapping the vertex normals of the virtual object model from the model space to the texture space to obtain a normal texture map includes:
[0148] Normalizing the vertex normals of the virtual object model to obtain normalized vertex normals;
[0149] The normalized vertex normals are mapped from the model space to the texture space to obtain a normal texture map.
[0150] In an embodiment of the present application, after acquiring the vertex normals of the virtual object model, the acquired vertex normals of the virtual object model are normalized, that is, the vertex normals of the virtual object model are normalized to the interval [0,1] to obtain the normalized vertex normals.
[0151] It should be noted that normalizing the vertex normals of the virtual object model can prevent the vertex normals of the virtual object model from being the original vertex normals when the mesh area of the virtual object model changes later. The normalization process can make the lighting effects based on consistent direction information.
[0152] The normalized vertex normals are mapped to the texture space. That is, the normalized vertex normals are converted to color values, and the converted color values are stored in the color channel of the texture space to obtain a normal texture map.
[0153] Corresponding to the rendering method provided in the embodiment of the present application, the embodiment of the present application also provides a rendering device, such as Fig.12 As shown, the device 1200 includes:
[0154] An acquisition module 1201 is used to acquire a virtual object model;
[0155] A mapping module 1202, used for mapping the vertex normals of the virtual object model from the model space to the texture space to obtain a normal texture map;
[0156] A smearing module 1203 is used to extract color information of a first pixel in the normal texture map, and smear the normal texture map with the color information of the first pixel to obtain a first normal brushstroke texture map;
[0157] A conversion module 1204, configured to convert the first normal stroke texture map into a tangent space to obtain a second normal stroke texture map;
[0158] The rendering module 1205 is used to render the virtual object model using the second normal brush stroke texture map in the tangent space to obtain a virtual object model with a brush stroke effect.
[0159] In some embodiments, the smearing module is further used to:
[0160] Determine, for the first pixel point, a corresponding smearing direction and a second pixel point in the smearing direction;
[0161] In the smearing direction, the color information of the second pixel is updated by the color information of the first pixel to obtain the updated color information of the second smearing pixel.
[0162] In some embodiments, the smearing module is further used to:
[0163] The color information of the second pixel is overwritten with the color information of the first pixel to update the color information of the second pixel.
[0164] In some embodiments, the smearing module is further used to:
[0165] The color information of the first pixel is superimposed with the color information of the second pixel to obtain updated color information of the second pixel.
[0166] In some embodiments, the conversion module is further configured to:
[0167] Construct TBN matrix;
[0168] The first normal stroke texture map in the model space is multiplied by the inverse matrix of the TBN matrix to obtain a second normal stroke texture map in the tangent space.
[0169] In some embodiments, the conversion module is further configured to:
[0170] Obtaining a tangent line of the virtual object model in the model space;
[0171] Cross-product the tangent of the virtual object model in the model space with the vertex normal to obtain a secondary tangent of the virtual object model in the model space;
[0172] A TBN matrix is constructed based on the vertex normals, the tangents and the bitangents of the virtual object model in the model space.
[0173] In some embodiments, the rendering module is further configured to:
[0174] determining a lighting effect of the virtual object model based on the second normal stroke texture map in the tangent space;
[0175] Based on the lighting effect of the virtual object model, the virtual object model is rendered to obtain a virtual object model with a brushstroke effect.
[0176] In some embodiments, the mapping module is further configured to:
[0177] Normalizing the vertex normals of the virtual object model to obtain normalized vertex normals;
[0178] The normalized vertex normals are mapped from the model space to the texture space to obtain a normal texture map.
[0179] Corresponding to the rendering method provided in the embodiment of the present application, the embodiment of the present application also provides an electronic device. Fig.13 As shown, the electronic device includes: a processor 1301; and a memory 1302, which is used to store a program of a rendering method. After the electronic device is powered on and the program storing the rendering method is run by the processor, the following steps are performed:
[0180] Get the virtual object model;
[0181] Mapping the vertex normals of the virtual object model from the model space to the texture space to obtain a normal texture map;
[0182] Extracting color information of a first pixel in the normal texture map, and applying the color information of the first pixel to the normal texture map to obtain a first normal brushstroke texture map;
[0183] Converting the first normal stroke texture map to a tangent space to obtain a second normal stroke texture map;
[0184] The virtual object model is rendered using the second normal brush stroke texture map in the tangent space to obtain a virtual object model with a brush stroke effect.
[0185] Corresponding to the rendering method provided in the embodiment of the present application, the embodiment of the present application further provides a computer-readable storage medium storing a program of the rendering method, the program is executed by a processor to perform the following steps:
[0186] Get the virtual object model;
[0187] Mapping the vertex normals of the virtual object model from the model space to the texture space to obtain a normal texture map;
[0188] Extracting color information of a first pixel in the normal texture map, and applying the color information of the first pixel to the normal texture map to obtain a first normal brushstroke texture map;
[0189] Converting the first normal stroke texture map to a tangent space to obtain a second normal stroke texture map;
[0190] The virtual object model is rendered using the second normal brush stroke texture map in the tangent space to obtain a virtual object model with a brush stroke effect.
[0191] Corresponding to the rendering method provided in the embodiment of the present application, the embodiment of the present application further provides a computer program product, the program product comprising: a computer program, the computer program is stored in a readable storage medium, at least one processor of the electronic device can read the computer program from the readable storage medium, and at least one processor executes the computer program so that the electronic device performs the following steps:
[0192] Get the virtual object model;
[0193] Mapping the vertex normals of the virtual object model from the model space to the texture space to obtain a normal texture map;
[0194] Extracting color information of a first pixel in the normal texture map, and applying the color information of the first pixel to the normal texture map to obtain a first normal brushstroke texture map;
[0195] Converting the first normal stroke texture map to a tangent space to obtain a second normal stroke texture map;
[0196] The virtual object model is rendered using the second normal brush stroke texture map in the tangent space to obtain a virtual object model with a brush stroke effect.
[0197] It should be noted that for the detailed description of the apparatus, electronic device, computer-readable storage medium and computer program product provided in the embodiments of the present application, reference can be made to the relevant description of the method in the embodiments of the present application, which will not be repeated here.
[0198] Although the present application is disclosed as above in the form of a preferred embodiment, it is not intended to limit the present application. Any technical personnel in this field may make possible changes and modifications without departing from the spirit and scope of the present application. Therefore, the scope of protection of the present application shall be based on the scope defined by the claims of the present application.
[0199] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.
[0200] The above-mentioned integrated module implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for enabling an electronic device (which can be a personal computer, a server, or a network device, etc.) or a processor (English: processor) to perform some steps of the method described in each embodiment of the present application.
[0201] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be implemented by a combination of hardware and software modules in the processor.
[0202] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk memory, and may also be a USB flash drive, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk, etc.
[0203] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.
[0204] The above storage medium can 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, magnetic disk or optical disk. The storage medium can be any available medium that can be accessed by a general or special purpose computer.
[0205] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0206] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A rendering method, characterized in that: The method comprises: Get the virtual object model; Mapping the vertex normals of the virtual object model from the model space to the texture space to obtain a normal texture map; Extracting color information of a first pixel in the normal texture map, and applying the color information of the first pixel to the normal texture map to obtain a first normal brushstroke texture map; Converting the first normal stroke texture map to a tangent space to obtain a second normal stroke texture map; The virtual object model is rendered using the second normal brush stroke texture map in the tangent space to obtain a virtual object model with a brush stroke effect.
2. The rendering method according to claim 1, characterized in that: The step of applying the color information of the first pixel to the normal texture map includes: Determine, for the first pixel point, a corresponding smearing direction and a second pixel point in the smearing direction; In the smearing direction, the color information of the second pixel is updated by using the color information of the first pixel to obtain the updated color information of the second pixel.
3. The rendering method according to claim 2, characterized in that: The updating the color information of the second pixel point by using the color information of the first pixel point includes: The color information of the second pixel is overwritten with the color information of the first pixel to update the color information of the second pixel.
4. The rendering method according to claim 2, characterized in that: The updating the color information of the second pixel point by using the color information of the first pixel point includes: The color information of the first pixel is superimposed with the color information of the second pixel to obtain updated color information of the second pixel.
5. The rendering method according to claim 1, characterized in that: The converting the first normal stroke texture map into a tangent space to obtain a second normal stroke texture map comprises: Construct TBN matrix; The first normal stroke texture map in the model space is multiplied by the inverse matrix of the TBN matrix to obtain a second normal stroke texture map in the tangent space.
6. The rendering method according to claim 5, characterized in that: The constructing of the TBN matrix comprises: Obtaining a tangent line of the virtual object model in the model space; Cross-product the tangent of the virtual object model in the model space with the vertex normal to obtain a secondary tangent of the virtual object model in the model space; A TBN matrix is constructed based on the vertex normals, the tangents and the bitangents of the virtual object model in the model space.
7. The rendering method according to claim 1, characterized in that: The step of rendering the virtual object model by using the second normal brushstroke texture map in the tangent space to obtain a virtual object model with a brushstroke effect includes: determining a lighting effect of the virtual object model based on the second normal stroke texture map in the tangent space; Based on the lighting effect of the virtual object model, the virtual object model is rendered to obtain a virtual object model with a brushstroke effect.
8. The rendering method according to claim 1, characterized in that: Mapping the vertex normals of the virtual object model from the model space to the texture space to obtain a normal texture map includes: Normalizing the vertex normals of the virtual object model to obtain normalized vertex normals; The normalized vertex normals are mapped from the model space to the texture space to obtain a normal texture map.
9. A rendering device, characterized in that: The device comprises: An acquisition module, used for acquiring a virtual object model; A mapping module, used for mapping the vertex normals of the virtual object model from the model space to the texture space to obtain a normal texture map; A smearing module, used for extracting color information of a first pixel in the normal texture map, and smearing the normal texture map with the color information of the first pixel to obtain a first normal brushstroke texture map; A conversion module, used for converting the first normal stroke texture map into a tangent space to obtain a second normal stroke texture map; A rendering module is used to render the virtual object model using the second normal brush stroke texture map in the tangent space to obtain a virtual object model with a brush stroke effect.
10. An electronic device, characterized in that: include: processor; as well as The memory is used to store a data processing program. After the electronic device is powered on and the program is run by the processor, the method according to any one of claims 1 to 8 is executed.
11. A computer-readable storage medium, characterized in that: A data processing program is stored, and the program is run by a processor to execute the method according to any one of claims 1 to 8.