Shadow rendering method and device, computer equipment and storage medium

By distributing two-dimensional grids in the virtual scene to cluster the light sources and matching the light source clusters for shadow rendering, the problem of high computational complexity of the traditional shadow map method in complex scenes is solved and the efficiency of shadow rendering is improved.

CN118628638APending Publication Date: 2024-09-10SHENZHEN WANGYU COMPUTER NETWORK CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202310248022.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-03-08
Publication Date
2024-09-10

AI Technical Summary

Technical Problem

The traditional shadow map rendering method has high computational complexity in complex scenes, resulting in low shadow rendering efficiency, especially when there are many light sources.

Method used

Distribute a two-dimensional grid in the world space of the virtual scene, cluster the light sources according to the grid to obtain the target light source cluster, and determine the matching light source cluster from multiple target light source clusters for each pixel for shadow rendering.

Benefits of technology

The efficiency of shadow rendering is improved, especially in complex scenes and multiple light sources, shadow rendering can be quickly achieved, thereby improving rendering performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118628638A
    Figure CN118628638A
Patent Text Reader

Abstract

The invention relates to a shadow rendering method and device, computer equipment and a storage medium. The method comprises the steps that two-dimensional grids are distributed on a preset plane in a world space where a virtual scene is located; clustering a plurality of light sources in the virtual scene according to each cell in the two-dimensional grid to obtain a target light source cluster corresponding to each cell; projection areas, on the preset plane, of illumination areas of light sources in the target light source cluster intersect with the corresponding cells; aiming at each pixel point in a screen space, determining a matched light source cluster which has illumination influence on the pixel point from the plurality of target light source clusters; and performing shadow rendering based on the respective matched light source cluster of each pixel point to obtain a shadow rendering result. By adopting the method, the shadow rendering efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of rendering technology, and in particular to a shadow rendering method, device, computer equipment and storage medium. Background Art

[0002] With the development of computer technology, shadow rendering technology has emerged. Shadow rendering technology is used to render shadows to enhance the realism of rendering results.

[0003] In traditional technology, shadow maps are usually used to render shadows. The computational complexity of the rendering method based on shadow maps is closely related to the complexity of the scene to be rendered. The higher the complexity of the scene, the higher the performance requirement.

[0004] Therefore, when the scene complexity is high, for example, when there are many light sources in the scene, the rendering method based on the shadow map has the problem of high computational complexity, resulting in low shadow rendering efficiency. Summary of the invention

[0005] Based on this, it is necessary to provide a shadow rendering method, apparatus, computer equipment, computer-readable storage medium and computer program product that can improve the efficiency of shadow rendering in response to the above technical problems.

[0006] On the one hand, the present application provides a shadow rendering method. The method includes: distributing a two-dimensional grid on a preset plane in the world space where the virtual scene is located; clustering multiple light sources in the virtual scene according to each cell in the two-dimensional grid to obtain a target light source cluster corresponding to each cell; there is an intersection relationship between the illumination area of ​​the light source in the target light source cluster and the projection area on the preset plane and the corresponding cell; for each pixel point in the screen space, determining a matching light source cluster that has an illumination effect on the pixel point from the multiple target light source clusters; performing shadow rendering based on the matching light source cluster of each pixel point to obtain a shadow rendering result.

[0007] On the other hand, the present application also provides a shadow rendering device. The device includes: a grid distribution module, which is used to distribute a two-dimensional grid on a preset plane in the world space where the virtual scene is located; a light source clustering module, which is used to cluster multiple light sources in the virtual scene according to each cell in the two-dimensional grid, and obtain a target light source cluster corresponding to each cell; there is an intersection relationship between the illumination area of ​​the light source in the target light source cluster and the projection area on the preset plane and the corresponding cell; a light source cluster matching module, which is used to determine, for each pixel point in the screen space, a matching light source cluster that has an illumination effect on the pixel point from the multiple target light source clusters; a shadow rendering module, which is used to perform shadow rendering based on the matching light source cluster of each pixel point to obtain a shadow rendering result.

[0008] In some embodiments, the light source clustering module is further used to obtain, for each cell in the two-dimensional grid, a target light source cluster for the cell based on the light sources among the multiple light sources that have an intersection relationship with the cell; wherein, having an intersection relationship with the cell means that a projection area of ​​the illumination area on the preset plane intersects with the cell, and the number of light sources in the target light source cluster is less than or equal to a preset number.

[0009] In some embodiments, the light source clustering module is also used to determine the intersecting light sources of the cell from the multiple light sources in sequence; the intersecting light sources of the cell refer to light sources whose projection areas of the illumination area on the preset plane intersect with the cell; when the number of light sources included in the current light source cluster of the cell is less than the preset number, the intersecting light sources are added to the current light source cluster of the cell; return to the step of determining the intersecting light sources of the cell from the multiple light sources in sequence until the multiple light sources are traversed; when the multiple light sources are traversed, the current light source cluster of the cell is determined as the target light source cluster of the cell.

[0010] In some embodiments, the light source clustering module is further used to determine a characterization value of the degree of influence of the intersecting light sources of the cell on the cell when the number of light sources included in the current light source cluster of the cell reaches the preset number; search for a first light source to be replaced from the current light source cluster of the cell; the characterization value of the degree of influence of the first light source to be replaced on the cell is less than the characterization value of the degree of influence of the intersecting light source on the cell; remove the first light source to be replaced found from the current light source cluster of the cell, and add the intersecting light source to the current light source cluster of the cell.

[0011] In some embodiments, the light source clustering module is further used to determine a distance quantization value of the intersecting light sources of the cell; the distance quantization value is used to characterize the distance between the intersecting light sources of the cell and the cell; based on the distance quantization value, a characterization value of the degree of influence of the intersecting light sources of the cell on the cell is determined; the characterization value of the degree of influence is negatively correlated with the distance quantization value.

[0012] In some embodiments, the light source clustering module is further used to determine the attribute quantization value of the intersecting light sources of the cell; the attribute quantization value is determined based on the attribute of the intersecting light sources of the cell; based on the distance quantization value and the attribute quantization value, determine the influence characterization value of the intersecting light sources of the cell on the cell.

[0013] In some embodiments, the number of light sources included in the target light source cluster is less than or equal to a preset number; the light source clustering module is further used to determine candidate light sources from the multiple light sources in turn, and determine cells that have an intersection relationship with the candidate light sources on a preset plane from each of the cells in the two-dimensional grid; when the number of light sources included in the current light source cluster of the determined cell is less than the preset number, the candidate light source is added to the current light source cluster of the determined cell; the step of determining candidate light sources from the multiple light sources in turn until the multiple light sources are traversed; after traversing the multiple light sources, the current light source cluster of each cell in the two-dimensional grid is respectively determined as the target light source cluster of each cell.

[0014] In some embodiments, the light source clustering module is further used to determine a characterization value of the degree of influence of the candidate light source on the determined cell when the number of light sources included in the current light source cluster of the determined cell reaches the preset number; search for a second light source to be replaced from the current light source cluster of the determined cell; the characterization value of the degree of influence of the second light source to be replaced on the determined cell is smaller than the characterization value of the degree of influence of the candidate light source on the determined cell; remove the found second light source to be replaced from the current light source cluster of the determined cell, and add the candidate light source to the current light source cluster of the determined cell.

[0015] In some embodiments, the light source cluster matching module is also used to determine the world space position of the pixel point; determine the cell to which the projection position of the world space position of the pixel point on the preset plane belongs, and obtain the target cell; and determine the target light source cluster corresponding to the target cell as the matching light source cluster that has an illumination effect on the pixel point.

[0016] In some embodiments, the shadow rendering module is also used to determine, for each pixel point in the screen space, the light source participating in the shadow rendering, when the matching light source cluster of the pixel point includes a light source participating in the shadow rendering; perform shadow rendering based on the light source touch information of the light source participating in the shadow rendering for the pixel point to obtain a shadow rendering result.

[0017] In some embodiments, the shadow rendering module is also used to determine the cluster touch information of the pixel point; the cluster touch information of the pixel point includes the light source touch information of each light source in the matching light source cluster of the pixel point for the pixel point; from the cluster touch information of the pixel point, the light source touch information of the light source participating in the shadow rendering for the pixel point is searched.

[0018] In some embodiments, the shadow rendering module is also used to determine the light source reach information of each light source in the matching light source cluster of the pixel point for the pixel point; and the light source reach information of each light source in the matching light source cluster of the pixel point for the pixel point is combined into the cluster reach information of the pixel point.

[0019] On the other hand, the present application further provides a computer device, wherein the computer device comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps in the above shadow rendering method when executing the computer program.

[0020] On the other hand, the present application further provides a computer-readable storage medium having a computer program stored thereon, and the computer program implements the steps in the above shadow rendering method when executed by a processor.

[0021] On the other hand, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps in the above shadow rendering method are implemented.

[0022] The shadow rendering method, device, computer equipment, storage medium and computer program product above distribute a two-dimensional grid on a preset plane in the world space where the virtual scene is located, cluster multiple light sources in the virtual scene according to each cell in the two-dimensional grid, and obtain a target light source cluster corresponding to each cell. There is an intersection relationship between the illumination area of ​​the light source in the target light source cluster and the projection area on the preset plane and the corresponding cell. For each pixel point in the screen space, a matching light source cluster having an illumination effect on the pixel point is determined from multiple target light source clusters, and shadow rendering is performed based on the matching light source cluster of each pixel point to obtain a shadow rendering result. Since the light sources are clustered and shadow rendering is performed based on the matching light source cluster of the pixel point, shadow rendering can be quickly achieved in the case where there are many light sources in the virtual scene, thereby improving the shadow rendering efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Figure 1 A diagram of an application environment of a shadow rendering method in some embodiments;

[0024] Figure 2 is a flowchart of a shadow rendering method in some embodiments;

[0025] Figure 3 is a schematic diagram of a two-dimensional grid in some embodiments;

[0026] Figure 4 A schematic diagram of the intersection of a projection area and a cell in some embodiments;

[0027] Figure 5 is a schematic diagram of a bit string stored in a screen pixel shadow mask buffer in some embodiments;

[0028] Figure 6 A flowchart of storing light source reach information via a bit string in some embodiments;

[0029] Figure 7 This is a real-time rendering picture obtained when no shadows are rendered in some embodiments;

[0030] Figure 8 The real-time rendering picture obtained by rendering the shadow in some embodiments;

[0031] Fig. 9 A schematic diagram of a light source cluster corresponding to a cell in some embodiments;

[0032] Fig.10 A flow chart of clustering multiple light sources to obtain a target light source cluster in some embodiments;

[0033] Fig.11 A flowchart of performing shadow rendering by reading light source reach information in some embodiments;

[0034] Fig.12 is a flowchart of a shadow rendering method in some embodiments;

[0035] Fig.13 is a structural block diagram of a shadow rendering device in some embodiments;

[0036] Fig.14 is an internal structure diagram of a computer device in some embodiments;

[0037] Fig.15 1 is a diagram of the internal structure of a computer device in some embodiments. DETAILED DESCRIPTION

[0038] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0039] The shadow rendering method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown, the terminal 102 communicates with the server 104 through a network. The data storage system can store data that the server 104 needs to process. The data storage system can be integrated on the server 104, or placed on the cloud or other servers.

[0040] Specifically, the terminal 102 can obtain a virtual scene from the server 104. The terminal 102 can distribute a two-dimensional grid on a preset plane in the world space where the virtual scene is located, cluster multiple light sources in the virtual scene according to each cell in the two-dimensional grid, and obtain a target light source cluster corresponding to each cell. There is an intersection relationship between the illumination area of ​​the light source in the target light source cluster and the projection area on the preset plane and the corresponding cell. For each pixel point in the screen space, a matching light source cluster having an illumination effect on the pixel point is determined from multiple target light source clusters, and shadow rendering is performed based on the matching light source cluster of each pixel point to obtain a shadow rendering result. The terminal 102 can display the shadow rendering result, or send the shadow rendering result to the server 104.

[0041] Among them, the terminal 102 can be, but is not limited to, various desktop computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, cloud security, host security and other network security services, CDN, and basic cloud computing services such as big data and artificial intelligence platforms. The terminal 102 and the server 104 can be directly or indirectly connected via wired or wireless communication, and this application does not limit this.

[0042] In some embodiments, Figure 2 As shown, a shadow rendering method is provided, which can be executed by a terminal or a server, or by a terminal and a server together. Figure 1 The terminal 102 in the example is used as an example to illustrate, and the following steps are included:

[0043] Step 202: distribute two-dimensional grids on a preset plane in the world space where the virtual scene is located.

[0044] The virtual scene is a virtual scene displayed (or provided) when the application is running on the terminal. The virtual scene can be a simulated environment scene of the real world, a semi-simulated and semi-fictitious three-dimensional environment scene, or a purely fictitious three-dimensional environment scene. The virtual scene can be any one of a two-dimensional virtual scene, a 2.5-dimensional virtual scene, and a three-dimensional virtual scene.

[0045] World Space refers to the three-dimensional space where the virtual scene is located. The size of the world space can be customized. For example, the world space is a three-dimensional space with a length of 100 meters, a width of 100 meters, and a height of 100 meters. The world space position refers to the position in the world space.

[0046] The preset plane can be set as needed. For example, the virtual scene includes the ground, which can also be called a horizontal plane. The preset plane can be a plane parallel to the horizontal plane, and the horizontal plane can be used as the preset plane. The preset plane can also be a plane with a preset angle to the horizontal plane. The preset angle can be set as needed, for example, 0-90 degrees. The size of the preset angle is not limited here.

[0047] The two-dimensional grid has a certain size and shape, and the size and shape of the two-dimensional grid can be preset as needed. For example, if the shape of the two-dimensional grid is a rectangle, the length and width of the two-dimensional grid can be set as needed. The two-dimensional grid includes a plurality of cells, and the shape of the cells includes but is not limited to at least one of a rectangle or a triangle. The sizes of the cells in the two-dimensional grid can be the same or different. Figure 3 As shown, a schematic diagram of a two-dimensional grid is shown. Figure 3 The two-dimensional grid in has a total of 16 cells. The position of a cell can be represented by rows and columns. The number in each cell represents the position of the cell. For example, "0-0" represents the cell in the 0th row and 0th column, and "1-1" represents the cell in the 1st row and 1st column.

[0048] Specifically, the terminal can distribute a two-dimensional grid on a preset plane in the world space where the virtual scene is located, and the position of the two-dimensional grid on the preset plane can be updated in real time. For example, in real-time rendering, the position of the two-dimensional grid on the preset plane can be updated in real time according to the real-time switching of the screen, so that the light sources in the target light source cluster obtained by clustering the two-dimensional grid can cover the light sources involved in the real-time rendering. A light source cluster is a collection of light sources.

[0049] Step 204 , clustering multiple light sources in the virtual scene according to each cell in the two-dimensional grid to obtain a target light source cluster corresponding to each cell; there is an intersection relationship between the projection area of ​​the illumination area of ​​the light source in the target light source cluster on the preset plane and the corresponding cell.

[0050] Among them, the light source refers to an object that can emit light by itself and is emitting light, such as the sun, electric lights, burning substances, etc. The light source in the virtual scene is a series of lighting data that can truly simulate the lighting effect of the light source in reality. The lighting area of ​​the light source refers to the area that the light source can illuminate. The lighting area of ​​the light source can be any one of a sphere or a cone. When the lighting area of ​​the light source is a sphere, the lighting area of ​​the light source can be called the range sphere of the light source. The multiple light sources in the virtual scene can be all or part of the light sources in the virtual scene, for example, they can be the light sources whose projection areas intersect with the two-dimensional grid in the virtual scene. The projection area of ​​the light source refers to the projection area of ​​the lighting area of ​​the light source on the preset plane. The multiple light sources in the virtual scene can be stored in the buffer of the GPU, and the two-dimensional grid can also be stored in the GPU. The light source cluster refers to a set of light sources, and the target light source cluster is a light source cluster obtained by clustering the multiple light sources in the virtual scene.

[0051] Specifically, the terminal can determine the projection areas of the illumination areas of the multiple light sources on the preset plane, and for each cell in the two-dimensional grid, obtain the target light source cluster corresponding to the cell based on the light sources whose projection areas intersect with the cell. For example, the terminal can select all or part of the light sources from the light sources whose projection areas intersect with the cell to form the target light source cluster corresponding to the cell. Figure 4 As shown, it shows a schematic diagram of the intersection of the projection area of ​​the light source and the cells in the two-dimensional grid. Figure 4 Each circle represents the projection area of ​​a light source, and the solid point in the circle represents the center point of the circle, which is the projection position of the world space position of the light source on the preset plane. L0-L5 represent 5 light sources, and the number following L can be called the index of the light source. The number after the colon represents the brightness. For example, 100 in L4:100 represents the brightness.

[0052] In some embodiments, for each cell, a cell column of the cell is generated. The cell column of the cell is a column with the cell as a cross section, perpendicular to the preset plane, and with a height greater than a preset height. The terminal can obtain a target light source cluster corresponding to the cell based on each light source intersecting the illumination area with the unit column. The unit column can also be called a light source cluster column. The terminal can select all or part of the light sources from each light source intersecting the illumination area with the unit column to form a target light source cluster corresponding to the cell.

[0053] Step 206 : for each pixel point in the screen space, determine a matching light source cluster having an illumination effect on the pixel point from a plurality of target light source clusters.

[0054] The screen space refers to the two-dimensional space of the screen, and the size of the screen space is the size of the screen, in pixels. The matching light source cluster that has an illumination effect on a pixel point can be called the matching light source cluster of the pixel point, and the matching light source cluster of the pixel point can include the target light source corresponding to the pixel point, and the target light source corresponding to the pixel point refers to the light source whose illumination area includes the world space position of the pixel point.

[0055] Specifically, the terminal can determine the world space position of the pixel point, determine the cell to which the projection position of the world space position of the pixel point on the preset plane belongs, obtain the target cell, and determine the target light source cluster corresponding to the target cell as the matching light source cluster that has an illumination effect on the pixel point.

[0056] Step 208 , performing shadow rendering based on the matching light source cluster of each pixel point to obtain a shadow rendering result.

[0057] Specifically, for each pixel, the terminal can determine the cluster reach information of the pixel. The cluster reach information of the pixel includes the light source reach information of each light source in the matching light source cluster of the pixel for the pixel. The light source reach information of the light source for the pixel represents whether the light source generates light for the world space position of the pixel. The light source reach information is one of the first preset value or the second preset value. The first preset value represents that the light source does not generate light for the world space position of the pixel; the second preset value represents that the light source generates light for the world space of the pixel. The first preset value and the second preset value are different. The first preset value and the second preset value can be represented by different numerical values. For example, the first preset value is 1 and the second preset value is 0. Of course, the first preset value and the second preset value can also be other numerical values, which are not specifically limited here.

[0058] In some embodiments, for any light source in the matching light source cluster of a pixel point, when the illumination area of ​​the light source includes the world space position of the pixel point, that is, when the light source is the target light source corresponding to the pixel point, the terminal can perform ray tracing based on the world space position of the target light source and the world space position of the pixel point to obtain the light source contact information of the target light source for the pixel point. Among them, ray tracing can be implemented based on screen space ray tracing (Screen SpaceRay Tracing) and screen space shadow (Screen Space Shadow) algorithms. Among them, screen space ray tracing refers to a common real-time computer graphics algorithm that uses a pixel shading program or a compute shading program to access the scene depth buffer to determine whether two points in space are blocked by a pixel in the screen space in the corresponding world space. The screen space shadow algorithm is a real-time computer graphics algorithm that calculates whether a pixel produces a shadow under the light source by performing screen space ray tracing between the current pixel to be drawn and the light source.

[0059] In some embodiments, for any light source in the light source cluster matching the pixel point, the terminal can calculate the distance between the light source and the observation position, and determine the light source contact information of the light source for the pixel point when the distance between the light source and the observation position is greater than a distance threshold. The distance threshold can be set as needed, and the observation position refers to the position of the virtual camera currently observing the virtual scene.

[0060] In some embodiments, the terminal may determine the starting position of ray tracing and the ending position of ray tracing based on the world space position of the target light source and the world space position of the pixel. Specifically, the terminal may determine the world space position of the pixel as the starting position of ray tracing, determine the direction from the world space position of the pixel to the world space position of the target light source, obtain the ray tracing direction, and determine the ending position of ray tracing based on the ray tracing direction and the preset tracing distance. Among them, the preset tracing distance can be set as needed, for example, it can be determined according to the length of the shadow, and the preset tracing distance is greater than or equal to the length of the shadow. The ray tracing direction refers to the direction from the world space position of the pixel to the world space position of the target light source, and the ray tracing direction can be represented by a direction vector. The direction vector points from the world space position of the pixel to the world space position of the target light source, and is a unit vector.

[0061] In some embodiments, the terminal may calculate the product of the preset tracking distance and the direction vector, add the result of the product to the world space position of the pixel point, and use the result of the addition as the end position. For example, the preset tracking distance is L, the direction vector is (x1, y1, z1), and the world space position of the pixel point is (x2, y2, z2), then the end position = (x2, y2, z2) + L*(x1, y1, z1).

[0062] In some embodiments, the terminal may determine the number of ray tracing steps according to the starting position of the ray tracing and the ending position of the ray tracing. Specifically, the terminal may convert the starting position of the ray tracing to the target two-dimensional space to obtain the starting position after the conversion, and convert the ending position of the ray tracing to the target two-dimensional space to obtain the ending position after the conversion. Wherein, the target two-dimensional space is any one of the texture space (i.e., UV space) or the screen space. The texture space is a unit square area, and the texture coordinates are represented by (u, v), 0<=u<=1 0<=v<=1. In the case where the target two-dimensional space is the texture space, the terminal may determine the position corresponding to the starting position of the ray tracing after the conversion to the texture space, and use the determined position as the starting position after the conversion, and determine the position corresponding to the ending position of the ray tracing after the conversion to the texture space, and use the determined position as the ending position after the conversion. Similarly, in the case where the target two-dimensional space is the screen space, the terminal may determine the position corresponding to the starting position of the ray tracing after the conversion to the screen space, and use the determined position as the starting position after the conversion, and determine the position corresponding to the ending position of the ray tracing after the conversion to the screen space, and use the determined position as the ending position after the conversion.

[0063] In some embodiments, the terminal may determine a tracing step factor based on the distance between the converted starting position and the converted ending position, and determine the ray tracing steps according to the tracing step factor and the tracing step threshold. The tracing step factor reflects the screen area occupied by the line segment between the starting position of the ray tracing and the ending position of the ray tracing in the screen space. The larger the tracing step factor, the larger the screen area occupied in the screen space. The tracing step threshold can be pre-set as needed. Specifically, the distance between the converted starting position and the converted ending position is positively correlated with the tracing step factor. The ray tracing steps are positively correlated with the tracing step factor and the tracing step threshold. For example, the terminal may calculate the distance between the converted starting position and the converted ending position, and determine the calculated distance as the tracing step factor. The terminal can calculate the product of the tracking step factor and the maximum tracking step, and use the result of the product as the candidate tracking step. When the candidate tracking step is less than the minimum tracking step, the minimum tracking step is used as the ray tracing step. When the candidate tracking step is greater than the maximum tracking step, the maximum tracking step is used as the ray tracing step. When the candidate tracking step is greater than or equal to the minimum tracking step and the candidate tracking step is less than or equal to the minimum tracking step, the candidate tracking step is used as the ray tracing step. Since the tracking step factor reflects the screen area occupied by the line segment between the starting position of the ray tracing and the ending position of the ray tracing in the screen space, the larger the screen area occupied, the closer the distance between the camera and the pixel point and the light source is, and vice versa, the farther the distance between the camera and the pixel point and the light source is, so that the ray tracing step is positively correlated with the tracking step factor, so that the closer the pixel point and the light source are to the camera, the more ray tracing steps there are, and vice versa, the fewer ray tracing steps there are, so that the ray tracing is more reasonable and the efficiency of ray tracing is improved.

[0064] In some embodiments, the terminal can perform ray tracing according to the number of ray tracing steps to obtain the light source contact information of the target light source for the pixel point. Specifically, the terminal can determine the ray tracing step length based on the preset tracing distance and the number of ray tracing steps. For example, the terminal can calculate the ratio of the preset tracing distance to the number of ray tracing steps, and determine the calculated ratio as the ray tracing step length. The terminal can determine multiple sampling positions along the ray tracing direction from the world space position of the pixel point; wherein the length of the interval between two adjacent sampling positions in the ray tracing direction is the ray tracing step length, and the number of sampling positions is the ray tracing step number. Multiple sampling positions refer to the number of ray tracing steps. For example, if the number of ray tracing steps is 6, then multiple sampling positions refer to 6 sampling positions. For each sampling position, the terminal can determine the difference between the depth value of the sampling position and the depth value of the screen space position corresponding to the sampling position, and obtain the depth difference of the sampling position. The screen space position is the position of the pixel point in the screen space, and the depth value of the screen space position is the depth value of the pixel point. The terminal can store the depth value of each pixel in the screen space. The terminal can determine the depth value of the sampling position to obtain a first depth value, calculate the pixel corresponding to the sampling position in the screen space, and obtain the depth value of the corresponding pixel to obtain a second depth value, and calculate the difference between the first depth value and the second depth value to obtain the depth difference of the sampling position. The terminal can obtain the light source contact information of the target light source for the pixel point based on the depth difference of each sampling position. Among them, the depth value is used to reflect the distance between the world space position and the observation position, and the depth value of the pixel point is used to reflect the distance between the position of the pixel point in the world space and the observation position. The larger the depth value, the farther it is from the observation position.

[0065] In some embodiments, the terminal may determine a depth difference threshold based on the depth value of the starting position of ray tracing and the depth value of the ending position of ray tracing. Specifically, the terminal may determine the depth value of the starting position of ray tracing to obtain a starting depth value, determine the depth value of the ending position of ray tracing to obtain a ending depth value, determine the difference between the starting depth value and the ending depth value to obtain a total depth difference, and determine the depth difference threshold based on the total depth difference and the number of ray tracing steps. For example, the terminal may calculate the ratio of the total depth difference to the number of ray tracing steps, and determine the calculated ratio as the depth difference threshold. The depth difference threshold may also be referred to as a step depth.

[0066] In some embodiments, when the depth difference at any sampling position is less than or equal to a depth difference threshold, the light source touch information of the target light source for the pixel point is determined to be a first preset value; when the depth difference at each sampling position is greater than the depth difference threshold, the light source touch information of the target light source for the pixel point is determined to be a second preset value.

[0067] In some embodiments, for any light source in the matching light source cluster of a pixel point, when the illumination area of ​​the light source does not include the world space position of the pixel point, the terminal uses the first preset value as the light source reach information of the light source for the pixel point.

[0068] In some embodiments, before performing shadow rendering, the terminal may combine the light source contact information of each light source in the matching light source cluster of the pixel point with the light source contact information of the pixel point. When performing shadow rendering, the light source contact information of the light source participating in the shadow rendering with respect to the pixel point is obtained from the cluster contact information of the pixel point, and shadow rendering is performed based on the light source contact information of the light source participating in the shadow rendering with respect to the pixel point to obtain the shadow rendering result. There may be one or more light sources participating in the shadow rendering, and the light source participating in the shadow rendering refers to the light source actually to be drawn in the GPU (graphics processing unit) delay pipeline.

[0069] In some embodiments, for each pixel in the screen space, the terminal can generate a corresponding bit string for the pixel. The bit string is a character string that only includes at least one of 0 or 1. The length of the bit string is a fixed value, and the fixed value is greater than or equal to the maximum length of the light source list used to store the light source cluster. The actual form of the bit string can be a 32-bit integer, etc. The terminal can store the cluster contact information of the pixel in the form of a bit string. For example, different bits in the bit string represent different light source contact information in the cluster contact information. Before determining the light source contact information, the terminal can generate a bit string for the pixel, and initialize the characters of each bit in the bit string to a second preset value, such as 0. When it is determined that the light source contact information of the light source for the pixel is the first preset value, the bit corresponding to the light source in the bit string is updated to the first preset value, such as 1. When it is determined that the light source contact information of the light source for the pixel is the second preset value, the bit string remains unchanged. The terminal can create a buffer in the GPU, which can be called a screen pixel shadow mask buffer, and store the bit string of each pixel in the buffer. When performing shadow rendering, the terminal can read the light source contact information of the light source for the pixel from the buffer. Figure 5 As shown, a schematic diagram of the screen pixel shadow mask buffer is shown. The size of the screen pixel shadow mask buffer can match the screen size. For example, if the screen size is 1920×1080, the number of storage blocks of the screen pixel shadow mask buffer can be 1920×1080, and each storage block stores a bit string of a pixel point. Figure 5 shows the bit string stored in a memory block in the screen pixel shadow mask buffer. Figure 6 As shown, a flowchart of storing light source reach information through bit strings is shown.

[0070] In the above shadow rendering method, a two-dimensional grid is distributed on a preset plane in the world space where the virtual scene is located, and multiple light sources in the virtual scene are clustered according to each cell in the two-dimensional grid to obtain a target light source cluster corresponding to each cell. There is an intersection relationship between the illumination area of ​​the light source in the target light source cluster and the projection area on the preset plane and the corresponding cell. For each pixel point in the screen space, a matching light source cluster that has an illumination effect on the pixel point is determined from multiple target light source clusters, and shadow rendering is performed based on the matching light source cluster of each pixel point to obtain a shadow rendering result. Since the light sources are clustered and shadow rendering is performed based on the matching light source cluster of the pixel point, shadow rendering can be quickly achieved in the case where there are many light sources in the virtual scene, thereby improving the efficiency of shadow rendering.

[0071] The shadow rendering method provided in this application can be applied to real-time rendering to add a stronger sense of layering and realism to the rendered image through shadows, such as Figure 7 As shown in the figure, the real-time rendering screen without rendering the shadow is shown. Figure 8 As shown, the real-time rendering screen obtained by rendering the shadow is obviously Figure 7 , Figure 8 The real-time rendering screen has a stronger sense of layering and reality. Real-time rendering of multiple light sources requires the cooperation of real-time rendering of shadows of multiple light sources to achieve realistic real-time rendering under multiple light sources. The shadow rendering method provided in this application can make the performance of rendering of multiple light sources independent of the scene scale and the number of light sources, thereby improving the rendering efficiency of multiple light sources in scenes with multiple light sources, so that the rendering of shadows of multiple light sources can achieve real-time performance.

[0072] In some embodiments, multiple light sources in a virtual scene are clustered according to each cell in a two-dimensional grid to obtain a target light source cluster corresponding to each cell, including: for each cell in the two-dimensional grid, based on a light source among multiple light sources that has an intersection relationship with the cell, a target light source cluster for the cell is obtained; wherein, having an intersection relationship with the cell means that a projection area of ​​the illumination area on a preset plane intersects with the cell, and the number of light sources in the target light source cluster is less than or equal to a preset number.

[0073] The preset number can be set as required, for example, 20 or 50. When the projection area of ​​the illumination area of ​​the light source on the preset plane intersects with the cell, it is considered that the light source has an intersection relationship with the cell.

[0074] Specifically, for each cell, the terminal can determine the intersecting light sources of the cell from multiple light sources. The intersecting light sources of the cell refer to the light sources whose projection areas of the illumination area on the preset plane intersect with the cell. The number of intersecting light sources of the cell can be one or more, and multiple means at least two. When the number of intersecting light sources of the cell is less than or equal to the preset number, the terminal can group the intersecting light sources of the unit into a target light source cluster corresponding to the cell.

[0075] In this embodiment, since the number of light sources in the target light source cluster is less than or equal to the preset number, the impact of the number of light sources on the rendering performance is alleviated. When there are many light sources in the virtual scene, the rendering performance and efficiency can be improved.

[0076] In some embodiments, based on the light sources in the plurality of light sources intersecting with the cell, obtaining the target light source cluster of the cell includes: determining the intersecting light sources of the cell from the plurality of light sources in sequence; the intersecting light sources of the cell refer to the light sources whose projection area of ​​the illumination area on the preset plane intersects with the cell; when the number of light sources included in the current light source cluster of the cell is less than the preset number, adding the intersecting light sources to the current light source cluster of the cell; returning to the step of determining the intersecting light sources of the cell from the plurality of light sources in sequence until the plurality of light sources are traversed; when the plurality of light sources are traversed, determining the current light source cluster of the cell as the target light source cluster of the cell. Among them, the terminal can initialize the light source cluster of each cell, and the initialized light source cluster has no light source and can accommodate at most the preset number of light sources. For example, an empty list with a fixed length can be initialized as the initialized light source cluster, and the empty list with a fixed length can store at most the preset number of light sources. It should be noted that storing light sources in the light source cluster refers to storing the identifier of the light source, not the light source itself. The current light source cluster is initially the initialized light source cluster, and when the plurality of light sources are traversed, light sources can be added to the current light source cluster.

[0077] Specifically, for each cell in the two-dimensional grid, the method of this embodiment can be used to determine the target light source cluster. When the number of light sources included in the current light source cluster of the cell is less than the preset number, the terminal can add the intersecting light sources to the current light source cluster of the cell; when the number of light sources included in the current light source cluster of the cell is greater than or equal to the preset number, the terminal can determine the light source to be replaced from the current light source cluster of the cell, replace the light source to be replaced in the current light source cluster of the cell with the intersecting light source, and return to the step of determining the intersecting light sources of the cell from multiple light sources in turn until multiple light sources are traversed; when multiple light sources are traversed, the current light source cluster of the cell is determined as the target light source cluster of the cell.

[0078] In this embodiment, the target light source cluster is quickly determined by traversing the multiple light sources, thereby improving clustering efficiency.

[0079] In some embodiments, the method also includes: when the number of light sources included in the current light source cluster of the cell reaches a preset number, determining a characterization value of the degree of influence of the intersecting light sources of the cell on the cell; searching for a first light source to be replaced from the current light source cluster of the cell; the characterization value of the degree of influence of the first light source to be replaced on the cell is less than the characterization value of the degree of influence of the intersecting light source on the cell; removing the found first light source to be replaced from the current light source cluster of the cell, and adding the intersecting light source to the current light source cluster of the cell.

[0080] The influence degree representation value is used to represent the influence degree of the light source on the unit column of the unit cell. The larger the influence degree representation value is, the greater the influence degree of the light is.

[0081] Specifically, the terminal can determine the minimum influence degree characterization value from the influence degree characterization values ​​corresponding to the current light source cluster of the cell. The influence degree characterization values ​​refer to the influence degree characterization values ​​of each light source in the current light source cluster of the cell for the cell. The terminal can compare the influence degree characterization value of the intersecting light source for the cell with the minimum influence degree characterization value. When the influence degree characterization value of the intersecting light source for the cell is greater than the minimum influence degree characterization value, the light source corresponding to the minimum influence degree characterization value is determined as the first light source to be replaced. Fig. 9 As shown, taking the cell in the 2nd row and the 2nd column as an example, light sources L0, L1, L2, L3, and L4 all intersect with the cell. Fig. 9 The table in shows the index of the light source included in the current light source cluster of the cell, the number of light sources, and the contribution score corresponding to the light source, where the contribution score refers to the value representing the degree of influence.

[0082] In some embodiments, the terminal may remove the first light source to be replaced from the current light source cluster of the cell, add the intersecting light source to the current light source cluster of the cell, and return to the step of sequentially determining the intersecting light source of the cell from multiple light sources.

[0083] In some embodiments, when the impact degree characterization value of the intersecting light source on the cell is less than or equal to the minimum impact degree characterization value, the terminal determines that the first light source to be replaced has not been found, and returns to the step of sequentially determining the intersecting light sources of the cell from multiple light sources. Fig.10 As shown, a flowchart of clustering multiple light sources to obtain a target light source cluster is shown. Fig.10 In the above, collecting the light source list refers to determining multiple light sources in the virtual scene, that is, determining multiple light sources to be clustered, and the contribution score refers to the value representing the degree of influence.

[0084] In the present embodiment, since the influence representation value of the first light source to be replaced on the cell is less than the influence representation value of the intersecting light source on the cell, the first light source to be replaced is removed from the current light source cluster of the cell, and the intersecting light source is added to the current light source cluster of the cell. The light sources in the current light source cluster can be updated in the direction of increasing the influence representation value, so that the light sources with larger influence representation values ​​are retained in the target light source cluster of the cell, which is conducive to accurate rendering and improves the rendering effect.

[0085] In some embodiments, determining a characterization value of the degree of influence of the intersecting light sources of a cell on the cell includes: determining a distance quantization value of the intersecting light sources of the cell; the distance quantization value is used to characterize the distance between the intersecting light sources of the cell and the cell; determining a characterization value of the degree of influence of the intersecting light sources of the cell on the cell based on the distance quantization value; the influence characterization value is negatively correlated with the distance quantization value.

[0086] The distance between the light source and the cell can be the distance between the world space position of the light source and the center position of the cell, or the distance between the projection position of the light source and the center position of the cell, and the projection position of the light source refers to the position of the projection of the world space position of the light source on the preset plane. The impact degree representation value is negatively correlated with the distance quantization value.

[0087] In this embodiment, since the distance quantization value represents the distance between the intersecting light source of the cell and the cell, and the distance between the light source and the cell can reflect the degree of illumination influence of the light source on the cell column of the cell, the influence degree characterization value is determined based on the distance quantization value, thereby improving the accuracy of the influence degree characterization value.

[0088] In some embodiments, determining a characterization value of the degree of influence of the intersecting light sources of a cell on the cell based on a distance quantization value includes: determining a property quantization value of the intersecting light sources of the cell; determining the property quantization value based on the property of the intersecting light sources of the cell; and determining a characterization value of the degree of influence of the intersecting light sources of the cell on the cell based on the distance quantization value and the property quantization value.

[0089] Among them, the attributes of the light source include but are not limited to at least one of the brightness or light intensity of the light source. The brightness is calculated by the color of the light source. The attribute quantization value is positively correlated with the brightness and light intensity of the light source. The attribute quantization value can also be related to the attenuation speed of the light source. The faster the attenuation speed of the light source, the smaller the attribute quantization value, and the slower the attenuation speed of the light source, the larger the attribute quantization value. The impact degree representation value is positively correlated with the attribute quantization value.

[0090] Specifically, the terminal may calculate a ratio of the attribute quantization value to the distance quantization value, and determine the ratio as a representation value of the degree of influence of the intersecting light source on the cell.

[0091] In this embodiment, the influence degree characterization value is determined based on the attribute quantization value and the distance quantization value, thereby improving the accuracy of the influence degree characterization value.

[0092] In some embodiments, the number of light sources included in the target light source cluster is less than or equal to a preset number; clustering the multiple light sources in the virtual scene according to each cell in the two-dimensional grid to obtain the target light source clusters corresponding to each cell respectively includes: determining candidate light sources from the multiple light sources in turn, and determining cells from each cell of the two-dimensional grid that have an intersection relationship with the candidate light source on a preset plane; when the number of light sources included in the current light source cluster of the determined cell is less than the preset number, adding the candidate light source to the current light source cluster of the determined cell; returning to the step of determining the candidate light source from the multiple light sources in turn until the multiple light sources are traversed; after traversing the multiple light sources, determining the current light source cluster of each cell in the two-dimensional grid as the target light source cluster of each cell.

[0093] Among them, the candidate light source is any light source among the multiple light sources. In the process of traversing the multiple light sources, different light sources can be used as candidate light sources each time. The cell that has an intersection relationship with the candidate light source on the preset plane refers to the cell that intersects with the projection area of ​​the illumination area of ​​the candidate light source on the preset plane. In the process of traversing the multiple light sources, the current light source cluster of the cell can be constantly changing. Before starting to traverse the multiple light sources, the current light source cluster of the cell may not include any light source, that is, the current light source cluster is initialized as a light source cluster that does not include any light source. In the process of traversing the multiple light sources, light sources are added to the current light source cluster.

[0094] Specifically, when the number of light sources included in the current light source cluster of the determined cell is less than a preset number, the terminal can add the candidate light source to the current light source cluster of the determined cell, and when the number of light sources included in the current light source cluster of the determined cell reaches a preset number, the terminal can stop traversing the multiple light sources, or the terminal can determine the light source to be replaced from the current light source cluster, replace the light source to be replaced in the current light source cluster with the candidate light source, and return to the step of determining the candidate light source from multiple light sources in turn until the multiple light sources are traversed.

[0095] In some embodiments, the clustering method includes at least one of a first clustering method or a second clustering method, the first clustering method is different from the second clustering method, and the first clustering method and the second clustering method are respectively applicable to a situation where there are relatively few light sources or the GPU has relatively strong parallel computing capabilities, and a situation where there are particularly many light sources or the GPU has slightly weak parallel computing capabilities. Before clustering, the terminal can determine the selected clustering method, and the selected clustering method can be automatically selected by the terminal according to the number of light sources or the GPU's parallel computing capabilities, or can be manually selected.

[0096] Among them, when the selected clustering method is the first clustering method, for each cell in the two-dimensional grid, the terminal can determine the intersecting light sources of the cell from multiple light sources in turn. The intersecting light sources of the cell refer to the light sources whose projection areas of the illumination areas on the preset plane intersect with the cell. When the number of light sources included in the current light source cluster of the cell is less than the preset number, the intersecting light sources are added to the current light source cluster of the cell, and the step of determining the intersecting light sources of the cell from multiple light sources in turn is returned until multiple light sources are traversed. When multiple light sources are traversed, the current light source cluster of the cell is determined as the target light source cluster of the cell.

[0097] Among them, when the selected clustering method is the second clustering method, the terminal can determine the candidate light source from multiple light sources in turn, determine the cells that have an intersection relationship with the candidate light source on the preset plane from each cell of the two-dimensional grid, and when the number of light sources included in the current light source cluster of the determined cell is less than the preset number, add the candidate light source to the current light source cluster of the determined cell, and return to the step of determining the candidate light source from multiple light sources in turn until multiple light sources are traversed. After traversing multiple light sources, the current light source cluster of each cell in the two-dimensional grid is determined as the target light source cluster of each cell.

[0098] In this embodiment, by traversing multiple light sources in the virtual scene, the target light source cluster of each cell is quickly determined, thereby improving clustering efficiency.

[0099] In some embodiments, the method also includes: when the number of light sources included in the current light source cluster of the determined cell reaches a preset number, determining a characterization value of the degree of influence of the candidate light source on the determined cell; searching for a second light source to be replaced from the current light source cluster of the determined cell; the characterization value of the degree of influence of the second light source to be replaced on the determined cell is less than the characterization value of the degree of influence of the candidate light source on the determined cell; removing the found second light source to be replaced from the current light source cluster of the determined cell, and adding the candidate light source to the current light source cluster of the determined cell.

[0100] Specifically, the terminal can determine the minimum influence degree characterization value from the influence degree characterization values ​​corresponding to the current light source cluster of the determined cell. The influence degree characterization values ​​refer to the influence degree characterization values ​​of each light source in the current light source cluster of the determined cell for the determined cell. The terminal can compare the influence degree characterization value of the candidate light source for the determined cell with the minimum influence degree characterization value. When the influence degree characterization value of the candidate light source for the determined cell is greater than the minimum influence degree characterization value, the light source corresponding to the minimum influence degree characterization value is determined as the second light source to be replaced found.

[0101] In some embodiments, when the influence degree characterization value of the candidate light source for the determined cell is less than or equal to the minimum influence degree characterization value, the terminal determines that the second light source to be replaced has not been found.

[0102] In the present embodiment, since the influence representation value of the second light source to be replaced on the determined cell is smaller than the influence representation value of the candidate light source on the determined cell, the second light source to be replaced found is removed from the current light source cluster of the determined cell, and the candidate light source is added to the current light source cluster of the determined cell. The light sources in the current light source cluster can be updated in the direction of increasing the influence representation value, so that the light sources with larger influence representation values ​​are retained in the target light source cluster of the cell, which is conducive to accurate rendering and improves the rendering effect.

[0103] In some embodiments, determining a matching light source cluster that has an illumination effect on a pixel point from a plurality of target light source clusters includes: determining a world space position of the pixel point; determining a cell to which a projection position of the world space position of the pixel point on a preset plane belongs, and obtaining a target cell; and determining the target light source cluster corresponding to the target cell as the matching light source cluster that has an illumination effect on the pixel point.

[0104] The area occupied by the target cell on the preset plane includes the projection position of the world space position of the pixel point on the preset plane.

[0105] In this embodiment, the matching light source cluster having illumination influence on the pixel point is accurately determined through the projection position.

[0106] In some embodiments, shadow rendering is performed based on the matching light source clusters of each pixel point, and the shadow rendering result obtained includes: for each pixel point in the screen space, when the matching light source cluster of the pixel point includes a light source participating in the shadow rendering, determining the light source touch information of the light source participating in the shadow rendering for the pixel point; shadow rendering is performed based on the light source touch information of the light source participating in the shadow rendering for the pixel point, to obtain the shadow rendering result.

[0107] There may be one or more light sources participating in shadow rendering. For each light source participating in shadow rendering, shadow rendering may be performed using the method provided in this embodiment. The light source participating in shadow rendering refers to the light source actually to be drawn in the GPU delay pipeline.

[0108] Specifically, the terminal can search for the light source contact information of the light source participating in shadow rendering for the pixel from the cluster contact information of the pixel. The cluster contact information of the pixel includes the light source contact information of each light source in the matching light source cluster of the pixel for the pixel. The cluster contact information of the pixel is generated before shadow rendering.

[0109] In some embodiments, when the light source contact information of the light source participating in shadow rendering for the pixel point is a first preset value, it is determined that the pixel point has a shadow under the light source participating in shadow rendering. When the light source contact information of the light source participating in shadow rendering for the pixel point is a second preset value, it is determined that the pixel point has no shadow under the light source participating in shadow rendering. The light source contact information of the pixel point can also be called the shadow mask of the pixel point. Fig.11 As shown, a flowchart of shadow rendering by reading light source contact information during shadow rendering is shown.

[0110] In this embodiment, shadow rendering can be quickly implemented based on light source reach information, thereby improving shadow rendering efficiency.

[0111] In some embodiments, determining the light source touch information of the light source participating in shadow rendering for the pixel point includes: determining the cluster touch information of the pixel point; the cluster touch information of the pixel point includes the light source touch information of each light source in the matching light source cluster of the pixel point for the pixel point; from the cluster touch information of the pixel point, searching for the light source touch information of the light source participating in shadow rendering for the pixel point.

[0112] Specifically, the cluster reach information of the pixel point is determined before shadow rendering, and the cluster reach information of the pixel point includes the light source reach information of each light source in the matching light source cluster of the pixel point for the pixel point. When shadow rendering is performed, the light source reach information of the light source participating in shadow rendering for the pixel point is obtained from the cluster reach information of the pixel point to perform shadow rendering.

[0113] In this embodiment, the light source contact information of the light source participating in shadow rendering for the pixel point is obtained from the cluster contact information of the pixel point, so that the light source contact information can be obtained quickly, thereby improving the rendering efficiency.

[0114] In some embodiments, determining the cluster touch information of a pixel point includes: determining the light source touch information of each light source in the matching light source cluster of the pixel point for the pixel point; and combining the light source touch information of each light source in the matching light source cluster of the pixel point for the pixel point to form the cluster touch information of the pixel point.

[0115] Specifically, before performing shadow rendering, for each pixel, the terminal may respectively collect the light source reach information of each light source in the matching light source cluster of the pixel for the pixel to form cluster reach information of the pixel.

[0116] In this embodiment, by generating light source reach information before shadow rendering, conditions are provided for rendering and rendering efficiency is improved.

[0117] In some embodiments, Fig.12 As shown, a shadow rendering method is provided, which can be executed by a terminal or jointly by a terminal and a server. The method is applied to a terminal as an example for description, and includes the following steps:

[0118] Step 1202, distributing two-dimensional grids on a preset plane in the world space where the virtual scene is located.

[0119] Step 1204 , clustering the multiple light sources in the virtual scene according to the cells in the two-dimensional grid to obtain target light source clusters corresponding to the cells.

[0120] There is an intersection relationship between the projection area of ​​the illumination area of ​​the light source in the target light source cluster on the preset plane and the corresponding cell.

[0121] Step 1206 : for each pixel point in the screen space, determine a matching light source cluster having an illumination effect on the pixel point from a plurality of target light source clusters.

[0122] Step 1208: for each pixel point in the screen space, determine the direction from the world space position of the pixel point to the world space position of the target light source, and obtain the ray tracing direction.

[0123] Among them, the light source reach information represents whether the target light source generates illumination for the world space position of the pixel point.

[0124] Step 1210, determining the world space position of the pixel point as the starting position of the ray tracing, and determining the ending position of the ray tracing based on the ray tracing direction and the preset tracing distance.

[0125] Step 1212, determine the number of ray tracing steps according to the starting position of the ray tracing and the ending position of the ray tracing, and determine the ray tracing step length based on the preset tracing distance and the number of ray tracing steps.

[0126] The preset tracing distance is the distance between the starting position of the ray tracing and the ending position of the ray tracing.

[0127] Step 1214, starting from the world space position of the pixel point, determine multiple sampling positions along the ray tracing direction.

[0128] The length of the interval between two adjacent sampling positions in the ray tracing direction is the ray tracing step length, and the number of sampling positions is the ray tracing step number.

[0129] Step 1216 : for each sampling position, determine the difference between the depth value of the sampling position and the depth value of the screen space position corresponding to the sampling position, and obtain the depth difference of the sampling position.

[0130] Step 1218, obtaining the light source contact information of the target light source for the pixel point according to the depth difference of each sampling position.

[0131] Step 1220, for each pixel point in the screen space, when the matching light source cluster of the pixel point includes a light source participating in shadow rendering, obtain the light source touch information of the light source participating in shadow rendering for the pixel point from the cluster touch information of the pixel point.

[0132] Step 1222: Perform shadow rendering on the pixel point based on the light source contact information of the light source involved in the shadow rendering to obtain a shadow rendering result.

[0133] In this embodiment, light source reach information is determined based on ray tracing and light sources in the virtual scene are clustered. When there are many light sources in the virtual scene, shadow rendering can be quickly implemented, thereby improving shadow rendering efficiency.

[0134] The shadow rendering method provided in this application can be applied to any scene that needs to render shadows, especially scenes with many light sources, including but not limited to scenes such as film and television special effects, games, mirror simulation, visual design, VR (Virtual Reality), industrial simulation, and digital cultural creation. Through the shadow rendering method of this application, the efficiency of shadow rendering can be improved in scenes such as film and television special effects, visual design, games, mirror simulation, VR, industrial simulation, and digital cultural creation.

[0135] The shadow rendering method provided in the present application is applied to digital cultural creation, and can realize the simulation of things with cultural representative significance, especially things illuminated by more light sources. For example, it can realize the simulation of the Great Wall. There are usually more lights on the Great Wall, and lights are usually installed around the Great Wall. By rendering the shadows produced by more lights, the real lighting effect of the Great Wall under the illumination of more lights can be reflected. Specifically, the terminal can distribute a two-dimensional grid on a preset plane in the world space where the digital Great Wall scene is located, cluster multiple light sources in the digital Great Wall scene according to each cell in the two-dimensional grid, and obtain a target light source cluster corresponding to each cell. For each pixel point in the screen space, a matching light source cluster that has a lighting effect on the pixel point is determined from multiple target light source clusters. For each pixel point in the screen space, the terminal can determine the light source contact information of each light source in the matching light source cluster for the pixel point. When performing shadow rendering, for each pixel point in the screen space, when the matching light source cluster of the pixel point includes the light source participating in the shadow rendering, the light source contact information of the light source participating in the shadow rendering for the pixel point is determined, and shadow rendering is performed based on the light source contact information of the light source participating in the shadow rendering for the pixel point to obtain the shadow rendering result of the digital Great Wall. Therefore, the shadow rendering method provided by the present application not only presents the real lighting effect of the digital Great Wall under the illumination of more lights, but also improves the efficiency of shadow rendering in the digital Great Wall.

[0136] For the game scene, the terminal can determine the target light source corresponding to each pixel point in the screen space from multiple light sources in the game scene. The world space position of the pixel point in the world space where the game scene is located is located in the illumination area of ​​the target light source corresponding to the pixel point. Ray tracing is performed based on the world space position of the target light source and the world space position of the pixel point to obtain the light source contact information of the target light source for the pixel point. The light source contact information indicates whether the target light source generates light for the world space position of the pixel point. Shadow rendering is performed on the game scene based on the light source contact information to obtain the shadow rendering result. This improves the rendering efficiency of shadows in the game scene.

[0137] For optimized rendering of VR scenes, the terminal can determine the target light source corresponding to each pixel point in the screen space from multiple light sources in the VR scene. The world space position of the pixel point in the world space where the VR scene is located is located in the illumination area of ​​the target light source corresponding to the pixel point. Ray tracing is performed based on the world space position of the target light source and the world space position of the pixel point to obtain the light source contact information of the target light source for the pixel point. The light source contact information indicates whether the target light source generates light for the world space position of the pixel point. Shadow rendering is performed on the VR scene based on the light source contact information to obtain the shadow rendering result. This improves the rendering efficiency of shadows in VR scenes.

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

[0139] Based on the same inventive concept, the embodiment of the present application also provides a shadow rendering device for implementing the shadow rendering method involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in one or more shadow rendering device embodiments provided below can refer to the limitations of the shadow rendering method above, and will not be repeated here.

[0140] In some embodiments, Fig.13 As shown, a shadow rendering device is provided, including: a grid distribution module 1302, a light source clustering module 1304, a light source cluster matching module 1306 and a shadow rendering module 1308, wherein:

[0141] The grid distribution module 1302 is used to distribute two-dimensional grids on a preset plane in the world space where the virtual scene is located.

[0142] The light source clustering module 1304 is used to cluster multiple light sources in the virtual scene according to each cell in the two-dimensional grid to obtain a target light source cluster corresponding to each cell; there is an intersection relationship between the projection area of ​​the illumination area of ​​the light source in the target light source cluster on the preset plane and the corresponding cell.

[0143] The light source cluster matching module 1306 is used to determine, for each pixel point in the screen space, a matching light source cluster having an illumination influence on the pixel point from a plurality of target light source clusters.

[0144] The shadow rendering module 1308 is used to perform shadow rendering based on the matching light source cluster of each pixel point to obtain a shadow rendering result.

[0145] In some embodiments, the light source clustering module 1304 is also used to obtain a target light source cluster for each cell in the two-dimensional grid based on the light sources among multiple light sources that have an intersection relationship with the cell; wherein the intersection relationship with the cell means that the projection area of ​​the illumination area on the preset plane intersects with the cell, and the number of light sources in the target light source cluster is less than or equal to the preset number.

[0146] In some embodiments, the light source clustering module 1304 is also used to determine the intersecting light sources of the cell from multiple light sources in sequence; the intersecting light sources of the cell refer to the light sources whose projection areas of the illumination area on the preset plane intersect with the cell; when the number of light sources included in the current light source cluster of the cell is less than the preset number, the intersecting light sources are added to the current light source cluster of the cell; return to the step of determining the intersecting light sources of the cell from multiple light sources in sequence until multiple light sources are traversed; when multiple light sources are traversed, the current light source cluster of the cell is determined as the target light source cluster of the cell.

[0147] In some embodiments, the light source clustering module 1304 is further used to determine a characterization value of the degree of influence of the intersecting light sources of the cell on the cell when the number of light sources included in the current light source cluster of the cell reaches a preset number; search for a first light source to be replaced from the current light source cluster of the cell; the characterization value of the degree of influence of the first light source to be replaced on the cell is less than the characterization value of the degree of influence of the intersecting light source on the cell; remove the found first light source to be replaced from the current light source cluster of the cell, and add the intersecting light source to the current light source cluster of the cell.

[0148] In some embodiments, the light source clustering module 1304 is further used to determine the distance quantification value of the intersecting light sources of the cell; the distance quantification value is used to characterize the distance between the intersecting light sources of the cell and the cell; based on the distance quantification value, the influence degree characterization value of the intersecting light sources of the cell on the cell is determined; the influence degree characterization value is negatively correlated with the distance quantification value.

[0149] In some embodiments, the light source clustering module 1304 is further used to determine the attribute quantization value of the intersecting light sources of the cell; the attribute quantization value is determined based on the attribute of the intersecting light sources of the cell; based on the distance quantization value and the attribute quantization value, determine the influence characterization value of the intersecting light sources of the cell on the cell.

[0150] In some embodiments, the number of light sources included in the target light source cluster is less than or equal to a preset number; the light source clustering module 1304 is further used to determine candidate light sources from the multiple light sources in sequence, and determine cells that have an intersection relationship with the candidate light sources on a preset plane from each cell of the two-dimensional grid; when the number of light sources included in the current light source cluster of the determined cell is less than the preset number, the candidate light source is added to the current light source cluster of the determined cell; return to the step of determining candidate light sources from the multiple light sources in sequence until the multiple light sources are traversed; after traversing the multiple light sources, the current light source cluster of each cell in the two-dimensional grid is respectively determined as the target light source cluster of each cell.

[0151] In some embodiments, the light source clustering module 1304 is further used to determine a characterization value of the degree of influence of a candidate light source on a determined cell when the number of light sources included in the current light source cluster of the determined cell reaches a preset number; search for a second light source to be replaced from the current light source cluster of the determined cell; the characterization value of the degree of influence of the second light source to be replaced on the determined cell is less than the characterization value of the degree of influence of the candidate light source on the determined cell; remove the found second light source to be replaced from the current light source cluster of the determined cell, and add the candidate light source to the current light source cluster of the determined cell.

[0152] In some embodiments, the light source cluster matching module 1306 is also used to determine the world space position of the pixel point; determine the cell to which the projection position of the world space position of the pixel point on the preset plane belongs, and obtain the target cell; and determine the target light source cluster corresponding to the target cell as the matching light source cluster that has an illumination effect on the pixel point.

[0153] In some embodiments, the shadow rendering module 1308 is also used to determine, for each pixel point in the screen space, the light source contact information of the light source participating in the shadow rendering for the pixel point, when the matching light source cluster of the pixel point includes the light source participating in the shadow rendering; shadow rendering is performed based on the light source contact information of the light source participating in the shadow rendering for the pixel point to obtain a shadow rendering result.

[0154] In some embodiments, the shadow rendering module 1308 is also used to determine the cluster touch information of the pixel point; the cluster touch information of the pixel point includes the light source touch information of each light source in the matching light source cluster of the pixel point for the pixel point; from the cluster touch information of the pixel point, the light source touch information of the light source participating in the shadow rendering for the pixel point is found.

[0155] In some embodiments, the shadow rendering module 1308 is also used to determine the light source reach information of each light source in the matching light source cluster of the pixel point for the pixel point; and the light source reach information of each light source in the matching light source cluster of the pixel point for the pixel point is combined into cluster reach information of the pixel point.

[0156] Each module in the above shadow rendering device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.

[0157] In some embodiments, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Fig.14 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data involved in the shadow rendering method. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a shadow rendering method is implemented.

[0158] In some embodiments, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Fig.15As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface, the display unit and the input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a shadow rendering method is implemented. The display unit of the computer device is used to form a visually visible image, and can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer covered on the display screen, or a button, trackball or touchpad set on the computer device casing, or an external keyboard, touchpad or mouse, etc.

[0159] Those skilled in the art will understand that Fig.14 and Fig.15 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0160] In some embodiments, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned shadow rendering method when executing the computer program.

[0161] In some embodiments, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned shadow rendering method are implemented.

[0162] In some embodiments, a computer program product is provided, including a computer program, which implements the steps in the above shadow rendering method when executed by a processor.

[0163] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.

[0164] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0165] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0166] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A shadow rendering method, characterized in that: The method comprises: Distributing a two-dimensional grid on a preset plane in the world space where the virtual scene is located; Clustering the multiple light sources in the virtual scene according to the cells in the two-dimensional grid to obtain target light source clusters corresponding to the cells; an illumination area of ​​the light source in the target light source cluster has an intersection relationship with a projection area on the preset plane and the corresponding cell; For each pixel point in the screen space, determining a matching light source cluster having an illumination influence on the pixel point from the multiple target light source clusters; Shadow rendering is performed based on the matching light source clusters of each pixel point to obtain a shadow rendering result.

2. The method according to claim 1, characterized in that The clustering of the multiple light sources in the virtual scene according to each cell in the two-dimensional grid to obtain the target light source clusters corresponding to each cell includes: For each cell in the two-dimensional grid, based on light sources among the multiple light sources that have an intersection relationship with the cell, a target light source cluster of the cell is obtained; The existence of an intersection relationship with the cell means that a projection area of ​​the illumination area on the preset plane intersects with the cell, and the number of light sources in the target light source cluster is less than or equal to a preset number.

3. The method according to claim 2, characterized in that The obtaining of the target light source cluster of the cell based on the light sources intersecting with the cell among the plurality of light sources comprises: Determining the intersecting light sources of the cell from the multiple light sources in sequence; the intersecting light sources of the cell refer to the light sources whose projection areas of the illumination areas on the preset plane intersect with the cell; When the number of light sources included in the current light source cluster of the cell is less than the preset number, adding the intersecting light source to the current light source cluster of the cell; Returning to the step of sequentially determining the intersecting light sources of the cell from the multiple light sources until the multiple light sources are traversed; In the case of traversing the multiple light sources, the current light source cluster of the cell is determined as the target light source cluster of the cell.

4. The method according to claim 3, characterized in that The method further comprises: When the number of light sources included in the current light source cluster of the cell reaches the preset number, determining a representative value of the degree of influence of the intersecting light sources of the cell on the cell; Searching for a first light source to be replaced from the current light source cluster of the cell; a representation value of the degree of influence of the first light source to be replaced on the cell is smaller than a representation value of the degree of influence of the intersecting light source on the cell; The first light source to be replaced that is found is removed from the current light source cluster of the cell, and the intersecting light source is added to the current light source cluster of the cell.

5. The method according to claim 4, characterized in that The determining of the influence degree characterization value of the intersecting light source of the cell on the cell comprises: Determine a distance quantization value of the intersecting light source of the cell; the distance quantization value is used to characterize the distance between the intersecting light source of the cell and the cell; Based on the distance quantization value, a characterization value of the degree of influence of the intersecting light source of the cell on the cell is determined; the characterization value of the degree of influence is negatively correlated with the distance quantization value.

6. The method according to claim 5, characterized in that The determining, based on the distance quantization value, a characterization value of the degree of influence of the intersecting light source of the cell on the cell comprises: Determine a quantitative value of an attribute of the intersecting light sources of the cell; the quantitative value of the attribute is determined based on the attribute of the intersecting light sources of the cell; Based on the distance quantization value and the attribute quantization value, a characterization value of the degree of influence of the intersecting light source of the cell on the cell is determined.

7. The method according to claim 1, characterized in that The number of light sources included in the target light source cluster is less than or equal to a preset number; The clustering of the multiple light sources in the virtual scene according to each cell in the two-dimensional grid to obtain the target light source clusters corresponding to each cell includes: Determine candidate light sources from the multiple light sources in sequence, and determine cells from the cells of the two-dimensional grid that intersect with the candidate light sources on a preset plane; When the number of light sources included in the determined current light source cluster of the cell is less than the preset number, adding the candidate light source to the determined current light source cluster of the cell; Returning to the step of sequentially determining candidate light sources from the multiple light sources until the multiple light sources are traversed; After traversing the plurality of light sources, the current light source cluster of each cell in the two-dimensional grid is respectively determined as the target light source cluster of each cell.

8. The method according to claim 7, characterized in that The method further comprises: When the number of light sources included in the current light source cluster of the determined cell reaches the preset number, determining a representative value of the degree of influence of the candidate light source on the determined cell; Searching for a second light source to be replaced from the current light source cluster of the determined cell; the influence degree representation value of the second light source to be replaced on the determined cell is smaller than the influence degree representation value of the candidate light source on the determined cell; The found second light source to be replaced is removed from the current light source cluster of the determined cell, and the candidate light source is added to the current light source cluster of the determined cell.

9. The method according to claim 1, characterized in that: The step of determining a matching light source cluster having an illumination influence on the pixel point from the multiple target light source clusters comprises: Determining a world space position of the pixel; Determine the cell to which the projection position of the world space position of the pixel point on the preset plane belongs, and obtain the target cell; The target light source cluster corresponding to the target cell is determined as a matching light source cluster having an illumination influence on the pixel point.

10. The method according to any one of claims 1 to 9, characterized in that: The shadow rendering is performed based on the matching light source cluster of each pixel point to obtain the shadow rendering result, which includes: For each pixel point in the screen space, when the matching light source cluster of the pixel point includes a light source participating in shadow rendering, determining light source reach information of the light source participating in shadow rendering for the pixel point; Shadow rendering is performed based on the light source contact information of the pixel point of the light source participating in the shadow rendering to obtain a shadow rendering result.

11. The method according to claim 10, characterized in that The determining of the light source contact information of the light source participating in the shadow rendering for the pixel point includes: Determine cluster reach information of the pixel point; the cluster reach information of the pixel point includes light source reach information of each light source in the matching light source cluster of the pixel point for the pixel point; From the cluster reach information of the pixel point, search for the light source reach information of the light source participating in the shadow rendering for the pixel point.

12. The method according to claim 11, characterized in that The determining of the cluster reach information of the pixel point comprises: Determine light source reach information of each light source in a matching light source cluster of the pixel point for the pixel point; The light source reach information of each light source in the matching light source cluster of the pixel point is respectively directed to the pixel point to form the cluster reach information of the pixel point.

13. A shadow rendering device, characterized in that: The device comprises: A grid distribution module, used to distribute two-dimensional grids on a preset plane in the world space where the virtual scene is located; A light source clustering module, used for clustering a plurality of light sources in the virtual scene according to each cell in the two-dimensional grid, to obtain a target light source cluster corresponding to each cell; an illumination area of ​​the light source in the target light source cluster has an intersection relationship between a projection area on the preset plane and the corresponding cell; A light source cluster matching module, configured to determine, for each pixel point in the screen space, a matching light source cluster having an illumination influence on the pixel point from the multiple target light source clusters; The shadow rendering module is used to perform shadow rendering based on the matching light source cluster of each pixel point to obtain a shadow rendering result.

14. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 12 are implemented.

15. 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 method according to any one of claims 1 to 12 are implemented.

16. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 12 are implemented.

Citation Information

Cited By

  • Shadow rendering method and apparatus, computer device, and storage medium

    EP4679378A1