Surface normal generation method, device, equipment and storage medium

By acquiring the vertex data of a triangle in a single step within a ray tracing accelerator, the intersection test of rays with the bounding volume hierarchy tree and the calculation of surface normals are achieved. This solves the bandwidth pressure problem caused by acquiring vertex data multiple times in existing technologies and improves rendering performance.

CN120219473BActive Publication Date: 2025-10-21MOORE THREADS TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510696178.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-05-27
Publication Date
2025-10-21
Estimated Expiration
2045-05-27

AI Technical Summary

Technical Problem

In existing technologies, the process of calculating surface normals requires retrieving triangle vertex data from memory multiple times, resulting in significant bandwidth pressure and impacting the rendering performance of the graphics processor.

Method used

In the ray tracing accelerator, by acquiring the vertex data of the triangle once, the intersection test of the ray with the bounding volume hierarchy tree and the calculation of the triangle surface normal are realized, reducing the number of memory accesses.

Benefits of technology

This improves the calculation efficiency of triangle surface normals and reduces memory access pressure, thereby improving the overall processing efficiency of the graphics processor in the ray tracing process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120219473B_ABST
    Figure CN120219473B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a surface normal generation method, device and equipment and a storage medium, wherein the surface normal generation method is applied to a ray tracing accelerator, and the surface normal generation method comprises the following steps: obtaining vertex data of a triangle in a target node in a bounding volume hierarchy tree in a process of performing intersection test of a ray and the target node; and generating a surface normal of the triangle based on the vertex data of the triangle in a case where it is determined that the surface normal of the triangle needs to be generated. The above scheme can improve the calculation efficiency of the surface normal of the triangle, and can also reduce the access pressure on the memory, thereby improving the processing efficiency of the graphics processor in the ray tracing processing process as a whole.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to, but is not limited to, the field of graphics processing technology, and in particular to a surface normal generation method, apparatus, device, and storage medium. Background Art

[0002] Ray tracing is a rendering technique used to simulate the propagation of light in three-dimensional (3D) scenes to generate realistic images. In ray tracing, the basic geometric operation is to calculate the intersection of light and the scene by testing all primitives in the scene. To achieve better rendering effects, it is often necessary to obtain the surface normals of primitives (e.g., triangles) for subsequent calculation and rendering. In related technologies, the process of calculating surface normals requires retrieving the triangle's vertex data from memory, which in turn creates significant bandwidth pressure and affects the rendering performance of the graphics processor. Summary of the Invention

[0003] In view of this, embodiments of the present application provide at least one surface normal generation method, apparatus, device, and storage medium.

[0004] The technical solution of the embodiment of the present application is implemented as follows:

[0005] On the one hand, an embodiment of the present application provides a surface normal generation method, which is applied to a ray tracing accelerator. The surface normal generation method includes: obtaining the vertex data of the triangle in the target node during the intersection test between the ray and the target node in the bounding volume hierarchy tree; when it is determined that the surface normal of the triangle needs to be generated, generating the surface normal of the triangle based on the vertex data of the triangle.

[0006] On the other hand, an embodiment of the present application provides a ray tracing accelerator, which includes: an acquisition unit for acquiring vertex data of a triangle in a target node in a bounding volume hierarchy tree during an intersection test between a ray and the target node; and a normal generation unit for generating a surface normal of a triangle based on the vertex data of the triangle when it is determined that the surface normal of the triangle needs to be generated.

[0007] On the other hand, an embodiment of the present application provides a computer device, including a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the program, it implements some or all of the steps in the above method.

[0008] On the other hand, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which implements some or all of the steps in the above method when executed by a processor.

[0009] In the embodiments of the present application, since the process of determining the surface normal of a triangle is implemented by a ray tracing accelerator, compared to the related art solution in which the ray tracing accelerator only performs the intersection test between the ray and the triangle, and then the computing core completes the surface normal calculation, the number of times vertex data is retrieved from memory is reduced from two to one. This not only improves the efficiency of calculating the surface normal of the triangle, but also reduces the pressure on memory access, thereby improving the overall processing efficiency of the graphics processor during the ray tracing process.

[0010] It should be understood that the above general description and the following detailed description are merely exemplary and explanatory, and do not limit the technical solutions of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] The drawings herein are incorporated into and constitute a part of the specification. These drawings illustrate embodiments consistent with the present application and, together with the specification, are used to illustrate the technical solutions of the present application.

[0012] Figure 1 Schematic diagram of the implementation process of a surface normal generation method provided in the embodiment of the present application Figure 1 ;

[0013] Figure 2 Schematic diagram of the implementation process of a surface normal generation method provided in the embodiment of the present application Figure 2 ;

[0014] Figure 3 Schematic diagram of the implementation process of a surface normal generation method provided in the embodiment of the present application Figure 3 ;

[0015] Figure 4 Schematic diagram of the implementation process of a surface normal generation method provided in the embodiment of the present application Figure 4 ;

[0016] Figure 5 Schematic diagram of the implementation process of a surface normal generation method provided in the embodiment of the present application Figure 5 ;

[0017] Figure 6 Schematic diagram of the implementation process of a surface normal generation method provided in the embodiment of the present application Figure 6 ;

[0018] Figure 7 Schematic diagram of the implementation process of a surface normal generation method provided in the embodiment of the present application Figure 7 ;

[0019] Figure 8 Schematic diagram of the implementation process of a surface normal generation method provided in the embodiment of the present application Figure 8 ;

[0020] Figure 9 A schematic diagram of a BVH tree provided in an embodiment of the present application;

[0021] Figure 10A A schematic diagram of an implementation of a first ray tracing accelerator provided in an embodiment of the present application;

[0022] Figure 10B A schematic diagram of an implementation of a second ray tracing accelerator provided in an embodiment of the present application;

[0023] Figure 11 A schematic diagram of a triangular surface normal provided in an embodiment of the present application;

[0024] Figure 12 A schematic diagram of calculating the normal of a triangle surface provided in an embodiment of the present application Figure 1 ;

[0025] Figure 13 A schematic diagram of calculating the normal of a triangle surface provided in an embodiment of the present application Figure 2 ;

[0026] Figure 14 Schematic diagram of the implementation process of a surface normal generation method provided in the embodiment of the present application Figure 9 ;

[0027] Figure 15 Schematic diagram 10 of an implementation flow of a surface normal generation method provided in an embodiment of the present application;

[0028] Figure 16 A schematic diagram of the structure of a ray tracing accelerator provided in an embodiment of the present application;

[0029] Figure 17 A hardware entity diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0030] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions of this application are further elaborated in detail below with reference to the accompanying drawings and embodiments. The described embodiments should not be regarded as limiting this application. All other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0031] In the following description, references to "some embodiments" describe a subset of all possible embodiments. However, it is understood that "some embodiments" may be the same subset or different subsets of all possible embodiments, and may be combined with each other without conflict. The terms "first / second / third" are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It is understood that the specific order or sequence of "first / second / third" may be interchanged where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.

[0032] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing this application only and are not intended to limit this application.

[0033] (1) Ray tracing is a rendering technique used to simulate the transport of light in a three-dimensional scene to produce realistic images. In ray tracing, the basic geometric operation is to calculate the intersection of the ray and the scene by testing all primitives in the scene. In practice, the primitives are triangles, which are arranged into a spatial data structure to accelerate the calculation of intersections.

[0034] (2) Bounding Volume Hierarchy (BVH) is the most popular acceleration data structure in ray tracing in the past decade. BVH is a tree-based structure that contains different types of nodes, including but not limited to box nodes and triangle nodes. Box nodes are usually internal nodes, while triangle nodes are leaf nodes that store the basic graphics of the scene. Each bounding volume tightly surrounds the basic graphics in the leaf, and then these bounding volumes are recursively combined into larger bounding volumes, eventually forming a tree structure with only one bounding volume at the top of the tree.

[0035] (3) Fixed-Function Ray Tracing Accelerator is a hardware accelerator used to improve the performance and efficiency of ray tracing algorithms. Fixed-Function Ray Tracing Accelerator accelerates the ray tracing algorithm through specially designed hardware circuits and optimization algorithms. It uses fixed functions to process the calculation of the intersection of light and objects in the scene, instead of using traditional programmable shaders. This fixed function design allows the accelerator to efficiently process a large number of ray intersection calculation operations in parallel, thereby significantly improving the performance of the ray tracing algorithm. The working method of the fixed-function ray tracing accelerator can be simply summarized as follows. First, it receives scene data and light information from the main processor. Then, the accelerator uses fixed functions to calculate the intersection of light and objects in the scene and determine the path and propagation mode of the light. Next, based on the intersection calculation results, the accelerator calculates and updates the color and brightness of the light. Finally, the accelerator sends the final image data back to the main processor.

[0036] In the implementation scenario of the relevant technology, BVH traversal is a depth-first tree traversal by testing whether the ray intersects with the bounding volume within the box-shaped node, that is, the ray / bounding volume intersection test. When the ray reaches a triangle node, the ray will perform an intersection test with the triangle in the triangle node. Among them, the intersection test for the triangle includes: obtaining the vertex data of the triangle, and calculating whether the ray and the triangle intersect based on the vertex data and the direction of the ray, as well as the actual intersection point in the case of intersection. In order to improve the test efficiency and calculation speed of the intersection test, the test processes of the above-mentioned ray / bounding volume intersection test and ray / triangle intersection test can be placed in the ray tracing accelerator. Finally, the ray tracing accelerator can feed back the triangles that meet the requirements to the computing core. The computing core determines the surface normal of the triangle based on the vertex data of the triangle and performs subsequent calculations.

[0037] Research has shown that determining triangle surface normals requires obtaining vertex data for both the ray / triangle intersection test in the ray tracing accelerator and the computational core. This multiple acquisition of triangle vertex data results in a significant number of memory accesses, significantly impacting the overall efficiency of the ray tracing system.

[0038] The present application provides a surface normal generation method that can be executed by a processor of a computer device. The computer device may include a server, laptop, tablet, desktop computer, smart TV, set-top box, mobile device (e.g., mobile phone, portable video player, personal digital assistant, dedicated messaging device, portable gaming device), or other device with data processing capabilities.

[0039] Figure 1 Schematic diagram of the implementation process of a surface normal generation method provided in the embodiment of the present application Figure 1 ,like Figure 1 As shown, the method includes the following steps S101 to S102:

[0040] Step S101 : in the process of performing intersection test between a ray and a target node in a bounding volume hierarchy tree, obtaining vertex data of a triangle in the target node.

[0041] In some implementation scenarios, to reduce the number of times the vertex data of a triangle in memory is retrieved during the calculation of the triangle surface normal, embodiments of the present application place the calculation of the triangle surface normal in the ray tracing accelerator. This allows the ray tracing accelerator to perform intersection tests between a ray and a target node in the bounding volume hierarchy tree by only retrieving the triangle vertex data from memory once, completing both the intersection test between the ray and the target node and the calculation of the triangle surface normal.

[0042] In some embodiments, the target node may be a node storing a basic shape in a BVH tree. Generally, a node storing a basic shape is a leaf node in the BVH tree. The basic shape may be any one of a triangle, a polygon, a point, and a line. To facilitate understanding of the present application, the following embodiments are described using a triangle as the basic shape.

[0043] In some embodiments, the above-mentioned process of performing intersection tests between a ray and a target node in a bounding volume hierarchy tree includes: calculating intersection tests between the ray and all triangles stored in the target node, determining the triangle that intersects with the ray among all triangles, and determining a triangle that needs to be fed back among the triangles that intersect with the ray based on user-defined rules, and finally feeding back the triangle to the upstream unit.

[0044] In the embodiment of the present application, the vertex data of the triangle in the target node is obtained not only for determining the surface normal of the triangle, but also for intersection testing of light and the triangle.

[0045] In some embodiments, the vertex data of the triangle includes vertex coordinates of each of the three vertices of the triangle. In some implementations, the vertex coordinates of the vertex include coordinate values ​​in three directions. For example, taking the three directions (x, y, z), the vertex coordinates of the vertex can be expressed as (Dx, Dy, Dz).

[0046] In some embodiments, the vertex data of the triangle obtained in the above step S101 includes: determining the index of the triangle, determining the indices of three vertices in the triangle based on the index of the triangle; and then obtaining the vertex coordinates of each of the three vertices based on the indices of the three vertices.

[0047] Step S102: When it is determined that a surface normal of a triangle needs to be generated, the surface normal of the triangle is generated based on vertex data of the triangle.

[0048] The surface normal of the triangle is a vector including normal components in three directions. Taking the three directions as (x, y, z) as an example, the surface normal of the triangle can be expressed as (nx, ny, nz).

[0049] In some embodiments, the surface normal of the triangle may be generated based on the vertex coordinates of the three vertices of the triangle by cross multiplication.

[0050] For example, if the coordinates of the three vertices of a triangle are known to be P1 (x1, y1, z1), P2 (x2, y2, z2), and P3 (x3, y3, z3), we can find any two edge vectors of the triangle, such as P1P2 and P1P3, and then calculate the surface normal of the triangle through cross product.

[0051] Of course, the present application may also adopt other methods to generate the surface normal of the triangle based on the vertex coordinates of the three vertices of the triangle, and the present application does not limit this.

[0052] In some embodiments, it may be determined that the surface normal of the triangle needs to be generated when at least one of the following conditions is met: the intersection test result indicates that the triangle intersects the light; and the instruction control bit indicates that the surface normal of the triangle needs to be generated.

[0053] The intersection test result is the test result of the intersection test between the ray and the target node in the bounding volume hierarchy tree. The intersection test result can indicate whether the triangle intersects with the ray.

[0054] In some embodiments, the above-mentioned instruction control bit may be carried in an intersection test request, which is sent by the computing core to the ray tracing accelerator, and the intersection test request is used to instruct the ray tracing accelerator to perform an intersection test between the ray and the target node in the bounding volume hierarchy tree and whether it is necessary to generate the surface normal of the triangle.

[0055] In some possible implementations, when the instruction control bit indicates that the surface normal of the triangle needs to be generated, the surface normal of the triangle is generated based on the vertex data of the triangle; or, when the intersection test result represents that the triangle intersects with the light, the surface normal of the triangle is generated based on the vertex data of the triangle; or, when the instruction control bit indicates that the surface normal of the triangle needs to be generated and the intersection test result represents that the triangle intersects with the light, the surface normal of the triangle is generated based on the vertex data of the triangle.

[0056] In the embodiments of the present application, since the process of determining the surface normal of a triangle is implemented by a ray tracing accelerator, compared to the related art solution in which the ray tracing accelerator only performs the intersection test between the ray and the triangle, and then the computing core completes the surface normal calculation, the number of times vertex data is retrieved from memory is reduced from two to one. This not only improves the efficiency of calculating the surface normal of the triangle, but also reduces the pressure on memory access, thereby improving the overall processing efficiency of the graphics processor during the ray tracing process.

[0057] In some embodiments, the ray tracing accelerator is connected to a computing core; the surface normal generated by the ray tracing accelerator is a surface normal before normalization; and the computing core is used to normalize the surface normal generated by the ray tracing accelerator.

[0058] In some possible implementations, the method further includes: a ray tracing accelerator sending a surface normal of the triangle to the computing core, wherein the surface normal generated by the ray tracing accelerator is a surface normal before normalization.

[0059] Considering that normalization involves square root and division operations, the hardware implementation cost is high. Deferring normalization to the compute core can reduce the complexity of the accelerator while utilizing the general computing power of the compute core to complete normalization.

[0060] In some possible implementations, when a ray tracing accelerator detects intersection between a ray and a triangle, it calculates an unnormalized surface normal (e.g., obtained by interpolating vertex normals from barycentric coordinates). The ray tracing accelerator sends the unnormalized surface normal to the compute core via a hardware interface. After receiving the data, the compute core normalizes the surface normal using shading instructions. The normalized surface normal is then used in subsequent shading tasks.

[0061] In the above embodiment, the ray tracing accelerator does not need to integrate a normalization logic unit, which reduces hardware area and power consumption. After removing the normalization operation, the ray tracing accelerator can process ray tracing tasks faster and improve the overall rendering throughput. The normalization operation is completed in the computing core and can also flexibly adapt to different rendering requirements.

[0062] Figure 2 This is a schematic diagram of the implementation process of a surface normal generation method provided in an embodiment of the present application. Figure 2 , the method can be executed by a processor of a computer device. The method can also include obtaining light data of the light during the process of performing an intersection test between the light and the target node in the bounding volume hierarchy tree; and generating an intersection test result corresponding to the triangle based on the light data and the vertex data of the triangle. Figure 1 , the above step S101 can be updated to step S201, and the method can further include step S202, combining Figure 2 The steps shown are explained.

[0063] Step S201 : in the process of performing an intersection test between a ray and a target node in a bounding volume hierarchy tree, obtaining vertex data of a triangle in the target node and ray data of the ray.

[0064] In some embodiments, since it is necessary to implement the intersection test between the ray and the triangle and the calculation of the surface normal of the triangle in the ray tracing accelerator at the same time, Figure 1 Based on the embodiment, in addition to obtaining the vertex data of the triangle in the target node, it is also necessary to obtain the light data of the light.

[0065] The light data of the light may include data such as the position of the light source point, the light direction vector, etc. The vertex data of the triangle may include coordinate data of the three vertices in the triangle.

[0066] Step S202: Generate an intersection test result corresponding to the triangle based on the light data and the vertex data of the triangle.

[0067] The intersection test result can indicate whether the current triangle intersects the ray. For example, the intersection test result can be a first intersection test result indicating that the current triangle intersects the ray; or a second intersection test result indicating that the current triangle does not intersect the ray. It is understood that if a first intersection test result indicating that the current triangle intersects the ray is obtained, the first intersection test result can also include the intersection position.

[0068] In some embodiments, after obtaining the light source point position, the light direction vector and the vertex coordinates of the three vertices of the triangle to be tested, the intersection test result can be generated in the following manner: based on the vertex coordinates of the three vertices of the triangle, construct the plane equation corresponding to the triangle; based on the light source point position, the light direction vector and the plane equation corresponding to the triangle in the light data, determine the coordinates of the intersection of the light and the plane where the triangle is located; when the intersection is inside the triangle, generate a first intersection test result representing that the current triangle intersects with the light; when the intersection is outside the triangle, generate a second intersection test result representing that the current triangle does not intersect with the light.

[0069] In the embodiment of the present application, since the surface normal of the triangle is calculated by a ray tracing accelerator, the surface normal determination process of the triangle can be completed simultaneously by obtaining the vertex data of the triangle once, and the intersection test between the light and the triangle can also be completed, thereby improving computing efficiency and reducing memory access pressure.

[0070] Figure 3 This is a schematic diagram of the implementation process of a surface normal generation method provided in an embodiment of the present application. Figure 3 , the method can be executed by a processor of a computer device. Figure 1 , the above step S101 can be updated to step S301, the method can further include step S302, step S102 can be updated to step S303, combined Figure 3 The steps shown are explained.

[0071] Step S301 : in the process of performing intersection test between a ray and a target node in a bounding volume hierarchy tree, obtaining vertex data of a triangle in the target node and ray data of the ray.

[0072] Step S302: Generate an intersection test result corresponding to the triangle based on the light data and the vertex data of the triangle.

[0073] Here, the above steps S301 to S302 correspond to the above steps S201 to S202 respectively, and the specific implementation of the above steps S201 to S202 may be referred to during implementation.

[0074] Step S303: In response to the intersection test result indicating that the triangle intersects the light, a surface normal of the triangle is generated based on vertex data of the triangle.

[0075] In the current embodiment, the ray tracing accelerator first obtains the vertex data of the triangle and the ray data of the light, and determines the intersection test result corresponding to the triangle based on the vertex data and the ray data. At this time, the surface normal of the triangle has not yet been calculated.

[0076] In some embodiments, when the obtained intersection test result indicates that the triangle intersects the light, the surface normal of the triangle is generated based on the vertex data of the triangle. The process of generating the surface normal can refer to Figure 2 Corresponding specific implementation methods.

[0077] In some embodiments, when the obtained intersection test result indicates that the triangle does not intersect the light ray, the vertex data of the triangle is discarded, and the subsequent surface normal calculation process of the triangle is not performed.

[0078] In other embodiments, a control bit may be set in the ray tracing accelerator to control whether the surface normal generation process is enabled. Based on this, the above step S303 may also include: in response to the intersection test result indicating that the triangle intersects with the ray, when the control bit is a first value, generating the surface normal of the triangle based on the vertex data of the triangle; when the control bit is a second value, discarding the vertex data of the triangle. It is understandable that the above process of determining whether the control bit is the first value can be set at any execution time before calculating the surface normal. This application does not limit this.

[0079] In an embodiment of the present application, before calculating the surface normal of a triangle, an intersection test result corresponding to the triangle is first determined based on the vertex data and the light data. Then, if the intersection test result indicates that the triangle does not intersect with the light, the subsequent surface normal calculation process of the triangle is not performed. In this way, unnecessary computing resources can be saved.

[0080] Figure 4 This is a schematic diagram of the implementation process of a surface normal generation method provided in an embodiment of the present application. Figure 4 , the method can be executed by a processor of a computer device. Figure 1 , the above step S101 can be updated to step S401, the method can further include step S402, step S102 can be updated to step S403, combined Figure 4 The steps shown are explained.

[0081] Step S401 : in the process of performing intersection test between a ray and a target node in a bounding volume hierarchy tree, obtaining vertex data of a triangle in the target node and ray data of the ray.

[0082] Step S402: Generate an intersection test result corresponding to the triangle based on the light data and the vertex data of the triangle.

[0083] Here, the above steps S401 to S402 correspond to the above steps S201 to S202 respectively, and the specific implementation of the above steps S201 to S202 may be referred to during implementation.

[0084] Step S403 : In response to obtaining the vertex data of the triangle, generate a surface normal of the triangle based on the vertex data of the triangle.

[0085] In the current embodiment, the ray tracing accelerator first obtains the vertex data of the triangle and the light data of the ray, and in response to obtaining the vertex data and light data of the triangle, generates the intersection test result corresponding to the triangle based on the light data and the vertex data of the triangle, and generates the surface normal of the triangle based on the vertex data of the triangle. That is, compared to Figure 3 Correspondingly, the current embodiment does not need to obtain the intersection test result before calculating the surface normal, and directly responds to obtaining the vertex data of the triangle and generates the surface normal of the triangle based on the vertex data of the triangle.

[0086] In the embodiment of the present application, regardless of the intersection test result corresponding to the triangle, the surface normal corresponding to the triangle is obtained. After obtaining the intersection test result corresponding to the triangle, the method further includes: if the intersection test result indicates that the triangle intersects the ray, retaining the surface normal of the triangle; if the intersection test result indicates that the triangle does not intersect the ray, discarding the surface normal of the triangle.

[0087] In other embodiments, a control bit may be set in the ray tracing accelerator to control whether the surface normal generation process is enabled. Based on this, the above step S403 may also include: in response to obtaining the vertex data of the triangle, generating the surface normal of the triangle based on the vertex data of the triangle when the control bit is a first value; and discarding the vertex data of the triangle when the control bit is a second value. It is understandable that the above process of determining whether the control bit is the first value can be set at any execution time before calculating the surface normal. This application is not limited to this.

[0088] In some embodiments, the method may further include step S404.

[0089] Step S404: Send feedback data to the computing core; the feedback data is determined based on the intersection test result of the triangle in the target node.

[0090] In related technologies, when there is a triangle at the current node that intersects with the ray, the ray tracing accelerator is used to determine a triangle that ultimately needs to be fed back to the computing core as the target triangle, as well as the coordinates of the intersection of the ray and the target triangle based on the vertex data of the triangle and the ray data of the ray.

[0091] In the embodiment of the present application, since the process of determining the surface normal of a triangle is also completed by the ray tracing accelerator, when a triangle intersecting the ray exists at the current node, the feedback data includes first feedback data indicating that a triangle intersecting the ray exists at the current node. In addition to including the target triangle and the coordinates of the intersection of the ray and the target triangle, the first feedback data also includes the surface normal of the target triangle. If no triangle intersecting the ray exists at the current node, the feedback data includes second feedback data indicating that no triangle intersecting the ray exists at the current node.

[0092] In some embodiments, the surface normal generation method further includes: receiving an intersection test request sent by a computing core; the intersection test request is used to instruct the ray tracing accelerator to perform an intersection test between the ray and the target node in the bounding volume hierarchy tree and whether it is necessary to generate the surface normal of the triangle.

[0093] In the embodiment of the present application, before obtaining the vertex data of the triangle in the target node and the ray data of the ray, the ray tracing accelerator needs to obtain an intersection test request sent by the computing core. In response to the intersection test request, the ray tracing accelerator begins to perform intersection tests between the ray and the target node in the bounding volume hierarchy tree, and to generate the surface normal of the triangle. Then, the surface normal generation method of any of the above embodiments is executed in the ray tracing accelerator.

[0094] Figure 5 This is a schematic diagram of the implementation process of a surface normal generation method provided in an embodiment of the present application. Figure 5 , the method can be executed by a processor of a computer device. Figure 4 , Figure 4 S404 in can be updated to S501 to S502, which will be combined Figure 5 The steps shown are explained.

[0095] Step S501: When the intersection test results of all triangles in the target node are obtained, the feedback data is generated based on the intersection test results of all triangles in the target node.

[0096] The feedback data is used to indicate whether a triangle intersecting the ray exists at the target node, and if the feedback data indicates that a triangle intersecting the ray exists at the target node, the feedback data includes a surface normal of the triangle intersecting the ray. The surface normal of the triangle intersecting the ray is generated based on the vertex data of the triangle during the intersection test.

[0097] In some embodiments, after obtaining the intersection test results of all triangles of the target node, it can be known whether each triangle in the target node intersects with the light. In the case that there is at least one triangle intersecting with the light, the above-mentioned feedback data includes first feedback data indicating that there is a triangle intersecting with the light at the current node. In addition to the target triangle and the coordinates of the intersection of the light and the target triangle, the first feedback data also includes the surface normal of the target triangle. In the case that there is no triangle intersecting with the light at the current node, the above-mentioned feedback data includes second feedback data indicating that there is no triangle intersecting with the light at the current node.

[0098] In some embodiments, step S5011 may be used to implement the above-mentioned intersection test results based on all triangles in the target node to generate the feedback data.

[0099] Step S5011: When there are at least two triangles at the target node that intersect with the light, determine the target triangle among the at least two triangles that intersect with the light based on a preset selection strategy; and generate feedback data including the surface normal of the target triangle.

[0100] In some embodiments, the preset selection strategy may include selecting the triangle closest to the light source of the ray and intersecting the ray as the target triangle; selecting any one of at least two triangles intersecting the ray as the target triangle; or selecting the last triangle intersecting the ray as the target triangle. This preset selection strategy may be customized based on actual rendering scenarios and user needs, and is not limited in this application.

[0101] Step S502: Send the feedback data to the computing core.

[0102] In an embodiment of the present application, the computing core can perform subsequent image rendering based on the obtained feedback data. For example, when the feedback data is the first feedback data indicating that the current node has a triangle that intersects with the ray, the calculation process of the reflected ray can be performed based on the target triangle and the coordinates of the intersection of the ray and the target triangle.

[0103] In an embodiment of the present application, the ray tracing accelerator can not only feed back the test results of the intersection test to the computing core, but also feed back the surface normal of the target triangle that intersects with the ray, thereby enabling the computing core to directly perform subsequent rendering processes based on the surface normal of the target triangle, saving the computing resources of the computing core. At the same time, from the perspective of the overall processing flow of the graphics processor, the frequency of memory access is reduced, saving system bandwidth.

[0104] Figure 6 This is a schematic diagram of the implementation process of a surface normal generation method provided in an embodiment of the present application. Figure 6 , the method can be executed by a processor of a computer device. Figure 6 The steps shown are explained.

[0105] Step S601 : in the process of performing intersection test between a ray and a target node in a bounding volume hierarchy tree, obtaining vertex data of a triangle in the target node and ray data of the ray.

[0106] Step S602: Generate an intersection test result corresponding to the triangle based on the light data and the vertex data of the triangle.

[0107] Step S603: Generate a surface normal of the triangle based on the vertex data of the triangle.

[0108] Here, the above steps S601 to S602 correspond to the above steps S201 to S202 respectively, and the specific implementation of the above steps S201 to S202 can be referred to when implementing. Step S603 corresponds to the above step S102, and the specific implementation of the above step S102 can be referred to when implementing.

[0109] Step S604: If the intersection test results of all triangles in the target node are not obtained, obtain the vertex data of the next triangle in the target node that has not been subjected to the intersection test, and obtain the surface normal of the next triangle and the intersection test result corresponding to the next triangle, until the intersection test results of all triangles in the target node are obtained, and send feedback data to the computing core; the feedback data is determined based on the intersection test results of the triangles in the target node.

[0110] In an embodiment of the present application, in the process of performing the intersection test of triangles and rays on all triangles of the target node in turn, the following steps will be repeated: obtaining the vertex data of the triangles that have not undergone the intersection test (in the case where the ray data of the ray is not obtained, the ray data of the ray will also be obtained), and based on the above steps S602 and S603, determining the intersection test result corresponding to the current triangle, and determining the surface normal of the current triangle. Repeat the above steps until all triangles in the target node have completed the above process. It can be understood that in the process of each loop, the relative order and execution status of the process of determining the intersection test result corresponding to the current triangle and the process of determining the surface normal of the current triangle can be referred to any of the above embodiments. Here, it is just a simple description of each loop process, and it is not a limitation on the relative order and execution status between the two processes.

[0111] In the above process, if it is determined that the intersection test results of all triangles in the target node have not been obtained, the vertex data of the next triangle in the target node that has not been subjected to the intersection test is obtained, and the surface normal of the next triangle and the intersection test result corresponding to the next triangle are obtained, until the intersection test results of all triangles in the target node are obtained, and feedback data is sent to the computing core.

[0112] In an embodiment of the present application, in the process of performing intersection tests / calculating surface normals on all triangles in the target node in turn, it can be determined whether the traversal process has been completed for all triangles in the target node, and after the traversal is completed, feedback data is determined based on the intersection test results of all triangles and the surface normals of the triangles. In this way, the accuracy of the feedback data can be guaranteed.

[0113] Figure 7 This is a schematic diagram of the implementation process of a surface normal generation method provided in an embodiment of the present application. Figure 7 , the method can be executed by a processor of a computer device. Figure 1 The ray tracing accelerator includes a normal generation unit, and the generation of the surface normal of the triangle based on the vertex data of the triangle includes: generating the surface normal of the triangle based on the vertex data of the triangle by the normal generation unit. The normal generation unit includes a first subtraction unit and a second subtraction unit corresponding to each direction, and a fusion calculation unit corresponding to each direction. The vertex data includes coordinates corresponding to three directions, Figure 1 S102 in can be updated to S701 to S703, which will be combined Figure 7 The steps shown are explained.

[0114] Step S701: Perform a subtraction operation on the coordinates corresponding to the second vertex and the first vertex of the triangle in the direction by the first subtraction unit to obtain a first difference coordinate.

[0115] In the embodiment of the present application, the vertex data includes coordinates corresponding to three directions, namely, coordinates in any one direction, coordinates in a first other direction, and coordinates in a second other direction. In step S701 above, the coordinates of the second vertex corresponding to that direction are subtracted from the coordinates of the first vertex corresponding to that direction using the first subtraction unit corresponding to each direction, thereby obtaining the first difference coordinates corresponding to each direction.

[0116] Step S702: Perform a subtraction operation on the coordinates of the third vertex and the first vertex of the triangle corresponding to the direction by the second subtraction unit to obtain second difference coordinates.

[0117] In an embodiment of the present application, in the above step S701, it is necessary to perform a subtraction operation on the coordinates corresponding to the third vertex in the direction and the coordinates corresponding to the first vertex in the direction through the second subtraction unit corresponding to each direction, so as to obtain the second difference coordinates corresponding to each direction.

[0118] For example, the triangle includes three vertices: V1, V2, and V3. The coordinates of the first vertex V1 are (D11, D12, D13), the coordinates of the second vertex V2 are (D21, D22, D23), and the coordinates of the third vertex V3 are (D31, D32, D33). Furthermore, the normal generation unit includes a first subtraction unit and a second subtraction unit corresponding to any direction, a first subtraction unit and a second subtraction unit corresponding to a first other direction, and a first subtraction unit and a second subtraction unit corresponding to a second other direction.

[0119] Accordingly, the above steps S701 to S702 can be implemented in the following manner:

[0120] For any direction: subtract the coordinate D21 of the second vertex V2 from the coordinate D11 of the first vertex V1 through the first subtraction unit corresponding to any direction to obtain the first difference coordinate corresponding to any direction; subtract the coordinate D31 of the third vertex V3 from the coordinate D11 of the first vertex V1 through the second subtraction unit corresponding to any direction to obtain the second difference coordinate corresponding to any direction.

[0121] For the first other direction: perform a subtraction operation on the coordinate D22 of the second vertex V2 and the coordinate D12 of the first vertex V1 through the first subtraction unit corresponding to the first other direction to obtain the first difference coordinate corresponding to the first other direction; perform a subtraction operation on the coordinate D32 of the third vertex V3 and the coordinate D12 of the first vertex V1 through the second subtraction unit corresponding to the first other direction to obtain the second difference coordinate corresponding to the first other direction.

[0122] For the second other direction: subtract the coordinate D23 of the second vertex V2 and the coordinate D13 of the first vertex V1 through the first subtraction unit corresponding to the second other direction to obtain the first difference coordinate corresponding to the second other direction; subtract the coordinate D33 of the third vertex V3 and the coordinate D13 of the first vertex V1 through the second subtraction unit corresponding to the second other direction to obtain the second difference coordinate corresponding to the second other direction.

[0123] As described above, the first difference coordinate and the second difference coordinate corresponding to each of the three directions can be obtained.

[0124] Step S703: Perform fusion calculation on the first difference coordinates and the second difference coordinates of the first other direction in the three directions, and the first difference coordinates and the second difference coordinates of the second other direction in the three directions through the fusion calculation unit corresponding to any direction in the three directions to obtain the normal component corresponding to the any direction.

[0125] In some embodiments, the fusion calculation in the above-mentioned fusion calculation unit includes: taking the product of the first difference coordinate of the first other direction and the second difference coordinate of the second other direction as the first intermediate value; taking the product of the first difference coordinate of the second other direction and the second difference coordinate of the first other direction as the second intermediate value; taking the difference between the second intermediate value and the first intermediate value as the normal component corresponding to any direction.

[0126] Exemplarily, the process of determining the normal vectors corresponding to the three directions includes:

[0127] For any direction: the product of the first difference coordinate of the first other direction and the second difference coordinate of the second other direction is used as the first intermediate value of any direction; the product of the first difference coordinate of the second other direction and the second difference coordinate of the first other direction is used as the second intermediate value of any direction; the difference between the second intermediate value and the first intermediate value in any direction is used as the normal component corresponding to the any direction.

[0128] For the first other direction: take the product of the first difference coordinate of any direction and the second difference coordinate of the second other direction as the first intermediate value of the first other direction; take the product of the first difference coordinate of the second other direction and the second difference coordinate of any direction as the second intermediate value of the first other direction; take the difference between the second intermediate value and the first intermediate value of the first other direction as the normal component corresponding to the first other direction.

[0129] For the second other direction: by taking the product of the first difference coordinate of the first other direction and the second difference coordinate of any direction as the first intermediate value of the second other direction; taking the product of the first difference coordinate of any direction and the second difference coordinate of the first other direction as the second intermediate value of the second other direction; taking the difference between the second intermediate value and the first intermediate value of the second other direction as the normal component corresponding to the second other direction.

[0130] As described above, the normal vector corresponding to each of the three directions can be obtained.

[0131] It can be understood that, in the process of determining the normal vector corresponding to each direction by the above-mentioned normal generation unit, since each direction corresponds to the first subtraction unit, the second subtraction unit and the fusion calculation unit, that is, the calculation process of the normal direction corresponding to each direction is independent of each other, therefore, parallel calculation of the normal direction corresponding to each direction can be achieved.

[0132] In an embodiment of the present application, since the normal generation unit includes a first subtraction unit corresponding to each direction, a second subtraction unit and a fusion calculation unit corresponding to each direction, for the normal components corresponding to the three directions, the three normal components can be calculated in parallel through the first subtraction unit, the second subtraction unit and the fusion calculation unit corresponding to each direction. In this way, the calculation efficiency of the normal of the triangle surface can be improved.

[0133] Figure 8 This is a schematic diagram of the implementation process of a surface normal generation method provided in an embodiment of the present application. Figure 8 , the method can be executed by a processor of a computer device. Figure 1 The ray tracing accelerator includes a normal generation unit, and generating the surface normal of the triangle based on the vertex data of the triangle includes: generating the surface normal of the triangle based on the vertex data of the triangle by the normal generation unit. The normal generation unit includes two first subtraction units, two second subtraction units, and a fusion calculation unit; the vertex data includes coordinates corresponding to three directions. Figure 1 The S102 in can be updated to S801, which will be combined with Figure 8 The steps shown are explained.

[0134] Step S801: Calculate the normal components in three directions in sequence through the first subtraction unit, the second subtraction unit and the fusion calculation unit.

[0135] In the embodiment of the present application, the vertex data includes coordinates corresponding to three directions, namely, coordinates in any direction, coordinates in a first other direction, and coordinates in a second other direction. Since the normal generation unit includes two first subtraction units, two second subtraction units, and a fusion calculation unit, the above five units need to be shared in the process of calculating the normal component corresponding to each direction, and the loop unit or loop logic in the normal generation unit controls the sequential determination process of the normal components in these three directions.

[0136] In some embodiments, the first subtraction unit, the second subtraction unit, and the fusion calculation unit may first perform the calculation process of the normal component in any direction, then control the first subtraction unit, the second subtraction unit, and the fusion calculation unit to perform the calculation process of the normal component in the first other direction, and finally control the first subtraction unit, the second subtraction unit, and the fusion calculation unit to perform the calculation process of the normal component in the second other direction. Of course, the order from any one direction to the second other direction is only an example of the order of calculation of the three directions in sequence. This application can also adopt other orders, as long as the calculation process of the normal components in the three directions is completed through three cycles.

[0137] In some embodiments, the calculation of the normal component in any one of the three directions can be achieved through steps S8011 to S8013.

[0138] Step S8011: Subtract, by one of the first subtraction units, the coordinates of the second vertex of the triangle in the first other direction from the coordinates of the first vertex in the first other direction to obtain first difference coordinates in the first other direction. Subtract, by another of the first subtraction units, the coordinates of the second vertex of the triangle in the second other direction from the coordinates of the first vertex in the second other direction to obtain first difference coordinates in the first other direction.

[0139] In some embodiments, for the first other direction, the coordinates of the second vertex in the first other direction and the coordinates of the first vertex in the first other direction are subtracted by the first subtraction unit corresponding to the first other direction to obtain the first difference coordinates of the first other direction; for the second other direction, the coordinates of the second vertex in the second other direction and the coordinates of the first vertex in the second other direction are subtracted by the first subtraction unit corresponding to the second other direction to obtain the first difference coordinates of the second other direction.

[0140] Step S8012: Subtract, by one of the second subtraction units, the coordinates of the third vertex of the triangle in the first other direction from the coordinates of the first vertex in the first other direction to obtain second difference coordinates in the first other direction. Subtract, by another of the second subtraction units, the coordinates of the third vertex of the triangle in the second other direction from the coordinates of the first vertex in the second other direction to obtain second difference coordinates in the second other direction.

[0141] In some embodiments, for the first other direction, the coordinates of the third vertex in the first other direction and the coordinates of the first vertex in the first other direction are subtracted by the second subtraction unit corresponding to the first other direction to obtain the second difference coordinates of the first other direction; for the second other direction, the coordinates of the third vertex in the second other direction and the coordinates of the first vertex in the second other direction are subtracted by the second subtraction unit corresponding to the second other direction to obtain the second difference coordinates of the second other direction.

[0142] Step S8013: The fusion calculation unit performs fusion calculation on the first difference coordinate of the first other direction, the first difference coordinate of the second other direction, the second difference coordinate of the first other direction, and the second difference coordinate of the second other direction to obtain the normal component corresponding to any direction.

[0143] In some embodiments, the fusion calculation in the above-mentioned fusion calculation unit includes: taking the product of the first difference coordinate of the first other direction and the second difference coordinate of the second other direction as the first intermediate value; taking the product of the first difference coordinate of the second other direction and the second difference coordinate of the first other direction as the second intermediate value; taking the difference between the first intermediate value and the second intermediate value as the normal component corresponding to any direction.

[0144] Exemplarily, the triangle includes three vertices, V1, V2 and V3, wherein the coordinates of the first vertex V1 are (D11, D12, D13), the coordinates of the second vertex V2 are (D21, D22, D23), and the coordinates of the third vertex V3 are (D31, D32, D33).

[0145] Accordingly, the process of determining the normal vectors corresponding to the above three directions includes three loop processes:

[0146] In the first loop process, the above-mentioned first subtraction unit, second subtraction unit and fusion calculation unit can first execute the calculation process of the normal component in any direction: the first subtraction unit corresponding to the first other direction performs a subtraction operation on the coordinate D22 of the second vertex in the first other direction and the coordinate D12 of the first vertex in the first other direction to obtain the first difference coordinate of the first other direction; the first subtraction unit corresponding to the second other direction performs a subtraction operation on the coordinate of the second vertex in the second other direction D23 and the coordinate D13 of the first vertex in the second other direction to obtain the first difference coordinate of the second other direction; the second subtraction unit corresponding to the first other direction performs a subtraction operation on the coordinate of the third vertex in the first other direction D32 and the coordinate D12 of the first vertex in the first other direction to obtain the second difference coordinate of the first other direction; the second subtraction unit corresponding to the second other direction performs a subtraction operation on the coordinate D33 of the third vertex in the second other direction and the coordinate D13 of the first vertex in the second other direction to obtain the second difference coordinate of the second other direction. The fusion calculation unit uses the product of the first difference coordinate of the first other direction and the second difference coordinate of the second other direction as the first intermediate value of any direction; uses the product of the first difference coordinate of the second other direction and the second difference coordinate of the first other direction as the second intermediate value of any direction; and uses the difference between the first intermediate value and the second intermediate value of any direction as the normal component corresponding to the any direction.

[0147] In the second loop process, the above-mentioned first subtraction unit, second subtraction unit and fusion calculation unit can first execute the calculation process of the normal component of the first other direction: the first subtraction unit corresponding to any direction subtracts the coordinate D21 of the first vertex in the any direction from the coordinate D11 of the second vertex in the any direction to obtain the first difference coordinate of the any direction; the first subtraction unit corresponding to the second other direction subtracts the coordinate D23 of the first vertex in the second other direction from the coordinate D13 of the second other direction to obtain the first difference coordinate of the second other direction; the second subtraction unit corresponding to any direction subtracts the coordinate D31 of the third vertex in the any direction from the coordinate D11 of the first vertex in the any direction to obtain the second difference coordinate of the any direction; the second subtraction unit corresponding to the second other direction subtracts the coordinate D33 of the third vertex in the second other direction from the coordinate D13 of the first vertex in the second other direction to obtain the second difference coordinate of the second other direction. The fusion calculation unit uses the product of the first difference coordinate of any direction and the second difference coordinate of the second other direction as the first intermediate value of the first other direction; uses the product of the first difference coordinate of the second other direction and the second difference coordinate of any direction as the second intermediate value of the first other direction; and uses the difference between the first intermediate value and the second intermediate value of the first other direction as the normal component corresponding to the first other direction.

[0148] In the third loop process, the first subtraction unit, the second subtraction unit and the fusion calculation unit can first execute the calculation process of the normal component of the second other direction: the first subtraction unit corresponding to any direction performs a subtraction operation on the coordinate D21 of the second vertex in any direction and the coordinate D11 of the first vertex in any direction to obtain the first difference coordinate of the any direction; the first subtraction unit corresponding to the first other direction performs a subtraction operation on the coordinate D22 of the second vertex in the first other direction and the coordinate D12 of the first vertex in the first other direction to obtain the first difference coordinate of the first other direction; the second subtraction unit corresponding to any direction performs a subtraction operation on the coordinate D31 of the third vertex in any direction and the coordinate D11 of the first vertex in any direction to obtain the second difference coordinate of the any direction; the second subtraction unit corresponding to the first other direction performs a subtraction operation on the coordinate D32 of the third vertex in the first other direction and the coordinate D12 of the first vertex in the first other direction to obtain the second difference coordinate of the first other direction. The fusion calculation unit uses the product of the first difference coordinate of any direction and the second difference coordinate of the first other direction as the first intermediate value of the first other direction; uses the product of the first difference coordinate of the first other direction and the second difference coordinate of any direction as the second intermediate value of the first other direction; and uses the difference between the first intermediate value and the second intermediate value of the first other direction as the normal component corresponding to the first other direction.

[0149] Based on the three loop processes described above, in the first loop process, the data input includes (D12, D13, D22, D23, D32, D33); in the second loop process, the data input includes (D11, D13, D21, D23, D31, D33); and in the third loop process, the data input includes (D11, D12, D21, D22, D31, D32). It can be seen that three parameters are the same in two adjacent loop processes. For example, the two adjacent loop processes for either direction and the first other direction have the same input parameters (D13, D23, D33); the two adjacent loop processes for the first other direction and the second other direction have the same input parameters (D11, D21, D31); and the two adjacent loop processes for either direction and the second other direction have the same input parameters (D12, D22, D32).

[0150] In the embodiment of the present application, since a set of algorithm units (including two first subtraction units, two second subtraction units, and a fusion calculation unit) can be shared in the process of calculating the normal components in three directions, the normal generation unit can be implemented at a low hardware cost, and the three normal components can be obtained in sequence based on the normal generation unit.

[0151] Therefore, in some embodiments, the surface normal generation method also includes: in response to obtaining the normal component corresponding to the current direction and needing to calculate the normal component corresponding to the next direction, obtaining the coordinates of the first vertex, the second vertex and the third vertex corresponding to the current direction; the input data of the first subtraction unit and the second subtraction unit corresponding to other directions remain unchanged; the other directions are directions among the three directions that are not the current direction and the next direction.

[0152] When the current direction is the first direction and the next direction is the second direction (two cycles of adjacent first and second directions), the other direction is the third direction. When determining the normal component corresponding to the second direction, since the coordinates of the first, second, and third vertices corresponding to the third direction (D13, D23, D33) have already been obtained when determining the normal component corresponding to the first direction, the input data of the first and second subtraction units corresponding to the third direction remain unchanged. Only the coordinates of the first, second, and third vertices corresponding to the first direction need to be updated / acquired.

[0153] When the current direction is the second direction and the next direction is the third direction (two cycles of the adjacent first and second directions), the remaining directions are the first directions. When determining the normal component corresponding to the third direction, since the coordinates of the first, second, and third vertices corresponding to the first direction (D11, D21, D31) have already been obtained when determining the normal component corresponding to the second direction, the input data of the first and second subtraction units corresponding to the first direction remain unchanged. Only the coordinates of the first, second, and third vertices corresponding to the second direction need to be updated / acquired.

[0154] Of course, the order of the first to third directions described above is merely an example of a sequential calculation order for the three directions. Other orders can also be used in this application, as long as the calculation process for the normal components of the three directions is completed through three cycles. It will be understood that regardless of the order used, there are three common input parameters between two adjacent directions. That is, only three output parameters need to be updated to complete the calculation of the normal components of a direction.

[0155] In an embodiment of the present application, since a set of algorithm units (including two first subtraction units, two second subtraction units and a fusion calculation unit) can be shared in the process of calculating the normal components in three directions, and at the same time, considering that there are the same three input parameters in the calculation process of two adjacent normal components, the three input parameters are kept unchanged and only the three changed input parameters are updated to complete the calculation of the normal component in the next direction. In this way, not only can the above-mentioned normal generation unit be implemented based on a low hardware cost, but also the system transmission bandwidth and computing power can be saved.

[0156] The following describes the application of the surface normal generation method provided in the embodiment of the present application in actual scenarios.

[0157] See also Figure 9 A schematic diagram of a BVH tree is shown. BVH traversal is a depth-first tree traversal performed by testing whether a ray intersects with the bounding volume within box node 91, i.e., a ray / bounding volume intersection test. When a ray reaches triangle node 92, it performs an intersection test with the triangle within that triangle node, i.e., a ray / triangle intersection test. Ray tracing hardware accelerators have recently become popular, particularly on graphics processing units (GPUs). Related art provides two implementation methods for ray tracing accelerators.

[0158] See also Figure 10A , which illustrates a first implementation method for a ray tracing accelerator. The system's computing core 1010 simulates a BVH traversal using a software program. The computing core 1010 issues intersection instructions to invoke a ray / bounding volume intersection test or a ray / triangle intersection test in the ray tracing accelerator 1020.

[0159] See also Figure 10B , which illustrates a second ray tracing accelerator implementation method. The ray tracing accelerator 1120 includes a fixed function for BVH traversal. The system's computing core 1110 directly issues BVH traversal instructions to the ray tracing accelerator 1120. During this process, the fixed function for BVH traversal invokes either a ray / bounding volume intersection test or a ray / triangle intersection test.

[0160] Based on any of the ray tracing accelerator implementation methods provided in the above embodiments, the program on the computing core will obtain one or more intersecting triangles that meet user-defined rules (for example, finding the nearest hit triangle, or finding any hit triangle on the ray's path). Typically, the ray tracing accelerator will return an identifier of the intersecting triangle (such as a triangle ID) and the position of the hit point on the triangle. In some implementation scenarios, the program on the computing core can use the triangle identifier to obtain the positions of the three vertices to generate the normal vector of the triangle, thereby further rendering the visual effect. For example, Ray-Traced Ambient Occlusion (RTAO) requires the normal vector of the hitting (intersecting) triangle to calculate the emission direction of its secondary light.

[0161] Exemplarily, the pseudo code of the function for generating the normal of a triangle surface includes:

[0162] / / The ray tracing accelerator gets the return parameter of the current ray: the triangle identifier (triangleId)

[0163] triangleId = get_ray_tracing_accelerator_return(bvh, ray);

[0164] / / Get the index of the vertex based on triangleId to facilitate the subsequent acquisition of the triangle vertex

[0165] uint triIndex0 = indexBuffer[triangleId + 0];

[0166] uint triIndex1 = indexBuffer[triangleId + 1];

[0167] uint triIndex2 = indexBuffer[triangleId + 2];

[0168] / / Extract vertices from the vertex buffer

[0169] float3 vertPos0 = vertexBuffer[triIndex0];

[0170] float3 vertPos1 = vertexBuffer[triIndex1];

[0171] float3 vertPos2 = vertexBuffer[triIndex2];

[0172] / / Calculate the surface normal (a three-component vector)

[0173] float surfaceNormal = cross_product(vertPos1 - vertPos0, vertPos2 -vertPos0);

[0174] / / Surface normal normalization

[0175] surfaceNormal = normalized(surfaceNormal)

[0176] In related technologies, the three vertices of the hitting triangle need to be obtained from the memory, and since each ray may intersect with multiple triangles, it will cause a large amount of memory access, thereby affecting the overall efficiency of the ray tracing system.

[0177] To avoid this frequent triangle data retrieval, the present embodiment enhances the ray tracing accelerator, allowing it to directly provide the surface normals of intersecting triangles, thereby reducing memory traffic and improving the overall efficiency of the ray tracing system. This method, further described below, allows the ray tracing accelerator to calculate triangle surface normals and return them to the main program running on the computing core, thereby reducing the program's memory traffic and improving the efficiency of the entire ray tracing system.

[0178] The triangle surface normal is a three-component vector (nx, ny, nz), representing a direction in 3D space. Each component is a 32-bit floating-point number. The following describes how the triangle surface normal is generated.

[0179] See also Figure 11 , which shows a schematic diagram of a triangular surface normal. The triangular surface consists of vertices V0, V1, and V2, wherein vertex V0 to vertex V2 forms vector E1, and vertex V0 to vertex V1 forms vector E0. The normal of the triangular surface can be determined by the following method:

[0180] / / The ray tracing accelerator obtains the positions of the three vertices of the triangle surface

[0181] float3 v0 = GetVertex0FromBvhNode(triangleId);

[0182] float3 v1 = GetVertex1FromBvhNode(triangleId);

[0183] float3 v2 = GetVertex2FromBvhNode(triangleId);

[0184] / / Generate vector E0

[0185] Line3: float e0_x = v1.x – v0.x;

[0186] Line4: float e0_y = v1.y – v0.y;

[0187] Line5: float e0_z = v1.z – v0.z;

[0188] / / Generate vector E1

[0189] Line6: float e1_x = v2.x – v0.x;

[0190] Line7: float e1_y = v2.y – v0.y;

[0191] Line8: float e1_z = v2.z – v0.z;

[0192] / / Calculate the triangle surface normal by the cross product of vector E0 and vector E1

[0193] Line9: normal.x = e0.y * e1.z - e0.z * e1.y

[0194] Line10: normal.y = e0.z * e1.x - e0.x * e1.z

[0195] Line11: normal.z = e0.x * e1.y - e0.y * e1.x

[0196] The above process of determining the normal of a triangle surface can be implemented in the fixed function unit of the ray tracing accelerator. It is worth noting that due to the high hardware cost, the calculated surface normals are not normalized. Normalization is performed in the shading instructions in the main program of the computing core.

[0197] In some embodiments, the present application provides an enhanced ray / triangle intersection test process. This test process adds a triangle surface normal generation process on the basis of the ray / triangle intersection test, that is, the triangle surface normal generation process is combined with the ray / triangle intersection test. The reason for this implementation of the present application is that when performing the ray / triangle intersection test, it is necessary to obtain the positions of the three vertices from the BVH node. In order to reuse this data, the process can be enhanced to perform not only the intersection point calculation in the intersection test, but also the surface normal calculation.

[0198] In one implementation, after obtaining each triangle's vertex, its surface normal is calculated. If the ray hits the triangle, the calculated surface normal is submitted; otherwise, the result is discarded. In another implementation, the surface normal calculation can be delayed until after the intersection hit / miss result is obtained. Furthermore, the surface normal generation process can be enabled / disabled via an instruction control bit.

[0199] In some embodiments, the present application provides an enhanced ray tracing instruction. To support the enhanced ray / triangle intersection test process described above, the return parameter of this enhanced ray tracing instruction includes three additional 32-bit double-byte (DWORD) data parameters, namely, triangle surface normals, compared to the return parameters of ray tracing instructions in conventional techniques. Furthermore, the enhanced ray tracing instruction adds an instruction control bit to enable / disable the surface normal generation process described above.

[0200] For example, after obtaining the triangle surface normal, the main program on the computing core may use the surface normal using the following pseudo code:

[0201] / / Get the return value from the traversal function supported by the ray tracing accelerator, that is, traverse the BVH to find the hit triangle

[0202] (triangleId, hit_point, normal) = traverse_bvh_to_find_intersected_triangle(bvh, ray)

[0203] / / If a hit triangle is found, the surface normal is normalized and further processing is performed

[0204] if (triangleId != INVALID) { normal = normalize(normal);

[0205] use the normal to do further processing;}

[0206] In some embodiments, see Figure 12 , which shows a schematic diagram of the calculation of the normal of a triangle surface Figure 1 The surface normal calculation unit set in the ray tracing accelerator may include subtraction units 1211 to 1216, and fusion calculation units 1221 to 1223. The above 6 subtraction units and 3 fusion calculation units can calculate the three normal components (normal.x, normal.y, normal.z) of the triangle surface normal N in parallel.

[0207] Exemplarily, the input of the surface normal calculation unit is the coordinates of the three vertices of the triangle, such as Figure 12 V0, V1 and V2 in. Among them, the subtraction unit 1211 is used to calculate E0_x=V1.x-V0.x; the subtraction unit 1212 is used to calculate E0_y=V1.y-V0.y; the subtraction unit 1213 is used to calculate E0_z=V1.z-V0.z; the subtraction unit 1214 is used to calculate E1_x=V2.x-V0.x; the subtraction unit 1215 is used to calculate E1_y=V2.y-V0.y; and the subtraction unit 1216 is used to calculate E1_z=V2.z-V0.z.

[0208] The above fusion calculation unit is used to perform fusion calculation on the input data, and the calculation formula is c=a1×b1-a2×b2. Among them, a1, b1, a2, b2 are the input data of the fusion calculation unit, and c is the output data of the fusion calculation unit. Figure 12 The fusion calculation unit 1221 is used to calculate normal_x=E0_y×E1_z-E0_z×E1_y; the fusion calculation unit 1222 is used to calculate normal_y=E0_z×E1_x-E0_x×E1_z; and the fusion calculation unit 1223 is used to calculate normal_z=E0_x×E1_y-E0_y×E1_x.

[0209] In the above embodiment, since the three normal components of the triangle surface normal N can be calculated in parallel, there is a shorter calculation delay, which improves the response speed of the system.

[0210] In some embodiments, see Figure 13 , which shows a schematic diagram of the calculation of the normal of a triangle surface Figure 2The surface normal calculation unit provided in the ray tracing accelerator may include subtraction units 1311 to 1314, a fusion calculation unit 1320, a loop unit 1330, and a data pool 1340. The surface normal calculation unit may loop through each normal component of the triangle surface normal until the three normal components (normal.x, normal.y, normal.z) of the triangle surface normal N are obtained. It is understood that the loop unit 1330 may be a hardware unit or a logic program.

[0211] The fusion calculation unit is used to perform fusion calculation on the input data, and the calculation formula is c=a1×b1-a2×b2. Among them, a1, b1, a2, and b2 are the input data of the fusion calculation unit, and c is the output data of the fusion calculation unit.

[0212] Exemplarily, the three normal components of the triangle surface normal N can be obtained through three cycles. In the first cycle, the input is (V1.y, V1.z, V0.y, V0.z, V2.y, V2.z), and the output is normal.x; in the second cycle, the input is (V1.x, V1.z, V0.x, V0.z, V2.x, V2.z), and the output is normal.y; in the third cycle, the input is (V1.x, V1.y, V0.x, V0.y, V2.x, V2.y), and the output is normal.z. Of course, normal.z can also be output in the first cycle, normal.x can be output in the second cycle, and normal.y can be output in the third cycle, which is not limited in this embodiment of the present application.

[0213] In the above embodiment, since each normal component of the triangle surface normal is calculated cyclically, the cyclic process shares the same subtraction unit and fusion calculation unit, thus reducing hardware costs.

[0214] In some embodiments, Figure 13 Based on the embodiment, consider the case where the input data in two adjacent loops are the same, such as the same input data (V1.z, V0.z, V2.z) exists in the process of calculating normal.x and normal.y, or the same input data (V1.x, V0.x, V2.x) exists in the process of calculating normal.z and normal.y, or the same input data (V1.y, V0.y, V2.y) exists in the process of calculating normal.z and normal.x.

[0215] Based on this, the present application also provides an implementation method, in the above Figure 13Based on the embodiment, between two adjacent loop processes, the same input data is kept unchanged, and only the different input data is updated.

[0216] For example, when the output of the first loop process is normal.x, the output of the second loop process is normal.y, and the output of the third loop process is normal.z, between the first loop process and the second loop process, the input parameters (V1.z, V0.z, V2.z) can be kept unchanged, and only (V1.x, V0.x, V2.x) can be updated; between the second loop process and the third loop process, the input parameters (V1.x, V0.x, V2.x) can be kept unchanged, and only (V1.y, V0.y, V2.y) can be updated.

[0217] In the above embodiment, since the same input data is kept unchanged during adjacent cycles, bandwidth and energy loss of data transmission can be saved.

[0218] See also Figure 14 , Figure 14 This is a schematic diagram of the implementation process of a surface normal generation method provided in an embodiment of the present application. Figure 9 , when the ray / triangle intersection calculation front end receives a test request, steps S1401 and S1402 are executed.

[0219] Step S1401: Acquire light data;

[0220] Step S1402: Obtain triangle vertices;

[0221] Step S1403: determine whether it is necessary to calculate the triangle surface normal;

[0222] If the triangle surface normal needs to be calculated, step S1405 is executed; if the triangle surface normal does not need to be calculated, step S1406 is executed.

[0223] Here, whether the triangle surface normal needs to be calculated can be achieved by enabling / disabling the above-mentioned surface normal generation process through the instruction control bit.

[0224] Step S1404: ray / triangle intersection test;

[0225] Step S1405: Generate triangle surface normals;

[0226] Step S1406: Determine whether the ray / triangle hits the target.

[0227] If the ray hits the triangle, step S1407 is executed; if the ray does not hit the triangle, step S1408 is executed.

[0228] Step S1407: Submit the hit result and the triangle surface normal (if any);

[0229] Step S1408: discard the triangle surface normal (if any);

[0230] Step S1409: Determine whether there are any triangles in the Bvh node;

[0231] Among them, when there are still triangles in the Bvh node, return to the ray / triangle intersection calculation front end to execute steps S1401 and S1402; when there are no triangles in the Bvh node, execute step S1410.

[0232] Step S1410: Return data.

[0233] In the above process, the triangle vertex data obtained in step S1402 can be reused in the generation of triangle surface normals. At the same time, whether the triangle surface normals need to be generated is determined by the instruction control bit. It should be noted that if the BVH node contains multiple triangles, the system can process multiple triangles in a loop. When at least two triangles are hit at the same time, the surface normal of the last selected triangle will be retained and returned to the main program based on the user-defined selection conditions. For example, for a collision hit condition, only the surface normal of the most recently hit triangle will be retained and returned.

[0234] See also Figure 15 , Figure 15 This is a flowchart diagram of an implementation of a surface normal generation method provided in an embodiment of the present application. When the ray / triangle intersection calculation front end receives a test request, steps S1501 and S1502 are executed.

[0235] Step S1501: Acquire light data;

[0236] Step S1502: Obtain triangle vertices;

[0237] Step S1503, ray / triangle intersection test;

[0238] Step S1504: determine whether the ray / triangle hits;

[0239] If the ray hits the triangle, step S1505 is executed; if the ray does not hit the triangle, step S1508 is executed.

[0240] Step S1505: determine whether it is necessary to calculate the triangle surface normal;

[0241] If the triangle surface normal needs to be calculated, step S1506 is executed; if the triangle surface normal does not need to be calculated, step S1507 is executed.

[0242] Step S1506: Generate triangle surface normals;

[0243] Step S1507: Submit the hit result and the triangle surface normal (if any);

[0244] Step S1508: discard the triangle surface normal;

[0245] Step S1509: Determine whether there are any triangles in the Bvh node;

[0246] Among them, when there are still triangles in the Bvh node, return to the ray / triangle intersection calculation front end to execute steps S1501 and S1502; when there are no triangles in the Bvh node, execute step S1510.

[0247] Step S1510: Return data.

[0248] In the above process, compared with Figure 14 Example, Figure 15 In an embodiment, whether to bypass step S1506 and step S1507, that is, bypass the process of generating the triangle surface normal, may be determined based on whether the ray / triangle is hit.

[0249] Based on the foregoing embodiments, an embodiment of the present application provides a ray tracing accelerator, which includes the various units included and the various modules included in each unit, and can be implemented by a processor in a computer device; of course, it can also be implemented by a specific logic circuit; in the implementation process, the processor can be a central processing unit (CPU), a microprocessor (MPU), a digital signal processor (DSP), or a field programmable gate array (FPGA), etc.

[0250] Figure 16 A schematic diagram of the structure of a ray tracing accelerator provided in an embodiment of the present application is shown in FIG. Figure 16 As shown, the ray tracing accelerator 1600 includes: an acquisition unit 1610 and a normal generation unit 1620, wherein:

[0251] An acquisition unit 1610 is configured to acquire vertex data of a triangle in a target node in a bounding volume hierarchy tree during an intersection test between a ray and the target node;

[0252] The normal generation unit 1620 is configured to generate a surface normal of the triangle based on the vertex data of the triangle.

[0253] In some embodiments, the ray tracing accelerator further includes an intersection testing unit, wherein;

[0254] The acquisition unit 1610 is further configured to acquire the ray data of the ray during the process of performing the intersection test between the ray and the target node in the bounding volume hierarchy tree;

[0255] The intersection test unit is used to generate an intersection test result corresponding to the triangle based on the light data and the vertex data of the triangle.

[0256] In some embodiments, the normal generation unit 1620 is further configured to generate a surface normal of the triangle based on vertex data of the triangle in response to the intersection test result indicating that the triangle intersects the light.

[0257] In some embodiments, the normal generation unit 1620 is further used to determine that the surface normal of the triangle needs to be generated when at least one of the following conditions is met: the intersection test result indicates that the triangle intersects with the light; the instruction control bit indicates that the surface normal of the triangle needs to be generated.

[0258] In some embodiments, the normal generation unit 1620 is further configured to generate a surface normal of the triangle based on the vertex data of the triangle in response to obtaining the vertex data of the triangle;

[0259] The intersection test unit is further configured to retain the surface normal of the triangle when the intersection test result indicates that the triangle intersects the light; and discard the surface normal of the triangle when the intersection test result indicates that the triangle does not intersect the light.

[0260] In some embodiments, the ray tracing accelerator further includes a feedback unit, wherein:

[0261] The feedback unit is used to send feedback data to the computing core; the feedback data is determined based on the intersection test result of the triangle in the target node.

[0262] In some embodiments, the feedback unit is further used to generate the feedback data based on the intersection test results of all triangles in the target node when the intersection test results of all triangles in the target node are obtained; wherein the feedback data is used to characterize whether there are triangles in the target node that intersect with the light ray, and when the feedback data characterizes that there are triangles in the target node that intersect with the light ray, the feedback data also includes the surface normals of the triangles that intersect with the light ray, and the surface normals of the triangles that intersect with the light ray are generated based on the vertex data of the triangles during the intersection test; and the feedback data is sent to the computing core.

[0263] In some embodiments, the feedback unit is further used to determine the target triangle among the at least two triangles intersecting the light ray based on a preset selection strategy when there are at least two triangles intersecting the light ray at the target node; and generate feedback data including the surface normal of the target triangle.

[0264] In some embodiments, the acquisition unit 1610 is also used to obtain the vertex data of the next triangle in the target node that has not undergone intersection testing, and obtain the surface normal of the next triangle and the intersection test result corresponding to the next triangle, until the intersection test results of all triangles in the target node are obtained, and send feedback data to the computing core.

[0265] In some embodiments, the ray tracing accelerator further includes a receiving unit, wherein:

[0266] The receiving unit is used to receive an intersection test request sent by the computing core; the intersection test request is used to instruct the ray tracing accelerator to perform an intersection test between the ray and the target node in the bounding volume hierarchy tree and whether it is necessary to generate a surface normal of a triangle.

[0267] In some embodiments, the vertex data includes coordinates corresponding to three directions, and the normal generation unit 1620 includes a first subtraction unit and a second subtraction unit corresponding to each direction, and a fusion calculation unit corresponding to each direction; wherein,

[0268] The first subtraction unit is configured to perform a subtraction operation on the coordinates corresponding to the second vertex and the first vertex of the triangle in the direction to obtain a first difference coordinate;

[0269] The second subtraction unit is configured to perform a subtraction operation on the coordinates corresponding to the third vertex and the first vertex of the triangle in the direction to obtain a second difference coordinate;

[0270] The fusion calculation unit corresponding to any one of the three directions is used to perform fusion calculation on the first difference coordinates and the second difference coordinates of the first other direction among the three directions, and the first difference coordinates and the second difference coordinates of the second other direction among the three directions to obtain the normal component corresponding to any one direction.

[0271] In some embodiments, the vertex data includes coordinates corresponding to three directions, and the normal generation unit 1620 includes two first subtraction units, two second subtraction units, and a fusion calculation unit; wherein the first subtraction unit, the second subtraction unit, and the fusion calculation unit are used to sequentially calculate the normal components of the three directions; in the process of calculating the normal component of any direction in the three directions,

[0272] a first subtraction unit, configured to perform a subtraction operation on the coordinates of the second vertex of the triangle in the first other direction and the coordinates of the first vertex in the first other direction to obtain a first difference coordinate in the first other direction;

[0273] another first subtraction unit, configured to perform a subtraction operation on the coordinates of the second vertex of the triangle in the second other direction and the coordinates of the first vertex in the second other direction to obtain a first difference coordinate in the first other direction;

[0274] a second subtraction unit, configured to perform a subtraction operation on the coordinates of the third vertex of the triangle in the first other direction and the coordinates of the first vertex in the first other direction to obtain a second difference coordinate in the first other direction;

[0275] another second subtraction unit, configured to perform a subtraction operation on the coordinates of the third vertex of the triangle in the second other direction and the coordinates of the first vertex in the second other direction to obtain a second difference coordinate in the second other direction;

[0276] The fusion calculation unit is used to perform fusion calculation on the first difference coordinate of the first other direction, the first difference coordinate of the second other direction, the second difference coordinate of the first other direction, and the second difference coordinate of the second other direction to obtain the normal component corresponding to any direction.

[0277] In some embodiments, the acquisition unit is also used to obtain the coordinates of the first vertex, the second vertex and the third vertex corresponding to the current direction in response to obtaining the normal component corresponding to the current direction and needing to calculate the normal component corresponding to the next direction; the input data of the first subtraction unit and the second subtraction unit corresponding to other directions remain unchanged; the other directions are directions among the three directions that are not the current direction and the next direction.

[0278] In some embodiments, the ray tracing accelerator is connected to a computing core; the surface normal generated by the ray tracing accelerator is a surface normal before normalization; and the computing core is used to normalize the surface normal generated by the ray tracing accelerator.

[0279] The description of the above device embodiment is similar to the description of the above method embodiment and has similar beneficial effects as the method embodiment. In some embodiments, the functions or modules included in the device provided in the embodiments of the present application can be used to perform the methods described in the above method embodiments. For technical details not disclosed in the device embodiments of the present application, please refer to the description of the method embodiments of the present application for understanding.

[0280] It should be noted that, in the embodiments of the present application, if the above-mentioned surface normal generation method is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiments of the present application, or the part that contributes to the relevant technology, can be embodied in the form of a software product. The software product is stored in a storage medium and includes a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the surface normal generation method described in each embodiment of the present application. The aforementioned storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a magnetic disk or an optical disk. In this way, the embodiments of the present application are not limited to any specific hardware, software or firmware, or any combination of hardware, software and firmware.

[0281] An embodiment of the present application provides a computer device, including a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the program, some or all of the steps in the above method are implemented.

[0282] The embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements some or all of the steps in the above method. The computer-readable storage medium may be transient or non-transient.

[0283] An embodiment of the present application provides a computer program, including computer-readable code. When the computer-readable code is run in a computer device, a processor in the computer device executes some or all of the steps for implementing the above method.

[0284] An embodiment of the present application provides a computer program product, comprising a non-transitory computer-readable storage medium storing a computer program. When the computer program is read and executed by a computer, the computer program implements some or all of the steps of the above-described method. The computer program product can be implemented in hardware, software, or a combination thereof. In some embodiments, the computer program product is embodied as a computer storage medium. In other embodiments, the computer program product is embodied as a software product, such as a software development kit (SDK).

[0285] It should be noted that the descriptions of the various embodiments above tend to emphasize the differences between the various embodiments, and their similarities or similarities can be referenced to each other. The descriptions of the above device, storage medium, computer program, and computer program product embodiments are similar to the descriptions of the above method embodiments and have similar beneficial effects as the method embodiments. For technical details not disclosed in the embodiments of the device, storage medium, computer program, and computer program product of this application, please refer to the description of the method embodiments of this application for understanding.

[0286] Figure 17 A hardware entity diagram of a computer device provided in an embodiment of the present application is shown as follows: Figure 17 As shown, the hardware entity of the computer device 1700 includes: a processor 1701 and a memory 1702, wherein the memory 1702 stores a computer program that can be run on the processor 1701, and the processor 1701 implements the steps in the method of any of the above embodiments when executing the program.

[0287] The memory 1702 stores computer programs that can be run on the processor. The memory 1702 is configured to store instructions and applications executable by the processor 1701. It can also cache data to be processed or processed by the processor 1701 and various modules in the computer device 1700 (for example, image data, audio data, voice communication data, and video communication data). This can be implemented through flash memory (FLASH) or random access memory (RAM).

[0288] When the processor 1701 executes the program, the steps of any of the above surface normal generation methods are implemented. The processor 1701 generally controls the overall operation of the computer device 1700.

[0289] An embodiment of the present application provides a computer storage medium, which stores one or more programs. The one or more programs can be executed by one or more processors to implement the steps of the surface normal generation method of any of the above embodiments.

[0290] It should be noted that the description of the above storage medium and device embodiments is similar to the description of the above method embodiments and has similar beneficial effects as the method embodiments. For technical details not disclosed in the storage medium and device embodiments of this application, please refer to the description of the method embodiments of this application for understanding.

[0291] The processor may be at least one of an application-specific integrated circuit (ASIC), a digital signal processor (DSP), a digital signal processing device (DSPD), a programmable logic device (PLD), a field programmable gate array (FPGA), a central processing unit (CPU), a controller, a microcontroller, and a microprocessor. It is understood that the electronic device that implements the functions of the processor may also be other electronic devices, which are not specifically limited in the embodiments of the present application.

[0292] The above-mentioned computer storage medium / memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic random access memory (FRAM), a flash memory (Flash Memory), a magnetic surface storage device, an optical disc, or a compact disc read-only memory (CD-ROM); it can also be various terminals that include one or any combination of the above-mentioned memories, such as mobile phones, computers, tablet devices, personal digital assistants, etc.

[0293] It should be understood that "one embodiment" or "an embodiment" mentioned throughout the specification means that the specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in the various embodiments of the present application, the size of the serial numbers of the above-mentioned steps / processes does not mean the order of execution, and the execution order of each step / process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. The above-mentioned serial numbers of the embodiments of the present application are for description only and do not represent the advantages and disadvantages of the embodiments.

[0294] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or apparatus comprising the element.

[0295] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.

[0296] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed across multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the scheme of this embodiment.

[0297] In addition, the functional units in the various embodiments of the present application can all be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the above-mentioned integrated units can be implemented in the form of hardware or in the form of hardware plus software functional units. It can be understood by those skilled in the art that all or part of the steps of the above-mentioned method embodiments can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above-mentioned method embodiments; and the aforementioned storage medium includes various media that can store program code, such as mobile storage devices, read-only memories (ROMs), magnetic disks, or optical disks.

[0298] Alternatively, if the above-mentioned integrated unit of the present application is implemented in the form of a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the relevant technology, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the surface normal generation method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks or optical disks.

[0299] The above is only an implementation method of the present application, but the scope of protection of the present application is not limited thereto. Any technician familiar with this technical field can easily think of changes or replacements within the technical scope disclosed in this application, which should be covered by the scope of protection of the present application.

Claims

1. A surface normal generation method, characterized in that: Applied to a ray tracing accelerator, the surface normal generation method includes: In the process of performing an intersection test between a ray and a target node in a bounding volume hierarchy tree, obtaining vertex data of a triangle in the target node; the intersection test is used to obtain an intersection test result; When it is determined that a surface normal of a triangle needs to be generated, the surface normal of the triangle is generated based on vertex data of the triangle.

2. The surface normal generation method according to claim 1, characterized in that: The surface normal generation method further comprises: In the process of performing an intersection test between a ray and a target node in a bounding volume hierarchy tree, obtaining ray data of the ray; Based on the light data and the vertex data of the triangle, an intersection test result corresponding to the triangle is generated.

3. The surface normal generation method according to claim 2, characterized in that: When at least one of the following conditions is met, it is determined that the surface normal of the triangle needs to be generated: The intersection test result indicates that the triangle intersects the light; The instruction control bits indicate that surface normals for the triangles need to be generated.

4. The surface normal generation method according to claim 1, characterized in that: Generating a surface normal of the triangle based on vertex data of the triangle includes: In response to acquiring vertex data of the triangle, generating a surface normal of the triangle based on the vertex data of the triangle; The surface normal generation method further comprises: If the intersection test result indicates that the triangle intersects the ray, retaining the surface normal of the triangle; In the event that the intersection test result indicates that the triangle does not intersect the ray, the surface normal of the triangle is discarded.

5. The surface normal generation method according to claim 2, characterized in that: The surface normal generation method further includes: Feedback data is sent to a computing core; the feedback data is determined based on an intersection test result of a triangle in the target node.

6. The surface normal generation method according to claim 5, characterized in that: The sending of feedback data to the computing core includes: When the intersection test results of all triangles in the target node are obtained, generating the feedback data based on the intersection test results of all triangles in the target node; The feedback data is used to indicate whether there is a triangle at the target node that intersects the ray, and if the feedback data indicates that there is a triangle at the target node that intersects the ray, the feedback data further includes a surface normal of the triangle that intersects the ray, where the surface normal of the triangle that intersects the ray is generated based on the vertex data of the triangle during the intersection test. The feedback data is sent to the computing core.

7. The surface normal generation method according to claim 6, characterized in that: The generating the feedback data based on the intersection test results of all triangles in the target node includes: In the case that there are at least two triangles at the target node that intersect with the light, based on a preset selection strategy, a target triangle is determined among the at least two triangles that intersect with the light; and feedback data including a surface normal of the target triangle is generated.

8. The surface normal generation method according to claim 2, characterized in that: The surface normal generation method further includes: If the intersection test results of all triangles in the target node are not obtained, the vertex data of the next triangle in the target node that has not been intersection tested is obtained, and the surface normal of the next triangle and the intersection test result corresponding to the next triangle are obtained, until the intersection test results of all triangles in the target node are obtained, and feedback data is sent to the computing core.

9. The surface normal generation method according to claim 2, characterized in that: The surface normal generation method further includes: Receive an intersection test request sent by the computing core; the intersection test request is used to instruct the ray tracing accelerator to perform an intersection test between the ray and the target node in the bounding volume hierarchy tree and whether it is necessary to generate a surface normal of a triangle.

10. The surface normal generation method according to any one of claims 1 to 9, characterized in that: The vertex data includes coordinates corresponding to three directions; the ray tracing accelerator includes a normal generation unit, the normal generation unit includes a first subtraction unit and a second subtraction unit corresponding to each direction, and a fusion calculation unit corresponding to each direction; Generating a surface normal of the triangle based on vertex data of the triangle includes: performing a subtraction operation on the coordinates corresponding to the second vertex and the first vertex of the triangle in the direction by the first subtraction unit to obtain a first difference coordinate; performing a subtraction operation on the coordinates corresponding to the third vertex and the first vertex of the triangle in the direction by the second subtraction unit to obtain a second difference coordinate; The first difference coordinate and the second difference coordinate of the first other direction among the three directions, as well as the first difference coordinate and the second difference coordinate of the second other direction among the three directions are fused and calculated by the fusion calculation unit corresponding to any one of the three directions to obtain the normal component corresponding to any one direction.

11. The surface normal generation method according to any one of claims 1 to 9, characterized in that: The vertex data includes coordinates corresponding to three directions; the ray tracing accelerator includes a normal generation unit, and the normal generation unit includes two first subtraction units, two second subtraction units, and a fusion calculation unit; the surface normal of the triangle is generated based on the vertex data of the triangle, including: Calculating normal components in three directions in sequence through the first subtraction unit, the second subtraction unit, and the fusion calculation unit; The process of calculating the normal component in any of the three directions includes: performing a subtraction operation on the coordinates of the second vertex of the triangle in the first other direction and the coordinates of the first vertex in the first other direction by a first subtraction unit to obtain a first difference coordinate in the first other direction; performing a subtraction operation on the coordinates of the second vertex of the triangle in the second other direction and the coordinates of the first vertex in the second other direction by another of the first subtraction units to obtain first difference coordinates in the first other direction; performing a subtraction operation on the coordinates of the third vertex of the triangle in the first other direction and the coordinates of the first vertex in the first other direction by a second subtraction unit to obtain a second difference coordinate in the first other direction; performing a subtraction operation on the coordinates of the third vertex of the triangle in the second other direction and the coordinates of the first vertex in the second other direction by another second subtraction unit to obtain a second difference coordinate in the second other direction; The fusion calculation unit performs fusion calculation on the first difference coordinate of the first other direction, the first difference coordinate of the second other direction, the second difference coordinate of the first other direction, and the second difference coordinate of the second other direction to obtain the normal component corresponding to any direction.

12. The surface normal generation method according to claim 11, characterized in that: The surface normal generation method further comprises: In response to obtaining the normal component corresponding to the current direction and needing to calculate the normal component corresponding to the next direction, the coordinates of the first vertex, the second vertex and the third vertex corresponding to the current direction are obtained; the input data of the first subtraction unit and the second subtraction unit corresponding to other directions remain unchanged; the other directions are directions among the three directions that are not the current direction and the next direction.

13. The surface normal generation method according to any one of claims 1 to 9, characterized in that: The ray tracing accelerator is connected to the computing core; the surface normal generated by the ray tracing accelerator is the surface normal before normalization; the computing core is used to normalize the surface normal generated by the ray tracing accelerator.

14. A ray tracing accelerator, characterized in that: The ray tracing accelerator includes: An acquisition unit, configured to acquire vertex data of a triangle in a target node in a bounding volume hierarchy tree during an intersection test between a ray and the target node; the intersection test is configured to obtain an intersection test result; The normal generation unit is used to generate the surface normal of the triangle based on the vertex data of the triangle when it is determined that the surface normal of the triangle needs to be generated.

15. The ray tracing accelerator according to claim 14, wherein: The ray tracing accelerator further includes an intersection testing unit, wherein; The acquisition unit is further configured to acquire the light data of the light during the process of performing the intersection test between the light and the target node in the bounding volume hierarchy tree; The intersection test unit is used to generate an intersection test result corresponding to the triangle based on the light data and the vertex data of the triangle.

16. The ray tracing accelerator according to claim 15, wherein: The normal generation unit is further configured to determine the surface normal of the triangle to be generated when at least one of the following conditions is met: The intersection test result indicates that the triangle intersects the light; The instruction control bits indicate that surface normals for the triangles need to be generated.

17. The ray tracing accelerator according to claim 14, wherein: The ray tracing accelerator further includes an intersection test unit, The normal generation unit is further configured to generate a surface normal of the triangle based on the vertex data of the triangle in response to acquiring the vertex data of the triangle; The intersection test unit is further configured to retain the surface normal of the triangle when the intersection test result indicates that the triangle intersects the light; and discard the surface normal of the triangle when the intersection test result indicates that the triangle does not intersect the light.

18. The ray tracing accelerator according to claim 15, wherein: The ray tracing accelerator further includes a feedback unit, wherein: The feedback unit is used to send feedback data to the computing core; the feedback data is determined based on the intersection test result of the triangle in the target node.

19. The ray tracing accelerator according to claim 18, wherein: The feedback unit is further used to generate the feedback data based on the intersection test results of all triangles in the target node when the intersection test results of all triangles in the target node are obtained; wherein the feedback data is used to characterize whether there is a triangle in the target node that intersects with the light, and when the feedback data characterizes that there is a triangle in the target node that intersects with the light, the feedback data also includes the surface normal of the triangle that intersects with the light, and the surface normal of the triangle that intersects with the light is generated based on the vertex data of the triangle during the intersection test; and the feedback data is sent to the computing core.

20. The ray tracing accelerator according to claim 19, wherein: The feedback unit is further used to determine the target triangle among the at least two triangles intersecting the light ray at the target node based on a preset selection strategy; and generate feedback data including the surface normal of the target triangle.

21. The ray tracing accelerator according to claim 15, wherein: The acquisition unit is also used to obtain the vertex data of the next triangle in the target node that has not been subjected to the intersection test, and obtain the surface normal of the next triangle and the intersection test result corresponding to the next triangle, until the intersection test results of all triangles in the target node are obtained, and send feedback data to the computing core.

22. The ray tracing accelerator according to claim 15, wherein: The ray tracing accelerator further includes a receiving unit, wherein: The receiving unit is used to receive an intersection test request sent by the computing core; the intersection test request is used to instruct the ray tracing accelerator to perform an intersection test between the ray and the target node in the bounding volume hierarchy tree and whether it is necessary to generate a surface normal of a triangle.

23. The ray tracing accelerator according to any one of claims 14 to 22, characterized in that: The vertex data includes coordinates corresponding to three directions, and the normal generation unit includes a first subtraction unit and a second subtraction unit corresponding to each direction, and a fusion calculation unit corresponding to each direction; wherein, The first subtraction unit is configured to perform a subtraction operation on the coordinates corresponding to the second vertex and the first vertex of the triangle in the direction to obtain a first difference coordinate; The second subtraction unit is configured to perform a subtraction operation on the coordinates corresponding to the third vertex and the first vertex of the triangle in the direction to obtain a second difference coordinate; The fusion calculation unit corresponding to any one of the three directions is used to perform fusion calculation on the first difference coordinates and the second difference coordinates of the first other direction among the three directions, and the first difference coordinates and the second difference coordinates of the second other direction among the three directions to obtain the normal component corresponding to any one direction.

24. The ray tracing accelerator according to any one of claims 14 to 22, wherein: The vertex data includes coordinates corresponding to three directions, and the normal generation unit includes two first subtraction units, two second subtraction units, and a fusion calculation unit; wherein the first subtraction unit, the second subtraction unit, and the fusion calculation unit are used to calculate the normal components of the three directions in sequence; in the process of calculating the normal component of any direction in the three directions, a first subtraction unit, configured to perform a subtraction operation on the coordinates of the second vertex of the triangle in the first other direction and the coordinates of the first vertex in the first other direction to obtain a first difference coordinate in the first other direction; another first subtraction unit, configured to perform a subtraction operation on the coordinates of the second vertex of the triangle in the second other direction and the coordinates of the first vertex in the second other direction to obtain a first difference coordinate in the first other direction; a second subtraction unit, configured to perform a subtraction operation on the coordinates of the third vertex of the triangle in the first other direction and the coordinates of the first vertex in the first other direction to obtain a second difference coordinate in the first other direction; another second subtraction unit, configured to perform a subtraction operation on the coordinates of the third vertex of the triangle in the second other direction and the coordinates of the first vertex in the second other direction to obtain a second difference coordinate in the second other direction; The fusion calculation unit is used to perform fusion calculation on the first difference coordinate of the first other direction, the first difference coordinate of the second other direction, the second difference coordinate of the first other direction, and the second difference coordinate of the second other direction to obtain the normal component corresponding to any direction.

25. The ray tracing accelerator according to claim 24, wherein: The acquisition unit is further configured to, in response to obtaining the normal component corresponding to the current direction and needing to calculate the normal component corresponding to the next direction, acquire the coordinates of the first vertex, the second vertex, and the third vertex corresponding to the current direction; the input data of the first subtraction unit and the second subtraction unit corresponding to other directions remain unchanged; The other directions are directions among the three directions that are not the current direction and the next direction.

26. The ray tracing accelerator according to any one of claims 14 to 22, characterized in that: The ray tracing accelerator is connected to the computing core; the surface normal generated by the ray tracing accelerator is the surface normal before normalization; the computing core is used to normalize the surface normal generated by the ray tracing accelerator.

27. A computer device comprising a memory and a processor, wherein the memory stores a computer program executable on the processor, wherein: When the processor executes the program, the steps of the surface normal generation method according to any one of claims 1 to 13 are implemented.

28. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the surface normal generation method according to any one of claims 1 to 13 are implemented.

Citation Information

Patent Citations

  • Method for parallel ray tracing by building BVH tree based on graphics processing unit (GPU)

    CN103021018A

  • Intersection test for ray tracing

    CN114331800A