A real-time game scene shadow rendering method and system based on ray tracing
By constructing multi-faceted light source field functions and caustic candidate sets, optimizing sampling density and ray tracing, the performance bottleneck of shadow rendering in scenarios involving semi-transparent objects and multi-dynamic surface light sources was solved, achieving efficient colored shadows and caustic effects to meet the needs of real-time game rendering.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- XIAMEN PANGQI NETWORK TECHNOLOGY CO LTD
- Filing Date
- 2026-05-22
- Publication Date
- 2026-07-31
AI Technical Summary
Existing technologies incur significant performance overhead in shadow rendering when dealing with the interaction between semi-transparent objects and multiple dynamic surface light sources in game scenes, failing to meet the rendering requirements of real-time games. Furthermore, existing solutions often require compromises to ignore semi-transparent objects or simplify light sources, resulting in shadow distortion.
By constructing multi-faceted light source field functions and caustic candidate sets, we can achieve importance sampling of dynamic surface light sources and efficient ray tracing of semi-transparent objects. We use caustic importance maps to optimize sampling density and complete the calculation of multi-source contributions and transmissivity of semi-transparent materials in a single ray tracing traversal.
It significantly improves the rendering efficiency of multi-source translucent colored shadows and caustics effects, with a performance improvement of up to 5-10 times, meeting the rendering requirements of 60FPS for real-time games.
Smart Images

Figure CN122492913A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer graphics rendering technology, specifically a method and system for rendering shadows in real-time game scenes based on ray tracing. Background Technology
[0002] In the field of real-time game rendering, the application of ray tracing technology has enabled shadow rendering to evolve from the traditional "deceiving the eye" to "physically simulated". In traditional rasterization rendering, shadows mainly rely on shadow mapping technology, which has inherent problems such as resolution limitations, difficulty in simulating soft penumbra, light leaks and artifacts. Real-time ray tracing technology achieves infinite resolution and natural, soft shadow effects by emitting probe rays from pixels to light sources and calculating shadows based on physical occlusion relationships.
[0003] However, game scenes often involve interactions between numerous semi-transparent objects (such as glass, water surfaces, crystals, and particle effects) and multiple dynamic surface light sources (such as neon lights, explosions, magic effects, and car headlight arrays). Existing technologies suffer from the following technical limitations when handling such complex scenes:
[0004] First, rendering shadows for semi-transparent objects is extremely expensive. Ray tracing of semi-transparent objects requires calculating the refraction, transmission, and spectral absorption of light, which cannot be simply determined using the binary occlusion method for opaque objects. Existing solutions for shadow calculation of semi-transparent objects typically require emitting multiple rays for each semi-transparent object to sample its material depth field, resulting in a computational complexity far exceeding that of opaque objects, making it difficult to run at real-time frame rates.
[0005] Secondly, the number of samples increases linearly in scenes with multiple dynamic surface light sources. When there are multiple dynamic surface light sources in a scene, existing ray tracing shadow systems typically adopt a strategy of "independent sampling and accumulation for each light source". For N surface light sources, each pixel needs to emit N sets of rays for occlusion detection, causing the number of samples to increase linearly with the number of light sources. When the number of light sources reaches 5 or more, the performance overhead increases sharply, making it impossible to meet the rendering requirements of 60FPS for real-time games.
[0006] Third, there is a lack of effective solutions for scenarios involving semi-transparent objects coupled with multiple light sources. When the two problems mentioned above occur simultaneously—that is, when multiple dynamic surface light sources illuminate a semi-transparent object—existing technologies face a dual performance bottleneck: they need to handle the complexity of the light path of the semi-transparent material and cope with the linear cumulative overhead of multiple light sources. Currently, commercial game engines typically adopt compromise solutions when handling such scenarios—either ignoring the shadow projection of the semi-transparent object or simplifying multiple surface light sources into point light sources or directional light sources, resulting in shadow distortion, missing color shadows, and the inability to render caustics. Summary of the Invention
[0007] The purpose of this invention is to provide a real-time game scene shadow rendering method and system based on ray tracing, so as to solve the problems mentioned in the background art.
[0008] To achieve the above objectives, the present invention provides the following technical solution: a real-time game scene shadow rendering method and system based on ray tracing, comprising the following steps:
[0009] Step S10: Obtain the dynamic surface light source parameter set in the current game scene. The dynamic surface light source parameter set includes the light source spatial position, light source geometry, light source spectral power distribution function, and light source intensity scalar value of each dynamic surface light source; obtain the semi-transparent object material parameter set in the current game scene. The semi-transparent object material parameter set includes the geometric mesh data, pose transformation matrix, material refractive index, material absorption coefficient, and material thickness field distribution function of each semi-transparent object; obtain the camera parameters of the current rendering frame, and generate a screen space pixel coordinate set based on the camera parameters;
[0010] Step S20: Construct the multi-faceted light source field function based on the dynamic surface light source parameter set. ,in Represents three-dimensional position coordinates in world space. The direction vector represents the field function of the multifaceted light source. Used to characterize at location Along the direction The cumulative radiation contribution of all dynamic surface light sources in this direction during observation;
[0011] Step S30: Construct a caustic candidate set C based on the material parameter set of the semi-transparent object. The caustic candidate set C includes surface points in the semi-transparent object whose material thickness field gradient magnitude and caustic weight factor both exceed a preset thickness change threshold and a preset caustic threshold. Map the caustic candidate set C to screen space to generate a caustic importance map. ;
[0012] Step S40: For each pixel in the screen space pixel coordinate set, generate the corresponding shading point coordinates based on the camera parameters, and query the caustic importance map. Obtain the caustic importance value of the pixel, determine the number of sampled rays for the pixel based on the caustic importance value, and then base the result on the multifaceted light source field function. Importance sampling is performed on the sampling direction to generate a set of sampled rays originating from the shading point, so that a single sampling can evaluate the cumulative contribution of all dynamic surface light sources to the shading point;
[0013] Step S50: Perform a ray tracing traversal once for each sampling ray in the sampling ray set. During the ray traversal, the occlusion judgment of all dynamic surface light sources and the transmission calculation of the semi-transparent material are completed simultaneously. When the sampling ray intersects with the semi-transparent object, the transmission attenuation coefficient is calculated based on the material's refractive index, the material's absorption coefficient, and the propagation distance of the sampling ray in the semi-transparent object. The transmission attenuation coefficient is then multiplied by the subsequently obtained light source contribution value to obtain the final contribution value of the sampling ray. After the ray traversal is completed, the final light source contribution value of the sampling ray is obtained by querying the multi-surface light source field function.
[0014] Step S60: For each pixel, the final contribution values of all sampled rays in the sampled ray set corresponding to that pixel are averaged to obtain the initial shadow value of that pixel, based on the caustic importance map. Determine the adaptive filtering radius, perform screen-space bilateral filtering on the initial shadow value to obtain the final shadow value of the pixel, multiply the final shadow value by the scene diffuse color value to generate the final rendering color of the pixel, and output the final rendering color to the frame buffer.
[0015] As a further preferred embodiment of this technical solution, in step S20, the field function of the multi-faceted light source is constructed. Specifically, it includes:
[0016] Sub-step S21: For each pixel in the screen space pixel coordinate set, generate a line of sight from the camera position through the pixel based on the camera parameters, determine the first intersection point of the line of sight with the scene geometry as the shading point, and obtain the world space coordinates of the shading point. ;
[0017] Sub-step S22: Based on the dynamic surface light source parameter set, assign each dynamic surface light source to the shading point. Along the direction The contribution value is encoded as the light source contribution tensor. The light source contributes tensor It includes the spatial location encoding, shape encoding, spectral encoding, and intensity encoding of the dynamic surface light source, as well as the orientation-related visibility encoding;
[0018] Sub-step S23: Aggregate the light source contribution tensors of all dynamic surface light sources to generate the multi-surface light source field function. ,in This represents the summation over all dynamic surface light sources.
[0019] As a further preferred embodiment of this technical solution, the construction of the caustic candidate set C in step S30 specifically includes:
[0020] Sub-step S31: For each semi-transparent object, obtain its material thickness field distribution function. Calculate the thickness field distribution function of the material. gradient ;
[0021] Sub-step S32: Obtain the refractive index n and absorption coefficient α of the material for each translucent object, and calculate the caustic weighting factor for each surface point. ;
[0022] Sub-step S33: Change the gradient magnitude The caustic weighting factor is greater than the preset thickness change threshold. Surface points with a value greater than a preset caustic threshold are included in the caustic candidate set C;
[0023] Sub-step S34: Map the surface points in the caustic candidate set C to screen space to generate the caustic importance map. The caustic importance diagram The value of each pixel represents the probability that the pixel region belongs to the caustic candidate region.
[0024] As a further preferred embodiment of this technical solution, generating the sampling light set in step S40 specifically includes:
[0025] Sub-step S41: For each pixel, generate a main line of sight passing through the pixel from the camera position according to the camera parameters, determine the first intersection point of the main line of sight and the scene geometry as the shading point, and obtain the world space coordinates P of the shading point;
[0026] Sub-step S42: Query the caustic importance map. Obtain the caustic importance value corresponding to this pixel. According to the caustic importance value Determine the number of sampled rays for this pixel. ,in Based on the number of samples, This is the proportionality coefficient;
[0027] Sub-step S43: Based on the multi-faceted light source field function Importance sampling is performed on the sampling direction to ensure the direction of the sampling light rays is correct. The probability of being selected and The value is directly proportional to the value;
[0028] Sub-step S44, for each sampling ray direction Generate a path starting from the colored point P and along the direction Propagated sampling light The set of sampled rays for that pixel is formed by combining all sampled rays. .
[0029] As a further preferred embodiment of this technical solution, performing a ray traversal in step S50 specifically includes:
[0030] Sub-step S51: For each shadow detection ray The accelerated structure of the scene is traversed to determine the sequence of intersections between the shadow probe ray and the scene geometry along its propagation path;
[0031] Sub-step S52: When the geometry corresponding to the first intersection in the intersection sequence is an opaque object, it is determined that the shadow detection ray is completely blocked, and the contribution value of the sampling ray is recorded as 0.
[0032] Sub-step S53: When the geometry corresponding to the first intersection point in the intersection point sequence is a semi-transparent object, obtain the refractive index n of the material, the absorption coefficient α of the material, and the propagation distance d of the sampled light within the semi-transparent object, and calculate the transmission attenuation coefficient. The refraction direction is calculated according to Snell's law, the propagation direction of the sampled light is updated, and the light continues to travel along the updated direction in the same ray tracing traversal.
[0033] Sub-step S54: Continue to perform intersection tests on the sampled rays with the updated direction until the sampled rays exit the scene or reach the preset maximum number of bounces, and record the light source contribution value of the final hit by the sampled rays. The contribution value of the light source By querying the field function of the multifaceted light source The value is obtained at the endpoint of the sampled light ray;
[0034] Sub-step S55: The sampling light Contribution value With the transmission attenuation coefficient Multiplying these values yields the final contribution value carried by the sampled ray. .
[0035] As a further preferred embodiment of this technical solution, obtaining the final shadow value of the pixel in step S60 specifically includes:
[0036] Sub-step S61: Obtain the final contribution value of all sampling rays in the sampling ray set corresponding to the pixel. Calculate the average of all final contribution values to obtain the initial shadow value for that pixel. ;
[0037] Sub-step S62: Query the caustic importance map. Obtain the caustic importance value corresponding to this pixel. Calculate the adaptive filter kernel radius ,in The basic filter radius;
[0038] Sub-step S63: Using the adaptive filter kernel radius For the initial shadow value A screen-space bilateral filtering process is performed, considering both the spatial distance and color similarity between pixels, to obtain the final shadow value of that pixel. .
[0039] As a further preferred embodiment of this technical solution, the light source geometry in the dynamic surface light source parameter set includes at least one of rectangular surface light source, circular surface light source, and polygonal surface light source; the light source spectral power distribution function is used to characterize the energy distribution of the light source at different wavelengths to support the rendering of colored shadows.
[0040] As a further preferred embodiment of this technical solution: the material thickness field distribution function in the material parameter set of the semi-transparent object is represented by a directed distance field, which stores the directed distance from the internal points of the semi-transparent object to the object surface, so as to support the rapid calculation of the propagation distance of the sampled light inside the semi-transparent object.
[0041] Compared with the prior art, the beneficial effects of the present invention are:
[0042] 1. In this invention, by constructing a multi-faceted light source field function, the contribution of all dynamic surface light sources is encoded into a unified function representation, so that the cumulative contribution of all light sources can be evaluated in a single sampling, and the number of samplings no longer increases linearly with the number of light sources. In multi-light source scenarios, the performance can be improved by 5-10 times.
[0043] 2. In this invention, by constructing a caustic candidate set, key regions in semi-transparent objects that drastically alter the light path are identified, and high-precision ray tracing resources are concentrated in these regions. This significantly reduces computational overhead while ensuring visual effects, and for the first time, stable rendering of multi-source semi-transparent colored shadows and caustic effects in real-time games is achieved.
[0044] 3. In this invention, the collection of contributions from multiple light sources and the calculation of transmissivity of semi-transparent materials are completed simultaneously through a single ray tracing traversal, avoiding the repetitive overhead caused by multiple traversals and significantly improving the overall rendering efficiency. Attached Figure Description
[0045] Figure 1 This is an overall flowchart of a real-time game scene shadow rendering method and system based on ray tracing according to the present invention;
[0046] Figure 2This is a flowchart illustrating the construction of a multi-faceted light source field function for a real-time game scene shadow rendering method and system based on ray tracing, as described in this invention.
[0047] Figure 3 This is a flowchart illustrating the construction of a caustic candidate set in a real-time game scene shadow rendering method and system based on ray tracing, according to the present invention.
[0048] Figure 4 This is a flowchart illustrating the generation of a sampled ray set in a real-time game scene shadow rendering method and system based on ray tracing, according to the present invention.
[0049] Figure 5 This is a flowchart illustrating the execution of ray tracing traversal in a real-time game scene shadow rendering method and system based on ray tracing, as described in this invention.
[0050] Figure 6 This is a flowchart illustrating the reconstructed pixel shadow values of a real-time game scene shadow rendering method and system based on ray tracing, as described in this invention. Detailed Implementation
[0051] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0052] Example 1
[0053] Please see Figure 1 As shown, this invention provides a technical solution: a method and system for real-time game scene shadow rendering based on ray tracing, the method comprising the following steps:
[0054] Step S10: Data Acquisition
[0055] First, the rendering system acquires the parameters of all dynamic surface light sources in the current game scene. Dynamic surface light sources are planar light sources whose shape, position, intensity, or color changes over time, such as neon lights, explosions, magical effects, and car headlight arrays. For each dynamic surface light source, the acquired light source parameters include:
[0056] Spatial location of the light source: the three-dimensional coordinates of the light source in the world coordinate system;
[0057] Light source geometry: such as rectangular surface light source, circular surface light source, polygonal surface light source, etc.;
[0058] Light source spectral power distribution function: Characterizes the energy distribution of a light source at different wavelengths, used to support color shadow rendering;
[0059] Light source intensity scalar value: the brightness of the light source;
[0060] The light source parameters of all dynamic surface light sources are summarized to form a dynamic surface light source parameter set.
[0061] Secondly, the rendering system obtains the material parameters of all semi-transparent objects in the current game scene. Semi-transparent objects are those through which light can partially pass, such as glass, water surfaces, crystals, and particle effects. For each semi-transparent object, the obtained material parameters include:
[0062] Object geometric mesh data: the three-dimensional model data of the object;
[0063] Pose transformation matrix: The position and orientation of an object in the world coordinate system;
[0064] Material refractive index: The refractive index of light entering an object from air;
[0065] Material absorption coefficient: The energy attenuation coefficient of light as it propagates inside an object;
[0066] Material thickness field distribution function: A function that describes the thickness distribution inside an object, which can be represented by a directed distance field;
[0067] The material parameters of all semi-transparent objects are compiled into a semi-transparent object material parameter set.
[0068] Finally, the rendering system obtains the camera parameters of the current rendering frame, including the camera's position in world space, camera orientation vector, camera field of view, near clipping plane distance, and far clipping plane distance. Based on the camera parameters, a screen-space pixel coordinate set is generated, which contains the two-dimensional coordinates of each pixel to be rendered.
[0069] Step S20: Construct the field function of the multifaceted light source
[0070] like Figure 2 As shown, this step constructs the field function of a multi-faceted light source based on the dynamic surface light source parameter set. This function is used to characterize spatial location. Along the direction During observation, the cumulative radiative contribution of all dynamic surface light sources in this direction.
[0071] Specifically, for each pixel in the screen space pixel coordinate set, a line of sight passing through the pixel from the camera position is generated based on the camera parameters. The first intersection point of this line of sight with the scene geometry is determined as the shading point, and the world space coordinates of the shading point are obtained. .
[0072] Then, based on the dynamic surface light source parameter set, each dynamic surface light source is shaded at the point. Along the direction The contribution value is encoded as the light source contribution tensor. This tensor contains the spatial position, shape, spectral, and intensity codes of the dynamic surface light source, as well as the orientation-dependent visibility code.
[0073] Finally, the light source contribution tensors of all dynamic surface light sources are aggregated to generate a multi-surface light source field function:
[0074]
[0075] in This represents the summation over all dynamic surface light sources.
[0076] In this way, the contributions of multiple dynamic surface light sources are encoded into a unified functional representation, laying the foundation for evaluating the contributions of all light sources in a subsequent single sampling.
[0077] Step S30: Construct a caustic candidate set
[0078] like Figure 3 As shown, this step constructs a caustic candidate set C based on the material parameter set of the semi-transparent object. Caustics refers to the bright spot effect formed when light passes through a semi-transparent object and focuses. The caustic candidate set is used to identify areas in the semi-transparent object where the light path changes drastically, so that these areas can be sampled in a focused manner.
[0079] Specifically, for each semi-transparent object, obtain its material thickness field distribution function. Calculate the gradient of the function. The magnitude of the gradient indicates the degree of drastic change in thickness.
[0080] Then, obtain the material refractive index of each translucent object. and material absorption coefficient Calculate the caustic weighting factor for each surface point:
[0081]
[0082] In this formula, The term represents the effect of changes in refractive index on the optical path. The term represents the effect of the absorption coefficient on the caustic intensity. The term represents the effect of the thickness change rate on caustic formation. The caustic weighting factor obtained by multiplying the three factors can comprehensively assess the likelihood of caustic effects occurring at that point.
[0083] Gradient magnitude Greater than the preset thickness change threshold and caustic weighting factor Surface points with values greater than the preset caustic threshold are included in the caustic candidate set C.
[0084] Finally, the surface points in the caustic candidate set C are mapped to screen space to generate a caustic importance graph. The value of each pixel in this image represents the probability that the pixel region belongs to a caustic candidate region. The larger the value, the more likely the region is to produce a caustic effect, and the higher the sampling density is required.
[0085] Step S40: Generate a set of sampled rays
[0086] like Figure 4 As shown, this step generates a corresponding set of sampled rays for each pixel in the screen space pixel coordinate set.
[0087] First, for each pixel, a main line of sight passing through the pixel from the camera position is generated based on the camera parameters. The first intersection point of the main line of sight and the scene geometry is determined as the shading point, and the world space coordinates P of the shading point are obtained.
[0088] Then, query the caustic importance map M_c to obtain the caustic importance value corresponding to that pixel. This value determines the number of sampled rays for that pixel:
[0089]
[0090] in Based on the number of samples, This is a scaling factor. The higher the caustic importance value, the more rays are sampled, resulting in higher rendering quality in caustic areas.
[0091] Next, based on the field function of the multi-faceted light source Importance sampling is performed on the sampling direction. Specifically, the sampling light direction is adjusted. The probability of being selected and The value is proportional to the light source's contribution, meaning that directions with a larger contribution receive a higher sampling probability, thus optimizing the allocation of sampling resources. This mechanism allows a single sampling to evaluate the cumulative contribution of all dynamic surface light sources to the shading point, decoupling computational complexity from the number of light sources.
[0092] Finally, for each sampling ray direction Generate a path starting from the colored point P and along the direction Propagated sampling light All sampled rays are combined to form the sampled ray set for that pixel. .
[0093] Step S50: Perform ray tracing traversal
[0094] like Figure 5As shown, this step performs a ray traversal once for each sample ray in the sample ray set. It should be noted that the "sample ray" generated in step S40 is specifically manifested as a "shadow detection ray" during the execution phase, which is used to determine the occlusion situation from the shading point to the light source direction.
[0095] For each shadow detection ray First, the scene's acceleration structure (such as BVH, i.e., the bounding box) is traversed to determine the sequence of intersections between the shadow probe ray and the scene geometry along its propagation path.
[0096] When the geometry corresponding to the first intersection in the intersection sequence is an opaque object, it is determined that the shadow detection ray is completely blocked, and the contribution value of the sampling ray is recorded as 0.
[0097] When the geometry corresponding to the first intersection point in the intersection point sequence is a semi-transparent object, obtain the refractive index of the material of that semi-transparent object. Material absorption coefficient And the distance the sampling light travels within the translucent object. Calculate the transmission attenuation coefficient:
[0098]
[0099] This coefficient represents the proportion of energy attenuation of light after it has traveled a distance *d* within a semi-transparent object. Simultaneously, the refraction direction is calculated according to Snell's law, and the propagation direction of the sampled light is updated. The light then continues to travel along the updated direction during the same ray tracing traversal. The phrase "same ray traversal" emphasizes that this is a calculation of the path extension of the same ray, rather than initiating a new traversal.
[0100] The sampled ray continues to be tested for intersection along the updated direction until it exits the scene or reaches the preset maximum number of bounces (usually 1-3). At this point, the light source contribution value of the final hit by the sampled ray is recorded. This value is obtained by querying the field function of the multifaceted light source. The value is obtained at the end position of the sampled light beam.
[0101] Finally, sample the light. Contribution value With transmission attenuation coefficient Multiplying these yields the final contribution carried by the sampled ray. If the light path encounters multiple semi-transparent objects, the transmission attenuation coefficient is the product of the attenuation coefficients of each segment.
[0102] In this way, this step completes the occlusion judgment of all dynamic surface light sources and the transmission calculation of semi-transparent materials in one ray tracing traversal, avoiding the repetitive overhead caused by multiple traversals.
[0103] Step S60: Reconstruct shadow values and output
[0104] like Figure 6 As shown, in this step, for each pixel, the final shadow value of the pixel is reconstructed based on the contribution value of each sampling ray in its corresponding sampling ray set.
[0105] First, obtain the final contribution value of all sampling rays in the sampling ray set corresponding to the pixel. Calculate the average of all final contribution values to obtain the initial shadow value for that pixel:
[0106]
[0107] Then, query the caustic importance map M_c to obtain the caustic importance value v_c corresponding to the pixel, and calculate the adaptive filter kernel radius:
[0108]
[0109] in The base filter radius. The meaning of this formula is: the higher the importance of caustics ( The larger the caustic value, the smaller the filter radius, thus preserving more details; the lower the importance of caustics, the larger the filter radius, thus better smoothing noise.
[0110] The adaptive filter kernel radius obtained by calculation For the initial shadow value Screen space bilateral filtering is performed. Bilateral filtering takes into account both the spatial distance between pixels and the color similarity, which can smooth noise while maintaining the sharpness of shadow edges.
[0111] Finally, the final shadow value Multiply the pixel's color by the scene's diffuse color value to generate the final rendered color, and then output the final rendered color to the frame buffer for display on the display device.
[0112] Example 2
[0113] Based on Example 1, this embodiment further defines the geometry of the light source in the dynamic surface light source parameter set.
[0114] The light source geometry in the dynamic surface light source parameter set includes at least one of rectangular surface light sources, circular surface light sources, and polygonal surface light sources. Different shapes of surface light sources require different sampling strategies in shadow calculation. The multi-surface light source field function of this invention can uniformly process surface light sources of various shapes through spatial position encoding and shape encoding.
[0115] Furthermore, the spectral power distribution function of the light source is used to characterize the energy distribution of the light source at different wavelengths. By encoding spectral information into the light source contribution tensor, this method can support the rendering of colored shadows, that is, the shadows cast by semi-transparent objects will show the superposition effect of the color of the light source and the color of the semi-transparent object.
[0116] Example 3
[0117] This embodiment, based on Embodiment 1, further defines the material thickness field distribution function in the material parameter set of the semi-transparent object.
[0118] The material thickness field distribution function is represented using a directed distance field (SDF). A directed distance field is an implicit surface representation method that stores the directed distances from points inside a semi-transparent object to the object's surface: positive values indicate that the point is outside the object, negative values indicate that the point is inside the object, and absolute values represent the distance from the point to the nearest surface.
[0119] Representing the material thickness field distribution function using a directed distance field has the following advantages: First, it can quickly calculate the propagation distance of sampled light rays inside a semi-transparent object, requiring only analytical calculation when the light rays intersect with the directed distance field, without traversing complex geometry; second, it can conveniently calculate the thickness gradient for constructing caustic candidate sets; third, the directed distance field can be generated through pre-computation or real-time voxelization, making it suitable for both static and dynamic semi-transparent objects.
[0120] Technical effect verification
[0121] The technical effects of this invention can be verified through the following comparisons:
[0122] Performance Comparison: In a test scene containing 10 dynamic surface light sources and 5 semi-transparent objects, the traditional "independent sampling and accumulation for each light source" method requires each pixel to emit 10 sets of rays, with each set containing approximately 50 rays, resulting in a total of approximately 500 sampling times. Using the method of this invention, through multi-surface light source field function encoding, each pixel only needs to emit approximately 30 rays (adaptively adjusted according to the importance of caustics), reducing the sampling time by approximately 94%, while simultaneously achieving colored shadows and caustics effects.
[0123] Quality Comparison: Under the same sampling budget, the method of this invention improves the sampling density in the caustic region by 3-5 times through importance sampling guided by the caustic candidate set, and can clearly present the color caustic effect of the glass edge; while the traditional method, due to the dispersion of sampling, shows the caustic region as a blurry bright spot, and the details are seriously lost.
[0124] Real-time performance verification: On an NVIDIA RTX 4080 graphics card, running the test scene at a resolution of 1920×1080, the traditional method achieved a frame rate of approximately 25 FPS, which could not meet the requirements of real-time games; the method of this invention maintained a stable frame rate of over 60 FPS, fully meeting the rendering requirements of real-time games.
[0125] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A method for real-time game scene shadow rendering based on ray tracing, characterized in that, Includes the following steps: Step S10: Obtain the dynamic surface light source parameter set in the current game scene. The dynamic surface light source parameter set includes the light source spatial position, light source geometry, light source spectral power distribution function, and light source intensity scalar value of each dynamic surface light source. Obtain the material parameter set of semi-transparent objects in the current game scene. The semi-transparent object material parameter set includes the geometric mesh data, pose transformation matrix, material refractive index, material absorption coefficient and material thickness field distribution function of each semi-transparent object; obtain the camera parameters of the current rendering frame, and generate a screen space pixel coordinate set based on the camera parameters; Step S20, constructing a multi-faceted light source field function based on the dynamic facet light source parameter set wherein denotes a three-dimensional position coordinate in the world space, denotes a direction vector, the multi-faceted light source field function is used to characterize the cumulative radiance contribution of all dynamic facet light sources in the direction when observed at a position ; Step S30, constructing a plenoptic candidate set C based on the translucent object material parameter set, the plenoptic candidate set C containing surface points with both the material thickness field gradient module length and the plenoptic weight factor exceeding the preset thickness variation threshold and the preset plenoptic threshold, and mapping the plenoptic candidate set C to the screen space to generate a plenoptic importance map ; Step S40: For each pixel in the screen space pixel coordinate set, generate the corresponding shading point coordinates based on the camera parameters, and query the caustic importance map. Obtain the caustic importance value of the pixel, determine the number of sampled rays for the pixel based on the caustic importance value, and then base the result on the multifaceted light source field function. Importance sampling is performed on the sampling direction to generate a set of sampled rays originating from the shading point, so that a single sampling can evaluate the cumulative contribution of all dynamic surface light sources to the shading point; Step S50: Perform a ray tracing traversal once for each sampling ray in the sampling ray set. During the ray traversal, the occlusion judgment of all dynamic surface light sources and the transmission calculation of the semi-transparent material are completed simultaneously. When the sampling ray intersects with the semi-transparent object, the transmission attenuation coefficient is calculated based on the material's refractive index, the material's absorption coefficient, and the propagation distance of the sampling ray in the semi-transparent object. The transmission attenuation coefficient is then multiplied by the subsequently obtained light source contribution value to obtain the final contribution value of the sampling ray. After the ray traversal is completed, the final light source contribution value of the sampling ray is obtained by querying the multi-surface light source field function. Step S60: For each pixel, the final contribution values of all sampled rays in the sampled ray set corresponding to that pixel are averaged to obtain the initial shadow value of that pixel, based on the caustic importance map. Determine the adaptive filtering radius, perform screen-space bilateral filtering on the initial shadow value to obtain the final shadow value of the pixel, multiply the final shadow value by the scene diffuse color value to generate the final rendering color of the pixel, and output the final rendering color to the frame buffer.
2. The method according to claim 1, characterized in that, In step S20, the multifaceted light source field function is constructed. Specifically, it includes: Sub-step S21: For each pixel in the screen space pixel coordinate set, generate a line of sight from the camera position through the pixel based on the camera parameters, determine the first intersection point of the line of sight with the scene geometry as the shading point, and obtain the world space coordinates of the shading point. ; Sub-step S22: Based on the dynamic surface light source parameter set, assign each dynamic surface light source to the shading point. Along the direction The contribution value is encoded as the light source contribution tensor. The light source contributes tensor It includes the spatial location encoding, shape encoding, spectral encoding, and intensity encoding of the dynamic surface light source, as well as the orientation-related visibility encoding; Sub-step S23: Aggregate the light source contribution tensors of all dynamic surface light sources to generate the multi-surface light source field function. ,in This represents the summation over all dynamic surface light sources.
3. The method according to claim 1, characterized in that, The construction of the caustic candidate set C in step S30 specifically includes: Sub-step S31: For each semi-transparent object, obtain its material thickness field distribution function. Calculate the thickness field distribution function of the material. gradient ; Sub-step S32: Obtain the refractive index n and absorption coefficient α of the material for each translucent object, and calculate the caustic weighting factor for each surface point. ; Sub-step S33: Change the gradient magnitude The caustic weighting factor is greater than the preset thickness change threshold. Surface points with a value greater than a preset caustic threshold are included in the caustic candidate set C; Sub-step S34: Map the surface points in the caustic candidate set C to screen space to generate the caustic importance map. The caustic importance diagram The value of each pixel represents the probability that the pixel region belongs to the caustic candidate region.
4. The method according to claim 1, characterized in that, The specific steps in step S40 of generating the sampled light set include: Sub-step S41: For each pixel, generate a main line of sight passing through the pixel from the camera position according to the camera parameters, determine the first intersection point of the main line of sight and the scene geometry as the shading point, and obtain the world space coordinates P of the shading point; Sub-step S42: Query the caustic importance map. Obtain the caustic importance value corresponding to this pixel. According to the caustic importance value Determine the number of sampled rays for this pixel. ,in Based on the number of samples, This is the proportionality coefficient; Sub-step S43: Based on the multi-faceted light source field function Importance sampling is performed on the sampling direction to ensure the direction of the sampling light rays is correct. The probability of being selected and The value is directly proportional to the value; Sub-step S44, for each sampling ray direction Generate a path starting from the colored point P and along the direction Propagated sampling light The set of sampled rays for that pixel is formed by combining all sampled rays. .
5. The method according to claim 1, characterized in that, The specific steps of performing a ray traversal in step S50 include: Sub-step S51: For each shadow detection ray The accelerated structure of the scene is traversed to determine the sequence of intersections between the shadow probe ray and the scene geometry along its propagation path; Sub-step S52: When the geometry corresponding to the first intersection in the intersection sequence is an opaque object, it is determined that the shadow detection ray is completely blocked, and the contribution value of the sampling ray is recorded as 0. Sub-step S53: When the geometry corresponding to the first intersection point in the intersection point sequence is a semi-transparent object, obtain the refractive index n of the material, the absorption coefficient α of the material, and the propagation distance d of the sampled light within the semi-transparent object, and calculate the transmission attenuation coefficient. The refraction direction is calculated according to Snell's law, the propagation direction of the sampled light is updated, and the light continues to travel along the updated direction in the same ray tracing traversal. Sub-step S54: Continue to perform intersection tests on the sampled rays with the updated direction until the sampled rays exit the scene or reach the preset maximum number of bounces, and record the light source contribution value of the final hit by the sampled rays. The contribution value of the light source By querying the field function of the multifaceted light source The value is obtained at the endpoint of the sampled light beam; Sub-step S55: The sampling light Contribution value With the transmission attenuation coefficient Multiplying these values yields the final contribution value carried by the sampled ray. .
6. The method according to claim 1, characterized in that, The specific steps in step S60 to obtain the final shadow value of the pixel include: Sub-step S61: Obtain the final contribution value of all sampling rays in the sampling ray set corresponding to the pixel. Calculate the average of all final contribution values to obtain the initial shadow value for that pixel. ; Sub-step S62: Query the caustic importance map. Obtain the caustic importance value corresponding to this pixel. Calculate the adaptive filter kernel radius ,in The basic filter radius; Sub-step S63: Using the adaptive filter kernel radius For the initial shadow value A screen-space bilateral filtering process is performed, considering both the spatial distance and color similarity between pixels, to obtain the final shadow value of that pixel. .
7. The method according to claim 1, characterized in that, The light source geometry in the dynamic surface light source parameter set includes at least one of rectangular surface light source, circular surface light source, and polygonal surface light source; the light source spectral power distribution function is used to characterize the energy distribution of the light source at different wavelengths to support the rendering of colored shadows.
8. The method according to claim 1, characterized in that, The material thickness field distribution function in the material parameter set of the semi-transparent object is represented by a directed distance field. The directed distance field stores the directed distance from the point inside the semi-transparent object to the object surface, so as to support the rapid calculation of the propagation distance of the sampled light inside the semi-transparent object.