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

By setting up a two-dimensional network and light source clusters in the virtual scene, the target light source cluster is determined for each pixel for rendering, which solves the problem of high computational complexity of the traditional shadow map rendering method in complex scenes, and improves the shadow rendering efficiency and Realism.

WO2024183489A9PCT designated stage expired Publication Date: 2024-10-17TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/073598
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-03-08
Filing Date
2024-01-23
Publication Date
2024-10-17

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

By setting up a two-dimensional network in the world space of the virtual scene, using the two-dimensional grid to cluster the light sources to obtain light source clusters, and determining the target light source cluster for each pixel, the virtual scene is rendered based on the target light source cluster.

Benefits of technology

The efficiency of shadow rendering is improved, especially in complex scenes and multiple light sources, real-time rendering can be achieved, and the layering and realism of the rendering results are enhanced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024073598_17102024_PF_FP_ABST
    Figure CN2024073598_17102024_PF_FP_ABST
Patent Text Reader

Abstract

A shadow rendering method, executed by a computer device. The method comprises: setting a two-dimensional grid on a preset plane in a world space where a virtual scene is located (202); according to cells in the two-dimensional grid, clustering a plurality of light sources in the virtual scene to obtain light source clusters respectively corresponding to the cells, wherein projection areas of illumination spaces irradiated by the light sources in the light source clusters on the preset plane intersect with the cells corresponding to the light source clusters (204); for pixel points in a screen space, determining target light source clusters among the plurality of light source clusters, wherein the illumination of the target light source clusters is related to the pixel values of the pixel points (206); and rendering a shadow of the virtual scene on the basis of the respective target light source clusters of the pixel points to obtain a shadow rendering result (208).
Need to check novelty before this filing date? Find Prior Art

Description

Shadow rendering method, device, computer equipment and storage medium

[0001] Related applications

[0002] This application claims priority to Chinese patent application number 2023102480229, filed on March 8, 2023, entitled “Shadow rendering method, device, computer device and storage medium,” the entire text of which is hereby incorporated by reference. Technical Field

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

[0004] 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.

[0005] Traditionally, shadow maps are used to render shadows. The computational complexity of shadow map-based rendering methods is closely related to the complexity of the scene being rendered. The more complex the scene, the higher the performance requirements.

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

[0007] Summary of the Invention

[0008] According to various embodiments provided in the present application, a shadow rendering method, apparatus, computer device, computer-readable storage medium, and computer program product are provided that can improve shadow rendering efficiency.

[0009] In one aspect, the present application provides a shadow rendering method. The method comprises:

[0010] Setting up a two-dimensional network on a preset plane in the world space where the virtual scene is located;

[0011] Clustering the plurality of light sources in the virtual scene according to each cell in the two-dimensional grid to obtain a light source cluster corresponding to each cell, wherein a projection area of ​​the illumination space illuminated by the light sources in the light source cluster on the preset plane intersects with the corresponding cell;

[0012] For each pixel point in the screen space, determining a target light source cluster from the multiple light source clusters, where illumination of the target light source cluster is related to a pixel value of the pixel point; and

[0013] The shadow of the virtual scene is rendered based on the target light source cluster of each pixel point to obtain a shadow rendering result.

[0014] On the other hand, the present application also provides a shadow rendering device. The device includes:

[0015] A grid distribution module is used to set up a two-dimensional network on a preset plane in the world space where the virtual scene is located;

[0016] a light source clustering module, configured to cluster the plurality of light sources in the virtual scene according to each cell in the two-dimensional grid, to obtain a light source cluster corresponding to each cell, wherein the projection area of ​​the illumination space illuminated by the light sources in the light source cluster on the preset plane intersects with the corresponding cell;

[0017] a light source cluster matching module, configured to determine, for each pixel point in the screen space, a target light source cluster from the multiple light source clusters, wherein the illumination of the target light source cluster is related to the pixel value of the pixel point;

[0018] The shadow rendering module is used to render the shadow of the virtual scene based on the target light source cluster of each pixel point to obtain a shadow rendering result.

[0019] In another aspect, the present application further provides a computer device comprising a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the above-mentioned shadow rendering method when executing the computer-readable instructions.

[0020] In another aspect, the present application further provides a computer-readable storage medium having computer-readable instructions stored thereon, which implement the above-mentioned shadow rendering method when executed by a processor.

[0021] In another aspect, the present application further provides a computer program product, comprising computer-readable instructions, which implement the above-mentioned shadow rendering method when executed by a processor.

[0022] Details of one or more embodiments of the present application are set forth in the following drawings and description. Other features, objects, and advantages of the present application will become apparent from the description, drawings, and claims. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the conventional technology, the following briefly introduces the drawings required for use in the embodiments or the conventional technology descriptions. Obviously, the drawings described below are merely embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the disclosed drawings without any creative work.

[0024] FIG1 is a diagram illustrating an application environment of a shadow rendering method in some embodiments;

[0025] FIG2 is a schematic diagram of a flow chart of a shadow rendering method in some embodiments;

[0026] FIG3 is a schematic diagram of a two-dimensional grid in some embodiments;

[0027] FIG4 is a schematic diagram of the intersection of a projection area and a cell in some embodiments;

[0028] FIG5 is a schematic diagram of a bit string stored in a screen pixel shadow mask buffer in some embodiments;

[0029] FIG6 is a flow chart illustrating some embodiments of storing light source reach information via a bit string;

[0030] FIG7 is a real-time rendering image obtained without rendering shadows in some embodiments;

[0031] FIG8 is a real-time rendering image obtained by rendering shadows in some embodiments;

[0032] FIG9 is a schematic diagram of light source clusters corresponding to cells in some embodiments;

[0033] FIG10 is a flow chart of clustering multiple light sources to obtain light source clusters in some embodiments;

[0034] FIG11 is a flowchart of shadow rendering by reading light source reach information in some embodiments;

[0035] FIG12 is a schematic flow chart of a shadow rendering method in some embodiments;

[0036] FIG13 is a block diagram of a shadow rendering apparatus in some embodiments;

[0037] FIG14 is a diagram illustrating the internal structure of a computer device in some embodiments;

[0038] FIG15 is a diagram illustrating the internal structure of a computer device in some embodiments. DETAILED DESCRIPTION

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

[0040] The shadow rendering method provided in the embodiments of the present application can be applied in the application environment shown in FIG1 . In this embodiment, terminal 102 communicates with server 104 via a network. A data storage system can store data that server 104 needs to process. The data storage system can be integrated with server 104 or placed in the cloud or on another server.

[0041] Specifically, the terminal 102 can obtain a virtual scene from the server 104. The terminal 102 can set up a two-dimensional network on a preset plane in the world space where the virtual scene is located, and use each cell in the two-dimensional grid to cluster multiple light sources in the virtual scene to obtain a light source cluster corresponding to each cell. The projection area of ​​the illumination space illuminated by the light source in the light source cluster on the preset plane intersects with the corresponding cell. For each pixel point in the screen space, a target light source cluster is determined from the multiple light source clusters. The illumination of the target light source cluster is related to the pixel value of the pixel point. The shadow of the virtual scene is rendered based on the target 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.

[0042] Among them, the terminal 102 can be, but is not limited to, various desktop computers, laptops, smart phones, tablets, 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. It can also be 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, as well as 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 through wired or wireless communication, and this application does not impose any restrictions on this.

[0043] In some embodiments, as shown in FIG2 , a shadow rendering method is provided. The method may be executed by a terminal or a server, or may be executed jointly by the terminal and the server. The method is described by taking the application of the method to the terminal 102 in FIG1 as an example, and includes the following steps:

[0044] Step 202: Setting a two-dimensional network on a preset plane in the world space where the virtual scene is located.

[0045] Among them, 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, or 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. Among them, the 2.5-dimensional virtual scene includes a width dimension, a length dimension and a depth dimension, and the depth dimension only expresses part of the depth information in the virtual scene, and cannot fully express the spatial shape in the 2.5-dimensional virtual scene. The three-dimensional virtual scene includes a width dimension, a length dimension and a depth dimension, and the depth dimension can express the complete depth information in the virtual scene, and can fully express the spatial shape in the three-dimensional virtual scene.

[0046] World space refers to the three-dimensional space in which the virtual scene resides. The size of the world space can be customized. For example, the world space can be 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 within the world space.

[0047] The preset plane can be set as needed. For example, if the virtual scene includes the ground, which can also be called the horizontal plane, the preset plane can be a plane parallel to the horizontal plane, or 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, from 0 to 90 degrees, and the size of the preset angle is not limited.

[0048] The two-dimensional grid has a certain size and shape. The size and shape of the two-dimensional grid can be pre-set 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 multiple cells. The shape of the cell includes but is not limited to at least one of a rectangle or a triangle. The size of each cell in the two-dimensional grid can be the same or different. As shown in Figure 3, a schematic diagram of a two-dimensional grid is shown. The two-dimensional grid in Figure 3 has a total of 16 cells. The position of the 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.

[0049] Specifically, the terminal can set up a two-dimensional grid on a preset plane in the world space where the virtual scene is located. 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 light source cluster obtained by clustering the two-dimensional grid can cover the light sources participating in the real-time rendering. A light cluster is a collection of light sources.

[0050] In step 204 , multiple light sources in the virtual scene are clustered using each cell in the two-dimensional grid to obtain a light source cluster corresponding to each cell. The projection area of ​​the illumination space illuminated by the light sources in the light source cluster on the preset plane intersects with the cell corresponding to the light source cluster.

[0051] A light source refers to an object that can emit its own light and is currently emitting light, such as the sun, electric lights, or burning substances. A light source in a virtual scene is a set of lighting data that realistically simulates the lighting effects of a real-world light source. The illuminated space illuminated by a light source refers to the area that the light source can illuminate. This illuminated space can be either spherical or conical. If the illuminated space is spherical, it can be referred to as the light source's range sphere.

[0052] 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 in the virtual scene whose projection area intersects with the two-dimensional grid. The projection area of ​​the light source refers to the projection area of ​​the illuminated space illuminated by the light source on the preset plane.

[0053] The intersection of a cell and a projected area means that the cell and the projected area intersect, that is, the cell and the projected area intersect. Specifically, the intersection of a cell and a projected area can be: the intersection of the cell and the projected area is a portion of the cell and the projected area respectively; or, when the cell is within the projected area, the intersection of the cell and the projected area is the cell; or, when the projected area is within the cell, the intersection of the cell and the projected area is the projected area. That is, in some embodiments, if a cell is within a projected area, or a projected area is within a cell, then the cell and the projected area also intersect.

[0054] The multiple light sources in the virtual scene can be stored in a GPU (graphics processing unit) buffer, and the two-dimensional grid can also be stored in the GPU. A light source cluster refers to a collection of light sources, which is obtained by clustering multiple light sources in the virtual scene.

[0055] When using cells in a two-dimensional grid to cluster multiple light sources in a virtual scene, each cell can be processed individually. That is, for each cell, it is determined whether the projection area of ​​the illumination space illuminated by the light sources in the light source cluster on the preset plane intersects with the cell. If so, the intersecting light source is added to the light source cluster corresponding to the cell.

[0056] Specifically, the terminal can determine the projection areas of the illumination spaces illuminated by the multiple light sources on the preset plane, and for each cell in the two-dimensional grid, obtain the 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 light source cluster corresponding to the cell. As shown in Figure 4, a schematic diagram of the intersection of the projection area of ​​the light source and the cells in the two-dimensional grid is shown. In 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. The center point of the circle is the projection position of the world space position of the light source on the preset plane. L0-L5 represent 5 light sources. The number following L can be called the index of the light source, and the number after the colon represents the brightness. For example, 100 in L4:100 represents brightness.

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

[0058] Step 206 : For each pixel point in the screen space, determine a target light source cluster from the multiple light source clusters, where the illumination of the target light source cluster is related to the pixel value of the pixel point.

[0059] Among them, 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 light source cluster whose illumination is related to the pixel value of the pixel point can be called the target light source cluster of the pixel point. The target light source cluster of the pixel point can include the target light source corresponding to the pixel point. The target light source corresponding to the pixel point refers to the light source whose illumination space includes the world space position of the pixel point. Each cell has a corresponding light source cluster. A plurality of cells are divided in the two-dimensional grid, and a plurality of cells correspond to a plurality of light source clusters. The target light source cluster whose illumination is related to the pixel value of the pixel point means that the illumination of the light source of the target light source cluster has an impact on the pixel value of the pixel point. In some specific embodiments, whether the light source in the target light source cluster is irradiated or the intensity of the illumination can cause the pixel value of the pixel point to change.

[0060] 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 light source cluster corresponding to the target cell as the target light source cluster whose illumination is related to the pixel value of the pixel point.

[0061] Step 208 : Render the shadow of the virtual scene based on the target light source cluster of each pixel point to obtain a shadow rendering result.

[0062] Shadows are formed when light from a light source in a virtual scene is blocked. Rendering shadows, also known as shadow rendering, is the process of visually presenting shadows. When rendering shadows in a virtual scene based on the target light source cluster for each pixel, the position of the shadow in the virtual scene can be determined for each pixel based on the scene layout in the virtual scene and the position of the light source in the target light source cluster for that pixel. The effect of the light from the target light source cluster on the pixel value of that pixel can then be determined, i.e., the contribution to the pixel value of that pixel. The pixel value of that pixel in the shadow can then be calculated based on the light from the target light source cluster. The pixel value of that pixel can then be rendered to obtain the shadow rendering result.

[0063] 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 target 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 and 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.

[0064] In some embodiments, for any light source in the target light source cluster of a pixel point, when the illumination space illuminated by 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 Space Ray Tracing) and screen space shadow (Screen Space Shadow) algorithms. Among them, screen space ray tracing refers to a commonly used 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 will produce a shadow under the light source by performing screen space ray tracing between the pixel to be drawn and the light source.

[0065] In some embodiments, for any light source in the target light source cluster for a pixel, the terminal can calculate the distance between the light source and the observation position. If the distance between the light source and the observation position is greater than a distance threshold, the terminal determines the light source's light source contact information for the pixel. 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.

[0066] In some embodiments, the terminal can 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 point. Specifically, the terminal can determine the world space position of the pixel point as the starting position of ray tracing, determine the direction from the world space position of the pixel point 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 point to the world space position of the target light source. The ray tracing direction can be represented by a direction vector. The direction vector points from the world space position of the pixel point to the world space position of the target light source and is a unit vector.

[0067] In some embodiments, the terminal can 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, and use the result of the addition as the end position. For example, if the preset tracking distance is L, the direction vector is (x1, y1, z1), and the world space position of the pixel is (x2, y2, z2), then the end position = (x2, y2, z2) + L*(x1, y1, z1).

[0068] In some embodiments, the terminal may determine the number of ray tracing steps based on 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 converted starting position, and convert the ending position of the ray tracing to the target two-dimensional space to obtain the converted ending position. 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 it is converted 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 it is converted to the texture space, and use the determined position as the converted ending position. 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 it is converted to the screen space, and use the determined position as the converted starting position, and determine the position corresponding to the ending position of the ray tracing after it is converted to the screen space, and use the determined position as the converted ending position.

[0069] 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 starting position after the conversion and the ending position after the conversion 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 starting position after the conversion and the ending position after the conversion, and determine the calculated distance as the tracing step factor. The terminal can calculate the product of the tracing step factor and the maximum tracing step, and use the result of the product as the candidate tracing step. If the candidate tracing step is less than the minimum tracing step, the minimum tracing step is used as the ray tracing step. If the candidate tracing step is greater than the maximum tracing step, the maximum tracing step is used as the ray tracing step. If the candidate tracing step is greater than or equal to the minimum tracing step and the candidate tracing step is less than or equal to the minimum tracing step, the candidate tracing step is used as the ray tracing step. Since 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, and the larger the occupied screen area, the closer the distance between the camera and the pixel point and the light source is, and conversely, the farther the distance between the camera and the pixel point and the light source is, the ray tracing step is positively correlated with the tracing step factor, so that the closer the pixel point and the light source are to the camera, the more ray tracing steps are, and conversely, the fewer ray tracing steps are, thereby making ray tracing more reasonable and improving the efficiency of ray tracing.

[0070] In some embodiments, the terminal may perform ray tracing according to the number of ray tracing steps to obtain light source contact information of the target light source for the pixel point. Specifically, the terminal may determine the ray tracing step length based on the preset tracing distance and the number of ray tracing steps. For example, the terminal may 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 may determine a plurality of sampling positions along the ray tracing direction starting 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 the plurality of sampling positions refers to 6 sampling positions. For each sampling position, the terminal may 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 to 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.

[0071] 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, and 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.

[0072] In some embodiments, when the depth difference at any sampling position is less than or equal to the depth difference threshold, the light source contact 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 contact information of the target light source for the pixel point is determined to be a second preset value.

[0073] In some embodiments, for any light source in the target light source cluster of a pixel point, when the illumination space illuminated by 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.

[0074] In some embodiments, before performing shadow rendering, the terminal may combine the light source contact information of each light source in the target 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 the shadow of the virtual scene is rendered based on the light source contact information of the light source participating in the shadow rendering with respect to the pixel point to obtain a 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, graphics processor) delay pipeline.

[0075] In some embodiments, for each pixel in the screen space, the terminal can generate a corresponding bit string for the pixel. A bit string is a character string that only includes at least one of 0 or 1. A bit string can also be called a bit sequence, which is a sequence of 0 or 1 in order. 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 use the form of a bit string to store the cluster touch information of the pixel point. For example, different bits in the bit string represent different light source touch information in the cluster touch information.

[0076] Before determining the light source contact information, the terminal can generate a bit string of pixel points and initialize the characters of each bit in the bit string to a second preset value, for example, to 0. When it is determined that the light source contact information of the light source for the pixel point is the first preset value, the bit corresponding to the light source in the bit string is updated to the first preset value, for example, to 1. When it is determined that the light source contact information of the light source for the pixel point is the second preset value, the bit string is kept unchanged.

[0077] 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 this buffer. When performing shadow rendering, the terminal can read the light source contact information for the pixel from this buffer. As shown in Figure 5, 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 in the screen pixel shadow mask buffer can be 1920×1080, and each storage block stores the bit string of a pixel. Figure 5 shows the bit string stored in a storage block in the screen pixel shadow mask buffer. As shown in Figure 6, a flowchart for storing light source contact information through bit strings is shown.

[0078] In the above-mentioned shadow rendering method, a two-dimensional grid is set up on a preset plane in the world space where the virtual scene is located. The multiple light sources in the virtual scene are clustered using each cell in the two-dimensional grid to obtain a light source cluster corresponding to each cell. The projection area of ​​the illumination space illuminated by the light sources in the light source cluster on the preset plane intersects with the corresponding cell. For each pixel in the screen space, a target light source cluster is determined from the multiple light source clusters. The illumination of the target light source cluster is related to the pixel value of the pixel. The shadow of the virtual scene is rendered based on the target light source cluster of each pixel to obtain a shadow rendering result. Because the light sources are clustered and the shadow of the virtual scene is rendered based on the target light source cluster of the pixel, shadow rendering can be quickly achieved when there are many light sources in the virtual scene, thereby improving shadow rendering efficiency.

[0079] The shadow rendering method provided in the present application can be applied to real-time rendering to add a stronger sense of layering and realism to the rendered picture through shadows. As shown in FIG7 , a real-time rendering picture obtained without rendering the shadows is shown. As shown in FIG8 , a real-time rendering picture obtained after rendering the shadows is shown. Obviously, compared with FIG7 , the real-time rendering picture of FIG8 has a stronger sense of layering and realism. Real-time rendering of more light sources requires the cooperation of real-time rendering of shadows of more light sources to achieve realistic real-time rendering under more light sources. The shadow rendering method provided in the present application can make the performance of rendering of more light sources independent of the scene scale and the number of light sources, thereby improving the rendering efficiency of more light sources in scenes with more light sources, so that the rendering of shadows of more light sources can achieve real-time performance.

[0080] In some embodiments, multiple light sources in a virtual scene are clustered using each cell in a two-dimensional grid to obtain a light source cluster corresponding to each cell, including: for each cell in the two-dimensional grid, based on the light sources among the multiple light sources that intersect with the cell, obtaining a light source cluster for the cell; wherein, intersecting with the cell means that the projection area of ​​the illumination space on a preset plane intersects with the cell, and the number of light sources in the light source cluster is less than or equal to a preset number.

[0081] The preset number can be set as needed, for example, 20 or 50. When the projection area of ​​the illumination space illuminated by the light source on the preset plane intersects with a cell, it is considered that the light source intersects with the cell.

[0082] Specifically, for each cell, the terminal can determine the intersecting light sources of the cell from multiple light sources. The intersecting light sources of a cell refer to the light sources where the projection area of ​​the illumination space on a preset plane intersects with the cell. The number of intersecting light sources of a cell can be one or more, and multiple means at least two. If the number of intersecting light sources of the cell is less than or equal to the preset number, the terminal can group the individual intersecting light sources of the unit into a light source cluster corresponding to the cell.

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

[0084] In some embodiments, obtaining a light source cluster for a cell based on light sources intersecting with the cell from among multiple light sources includes: sequentially determining the intersecting light sources for the cell from among the multiple light sources; the intersecting light sources for the cell refer to light sources whose projection area of ​​the illumination space on a preset plane intersects with the cell; if the number of light sources included in the current light source cluster of the cell is less than a preset number, adding the intersecting light sources to the current light source cluster of the cell; returning to the step of sequentially determining the intersecting light sources for the cell from among the multiple light sources until the multiple light sources are traversed; if the multiple light sources are traversed, determining the current light source cluster for the cell as the light source cluster for the cell. The terminal may initialize the light source cluster for each cell, wherein the initialized light source cluster contains no light sources and can accommodate at most the preset number of light sources. For example, an empty list of a fixed length may be initialized as the initialized light source cluster, and the fixed length empty list can record at most the preset number of light sources. It should be noted that recording light sources in the light source cluster refers to recording the identifiers of the light sources. The current light source cluster is initially the initialized light source cluster, and light sources may be added to the current light source cluster as the multiple light sources are traversed.

[0085] Specifically, for each cell in a two-dimensional grid, the method of this embodiment can be used to determine the light source cluster. When the number of light sources included in the current light source cluster of a cell is less than a preset number, the terminal can add the intersecting light source to the current light source cluster of the cell; when the number of light sources included in the current light source cluster of a 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 sequentially determining the intersecting light source of the cell from multiple light sources until multiple light sources are traversed; when multiple light sources are traversed, the current light source cluster of the cell is determined as the light source cluster of the cell.

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

[0087] In some embodiments, the shadow rendering 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 source 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.

[0088] The influence degree representation value is used to represent the degree of influence of the light source on the unit column of the unit cell. The larger the influence degree representation value is, the greater the correlation between the light and the pixel value of the pixel point is.

[0089] Specifically, the terminal can determine the minimum influence degree representation value from the various influence degree representation values ​​corresponding to the current light source cluster of the cell. The various influence degree representation values ​​refer to the influence degree representation values ​​of the various light sources in the current light source cluster of the cell for the cell. The terminal can compare the influence degree representation value of the intersecting light source for the cell with the minimum influence degree representation value. When the influence degree representation value of the intersecting light source for the cell is greater than the minimum influence degree representation value, the light source corresponding to the minimum influence degree representation value is determined as the first light source to be replaced found. As shown in Figure 9, taking the cell in the second row and the second column as an example, light sources L0, L1, L2, L3, and L4 all intersect with the cell. The table in Figure 9 shows the index of the light sources included in the current light source cluster of the cell, the number of light sources, and the contribution points corresponding to the light sources. The contribution points refer to the influence degree representation values.

[0090] 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.

[0091] In some embodiments, if the influence representation value of the intersecting light source for the cell is less than or equal to the minimum influence representation 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 source for the cell from multiple light sources. As shown in Figure 10, a flowchart for clustering multiple light sources to obtain a light source cluster is shown. In Figure 10, collecting a 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 influence representation value.

[0092] In this 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 light source cluster of the cell, which is conducive to accurate rendering and improves the rendering effect.

[0093] In some embodiments, determining a value representing the degree of influence of an intersecting light source of a cell on the cell includes: determining a distance quantization value of the intersecting light source of the cell; the distance quantization value is used to represent the distance between the intersecting light source of the cell and the cell; determining a value representing the degree of influence of the intersecting light source of the cell on the cell based on the distance quantization value; and the degree of influence representation value and the distance quantization value are negatively correlated. The negative correlation between the degree of influence representation value and the distance quantization value means that a larger degree of influence representation value corresponds to a smaller distance quantization value, and a smaller degree of influence representation value corresponds to a larger distance quantization value.

[0094] The distance between a light source and a cell can be the distance between the light source's world-space position and the cell's center, or the distance between the light source's projected position and the cell's center. The projected position of the light source refers to the position of the projection of the light source's world-space position onto the preset plane. The impact representation value is negatively correlated with the distance quantization value.

[0095] 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 representation value is determined based on the distance quantization value, thereby improving the accuracy of the influence degree representation value.

[0096] 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 an 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; 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 attribute quantization value.

[0097] The light source attributes include, but are not limited to, at least one of the brightness or intensity of the light source. Brightness is calculated based on the color of the light source. The attribute quantization value is positively correlated with both the brightness and intensity of the light source. The attribute quantization value may also be related to the light source's decay rate: faster decay rates correspond to smaller attribute quantization values, while slower decay rates correspond to larger attribute quantization values. The impact representation value is positively correlated with the attribute quantization value.

[0098] 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.

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

[0100] In some embodiments, the number of light sources included in the light source cluster is less than or equal to a preset number; using each cell in the two-dimensional grid to cluster multiple light sources in the virtual scene, and obtaining the light source clusters corresponding to each cell respectively includes: determining candidate light sources from multiple light sources in turn, and determining cells that intersect 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, adding the candidate light source to the current light source cluster of the determined cell; returning to the step of determining candidate light sources from multiple light sources in turn until multiple light sources are traversed; after traversing multiple light sources, determining the current light source cluster of each cell in the two-dimensional grid as the light source cluster of each cell respectively.

[0101] Among them, the candidate light source is any light source among the multiple light sources. In the process of traversing the multiple light sources, a different light source can be used as a candidate light source each time. The cell that intersects with the candidate light source on the preset plane refers to the cell that intersects with the projection area of ​​the illumination space illuminated by 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 to 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.

[0102] 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. 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 sequence until multiple light sources are traversed.

[0103] In some embodiments, the clustering method includes at least one of a first clustering method and a second clustering method, the first clustering method being different from the second clustering method, and the first clustering method and the second clustering method being 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 may determine a selected clustering method, and the selected clustering method may be automatically selected by the terminal based on the number of light sources or the GPU's parallel computing capabilities, or may be manually selected.

[0104] 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 source of the cell from multiple light sources in turn. The intersecting light source of the cell refers to the light source where the projection area of ​​the illumination space 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, the intersecting light source is added to the current light source cluster of the cell, and the step of determining the intersecting light source 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 light source cluster of the cell.

[0105] 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 sequence, and determine the cells that intersect with the candidate light source on the 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, and the step of determining the candidate light source from multiple light sources in sequence is returned 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 respectively determined as the light source cluster of each cell.

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

[0107] In some embodiments, the shadow rendering 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.

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

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

[0110] In this 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 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 source cluster of the cell retains the light source with a larger influence representation value, which is conducive to accurate rendering and improves the rendering effect.

[0111] In some embodiments, for each pixel point in the screen space, determining the target light source cluster from the multiple light source clusters includes: determining the world space position of the pixel point; determining the cell to which the projection position of the world space position of the pixel point on a preset plane belongs, and obtaining the target cell; and determining the light source cluster corresponding to the target cell as the target light source cluster whose illumination is related to the pixel value of the pixel point.

[0112] 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.

[0113] In this embodiment, the target light source cluster related to the illumination and the pixel value of the pixel point is accurately determined through the projection position, thereby avoiding subsequent shadow distortion in rendering.

[0114] In some embodiments, the shadow of the virtual scene is rendered based on the target light source cluster of each pixel point, and the shadow rendering result obtained includes: for each pixel point in the screen space, when the target light source cluster of the pixel point includes a light source participating in the shadow rendering, determining the light source contact information of the light source participating in the shadow rendering for the pixel point; the light source contact information represents whether the light source participating in the shadow rendering generates illumination for the world space position of the pixel point; the shadow of the virtual scene is rendered 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.

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

[0116] 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 target light source cluster of the pixel. The cluster contact information of the pixel is generated before shadow rendering.

[0117] 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. As shown in Figure 11, a flowchart of shadow rendering by reading light source contact information during shadow rendering is shown.

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

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

[0120] Specifically, the pixel's cluster reach information is determined before shadow rendering begins. This includes the light source reach information for each light source in the pixel's target light source cluster. During shadow rendering, the light source reach information for each light source participating in shadow rendering is retrieved from the pixel's cluster reach information to perform shadow rendering.

[0121] 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 rendering efficiency.

[0122] 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 target light source cluster of the pixel point for the pixel point; and combining the light source touch information of each light source in the target light source cluster of the pixel point for the pixel point to form the cluster touch information of the pixel point.

[0123] Specifically, before performing shadow rendering, for each pixel, the terminal may collect the light source contact information of each light source in the target light source cluster of the pixel for the pixel, and form cluster contact information of the pixel.

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

[0125] In some embodiments, as shown in FIG12 , a shadow rendering method is provided. The method may be executed by a terminal or jointly by a terminal and a server. The method is described using the application of the method to a terminal as an example, and includes the following steps:

[0126] Step 1202: Set a two-dimensional network on a preset plane in the world space where the virtual scene is located.

[0127] Step 1204 : clustering the multiple light sources in the virtual scene using the cells in the two-dimensional grid to obtain light source clusters corresponding to the cells.

[0128] The projection area of ​​the illumination space illuminated by the light sources in the light source cluster on the preset plane intersects with the corresponding cells.

[0129] Step 1206 : For each pixel point in the screen space, determine a target light source cluster from the multiple light source clusters, where the illumination of the target light source cluster is related to the pixel value of the pixel point.

[0130] 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 to obtain the ray tracing direction.

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

[0132] In step 1210 , the world space position of the pixel point is determined as the starting position of the ray tracing, and the ending position of the ray tracing is determined based on the ray tracing direction and the preset tracing distance.

[0133] Step 1212, determining the number of ray tracing steps based on the starting position of the ray tracing and the ending position of the ray tracing, and determining the ray tracing step length based on the preset tracing distance and the number of ray tracing steps.

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

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

[0136] 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.

[0137] 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 to obtain the depth difference of the sampling position.

[0138] Step 1218: Obtain the light source contact information of the target light source for the pixel point based on the depth difference of each sampling position.

[0139] Step 1220: For each pixel point in the screen space, if the target light source cluster of the pixel point includes a light source participating in shadow rendering, obtain the light source contact information of the light source participating in shadow rendering for the pixel point from the cluster contact information of the pixel point.

[0140] Step 1222: Render the shadow of the virtual scene 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.

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

[0142] The shadow rendering method provided in this application can be applied to any scene that requires shadow rendering, especially scenes with multiple 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. The shadow rendering method provided in this application can improve shadow rendering efficiency in scenes such as film and television special effects, visual design, games, mirror simulation, VR, industrial simulation, and digital cultural creation.

[0143] The shadow rendering method provided in this 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 set up a two-dimensional network on a preset plane in the world space where the digital Great Wall scene is located, and cluster the multiple light sources in the digital Great Wall scene according to each cell in the two-dimensional grid to obtain the light source cluster corresponding to each cell. For each pixel point in the screen space, a target light source cluster is determined from the multiple light source clusters. The illumination of the target light source cluster is related to the pixel value of the pixel point. For each pixel point in the screen space, the terminal can determine the light source contact information of each light source in the target light source cluster for the pixel point. When performing shadow rendering, for each pixel in screen space, if the target light source cluster for that pixel includes a light source participating in shadow rendering, the light source contact information for that pixel is determined. Based on this light source contact information for that pixel, the shadow of the virtual scene is rendered to obtain a shadow rendering result for the digital Great Wall. Thus, the shadow rendering method provided in this application not only presents the realistic lighting effects of the digital Great Wall under multiple lighting conditions, but also improves the efficiency of shadow rendering in the digital Great Wall.

[0144] For each pixel in the game scene, the terminal can determine the target light source corresponding to the pixel from multiple light sources in the game scene. The pixel's world space position in the world space where the game scene is located is located within the illumination space illuminated by the target light source corresponding to the pixel. Ray tracing is performed based on the world space position of the target light source and the world space position of the pixel to obtain the target light source's light source contact information for the pixel. The light source contact information indicates whether the target light source generates light at the pixel's world space position. Based on the light source contact information, shadow rendering is performed on the game scene to obtain the shadow rendering result. This improves the rendering efficiency of shadows in the game scene.

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

[0146] It should be understood that, although the steps in the flowcharts of the above embodiments are shown in sequence as indicated by the arrows, these steps are not necessarily performed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be performed in other orders. Moreover, at least a portion of the steps in the flowcharts of the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily performed at the same time, but can be performed at different times. The execution order of these steps or stages is not necessarily to be performed in sequence, but can be performed in turn or alternately with other steps or at least a portion of steps or stages in other steps.

[0147] Based on the same inventive concept, embodiments of the present application also provide a shadow rendering device for implementing the aforementioned shadow rendering method. The solution provided by this device is similar to the solution described in the aforementioned method. Therefore, the specific limitations of one or more shadow rendering device embodiments provided below can be found in the above-described limitations of the shadow rendering method and will not be further elaborated here.

[0148] In some embodiments, as shown in FIG13 , a shadow rendering apparatus is provided, comprising: 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:

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

[0150] The light source clustering module 1304 is used to cluster multiple light sources in the virtual scene using each cell in the two-dimensional grid to obtain a light source cluster corresponding to each cell, and the projection area of ​​the illumination space illuminated by the light sources in the light source cluster on the preset plane intersects with the corresponding cell.

[0151] The light source cluster matching module 1306 is configured to determine, for each pixel point in the screen space, a target light source cluster from the multiple light source clusters, where the illumination of the target light source cluster is related to the pixel value of the pixel point.

[0152] The shadow rendering module 1308 is used to render the shadow of the virtual scene based on the target light source cluster of each pixel point to obtain a shadow rendering result.

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

[0154] In some embodiments, the light source clustering module 1304 is further 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 area of ​​the illumination space on a 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 a preset number, the intersecting light sources are added to the current light source cluster of the cell; the step of determining the intersecting light sources of the cell from multiple light sources in sequence 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 light source cluster of the cell.

[0155] 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.

[0156] In some embodiments, the light source clustering module 1304 is further used to determine a distance quantization value of the intersecting light sources of a 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.

[0157] In some embodiments, the light source clustering module 1304 is further configured to determine a property quantization value of the intersecting light sources of the cell; the property quantization value is determined based on the property of the intersecting light sources of the cell; and a characterization value of the degree of influence of the intersecting light sources of the cell on the cell is determined based on the distance quantization value and the property quantization value.

[0158] In some embodiments, the number of light sources included in the 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 multiple light sources in sequence, and determine cells that intersect 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; the step of determining candidate light sources from multiple light sources in sequence is returned 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 respectively determined as the light source cluster of each cell.

[0159] In some embodiments, the light source clustering module 1304 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 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.

[0160] In some embodiments, the light source cluster matching module 1306 is further 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 to obtain the target cell; and determine the light source cluster corresponding to the target cell as the target light source cluster whose illumination is related to the pixel value of the pixel point.

[0161] 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 target light source cluster of the pixel point includes the light source participating in the shadow rendering; and render the shadow of the virtual scene 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.

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

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

[0164] Each module in the shadow rendering device described above can be implemented in whole or in part through 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 the computer device in the form of software, so that the processor can call and execute the corresponding operations of each module.

[0165] In some embodiments, a computer device is provided, which may be a server, and its internal structure diagram may be as shown in Figure 14. The computer device includes a processor, memory, an input / output (I / O) interface, and a communication interface. The processor, memory, and I / O interface are connected via a system bus, and the communication interface is connected to the system bus via the I / O 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, computer-readable instructions, and a database. The internal memory provides an environment for the operation of the operating system and computer-readable instructions in the non-volatile storage medium. The database of the computer device is used to store data involved in a shadow rendering method. The I / O interface of the computer device is used to exchange information between the processor and external devices. The communication interface of the computer device is used to communicate with external terminals via a network connection. When executed by the processor, the computer-readable instructions implement a shadow rendering method.

[0166] In some embodiments, a computer device is provided, which may be a terminal. Its internal structure diagram may be as shown in Figure 15. The computer device includes a processor, memory, an input / output interface, a communication interface, a display unit, and an input device. The processor, memory, and input / output interface are connected via a system bus, and the communication interface, display unit, and 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 internal memory. The non-volatile storage medium stores an operating system and computer-readable instructions. The internal memory provides an environment for the operation of the operating system and computer-readable instructions in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and external devices. The communication interface of the computer device is used to communicate with external terminals via wired or wireless communication. The wireless communication may be achieved via Wi-Fi, a mobile cellular network, NFC (near-field communication), or other technologies. When executed by the processor, the computer-readable instructions implement a shadow rendering method. 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 covering the display screen, or a button, trackball or touchpad set on the computer device casing, or an external keyboard, touchpad or mouse, etc.

[0167] Those skilled in the art will understand that the structures shown in Figures 14 and 15 are merely block diagrams of partial structures related to the solution of the present application, and do 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 shown in the figures, or combine certain components, or have a different component arrangement.

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

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

[0170] In some embodiments, a computer program product is provided, comprising computer-readable instructions, which implement the steps in the above shadow rendering method when executed by a processor.

[0171] 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 the relevant laws, regulations and standards of relevant countries and regions.

[0172] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through computer-readable instructions. The computer-readable instructions can be stored in a non-volatile computer-readable storage medium. When the computer-readable instructions are executed, they can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, database or other media used in the embodiments provided in this application may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory may include random access memory (RAM) or external cache memory, etc. By way of 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 the various embodiments provided herein may include at least one of a relational database and a non-relational database. Non-relational databases may include, but are not limited to, distributed databases based on blockchains. The processor involved in the various embodiments provided herein may be, but are not limited to, a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic unit, a data processing logic unit based on quantum computing, and the like.

[0173] The technical features of the above embodiments can 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.

[0174] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art could make various modifications and improvements without departing from the spirit of the present application, all of which fall within the scope of protection of the present application. Therefore, the scope of protection of the present patent application shall be determined by the appended claims.

Claims

1. A shadow rendering method, performed by a computer device, the method comprising: Setting 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 using each cell in the two-dimensional grid to obtain light source clusters corresponding to each cell, wherein a projection area of ​​the illumination space illuminated by the light sources in the light source cluster on the preset plane intersects with the cell corresponding to the light source cluster; For each pixel point in the screen space, determine a target light source cluster from the multiple light source clusters, where illumination of the target light source cluster is related to a pixel value of the pixel point; and The shadows in the world space are rendered based on the target light source clusters of each pixel point to obtain shadow rendering results.

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

3. The method according to claim 1 or 2, wherein obtaining the light source cluster of the cell based on the light sources intersecting with the cell among the plurality of light sources comprises: sequentially determining the intersecting light sources of the cell from the multiple light sources; The intersecting light source of the cell refers to the light source whose projection area of ​​the illumination space 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 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 all 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 light source cluster of the cell.

4. The method according to any one of claims 1 to 3, further comprising: 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; The representation value of the influence degree of the first light source to be replaced on the cell is smaller than the representation value of the influence degree 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 any one of claims 1 to 4, wherein determining the value representing the degree of influence of the intersecting light sources of the cell on the cell comprises: Determining a distance quantization value of an intersecting light source of the cell; The distance quantization value is used to represent the distance between the intersecting light source of the cell and the cell; Determine, based on the distance quantization value, a representation value of the degree of influence of the intersecting light source of the cell on the cell; The influence degree representation value is negatively correlated with the distance quantization value.

6. The method according to any one of claims 1 to 5, wherein determining the influence characterization value of the intersecting light source of the cell on the cell based on the distance quantization value comprises: Determining a quantitative value of a property of an intersecting light source 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, 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 any one of claims 1 to 6, wherein the number of light sources included in the 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 light source clusters corresponding to each cell includes: Determine candidate light sources from the multiple light sources in sequence, and determine cells intersecting with the candidate light sources on a preset plane from the cells of the two-dimensional grid; 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 all 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 determined as the light source cluster of each cell.

8. The method according to any one of claims 1 to 7, further comprising: 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 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 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 any one of claims 1 to 8, wherein for each pixel point in the screen space, determining a target light source cluster from the multiple 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 light source cluster corresponding to the target cell is determined as a target light source cluster whose illumination is related to the pixel value of the pixel point.

10. The method according to any one of claims 1 to 9, wherein rendering the shadow of the virtual scene based on the target light source cluster of each pixel point to obtain the shadow rendering result comprises: For each pixel point in the screen space, when the target light source cluster of the pixel point includes a light source participating in shadow rendering, determining light source contact information of the light source participating in shadow rendering for the pixel point; The light source reach information represents whether the light source participating in shadow rendering generates illumination for the world space position of the pixel point; The shadow of the virtual scene is rendered 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. According to the method according to any one of claims 1 to 10, determining the light source contact information of the light source participating in shadow rendering for the pixel point comprises: Determine cluster reach information of the pixel point; The cluster reaching information of the pixel point includes light source reaching information of each light source in the target 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 any one of claims 1 to 11, wherein determining the cluster reach information of the pixel point comprises: Determine light source reach information of each light source in the target light source cluster of the pixel point for the pixel point; The light source reaching information of each light source in the target light source cluster of the pixel point is respectively used to form the cluster reaching information of the pixel point.

13. A shadow rendering device, the device comprising: A grid distribution module is used to set up a two-dimensional network on a preset plane in the world space where the virtual scene is located; A light source clustering module is used to cluster multiple light sources in the virtual scene according to each cell in the two-dimensional grid. Clustering is performed to obtain light source clusters corresponding to each of the cells, wherein a projection area of ​​the illumination space illuminated by the light sources in the light source cluster on the preset plane intersects with the corresponding cell; A light source cluster matching module, configured to determine, for each pixel point in the screen space, a target light source cluster from the multiple light source clusters, wherein the illumination of the target light source cluster is related to the pixel value of the pixel point; and The shadow rendering module is used to render the shadow of the virtual scene based on the target 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 computer-readable instructions, and the processor implements the method according to any one of claims 1 to 12 when executing the computer-readable instructions.

15. A computer-readable storage medium having computer-readable instructions stored thereon, wherein the computer-readable instructions implement the method according to any one of claims 1 to 12 when executed by a processor.

16. A computer program product comprising computer readable instructions, which implement the method according to any one of claims 1 to 12 when executed by a processor.