Ray tracing calculation method, device, equipment and storage medium

By introducing a preset stack to ray tracing technology for non-recursive traversal of binary trees, the lack of computing efficiency and flexibility of existing ray tracing technologies is solved, and efficient ray tracing calculations on GPU general computing cores are realized.

CN118657868BActive Publication Date: 2024-12-03XIAN XINTONG SEMICON TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411139921.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-20
Publication Date
2024-12-03
Estimated Expiration
2044-08-20

AI Technical Summary

Technical Problem

The existing ray tracing technology has shortcomings in terms of computing efficiency and flexibility, especially under recursive computing methods, it is difficult to fully realize efficient computing on the general computing core of the GPU.

Method used

By introducing a preset stack for non-recursive traversal of the binary tree, using the access flags of the top nodes for ray tracing, non-recursive ray tracing is realized, and ray tracing is completed completely on the GPU's general computing core, and parallel computing power is used.

Benefits of technology

Improves the computing efficiency and flexibility of ray tracing, provides a more free and flexible programming model, and can achieve complete ray tracing calculations completely on the general computing core of the GPU.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118657868B_ABST
    Figure CN118657868B_ABST
Patent Text Reader

Abstract

The present application discloses a ray tracing calculation method, apparatus, device and storage medium. The present application relates to the technical field of computer graphics. The present solution adds an additional preset stack and uses the preset stack to non-recursively traverse a binary tree, thereby realizing non-recursive calculation of ray tracing. The complete ray tracing calculation can be realized entirely on the general computing core of a GPU. The parallel computing capability of the GPU can also be utilized, and a freer and more flexible programming model can be obtained, thereby improving computing efficiency and providing higher flexibility.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of computer graphics, and in particular to a ray tracing calculation method, apparatus, device and storage medium. Background Art

[0002] At present, real-time rendering technology is a technology widely used in the field of computer graphics. It can present three-dimensional scenes with high-quality effects under real-time requirements. Real-time rendering technology is mainly used in electronic games, virtual reality, augmented reality and other fields. Ray tracing technology is an advanced rendering technology that can simulate the propagation and reflection of real light and achieve realistic light and shadow effects. It has become the mainstream method of real-time rendering.

[0003] In related technologies, ray tracing is a recursive calculation method. Specifically, a ray is emitted from a point. When the ray hits a transparent object in the scene, it is necessary to continue to emit several rays, such as reflected rays and refracted rays. If a function is created in advance, its parameters are the ray and the entire scene, and its return value is the color of the ray, then every time the ray hits a transparent object in the scene, the function needs to be recursively called for calculation.

[0004] However, when the above method is used to perform ray tracing calculations, there are problems of low calculation efficiency and poor flexibility. Summary of the invention

[0005] The present application aims to at least solve the technical problems existing in the prior art. To this end, the present application proposes a ray tracing calculation method in a first aspect, the method comprising:

[0006] After the initial light hits an object in the scene for reflection and refraction, a binary tree formed by all the light is obtained; wherein the root node in the binary tree is used to represent the initial light, and the child nodes in the binary tree are used to represent the reflected light and the refracted light obtained after reflection and refraction;

[0007] Traverse each node in the binary tree in sequence through a preset stack and perform a stacking operation, perform ray tracing calculation according to the first access flag corresponding to the reflected light of each node and the second access flag corresponding to the refracted light of the top node of the stack, obtain the calculation result of the intermediate return color, and obtain the updated current number of bounces; wherein the first access flag is used to indicate whether the reflected light has been visited, and the second access flag is used to indicate whether the refracted light has been visited;

[0008] Based on the updated current number of bounces, the current number of nodes in the preset stack, and the calculation results of the intermediate return colors corresponding to each child node, the target return color corresponding to the initial light is obtained.

[0009] In a possible implementation, each node in the binary tree is traversed in sequence through a preset stack and a stacking operation is performed, and a ray tracing calculation is performed according to a first access flag corresponding to a reflected light of each node and a second access flag corresponding to a refracted light of a top node of the stack, to obtain a calculation result of an intermediate returned color, including:

[0010] Traverse each node in the binary tree in sequence through the preset stack, and push the root node into the stack first;

[0011] Get the top node in the preset stack. If the first access flag corresponding to the reflected light of the top node is unvisited, perform an intersection test on the initial light corresponding to the top node and the object in the scene to obtain the calculation result of the intermediate return color.

[0012] If the first access flag corresponding to the reflected light of the top node of the stack is visited, a ray tracing calculation is performed according to the second access flag corresponding to the refracted light of the top node of the stack to obtain a calculation result of the intermediate returned color.

[0013] In a possible implementation, the initial light corresponding to the top node of the stack is subjected to an intersection test with an object in the scene to obtain a calculation result of an intermediate return color, including:

[0014] If the initial ray does not intersect with an object in the scene, the calculation result of the intermediate return color is determined based on the preset background color;

[0015] If the initial light intersects an opaque object in the scene, the intermediate return color is calculated based on the diffuse color and highlight color of the opaque object;

[0016] If the initial light intersects with a transparent object in the scene, a new reflected light is constructed, and the child node corresponding to the new reflected light is pushed into the stack. Based on the first access flag corresponding to the reflected light of the child node and the second access flag corresponding to the refracted light of the child node, a ray tracing calculation is performed to obtain the calculation result of the intermediate returned color.

[0017] In a possible implementation, if the first access flag corresponding to the reflected light of the top node of the stack is visited, a ray tracing calculation is performed according to the second access flag corresponding to the refracted light of the top node of the stack to obtain a calculation result of the intermediate returned color, including:

[0018] If the first access flag corresponding to the reflected light of the top node of the stack is visited, and the second access flag corresponding to the refracted light of the top node of the stack is not visited, then a new refracted light is constructed, and the child node corresponding to the new refracted light is pushed into the stack. Based on the first access flag corresponding to the reflected light of the child node and the second access flag corresponding to the refracted light of the child node, ray tracing calculation is performed to obtain the calculation result of the intermediate return color.

[0019] In a possible implementation, if the first access flag corresponding to the reflected light of the top node of the stack is visited, a ray tracing calculation is performed according to the second access flag corresponding to the refracted light of the top node of the stack to obtain a calculation result of the intermediate returned color, including:

[0020] If the first access flag corresponding to the reflected light of the top node of the stack is visited, and the second access flag corresponding to the refracted light of the top node of the stack is visited, then the calculation result of the intermediate return color is obtained based on the intermediate return color corresponding to the reflected light of the top node of the stack and the intermediate return color corresponding to the refracted light of the top node of the stack.

[0021] In a possible implementation, based on the updated current number of bounces, the current number of nodes in the preset stack, and the calculation results of the intermediate return colors corresponding to each child node, the target return color corresponding to the initial light is obtained, including:

[0022] If the updated current bounce count reaches the preset maximum bounce count, or the current number of nodes in the preset stack is greater than one, the preset return process is executed;

[0023] If the number of current nodes in the preset stack is equal to one, the target return color corresponding to the initial light is obtained based on the calculation results of the intermediate return colors corresponding to the two child nodes under the current node.

[0024] In a possible implementation, the preset return process includes:

[0025] Obtain the ray type flag of the top node in the preset stack, pop the top node out of the stack, and obtain the updated current number of bounces; wherein the ray type flag is used to indicate whether the top node represents a reflected ray;

[0026] Based on the ray type flag of the top node, the intermediate return color and the first access flag corresponding to the reflected ray of the top node are updated, or the intermediate return color and the second access flag corresponding to the refracted ray of the top node are updated.

[0027] A second aspect of the present application provides a ray tracing computing device, the device comprising:

[0028] An acquisition module, used for acquiring a binary tree formed by all the light rays after the initial light rays hit an object in the scene for reflection and refraction; wherein the root node in the binary tree is used for representing the initial light rays, and the child nodes in the binary tree are used for representing the reflected light rays and the refracted light rays obtained after reflection and refraction;

[0029] A first calculation module is used to sequentially traverse each node in the binary tree through a preset stack and perform a stacking operation, perform a ray tracing calculation according to a first access flag corresponding to the reflected light of each node and a second access flag corresponding to the refracted light of the top node of the stack, obtain a calculation result of an intermediate return color, and obtain an updated current number of bounces; wherein the first access flag is used to indicate whether the reflected light has been visited, and the second access flag is used to indicate whether the refracted light has been visited;

[0030] The second calculation module is used to obtain the target return color corresponding to the initial light based on the updated current number of bounces, the current number of nodes in the preset stack, and the calculation results of the intermediate return colors corresponding to each child node.

[0031] In a possible implementation manner, the first calculation module is specifically used to:

[0032] Through the preset stack, each node in the binary tree is traversed in sequence and pushed into the stack. According to the first access flag corresponding to the reflected light of each node and the second access flag corresponding to the refracted light of the top node of the stack, the ray tracing calculation is performed to obtain the calculation result of the intermediate return color, including:

[0033] Traverse each node in the binary tree in sequence through the preset stack, and push the root node into the stack first;

[0034] Get the top node in the preset stack. If the first access flag corresponding to the reflected light of the top node is unvisited, perform an intersection test on the initial light corresponding to the top node and the object in the scene to obtain the calculation result of the intermediate return color.

[0035] If the first access flag corresponding to the reflected light of the top node of the stack is visited, a ray tracing calculation is performed according to the second access flag corresponding to the refracted light of the top node of the stack to obtain a calculation result of the intermediate returned color.

[0036] In a possible implementation manner, the first calculation module is further used to:

[0037] If the initial ray does not intersect with an object in the scene, the calculation result of the intermediate return color is determined based on the preset background color;

[0038] If the initial light intersects an opaque object in the scene, the intermediate return color is calculated based on the diffuse color and highlight color of the opaque object;

[0039] If the initial light intersects with a transparent object in the scene, a new reflected light is constructed, and the child node corresponding to the new reflected light is pushed into the stack. Based on the first access flag corresponding to the reflected light of the child node and the second access flag corresponding to the refracted light of the child node, a ray tracing calculation is performed to obtain the calculation result of the intermediate returned color.

[0040] In a possible implementation manner, the first calculation module is further used to:

[0041] If the first access flag corresponding to the reflected light of the top node of the stack is visited, and the second access flag corresponding to the refracted light of the top node of the stack is not visited, then a new refracted light is constructed, and the child node corresponding to the new refracted light is pushed into the stack. Based on the first access flag corresponding to the reflected light of the child node and the second access flag corresponding to the refracted light of the child node, ray tracing calculation is performed to obtain the calculation result of the intermediate return color.

[0042] In a possible implementation manner, the first calculation module is further used to:

[0043] If the first access flag corresponding to the reflected light of the top node of the stack is visited, and the second access flag corresponding to the refracted light of the top node of the stack is visited, then the calculation result of the intermediate return color is obtained based on the intermediate return color corresponding to the reflected light of the top node of the stack and the intermediate return color corresponding to the refracted light of the top node of the stack.

[0044] In a possible implementation manner, the second calculation module is specifically used to:

[0045] If the updated current bounce count reaches the preset maximum bounce count, or the current number of nodes in the preset stack is greater than one, the preset return process is executed;

[0046] If the number of current nodes in the preset stack is equal to one, the target return color corresponding to the initial light is obtained based on the calculation results of the intermediate return colors corresponding to the two child nodes under the current node.

[0047] In a possible implementation manner, the second calculation module is further used to:

[0048] Obtain the ray type flag of the top node in the preset stack, pop the top node out of the stack, and obtain the updated current number of bounces; wherein the ray type flag is used to indicate whether the top node represents a reflected ray;

[0049] Based on the ray type flag of the top node, the intermediate return color and the first access flag corresponding to the reflected ray of the top node are updated, or the intermediate return color and the second access flag corresponding to the refracted ray of the top node are updated.

[0050] The third aspect of the present application proposes an electronic device, which includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the ray tracing calculation method as described in the first aspect.

[0051] In a fourth aspect, the present application proposes a computer-readable storage medium, wherein at least one instruction, at least one program, a code set or an instruction set is stored in the storage medium, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by a processor to implement the ray tracing computational method as described in the first aspect.

[0052] The embodiments of the present application have the following beneficial effects:

[0053] The calculation method of ray tracing provided by the embodiment of the present application includes: after the initial ray hits the object in the scene for reflection and refraction, obtain the binary tree formed by all the rays, traverse each node in the binary tree in sequence through the preset stack and perform a stacking operation, perform ray tracing calculation according to the first access flag corresponding to the reflected ray of each node and the second access flag corresponding to the refracted ray of the top node of the stack, obtain the calculation result of the intermediate return color, and obtain the updated current number of bounces, based on the updated current number of bounces, the current number of nodes in the preset stack and the calculation result of the intermediate return color corresponding to each child node, obtain the target return color corresponding to the initial ray. This scheme adds an additional preset stack and uses the preset stack to non-recursively traverse the binary tree, so as to realize the non-recursive calculation of ray tracing, and can completely realize the complete ray tracing calculation on the general computing core of the GPU. It can also use the parallel computing capability of the GPU, and obtain a freer and more flexible programming model, which improves the computing efficiency and has high flexibility. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] Figure 1 A block diagram of a computer device provided in an embodiment of the present application;

[0055] Figure 2 A flowchart of a ray tracing calculation method provided in an embodiment of the present application;

[0056] Figure 3 A schematic diagram of a light beam after an initial light beam hits an object in a scene and is reflected and refracted, provided in an embodiment of the present application;

[0057] Figure 4 A schematic diagram of a binary tree provided in an embodiment of the present application;

[0058] Figure 5 A flowchart of the steps for generating a calculation result of an intermediate return color provided in an embodiment of the present application;

[0059] Figure 6 A structural block diagram of a ray tracing computing device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0060] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0061] In related technologies, ray tracing is a recursive calculation method. Specifically, a ray is emitted from a point. When the ray hits a transparent object in the scene, it is necessary to continue to emit several rays, such as reflected rays and refracted rays. If a function is created in advance, its parameters are the ray and the entire scene, and its return value is the color of the ray, then every time the ray hits a transparent object in the scene, the function needs to be recursively called for calculation.

[0062] The existing technology recursively calls the function to perform ray tracing calculations. Since the recursive calculation process is nested, that is, the calculation process of the next level needs to use the calculation results of the previous level, and some GPUs use parallel computing and do not support recursive operations. In other words, the current ray tracing calculation method is to complete the calculation on the GPU's dedicated ray tracing accelerator and the general computing core. The ray tracing accelerator is responsible for generating and emitting rays, testing whether the rays intersect with objects, etc., and the general computing core is responsible for shading calculations, etc., which cannot be fully implemented on the GPU's general computing core. Although this method of using a dedicated ray tracing accelerator can improve the calculation efficiency of ray tracing, the dedicated ray tracing accelerator is not programmable, which leads to a lack of versatility and scalability in algorithm implementation.

[0063] If the complete ray tracing calculation can be implemented on the general computing core of the GPU, it can not only take advantage of the parallel computing capability of the GPU, but also obtain a freer and more flexible programming model. However, in fact, the general computing core of the GPU often does not support the recursion of functions very well. Therefore, the existing technology still has many problems in the calculation of ray tracing.

[0064] In view of this, the present application proposes a ray tracing calculation method, which adds an additional preset stack and uses the preset stack to non-recursively traverse the binary tree, so as to realize non-recursive calculation of ray tracing. The complete ray tracing calculation can be fully realized on the general computing core of the GPU, and the parallel computing capability of the GPU can be utilized. A freer and more flexible programming model can be obtained, which improves computing efficiency and has higher flexibility.

[0065] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present disclosure, unless otherwise specified, "multiple" means two or more. In addition, the use of "based on" or "according to" means openness and inclusiveness, because the process, steps, calculations or other actions "based on" or "according to" one or more of the conditions or values ​​may be based on additional conditions or values ​​beyond the described values ​​in practice.

[0066] The ray tracing calculation method provided in the present application can be applied to a computer device (electronic device), which can be a server or a terminal. The server can be a single server or a server cluster composed of multiple servers. The embodiments of the present application do not specifically limit this. The terminal can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, and portable wearable devices.

[0067] Take the computer device as a server as an example. Figure 1 A block diagram of a server is shown, such as Figure 1 As shown, the server may include a processor and a memory connected via a system bus. The processor of the server is used to provide computing and control capabilities. The memory of the server includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. When the computer program is executed by the processor, a ray tracing calculation method is implemented.

[0068] Those skilled in the art will understand that Figure 1 The structure shown in the figure is only a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the server to which the solution of the present application is applied. Optionally, the server may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.

[0069] It should be noted that the execution subject of the embodiments of the present application may be a computer device or a ray tracing computing device. The following method embodiments will be described using a computer device as the execution subject.

[0070] Figure 2 A flowchart of a ray tracing calculation method provided in an embodiment of the present application. Figure 2 As shown, the method comprises the following steps:

[0071] Step 202: After the initial light hits an object in the scene and is reflected and refracted, a binary tree formed by all the light rays is obtained.

[0072] The root node in the binary tree is used to represent the initial light, and the child nodes in the binary tree are used to represent the reflected light and the refracted light obtained after reflection and refraction. Figure 3 As shown, Figure 3 A schematic diagram of a light beam after an initial light beam hits an object in a scene and is reflected and refracted is provided in an embodiment of the present application, wherein A, B, and C are three objects, and reflection and refraction occur when the light beam hits A, B, and C, and arrow lines 1, 2, 3, 4, 5, 6, and 7 represent the direction of the light beam. Light beam 1 is the initial light beam, and after light beam 1 hits object A, reflected light beam 2 and refracted light beam 5 are emitted. After light beam 2 hits object B, reflected light beam 3 and refracted light beam 4 are emitted. After light beam 5 hits object C, reflected light beam 6 and refracted light beam 7 are emitted.

[0073] It should be noted that, in order to simplify the description, Figure 3 It does not specify the reflection and refraction that occurs again when the refracted light hits the object, such as Figure 3 In the actual calculation process, the reflection and refraction that occur here also need to be calculated accordingly.

[0074] Figure 4 A schematic diagram of a binary tree provided in an embodiment of the present application is Figure 3 After the light hits the object, the reflected light and refracted light emitted form a binary tree, where the root node represents the initial light and the child nodes represent the reflected light and refracted light.

[0075] For each node in the binary tree, the following node contents may be included: light, recorded as ray, intersection information, material information of the object, the color of the light itself, recorded as color, whether it is a reflected light, recorded as is_reflect, the color of the reflected light, recorded as reflect_color, the color of the refracted light, recorded as refract_color, the first visit flag of the reflected light, recorded as reflect_visited, and the second visit flag of the refracted light, recorded as refract_visited.

[0076] Step 204, traverse each node in the binary tree in sequence through the preset stack and perform a stacking operation, perform ray tracing calculations based on the first access flag corresponding to the reflected light of each node and the second access flag corresponding to the refracted light of the top node of the stack, obtain the calculation result of the intermediate return color, and obtain the updated current number of bounces.

[0077] The first access flag is used to indicate whether the reflected light has been visited. Optionally, when the first access flag is true, it indicates that the reflected light has been visited. When the first access flag is false, it indicates that the reflected light has not been visited. The second access flag is used to indicate whether the refracted light has been visited. Optionally, when the second access flag is true, it indicates that the refracted light has been visited. When the second access flag is false, it indicates that the refracted light has not been visited.

[0078] By adding an extra preset stack and using it to non-recursively traverse the binary tree, non-recursive calculations for ray tracing can be achieved. Binary tree traversal means starting from the root node and visiting all nodes in the binary tree in a certain order, so that each node is visited once and only once. In the non-recursive traversal process, it can be implemented by first visiting the root node, then traversing the left subtree, and then traversing the right subtree. The specific implementation process can refer to the existing non-recursive process, which will not be repeated here.

[0079] In addition, the preset stack also needs to be initialized, including setting the node type of the stack, the size of the stack, etc., wherein the node type of the stack may include a root node, a parent node, a child node, etc. Thus, each node in the binary tree can be traversed in sequence through the preset stack and a stacking operation can be performed, and the ray tracing calculation can be performed according to the first access flag corresponding to the reflected light of each node and the second access flag corresponding to the refracted light of the top node of the stack, to obtain the calculation result of the intermediate return color and the updated current number of bounces. In the stacking operation, the current number of bounces is increased by one to obtain the updated current number of bounces.

[0080] In some optional embodiments, Figure 5 As shown, Figure 5 A flowchart of the steps for generating a calculation result of an intermediate return color provided in an embodiment of the present application includes:

[0081] Step 502: traverse each node in the binary tree in sequence through a preset stack, and first push the root node into the stack.

[0082] Step 504, obtain the top node in the preset stack. If the first access flag corresponding to the reflected light of the top node is not visited, perform an intersection test on the initial light corresponding to the top node and the object in the scene to obtain the calculation result of the intermediate return color.

[0083] Step 506: If the first access flag corresponding to the reflected light of the top node of the stack is visited, perform ray tracing calculation according to the second access flag corresponding to the refracted light of the top node of the stack to obtain the calculation result of the intermediate return color.

[0084] Among them, after pushing the root node into the stack, take out the top node of the stack. If the first access flag corresponding to the reflected light of the top node of the stack is not visited, that is, false, it is necessary to perform an intersection test on the initial light corresponding to the top node of the stack and the object in the scene to obtain the calculation result of the intermediate return color. The intersection information and the material information of the object can also be updated.

[0085] In some optional embodiments, if the initial light does not intersect with the object in the scene, that is, it intersects with the background, the calculation result of the intermediate return color is determined based on the preset background color, that is, the temporarily saved intermediate return color is the preset background color.

[0086] If the initial light intersects an opaque object in the scene, the calculation result of the intermediate return color is determined based on the diffuse color and highlight color of the opaque object, that is, the temporarily saved intermediate return color is the diffuse color plus the highlight color.

[0087] If the initial light intersects with a transparent object in the scene, a new reflected light is constructed, and the child node corresponding to the new reflected light is pushed into the stack. Based on the first access flag corresponding to the reflected light of the child node and the second access flag corresponding to the refracted light of the child node, a ray tracing calculation is performed to obtain the calculation result of the intermediate returned color.

[0088] If the initial light intersects with a transparent object in the scene, the starting point and direction of the new reflected light need to be calculated according to the law of light reflection, and a new reflected light is constructed. Therefore, the light of the new node is the new reflected light, and the light type flag of the new node is true. The light type flag can be recorded as is_reflect. When the light type flag is true, it means that the light of the new node is a reflected light. Next, the new node needs to be pushed into the stack, and the current number of bounces is increased by one to obtain the updated current number of bounces.

[0089] In other optional embodiments, if the first access flag corresponding to the reflected light of the top node of the stack is visited, and the second access flag corresponding to the refracted light of the top node of the stack is not visited, then a new refracted light is constructed, and the child node corresponding to the new refracted light is pushed into the stack, and based on the first access flag corresponding to the reflected light of the child node and the second access flag corresponding to the refracted light of the child node, a ray tracing calculation is performed to obtain the calculation result of the intermediate return color.

[0090] Among them, if the first access flag corresponding to the reflected light of the top node of the stack is visited, that is, true, and the second access flag corresponding to the refracted light of the top node of the stack is not visited, that is, false, then it is necessary to calculate the starting point and direction of the new refracted light according to the law of refraction of light, and construct a new refracted light. Therefore, the light of the new node is the new refracted light, and the light type flag of the new node is false, indicating that the light of the new node is a refracted light. Next, it is necessary to push the new node into the stack, add one to the current number of bounces, and get the updated current number of bounces.

[0091] In some other optional embodiments, if the first access flag corresponding to the reflected light of the top node of the stack is visited, and the second access flag corresponding to the refracted light of the top node of the stack is visited, then the calculation result of the intermediate return color is obtained based on the intermediate return color corresponding to the reflected light of the top node of the stack, and the intermediate return color corresponding to the refracted light of the top node of the stack.

[0092] If the first access flag corresponding to the reflected light of the top node is visited, that is, true, and the second access flag corresponding to the refracted light of the top node is visited, that is, true, then it is necessary to obtain the calculation result of the intermediate return color corresponding to the top node according to the intermediate return color corresponding to the reflected light of the top node and the intermediate return color corresponding to the refracted light of the top node. That is, the intermediate return color temporarily saved by the top node is the color calculated by the intermediate return color corresponding to the reflected light and the intermediate return color corresponding to the refracted light.

[0093] Step 206: Based on the updated current number of bounces, the current number of nodes in the preset stack, and the calculation results of the intermediate return colors corresponding to each child node, the target return color corresponding to the initial light is obtained.

[0094] If the updated current bounce number reaches the preset maximum bounce number, or the current number of nodes in the preset stack is greater than one, the preset return process is executed. If the current number of nodes in the preset stack is equal to one, the target return color corresponding to the initial light is obtained based on the calculation results of the intermediate return colors corresponding to the two child nodes under the current node.

[0095] In some optional embodiments, the preset return process includes: obtaining a light type flag of a top node in a preset stack, popping the top node, and obtaining an updated current number of bounces. Based on the light type flag of the top node, updating the intermediate return color and the first access flag corresponding to the reflected light of the top node, or updating the intermediate return color and the second access flag corresponding to the refracted light of the top node.

[0096] If the updated current number of bounces reaches the preset maximum number of bounces, it is necessary to obtain the ray type flag of the top node in the preset stack, which is used to indicate whether the top node represents a reflected ray, and pop the top node out of the stack. In the pop operation, it is necessary to reduce the current number of bounces by one, that is, to obtain the updated current number of bounces. The preset maximum number of bounces can be pre-defined, for example, it can be set to 5.

[0097] It is also necessary to update the intermediate return color and the first access flag corresponding to the reflected light of the top node, or update the intermediate return color and the second access flag corresponding to the refracted light of the top node according to the light type flag of the top node. In other words, if the light type flag of the top node is true, it is necessary to update the intermediate return color and the first access flag corresponding to the reflected light of the top node. Here, updating the first access flag means updating false to true. If the light type flag of the top node is false, it is necessary to update the intermediate return color and the second access flag corresponding to the refracted light of the top node. Here, updating the second access flag means updating false to true.

[0098] At this time, after obtaining the updated current number of bounces, if it is less than the preset maximum number of bounces, then the above ray tracing calculation process can be continued. If the current number of nodes in the preset stack is greater than one, the preset return process also needs to be executed, and the above ray tracing calculation process is continued.

[0099] When the number of current nodes in the preset stack is equal to one, the target return color corresponding to the initial light is obtained based on the calculation result of the intermediate return color corresponding to the two child nodes under the current node. Among them, when the number of current nodes in the preset stack is equal to one, that is, the current node is the root node, and the root node represents the initial light, so the target return color corresponding to the initial light can be obtained based on the calculation result of the intermediate return color corresponding to the two child nodes under the root node, and the above-mentioned ray tracing calculation process is terminated. It should be noted that when the number of current nodes in the preset stack is equal to one, if any of the two child nodes under the current node does not return the corresponding intermediate return color, the above-mentioned ray tracing calculation process must still be continued.

[0100] In some optional embodiments, Figure 4 The binary tree is used as an example to illustrate the changes in the preset stack. The following is a case where the middle color is returned when hitting the background or opaque object. In the following example, there is a case where the preset maximum number of bounces is not reached. Not all cases are shown one by one, but only for illustrative purposes.

[0101] 1. After initialization, the root node corresponding to the initial ray 1 is pushed into the stack, the current number of bounces is 0, and the preset stack includes stack element 0. Correspondingly, ray = initial ray 1, color = 0, is reflect = false, reflect_color = 0, refract_color = 0, reflect_visited = false, refract_visited = false.

[0102] 2. The initial ray 1 hits the transparent object, emitting a new reflected ray 2. The new node corresponding to the new reflected ray 2 is pushed into the stack, and the updated current bounce count is 1. At this point, the preset stack includes stack element 0, corresponding to ray = initial ray 1, color = 0, is reflect = false, reflect_color = 0, refract_color = 0, reflect_visited = false, refract_visited = false. The preset stack also includes stack element 1, corresponding to ray = reflected ray 2, color = 0, is reflect = true, reflect_color = 0, refract_color = 0, reflect_visited = false, refract_visited = false.

[0103] 3. Reflected ray 2 hits the transparent object, and continues to emit new reflected ray 3. The new node corresponding to the new reflected ray 3 is pushed into the stack, and the updated current bounce count is 2. At this time, the preset stack includes stack element 0, corresponding to ray = initial ray 1, color = 0, is reflect = false, reflect_color = 0, refract_color = 0, reflect_visited = false, refract_visited = false. The preset stack also includes stack element 1, corresponding to ray = reflected ray 2, color = 0, is reflect = true, reflect_color = 0, refract_color = 0, reflect_visited = false, refract_visited = false. The preset stack also includes stack element 2, corresponding to ray = reflected ray 3, color = 0, is reflect = true, reflect_color = 0, refract_color = 0, reflect_visited = false, refract_visited = false.

[0104] 4. If reflected ray 3 hits the background or opaque object, it is necessary to return the middle return color of reflected ray 3 to the previous node, that is, return to the child node corresponding to reflected ray 2, and the updated current bounce count is 1. At this time, the preset stack includes stack element 0, corresponding to ray = initial ray 1, color = 0, is reflect = false, reflect_color = 0, refract_color = 0, reflect_visited = false, refract_visited = false. The preset stack also includes stack element 1, corresponding to ray = reflected ray 2, color = 0, is reflect = true, reflect_color = updated, refract_color = 0, reflect_visited = true, refract_visited = false.

[0105] 5. After the reflected ray 2 has been visited, a new refracted ray 4 needs to be emitted. The new node corresponding to the new refracted ray 4 is pushed into the stack, and the current number of bounces after update is 2. At this time, the preset stack includes stack element 0, corresponding to ray = initial ray 1, color = 0, is reflect = false, reflect_color = 0, refract_color = 0, reflect_visited = false, refract_visited = false. The preset stack also includes stack element 1, corresponding to ray = reflected ray 2, color = 0, is reflect = true, reflect_color = updated, refract_color = 0, reflect_visited = true, refract_visited = false. The preset stack also includes stack element 2, corresponding to ray = refracted ray 4, color = 0, is reflect = false, reflect_color = 0, refract_color = 0, reflect_visited = false, refract_visited = false.

[0106] 6. If refracted ray 4 hits the background or opaque object, it is necessary to return the middle return color of refracted ray 4 to the previous node, that is, return to the child node corresponding to reflected ray 2, and the updated current bounce count is 1. At this time, the preset stack includes stack element 0, corresponding to ray = initial ray 1, color = 0, is reflect = false, reflect_color = 0, refract_color = 0, reflect_visited = false, refract_visited = false. The preset stack also includes stack element 1, corresponding to ray = reflected ray 2, color = 0, is reflect = true, reflect_color = updated, refract_color = updated, reflect_visited = true, refract_visited = false.

[0107] 7. At this time, reflected ray 3 has been visited, and refracted ray 4 has been visited, so the intermediate return color of reflected ray 2 can also be returned to the previous node, that is, the root node, that is, the reflected ray color of initial ray 1 can be updated according to the intermediate return color of reflected ray 2, and the current number of bounces after the update is 0. That is, the preset stack includes stack element 0, corresponding to, ray = initial ray 1, color = 0, is reflect = false, reflect_color = update, refract_color = 0, reflect_visited = true, refract_visited = false. It should be noted that the number of current nodes in the preset stack here is equal to one, but one of the two child nodes under the current node does not return the corresponding intermediate return color, that is, although the child node corresponding to reflected ray 2 under the root node corresponding to initial ray 1 has updated the intermediate return color, the child node corresponding to refracted ray 5 under the root node has not updated the intermediate return color, so the above ray tracing calculation process still needs to be looped.

[0108] 8. The reflected ray of the initial ray 1 has been visited, and a new refracted ray 5 needs to be emitted. The new node corresponding to the new refracted ray 5 is pushed into the stack, and the current number of bounces after update is 1. At this time, the preset stack includes stack element 0, corresponding to, ray = initial ray 1, color = 0, is reflect = false, reflect_color = update, refract_color = 0, reflect_visited = true, refract_visited = false. The preset stack also includes stack element 1, corresponding to, ray = refracted ray 5, color = 0, is reflect = false, reflect_color = 0, refract_color = 0, reflect_visited = false, refract_visited = false.

[0109] 9. Refracted ray 5 hits the transparent object and continues to emit new reflected ray 6. The new node corresponding to the new reflected ray 6 is pushed into the stack, and the current number of bounces after update is 2. At this time, the preset stack includes stack element 0, corresponding to ray = initial ray 1, color = 0, is reflect = false, reflect_color = update, refract_color = 0, reflect_visited = true, refract_visited = false. The preset stack also includes stack element 1, corresponding to ray = refracted ray 5, color = 0, is reflect = false, reflect_color = 0, refract_color = 0, reflect_visited = false, refract_visited = false. The preset stack also includes stack element 2, corresponding to ray = reflected ray 6, color = 0, is reflect = true, reflect_color = 0, refract_color = 0, reflect_visited = false, refract_visited = false.

[0110] 10. If the reflected ray 6 hits the background or opaque object, it is necessary to return the middle return color of the reflected ray 6 to the previous node, that is, return to the child node corresponding to the refracted ray 5, and the updated current bounce count is 1. At this time, the preset stack includes stack element 0, corresponding to ray = initial ray 1, color = 0, is reflect = false, reflect_color = update, refract_color = 0, reflect_visited = true, refract_visited = false. The preset stack also includes stack element 1, corresponding to ray = refracted ray 5, color = 0, is reflect = false, reflect_color = update, refract_color = 0, reflect_visited = true, refract_visited = false.

[0111] 11. After the reflected ray 6 has been visited, a new refracted ray 7 needs to be emitted. The new node corresponding to the new refracted ray 7 is pushed into the stack, and the current number of bounces after update is 2. At this time, the preset stack includes stack element 0, corresponding to ray = initial ray 1, color = 0, is reflect = false, reflect_color = update, refract_color = 0, reflect_visited = true, refract_visited = false. The preset stack also includes stack element 1, corresponding to ray = refracted ray 5, color = 0, is reflect = false, reflect_color = update, refract_color = 0, reflect_visited = true, refract_visited = false. The preset stack also includes stack element 2, corresponding to ray = refracted ray 7, color = 0, is reflect = false, reflect_color = 0, refract_color = 0, reflect_visited = false, refract_visited = false.

[0112] 12. If refracted ray 7 hits the background or opaque object, it is necessary to return the middle return color of refracted ray 7 to the previous node, that is, return to the child node corresponding to refracted ray 5, and the updated current bounce count is 1. At this time, the preset stack includes stack element 0, corresponding to, ray = initial ray 1, color = 0, is reflect = false, reflect_color = update, refract_color = 0, reflect_visited = true, refract_visited = false. The preset stack also includes stack element 1, corresponding to, ray = refracted ray 5, color = 0, is reflect = false, reflect_color = update, refract_color = update, reflect_visited = true, refract_visited = true.

[0113] 13. At this time, the reflected ray 6 has been visited, and the refracted ray 7 has been visited, so the intermediate return color of the refracted ray 5 can also be returned to the previous node, that is, the root node, that is, the refracted ray color of the initial ray 1 can be updated according to the intermediate return color of the refracted ray 5. At this time, the preset stack includes stack element 0, corresponding to, ray = initial ray 1, color = 0, is reflect = false, reflect_color = update, refract_color = update, reflect_visited = true, refract_visited = true.

[0114] 14. Since reflected ray 2 has been visited, refracted ray 5 has been visited, and the current number of nodes in the preset stack is one, the loop ends and returns to the target return color of initial ray 1. At this time, the preset stack includes stack element 0, corresponding to ray = initial ray 1, color = target return color, is reflect = false, reflect_color = update, refract_color = update, reflect_visited = true, refract_visited = true.

[0115] In an embodiment of the present application, the method includes: after the initial light hits an object in the scene for reflection and refraction, obtaining a binary tree formed by all the light rays, traversing each node in the binary tree in sequence through a preset stack and performing a stacking operation, performing a ray tracing calculation according to a first access flag corresponding to the reflected light of each node and a second access flag corresponding to the refracted light of the top node of the stack, obtaining a calculation result of the intermediate return color, and obtaining an updated current number of bounces, and obtaining a target return color corresponding to the initial light based on the updated current number of bounces, the current number of nodes in the preset stack, and the calculation result of the intermediate return color corresponding to each child node. This solution adds an additional preset stack and uses the preset stack to non-recursively traverse the binary tree, thereby realizing non-recursive calculation of ray tracing, realizing complete ray tracing calculation entirely on the general computing core of the GPU, and utilizing the parallel computing capability of the GPU, and obtaining a freer and more flexible programming model, thereby improving computing efficiency and having high flexibility.

[0116] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0117] Figure 6 A structural block diagram of a ray tracing computing device provided in an embodiment of the present application.

[0118] like Figure 6 As shown, the ray tracing computing device 600 includes:

[0119] The acquisition module 602 is used to obtain a binary tree formed by all light rays after the initial light rays hit an object in the scene for reflection and refraction; wherein the root node in the binary tree is used to represent the initial light rays, and the child nodes in the binary tree are used to represent the reflected light rays and the refracted light rays obtained after reflection and refraction.

[0120] The first calculation module 604 is used to traverse each node in the binary tree in sequence through a preset stack and perform a stacking operation, perform ray tracing calculations according to a first access flag corresponding to the reflected light of each node and a second access flag corresponding to the refracted light of the top node of the stack, obtain the calculation result of the intermediate return color, and obtain the updated current number of bounces; wherein the first access flag is used to indicate whether the reflected light has been visited, and the second access flag is used to indicate whether the refracted light has been visited.

[0121] The second calculation module 606 is used to obtain the target return color corresponding to the initial light based on the updated current number of bounces, the current number of nodes in the preset stack, and the calculation results of the intermediate return colors corresponding to each child node.

[0122] Regarding the device in the above embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment of the method, and will not be elaborated here. Each module in the above ray tracing computing device can be implemented in whole or in part by software, hardware, and a combination thereof. The above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations of the above modules.

[0123] In one embodiment of the present application, a computer device is provided, the computer device comprising a memory and a processor, the memory storing a computer program, and the processor implementing the following steps when executing the computer program:

[0124] After the initial light hits an object in the scene for reflection and refraction, a binary tree formed by all the light is obtained; wherein the root node in the binary tree is used to represent the initial light, and the child nodes in the binary tree are used to represent the reflected light and the refracted light obtained after reflection and refraction;

[0125] Traverse each node in the binary tree in sequence through a preset stack and perform a stacking operation, perform ray tracing calculation according to the first access flag corresponding to the reflected light of each node and the second access flag corresponding to the refracted light of the top node of the stack, obtain the calculation result of the intermediate return color, and obtain the updated current number of bounces; wherein the first access flag is used to indicate whether the reflected light has been visited, and the second access flag is used to indicate whether the refracted light has been visited;

[0126] Based on the updated current number of bounces, the current number of nodes in the preset stack, and the calculation results of the intermediate return colors corresponding to each child node, the target return color corresponding to the initial light is obtained.

[0127] In one embodiment of the present application, when the processor executes the computer program, the processor further implements the following steps:

[0128] Traverse each node in the binary tree in sequence through the preset stack, and push the root node into the stack first;

[0129] Get the top node in the preset stack. If the first access flag corresponding to the reflected light of the top node is unvisited, perform an intersection test on the initial light corresponding to the top node and the object in the scene to obtain the calculation result of the intermediate return color.

[0130] If the first access flag corresponding to the reflected light of the top node of the stack is visited, a ray tracing calculation is performed according to the second access flag corresponding to the refracted light of the top node of the stack to obtain a calculation result of the intermediate returned color.

[0131] In one embodiment of the present application, when the processor executes the computer program, the processor further implements the following steps:

[0132] If the initial ray does not intersect with an object in the scene, the calculation result of the intermediate return color is determined based on the preset background color;

[0133] If the initial light intersects an opaque object in the scene, the intermediate return color is calculated based on the diffuse color and highlight color of the opaque object;

[0134] If the initial light intersects with a transparent object in the scene, a new reflected light is constructed, and the child node corresponding to the new reflected light is pushed into the stack. Based on the first access flag corresponding to the reflected light of the child node and the second access flag corresponding to the refracted light of the child node, a ray tracing calculation is performed to obtain the calculation result of the intermediate returned color.

[0135] In one embodiment of the present application, when the processor executes the computer program, the processor further implements the following steps:

[0136] If the first access flag corresponding to the reflected light of the top node of the stack is visited, and the second access flag corresponding to the refracted light of the top node of the stack is not visited, then a new refracted light is constructed, and the child node corresponding to the new refracted light is pushed into the stack. Based on the first access flag corresponding to the reflected light of the child node and the second access flag corresponding to the refracted light of the child node, ray tracing calculation is performed to obtain the calculation result of the intermediate return color.

[0137] In one embodiment of the present application, when the processor executes the computer program, the processor further implements the following steps:

[0138] If the first access flag corresponding to the reflected light of the top node of the stack is visited, and the second access flag corresponding to the refracted light of the top node of the stack is visited, then the calculation result of the intermediate return color is obtained based on the intermediate return color corresponding to the reflected light of the top node of the stack and the intermediate return color corresponding to the refracted light of the top node of the stack.

[0139] In one embodiment of the present application, when the processor executes the computer program, the processor further implements the following steps:

[0140] If the updated current bounce count reaches the preset maximum bounce count, or the current number of nodes in the preset stack is greater than one, the preset return process is executed;

[0141] If the number of current nodes in the preset stack is equal to one, the target return color corresponding to the initial light is obtained based on the calculation results of the intermediate return colors corresponding to the two child nodes under the current node.

[0142] In one embodiment of the present application, when the processor executes the computer program, the processor further implements the following steps:

[0143] Obtain the ray type flag of the top node in the preset stack, pop the top node out of the stack, and obtain the updated current number of bounces; wherein the ray type flag is used to indicate whether the top node represents a reflected ray;

[0144] Based on the ray type flag of the top node, the intermediate return color and the first access flag corresponding to the reflected ray of the top node are updated, or the intermediate return color and the second access flag corresponding to the refracted ray of the top node are updated.

[0145] The computer device provided in the embodiment of the present application has similar implementation principles and technical effects to those of the above-mentioned method embodiment, and will not be described in detail here.

[0146] In one embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:

[0147] After the initial light hits an object in the scene for reflection and refraction, a binary tree formed by all the light is obtained; wherein the root node in the binary tree is used to represent the initial light, and the child nodes in the binary tree are used to represent the reflected light and the refracted light obtained after reflection and refraction;

[0148] Traverse each node in the binary tree in sequence through a preset stack and perform a stacking operation, perform ray tracing calculation according to the first access flag corresponding to the reflected light of each node and the second access flag corresponding to the refracted light of the top node of the stack, obtain the calculation result of the intermediate return color, and obtain the updated current number of bounces; wherein the first access flag is used to indicate whether the reflected light has been visited, and the second access flag is used to indicate whether the refracted light has been visited;

[0149] Based on the updated current number of bounces, the current number of nodes in the preset stack, and the calculation results of the intermediate return colors corresponding to each child node, the target return color corresponding to the initial light is obtained.

[0150] In one embodiment of the present application, when the computer program is executed by a processor, the following steps are further implemented:

[0151] Traverse each node in the binary tree in sequence through the preset stack, and push the root node into the stack first;

[0152] Get the top node in the preset stack. If the first access flag corresponding to the reflected light of the top node is unvisited, perform an intersection test on the initial light corresponding to the top node and the object in the scene to obtain the calculation result of the intermediate return color.

[0153] If the first access flag corresponding to the reflected light of the top node of the stack is visited, a ray tracing calculation is performed according to the second access flag corresponding to the refracted light of the top node of the stack to obtain a calculation result of the intermediate returned color.

[0154] In one embodiment of the present application, when the computer program is executed by a processor, the following steps are further implemented:

[0155] If the initial ray does not intersect with an object in the scene, the calculation result of the intermediate return color is determined based on the preset background color;

[0156] If the initial light intersects an opaque object in the scene, the intermediate return color is calculated based on the diffuse color and highlight color of the opaque object;

[0157] If the initial light intersects with a transparent object in the scene, a new reflected light is constructed, and the child node corresponding to the new reflected light is pushed into the stack. Based on the first access flag corresponding to the reflected light of the child node and the second access flag corresponding to the refracted light of the child node, a ray tracing calculation is performed to obtain the calculation result of the intermediate returned color.

[0158] In one embodiment of the present application, when the computer program is executed by a processor, the following steps are further implemented:

[0159] If the first access flag corresponding to the reflected light of the top node of the stack is visited, and the second access flag corresponding to the refracted light of the top node of the stack is not visited, then a new refracted light is constructed, and the child node corresponding to the new refracted light is pushed into the stack. Based on the first access flag corresponding to the reflected light of the child node and the second access flag corresponding to the refracted light of the child node, ray tracing calculation is performed to obtain the calculation result of the intermediate return color.

[0160] In one embodiment of the present application, when the computer program is executed by a processor, the following steps are further implemented:

[0161] If the first access flag corresponding to the reflected light of the top node of the stack is visited, and the second access flag corresponding to the refracted light of the top node of the stack is visited, then the calculation result of the intermediate return color is obtained based on the intermediate return color corresponding to the reflected light of the top node of the stack and the intermediate return color corresponding to the refracted light of the top node of the stack.

[0162] In one embodiment of the present application, when the computer program is executed by a processor, the following steps are further implemented:

[0163] If the updated current bounce count reaches the preset maximum bounce count, or the current number of nodes in the preset stack is greater than one, the preset return process is executed;

[0164] If the number of current nodes in the preset stack is equal to one, the target return color corresponding to the initial light is obtained based on the calculation results of the intermediate return colors corresponding to the two child nodes under the current node.

[0165] In one embodiment of the present application, when the computer program is executed by a processor, the following steps are further implemented:

[0166] Obtain the ray type flag of the top node in the preset stack, pop the top node out of the stack, and obtain the updated current number of bounces; wherein the ray type flag is used to indicate whether the top node represents a reflected ray;

[0167] Based on the ray type flag of the top node, the intermediate return color and the first access flag corresponding to the reflected ray of the top node are updated, or the intermediate return color and the second access flag corresponding to the refracted ray of the top node are updated.

[0168] The computer-readable storage medium provided in this embodiment has similar implementation principles and technical effects to those of the above method embodiments, and will not be described in detail here.

[0169] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0170] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.

[0171] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A ray tracing calculation method, characterized in that: The method comprises: After the initial light hits an object in the scene for reflection and refraction, a binary tree formed by all the light is obtained; wherein the root node in the binary tree is used to represent the initial light, and the child nodes in the binary tree are used to represent the reflected light and the refracted light obtained after the reflection and refraction; Traversing each node in the binary tree in sequence through a preset stack and performing a stacking operation, performing ray tracing calculation according to a first access flag corresponding to the reflected light of each node and a second access flag corresponding to the refracted light of the top node of the stack, obtaining a calculation result of the intermediate returned color, and obtaining an updated current number of bounces; wherein the first access flag is used to indicate whether the reflected light has been visited, and the second access flag is used to indicate whether the refracted light has been visited; Based on the updated current number of bounces, the current number of nodes in the preset stack, and the calculation results of the intermediate return colors corresponding to each child node, the target return color corresponding to the initial light is obtained.

2. The method according to claim 1, characterized in that The method of sequentially traversing each node in the binary tree through a preset stack and performing a stacking operation, performing a ray tracing calculation according to a first access flag corresponding to a reflected ray of each node and a second access flag corresponding to a refracted ray of a top node of the stack, and obtaining a calculation result of an intermediate returned color includes: Traverse each node in the binary tree in sequence through a preset stack, and first push the root node into the stack; Obtaining a top node in the preset stack, and if the first access flag corresponding to the reflected light of the top node is unvisited, performing an intersection test on the initial light corresponding to the top node and an object in the scene to obtain a calculation result of the intermediate return color; If the first access flag corresponding to the reflected light of the top node of the stack is visited, a ray tracing calculation is performed according to the second access flag corresponding to the refracted light of the top node of the stack to obtain a calculation result of the intermediate returned color.

3. The method according to claim 2, characterized in that The performing an intersection test on the initial light corresponding to the top node of the stack and the object in the scene to obtain the calculation result of the intermediate returned color includes: If the initial light does not intersect with an object in the scene, the calculation result of the intermediate returned color is determined based on a preset background color; If the initial light intersects an opaque object in the scene, the calculation result of the intermediate return color is determined based on the diffuse color and the highlight color of the opaque object; If the initial light intersects with a transparent object in the scene, a new reflected light is constructed, and the child node corresponding to the new reflected light is pushed into the stack. Based on the first access flag corresponding to the reflected light of the child node and the second access flag corresponding to the refracted light of the child node, a ray tracing calculation is performed to obtain the calculation result of the intermediate return color.

4. The method according to claim 2, characterized in that: If the first access flag corresponding to the reflected light of the top node of the stack is visited, performing ray tracing calculation according to the second access flag corresponding to the refracted light of the top node of the stack to obtain the calculation result of the intermediate returned color includes: If the first access flag corresponding to the reflected light of the top node of the stack is visited, and the second access flag corresponding to the refracted light of the top node of the stack is not visited, a new refracted light is constructed, and the child node corresponding to the new refracted light is pushed into the stack, and a ray tracing calculation is performed based on the first access flag corresponding to the reflected light of the child node and the second access flag corresponding to the refracted light of the child node to obtain the calculation result of the intermediate return color.

5. The method according to claim 2, characterized in that: If the first access flag corresponding to the reflected light of the top node of the stack is visited, performing ray tracing calculation according to the second access flag corresponding to the refracted light of the top node of the stack to obtain the calculation result of the intermediate returned color includes: If the first access flag corresponding to the reflected light of the top node of the stack is visited, and the second access flag corresponding to the refracted light of the top node of the stack is visited, then the calculation result of the intermediate return color is obtained based on the intermediate return color corresponding to the reflected light of the top node of the stack and the intermediate return color corresponding to the refracted light of the top node of the stack.

6. The method according to any one of claims 1 to 4, characterized in that: The step of obtaining the target return color corresponding to the initial light based on the calculation result of the updated current number of bounces, the current number of nodes in the preset stack, and the intermediate return color corresponding to each child node comprises: If the updated current number of bounces reaches the preset maximum number of bounces, or the number of current nodes in the preset stack is greater than one, then executing the preset return process; If the number of current nodes in the preset stack is equal to one, the target return color corresponding to the initial light is obtained based on the calculation results of the intermediate return colors corresponding to the two child nodes under the current node.

7. The method according to claim 6, characterized in that The preset return process includes: Obtaining a light type flag of a top node in a preset stack, popping the top node from the stack, and obtaining an updated current number of bounces; wherein the light type flag is used to indicate whether the top node represents a reflected light; Based on the light type flag of the top node of the stack, the intermediate return color and the first access flag corresponding to the reflected light of the top node of the stack are updated, or the intermediate return color and the second access flag corresponding to the refracted light of the top node of the stack are updated.

8. A ray tracing computing device, characterized in that: The device comprises: An acquisition module, used for acquiring a binary tree formed by all the light rays after the initial light rays hit an object in the scene for reflection and refraction; wherein the root node in the binary tree is used for representing the initial light rays, and the child nodes in the binary tree are used for representing the reflected light rays and the refracted light rays obtained after the reflection and refraction; A first calculation module is used to sequentially traverse each node in the binary tree through a preset stack and perform a stacking operation, perform ray tracing calculation according to a first access flag corresponding to the reflected light of each node and a second access flag corresponding to the refracted light of the top node of the stack, obtain a calculation result of the intermediate return color, and obtain an updated current number of bounces; wherein the first access flag is used to indicate whether the reflected light has been visited, and the second access flag is used to indicate whether the refracted light has been visited; The second calculation module is used to obtain the target return color corresponding to the initial light based on the calculation results of the updated current number of bounces, the current number of nodes in the preset stack and the intermediate return color corresponding to each child node.

9. An electronic device, characterized in that: The electronic device includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the ray tracing computational method as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that: The storage medium stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the ray tracing computational method as described in any one of claims 1-7.