Scene voxelization method based on gpu rasterizer
By adopting a scene voxelization method based on GPU rasterizers, the voxelization process is simplified, the voxel gap problem is solved, and the running speed and accuracy are improved, making it suitable for real-time application scenarios.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NORTHEASTERN UNIV CHINA
- Filing Date
- 2022-12-23
- Publication Date
- 2026-05-29
AI Technical Summary
Existing voxelization methods still need performance optimization in real-time interactive applications such as games, especially the voxel gap problem and the performance loss caused by multiple rendering passes.
A scene voxelization method based on GPU rasterizers is adopted. By converting the mesh model to homogeneous clip space, the voxelization process is simplified by using primitive maximum projection plane flipping technology and conservative rasterization technology that extends primitive edges, and primitive information is processed in the geometry shader.
It improves the running speed of the voxelization method, ensures the accuracy of the voxelization results, is suitable for real-time application scenarios, and supports functions such as global illumination calculation, ambient occlusion calculation, and collision detection.
Smart Images

Figure CN115953290B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of real-time rendering technology, and in particular to a scene voxelization method based on a GPU rasterizer. Background Technology
[0002] Just like pixels in two-dimensional materials, voxels are the basic units of three-dimensional materials, recording information within a certain volume range in space. Voxels have a wide range of applications, from storing and representing objects such as smoke and water flow, to 3D printing models, skeletal scanning, and terrain recording. In recent years, a classic application has been assisting in the implementation of global illumination algorithms in game software.
[0003] Voxel data can come from various sources, including point cloud data, model meshes, or other data formats. For model meshes, Karabassi et al. proposed a fast but coarse method for voxel generation. Specifically, they render the model from six orthogonal viewpoints of a cube enclosing the mesh, generating six corresponding depth maps to store the outermost model information in each direction. Then, they compare the center position of each voxel with the depth information in the depth maps to determine whether the voxel is inside or outside the model. This method results in the loss of all model details that cannot be directly observed from the six faces of the cube, which poses a significant problem for models with enclosing structures.
[0004] An improved version of the above method, a voxelization approach for mesh models has been proposed. Unlike the previous rendering process that used six orthogonal perspectives surrounding the cube, this improved method only renders the front, side, and top surfaces. Furthermore, it disables depth testing and backface culling during the rendering process to ensure that all model meshes are rendered. Then, in the shader, the improved method determines whether to retain a primitive based on whether its maximum projection axis is parallel to the camera direction. This ensures that the primitive is rendered only in the camera direction where its projected area is maximized, thus avoiding voxel gaps.
[0005] Although the improved method compresses the original six rendering passes to three passes, greatly improving the efficiency of the method and improving the problem of detail loss after voxelization for models with wrapped structures, there is still room for performance optimization in application scenarios such as games that require real-time interaction speed. Summary of the Invention
[0006] The technical problem to be solved by the present invention is to address the shortcomings of the prior art by providing a scene voxelization method based on GPU rasterizers, and further optimizing and improving the voxelization method to meet the application scenarios of real-time interaction speed such as video games.
[0007] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows:
[0008] A scene voxelization method based on GPU rasterizers includes the following steps:
[0009] Step 1: Transform the spatial position of the mesh model objects to homogeneous clip space;
[0010] Step 2: Use the technique of flipping primitives based on the maximum projection surface of primitives to solve the voxel gap problem caused by the grazing angle between the primitive and the camera direction;
[0011] Step 3: Use a conservative rasterization technique that extends the edge of the primitive to solve the problem of voxel gaps caused by the primitive only covering a part of the voxel and not covering the center of the voxel.
[0012] Step 4: Calculate the average value of all primitive information, assuming that all primitives covering the voxel contribute to the voxel to the same degree, and introduce access control and data transformation operations.
[0013] Furthermore, the specific method for step 1 is as follows:
[0014] Step 1.1: Transform the vertex positions of the mesh model into the secondary clipping space through spatial transformation. The specific transformation order is as follows: First, transform the vertex positions of the mesh model from model space to world space to obtain the absolute positions with the origin of world space as the axis point, which is convenient for determining the relative relationships between different mesh models; then, transform the vertices of the mesh model from world space to view space to intuitively describe the relative positions of the mesh model vertices and the camera center; finally, transform the vertices of the mesh model from view space to homogeneous clipping space. This homogeneous clipping space is mainly used to clip the rendered primitives. Primitives that are completely within the view frustum are retained, primitives that are outside the view frustum are removed, and primitives that intersect with the boundary of the view frustum are clipped, and new vertices are generated at the boundary.
[0015] Step 1.2: Process the vertex positions of the final homogeneous clipping space model according to platform differences to ensure that the xyz coordinate values of the vertex positions are consistent.
[0016] Furthermore, in step 1.1, the vertex positions of the mesh model are transformed into the secondary clipping space through spatial transformation, which requires the use of the MVP matrix:
[0017]
[0018]
[0019]
[0020] Among them, Tx T y T z S represents the coordinates of the origin of the mesh model space in world space; x S y S z R represents the stretching of the mesh model along each axis in world space; R, U, and Dir represent the x, y, and z axes of the view space in world space, with different subscripts representing different components; P represents the coordinates of the camera origin in world space, with different subscripts representing different components; l and r represent the left and right boundary values of the orthogonal camera's view frustum in view space, respectively; t and b represent the upper and lower boundary values of the orthogonal camera's view frustum in view space, respectively; and f and n represent the near and far boundary values of the orthogonal camera's view frustum in view space, respectively.
[0021] Through the Model matrix M model Transform the vertex positions of the mesh model from model space to world space using the View matrix M. viewport The vertices of the mesh model are transformed from world space to view space using an orthogonal projection matrix M. ortho Transform the vertices of the mesh model from the view space to the homogeneous clip space.
[0022] Furthermore, in step 1.2, in the OpenGL environment, after the mesh model vertices are transformed to the secondary clip space, the range of the three-axis coordinates is within the range of positive and negative w components, and no additional adjustment is required; while in the DirectX environment, the range of xy-axis values is positive and negative w components by default, and the z-axis is in the range of w to 0 or 0 to w depending on whether the reverse z buffer feature is enabled. Therefore, the z-axis component needs to be adjusted to the same range of positive and negative w components as the xy-axis using different mappings as needed.
[0023] Furthermore, the specific method for step 2 is as follows:
[0024] Step 2.1: In the geometry shader, obtain the three vertices ABC that constitute a triangle primitive, calculate vectors BA and CA, and then perform a cross product operation on vectors BA and CA:
[0025] The cross product of vectors can obtain another vector perpendicular to the plane containing the two vectors. Here it is used to solve for the surface normal of the triangular primitive. Then, based on the component with the largest absolute value among the xyz components of the surface normal, we can determine in which direction the primitive has the largest projected area.
[0026] Step 2.2: Simplify the three rasterization processes into one pass. In the geometry shader, when it is determined that the plane containing the maximum projected area is not the xy plane, the xyz coordinates of the vertex are swapped instead of the primitive being discarded directly. The operation of swapping the xyz coordinates is essentially the same as placing the camera on the front, side, and top surfaces for voxelization.
[0027] Furthermore, the specific method of step 3 is as follows:
[0028] Step 3.1: Calculate the maximum and minimum values of the three vertices ABC of the triangle primitive in screen space on the xyz components to solve for the AABB bounding box of the primitive, and extend the AABB bounding box by one pixel width.
[0029] Step 3.2: Expand the primitive along the normal direction of the three sides of the triangle primitive. Specifically, based on the normal direction of each edge, find the half diagonal line in the same quadrant as the normal line, then expand and translate the edge by one pixel width along the half diagonal line, and finally calculate the intersection of the three expanded edges to obtain the wrapping triangle of the original triangle primitive.
[0030] Step 3.3: Use the bounding triangle as the output primitive of the geometry shader and send the AABB bounding box information to the fragment shader. In the fragment shader, determine whether the screen space vertex position is within the AABB bounding box, remove fragments located outside the AABB bounding box, and finally obtain the optimal single-pixel width bounding polygon of the original triangle primitive.
[0031] Furthermore, in step 3.1, the pixel width (pixelWidth) is as follows:
[0032] pixelWidth=(1 / ScreenWidth)*posCS.w
[0033] Where ScreenWidth is the screen pixel resolution; posCS is the coordinate of the mesh model vertex in clip space, and w is its fourth component;
[0034] To ensure that the AABB box is precisely expanded by one pixel width after being converted to screen space, the inverse operation of homogeneous division is performed on pixelWidth, multiplied by the w component of the current vertex.
[0035] Furthermore, the specific method of step 4 is as follows:
[0036] Step 4.1: To address resource contention issues, various graphics APIs provide largely similar functions for controlling resource access.
[0037] Step 4.2: Use Compute Shader, i.e., the GPGPU program, to further process the voxel map obtained during the rasterization process and obtain the cumulative value of primitive information stored in each voxel position. If the data has been converted from floating-point to unsigned integer, it needs to be divided by the preset precision to convert it back to floating-point type, and then divided by the number of primitives that provide information to obtain the final data information of the voxel.
[0038] The beneficial effects of adopting the above technical solution are as follows: The scene voxelization method based on GPU rasterizers provided by this invention simplifies the original multi-pass voxelization process into a single pass by utilizing the technique of flipping the primitive orientation based on the maximum projected area of the primitive in the geometry shader. This greatly improves the running speed of the voxelization method, making it very suitable for real-time applications. At the same time, operations such as conservative rasterization of extended primitives ensure the accuracy of the voxelization results, providing a fast and relatively accurate voxelization scheme for scenes. The scene voxelization scheme with strong real-time performance and high accuracy provided by this invention basically meets the running speed requirements of real-time application environments such as games. After voxelizing the scene using this scheme, the voxel information of the scene can be used for calculations such as global illumination calculation, ambient occlusion calculation, and collision detection, and can be widely applied in fields such as video games and industrial simulation. Attached Figure Description
[0039] Figure 1 A flowchart of a scene voxelization method based on a GPU rasterizer provided in an embodiment of the present invention;
[0040] Figure 2 A schematic diagram illustrating the voxel gap problem in different results of voxelizing the same primitive from three different perspectives, as provided in an embodiment of the present invention.
[0041] Figure 3 This is a schematic diagram of the optimal single-pixel width of the original triangular primitive wrapping the polygon, provided in an embodiment of the present invention. Detailed Implementation
[0042] The specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples. The following examples are for illustrative purposes only and are not intended to limit the scope of the invention.
[0043] like Figure 1 As shown, the method of this embodiment is described below.
[0044] A scene voxelization method based on GPU rasterizers includes the following steps:
[0045] Step 1: Transform the spatial position of the mesh model objects to homogeneous clip space; the specific method is as follows:
[0046] Step 1.1: The original vertex data stored in the mesh model are all in the object coordinate system centered on the custom pivot point of the mesh. To calculate the voxel space index of the vertices after the mesh model is converted into voxels, the vertex positions of the mesh model need to be transformed into the secondary clipping space through a spatial transformation. This process requires the use of the MVP matrix.
[0047]
[0048]
[0049]
[0050] Among them, T x T y T z S represents the coordinates of the origin of the mesh model space in world space; x S y S z R represents the stretching of the mesh model along each axis in world space; R, U, and Dir represent the x, y, and z axes of the view space in world space, with different subscripts representing different components; P represents the coordinates of the camera origin in world space, with different subscripts representing different components; l and r represent the left and right boundary values of the orthogonal camera's view frustum in view space, respectively; t and b represent the upper and lower boundary values of the orthogonal camera's view frustum in view space, respectively; and f and n represent the near and far boundary values of the orthogonal camera's view frustum in view space, respectively.
[0051] The specific transformation sequence is as follows: first, through the Model matrix M... model Transform the vertex positions of the mesh model from model space to world space to obtain the absolute positions with the world space origin as the axis, which facilitates determining the relative relationships between different mesh models; then, use the View matrix M... viewport The vertices of the mesh model are transformed from world space to view space, intuitively describing the relative positions of the mesh model vertices and the camera center; finally, an orthogonal projection matrix M is used. ortho The vertices of the mesh model are transformed from the view space to the homogeneous clip space. This homogeneous clip space is mainly used to clip the rendered primitives. Primitives that are completely within the view frustum are retained, primitives that are outside the view frustum are removed, and primitives that intersect with the view frustum boundary are clipped, and new vertices are generated at the boundary.
[0052] Step 1.2: To ensure the algorithm functions correctly in subsequent steps, the final homogeneous clip space model vertex positions need to be processed according to platform differences, guaranteeing consistent x, y, and z coordinate ranges for each vertex. In the OpenGL environment, after transforming the mesh model vertices to the second clip space, the coordinate ranges for all three axes are within the positive and negative w components, requiring no additional adjustment. However, in the DirectX environment, the x and y axes default to positive and negative w components, while the z-axis ranges from w to 0 or from 0 to w depending on whether the inverse z-buffer is enabled. Therefore, the z-axis component needs to be adjusted using different mappings to match the positive and negative w component range of the x and y axes.
[0053] Step 2: Use a technique based on flipping primitives using the maximum projection plane to solve the voxel gap problem caused by the grazing angle between the primitive and the camera direction; the specific method is as follows:
[0054] Step 2.1: In the geometry shader, obtain the three vertices ABC that constitute a triangle primitive, calculate vectors BA and CA, and then perform a cross product operation on vectors BA and CA:
[0055] The cross product of vectors yields another vector perpendicular to the plane containing the two vectors. Here, it is used to solve for the surface normal of a triangular primitive. Then, based on the component with the largest absolute value among the xyz components of the surface normal, we can determine in which direction the primitive has the largest projected area. For example, when the absolute value of the x-axis component is the largest, the projected area of the primitive on the yz plane is the largest, and the same applies when the absolute value of the yz-axis component is the largest.
[0056] Step 2.2: During voxelization, due to the grazing angle between the primitives and the camera's viewpoint, the following will occur: Figure 2 The voxel gap problem shown, Figure 2 The example demonstrates different results of voxelizing the same primitive from three different viewpoints. Traditionally, the camera is positioned at the front, side, and top to align with the voxelization area, performing three voxelization passes. In each pass, if the geometry shader determines that the plane containing the primitive's maximum projected area is not an xy-plane, the primitive is discarded to ensure that it is only voxelized when its maximum projection axis overlaps with the camera's viewpoint, thus avoiding voxel gaps. However, this approach involves three voxelization passes for the same model mesh, tripling the number of draw calls and severely impacting performance. A more optimized approach simplifies the three rasterization passes into a single pass. Instead of discarding the primitive, when the geometry shader determines that the plane containing the maximum projected area is not an xy-plane, the xyz coordinates of the vertex are swapped. Swapping the xyz coordinates is essentially the same as voxelizing from the front, side, and top, thus simplifying the original three-pass rasterization process into a single pass.
[0057] Step 3: Use a conservative rasterization technique that extends the primitive edges to solve the voxel gap problem caused by the primitive only covering a part of the voxel and not the center of the voxel; the specific method is as follows:
[0058] Step 3.1: Calculate the maximum and minimum values of the three vertices A, B, C of the triangular primitive in screen space on the x, y, and z components to solve for the AABB bounding box of the primitive, and then extend the AABB bounding box by one pixel width:
[0059] pixelWidth=(1 / ScreenWidth)*posCS.w
[0060] Where ScreenWidth is the screen pixel resolution; posCS is the coordinates of the mesh model vertex in clip space, and w is its fourth component.
[0061] Because the AABB box calculation is performed in the geometry shader, the vertex position has not yet undergone homogeneous division. Therefore, the vertex position is actually in the homogeneous clip space rather than the screen space. In order to ensure that the AABB box is accurately expanded by one pixel width after being converted to screen space, the inverse operation of homogeneous division is performed on pixelWidth, which is multiplied by the w component of the current vertex.
[0062] Step 3.2: Expand the primitive along the normal direction of the three sides of the triangle primitive. Specifically, based on the normal direction of each edge, find the half diagonal line in the same quadrant as the normal line, then expand and translate the edge by one pixel width along the half diagonal line, and finally calculate the intersection of the three expanded edges to obtain the wrapping triangle of the original triangle primitive.
[0063] Step 3.3: Use the bounding triangle as the output primitive of the geometry shader, and send the AABB bounding box information to the fragment shader. In the fragment shader, determine whether the screen space vertex position is within the AABB bounding box, and remove fragments located outside the AABB bounding box. Finally, obtain the optimal single-pixel width bounding polygon of the original triangle primitive, such as... Figure 3 As shown.
[0064] Step 4: Calculate the average value of all primitive information, assuming that all primitives covering the voxel contribute to the voxel to the same degree, and introduce access control and data transformation operations; the specific method is as follows:
[0065] Step 4.1: To address resource contention issues, graphics APIs such as OpenGL and DirectX provide similar functions for controlling resource access. For example, DirectX provides a series of functions called InterlockedXXX to ensure that only one fragment can access a resource at a given location at a time, resolving resource contention problems. The fragment shader will use the InterlockedAdd function to record the contribution of all primitive information in each voxel, as well as the total number of primitives providing the information, for later averaging calculations. Here, a data type conversion issue arises. InterlockedAdd only supports operations on unsigned integers, while much of the primitive information, such as color and normal orientation, is of floating-point type. Therefore, it is necessary to first multiply the floating-point number by a pre-set precision value and round it to an integer type before performing the InterlockedAdd operation.
[0066] Step 4.2: Use Compute Shader, i.e., the GPGPU program, to further process the voxel map obtained during the rasterization process and obtain the cumulative value of primitive information stored in each voxel position. If the data has been converted from floating-point to unsigned integer, it needs to be divided by the preset precision to convert it back to floating-point type, and then divided by the number of primitives that provide information to obtain the final data information of the voxel.
[0067] This embodiment utilizes the technique of flipping the orientation of primitives based on their maximum projected area in the geometry shader to simplify the original multi-pass voxelization process into a single pass, greatly improving the running speed of the voxelization method. This makes it very suitable for real-time applications. At the same time, operations such as conservative rasterization of extended primitives ensure the accuracy of the voxelization results, providing a fast and relatively accurate voxelization solution for the scene.
[0068] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope defined by the claims of the present invention.
Claims
1. A scene voxelization method based on GPU rasterizers, characterized in that: Includes the following steps Step 1: Transform the spatial position of the mesh model objects to homogeneous clip space; Step 2: Flip the primitive based on its maximum projection surface; the specific method is as follows: Step 2.1: In the geometry shader, obtain the three vertices ABC that constitute a triangle primitive, calculate vectors BA and CA, and then perform a cross product operation on vectors BA and CA: The cross product of vectors can obtain another vector perpendicular to the plane containing the two vectors. Here it is used to solve for the surface normal of the triangular primitive. Then, based on the component with the largest absolute value among the xyz components of the surface normal, we can determine in which direction the primitive has the largest projected area. Step 2.2: Simplify the three rasterization processes into one pass. In the geometry shader, if it is determined that the plane containing the maximum projected area is not the xy plane, the xyz coordinates of the vertex are swapped. Step 3: Rasterize using extended primitive edges; the specific method is as follows: Step 3.1: Calculate the maximum and minimum values of the three vertices ABC of the triangle primitive in screen space on the xyz components to solve for the AABB bounding box of the primitive, and extend the AABB bounding box by one pixel width. Step 3.2: Expand the primitive along the normal direction of the three sides of the triangle primitive. Specifically, based on the normal direction of each edge, find the half diagonal line in the same quadrant as the normal line, then expand and translate the edge by one pixel width along the half diagonal line, and finally calculate the intersection of the three expanded edges to obtain the wrapping triangle of the original triangle primitive. Step 3.3: Use the bounding triangle as the output primitive of the geometry shader and send the AABB bounding box information to the fragment shader. In the fragment shader, determine whether the screen space vertex position is within the AABB bounding box, remove fragments located outside the AABB bounding box, and finally obtain the optimal single-pixel width bounding polygon of the original triangle primitive. Step 4: Calculate the average value of all graphic element information, and perform access control and data transformation.
2. The scene voxelization method based on GPU rasterizer according to claim 1, characterized in that: The specific method for step 1 is as follows: Step 1.1: Transform the vertex positions of the mesh model into homogeneous clip space through spatial transformation. The specific transformation order is as follows: First, transform the vertex positions of the mesh model from model space to world space to obtain the absolute positions with the origin of world space as the axis; then, transform the vertices of the mesh model from world space to view space; finally, transform the vertices of the mesh model from view space to homogeneous clip space. In homogeneous clip space, the rendered primitives are clipped. Primitives that are completely within the view frustum are retained, primitives that are outside the view frustum are removed, and primitives that intersect with the boundary of the view frustum are clipped, and new vertices are generated at the boundary. Step 1.2: Process the vertex positions of the final homogeneous clipping space model according to platform differences to ensure that the xyz coordinate values of the vertex positions are consistent.
3. The scene voxelization method based on GPU rasterizer according to claim 2, characterized in that: In step 1.1, the vertex positions of the mesh model are transformed into homogeneous clipping space through spatial transformation, which requires the use of the MVP matrix: ; ; ; Among them, T x T y T z S represents the coordinates of the origin of the mesh model space in world space; x S y S z R represents the stretching of the mesh model along each axis in world space; R, U, and Dir represent the x, y, and z axes of the view space in world space, with different subscripts representing different components; P represents the coordinates of the camera origin in world space, with different subscripts representing different components; l and r represent the left and right boundary values of the orthogonal camera's view frustum in view space, respectively; t and b represent the upper and lower boundary values of the orthogonal camera's view frustum in view space, respectively; and f and n represent the near and far boundary values of the orthogonal camera's view frustum in view space, respectively. Through the Model matrix M model Transform the vertex positions of the mesh model from model space to world space using the View matrix M. viewport The vertices of the mesh model are transformed from world space to view space using an orthogonal projection matrix M. ortho Transform the vertices of the mesh model from the view space to the homogeneous clip space.
4. The scene voxelization method based on GPU rasterizer according to claim 2, characterized in that: In step 1.2, in the OpenGL environment, after the mesh model vertices are transformed to homogeneous clip space, the range of the three-axis coordinates is within the range of positive and negative w components, and no additional adjustment is required. However, in the DirectX environment, the range of x and y axes is positive and negative w components by default, while the z axis is in the range of w to 0 or 0 to w depending on whether the inverse z buffer feature is enabled. Therefore, the z axis component needs to be adjusted to the same range of positive and negative w components as the x and y axes using different mappings as needed.
5. The scene voxelization method based on GPU rasterizer according to claim 1, characterized in that: In step 3.1, the pixel width (pixelWidth) is as follows: ; Where ScreenWidth is the screen pixel resolution; posCS is the coordinate of the mesh model vertex in clip space, and w is its fourth component; To ensure that the AABB box is precisely expanded by one pixel width after being converted to screen space, the inverse operation of homogeneous division is performed on pixelWidth, multiplied by the w component of the current vertex.
6. The scene voxelization method based on GPU rasterizer according to claim 1, characterized in that: The specific method for step 4 is as follows: Step 4.1: Control resource access to ensure that only one fragment program can access the resource at a specified location at any given time; Step 4.2: Use Compute Shader, i.e., the GPGPU program, to further process the voxel map obtained during the rasterization process and obtain the cumulative value of primitive information stored in each voxel position. If the data has been converted from floating-point to unsigned integer, it needs to be divided by the preset precision to convert it back to floating-point type, and then divided by the number of primitives that provide information to obtain the final data information of the voxel.