A three-dimensional rendering method, apparatus, device and medium
By using spatially managed octrees and view frustum culling techniques in complex industrial scenarios, the problems of model over-drawing and resource waste were solved, achieving efficient 3D rendering effects.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CISDI ENGINEERING CO LTD
- Filing Date
- 2023-09-18
- Publication Date
- 2026-06-16
AI Technical Summary
Existing technologies suffer from problems such as over-drawing of models, insufficient CPU/GPU collaborative computing, waste of computing resources, and low rendering efficiency in 3D rendering of complex industrial scenes.
A spatial management octree is used for 3D spatial partitioning, and combined with view frustum culling and occlusion culling techniques, CPU and GPU resource allocation is optimized and rendering efficiency is improved by constructing a spatial management octree, view frustum, and occlusion query.
It effectively solves the problem of over-drawing models in complex scenes, improves the rendering efficiency of 3D models, and achieves real-time rendering effects.
Smart Images

Figure CN117237502B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of three-dimensional graphics technology, and in particular to a three-dimensional rendering method, apparatus, device, and medium. Background Technology
[0002] With the continuous improvement of computer hardware performance and ongoing research in computer graphics, 3D rendering technology has made tremendous progress. However, in large-scale industrial scenarios, such as the steel metallurgy industry, a factory with a complete steel production process needs to include multiple production systems such as raw material yards, ironmaking workshops, steelmaking workshops, continuous casting workshops, and rolling mills. Each production system has a large number of production equipment responsible for different processes, making the scene extremely complex, with numerous types of equipment models requiring high precision. For real-time 3D rendering of such scenes, the computational load is too enormous; brute-force drawing of every object is extremely impractical. Even with the inclusion of some basic culling algorithms, achieving real-time rendering results is difficult.
[0003] Currently, traditional rendering techniques suffer from problems such as over-drawing models, insufficient CPU / GPU collaborative computing, wasted computing resources, and low graphics rendering efficiency. Therefore, how to better determine which models should be drawn in each frame and rationally allocate CPU and GPU resources to improve rendering efficiency is a problem that needs further research. Summary of the Invention
[0004] In view of the shortcomings of the prior art described above, the purpose of this invention is to provide a three-dimensional rendering method, apparatus, device and medium to solve the problem of how to improve rendering efficiency in the prior art.
[0005] To achieve the above and other related objectives, the present invention provides a three-dimensional rendering method, comprising the following steps:
[0006] Obtain the model data of the scene model to be rendered, and construct a spatial management octree based on the model data;
[0007] The space management octree is used to perform three-dimensional space partitioning, and based on the three-dimensional space partitioning results of the space management octree and the view frustum constructed in advance or in real time, view frustum culling and occlusion culling are performed on the scene model to be rendered.
[0008] Based on the results of view frustum culling and occlusion culling, the scene model to be rendered is rendered in 3D.
[0009] In one embodiment of the present invention, the process of constructing a spatially managed octree based on the model data includes:
[0010] The model data is parsed to read the position information of each original rendering model; wherein, the scene model to be rendered includes multiple original rendering models;
[0011] Based on the position information of each original rendering model, a spatial management octree is recursively constructed for the scene model to be rendered; and...
[0012] Stop recursion when the recursion depth is greater than or equal to the preset depth; or stop recursion when there is only one object in each original rendered model.
[0013] The space management octree constructed recursively contains multiple parent nodes, with each original rendering model corresponding to one parent node; each parent node has multiple child nodes, and the sum of the volume elements of all child nodes corresponding to each parent node is equal to the volume of the corresponding parent node.
[0014] In one embodiment of the present invention, after stopping recursion, the method further includes:
[0015] Each original rendered model is treated as a cube subspace, and a cube space with a side length twice that of the current cube subspace is defined as the outer boundary.
[0016] Calculate the circumsphere of the cube subspace as a bounding sphere for approximating the original rendered model; and,
[0017] To calculate the octree node levels that need to be inserted for each bounding sphere, we have: In the formula, Indicates the node level of an octree; This represents the side length of the parent node of the octree; Indicates the diameter of the enclosing sphere;
[0018] Find the parent node in the octree node hierarchy that contains the center of the sphere, and traverse the found parent node to determine whether there are child nodes;
[0019] If a child node exists among the found parent nodes, then when the inner boundary contains the center of the bounding sphere and the bounding sphere is within the outer boundary, the bounding sphere is stored in the child node, resulting in a space-managed relaxed octree; wherein, the inner boundary is composed of the cube subspace;
[0020] If the found parent node does not have any child nodes, then the bounding sphere is stored in the parent node to obtain a space-managed relaxed octree.
[0021] In one embodiment of the present invention, the process of frustum culling of the scene model to be rendered, based on the three-dimensional spatial partitioning result of the space management octree and the view frustum constructed in advance or in real time, includes:
[0022] Acquire the shooting parameters of the image capturing device in a three-dimensional spatial scene, and construct a view frustum representing the visible area in the three-dimensional spatial scene based on the shooting parameters; wherein the shooting parameters include at least one of the following: position information, shooting direction or viewing direction, near plane, far plane;
[0023] Based on the three-dimensional spatial partitioning result of the space management octree, the parent node of the space management octree is determined;
[0024] Perform an intersection test between the parent node of the space management octree and the view frustum, and filter out the parent nodes from the space management octree that do not intersect with the view frustum; and,
[0025] View frustum culling is performed on the scene model to be rendered based on the parent node that does not intersect with the view frustum.
[0026] In one embodiment of the present invention, the process of performing frustum culling on the scene model to be rendered further includes:
[0027] With projection matrix This refers to the viewing cone;
[0028] Based on the projection matrix The coordinates of the image capturing device in a three-dimensional scene. Perform a projection transformation to obtain the coordinate points. Homogeneous coordinates in clip space ,have:
[0029]
[0030] Traverse the original rendering models corresponding to the parent nodes that intersect with the view frustum, and denote them as the target rendering models;
[0031] The eight vertices of the bounding box of the target rendering model are projected and transformed, and it is determined whether all vertices are within the clipping space after the projection transformation; and if not all vertices are within the clipping space after the projection transformation, the scene model to be rendered is frustum culled again according to the corresponding parent node or target rendering model.
[0032] In one embodiment of the present invention, the process of occlusion culling of the scene model to be rendered includes:
[0033] Perform occlusion query on the bounding box of the scene model to be rendered after frustum culling to obtain the corresponding occlusion query results;
[0034] Based on the occlusion query results, occlusion culling is performed on the scene model to be rendered.
[0035] In one embodiment of the present invention, the process of performing 3D rendering of the scene model to be rendered based on the view frustum culling result and the occlusion culling result includes:
[0036] The frustum culling and occlusion culling results are obtained, and the bounding box of the scene model to be rendered after occlusion culling is bound to the preset rendering pipeline. The model then goes through the vertex stage, rasterization, fragment stage and per-pixel stage in sequence to perform 3D rendering of the scene model.
[0037] The present invention also provides a three-dimensional rendering apparatus, the apparatus comprising:
[0038] The scene management module is used to obtain the model data of the scene model to be rendered, and to construct a spatial management octree based on the model data;
[0039] The culling module is used to perform three-dimensional space partitioning using the space management octree, and to perform view frustum culling and occlusion culling on the scene model to be rendered based on the three-dimensional space partitioning result of the space management octree and the view frustum constructed in advance or in real time.
[0040] The rendering module is used to perform 3D rendering of the scene model to be rendered based on the frustum culling results and occlusion culling results.
[0041] The present invention also provides a three-dimensional rendering device, comprising:
[0042] processor; and,
[0043] A computer-readable medium storing instructions that, when executed by the processor, cause the device to perform a 3D rendering method as described above.
[0044] The present invention also provides a computer-readable medium having instructions stored thereon, the instructions being loaded by a processor and executed as described in any of the above three-dimensional rendering methods.
[0045] As described above, the present invention provides a 3D rendering method, apparatus, device, and medium, which has the following beneficial effects: The present invention first acquires model data of the scene model to be rendered and constructs a spatial management octree based on the model data; then, it uses the spatial management octree to perform 3D spatial partitioning, and performs view frustum culling and occlusion culling on the scene model to be rendered based on the 3D spatial partitioning results of the spatial management octree and the view frustums constructed in advance or in real time; finally, it performs 3D rendering of the scene model to be rendered based on the view frustum culling results and occlusion culling results. Therefore, the present invention can solve the over-rendering problem caused by the scene model being located outside the view frustum and mutual occlusion between scene models in complex rendering scenes, thereby improving the rendering efficiency of 3D models in complex scenes and achieving real-time rendering. Attached Figure Description
[0046] Figure 1 This is a schematic diagram illustrating an exemplary system architecture for applying the technical solutions in one or more embodiments of the present invention;
[0047] Figure 2 This is a flowchart illustrating a three-dimensional rendering method provided in one embodiment of the present invention;
[0048] Figure 3 This is a flowchart illustrating a three-dimensional rendering method provided in another embodiment of the present invention;
[0049] Figure 4 This is a schematic diagram of the cone removal process provided in one embodiment of the present invention;
[0050] Figure 5 This is a schematic diagram of the occlusion removal process provided in one embodiment of the present invention;
[0051] Figure 6 This is a schematic diagram of the hardware structure of a three-dimensional rendering device provided in one embodiment of the present invention;
[0052] Figure 7 This is a schematic diagram of the hardware structure of a three-dimensional rendering device provided in another embodiment of the present invention;
[0053] Figure 8 This is a schematic diagram of the hardware structure of a 3D rendering device suitable for implementing one or more embodiments of the present invention. Detailed Implementation
[0054] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that, unless otherwise specified, the following embodiments and features described therein can be combined with each other.
[0055] It should be noted that the illustrations provided in this embodiment are only schematic representations of the basic concept of the present invention. Therefore, the drawings only show the components related to the present invention and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.
[0056] Figure 1 A schematic diagram of an exemplary system architecture that can apply the technical solutions of one or more embodiments of the present invention is shown. Figure 1 As shown, the system architecture 100 may include terminal device 110, network 120, and server 130. Terminal device 110 may include various electronic devices such as smartphones, tablets, laptops, and desktop computers. Server 130 may be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. Network 120 may be a communication medium of various connection types capable of providing a communication link between terminal device 110 and server 130, such as a wired communication link or a wireless communication link.
[0057] Depending on the implementation requirements, the system architecture in this embodiment of the invention can have any number of terminal devices, networks, and servers. For example, server 130 can be a server group composed of multiple server devices. Furthermore, the technical solutions provided in this embodiment of the invention can be applied to terminal device 110, or to server 130, or can be implemented jointly by terminal device 110 and server 130; this invention does not impose any special limitations on these applications.
[0058] In one embodiment of the present invention, the terminal device 110 or server 130 can acquire model data of the scene model to be rendered and construct a spatial management octree based on the model data; perform three-dimensional spatial partitioning using the spatial management octree; and perform view frustum culling and occlusion culling on the scene model to be rendered based on the three-dimensional spatial partitioning result of the spatial management octree and the view frustum constructed in advance or in real time; and perform three-dimensional rendering of the scene model to be rendered based on the view frustum culling result and the occlusion culling result. By using the terminal device 110 or server 130 to execute the three-dimensional rendering method, the over-rendering problem caused by the scene model to be rendered being located outside the view frustum and the mutual occlusion between scene models to be rendered in complex rendering scenes can be solved, thereby improving the rendering efficiency of three-dimensional models in complex scenes and achieving the effect of real-time rendering.
[0059] The above section introduced an exemplary system architecture for applying the technical solution of this invention. Next, we will continue to introduce the three-dimensional rendering method of this invention.
[0060] Figure 2 A schematic flowchart of a three-dimensional rendering method according to an embodiment of the present invention is shown. Specifically, in an exemplary embodiment, as follows... Figure 2 As shown, this embodiment provides a 3D rendering method, which includes the following steps:
[0061] S210: Obtain the model data of the scene model to be rendered, and construct a space management octree based on the model data;
[0062] S220 uses a space management octree to partition the 3D space, and performs view frustum culling and occlusion culling on the scene model to be rendered based on the 3D space partitioning results of the space management octree and the view frustums built in advance or in real time.
[0063] S230 performs 3D rendering of the scene model to be rendered based on the results of view frustum culling and occlusion culling.
[0064] Therefore, this embodiment can solve the over-drawing problem caused by the scene model being located outside the view frustum and the mutual occlusion between scene models in complex rendering scenarios, thereby improving the rendering efficiency of 3D models in complex scenarios and achieving the effect of real-time rendering.
[0065] In an exemplary embodiment, step S210, which involves constructing a spatial management octree based on model data, includes:
[0066] The model data is parsed to read the position information of each original rendering model; the scene model to be rendered includes multiple original rendering models.
[0067] Based on the position information of each original rendered model, a spatial management octree is recursively constructed for the scene model to be rendered; and the recursion stops when the recursion depth is greater than or equal to a preset depth. Alternatively, based on the position information of each original rendered model, a spatial management octree is recursively constructed for the scene model to be rendered; and the recursion stops when each original rendered model contains only one object.
[0068] The space management octree constructed recursively contains multiple parent nodes, with each original rendering model corresponding to one parent node; each parent node has multiple child nodes, and the sum of the volume elements of all child nodes corresponding to each parent node is equal to the volume of the corresponding parent node.
[0069] According to the above description, in an exemplary embodiment, after stopping recursion, this embodiment may further include:
[0070] Each original rendered model is treated as a cube subspace, and a cube space with a side length twice that of the current cube subspace is defined as the outer boundary.
[0071] Calculate the circumsphere of the cube subspace as the bounding sphere used to approximate the original rendered model; and calculate the octree node levels to be inserted for each bounding sphere, as follows: In the formula, Indicates the node level of an octree; This represents the side length of the parent node of the octree; This indicates the diameter of the sphere.
[0072] Find the parent node in the octree node hierarchy that contains the center of the sphere, and traverse the found parent node to determine whether there are child nodes.
[0073] If a parent node has a child node, then when the inner boundary contains the center of the bounding sphere and the bounding sphere is inside the outer boundary, the bounding sphere is stored in the child node, resulting in a space-managed relaxed octree; where the inner boundary is composed of a cube subspace.
[0074] If the found parent node does not have any child nodes, then the bounding sphere is stored in the parent node, resulting in a space-managed relaxed octree.
[0075] Therefore, in order to prevent the original rendering model located at the intersection of nodes from being divided into the upper-level nodes, this embodiment defines an outer boundary with a side length twice that of the current space when determining whether the original rendering model is in a certain space, and uses this as a determination condition, thereby obtaining a space-managed relaxed octree.
[0076] In an exemplary embodiment, step S220, which involves frustum culling of the scene model to be rendered based on the three-dimensional spatial partitioning result of the spatial management octree and the pre-built or real-time constructed frustums, includes:
[0077] The imaging parameters of the image capturing device in the three-dimensional spatial scene are obtained, and a view frustum representing the visible area in the three-dimensional spatial scene is constructed based on the imaging parameters; wherein the imaging parameters include at least one of the following: position information, shooting direction or viewing direction, near plane, far plane.
[0078] Based on the three-dimensional spatial partitioning results of the spatial management octree, the parent node of the spatial management octree is determined.
[0079] The spatial management octree is subjected to an intersection test with the view frustum, and parent nodes that do not intersect with the view frustum are selected from the spatial management octree; and view frustum culling is performed on the scene model to be rendered based on the parent nodes that do not intersect with the view frustum.
[0080] Therefore, this embodiment can construct a view frustum representing the visible area based on parameters such as the camera's location, viewing direction, near plane, and far plane in the 3D scene, and establish an axis-aligned bounding box for the view frustum. The bounding box of the view frustum is then subjected to an intersection test with the constructed spatially managed relaxed octree to determine the intersecting nodes. During the intersection test, this embodiment can traverse the nodes and view frustum for testing. The test results include three categories: disjoint, intersecting, and containing. If the test result is disjoint, the intersection test for all child nodes under that node can be skipped. If the test result is containing, all child nodes under that node can be considered intersecting, and the intersection test for the child nodes is also skipped. If the test result is intersecting, the child nodes will continue to be traversed for relevant tests.
[0081] According to the above description, in an exemplary embodiment, step S220, which involves frustum culling of the scene model to be rendered, further includes:
[0082] With projection matrix Indicates the visual cone;
[0083] Based on projection matrix The coordinates of the image capturing device in a three-dimensional scene. Perform a projection transformation to obtain the coordinate points. Homogeneous coordinates in clip space ,have:
[0084]
[0085] Traverse the original rendering models corresponding to the parent nodes that intersect with the view frustum, and denote them as the target rendering models;
[0086] Perform a projection transformation on the eight vertices of the bounding box of the target rendering model, and determine whether all vertices are in clip space after the projection transformation; and if not all vertices are in clip space after the projection transformation, perform view frustum culling on the scene model to be rendered again according to the corresponding parent node or target rendering model.
[0087] In this embodiment, after the transformation, Represents the homogeneous coordinates in clip space. For a point to lie within the view frustum, the following conditions must be met: ; ; Therefore, when performing an inclusion test on the model and the view frustum, the eight vertices of the model's bounding box can be transformed into clip space through projection transformation before performing the inclusion test. If all points are within clip space, the model and the view frustum are in an inclusion relationship; if all points are outside clip space, the result is disjoint.
[0088] In an exemplary embodiment, step S220, which involves occlusion culling of the scene model to be rendered, includes: performing an occlusion query on the bounding box of the scene model to be rendered after frustum culling to obtain the corresponding occlusion query result; and performing occlusion culling on the scene model to be rendered according to the occlusion query result. Furthermore, step S230, which involves performing 3D rendering of the scene model to be rendered based on the frustum culling result and the occlusion culling result, includes: obtaining the frustum culling result and the occlusion culling result, binding the bounding box of the scene model to be rendered after occlusion culling to a preset rendering pipeline, and sequentially performing vertex stage, rasterization, fragment stage, and per-pixel stage to perform 3D rendering of the scene model to be rendered.
[0089] In another exemplary embodiment of the present invention, such as Figure 3 As shown, this embodiment also provides a 3D rendering method, including the following steps:
[0090] S1: Read the texture, geometry, vertex, and other data of the scene model to be rendered. Based on the position data, construct a spatial management octree for the scene to be rendered and perform 3D spatial partitioning. Specifically, the reading of the scene model data to be rendered and the construction of the spatial management octree include the following steps S11-S12.
[0091] S11: Reads various model data of the scene to be rendered from the file, including vertex positions, vertex normals, triangle list, etc. The memory layout for data storage adopts SOA (Struct-of-array), that is, vertex data is stored contiguously in memory, and only the indices of the required vertices are stored in the triangle list. This reduces the scattered storage of data in memory, improves the parallelism during reading, and improves program performance.
[0092] S12: Based on the position information of each model in the scene to be rendered, construct a space management octree recursively. Each node of the octree represents a cube subspace, and each node has eight child nodes. The sum of the volume elements represented by the eight child nodes equals the volume of the parent node. When recursively building the tree, the recursion stops when the set maximum depth is reached or when there is only one object in the subspace.
[0093] In addition, to prevent models located at node intersections from being assigned to upper-level nodes, an outer boundary with a side length twice that of the current space is defined when determining whether a model is in a certain space. This is used as a criterion, i.e., a relaxed octree.
[0094] The insertion of a model into a space-managed relaxed octree involves the following steps:
[0095] 1) Calculate the bounding sphere of the model, used to approximate the model. The diameter is ;
[0096] 2) Calculate the octree node level at which the bounding sphere should be inserted, and find the nodes at that level that contain the center of the bounding sphere. Let the side length of the root node of the octree be... The formula for calculating the node level is:
[0097] ;
[0098] 3) Traverse nodes If there are child nodes The inner boundary contains the surrounding sphere. The center of the sphere, and surrounding the sphere If it is inside the outer boundary, store it in a child node. If it does not exist, then... Stored in nodes Based on the above steps, it can be seen that, compared with the traditional octree, the relaxed octree requires further judgment, namely:
[0099] ;
[0100] S2: Construct a view frustum based on the camera's position in the 3D scene, and perform view frustum culling on the scene to be rendered using the scene management octree. Specifically, as follows... Figure 4 As shown, the construction and removal process of the visual cone includes the following steps S21-22.
[0101] S21: Based on parameters such as the camera's location, viewing direction, near plane, and far plane in the 3D scene, construct a view frustum to represent the visible area, and create an axis-aligned bounding box for the view frustum. Perform an intersection test between the bounding box of the view frustum and the spatially managed relaxed octree constructed in S1 to determine the intersecting nodes.
[0102] When performing an intersection test, the node and the view frustum are traversed for testing. The test results include three possibilities: disjoint, intersecting, and containing. If the test result is disjoint, the intersection test for all child nodes of that node can be skipped. If the test result is containing, all child nodes of that node can be considered intersecting, and the intersection test for child nodes is also skipped. If the test result is intersecting, the child nodes are traversed again, and the relevant tests are performed.
[0103] S22: Traverse all models inside nodes that intersect with the view frustum bounding box, and perform an inclusion test with the view frustum. The camera's view frustum is usually represented in the form of a projection matrix. Assuming the projection matrix is... Points in the camera space After projection transformation, the homogeneous coordinates of the clipping space are obtained as follows: The formula is as follows:
[0104]
[0105] After transformation Represents the homogeneous coordinates in clip space. For a point to lie within the view frustum, the following conditions must be met:
[0106]
[0107]
[0108]
[0109] Therefore, when performing an inclusion test on the model and the view frustum, the eight vertices of the model's bounding box can be transformed into clip space through projection transformation before performing the inclusion test. If all points are within clip space, the model and the view frustum are in an inclusion relationship; if all points are outside clip space, the result is disjoint.
[0110] S3: Using the bounding boxes of the culled models to be rendered, perform GPU-driven occlusion culling on the bounding boxes, and draw the corresponding original model with visibility based on the final culling results. Specifically, such as... Figure 5 As shown, the occlusion query and indirect drawing of the model includes the following steps S31-S33.
[0111] S31: Using the bounding box of the culled model to be rendered, perform occlusion query on the bounding box. To combine scene depth and model occlusion information to further determine the model that actually needs to be drawn in this frame, it is necessary to query the occlusion status of the culled model to obtain occlusion information. First, the bounding box of the model is bound to the rendering pipeline for drawing. The entire drawing process will go through the vertex stage, rasterization, fragment stage, and per-pixel stage in sequence. The fragment stage will perform complex lighting calculations, while the per-pixel stage will perform z-test on the calculated fragment values to determine whether the fragment will eventually be displayed on the screen.
[0112] To avoid overdrawing caused by discarding calculation results after extensive computation in the fragment stage due to failing the pixel-by-pixel depth test, an early-z technique is used in this stage. This technique modifies the traditional rendering pipeline by adding an early-z stage between the rasterization and fragment stages, where a pixel-by-pixel z-test is performed in advance.
[0113] Using the early-z technique, each pixel is an unoccluded pixel to be rendered in the pixel-by-pixel stage. A buffer of the same length as the number of bounding boxes is allocated on the GPU (Graphics Processing Unit). The bounding box IDs corresponding to the pixels entering the pixel-by-pixel stage are recorded, and the results are stored in the corresponding positions of the buffer as boolean values, thus obtaining a buffer located on the GPU that stores the model occlusion results.
[0114] S32: Based on the model occlusion query results, select the corresponding models and add them to the rendering. In order to achieve GPU-driven occlusion culling, the occlusion query results are not transmitted from the GPU to the CPU (Central Processing Unit) for decision-making, but are directly used as filtering information and provided to the buffer of another GPU.
[0115] In addition, a command buffer of the same size is allocated to store all drawing commands for the models to be rendered before occlusion queries, including setting rendering states, drawing geometry, applying shaders, and setting texture parameters. By adding these rendering instructions to the command buffer, the rendering process can be optimized and data transfer between the CPU and GPU can be reduced.
[0116] By combining the data from the model occlusion query and the computation pipeline, the drawing commands corresponding to the models that have passed the occlusion query are filled into another command buffer in a fragment-free, compact manner, thus implementing the BufferDefragment operation. This buffer contains all the drawing commands for the models that need to be drawn within the current frame. It's worth noting that through the computation shaders in the computation pipeline, the entire BufferDefragment operation is performed on the GPU in a multi-threaded, highly parallel manner, processing large amounts of data simultaneously and fully leveraging the GPU's high-speed data exchange and parallel processing capabilities.
[0117] S33: Based on the occlusion culling results, draw the corresponding original model with visibility. In S32, a command buffer containing all the commands to be drawn in this frame and arranged closely together is obtained. For this command buffer, the indirect drawing graphics rendering technique is performed to complete the drawing of all models, including the model's lighting information, geometric information, material information, position information, etc.
[0118] Traditional drawing methods require a complete drawing command before each drawing operation, while indirect drawing uses command data to store the parameters of the drawing command in a buffer and then executes the drawing operation by referencing this buffer. Therefore, this embodiment, through indirect drawing technology, can greatly reduce CPU overhead, dynamically generate drawing commands, and perform batch drawing operations as needed, thereby reducing the overhead of API (Application Programming Interface) calls and improving drawing efficiency.
[0119] In summary, this invention provides a 3D rendering method. First, it acquires model data of the scene to be rendered and constructs a spatial management octree based on the model data. Then, it uses the spatial management octree to perform 3D spatial partitioning. Based on the 3D spatial partitioning results of the spatial management octree and a pre-constructed or real-time built view frustum, it performs view frustum culling and occlusion culling on the scene to be rendered. Finally, based on the view frustum culling and occlusion culling results, it performs 3D rendering of the scene to be rendered. Therefore, this method can solve the over-rendering problem caused by the scene to be rendered being located outside the view frustum and by mutual occlusion between scene models in complex rendering scenes, thereby improving the rendering efficiency of 3D models in complex scenes and achieving real-time rendering.
[0120] like Figure 6 As shown, the present invention also provides a three-dimensional rendering apparatus, comprising:
[0121] Scene management module 610 is used to obtain model data of the scene model to be rendered and construct a spatial management octree based on the model data;
[0122] The culling module 620 is used to perform three-dimensional space partitioning using a space management octree, and to perform view frustum culling and occlusion culling on the scene model to be rendered based on the three-dimensional space partitioning results of the space management octree and the view frustums built in advance or in real time.
[0123] The rendering module 630 is used to perform 3D rendering of the scene model to be rendered based on the results of view frustum culling and occlusion culling.
[0124] Therefore, this embodiment can solve the over-drawing problem caused by the scene model being located outside the view frustum and the mutual occlusion between scene models in complex rendering scenarios, thereby improving the rendering efficiency of 3D models in complex scenarios and achieving the effect of real-time rendering.
[0125] In an exemplary embodiment, the process by which the scene management module 610 constructs a spatial management octree based on model data includes:
[0126] The model data is parsed to read the position information of each original rendering model; the scene model to be rendered includes multiple original rendering models.
[0127] Based on the position information of each original rendered model, a spatial management octree is recursively constructed for the scene model to be rendered; and the recursion stops when the recursion depth is greater than or equal to a preset depth. Alternatively, based on the position information of each original rendered model, a spatial management octree is recursively constructed for the scene model to be rendered; and the recursion stops when each original rendered model contains only one object.
[0128] The space management octree constructed recursively contains multiple parent nodes, with each original rendering model corresponding to one parent node; each parent node has multiple child nodes, and the sum of the volume elements of all child nodes corresponding to each parent node is equal to the volume of the corresponding parent node.
[0129] According to the above description, in an exemplary embodiment, after stopping recursion, this embodiment may further include:
[0130] Each original rendered model is treated as a cube subspace, and a cube space with a side length twice that of the current cube subspace is defined as the outer boundary.
[0131] Calculate the circumsphere of the cube subspace as the bounding sphere used to approximate the original rendered model; and calculate the octree node levels to be inserted for each bounding sphere, as follows: In the formula, Indicates the node level of an octree; This represents the side length of the parent node of the octree; This indicates the diameter of the sphere.
[0132] Find the parent node in the octree node hierarchy that contains the center of the sphere, and traverse the found parent node to determine whether there are child nodes.
[0133] If a parent node has a child node, then when the inner boundary contains the center of the bounding sphere and the bounding sphere is inside the outer boundary, the bounding sphere is stored in the child node, resulting in a space-managed relaxed octree; where the inner boundary is composed of a cube subspace.
[0134] If the found parent node does not have any child nodes, then the bounding sphere is stored in the parent node, resulting in a space-managed relaxed octree.
[0135] Therefore, in order to prevent the original rendering model located at the intersection of nodes from being divided into the upper-level nodes, this embodiment defines an outer boundary with a side length twice that of the current space when determining whether the original rendering model is in a certain space, and uses this as a determination condition, thereby obtaining a space-managed relaxed octree.
[0136] In an exemplary embodiment, the culling module 620 performs view frustum culling on the scene model to be rendered based on the three-dimensional spatial partitioning result of the spatial management octree and the view frustum constructed in advance or in real time.
[0137] The imaging parameters of the image capturing device in the three-dimensional spatial scene are obtained, and a view frustum representing the visible area in the three-dimensional spatial scene is constructed based on the imaging parameters; wherein the imaging parameters include at least one of the following: position information, shooting direction or viewing direction, near plane, far plane.
[0138] Based on the three-dimensional spatial partitioning results of the spatial management octree, the parent node of the spatial management octree is determined.
[0139] The spatial management octree is subjected to an intersection test with the view frustum, and parent nodes that do not intersect with the view frustum are selected from the spatial management octree; and view frustum culling is performed on the scene model to be rendered based on the parent nodes that do not intersect with the view frustum.
[0140] Therefore, this embodiment can construct a view frustum representing the visible area based on parameters such as the camera's location, viewing direction, near plane, and far plane in the 3D scene, and establish an axis-aligned bounding box for the view frustum. The bounding box of the view frustum is then subjected to an intersection test with the constructed spatially managed relaxed octree to determine the intersecting nodes. During the intersection test, this embodiment can traverse the nodes and view frustum for testing. The test results include three categories: disjoint, intersecting, and containing. If the test result is disjoint, the intersection test for all child nodes under that node can be skipped. If the test result is containing, all child nodes under that node can be considered intersecting, and the intersection test for the child nodes is also skipped. If the test result is intersecting, the child nodes will continue to be traversed for relevant tests.
[0141] According to the above description, in an exemplary embodiment, the process of the culling module 620 performing frustum culling on the scene model to be rendered further includes:
[0142] With projection matrix Indicates the visual cone;
[0143] Based on projection matrix The coordinates of the image capturing device in a three-dimensional scene. Perform a projection transformation to obtain the coordinate points. Homogeneous coordinates in clip space ,have:
[0144]
[0145] Traverse the original rendering models corresponding to the parent nodes that intersect with the view frustum, and denote them as the target rendering models;
[0146] Perform a projection transformation on the eight vertices of the bounding box of the target rendering model, and determine whether all vertices are in clip space after the projection transformation; and if not all vertices are in clip space after the projection transformation, perform view frustum culling on the scene model to be rendered again according to the corresponding parent node or target rendering model.
[0147] In this embodiment, after the transformation, Represents the homogeneous coordinates in clip space. For a point to lie within the view frustum, the following conditions must be met: ; ; Therefore, when performing an inclusion test on the model and the view frustum, the eight vertices of the model's bounding box can be transformed into clip space through projection transformation before performing the inclusion test. If all points are within clip space, the model and the view frustum are in an inclusion relationship; if all points are outside clip space, the result is disjoint.
[0148] In an exemplary embodiment, the culling module 620 performs occlusion culling on the scene model to be rendered, including: performing an occlusion query on the bounding box of the scene model to be rendered after frustum culling to obtain the corresponding occlusion query result; and performing occlusion culling on the scene model to be rendered according to the occlusion query result. Furthermore, the rendering module 630 performs 3D rendering of the scene model to be rendered based on the frustum culling result and the occlusion culling result, including: obtaining the frustum culling result and the occlusion culling result, binding the bounding box of the scene model to be rendered after occlusion culling to a preset rendering pipeline, and sequentially performing vertex stage, rasterization, fragment stage, and per-pixel stage to perform 3D rendering of the scene model to be rendered.
[0149] In another exemplary embodiment of the present invention, such as Figure 7 As shown, this embodiment also provides a 3D rendering device, including: a scene management module, a model culling module, and a rendering module.
[0150] The scene management module constructs a spatial management octree for the rendering scene, dividing all models in the scene into the corresponding child nodes of the octree for management.
[0151] The model culling module constructs the scene camera's view frustum and uses an octree to culle models outside the field of view; it also constructs an occlusion query buffer and a command buffer to further culle occluded models.
[0152] The drawing and rendering module uses indirect drawing graphics rendering technology to dynamically generate drawing commands and batch draw the culled models, then output the rendering results.
[0153] In this embodiment, the scene management module can be used to complete all the processes described in steps S1, S11, and S12; the model culling module can be used to complete all the processes described in steps S2, S21, and S22; and the rendering module can be used to complete all the processes described in steps S3, S31, and S32. Therefore, the technical effects or functions of the 3D rendering device in this embodiment can be referred to the embodiments corresponding to the above-described 3D rendering method, and will not be repeated here.
[0154] It should be noted that the 3D rendering apparatus and the 3D rendering method provided in the above embodiments belong to the same concept. The specific methods of execution of each module have been described in detail in the method embodiments and will not be repeated here. In practical applications, the 3D rendering apparatus provided in the above embodiments can be assigned to different functional modules as needed, that is, the internal structure of the apparatus can be divided into different functional modules to complete all or part of the process described in the above 3D rendering method. For example, the scene management module 610 can be used to complete all the processes described in step S210, the culling module 620 can be used to complete all the processes described in step S220, and the rendering module 630 can be used to complete all the processes described in step S230.
[0155] This invention also provides a 3D rendering device, which may include: one or more processors; and one or more machine-readable media storing instructions thereon, which, when executed by the one or more processors, cause the device to perform... Figure 2 / Figure 3 The aforementioned 3D rendering method. Figure 8 A schematic diagram of a 3D rendering device 1000 is shown. (See also...) Figure 8 As shown, the 3D rendering device 1000 includes: a processor 1010, a memory 1020, a power supply 1030, a display unit 1040, and an input unit 1060.
[0156] The processor 1010 is the control center of the 3D rendering device 1000. It connects various components via interfaces and lines, and executes various functions of the 3D rendering device 1000 by running or executing software programs and / or data stored in the memory 1020, thereby providing overall monitoring of the 3D rendering device 1000. In this embodiment of the invention, when the processor 1010 calls the computer program stored in the memory 1020, it executes, for example... Figure 2 / Figure 3 The aforementioned 3D rendering method. Optionally, the processor 1010 may include one or more processing units; preferably, the processor 1010 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. In some embodiments, the processor and memory can be implemented on a single chip; in some embodiments, they can also be implemented separately on independent chips.
[0157] The memory 1020 may primarily include a program storage area and a data storage area. The program storage area may store the operating system, various applications, etc.; the data storage area may store data created based on the use of the 3D rendering device 1000, etc. In addition, the memory 1020 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0158] The 3D rendering device 1000 also includes a power supply 1030 (such as a battery) that supplies power to various components. The power supply can be logically connected to the processor 1010 through a power management system, thereby enabling the management of charging, discharging, and power consumption.
[0159] The display unit 1040 can be used to display information input by the user or information provided to the user, as well as various menus of the 3D rendering device 1000. In this embodiment of the invention, it is mainly used to display the display interfaces of various applications in the 3D rendering device 1000, as well as text, images, and other objects displayed in the display interfaces. The display unit 1040 may include a display panel 1050. The display panel 1050 may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like.
[0160] The input unit 1060 can be used to receive information such as numbers or characters input by the user. The input unit 1060 may include a touch panel 1070 and other input devices 1080. The touch panel 1070, also known as a touch screen, can collect touch operations on or near the user (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel 1070).
[0161] Specifically, the touch panel 1070 can detect user touch operations and the signals generated by these operations, convert them into touch point coordinates, send them to the processor 1010, and receive and execute commands from the processor 1010. Furthermore, the touch panel 1070 can be implemented using various types of sensors, including resistive, capacitive, infrared, and surface acoustic wave sensors. Other input devices 1080 can include, but are not limited to, one or more of the following: physical keyboard, function keys (such as volume control buttons, power buttons, etc.), trackball, mouse, joystick, etc.
[0162] Of course, the touch panel 1070 can cover the display panel 1050. When the touch panel 1070 detects a touch operation on or near it, it transmits the information to the processor 1010 to determine the type of touch event. Subsequently, the processor 1010 provides corresponding visual output on the display panel 1050 based on the type of touch event. Although in Figure 8 In this embodiment, the touch panel 1070 and the display panel 1050 are two independent components to realize the input and output functions of the 3D rendering device 1000. However, in some embodiments, the touch panel 1070 and the display panel 1050 can be integrated to realize the input and output functions of the 3D rendering device 1000.
[0163] The 3D rendering device 1000 may also include one or more sensors, such as pressure sensors, gravity acceleration sensors, proximity sensors, etc. Of course, depending on the specific application requirements, the 3D rendering device 1000 may also include other components such as cameras.
[0164] This invention also provides a computer-readable storage medium storing instructions that, when executed by one or more processors, enable the device to perform the functions described in this invention. Figure 2 / Figure 3 The aforementioned 3D rendering method.
[0165] It will be understood by those skilled in the art that Figure 8 This is merely an example of a 3D rendering device and does not constitute a limitation on the device. The device may include more or fewer components than illustrated, or a combination of certain components, or different components. For ease of description, the above parts are divided into modules (or units) according to their functions and described separately. Of course, in implementing this invention, the functions of each module (or unit) can be implemented in one or more software or hardware components.
[0166] Those skilled in the art will understand that the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. The present invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention, and it should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be applied to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing device, produce implementations of the flowchart illustrations and / or block diagrams. Figure 1One or more processes and / or boxes Figure 1 The computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The functions specified in one or more boxes. These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable apparatus for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0167] It should be understood that although terms such as first, second, third, etc., may be used in the embodiments of the present invention to describe the preset range, these preset ranges should not be limited to these terms. These terms are only used to distinguish the preset ranges from one another. For example, without departing from the scope of the embodiments of the present invention, the first preset range may also be referred to as the second preset range, and similarly, the second preset range may also be referred to as the first preset range.
[0168] The above embodiments are merely illustrative of the principles and effects of the present invention and are not intended to limit the invention. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in the present invention should still be covered by the claims of the present invention.
Claims
1. A three-dimensional rendering method, characterized in that, The method includes the following steps: Obtain the model data of the scene model to be rendered, and construct a spatial management octree based on the model data; The space management octree is used to perform three-dimensional space partitioning, and based on the three-dimensional space partitioning results of the space management octree and the view frustum constructed in advance or in real time, view frustum culling and occlusion culling are performed on the scene model to be rendered. Based on the results of view frustum culling and occlusion culling, the scene model to be rendered is rendered in 3D. The process of constructing a spatial management octree based on the model data includes: parsing the model data and reading the position information of each original rendering model; wherein, the scene model to be rendered includes multiple original rendering models; based on the position information of each original rendering model, constructing a spatial management octree for the scene model to be rendered recursively; and stopping recursion when the recursion depth is greater than or equal to a preset depth; or stopping recursion when each original rendering model has only one object; wherein, the spatial management octree constructed recursively contains multiple parent nodes, each original rendering model corresponds to one parent node; each parent node has multiple child nodes, and the sum of the volume elements of all child nodes corresponding to each parent node is equal to the volume of the corresponding parent node; After stopping recursion, the method further includes: treating each original rendering model as a cube subspace, and defining a cube space with a side length twice that of the current cube subspace as its outer boundary; calculating the circumscribed sphere of the cube subspace as a bounding sphere to approximate the original rendering model; and calculating the octree node levels to be inserted for each bounding sphere, as follows: In the formula, Indicates the node level of an octree; This represents the side length of the parent node of the octree; The diameter of the bounding sphere is represented; the parent node containing the center of the bounding sphere at the node level of the octree is found, and the parent node is traversed to determine whether there is a child node; if there is a child node in the parent node, then when the center of the bounding sphere is contained in the inner boundary and the bounding sphere is within the outer boundary, the bounding sphere is stored in the child node, thus obtaining a space-managed relaxed octree; wherein, the inner boundary is composed of the cube subspace; if there is no child node in the parent node, then the bounding sphere is stored in the parent node, thus obtaining a space-managed relaxed octree.
2. The three-dimensional rendering method according to claim 1, characterized in that, Based on the 3D spatial partitioning results of the space management octree and the pre-built or real-time constructed view frustums, the process of performing view frustum culling on the scene model to be rendered includes: Acquire the shooting parameters of the image capturing device in a three-dimensional spatial scene, and construct a view frustum representing the visible area in the three-dimensional spatial scene based on the shooting parameters; wherein the shooting parameters include at least one of the following: position information, shooting direction or viewing direction, near plane, far plane; Based on the three-dimensional spatial partitioning result of the space management octree, the parent node of the space management octree is determined; Perform an intersection test between the parent node of the space management octree and the view frustum, and filter out the parent nodes from the space management octree that do not intersect with the view frustum; and, View frustum culling is performed on the scene model to be rendered based on the parent node that does not intersect with the view frustum.
3. The three-dimensional rendering method according to claim 2, characterized in that, The process of performing view frustum culling on the scene model to be rendered also includes: With projection matrix This refers to the view frustum; Based on the projection matrix The coordinates of the image capturing device in a three-dimensional scene. Perform a projection transformation to obtain the coordinate points. Homogeneous coordinates in clip space ,have: Traverse the original rendering models corresponding to the parent nodes that intersect with the view frustum, and denote them as the target rendering models; The eight vertices of the bounding box of the target rendering model are projected and transformed, and it is determined whether all vertices are within the clipping space after the projection transformation; and if not all vertices are within the clipping space after the projection transformation, the scene model to be rendered is frustum culled again according to the corresponding parent node or target rendering model.
4. The three-dimensional rendering method according to claim 1 or 3, characterized in that, The process of occlusion culling of the scene model to be rendered includes: Perform occlusion query on the bounding box of the scene model to be rendered after frustum culling to obtain the corresponding occlusion query results; Based on the occlusion query results, occlusion culling is performed on the scene model to be rendered.
5. The three-dimensional rendering method according to claim 4, characterized in that, The process of rendering the scene model to be rendered in 3D based on the frustum culling and occlusion culling results includes: The frustum culling and occlusion culling results are obtained, and the bounding box of the scene model to be rendered after occlusion culling is bound to the preset rendering pipeline. The model then goes through the vertex stage, rasterization, fragment stage and per-pixel stage in sequence to perform 3D rendering of the scene model.
6. A three-dimensional rendering device, characterized in that, The device includes: The scene management module is used to obtain the model data of the scene model to be rendered, and to construct a spatial management octree based on the model data; The process of constructing a spatial management octree based on the model data includes: parsing the model data and reading the position information of each original rendering model; wherein, the scene model to be rendered includes multiple original rendering models; based on the position information of each original rendering model, constructing a spatial management octree for the scene model to be rendered recursively; and stopping recursion when the recursion depth is greater than or equal to a preset depth; or stopping recursion when each original rendering model has only one object; wherein, the spatial management octree constructed recursively contains multiple parent nodes, each original rendering model corresponds to one parent node; each parent node has multiple child nodes, and the sum of the volume elements of all child nodes corresponding to each parent node is equal to the volume of the corresponding parent node; after stopping recursion, it also includes: treating each original rendering model as a cube subspace, and defining a cube space with a side length twice that of the current cube subspace as the outer boundary; calculating the circumscribed sphere of the cube subspace as a bounding sphere used to approximate the original rendering model; and calculating the octree node levels to be inserted for each bounding sphere, including: In the formula, Indicates the node level of an octree; This represents the side length of the parent node of the octree; The diameter of the bounding sphere is represented; the parent node containing the center of the bounding sphere at the node level of the octree is found, and the parent node is traversed to determine whether there is a child node; if the parent node contains a child node, then when the inner boundary contains the center of the bounding sphere and the bounding sphere is within the outer boundary, the bounding sphere is stored in the child node, thus obtaining a space-managed relaxed octree; wherein, the inner boundary is composed of the cube subspace; if the parent node does not contain a child node, then the bounding sphere is stored in the parent node, thus obtaining a space-managed relaxed octree. The culling module is used to perform three-dimensional space partitioning using the space management octree, and to perform view frustum culling and occlusion culling on the scene model to be rendered based on the three-dimensional space partitioning result of the space management octree and the view frustum constructed in advance or in real time. The rendering module is used to perform 3D rendering of the scene model to be rendered based on the frustum culling results and occlusion culling results.
7. A three-dimensional rendering device, characterized in that, include: processor; and, A computer-readable medium storing instructions that, when executed by the processor, cause the device to perform the three-dimensional rendering method as described in any one of claims 1 to 5.
8. A computer-readable medium, characterized in that, It stores instructions that are loaded by a processor and executed as the 3D rendering method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
BIM rendering method and equipment based on lightweight equipment, and computer readable storage medium
CN112347546A
Grid-based loose octree for spatial partitioning
US20030227455A1