Rendering method, system and equipment and storage medium
By finding the target element at the camera position to build an accelerated structure and performing ray tracing shading calculation, the storage consumption problem of ray tracing rendering technology is solved, and the realistic effect of efficient rendering of large-scale three-dimensional scenes is achieved.
Patent Information
- Application Number
- CN202410095619.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-23
- Publication Date
- 2025-07-25
AI Technical Summary
The existing rendering technology based on ray tracing has a large storage consumption problem, making it difficult to render efficiently in large-scale three-dimensional scenes.
By finding target primitives within the preset radius range at the camera position, building an acceleration structure, and emitting simulated ray tracing intersection primitives at the camera position, combining ray tracing chromatography and screen space chromatography calculations to reduce storage consumption.
It effectively reduces storage consumption, improves rendering efficiency, and can display realistic global lighting effects in close-range scenes, and improves rendering speed in long-range scenes.
Smart Images

Figure CN120374819A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer-aided design technology, and in particular, to a rendering method, system, device, and storage medium. Background Art
[0002] In raster rendering technology, usually taking objects as units, the rendering tasks in a three-dimensional scene are divided into multiple subtasks. Each object is composed of several triangular faces. After geometric transformation, these triangular faces are mapped to the specified area of the screen, and then the covered areas of these triangular faces are disassembled into individual pixels. This disassembly process is called rasterization. Based on this task disassembly method, the rendering process can be highly parallelized and has high efficiency. However, in this process, the next layer will lose the understanding of the global information of the previous layer, resulting in unsatisfactory rendering effects in scenes with high requirements for realism.
[0003] To solve the above problems, a rendering technology based on ray tracing has emerged. Specifically, the rendering process based on ray tracing can mainly be: emitting rays from the screen, and after the rays enter the three-dimensional scene to be rendered, determining whether this ray intersects with the objects in the three-dimensional scene. Finally, according to the intersection result, the three-dimensional scene is rendered on the screen. Currently, this rendering technology based on ray tracing has a large storage consumption problem and urgently needs to be solved. Summary of the Invention
[0004] In view of this, embodiments of the present disclosure provide a rendering method, a rendering system, an electronic device, and a computer-readable storage medium, which can reduce storage consumption.
[0005] On the one hand, the present disclosure provides a rendering method, and the method includes:
[0006] According to the camera position and camera orientation when observing the scene to be rendered, starting from the camera position, searching for target primitives within a preset radius range in the camera orientation in the scene to be rendered;
[0007] Constructing an acceleration structure composed of the target primitives;
[0008] Emitting simulated rays passing through each pixel point of the display screen at the camera position, and tracing the simulated rays to obtain intersection primitives in the acceleration structure that have intersections with the simulated rays;
[0009] Based on the intersection primitives, performing ray tracing shading calculations on each of the pixel points, and based on other primitives in the scene to be rendered except the target primitives, performing screen space shading calculations on each of the pixel points, so as to display an image of the scene to be rendered on the display screen.
[0010] In the technical solutions of some embodiments of the present application, target primitives within a preset radius range in the to-be-rendered scene are searched for in the camera orientation, and an acceleration structure composed of the target primitives is constructed. Here, since the acceleration structure is constructed only for some primitives in the to-be-rendered scene, the data volume of the constructed acceleration structure can be greatly reduced, thereby achieving the purpose of reducing storage consumption. On this basis, ray tracing shading calculations are performed on each pixel point based on the intersection primitives in the acceleration structure that intersect with the simulated rays, and screen space shading calculations are performed on each pixel point based on the other primitives in the to-be-rendered scene except the target primitives. In this way, on the one hand, when displaying the image of the to-be-rendered scene on the display screen, it is possible to avoid missing other primitives in the to-be-rendered scene except the target primitives, and a complete image of the to-be-rendered scene can be displayed in the to-be-rendered scene; on the other hand, in a close-range scene, the preset radius can be relatively large, so that the image of the to-be-rendered scene can be mainly displayed on the display screen based on the ray tracing shading calculation results, achieving a more realistic global illumination effect; while in a long-range scene, the preset radius can be relatively small, thereby reducing the search duration of the intersection primitives and improving the rendering efficiency.
[0011] In some embodiments, the emitting of simulated rays passing through each pixel point of the display screen at the camera position includes:
[0012] According to different lighting effects, multiple different simulated rays passing through the same pixel point are emitted at the camera position, where different simulated rays are used to achieve different lighting effects.
[0013] This solution of emitting multiple different simulated rays passing through the same pixel point at the camera position according to different lighting effects can make the obtained intersection primitives more complete, and thus the ray tracing shading calculation results for each pixel point can be more accurate.
[0014] In some embodiments, the simulated rays for achieving different lighting effects have their respective corresponding first shading calculation formulas;
[0015] For any pixel point in the display screen, performing ray tracing shading calculation on this pixel point includes:
[0016] Among the multiple simulated rays passing through this pixel point, the intersection primitives corresponding to each simulated ray with the acceleration structure are respectively determined;
[0017] Based on the primitive information of the intersection primitives corresponding to each simulated ray and the first shading calculation formula, first ray tracing shading calculations are respectively performed on this pixel point;
[0018] The first ray tracing shading calculation results obtained based on different simulated rays are fused, and the fused result is used as the ray tracing shading calculation result of this pixel point.
[0019] Separate first shading calculation formulas are set for the simulated light rays used to achieve different lighting effects, facilitating the adaptive adjustment of the first shading calculation formulas according to different lighting effects, so that the obtained first ray tracing shading calculation results are more in line with the corresponding lighting effect scenarios.
[0020] In some embodiments, the simulated light rays used to achieve different lighting effects also have their respective corresponding second shading calculation formulas;
[0021] The performing ray tracing shading calculation on each of the pixel points includes:
[0022] For any pixel point in the display screen, after a simulated light ray passes through this pixel point, if the simulated light ray has no intersection primitive with the acceleration structure, then according to the second shading calculation formula corresponding to the simulated light ray, perform second ray tracing shading calculation on this pixel point;
[0023] Fuse the second ray tracing shading calculation results obtained based on different simulated light rays, or fuse the first ray tracing shading calculation results and the second ray tracing shading calculation results obtained based on different simulated light rays, and use the fused result as the ray tracing shading calculation result of this pixel point.
[0024] Separate second shading calculation formulas are set for the simulated light rays used to achieve different lighting effects, facilitating the setting of the second shading calculation logic under different lighting effects according to actual needs.
[0025] In some embodiments, the emitting, from the camera position, simulated light rays passing through each pixel point of the display screen and tracing the simulated light rays to obtain the intersection primitives in the acceleration structure that have intersections with the simulated light rays includes:
[0026] Construct multiple different level-of-detail models composed of the target primitives;
[0027] In the multiple different level-of-detail models, based on one of the target level-of-detail models, use the rasterization rendering method to determine the first intersection primitive of each of the simulated light rays with the acceleration structure;
[0028] Taking the first intersection primitive as the starting point, use the ray tracing rendering method to determine the other intersection primitives of each of the simulated light rays with the acceleration structure except the first intersection primitive.
[0029] The rasterization rendering method has high efficiency. Based on the rasterization rendering method to determine the first intersection primitive of the simulated light rays passing through each pixel point of the display screen with the acceleration structure, the efficiency of determining the intersection primitive can be improved.
[0030] In some embodiments, the rasterization rendering method is executed in a central processing unit, and the ray tracing method is executed in a graphics processing unit;
[0031] After determining the first intersection primitive of each simulated ray and the acceleration structure based on the target level of detail model, the method further includes:
[0032] Recording the target level of detail model so that the graphics processing unit executes the ray tracing rendering method based on the recorded target level of detail model.
[0033] In this way, the central processing unit and the graphics processing unit can find the intersection primitive based on the same level of detail model, avoiding the problem that the ray is blocked by the level of detail model itself when the ray tracing rendering method is executed in the graphics processing unit.
[0034] In some embodiments, the ray tracing coloring calculation for each pixel point based on the intersection primitive includes:
[0035] For any pixel point on the display screen, if there are multiple intersection primitives between the simulated ray passing through the pixel point and the acceleration structure, find the target intersection primitive closest to the camera position among the multiple intersection primitives, and perform ray tracing coloring calculation for the pixel point based on the target intersection primitive.
[0036] Performing ray tracing coloring calculation for the pixel point based on the target intersection primitive closest to the camera position conforms to the optical imaging principle and can ensure the authenticity of the image displayed on the display screen.
[0037] On the other hand, the present disclosure also provides a rendering system, and the system includes:
[0038] A primitive lookup module, configured to start from the camera position and find target primitives within a preset radius range in the camera orientation in the to-be-rendered scene according to the camera position and camera orientation when observing the to-be-rendered scene;
[0039] A construction module, configured to construct an acceleration structure composed of the target primitives;
[0040] A ray tracing module, configured to emit simulated rays passing through each pixel point of the display screen at the camera position and trace the simulated rays to obtain intersection primitives that have intersections with the simulated rays in the acceleration structure;
[0041] A rendering module, configured to perform ray tracing shading calculations on each of the pixel points based on the intersection primitives, and perform screen space shading calculations on each of the pixel points based on other primitives in the scene to be rendered except the target primitive, so as to display an image of the scene to be rendered on the display screen.
[0042] On the other hand, the present disclosure also provides a computer-readable storage medium, which is used to store a computer program. When the computer program is executed by a processor, the method described above is implemented.
[0043] On the other hand, the present disclosure also provides an electronic device, which includes a processor and a memory. The memory is used to store a computer program. When the computer program is executed by the processor, the method described above is implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] The features and advantages of the present disclosure will be more clearly understood by referring to the accompanying drawings. The drawings are schematic and should not be construed as imposing any limitation on the present disclosure. In the drawings:
[0045] Figure 1 A schematic diagram showing the principle of ray tracing rendering technology is shown;
[0046] Figure 2 A flowchart showing the rendering method provided by an embodiment of the present application is shown;
[0047] Figure 3 A schematic diagram showing the search for a target primitive provided by an embodiment of the present application is shown;
[0048] Figure 4 A schematic diagram showing the emission of multiple simulated rays provided by an embodiment of the present application is shown;
[0049] Figure 5 A schematic diagram showing the LOD0 model and the LOD1 model provided by an embodiment of the present application is shown;
[0050] Figure 6 A schematic diagram showing the DXR ray tracing framework corresponding to different lighting effects provided by an embodiment of the present application is shown;
[0051] Figure 7 A schematic diagram showing the acceleration structure provided by an embodiment of the present application is shown;
[0052] Figure 8 A schematic diagram showing the modules of the rendering system provided by an embodiment of the present application is shown;
[0053] Figure 9 A schematic diagram showing the electronic device provided by an embodiment of the present application is shown. Specific Embodiments
[0054] To make the objectives, technical solutions, and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present disclosure. Apparently, the described embodiments are some, but not all, of the embodiments of the present disclosure. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present disclosure without creative efforts shall fall within the scope of protection of the present disclosure.
[0055] In this application, a scene to be rendered refers to a three-dimensional model to be displayed as a two-dimensional image on a display screen. For example, a three-dimensional model representing the internal structure of a room can be used as a scene to be rendered. Another example is that a three-dimensional model representing the layout of a community can be used as another scene to be rendered. In a scene to be rendered, primitives can be used to represent objects. Each scene to be rendered may include one or more primitives. For example, primitives A and B are used to represent a building, and primitive C is used to represent a road. Each primitive can be composed of one or more triangular patches.
[0056] When displaying a scene to be rendered on a display screen based on ray tracing rendering technology, a viewing point is required. The viewing point represents the position and orientation when observing the scene to be rendered. Different viewing points result in different two-dimensional images displayed on the display screen. For example, the two-dimensional image A obtained by observing a three-dimensional scene from a position 50 meters away from the three-dimensional scene in the southeast direction of the three-dimensional scene is different from the two-dimensional image B obtained by observing the three-dimensional scene from a position 1000 meters away from the three-dimensional scene in the north direction of the three-dimensional scene. In this application, a camera is used to represent this viewing point. The camera position represents the position when observing the scene to be rendered, and the camera orientation represents the orientation when observing the scene to be rendered.
[0057] Refer to Figure 1 for a schematic diagram of the principle of ray tracing rendering technology. Figure 1 In, at the camera position, simulated rays can be emitted separately for each pixel point on the display screen. After passing through the pixel points, these simulated rays can enter the scene to be rendered. Taking the simulated ray a passing through pixel point A as an example. After the simulated ray a passes through pixel point A and enters the scene to be rendered, based on its ray direction, the following several situations may exist:
[0058] 1) The simulated ray a first collides with primitive 1 in the scene to be rendered and undergoes phenomena such as reflection or refraction, and then collides with primitive 2. And so on, until the simulated ray a passes through the scene to be rendered or is absorbed in the scene to be rendered.
[0059] 2) The simulated ray a does not collide with any of the primitives in the scene to be rendered;
[0060] 3) After the simulated ray a collides with one of the primitives in the scene to be rendered, it is either absorbed or passes through the scene to be rendered.
[0061] It can be understood that since the ray directions of different simulated rays are different, the ray paths of each simulated ray in the scene to be rendered may not be exactly the same. Furthermore, the primitives that collide with each simulated ray in the scene to be rendered may not be exactly the same.
[0062] Continuing with Figure 1 the simulated ray a passing through pixel point A in
[0063] as an example. If the simulated ray a collides with one or more primitives in the scene to be rendered, then among the colliding primitives, find the primitive closest to the camera position, and perform a shading calculation on pixel point A (i.e., calculate the color at pixel point A) based on the pre-set first calculation formula and information such as the material of the found primitive. If the simulated ray a does not collide with any primitive in the scene to be rendered, then perform a shading calculation on pixel point A according to the pre-set second calculation formula. Here, the first calculation formula refers to the formula for performing a shading calculation on pixel point A when there is a primitive in the scene to be rendered that collides with the simulated ray, and the second calculation formula refers to the formula for performing a shading calculation on pixel point A when there is no primitive in the scene to be rendered that collides with the simulated ray. According to a similar principle, perform a shading calculation on other pixel points on the display screen, and then the scene to be rendered can be displayed on the display screen.In the above ray tracing rendering process, calculating whether the simulated ray collides with the primitive in the scene to be rendered is essentially calculating whether the simulated ray intersects with the triangular patches that make up the primitive, and this process is extremely time-consuming. To improve the calculation efficiency, usually an acceleration structure is constructed for all the triangular patches in the scene to be rendered, and then the triangular patches that have an intersection relationship with the simulated ray can be quickly found with the help of the acceleration structure. Among them, the acceleration structure includes but is not limited to BVH (Bounding Volume Hierarchy) tree, KD (k-dimensional) tree, etc. However, this method is applicable to small-scale scenes to be rendered, but not very applicable to large-scale scenes to be rendered. For example, assume that the scene to be rendered is a CIM (City Information Modeling) scene, which includes BIM (Building Information Modeling) and GIS (Geographic Information System), etc., and the data volume can usually reach hundreds of gigabytes. The amount of memory required for the acceleration structure created for the CIM scene is also unbearable for current electronic devices. At the same time, the huge data volume of the acceleration structure will also slow down the process of finding the intersection between the simulated ray and the triangular patches, reducing the calculation efficiency.
[0064] In view of this, the present application provides a rendering method, which can reduce the storage consumption of the acceleration structure and improve the calculation efficiency. The rendering method can be applied to an electronic device. The electronic device includes but is not limited to a laptop computer, a desktop computer, a server, etc. In some embodiments, the electronic device may include a Central Processing Unit (CPU) and a Graphics Processing Unit (GPU).
[0065] Specifically, please refer to Figure 2 , which is a schematic flowchart of the rendering method provided by an embodiment of the present application. Figure 2 In, the rendering method includes the following steps:
[0066] Step S21, according to the camera position and camera orientation when observing the scene to be rendered, starting from the camera position, find the target primitives in the scene to be rendered within a preset radius range in the camera orientation.
[0067] Among them, the preset radius can be reasonably adjusted according to the size of the scene to be rendered. When there are fewer primitives in the scene to be rendered (such as a close-range scene), the preset radius can be larger; when there are more primitives in the scene to be rendered (such as a long-range scene), the preset radius can be smaller.
[0068] When searching for target primitives, one can start from the camera position, draw a circle centered on the camera orientation with a preset radius. All primitives within this circular range are target primitives. For ease of understanding, the following provides an intuitive illustration in combination with a specific scene to be rendered. For example, assume Figure 3 the three-dimensional scene shown is the scene to be rendered. Moreover, the camera position is below the scene to be rendered, the camera orientation is as shown by the dashed arrow, and the preset radius is r. Then, the primitives that make up buildings B and C can be target primitives, and the primitives that make up building A can be non-target primitives. When implemented inside a computer, one can search for target primitives within the preset radius range by traversing the scene tree of the scene to be rendered based on the camera position and camera orientation.
[0069] The found target primitives can be put into the graphics processing unit. The graphics processing unit can only save target primitives and not save non-target primitives. On this premise, since the camera position and camera orientation can change dynamically, the target primitives in the graphics processing unit should also be able to change dynamically. For example, when the camera position is position 1 and the camera orientation is orientation 1, primitive A is a target primitive. In this case, primitive A needs to be put into the graphics processing unit. However, when the camera position switches to position 2 and the camera orientation switches to orientation 2, primitive A becomes a non-target primitive. In this case, primitive A needs to be removed from the graphics processing unit. Based on the above description, when traversing the scene tree of the scene to be rendered, each time a primitive is traversed, one can first determine whether the primitive is a target primitive and whether the primitive is in the graphics processing unit. Furthermore, one can determine whether to perform the operation of putting the primitive into the graphics processing unit according to the judgment result. For example, when it is determined that a primitive is a target primitive, one can perform a query operation in the graphics processing unit to check whether the primitive is in the graphics processing unit. If not, perform the operation of putting the primitive into the graphics processing unit. If so, no operation needs to be performed.
[0070] In this embodiment, to avoid frequently performing query operations in the graphics processing unit, status parameters can be set for each primitive in the scene to be rendered. If the status parameter value of a primitive is the first value (such as true), it means that the primitive has been put into the graphics processing unit; if the status parameter value of a primitive is the second value (such as false), it means that the primitive has not been put into the graphics processing unit yet. Based on this, when traversing the scene tree of the scene to be rendered, the following situations can be divided:
[0071] If it is determined that a primitive is a target primitive and the status parameter value of the primitive is the first value, indicating that the primitive is already in the graphics processing unit, there is no need to perform the operation of putting the primitive into the graphics processing unit again, and the status parameter value of the primitive remains unchanged;
[0072] If it is determined that a primitive is a target primitive and the value of the state parameter of this primitive is the second value, then put this primitive into the graphics processor and modify the value of the state parameter of this primitive to the first value;
[0073] If it is determined that a primitive is a non-target primitive and the value of the state parameter of this primitive is the first value, indicating that this primitive is currently in the graphics processor, it is necessary to remove this primitive from the graphics processor and modify the value of the state parameter of this primitive to the second value;
[0074] If it is determined that a primitive is a non-target primitive and the value of the state parameter of this primitive is the second value, indicating that this primitive is not currently in the graphics processor, the operation of removing this primitive from the graphics processor can be skipped and the value of the state parameter of this primitive remains unchanged.
[0075] In this way, frequent query operations on the graphics processor are avoided.
[0076] Step S22: Construct an acceleration structure composed of target primitives.
[0077] Specifically, the acceleration structure can store the primitive information of each target primitive. Among them, the primitive information can include the first attribute information of the primitive itself and the second attribute information of the primitive in the scene to be rendered. The first attribute information includes but is not limited to the primitive identifier, material, length, width, height, color, etc. of the primitive. The second attribute information includes but is not limited to the coordinate positions of the triangular patches that make up the primitive in the scene to be rendered, etc.
[0078] In this embodiment, the acceleration structure is a BVH tree. Since the acceleration structure is a conventional technology that those skilled in the art should know, this application will not elaborate on it here. To improve the calculation efficiency, the acceleration structure can be generated in a multi-threaded parallel manner.
[0079] Step S23: Emit simulated rays passing through each pixel point of the display screen at the camera position and trace the simulated rays to obtain the intersection primitives in the acceleration structure that intersect with the simulated rays.
[0080] Regarding emitting simulated rays passing through each pixel point of the display screen at the camera position, reference can be made to Figure 1 the relevant description, which will not be elaborated here.
[0081] In step S23, that is, by tracing the optical paths of each simulated ray and based on the coordinate positions of the triangular patches that make up each primitive in the acceleration structure in the scene to be rendered, etc., the primitives in the acceleration structure that collide with each simulated ray are obtained, that is, the intersection primitives.
[0082] Step S24: Based on the intersection primitive, perform ray tracing shading calculations on each pixel, and based on other primitives in the scene to be rendered except the target primitive, perform screen space shading calculations on each pixel, so as to display the image of the scene to be rendered on the display screen.
[0083] Those skilled in the art can understand that when performing ray tracing shading calculations, the primitive information of the primitive (such as the material of the primitive) needs to be used, while when performing screen space shading calculations, mainly the depth and other information of the primitive are used, and the primitive information of the primitive is not required. Based on this principle, with reference to Figure 3 , after constructing an acceleration structure for the target primitive in the scene to be rendered within a preset radius range, since the acceleration structure includes the primitive information of the target primitive, when there is an intersection primitive in the acceleration structure that intersects with the simulated ray, the ray tracing shading calculation can be performed on the pixel based on the primitive information of the intersection primitive. For the primitives outside the preset radius range in the scene to be rendered, since the primitive information of this part of the primitives cannot be obtained, the screen space shading calculation can be performed on the pixel based on this part of the primitives. Finally, by fusing the ray tracing shading calculation result and the screen space shading calculation result, the color of the pixel on the display screen can be obtained, and then the image of the scene to be rendered can be displayed on the display screen.
[0084] For ease of understanding, take the pixel A in Figure 1 as an example. After the simulated ray a passes through the pixel A, if an intersection primitive that intersects with the simulated ray a is found in the acceleration structure, among these intersection primitives, substitute the primitive information of the intersection primitive closest to the camera position into the first shading calculation formula to perform ray tracing shading calculation on the pixel A, and obtain the ray tracing shading calculation result of the pixel A. Among them, the first shading calculation formula represents the formula for performing shading calculation on the pixel A when there is an intersection primitive between the simulated ray a and the acceleration structure. At the same time, based on the primitives outside the preset radius range in the scene to be rendered, perform screen space shading calculation on the pixel A to obtain the screen space shading calculation result of the pixel A. Finally, by fusing the ray tracing shading calculation result and the screen space shading calculation result of the pixel A, the color of the pixel A can be obtained, so that the color rendering of the pixel A can be performed.
[0085] Among them, when fusing the ray tracing shading calculation result and the screen space shading calculation result, the fusion can be performed according to the respective weights of the ray tracing shading calculation result and the screen space shading calculation result. For example, usually, the image rendered according to the ray tracing shading calculation result can have a more realistic global illumination effect, while the global illumination effect of the image rendered according to the screen space shading calculation result is slightly worse. Therefore, the ray tracing shading calculation result can have a higher weight, and the weight of the screen space shading calculation result can be lower.
[0086] Further, continue to take the pixel point A in Figure 1 as an example. After simulating the light ray a passing through the pixel point A, if no intersection primitive intersecting with the simulated light ray a is found in the acceleration structure, the ray tracing coloring calculation can be performed on the pixel point A based on the second coloring calculation formula, and the ray tracing coloring calculation result of the pixel point A can be obtained. Among them, the second coloring calculation formula represents the formula for performing the coloring calculation on the pixel point A when there is no intersection primitive between the simulated light ray a and the acceleration structure.
[0087] In summary, in the technical solutions of some embodiments of the present application, target primitives within a preset radius range in the to-be-rendered scene are searched for in the camera orientation, and an acceleration structure composed of the target primitives is constructed. Here, since the acceleration structure is constructed only for some primitives in the to-be-rendered scene, the data volume of the constructed acceleration structure can be greatly reduced, and thus the purpose of reducing storage consumption can be achieved. On this basis, since the data volume of the acceleration structure is greatly reduced, the time duration can also be greatly shortened when determining the intersection primitives in the acceleration structure that intersect with the simulated light ray.
[0088] In addition, ray tracing coloring calculations are performed on each pixel point based on the intersection primitives in the acceleration structure that intersect with the simulated light ray, and screen space coloring calculations are performed on each pixel point based on other primitives in the to-be-rendered scene except the target primitives. In this way, on the one hand, when displaying the image of the to-be-rendered scene on the display screen, other primitives in the to-be-rendered scene except the target primitives can be prevented from being omitted, and the complete image of the to-be-rendered scene can be displayed in the to-be-rendered scene; on the other hand, in a close-range scene, the preset radius can be relatively large, so that the image of the to-be-rendered scene can be mainly displayed on the display screen based on the ray tracing coloring calculation result, achieving a more realistic global illumination effect; while in a long-range scene, the preset radius can be relatively small, thereby reducing the search time duration of the intersection primitives and improving the rendering efficiency.
[0089] The following further describes the solution of the present application.
[0090] In some embodiments, the ray tracing coloring calculation of each pixel point based on the intersection primitive in step S24 includes:
[0091] For any pixel point on the display screen, if there are multiple intersection primitives between the simulated light ray passing through the pixel point and the acceleration structure, among the multiple intersection primitives, the target intersection primitive closest to the camera position is searched for, and the ray tracing coloring calculation is performed on the pixel point based on the target intersection primitive.
[0092] For example, assume that the simulated light passing through pixel point A intersects with the acceleration structure at intersection primitives A, B, and C. Among them, intersection primitive B is the closest to the camera position. Then, intersection primitive B is taken as the target intersection primitive, and the primitive information of the target intersection primitive is substituted into the first shading calculation formula to perform ray tracing shading calculation on pixel point A. Here, performing ray tracing shading calculation on the pixel point based on the target intersection primitive closest to the camera position conforms to the optical imaging principle and can ensure the authenticity of the image displayed on the display screen.
[0093] In some embodiments, emitting simulated light passing through each pixel point of the display screen at the camera position may include:
[0094] According to different lighting effects, emit multiple different simulated lights passing through the same pixel point at the camera position, where different simulated lights are used to achieve different lighting effects.
[0095] Specifically, in this embodiment, the lighting effects include but are not limited to the following:
[0096] 1) Shadow effect: used to simulate soft area lighting effects for primitives in the scene to be rendered;
[0097] 2) Reflection effect: used to simulate accurate environmental performance in the scene to be rendered and support multiple reflections;
[0098] 3) Translucency effect: used to accurately represent the glass and liquid materials of primitives in the scene to be rendered and display correct reflections, absorptions, and refractions that conform to physics on transparent surfaces;
[0099] 4) Light occlusion effect: used to accurately project shadows on areas where light is blocked in the scene to be rendered, making the primitives better integrated into the scene to be rendered;
[0100] 5) Global illumination, used to apply real-time interactive reflected lighting effects to areas in the scene to be rendered that are not directly illuminated by the light source.
[0101] For different lighting effects, the simulated lights emitted from the camera position may not be exactly the same. For example, to achieve the shadow effect, the light intensity of the simulated light a emitted from the camera position may be 5 lux, and to achieve the reflection effect, the light intensity of the simulated light b emitted from the camera position may be 10 lux. For ease of understanding, refer to Figure 4 , which is a schematic diagram of the emission of multiple simulated lights provided in an embodiment of the present application. Figure 4In this case, take pixel point A as an example. Exemplarily, 3 simulated light rays passing through pixel point A are emitted from the camera position. Among them, the light direction of simulated light ray a can be different from that of simulated light rays b and c, and the light intensity of simulated light ray b can be different from that of simulated light rays a and c. Further, the collision situations of each simulated light ray passing through this pixel point A with the primitives in the scene to be rendered can be the same, or different or not completely the same. For example Figure 4 In this case, simulated light ray a collides with primitives A and B in the scene to be rendered, while the simulated light ray b passing through pixel point A only collides with primitive C in the scene to be rendered. On this basis, it can be understood that there can also be several different situations such as the same, different, and not completely the same for the intersection primitives in the acceleration structure corresponding to each simulated light ray. This solution of emitting multiple different simulated light rays passing through the same pixel point at the camera position according to different lighting effects can make the obtained intersection primitives more complete, and thus can make the ray tracing shading calculation results for each pixel point more accurate.
[0102] In some embodiments, the simulated light rays for realizing different lighting effects have their respective corresponding first shading calculation formulas. For example, when the simulated light ray for realizing the shadow effect has an intersection primitive with the acceleration structure, ray tracing shading calculation can be performed based on the first shading calculation formula A; and when the simulated light ray for realizing the reflection effect has an intersection primitive with the acceleration structure, ray tracing shading calculation can be performed based on the first shading calculation formula B. In view of this, for any pixel point on the display screen, performing ray tracing shading calculation on this pixel point can include:
[0103] Among the multiple simulated light rays passing through this pixel point, respectively determine the intersection primitives corresponding to each simulated light ray with the acceleration structure;
[0104] Based on the primitive information of the intersection primitives corresponding to each simulated light ray and the first shading calculation formula, respectively perform the first ray tracing shading calculation on this pixel point;
[0105] Fuse the first ray tracing shading calculation results obtained based on different simulated light rays, and use the fusion result as the ray tracing shading calculation result of this pixel point.
[0106] Specifically, for any simulated light ray, after determining the intersection primitive closest to the camera position corresponding to this simulated light ray, the primitive information of the corresponding intersection primitive can be substituted into the first shading calculation formula corresponding to this simulated light ray to perform the first ray tracing shading calculation on this pixel point. Still take Figure 4 pixel point A in as an example. Assume:
[0107] Simulated ray a: corresponding to the first shading calculation formula A, and the intersection primitives with the acceleration structure are primitive 1 and primitive 2, where primitive 1 is the closest to the camera position;
[0108] Simulated ray b: corresponding to the first shading calculation formula B, and the intersection primitive with the acceleration structure is primitive 2;
[0109] Simulated ray c: corresponding to the first shading calculation formula C, and the intersection primitives with the acceleration structure are primitive 2 and primitive 3, where primitive 3 is the closest to the camera position.
[0110] Based on the above assumptions, for simulated ray a, the primitive information of primitive 1 can be substituted into the first shading calculation formula A corresponding to simulated ray a to obtain the first ray tracing shading calculation result based on simulated ray a; for simulated ray b, the primitive information of primitive 2 can be substituted into the first shading calculation formula B corresponding to simulated ray b to obtain the first ray tracing shading calculation result based on simulated ray b; for simulated ray c, the primitive information of primitive 3 can be substituted into the first shading calculation formula C corresponding to simulated ray c to obtain the first ray tracing shading calculation result based on simulated ray c. Furthermore, by fusing the first ray tracing shading calculation results obtained based on simulated rays a, b, and c, the ray tracing shading calculation result of pixel point A can be obtained.
[0111] In the above embodiment, the first shading calculation formula is set separately for the simulated rays used to achieve different lighting effects, which facilitates the adaptive adjustment of the first shading calculation formula according to different lighting effects, making the obtained first ray tracing shading calculation result more in line with the corresponding lighting effect scenario.
[0112] Similarly, in some embodiments, the simulated rays used to achieve different lighting effects may also have their respective corresponding second shading calculation formulas. The above ray tracing shading calculation for each pixel point may include:
[0113] For any pixel point on the display screen, after a simulated ray passes through this pixel point, if there is no intersection primitive between this simulated ray and the acceleration structure, then according to the second shading calculation formula corresponding to this simulated ray, a second ray tracing shading calculation is performed on this pixel point;
[0114] Fuse the second ray tracing shading calculation results obtained based on different simulated rays, or fuse the first ray tracing shading calculation results and the second ray tracing shading calculation results obtained based on different simulated rays, and use the fusion result as the ray tracing shading calculation result of this pixel point.
[0115] Specifically, in this embodiment, second shading calculation formulas are mainly set for the simulated rays used to achieve different lighting effects to define the formulas for performing ray tracing shading calculations on pixel points when each simulated ray has no intersection primitive with the acceleration structure. Here, setting second shading calculation formulas for the simulated rays used to achieve different lighting effects facilitates setting the second shading calculation logic under different lighting effects according to actual needs.
[0116] For ease of understanding, still taking the pixel point A in Figure 4 as an example. Assume that:
[0117] Simulated ray a: corresponds to the second shading calculation formula A, and has no intersection primitive with the acceleration structure;
[0118] Simulated ray b: corresponds to the first shading calculation formula B, and the intersection primitive with the acceleration structure is primitive 2;
[0119] Simulated ray c: corresponds to the first shading calculation formula C, and has no intersection primitive with the acceleration structure.
[0120] Based on the above assumptions, for simulated ray a, the second shading calculation formula corresponding to simulated ray a can be executed to obtain the second ray tracing shading calculation result based on simulated ray a; for simulated ray b, the primitive information of primitive 2 can be substituted into the first shading calculation formula B corresponding to simulated ray b to obtain the first ray tracing shading calculation result based on simulated ray b; for simulated ray c, the second shading calculation formula corresponding to simulated ray c can be executed to obtain the second ray tracing shading calculation result based on simulated ray c. Furthermore, by fusing the second ray tracing shading calculation results obtained based on simulated rays a and c and the first ray tracing shading calculation result obtained based on simulated ray b, the ray tracing shading calculation result of pixel point A can be obtained.
[0121] Furthermore, in some embodiments, considering that the rasterization rendering method is highly efficient, and the first intersection primitive of the simulated rays passing through each pixel point of the display screen with the acceleration structure is the intersection result of the rasterization rendering method. Therefore, the first intersection primitive of the simulated rays passing through each pixel point of the display screen with the acceleration structure can be determined based on the rasterization rendering method. In this way, the efficiency of determining the intersection primitive can be improved. Specifically, the step of emitting simulated rays passing through each pixel point of the display screen at the camera position in step 23 and tracing the simulated rays to obtain the intersection primitive having an intersection with the simulated rays in the acceleration structure can include steps 11) to 13):
[0122] 11) Construct multiple different level-of-detail models composed of target primitives.
[0123] Specifically, the hierarchical detail model, also known as the LOD (Levels of Detail) model. When constructing an LOD model composed of target primitives, the most complete LOD0 model can be first made based on all the target primitives, and then, on the basis of the LOD0 model, other LOD models, such as the LOD1 model, the LOD2 model, etc., can be obtained by means of face reduction.
[0124] 12) Among multiple different hierarchical detail models, based on one target hierarchical detail model, using the rasterization rendering method, determine the first intersection primitive of each simulated ray and the acceleration structure.
[0125] Among them, the rasterization rendering method is a conventional technology that those skilled in the art should be aware of, and this application will not elaborate here.
[0126] 13) Taking the first intersection primitive as the starting point, use the ray tracing method to determine the other intersection primitives of each simulated ray and the acceleration structure except the first intersection primitive.
[0127] In this way, the efficiency of finding intersection primitives can be improved.
[0128] In some embodiments, the rasterization rendering method can be executed in the central processing unit, and the ray tracing method can be executed in the graphics processing unit. Since all the target primitives are stored in the graphics processing unit, the graphics processing unit usually executes the ray tracing rendering method based on the most complete LOD model (i.e., the LOD0 model). In this case, if the central processing unit executes the rasterization rendering method based on an LOD model other than the LOD0 model (such as the LOD1 model), then it is possible that the first intersection primitive obtained is located inside the LOD0 model. Here, take the central processing unit executing the rasterization rendering method based on the LOD1 model as an example. Referring to Figure 5 , is a schematic diagram of the LOD0 model and the LOD1 model provided by an embodiment of this application. Figure 5 In, assume that the outer circle is the LOD0 model, and by means of face reduction of the LOD0 model, an LOD1 model smaller than the LOD0 model is obtained. On this basis, assume that the central processing unit determines the first intersection primitive P based on the LOD1 model. And in the graphics processing unit, based on the LOD0 model, rays are emitted from the first intersection primitive P to continue searching for the next intersection primitive. By Figure 5It can be clearly seen that in a graphics processing unit, the rays emitted from the intersection primitive P are blocked by the LOD0 model itself, resulting in inaccurate determination of the next intersection primitive according to the ray tracing method. The reason for this situation is that the LOD models used by the central processing unit and the graphics processing unit are different. In view of this, after determining the first intersection primitive of each simulated ray and the acceleration structure based on the target level of detail model, the method of the present application further includes:
[0129] Recording the target level of detail model, so that the graphics processing unit performs a ray tracing rendering method based on the recorded target level of detail model.
[0130] In this way, the central processing unit and the graphics processing unit can find intersection primitives based on the same level of detail model, avoiding the problem that the rays are blocked by the level of detail model itself when performing the ray tracing rendering method in the graphics processing unit.
[0131] The method of the present application will be described in detail below in conjunction with a specific embodiment.
[0132] In this embodiment, processes such as emitting simulated rays, tracing simulated rays, finding intersection primitives in the acceleration structure that intersect with the simulated rays, and performing ray tracing shading calculations on pixel points in step S23 can be implemented based on the DXR (DirectX Raytracing) ray tracing framework. Specifically, different lighting effects can correspond to different DXR ray tracing frameworks. For ease of understanding, refer to Figure 6 , which is a schematic diagram of DXR ray tracing frameworks corresponding to different lighting effects provided for an embodiment of the present application. Figure 6 In, n DXR ray tracing frameworks are schematically listed. Different DXR ray tracing frameworks can correspond to different lighting effects. For example, the first DXR ray tracing framework can correspond to the lighting effect of shadows, and the second DXR ray tracing framework can correspond to the lighting effect of reflections. Each DXR ray tracing framework can include method definition modules such as ray initialization, intersection judgment, intersection validity judgment, first ray tracing shading calculation when an intersection primitive is found, and second ray tracing shading calculation when no intersection primitive is found. In each DXR ray tracing framework, different method definitions can be made in the method definition module according to the lighting effect corresponding to the DXR ray tracing framework. Specifically:
[0133] Ray initialization module: used to generate simulated rays. Since the simulated rays under different lighting effects can be different, different ray initialization methods can be defined in the ray initialization modules of different DXR ray tracing frameworks to generate different simulated rays in different DXR ray tracing frameworks.
[0134] Intersection judgment module: used to judge whether the target primitive in the acceleration structure intersects with the simulated ray. Under different lighting effects, the method of intersection judgment can be different. Therefore, different intersection judgment methods can be defined in the intersection judgment modules under different DXR ray tracing frameworks to judge whether the target primitive in the acceleration structure intersects with the simulated ray according to different intersection judgment methods in different DXR ray tracing frameworks.
[0135] Validity judgment module, used to judge whether the target primitive intersecting with the simulated ray is valid. Similarly, different validity judgment methods can be defined in the validity judgment modules under different DXR ray tracing frameworks.
[0136] First ray tracing calculation module, used to perform the first ray tracing calculation when there is an intersection primitive between the simulated ray and the acceleration structure. Similarly, different first shading calculation formulas can be defined in the first ray tracing calculation modules under different DXR ray tracing frameworks.
[0137] Second ray tracing calculation module, used to perform the second ray tracing calculation when there is no intersection primitive between the simulated ray and the acceleration structure. Similarly, different second shading calculation formulas can be defined in the second ray tracing calculation modules under different DXR ray tracing frameworks.
[0138] Further, refer to Figure 7 for the schematic diagram of the acceleration structure provided by an embodiment of the present application. Figure 7 In it, the acceleration structure includes a top-level acceleration structure and a bottom-level acceleration structure. The top-level acceleration structure includes primitive instances corresponding one-to-one to the target primitives. The bottom-level acceleration structure includes the primitive information of each target primitive. The primitive instances are associated with the primitive information in the bottom-level acceleration structure in a one-to-one correspondence. On this basis, the following method can be used to find the intersection primitive in the acceleration structure that intersects with the simulated ray:
[0139] For any primitive instance in the top-level acceleration structure, based on the primitive information associated with the primitive instance, determine whether there is a coincidence position between the target primitive corresponding to the primitive instance and the simulated ray. If so, determine the target primitive corresponding to the primitive instance as the intersection primitive.
[0140] Further, refer to Figure 7, in some embodiments, the first shading calculation formula and the second shading calculation formula defined in each of the above DXR ray tracing frameworks may be stored in a shading calculation table. The top-level acceleration structure includes a search index for searching for the first shading calculation formula and the second shading calculation formula in the shading calculation table. For any pixel point A on the display screen, after a simulated ray passes through the pixel point A, if the target primitive corresponding to a primitive instance coincides with the simulated ray, the first shading calculation formula is searched for in the shading calculation table based on the search index of the first shading calculation formula stored in the top-level acceleration structure, and the primitive information associated with the primitive instance is substituted into the first shading calculation formula to perform the first ray tracing shading calculation on the pixel point A. If there is no target primitive corresponding to a primitive instance that coincides with the simulated ray, the second shading calculation formula is searched for in the shading calculation table based on the search index of the second shading calculation formula stored in the top-level acceleration structure to perform the second ray tracing shading calculation on the pixel point A.
[0141] Thus, all the relevant descriptions of the rendering method of this application are completed.
[0142] Corresponding to the rendering method, this application also provides a rendering system. Referring in combination to Figure 8 , which is a schematic diagram of the modules of the rendering system provided by an embodiment of this application. Figure 8 In
[0143] The primitive search module is used to search for target primitives within a preset radius range in the to-be-rendered scene in the camera orientation starting from the camera position according to the camera position and camera orientation when observing the to-be-rendered scene;
[0144] The construction module is used to construct an acceleration structure composed of target primitives;
[0145] The ray tracing module is used to emit simulated rays passing through each pixel point of the display screen at the camera position and trace the simulated rays to obtain the intersection primitives in the acceleration structure that intersect with the simulated rays;
[0146] The rendering module is used to perform ray tracing shading calculation on each pixel point based on the intersection primitives, and perform screen space shading calculation on each pixel point based on other primitives in the to-be-rendered scene except the target primitives, so as to display the image of the to-be-rendered scene on the display screen.
[0147] Please refer to Figure 9 , which is a schematic diagram of an electronic device provided by an embodiment of this application. The electronic device includes a processor and a memory. The memory is used to store a computer program, and when the computer program is executed by the processor, the above method is implemented.
[0148] Among them, the processor can be a Central Processing Unit (CPU). The processor can also be other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field-Programmable Gate Arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., or a combination of the above types of chips.
[0149] As a non-transitory computer-readable storage medium, the memory can be used to store non-transitory software programs, non-transitory computer-executable programs, and modules, such as the program instructions / modules corresponding to the method in the embodiments of the present invention. By running the non-transitory software programs, instructions, and modules stored in the memory, the processor executes various functional applications and data processing of the processor, that is, implements the method in the above method embodiments.
[0150] The memory can include a program storage area and a data storage area. Among them, the program storage area can store an operating system and application programs required for at least one function; the data storage area can store data created by the processor, etc. In addition, the memory can include high-speed random access memory, and can also include non-transitory memory, such as at least one magnetic disk storage device, a flash memory device, or other non-transitory solid-state storage devices. In some embodiments, the memory optionally includes a memory remotely set relative to the processor, and these remote memories can be connected to the processor through a network. Examples of the above networks include, but are not limited to, the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof.
[0151] An embodiment of the present application also provides a computer-readable storage medium for storing a computer program, which, when executed by a processor, implements the above method.
[0152] Although the embodiments of the present disclosure have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the present disclosure, and such modifications and variations fall within the scope defined by the appended claims.
Claims
1. A rendering method, characterized in that, The method includes: According to the camera position and camera orientation when observing the scene to be rendered, starting from the camera position, searching for target primitives in the scene to be rendered within a preset radius range in the camera orientation; Constructing an acceleration structure composed of the target primitives; Emitting simulated rays passing through each pixel point of the display screen at the camera position, and tracing the simulated rays to obtain intersection primitives in the acceleration structure that have intersections with the simulated rays; Based on the intersection primitives, performing ray tracing shading calculations for each pixel point, and based on other primitives in the scene to be rendered except the target primitives, performing screen space shading calculations for each pixel point to display an image of the scene to be rendered on the display screen.
2. The method according to claim 1, wherein The emitting simulated rays passing through each pixel point of the display screen at the camera position includes: According to different lighting effects, emitting multiple different simulated rays passing through the same pixel point at the camera position, where different simulated rays are used to achieve different lighting effects.
3. The method according to claim 2, wherein The simulated rays used to achieve different lighting effects have their respective corresponding first shading calculation formulas; For any pixel point in the display screen, performing ray tracing shading calculation for this pixel point includes: Among the multiple simulated rays passing through this pixel point, respectively determining the intersection primitives corresponding to each simulated ray in the acceleration structure; Based on the primitive information of the intersection primitives corresponding to each simulated ray and the first shading calculation formula, respectively performing first ray tracing shading calculations for this pixel point; Fusing the first ray tracing shading calculation results obtained based on different simulated rays, and using the fused result as the ray tracing shading calculation result of this pixel point.
4. The method according to claim 3, characterized in that, The simulated rays used to achieve different lighting effects also have their respective corresponding second shading calculation formulas; The performing ray tracing shading calculations for each pixel point includes: For any pixel point in the display screen, after a simulated ray passes through this pixel point, if the simulated ray has no intersection primitive in the acceleration structure, then performing a second ray tracing shading calculation for this pixel point according to the second shading calculation formula corresponding to the simulated ray; Fusing the second ray tracing shading calculation results obtained based on different simulated rays, or fusing the first ray tracing shading calculation results and the second ray tracing shading calculation results obtained based on different simulated rays, and using the fused result as the ray tracing shading calculation result of this pixel point.
5. The method according to claim 1, wherein The emitting simulated rays passing through each pixel point of the display screen at the camera position and tracing the simulated rays to obtain intersection primitives in the acceleration structure that have intersections with the simulated rays includes: Constructing multiple different level-of-detail models composed of the target primitives; Among the multiple different level-of-detail models, based on one target level-of-detail model, using a rasterization rendering method to determine the first intersection primitive of each simulated ray with the acceleration structure; Using the first intersection primitive as a starting point, using a ray tracing rendering method to determine other intersection primitives of each simulated ray with the acceleration structure except the first intersection primitive.
6. The method according to claim 5, characterized in that, The rasterization rendering method is executed in a central processing unit, and the ray tracing method is executed in a graphics processing unit; After determining the first intersection primitive of each of the simulated rays and the acceleration structure based on the target level of detail model, the method further includes: Recording the target level of detail model so that the graphics processing unit executes the ray tracing rendering method based on the recorded target level of detail model.
7. The method according to claim 1, characterized in that, The performing ray tracing shading calculation on each of the pixel points based on the intersection primitive includes: For any pixel point in the display screen, if there are multiple intersection primitives of the simulated ray passing through the pixel point and the acceleration structure, find the target intersection primitive closest to the camera position among the multiple intersection primitives, and perform ray tracing shading calculation on the pixel point based on the target intersection primitive.
8. A rendering system, characterized in that, The system includes: A primitive search module, configured to search for target primitives within a preset radius range in the to-be-rendered scene in the camera orientation starting from the camera position according to the camera position and camera orientation when observing the to-be-rendered scene; A construction module, configured to construct an acceleration structure composed of the target primitives; A ray tracing module, configured to emit simulated rays passing through each pixel point of the display screen at the camera position and trace the simulated rays to obtain intersection primitives in the acceleration structure that have intersections with the simulated rays; A rendering module, configured to perform ray tracing shading calculation on each of the pixel points based on the intersection primitives, and perform screen space shading calculation on each of the pixel points based on other primitives in the to-be-rendered scene except the target primitives, so as to display an image of the to-be-rendered scene on the display screen.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
10. An electronic device, characterized in that, The electronic device includes a processor and a memory, the memory is used to store a computer program, and when the computer program is executed by the processor, the method according to any one of claims 1 to 7 is implemented.