Normal map generation method, device, electronic device and storage medium
Generating normal maps through rasterization and ray tracing technology solves the problem of excessively long baking of normals and improves calculation speed and efficiency.
Patent Information
- Application Number
- CN202111641875.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-29
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2041-12-29
AI Technical Summary
The prior art takes too long and has too low efficiency in normal baking, especially in the processing of complex models, and the calculation consumption increases significantly.
Reference model data is obtained through rasterization processing, normal information is generated using ray tracing technology, and whether the ray hits the working model is judged, and normal vectors of hit points are converted to generate normal maps.
This greatly improves the calculation speed of normal baking and the production efficiency of normal maps, and reduces the time consumption of processing complex models.
Smart Images

Figure CN114494564B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of model making technology, and in particular to a normal map generation method, device, electronic device and storage medium. Background Art
[0002] With the rapid development of computer technology, creating virtual models using modeling software has become an essential step in the production of many products. For example, when making games, it is necessary to use modeling software to create many 3D models, and then combine these 3D models to form the virtual scene of the game.
[0003] In real-time model rendering, normals are a crucial attribute that determines surface rendering. Traditional normal baking typically uses the central processing unit (CPU) to calculate these values. As model complexity increases, CPU baking becomes more time-consuming and computationally expensive. Consequently, existing methods for improving baking efficiency in virtual model rendering remain lacking. Summary of the Invention
[0004] In view of this, the present application proposes a normal map generation method, device, electronic device and storage medium, thereby at least to a certain extent improving the problem of excessive time consumption and low efficiency in normal baking in the prior art.
[0005] Based on the above objectives, this application provides a normal map generation method, comprising:
[0006] Acquiring reference model data of a reference model, and performing rasterization processing on the reference model data to obtain rendering data;
[0007] Inputting the rendering data into a ray generation shader to determine ray tracing pixels, determining sampling point information of the ray tracing pixels, and generating ray information based on the sampling point information and the rendering data;
[0008] emitting light according to the light information, and determining whether the light hits the working model;
[0009] In response to hitting the working model, a normal vector of the hit point is determined, and a normal map is generated after converting the normal vector.
[0010] In some embodiments, performing rasterization processing on the reference model data to obtain rendering data includes:
[0011] Mapping vertex coordinate data of the reference model data to a standardized device coordinate space to generate vertex position data;
[0012] Rasterization processing is performed according to the vertex position data, the normal data and the tangent data of the reference model data, and the data after rasterization processing is used as the rendering data.
[0013] In some embodiments, determining the sampling point information of the ray tracing pixel includes:
[0014] Sampling point quantity information is obtained, and sampling points corresponding to the sampling point quantity information are randomly generated on the ray tracing pixel according to a Holden sequence to generate the sampling point information.
[0015] In some embodiments, generating light information according to the sampling point information and the rendering data includes:
[0016] A sampling point is selected according to the sampling point information, the coordinate information of the sampling point is calculated, the corresponding vertex information and normal information are determined in the rendering data according to the coordinate information, the position corresponding to the vertex information is used as the light emission point, and the inverse direction of the normal vector recorded in the normal information is used as the light emission direction to generate the light information.
[0017] In some embodiments, after using the position corresponding to the vertex information as the ray emission point, the method further includes:
[0018] Obtain an emission point offset value, and calculate the emission point offset value into the light emission point.
[0019] In some embodiments, emitting light according to the light information includes:
[0020] Establishing an iterative loop according to the number of sampling points; wherein the sampling points corresponding to the light information are different in each iteration;
[0021] In each iteration, a ray is emitted according to the ray information.
[0022] In some embodiments, after determining the normal vector of the hit point, the method further includes:
[0023] After each iteration, the normal vectors of the same hit point are summed up, and the processed normal vectors are scaled to generate a standardized normal vector.
[0024] In some embodiments, converting the normal vector to generate a normal map includes:
[0025] Obtaining tangent information of the rendering data, generating a transformation matrix according to the tangent information, and inputting the normal vector into the transformation matrix to generate a normal vector in a tangent space;
[0026] Normalization is performed on the normal vector in the tangent space to generate the normal map.
[0027] In some embodiments, the reference model is a low-precision model used to generate the light information; the working model is a high-precision model used to generate the normal vector.
[0028] Based on the same concept, the present application also provides a normal map generation device, comprising:
[0029] a rasterization module, configured to obtain reference model data of a reference model, and perform rasterization processing on the reference model data to obtain rendering data;
[0030] a generating module, configured to input the rendering data into a ray generating shader to determine ray tracing pixels, determine sampling point information of the ray tracing pixels, and generate ray information according to the sampling point information and the rendering data;
[0031] a judgment module, configured to emit light according to the light information and judge whether the light hits the working model;
[0032] The conversion module is used for determining a normal vector of a hit point in response to hitting the working model, and converting the normal vector to generate a normal map.
[0033] Based on the same concept, the present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements any of the above methods when executing the program.
[0034] Based on the same concept, the present application also provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable the computer to implement any of the methods described above.
[0035] From the above description, it can be seen that the present application provides a normal map generation method, device, electronic device and storage medium, including: obtaining reference model data of a reference model, performing rasterization processing based on the reference model data to obtain rendering data; inputting the rendering data into a ray generation shader to determine ray tracing pixels, determining the sampling point information of the ray tracing pixels, and generating ray information based on the sampling point information and the rendering data; emitting light according to the light information to determine whether the light hits the working model; in response to hitting the working model, determining the normal vector of the hit point, converting the normal vector and generating a normal map. The present application obtains rendering data as ray generation information after rasterization, and uses the relevant technologies and methods of ray tracing to generate normals and normal maps, thereby accelerating the normal baking calculation using ray tracing technology, greatly improving the overall calculation speed, and improving the production efficiency of normal maps. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the following briefly introduces the drawings required for use in the embodiments or related technical descriptions. Obviously, the drawings described below are merely embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0037] Figure 1 A schematic diagram of a process for generating a normal map according to an embodiment of the present application;
[0038] Figure 2 A schematic diagram comparing the 3D model and UV coordinates proposed in the embodiment of the present application;
[0039] Figure 3 A schematic diagram of randomly generated sampling points on a pixel proposed in an embodiment of the present application;
[0040] Figure 4 This is an example schematic diagram of interpolation calculation using barycentric coordinates proposed in an embodiment of the present application;
[0041] Figure 5 A schematic diagram of the light emission point offset proposed in an embodiment of the present application;
[0042] Figure 6 A schematic flow chart of a method for generating a normal map in a specific application scenario proposed in an embodiment of the present application;
[0043] Figure 7 A schematic structural diagram of a normal map generation device proposed in an embodiment of the present application;
[0044] Figure 8 This is a schematic diagram of the electronic device structure proposed in an embodiment of the present application. DETAILED DESCRIPTION
[0045] In order to make the purpose, technical solutions and advantages of this specification more clear, this specification is further described in detail below in combination with specific embodiments and with reference to the accompanying drawings.
[0046] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the embodiments of the present application should have the usual meanings understood by people with ordinary skills in the field to which this application belongs. The "first", "second" and similar words used in the embodiments of the present application do not indicate any order, quantity or importance, but are only used to distinguish different components. "Include" or "comprise" and similar words mean that the elements, objects or method steps that appear before the word cover the elements, objects or method steps listed after the word and their equivalents, without excluding other elements, objects or method steps. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0047] As mentioned in the background section, baking complex models is often time-consuming. To improve computational efficiency, the 3D-DDA (3D Digital Differential Analyzer) algorithm has emerged, leveraging graphics processing units (GPUs) to accelerate normal baking. This method voxelizes polygonal meshes into a 3D texture and then performs soft ray tracing. However, this method utilizes rasterization, which only increases normal baking speed by about 5-6 times. Furthermore, the algorithm is complex and lacks maintainability. Baking normals essentially stores the normal directions of the working model (high-poly model) as pixels on the surface of a reference model (low-poly model). The reference model with the normal map applied will have the same lighting and shadow variations as the working model, making it look like the working model. A normal map creates a normal at every point on the original object's concave and convex surface, using RGB color channels to indicate the normal's direction. While you might think of it as a different surface parallel to the original concave and convex surface, it's actually just a smooth plane. For visual effects, it is more efficient than the original bump surface. If the light source is applied at a specific position, it can generate accurate lighting direction and reflection effects with high detail on the surface with low detail.
[0048] In view of the above actual situation, the embodiment of the present application proposes a normal map generation solution, which obtains rendering data after rasterization as information for light generation, and uses relevant technologies and methods of ray tracing to generate normals and normal maps, thereby using ray tracing technology to accelerate the normal baking calculation, greatly improving the overall calculation speed and improving the production efficiency of normal maps.
[0049] like Figure 1 FIG. 1 is a flow chart of a normal map generation method proposed in this application, which specifically includes:
[0050] Step 101 : Acquire reference model data of a reference model, perform rasterization processing on the reference model data, and obtain rendering data.
[0051] In this step, the working model corresponds to the reference model, the working model is a high-polygon model or a high-precision model, and the reference model is a low-polygon model or a low-precision model. When the model is generated, detailed depiction and production are generally performed on the corresponding high-detail model. Then, according to the correspondence between the normals, the texture made on the working model is pasted on the corresponding reference model, so that the reference model can also achieve the corresponding optimization and rendering effects. Afterwards, the reference model data is the UV coordinate data, normal data, tangent data, etc. on the reference model. Among them, UV here refers to the abbreviation of U and V texture mapping coordinates (it is similar to the X, Y, and Z axes of the spatial model). It defines the position information of each point on the picture. These points are interconnected with the 3D model to determine the position of the surface texture map. UV is to accurately correspond each point on the image to the surface of the model object, and the two-dimensional UV coordinates can be accurately corresponded to each point on the three-dimensional model, such as Figure 2 As shown, the left side is the 3D model and the right side is the UV coordinate space of the 3D model.
[0052] Rasterization can then be performed based on this reference model data. Rasterization is the process of converting a primitive into a two-dimensional image. Each point in a two-dimensional image contains color, depth, and texture data. This point and related information is called a fragment. Rasterization converts an image into a grid of raster elements, with each element corresponding to a pixel in the frame buffer. In specific application scenarios, during the input assembly (IA) phase of rasterization, a vertex can carry multiple data. Data such as the reference model data can then be written into the data carried by the vertex, followed by hardware rasterization. After rasterization is complete, the various data in the reference model data can be baked into corresponding buffer texture maps to generate rendering data. For example, the vertex coordinate data, normal data, and tangent data of the reference model data can be written into the corresponding vertex buffer texture map, normal buffer texture map, and tangent buffer texture map, respectively, to generate rendering data.
[0053] Step 102 : Input the rendering data into a ray generation shader to determine ray tracing pixels, determine sampling point information of the ray tracing pixels, and generate ray information based on the sampling point information and the rendering data.
[0054] In this step, the ray generation shader (Ray Generation Shader) is a shader that calls the TraceRay function to generate rays. It is an inherent shader in the RTX architecture (ray tracing architecture). In the ray tracing process, generally, the pixel on the reference model emits light to the working model. After determining whether the light hits the working model, the hit light is traced, so that the ray traced pixel can generally be the corresponding pixel on the reference model. In a specific application scenario, the rendering data (vertex coordinate position, normal, tangent, etc.) buffer is bound to the ray generation shader. Afterwards, the ray generation shader can determine the position of the ray traced pixel based on the scheduled ray index, wherein the ray index is a hardware-accelerated index value automatically generated by the RTX architecture for the user or operator. The pixel position of the write data can be determined by this index value. In this embodiment, the write data is the input rendering data.
[0055] Afterwards, the sampling point information is determined based on the determined ray tracing pixel, wherein the sampling point information is the information of at least one sampling point generated according to a specific rule on a single pixel. In a specific application scenario, the required number of sampling points can be determined by user input, or the number of sampling points can be calculated by a specific algorithm, such as obtaining the input SamplesPerPixel value (i.e., the number of sampling points information), which determines the number of sampling points for each pixel. In ray tracing, each pixel needs to be sampled multiple times to eliminate aliasing. Afterwards, these random sampling points can be generated on a single pixel through a random sequence based on the determined number of sampling points, such as Figure 3 As shown, the sampling points are randomly generated on a pixel.
[0056] Finally, light information can be generated based on these sampling point information combined with rendering data. Among them, light information is the emission point, emission direction and other information related to light generation. For the sampling point information of any sampling point, the sampling point information can be used to calculate the UV coordinates, and each point in the buffer texture map of various data in the rendering data must also have corresponding UV coordinates, and then the two can be matched, so that the UV coordinates calculated by the sampling point information can be used to sample the vertex coordinate position data, normal data and other rendering buffer data in the rendering data according to the corresponding relationship. Finally, the vertex coordinate position can be used as the starting point of light emission, and the reverse direction of the normal vector direction can be used as the direction of light emission to finally generate the light information corresponding to the sampling point information.
[0057] Step 103: emit light according to the light information and determine whether the light hits the working model.
[0058] In this step, after emitting light according to the light information, the light is generally emitted from the reference model to the working model, that is, from the low-poly model to the high-poly model. However, among all the emitted light rays, not all of them will hit the working model, so it is necessary to first determine which rays hit the working model. In specific application scenarios, the ray traversal function of the RTX framework can be used to traverse the light rays to determine which rays hit the working model and which ones do not. For hits, the closest hit shader (Closest Hit Shader) can be activated, and for misses, the miss shader (Miss Shader) can be activated.
[0059] Step 104 : In response to hitting the working model, determining a normal vector of the hit point, and converting the normal vector to generate a normal map.
[0060] In this step, for the hitting ray, the normal vector of the hitting point can be determined according to the specific form of the hitting working model. For example, when the hitting point is a plane, the normal vector of the hitting point can be determined directly by determining the normal vector of the plane. In a specific embodiment, the minimum unit of the working model (i.e., the high-poly model) is a triangle unit, so the normal vector of the hitting point can be calculated by interpolating the normals on the three vertices of the triangle according to the coordinates of the center of gravity of the triangle. Figure 4 As shown, in the triangle enclosed by the x1 normal, x2 normal, and x3 normal (since the normal vector is a three-dimensional vector, it is a point in the plane, and its vector direction is above or below the plane), find the normal vector of the midpoint p, where the area of the triangle is A, A1, A2, and A3 are the areas of the corresponding three small triangles, then the coordinates of the center of gravity are The interpolated normal vector value p = ux1 + vx2 + wx3. For rays that miss the target, the default value (0, 0, 1) can be returned. Because not all pixels in a normal map have corresponding model UV information, a default upward-pointing normal (0, 0, 1) is assigned to these locations.
[0061] Afterwards, for these calculated normal vectors, since they are calculated in world space, they must be converted to tangent space to facilitate subsequent production. Here, the tangent data of the working model or the reference model can be used to generate a tangent space transformation matrix, and the normal vectors are transformed to tangent space in this matrix, thus completing the production of the normal map.
[0062] From the above description, it can be seen that a normal map generation method of an embodiment of the present application includes: obtaining reference model data of a reference model, performing rasterization processing based on the reference model data to obtain rendering data; inputting the rendering data into a ray generation shader to determine ray tracing pixels, determining sampling point information of the ray tracing pixels, and generating ray information based on the sampling point information and the rendering data; emitting light according to the light information to determine whether the light hits the working model; in response to hitting the working model, determining the normal vector of the hit point, and converting the normal vector to generate a normal map. The present application obtains rendering data as ray generation information after rasterization, and uses the relevant technologies and methods of ray tracing to generate normals and normal maps, thereby accelerating the normal baking calculation using ray tracing technology, greatly improving the overall calculation speed, and improving the production efficiency of normal maps.
[0063] It should be noted that the method of the embodiment of the present application can be performed by a single device, such as a computer or server. The method of the embodiment of the present application can also be applied in a distributed scenario and completed by multiple devices working together. In the case of such a distributed scenario, one of the multiple devices may only perform one or more steps of the method of the embodiment of the present application, and the multiple devices will interact with each other to complete the method described.
[0064] It should be noted that the above description is of specific embodiments of the present application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the above embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0065] In an optional exemplary embodiment, performing rasterization processing on the reference model data to obtain rendering data includes: mapping vertex coordinate data of the reference model data to a normalized device coordinate space to generate vertex position data; performing rasterization processing on the vertex position data, normal data, and tangent data of the reference model data, and using the rasterized data as the rendering data. This facilitates rapid rasterization processing.
[0066] In this embodiment, the coordinate data of each vertex of a general reference model, that is, the UV coordinates of the vertices generally have a numerical range between 0 and 1. When rasterizing, it is generally necessary to map these coordinates to the Normalized Device Coordinate space (NDC space). In the NDC space, the coordinate range is between -1 and 1. Therefore, when mapping the two, the mapping formula Y=2(X-0.5) can be used to obtain it, where X is the value before mapping, and its range is between 0 and 1; Y is the value after conversion, and its range is between -1 and 1. In this way, the homogeneous coordinate data of the transformed vertex, that is, the vertex position data, is obtained. Afterwards, the vertex position data is written into the vertex data structure together with the normal data and tangent data, and the hardware rasterization processing is performed, so that the rasterization plug-in can quickly perform the conversion, save conversion time, and improve efficiency.
[0067] In an optional exemplary embodiment, determining the sampling point information of the ray-traced pixel includes: obtaining sampling point quantity information, and randomly generating a number of sampling points corresponding to the sampling point quantity information on the ray-traced pixel according to a Holden sequence, thereby generating the sampling point information, thereby accurately generating the sampling point information for each sampling point.
[0068] In this embodiment, the number of sampling points (SamplesPerPixel) is the number of sampling points per pixel. In ray tracing, multiple samplings are required for each pixel to eliminate aliasing. The Halton sequence is a method for generating sampling points for a single pixel. Specifically, for a ray-traced pixel, the number of sampling points required is determined by the number of sampling points information, and the Halton sequence is used to randomly generate this number of sampling points. Finally, sampling point information is generated based on these generated sampling points.
[0069] In an optional exemplary embodiment, the generating of light information based on the sampling point information and the rendering data includes: selecting a sampling point based on the sampling point information, calculating the coordinate information of the sampling point, determining the corresponding vertex information and normal information in the rendering data based on the coordinate information, using the position corresponding to the vertex information as the light emission point, and using the inverse direction of the normal vector recorded in the normal information as the light emission direction to generate the light information.
[0070] In this embodiment, since each sampling point corresponds to a ray, a collection point is first selected from the sampling point information of multiple sampling points, and the coordinate information of the sampling point, i.e., the UV coordinate of the point, is calculated. The vertex information and normal information contained in the rendering data are sampled using the UV coordinate. The vertex coordinate corresponding to the vertex information is then used as the emission point of the ray, and the inverse direction of the normal vector direction is used as the direction of the ray. Finally, the ray information corresponding to the sampling point is generated in this way. The same process can be repeated for other sampling points.
[0071] In an optional exemplary embodiment, after using the position corresponding to the vertex information as the ray emission point, the method further includes: obtaining an emission point offset value, and calculating the emission point offset value into the ray emission point, thereby preventing errors or errors caused by the emission point of the emitted ray being within the reference model.
[0072] The emission point offset value is the CageBias value, which is a ray origin offset value used to prevent the ray origin from being inside the model. Figure 5 As shown, line A is the baked model surface, and line B is the contour line after adding the offset (CageBias). The emission point offset value can be set by the user in advance.
[0073] In an optional exemplary embodiment, emitting light according to the light information includes: establishing an iterative loop according to the sampling point quantity information; wherein the sampling points corresponding to the light information are different in each iteration; and emitting light according to the light information in each iteration.
[0074] In this embodiment, according to the aforementioned embodiment, there may be more than one sampling point. Therefore, for multiple sampling points, each sampling point needs to perform a light emission, so it is necessary to construct an iterative loop. The sampling points corresponding to each loop are different, and the number of iterations is the number of sampling points corresponding to the sampling point number information, so that each sampling point can complete the light emission.
[0075] In an optional exemplary embodiment, after determining the normal vector of the hit point, the method further includes: after each iteration, summing the normal vectors of the same hit point and scaling the processed normal vectors to generate a normalized normal vector. This allows for anti-aliasing to prevent jagged normal maps.
[0076] In this embodiment, since multiple rays may hit a hit point during multiple iterations, the resulting normal vectors may differ slightly, causing aliasing. Anti-aliasing can be performed here by adding the normal values obtained each time and combining them into one. Since the normal map's normal vector range is -1 to 1, the added vector may exceed this range, requiring scaling to bring it to a constant range of -1 to 1 to meet the needs of the normal map.
[0077] In an optional exemplary embodiment, converting the normal vector to generate a normal map includes: obtaining tangent information of the rendering data, generating a transformation matrix based on the tangent information, inputting the normal vector into the transformation matrix to generate a tangent-space normal vector; and normalizing the tangent-space normal vector to generate the normal map. In this manner, the corresponding normal map is accurately generated.
[0078] In this embodiment, since the normal vector calculated at the beginning is a normal vector in the world space, it is not suitable for the subsequent production process, so it needs to be converted into a normal vector in the tangent space. Then, the tangent information in the rendering data is used to generate a tangent space transformation matrix, and then the normal vector is placed into the transformation matrix and transformed from the world space to the tangent space. Afterwards, since the normal map cannot store negative values, and the current normal vector is in the range of -1 to 1, it is necessary to map it from the range of -1 to 1 to the range of 0 to 1. The mapping formula can be the inverse formula of the mapping formula from the range of 0 to 1 to the range of -1 to 1 in the aforementioned embodiment, that is Where M is the value after mapping, and N is the value before mapping.
[0079] In an optional exemplary embodiment, the reference model is a low-precision model used to generate the light information; the working model is a high-precision model used to generate the normal vector.
[0080] In a specific embodiment, the reference model corresponds to the working model. The working model is a high-precision model or a high-polygon model, generally referred to as a high-poly model. A high-poly model is finely segmented and composed of many faces with many nodes. Such a model runs relatively slowly during operation, but can be made very fine, making it easier for engineers to perform operations such as detail production. The reference model is a low-precision model or a low-polygon model, generally referred to as a low-poly model. The low-poly model is the opposite of the high-poly model, but when rendered with a normal map or ordinary bump map, it can also display a much finer picture effect than the actual model's number of faces. Therefore, when working on large scenes or particularly fine pictures, they are usually produced on the high-poly model, and then the normal map is exported from the high-poly model and applied to the low-poly model for operation, which greatly improves efficiency.
[0081] In a specific embodiment, Figure 6 This embodiment is mainly divided into two processes:
[0082] (1) Generate light information (rasterization stage). Step 601, input the reference model. That is, input the UV coordinates, normal data and tangent data of the reference model into the rasterization pipeline. Step 602, transform the model into UV space. That is, in the vertex shader, map the UV coordinates from the range of 0 to 1 to the range of -1 to 1, and use them as the homogeneous coordinates of the transformed vertex. Write the converted vertex position data, normal data and tangent data into the vertex data structure for rasterization. Step 603, rasterization. That is, perform hardware rasterization. After rasterization is completed, in the pixel shader, write the vertex position data, normal data and tangent data into the corresponding rendering texture map for rendering target to generate the final rendering data. They will serve as the light emission information to be read in the next stage.
[0083] (2) Perform normal baking (ray tracing stage). Input the normal data, tangent data and other geometric information of the reference model into the ray tracing pipeline buffer. Input the material information of the working model into the shader binding table (SBT) of the ray tracing pipeline, which will generate a hit group (Hit Group) for each working model. When the light hits, the hit point can be colored according to the shader binding table. Step 604, generate light information. Bind the vertex position data, normal data and tangent data buffer generated in the previous stage to the ray generation shader (Ray Generation Shader). The ray generation shader first generates the pixel position according to the scheduled light index. And use the input sampling point number information (SamplesPerPixel value) to generate random sampling points according to the Halton sequence (Halton sequence). Use the random pixel sampling points generated by the Halton sequence to calculate the UV coordinates, and use this UV coordinate to sample the vertex information and normal information of the rendering data generated in the previous stage. The vertex information can be used as the origin of the emitted light, and the inverse direction of the vector direction of the normal information is used as the direction of the light. Among them, the input emission point offset value (CageBias value) can be used as the offset value of the ray origin to avoid the ray origin being inside the reference model. Step 605, emit light. That is, build a loop and use the Halton sequence offset to emit light in each iteration. The number of iterations is the passed-in SamplesPerPixel value, so that each sampling point can perform a ray emission. Step 606, ray traversal. After emitting the light, the RTX framework will automatically start the ray traversal. Step 607, determine the hit. After the ray traversal is completed, the closest hit shader (ClosestHit Shader) and the miss shader (Miss Shader) will be started respectively according to whether the target is hit. If the working model is hit, execute step 608, calculate the interpolated normal, and call the closest hit shader. It will interpolate the normal vectors on the three vertices of the triangle according to the barycentric coordinates of the triangle of the smallest unit of the working model to calculate the normal vector of the hit point. After calculating the normal vector, the normal vector value is put into the Payload of the ray. If the ray does not hit, execute step 609, generate a default normal, and call the miss shader. Return a default value (0,0,1) to the ray's Payload. After each iteration, add the obtained normal vector values and normalize them to the range of -1 to 1. In this way, the jitter sampling deviation of the Halton sequence can be used for anti-aliasing processing. Finally, a tangent space transformation matrix is constructed using the tangent data of the reference model to transform the obtained normal vector from world space to tangent space. The normal vector converted to tangent space is normalized to finally generate a normal map.
[0084] Based on the same concept, corresponding to any of the above-mentioned embodiment methods, the present application also provides a normal map generation device.
[0085] refer to Figure 7 , the normal map generating device comprises:
[0086] The rasterization module 710 is configured to obtain reference model data of a reference model, and perform rasterization processing on the reference model data to obtain rendering data.
[0087] The generation module 720 is configured to input the rendering data into a ray generation shader to determine ray tracing pixels, determine sampling point information of the ray tracing pixels, and generate ray information according to the sampling point information and the rendering data.
[0088] The judgment module 730 is used to emit light according to the light information and judge whether the light hits the working model.
[0089] The conversion module 740 is configured to determine a normal vector of a hit point in response to hitting the working model, and generate a normal map after converting the normal vector.
[0090] For the convenience of description, the above devices are described as being divided into various modules according to their functions. Of course, when implementing the embodiments of the present application, the functions of each module can be implemented in the same or multiple software and / or hardware.
[0091] The device of the above embodiment is used to implement the corresponding normal map generation method in the above embodiment, and has the beneficial effects of the corresponding method embodiment, which will not be repeated here.
[0092] In an optional exemplary embodiment, the rasterization module 710 is further configured to:
[0093] Mapping vertex coordinate data of the reference model data to a standardized device coordinate space to generate vertex position data;
[0094] Rasterization processing is performed according to the vertex position data, the normal data and the tangent data of the reference model data, and the data after rasterization processing is used as the rendering data.
[0095] In an optional exemplary embodiment, the generating module 720 is further configured to:
[0096] Sampling point quantity information is obtained, and sampling points corresponding to the sampling point quantity information are randomly generated on the ray tracing pixel according to a Holden sequence to generate the sampling point information.
[0097] In an optional exemplary embodiment, the generating module 720 is further configured to:
[0098] A sampling point is selected according to the sampling point information, the coordinate information of the sampling point is calculated, the corresponding vertex information and normal information are determined in the rendering data according to the coordinate information, the position corresponding to the vertex information is used as the light emission point, and the inverse direction of the normal vector recorded in the normal information is used as the light emission direction to generate the light information.
[0099] In an optional exemplary embodiment, the generating module 720 is further configured to:
[0100] Obtain an emission point offset value, and calculate the emission point offset value into the light emission point.
[0101] In an optional exemplary embodiment, the judgment module 730 is further configured to:
[0102] Establishing an iterative loop according to the number of sampling points; wherein the sampling points corresponding to the light information are different in each iteration;
[0103] In each iteration, a ray is emitted according to the ray information.
[0104] In an optional exemplary embodiment, the conversion module 740 is further configured to:
[0105] After each iteration, the normal vectors of the same hit point are summed up, and the processed normal vectors are scaled to generate a standardized normal vector.
[0106] In an optional exemplary embodiment, the conversion module 740 is further configured to:
[0107] Obtaining tangent information of the rendering data, generating a transformation matrix according to the tangent information, and inputting the normal vector into the transformation matrix to generate a normal vector in a tangent space;
[0108] Normalization is performed on the normal vector in the tangent space to generate the normal map.
[0109] In an optional exemplary embodiment, the reference model is a low-precision model used to generate the light information; the working model is a high-precision model used to generate the normal vector.
[0110] Based on the same concept, corresponding to any of the above-mentioned embodiments and methods, the present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and runnable on the processor, wherein when the processor executes the program, the normal map generation method described in any of the above embodiments is implemented.
[0111] Figure 810 is a schematic diagram showing a more specific hardware structure of an electronic device provided in this embodiment. The device may include: a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040 are communicatively connected to each other within the device via the bus 1050.
[0112] The processor 1010 can be implemented using a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.
[0113] The memory 1020 can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage devices, dynamic storage devices, etc. The memory 1020 can store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 1020 and is called and executed by the processor 1010.
[0114] The input / output interface 1030 is used to connect input / output modules to implement information input and output. The input / output modules can be configured as components within the device (not shown in the figure) or can be externally connected to the device to provide corresponding functions. Input devices may include a keyboard, mouse, touch screen, microphone, various sensors, etc., and output devices may include a display, speaker, vibrator, indicator light, etc.
[0115] The communication interface 1040 is used to connect to a communication module (not shown) to enable communication between the device and other devices. The communication module can communicate via a wired method (such as USB, network cable, etc.) or a wireless method (such as mobile network, WiFi, Bluetooth, etc.).
[0116] The bus 1050 comprises a path for transmitting information between the various components of the device (eg, the processor 1010 , the memory 1020 , the input / output interface 1030 , and the communication interface 1040 ).
[0117] It should be noted that although the above device only shows the processor 1010, the memory 1020, the input / output interface 1030, the communication interface 1040, and the bus 1050, in a specific implementation, the device may also include other components necessary for normal operation. In addition, it will be understood by those skilled in the art that the above device may only include the components necessary to implement the embodiments of this specification, and does not necessarily include all the components shown in the figure.
[0118] The electronic device of the above embodiment is used to implement the corresponding normal map generation method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be described in detail here.
[0119] Based on the same concept, corresponding to any of the above-mentioned embodiment methods, the present application also provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the normal map generation method described in any of the above embodiments.
[0120] The computer-readable media of this embodiment include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device.
[0121] The computer instructions stored in the storage medium of the above embodiment are used to enable the computer to execute the normal map generation method described in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0122] Those skilled in the art should understand that the discussion of any of the above embodiments is merely illustrative and is not intended to imply that the scope of the present application (including the claims) is limited to these examples. Within the scope of the present application, the technical features in the above embodiments or different embodiments may be combined, the steps may be implemented in any order, and there are many other variations of the different aspects of the embodiments of the present application as described above, which are not provided in detail for the sake of simplicity.
[0123] In addition, for simplicity of description and discussion, and in order not to make the embodiment of the application difficult to understand, the known power supply / ground connection with integrated circuit (IC) chip and other components may or may not be shown in the accompanying drawings provided. In addition, the device can be shown in the form of a block diagram to avoid making the embodiment of the application difficult to understand, and this also takes into account the following fact, that is, the details of the embodiment of these block diagram devices are highly dependent on the platform to be implemented in the embodiment of the application (that is, these details should be fully within the scope of understanding of those skilled in the art). When specific details (for example, circuit) are set forth to describe exemplary embodiments of the application, it will be apparent to those skilled in the art that the embodiment of the application can be implemented without these specific details or when these specific details are changed. Therefore, these descriptions should be considered to be illustrative rather than restrictive.
[0124] Although the present invention has been described in conjunction with specific embodiments thereof, many alternatives, modifications, and variations of these embodiments will be apparent to those skilled in the art based on the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may utilize the embodiments discussed.
[0125] The embodiments of the present application are intended to cover all such substitutions, modifications, and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the embodiments of the present application should be included in the scope of protection of this application.
Claims
1. A normal map generation method, characterized in that: include: Acquire reference model data of a reference model, and perform rasterization processing on the reference model data to obtain rendering data; wherein the reference model is a low-polygon model, and the reference model data includes at least one of coordinate data, normal data, and tangent data; Inputting the rendering data into a ray generation shader to determine ray tracing pixels, determining sampling point information of the ray tracing pixels, and generating ray information based on the sampling point information and the rendering data; Emitting light according to the light information, and determining whether the light hits a working model; wherein the working model is a high-polygon model; In response to hitting the working model, determining a normal vector of the hit point, and generating a normal map after converting the normal vector; The step of performing rasterization processing on the reference model data to obtain rendering data includes: Mapping vertex coordinate data of the reference model data to a standardized device coordinate space to generate vertex position data; performing rasterization processing according to the vertex position data, the normal data and the tangent data of the reference model data, and using the rasterized data as the rendering data; The generating of light information according to the sampling point information and the rendering data includes: A sampling point is selected according to the sampling point information, coordinate information of the sampling point is calculated, corresponding vertex information and normal information are determined in the rendering data according to the coordinate information, and the light information is generated according to the corresponding vertex information and normal information.
2. The method according to claim 1, characterized in that The determining the sampling point information of the ray tracing pixel includes: Sampling point quantity information is obtained, and sampling points corresponding to the sampling point quantity information are randomly generated on the ray tracing pixel according to a Holden sequence to generate the sampling point information.
3. The method according to claim 1, characterized in that The corresponding position of the corresponding vertex information is used as the light emission point, and the inverse direction of the normal vector recorded in the corresponding normal information is used as the light emission direction to generate the light information.
4. The method according to claim 3, characterized in that After using the position corresponding to the vertex information as the light emission point, the method further includes: Obtain an emission point offset value, and calculate the emission point offset value into the light emission point.
5. The method according to claim 2, characterized in that The emitting light according to the light information includes: Establishing an iterative loop according to the number of sampling points; wherein the sampling points corresponding to the light information are different in each iteration; In each iteration, a ray is emitted according to the ray information.
6. The method according to claim 5, characterized in that After determining the normal vector of the hit point, the method further includes: After each iteration, the normal vectors of the same hit point are summed up, and the processed normal vectors are scaled to generate a standardized normal vector.
7. The method according to claim 1, characterized in that The step of converting the normal vector to generate a normal map comprises: Obtaining tangent information of the rendering data, generating a transformation matrix according to the tangent information, and inputting the normal vector into the transformation matrix to generate a normal vector in a tangent space; Normalization is performed on the normal vector in the tangent space to generate the normal map.
8. The method according to claim 1, characterized in that The reference model is a low-precision model used to generate the light information; the working model is a high-precision model used to generate the normal vector.
9. A normal map generating device, characterized in that: include: a rasterization module, configured to obtain reference model data of a reference model, and perform rasterization processing on the reference model data to obtain rendering data; wherein the reference model is a low-polygon model, and the reference model data includes at least one of coordinate data, normal data, and tangent data; a generating module, configured to input the rendering data into a ray generating shader to determine ray tracing pixels, determine sampling point information of the ray tracing pixels, and generate ray information according to the sampling point information and the rendering data; a judgment module, configured to emit light according to the light information and judge whether the light hits a working model; wherein the working model is a high-polygon model; a conversion module, configured to determine a normal vector of a hit point in response to hitting the working model, and convert the normal vector to generate a normal map; The step of performing rasterization processing on the reference model data to obtain rendering data includes: Mapping vertex coordinate data of the reference model data to a standardized device coordinate space to generate vertex position data; performing rasterization processing according to the vertex position data, the normal data and the tangent data of the reference model data, and using the rasterized data as the rendering data; The generating of light information according to the sampling point information and the rendering data includes: A sampling point is selected according to the sampling point information, coordinate information of the sampling point is calculated, corresponding vertex information and normal information are determined in the rendering data according to the coordinate information, and the light information is generated according to the corresponding vertex information and normal information.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the method according to any one of claims 1 to 8 is implemented.
11. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to enable the computer to implement the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Object rendering method and device, storage medium and electronic device
CN108564646A
Hybrid ray tracing drawing method and system
CN112017254A