Shadow rendering method and device, computer equipment and storage medium
By determining the target light source for each pixel and performing ray tracing, combined with light source clustering and lighting area intersection optimization, the problem of low shadow rendering efficiency in the traditional shadow map method is solved, and efficient shadowing in complex scenes and multiple light sources is achieved. render.
Patent Information
- Application Number
- CN202310258041.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-08
- Publication Date
- 2024-09-10
AI Technical Summary
The traditional rendering method based on shadow maps has high computational complexity in complex scenes, resulting in low shadow rendering efficiency, especially when there are many light sources.
By determining the target light source for each pixel in the virtual scene, and obtaining light source contact information based on ray tracing for shadow rendering, the intersection relationship between light source clustering and lighting areas is used to optimize light source processing.
Improved the efficiency of shadow rendering, especially in complex scenes and multiple light sources, improving rendering performance and realism.
Smart Images

Figure CN118628639A
Abstract
Description
Technical Field
[0001] The present application relates to the field of rendering technology, and in particular to a shadow rendering method, device, computer equipment and storage medium. Background Art
[0002] With the development of computer technology, shadow rendering technology has emerged. Shadow rendering technology is used to render shadows to enhance the realism of rendering results.
[0003] In traditional technology, shadow maps are usually used to render shadows. The computational complexity of the rendering method based on shadow maps is closely related to the complexity of the scene to be rendered. The higher the complexity of the scene, the higher the performance requirement.
[0004] Therefore, when the scene complexity is high, for example, when there are many light sources in the scene, the rendering method based on the shadow map has the problem of high computational complexity, resulting in low shadow rendering efficiency. Summary of the invention
[0005] Based on this, it is necessary to provide a shadow rendering method, apparatus, computer equipment, computer-readable storage medium and computer program product that can improve the efficiency of shadow rendering in response to the above technical problems.
[0006] On the one hand, the present application provides a shadow rendering method. The method includes: for each pixel in the screen space, determining the target light source corresponding to the pixel from multiple light sources in the virtual scene; the world space position of the pixel in the world space where the virtual scene is located is located in the illumination area of the target light source corresponding to the pixel; based on the world space position of the target light source and the world space position of the pixel, ray tracing is performed 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 for the world space position of the pixel; based on the light source contact information, shadow rendering is performed on the virtual scene to obtain a shadow rendering result.
[0007] On the other hand, the present application also provides a shadow rendering device. The device includes: a light source determination module, which is used to determine, for each pixel point in the screen space, a target light source corresponding to the pixel point from multiple light sources in the virtual scene; the world space position of the pixel point in the world space where the virtual scene is located is located in the illumination area of the target light source corresponding to the pixel point; an information acquisition module, which is used to 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; the light source contact information indicates whether the target light source generates illumination for the world space position of the pixel point; a shadow rendering module, which is used to perform shadow rendering on the virtual scene based on the light source contact information to obtain a shadow rendering result.
[0008] In some embodiments, the information acquisition module is also used to determine the starting position of the ray tracing and the ending position of the ray tracing based on the world space position of the target light source and the world space position of the pixel point; determine the number of ray tracing steps according to the starting position of the ray tracing and the ending position of the ray tracing; perform ray tracing according to the number of ray tracing steps to obtain the light source touch information of the target light source for the pixel point.
[0009] In some embodiments, the information acquisition module is also used to 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; determine the world space position of the pixel point as the starting position of the ray tracing; and determine the end position of the ray tracing based on the ray tracing direction and a preset tracing distance.
[0010] In some embodiments, the information acquisition module is also used to 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; determine the tracing step factor based on the distance between the converted starting position and the converted ending position; determine the ray tracing steps according to the tracing step factor and the tracing step threshold.
[0011] In some embodiments, the information acquisition module is also used to determine the ray tracing step size based on the preset tracing distance and the ray tracing step number; starting from the world space position of the pixel point, a plurality of sampling positions are determined along the ray tracing direction; the length between two adjacent sampling positions in the ray tracing direction is the ray tracing step size, and the number of sampling positions is the ray tracing step number; for each of the sampling positions, the difference between the depth value of the sampling position and the depth value of the screen space position corresponding to the sampling position is determined to obtain the depth difference of the sampling position; according to the depth difference of each of the sampling positions, the light source reach information of the target light source for the pixel point is obtained.
[0012] In some embodiments, the information acquisition module is also used to determine a depth difference threshold based on the depth value of the starting position of the ray tracing and the depth value of the ending position of the ray tracing; when the depth difference of any of the sampling positions is less than or equal to the depth difference threshold, the light source reach information of the target light source for the pixel point is determined to be a first preset value; the first preset value indicates that the target light source does not generate illumination for the world space position of the pixel point; when the depth difference of each of the sampling positions is greater than the depth difference threshold, the light source reach information of the target light source for the pixel point is determined to be a second preset value; the second preset value indicates that the target light source generates illumination for the world space of the pixel point.
[0013] In some embodiments, the information acquisition module is also used to determine the depth value of the starting position of the ray tracing to obtain a starting depth value, and determine the depth value of the ending position of the 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; determine a depth difference threshold based on the total depth difference and the number of ray tracing steps.
[0014] In some embodiments, the light source determination module is also used to distribute a two-dimensional grid on a preset plane in the world space where the virtual scene is located; cluster multiple light sources in the virtual scene according to each cell in the two-dimensional grid to obtain a target light source cluster corresponding to each cell; there is an intersection relationship between the illumination area of the light source in the target light source cluster and the projection area on the preset plane and the corresponding cell; determine a matching light source cluster that has a lighting effect on the pixel point from the target light source clusters corresponding to each cell; and determine the target light source corresponding to the pixel point from the matching light source clusters that have a lighting effect on the pixel point.
[0015] In some embodiments, the light source determination module is also used to obtain, for each cell in the two-dimensional grid, a target light source cluster for the cell based on the light sources among the multiple light sources that have an intersection relationship with the cell; wherein, having an intersection relationship with the cell means that a projection area of the illumination area on the preset plane intersects with the cell, and the number of light sources in the target light source cluster is less than or equal to a preset number.
[0016] In some embodiments, the light source determination module is also used to determine the intersecting light sources of the cell from the multiple light sources in sequence; the intersecting light sources of the cell refer to light sources whose projection areas of the illumination area on the preset plane intersect with the cell; when the number of light sources included in the current light source cluster of the cell is less than the preset number, the intersecting light sources are added to the current light source cluster of the cell; return to the step of determining the intersecting light sources of the cell from the multiple light sources in sequence until the multiple light sources are traversed; when the multiple light sources are traversed, the current light source cluster of the cell is determined as the target light source cluster of the cell.
[0017] In some embodiments, the light source determination module is also used to determine the cell to which the projection position of the world space position of the pixel point on the preset plane belongs, and obtain the target cell; and determine the target light source cluster corresponding to the target cell as the matching light source cluster that has an illumination effect on the pixel point.
[0018] In some embodiments, the device is also used to: combine the light source touch information of each light source in the matching light source cluster of the pixel point for the pixel point into cluster touch information of the pixel point; the shadow rendering module is also used to, for each pixel point in the screen space, obtain the light source touch information of the light source participating in the shadow rendering for the pixel point from the cluster touch information of the pixel point when the matching light source cluster of the pixel point includes the light source participating in the shadow rendering; perform shadow rendering based on the light source touch information of the light source participating in the shadow rendering for the pixel point to obtain a shadow rendering result.
[0019] On the other hand, the present application further provides a computer device, wherein the computer device comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps in the above shadow rendering method when executing the computer program.
[0020] On the other hand, the present application further provides a computer-readable storage medium having a computer program stored thereon, and the computer program implements the steps in the above shadow rendering method when executed by a processor.
[0021] On the other hand, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps in the above shadow rendering method are implemented.
[0022] The above-mentioned shadow rendering method, device, computer equipment, storage medium and computer program product, for each pixel point in the screen space, determine the target light source corresponding to the pixel point from multiple light sources in the virtual scene, the world space position of the pixel point in the world space where the virtual scene is located is located in the illumination area of the target light source corresponding to the pixel point, and ray tracing is performed based on the distance between the target light source and the pixel point in the world space to obtain the light source contact information of the target light source for the pixel point, the light source contact information represents whether the target light source generates light at the world space position of the pixel point, and the virtual scene is shadow rendered based on the contact information of each light source. Since shadow rendering is performed based on the light source contact information determined by ray tracing, shadow rendering can be quickly implemented in the case where there are many light sources in the virtual scene, thereby improving the efficiency of shadow rendering. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 A diagram of an application environment of a shadow rendering method in some embodiments;
[0024] Figure 2 is a flowchart of a shadow rendering method in some embodiments;
[0025] Figure 3A is a schematic diagram of a two-dimensional grid in some embodiments;
[0026] Figure 3B A schematic diagram of the intersection of a projection area and a cell in some embodiments;
[0027] Figure 4 This is a real-time rendering picture obtained when no shadows are rendered in some embodiments;
[0028] Figure 5 The real-time rendering picture obtained by rendering the shadow in some embodiments;
[0029] Figure 6 A schematic diagram of a process for determining light source reach information in some embodiments;
[0030] Figure 7 is a flowchart of a shadow rendering method in some embodiments;
[0031] Figure 8 is a structural block diagram of a shadow rendering device in some embodiments;
[0032] Fig. 9 is an internal structure diagram of a computer device in some embodiments;
[0033] Fig.10 1 is a diagram of the internal structure of a computer device in some embodiments. DETAILED DESCRIPTION
[0034] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0035] The shadow rendering method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown, the terminal 102 communicates with the server 104 through a network. The data storage system can store data that the server 104 needs to process. The data storage system can be integrated on the server 104, or placed on the cloud or other servers.
[0036] Specifically, the terminal 102 can obtain a virtual scene from the server 104. For each pixel in the screen space, the terminal 102 can determine the target light source corresponding to the pixel from multiple light sources in the virtual scene. The world space position of the pixel in the world space where the virtual scene is located is located in the illumination area of 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 for the world space position of the pixel. The virtual scene is shadow rendered based on the light source contact information to obtain the shadow rendering result. The terminal 102 can display the shadow rendering result or send the shadow rendering result to the server 104.
[0037] Among them, the terminal 102 can be, but is not limited to, various desktop computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, cloud security, host security and other network security services, CDN, and basic cloud computing services such as big data and artificial intelligence platforms. The terminal 102 and the server 104 can be directly or indirectly connected via wired or wireless communication, and this application does not limit this.
[0038] In some embodiments, Figure 2As shown, a shadow rendering method is provided, which can be executed by a terminal or a server, or by a terminal and a server together. Figure 1 The terminal 102 in the example is used as an example to illustrate, and the following steps are included:
[0039] Step 202, for each pixel point in the screen space, determine the target light source corresponding to the pixel point from multiple light sources in the virtual scene; the world space position of the pixel point in the world space where the virtual scene is located is located in the illumination area of the target light source corresponding to the pixel point.
[0040] The virtual scene is a virtual scene displayed (or provided) when the application is running on the terminal. The virtual scene can be a simulated environment scene of the real world, a semi-simulated and semi-fictitious three-dimensional environment scene, or a purely fictitious three-dimensional environment scene. The virtual scene can be any one of a two-dimensional virtual scene, a 2.5-dimensional virtual scene, and a three-dimensional virtual scene.
[0041] A light source refers to an object that can emit light by itself and is emitting light, such as the sun, electric lights, burning substances, etc. The light source in a virtual scene is a series of lighting data that can realistically simulate the lighting effects of a light source in reality. The illumination area of a light source refers to the area that the light source can illuminate. The illumination area of a light source can be either spherical or conical. When the illumination area of a light source is spherical, the illumination area of the light source can be called the range sphere of the light source. The target light source corresponding to a pixel point refers to the light source whose illumination area includes the world space position of the pixel point.
[0042] World Space refers to the three-dimensional space where the virtual scene is located. The size of the world space can be customized. For example, the world space is a three-dimensional space with a length of 100 meters, a width of 100 meters, and a height of 100 meters. The world space position refers to the position in the world space. Screen Space refers to the two-dimensional space of the screen. The size of the screen space is the size of the screen in pixels.
[0043] Specifically, the terminal can distribute a two-dimensional grid on a preset plane in the world space where the virtual scene is located, and the position of the two-dimensional grid on the preset plane can be updated in real time. For example, in real-time rendering, the position of the two-dimensional grid on the preset plane can be updated in real time according to the real-time switching of the screen, so that the light sources in the target light source cluster obtained by clustering the two-dimensional grid can cover the light sources participating in the real-time rendering. 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 illumination area of the light source on the preset plane. The multiple light sources in the virtual scene can be stored in the buffer of the GPU (graphics processing unit), and the two-dimensional grid can also be stored in the GPU.
[0044] Among them, the preset plane can be set as needed. For example, the virtual scene includes the ground, and the ground can also be called a horizontal plane. The preset plane can be a plane parallel to the horizontal plane, and the horizontal plane can be used as the preset plane. The preset plane can also be a plane with a preset angle with the horizontal plane. The preset angle can be set as needed, for example, it can be 0-90 degrees, and the size of the preset angle is not limited here. The two-dimensional grid has a certain size and shape. The size and shape of the two-dimensional grid can be preset as needed. For example, the shape of the two-dimensional grid is a rectangle, and the length and width of the two-dimensional grid can be set as needed. The two-dimensional grid includes multiple cells, and 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. Figure 3A As shown, a schematic diagram of a two-dimensional grid is shown. Figure 3A The two-dimensional grid in has a total of 16 cells. The position of a cell can be represented by rows and columns. The number in each cell represents the position of the cell. For example, "0-0" represents the cell in the 0th row and 0th column, and "1-1" represents the cell in the 1st row and 1st column.
[0045] In some embodiments, the terminal may determine the projection areas of the illumination areas of the multiple light sources on the preset plane, and for each cell in the two-dimensional grid, obtain the target light source cluster corresponding to the cell based on the light sources whose projection areas intersect with the cell. Figure 3B As shown, it shows a schematic diagram of the intersection of the projection area of the light source and the cells in the two-dimensional grid. Figure 3BEach circle in represents the projection area of a light source, and the solid point in the circle represents the center point of the circle, which is the projection position of the world space position of the light source on the preset plane. L0-L5 represent 5 light sources, and the number following L can be called the index of the light source. The number after the colon represents the brightness, for example, 100 in L4:100 represents the brightness. For example, the terminal can select all or part of the light sources from the light sources whose projection area intersects with the cell to form a target light source cluster corresponding to the cell. A light source cluster refers to a set composed of light sources, and a target light source cluster is a light source cluster obtained by clustering multiple light sources in a virtual scene. The terminal can determine a matching light source cluster that has an illumination effect on a pixel from the target light source clusters corresponding to each cell, and determine a target light source corresponding to the pixel from the matching light source clusters that have an illumination effect on the pixel. Among them, the matching light source cluster that has an illumination effect on the pixel can be called the matching light source cluster of the pixel, and the target light source corresponding to the pixel refers to the light source whose illumination area includes the world space position of the pixel.
[0046] In some embodiments, for each cell, a cell column of the cell is generated. The cell column of the cell is a column with the cell as a cross section, perpendicular to the preset plane, and with a height greater than a preset height. The terminal can obtain a target light source cluster corresponding to the cell based on each light source intersecting the illumination area with the unit column. The unit column can also be called a light source cluster column. The terminal can select all or part of the light sources from each light source intersecting the illumination area with the unit column to form a target light source cluster corresponding to the cell.
[0047] In some embodiments, the terminal may determine the cell to which the projection position of the world space position of the pixel on the preset plane belongs, obtain the target cell, and determine the target light source cluster corresponding to the target cell as the matching light source cluster that has an illumination effect on the pixel. The terminal may determine the light source whose illumination area includes the world space position of the pixel from the matching light source cluster that has an illumination effect on the pixel, and obtain the target light source corresponding to the pixel.
[0048] Step 204, performing ray tracing based on the world space position of the target light source and the world space position of the pixel point, to obtain light source reach information of the target light source for the pixel point; the light source reach information indicates whether the target light source generates illumination for the world space position of the pixel point.
[0049] Ray tracing can be implemented based on the Screen Space Ray Tracing and Screen Space Shadow algorithms. Screen Space Ray Tracing refers to a common real-time computer graphics algorithm that uses a pixel shader or a compute shader to access the scene depth buffer to determine whether two points in space are blocked by a certain 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 current pixel to be drawn and the light source.
[0050] The light source reach information of the light source for the pixel point indicates whether the light source generates illumination for the world space position of the pixel point. The light source reach information is one of the first preset value or the second preset value. The first preset value indicates that the light source does not generate illumination for the world space position of the pixel point; the second preset value indicates that the light source generates illumination for the world space of the pixel point. 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.
[0051] Specifically, for any light source in the matching light source cluster of a pixel point, when the illumination area of the light source includes the world space position of the pixel point, that is, when the light source is the target light source corresponding to the pixel point, the terminal can perform ray tracing based on the world space position of the target light source and the world space position of the pixel point to obtain the light source reach information of the target light source for the pixel point.
[0052] In some embodiments, for any light source in the matching light source cluster of a pixel point, when the illumination area of the light source does not include the world space position of the pixel point, the terminal uses the first preset value as the light source reach information of the light source for the pixel point.
[0053] In some embodiments, for any light source in the matching light source cluster of a pixel point, when the distance between the target light source and the observation position is greater than a distance threshold, the terminal can obtain the light source contact information of the light source for the pixel point. 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.
[0054] In some embodiments, when the light source reach information of each light source in the matching light source cluster for the pixel point is obtained, before shadow rendering, the terminal can combine the light source reach information of each light source in the matching light source cluster for the pixel point to form cluster reach information of the pixel point.
[0055] Step 206: Perform shadow rendering on the virtual scene based on the light source reach information to obtain a shadow rendering result.
[0056] Specifically, the terminal can determine the target light source corresponding to the pixel point from multiple light sources of the virtual scene in turn, determine a different target light source each time, and when the terminal obtains the light source contact information of the target light source for the pixel point, the terminal performs shadow rendering on the virtual scene based on the light source contact information until the multiple light sources are traversed to obtain the final shadow rendering result. Alternatively, the terminal can determine the cluster contact information of each pixel point before rendering. When performing shadow rendering, for each pixel point in the screen space, when the matching light source cluster of the pixel point includes the light source participating in the shadow rendering, the light source contact information of the light source participating in the shadow rendering for the pixel point is obtained from the cluster contact information of the pixel point, and shadow rendering is performed based on the light source contact information of the light source participating in the shadow rendering for the pixel point to obtain the shadow rendering result. Among them, there can be one or more light sources participating in the shadow rendering. For each light source participating in the shadow rendering, shadow rendering can be performed using the method provided in this embodiment. The light source participating in the shadow rendering refers to the light source actually to be drawn in the GPU delay pipeline.
[0057] In some embodiments, for each pixel in the screen space, the terminal can generate a corresponding bit string for the pixel, the bit string is a string that only includes at least one of 0 or 1, the length of the bit string is a fixed value, and the fixed value is greater than or equal to the maximum length of the light source list used to store the light source cluster, the actual form of the bit string can be a 32-bit integer, etc., the terminal can store the cluster touch information of the pixel in the form of a bit string, for example, different bits in the bit string represent different light source touch information in the cluster touch information. Before determining the light source touch information, the terminal can generate a bit string of the pixel, and initialize the characters of each bit in the bit string to a second preset value, such as 0, and when it is determined that the light source touch information of the light source for the pixel is the first preset value, the bit corresponding to the light source in the bit string is updated to the first preset value, such as 1, and when it is determined that the light source touch information of the light source for the pixel is the second preset value, the bit string remains unchanged. The terminal can create a buffer in the GPU, which can be called a screen pixel shadow mask buffer, and store the bit string of each pixel in the buffer. When performing shadow rendering, the terminal can read the light source touch information of the light source for the pixel from the buffer.
[0058] In the above shadow rendering method, for each pixel in the screen space, the target light source corresponding to the pixel is determined from multiple light sources in the virtual scene. The world space position of the pixel in the world space where the virtual scene is located is located in the illumination area of the target light source corresponding to the pixel. Ray tracing is performed based on the distance between the target light source and the pixel in the world space 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. The virtual scene is shadow rendered based on the contact information of each light source. Since shadow rendering is performed based on the light source contact information determined by ray tracing, shadow rendering can be quickly implemented in the case where there are many light sources in the virtual scene, thereby improving the efficiency of shadow rendering.
[0059] The shadow rendering method provided in this application can be applied to real-time rendering to add a stronger sense of layering and realism to the rendered image through shadows, such as Figure 4 As shown in the figure, the real-time rendering screen without rendering the shadow is shown. Figure 5 As shown, the real-time rendering screen obtained by rendering the shadow is obviously Figure 4 , Figure 5 The real-time rendering screen has a stronger sense of layering and reality. Real-time rendering of multiple light sources requires the cooperation of real-time rendering of shadows of multiple light sources to achieve realistic real-time rendering under multiple light sources. The shadow rendering method provided in this application can make the performance of rendering of multiple light sources independent of the scene scale and the number of light sources, thereby improving the rendering efficiency of multiple light sources in scenes with multiple light sources, so that the rendering of shadows of multiple light sources can achieve real-time performance.
[0060] In some embodiments, 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 touch information of the target light source for the pixel, including: determining the starting position and the ending position of the ray tracing based on the world space position of the target light source and the world space position of the pixel; determining the number of ray tracing steps according to the starting position and the ending position of the ray tracing; and performing ray tracing according to the number of ray tracing steps to obtain the light source touch information of the target light source for the pixel.
[0061] The world space position of the target light source refers to the position of the target light source in the world space. The starting position of ray tracing is the world space position of the pixel point.
[0062] Specifically, the terminal may determine the world space position of the pixel point as the starting position of the ray tracing. The terminal may 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 position where the distance between the world space position of the pixel point in the ray tracing direction and the preset tracing distance is equal to the end position of the ray tracing. The preset tracing distance may be set as required, for example, it may 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.
[0063] In some embodiments, the terminal may determine a tracing step factor based on the starting position of the ray tracing and the ending position of the ray tracing, and determine the ray tracing steps based on the tracing step factor and the tracing step threshold. 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. The depth difference threshold can be preset, or the depth difference threshold can be determined based on the depth value of the starting position of the ray tracing and the depth value of the ending position of the ray tracing.
[0064] In this embodiment, the number of ray tracing steps is determined according to the starting position of the ray tracing and the ending position of the ray tracing, so that the number of ray tracing steps can be reasonably limited and the ray tracing efficiency can be improved.
[0065] In some embodiments, determining the starting position 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 includes: determining 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; determining the world space position of the pixel point as the starting position of ray tracing; and determining the ending position of ray tracing based on the ray tracing direction and a preset tracing distance.
[0066] 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, and 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] Specifically, 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 point, and use the result of the addition as the end position. For example, the preset tracking distance is L, the direction vector is (x1, y1, z1), and the world space position of the pixel point is (x2, y2, z2), then the end position = (x2, y2, z2) + L*(x1, y1, z1).
[0068] In this embodiment, the termination position of ray tracing is determined based on the ray tracing direction and the preset tracing distance, so that the ray tracing distance can be limited and the ray tracing efficiency can be improved.
[0069] In some embodiments, determining the number of ray tracing steps based on the starting position of the ray tracing and the ending position of the ray tracing includes: converting the starting position of the ray tracing to the target two-dimensional space to obtain the converted starting position, and converting the ending position of the ray tracing to the target two-dimensional space to obtain the converted ending position; determining a tracing step factor based on the distance between the converted starting position and the converted ending position; determining the number of ray tracing steps based on the tracing step factor and the tracing step threshold.
[0070] The target two-dimensional space is either 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. The tracing step threshold can be preset as needed. 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.
[0071] Specifically, when the target two-dimensional space is a texture space, the terminal can determine the position corresponding to the starting position of ray tracing after being 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 ray tracing after being converted to the texture space, and use the determined position as the ending position after the conversion. Similarly, when the target two-dimensional space is a screen space, the terminal can determine the position corresponding to the starting position of ray tracing after being converted to the screen space, and use the determined position as the starting position after the conversion, and determine the position corresponding to the ending position of ray tracing after being converted to the screen space, and use the determined position as the ending position after the conversion.
[0072] In some embodiments, the distance between the converted starting position and the converted ending position is positively correlated with the tracking step factor. The ray tracing steps are positively correlated with the tracking step factor and the tracking step threshold. For example, the terminal may calculate the distance between the converted starting position and the converted ending position, and determine the calculated distance as the tracking step factor.
[0073] In some embodiments, the tracking step threshold may include a minimum tracking step and a maximum tracking step, and the minimum tracking step and the maximum tracking step may be preset as needed. The terminal may calculate the product of the tracking step factor and the maximum tracking step, and use the result of the product as a candidate tracking step. If the candidate tracking step is less than the minimum tracking step, the minimum tracking step is used as the ray tracing step. If the candidate tracking step is greater than the maximum tracking step, the maximum tracking step is used as the ray tracing step. If the candidate tracking step is greater than or equal to the minimum tracking step and the candidate tracking step is less than or equal to the minimum tracking step, the candidate tracking step is used as the ray tracing step.
[0074] In this embodiment, 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 occupied screen area, the closer the distance between the camera and the pixel point and the light source is. Conversely, the farther the distance between the camera and the pixel point and the light source is. Therefore, the ray tracing steps are 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 taken. Conversely, the fewer ray tracing steps are taken. This makes ray tracing more reasonable and improves the efficiency of ray tracing.
[0075] In some embodiments, ray tracing is performed according to the number of ray tracing steps to obtain light source contact information of the target light source for the pixel point, including: determining the ray tracing step length based on a preset tracing distance and the number of ray tracing steps; starting from the world space position of the pixel point, a plurality of sampling positions are determined along the ray tracing direction; 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 steps; for each sampling position, determining 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; according to the depth difference of each sampling position, the light source contact information of the target light source for the pixel point is obtained.
[0076] The multiple sampling positions refer to the number of sampling positions of the ray tracing steps. For example, if the number of ray tracing steps is 6, the multiple sampling positions refer to 6 sampling positions.
[0077] Specifically, 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 screen space position is the position of the pixel in the screen space, and the depth value of the screen space position is the depth value of the pixel. The terminal may store the depth value of each pixel in the screen space. The terminal may 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. 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 is used to reflect the distance between the position of the pixel in the world space and the observation position. The larger the depth value, the farther the distance from the observation position. In some embodiments, when the depth difference of any sampling position is less than or equal to the depth difference threshold, the terminal may determine that the light source touch information of the target light source for the pixel is the first preset value, and when the depth difference of each sampling position is greater than the depth difference threshold, the terminal may determine that the light source touch information of the target light source for the pixel is the second preset value. The depth difference threshold can be set as needed, or the depth difference threshold can be determined based on the depth value of the starting position of the ray tracing and the depth value of the ending position of the ray tracing. Figure 6 As shown, a schematic diagram of the process of determining the light source contact information is shown. Figure 6 The "number of light tracing steps" refers to the number of ray tracing steps, and "whether the tracing result pixel and the light source are blocked" is used to determine whether the light source is blocked. When the depth difference at any sampling position is less than or equal to the depth difference threshold, the light source is determined to be blocked. When the depth difference at each sampling position is greater than the depth difference threshold, the light source is determined to be not blocked.
[0078] In this embodiment, the light source triggering information is determined by the depth value, thereby improving the accuracy and efficiency of determining the light source triggering information.
[0079] In some embodiments, obtaining the light source touch information of the target light source for the pixel point based on the depth difference of each sampling position includes: determining the depth difference threshold based on the depth value of the starting position of the ray tracing and the depth value of the ending position of the ray tracing; when the depth difference of any sampling position is less than or equal to the depth difference threshold, determining that the light source touch information of the target light source for the pixel point is a first preset value; the first preset value indicates that the target light source does not generate illumination for the world space position of the pixel point; when the depth difference of each sampling position is greater than the depth difference threshold, determining that the light source touch information of the target light source for the pixel point is a second preset value; the second preset value indicates that the target light source generates illumination for the world space of the pixel point.
[0080] Specifically, the terminal may determine the depth value of the starting position of the ray tracing to obtain the starting depth value, determine the depth value of the ending position of the ray tracing to obtain the ending depth value, determine the difference between the starting depth value and the ending depth value to obtain the 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 the step depth.
[0081] In this embodiment, when the depth difference at any sampling position is less than or equal to the depth difference threshold, the light source touch information of the target light source for the pixel point is determined to be a first preset value. When the depth difference at each sampling position is greater than the depth difference threshold, the light source touch information of the target light source for the pixel point is determined to be a second preset value, thereby improving the accuracy of the light source touch information.
[0082] In some embodiments, determining the depth difference threshold based on the depth value of the starting position of the ray tracing and the depth value of the ending position of the ray tracing includes: determining the depth value of the starting position of the ray tracing to obtain a starting depth value, and determining the depth value of the ending position of the ray tracing to obtain a ending depth value; determining the difference between the starting depth value and the ending depth value to obtain a total depth difference; determining the depth difference threshold based on the total depth difference and the number of ray tracing steps.
[0083] Specifically, the depth difference threshold is positively correlated with the total depth difference, and the depth difference threshold is negatively correlated with 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.
[0084] In this embodiment, the depth difference threshold is determined based on the total depth difference and the number of ray tracing steps, thereby improving the accuracy of the depth difference threshold.
[0085] In some embodiments, determining a target light source corresponding to a pixel point from multiple light sources in a virtual scene includes: distributing a two-dimensional grid on a preset plane in the world space where the virtual scene is located; clustering multiple light sources in the virtual scene according to each cell in the two-dimensional grid to obtain a target light source cluster corresponding to each cell; an intersection relationship exists between the projection area of the illumination area of the light source in the target light source cluster on the preset plane and the corresponding cell; determining a matching light source cluster that has an illumination effect on the pixel point from the target light source clusters corresponding to each cell; and determining the target light source corresponding to the pixel point from the matching light source clusters that have an illumination effect on the pixel point.
[0086] Specifically, the number of light sources included in the target light source cluster is less than or equal to a preset number. The terminal can select light sources whose number is less than or equal to a preset number from the light sources whose projection area intersects with the cell to form the target light source cluster corresponding to the cell. Alternatively, the terminal can select light sources whose number is less than or equal to a preset number from the light sources whose illumination area intersects with the cell column to form the target light source cluster corresponding to the cell.
[0087] In some embodiments, the terminal may initialize the light source cluster of each cell, wherein the initialized light source cluster has no light source and can accommodate at most the preset number of light sources. For example, an empty list of fixed length may be initialized as the initialized light source cluster, wherein the empty list of fixed length can store at most the preset number of light sources. It should be noted that storing light sources in the light source cluster refers to storing the identifier of the light source, not the light source itself. The current light source cluster is initially the initialized light source cluster, and when traversing the multiple light sources, light sources may be added to the current light source cluster. The terminal may determine candidate light sources from multiple light sources in sequence, determine cells that have an intersecting relationship with the candidate light source on a preset plane from each cell of the two-dimensional grid, and when the number of light sources included in the current light source cluster of the determined cell is less than the preset number, add the candidate light source to the current light source cluster of the determined cell, and return to the step of determining the candidate light source from multiple light sources in sequence until multiple light sources are traversed. After traversing multiple light sources, the terminal may determine the current light source cluster of each cell in the two-dimensional grid as the target light source cluster of each cell. Among them, the candidate light source is any light source among the multiple light sources, and in the process of traversing the multiple light sources, different light sources may be used as candidate light sources each time. The cell that has an intersection relationship with the candidate light source on the preset plane refers to the cell that intersects with the projection area of the illumination area of the candidate light source on the preset plane. In the process of traversing the multiple light sources, the current light source cluster of the cell can be constantly changing. Before starting to traverse the multiple light sources, the current light source cluster of the cell may not include any light source, that is, the current light source cluster is initialized as a light source cluster that does not include any light source. In the process of traversing the multiple light sources, light sources are added to the current light source cluster.
[0088] In this embodiment, since the light sources are clustered and shadow rendering is performed based on the matching light source clusters of the pixels, shadow rendering can be quickly implemented when there are many light sources in the virtual scene, thereby improving the shadow rendering efficiency.
[0089] In some embodiments, multiple light sources in a virtual scene are clustered according to each cell in a two-dimensional grid to obtain a target light source cluster corresponding to each cell, including: for each cell in the two-dimensional grid, based on a light source among multiple light sources that has an intersection relationship with the cell, a target light source cluster for the cell is obtained; wherein, having an intersection relationship with the cell means that a projection area of the illumination area on a preset plane intersects with the cell, and the number of light sources in the target light source cluster is less than or equal to a preset number.
[0090] The preset number can be set as required, for example, 20 or 50. When the projection area of the illumination area of the light source on the preset plane intersects with the cell, it is considered that the light source has an intersection relationship with the cell.
[0091] Specifically, for each cell, the terminal can determine the intersecting light sources of the cell from multiple light sources. The intersecting light sources of the cell refer to the light sources whose projection areas of the illumination area on the preset plane intersect with the cell. The number of intersecting light sources of the cell can be one or more, and multiple means at least two. When the number of intersecting light sources of the cell is less than or equal to the preset number, the terminal can group the intersecting light sources of the unit into a target light source cluster corresponding to the cell.
[0092] In some embodiments, when the number of intersecting light sources of the cell is greater than the preset number, the terminal can calculate the influence degree characterization value of each intersecting light source on the cell, and select a preset number of intersecting light sources from the intersecting light sources of the cell in order of the influence degree characterization values from large to small, and the selected intersecting light sources are organized into a target light source cluster corresponding to the cell.
[0093] In some embodiments, the influence degree characterization value of the light source on the cell can be determined by at least one of the distance quantization value or the attribute quantization value. The influence degree characterization value is negatively correlated with the distance quantization value. The distance quantization value is used to characterize the distance between the light source and the cell. The distance between the light source and the cell can be the distance between the world space position of the light source and the center position of the cell, or the distance between the projection position of the light source and the center position of the cell. The projection position of the light source refers to the position of the projection of the world space position of the light source on the preset plane. The attribute quantization value is determined based on the attribute of the light source, wherein the attribute of the light source includes but is not limited to at least one of the brightness or illumination intensity of the light source. The brightness is calculated by the color of the light source. The attribute quantization value is positively correlated with both the brightness and illumination intensity of the light source. The attribute quantization value can also be related to the attenuation speed of the light source. The faster the attenuation speed of the light source, the smaller the attribute quantization value, and the slower the attenuation speed of the light source, the larger the attribute quantization value. The influence degree characterization value is positively correlated with the attribute quantization value. For example, the terminal can calculate the ratio of the attribute quantization value to the distance quantization value, and determine the ratio as the influence degree characterization value of the intersecting light source on the cell.
[0094] In this embodiment, since the number of light sources in the target light source cluster is less than or equal to the preset number, the impact of the number of light sources on the rendering performance is alleviated. When there are many light sources in the virtual scene, the rendering performance and efficiency can be improved.
[0095] In some embodiments, obtaining a target light source cluster for a cell based on light sources among multiple light sources that intersect with the cell includes: determining the intersecting light sources of the cell from the multiple light sources in sequence; the intersecting light sources of the cell refer to light sources whose projection areas of the illumination areas on a preset plane intersect with the cell; when the number of light sources included in the current light source cluster of the cell is less than a preset number, adding the intersecting light sources to the current light source cluster of the cell; returning to the step of determining the intersecting light sources of the cell from the multiple light sources in sequence until the multiple light sources are traversed; when the multiple light sources are traversed, determining the current light source cluster of the cell as the target light source cluster of the cell.
[0096] Specifically, when the number of light sources included in the current light source cluster of the cell reaches a preset number, the terminal can determine the influence degree characterization value of the intersecting light sources of the cell on the cell, and search for the first light source to be replaced from the current light source cluster of the cell, and the influence degree characterization value of the first light source to be replaced on the cell is less than the influence degree characterization value of the intersecting light source on the cell. For example, the terminal can determine the minimum influence degree characterization value from the influence degree characterization values corresponding to the current light source cluster of the cell. The influence degree characterization values refer to the influence degree characterization values of each light source in the current light source cluster of the cell for the cell. The terminal can compare the influence degree characterization value of the intersecting light source on the cell with the minimum influence degree characterization value. When the influence degree characterization value of the intersecting light source on the cell is greater than the minimum influence degree characterization value, the light source corresponding to the minimum influence degree characterization value is determined as the first light source to be replaced found. Thereby, the light source with a larger influence degree characterization value is retained in the target light source cluster of the cell, which is conducive to accurate rendering and improves the rendering effect.
[0097] In some embodiments, the terminal may remove the first light source to be replaced that is found from the current light source cluster of the cell, and add the intersecting light source to the current light source cluster of the cell, and return to the step of determining the intersecting light sources of the cell from multiple light sources in sequence until multiple light sources are traversed. When multiple light sources are traversed, the current light source cluster of the cell is determined as the target light source cluster of the cell. When the impact degree representation value of the intersecting light source on the cell is less than or equal to the minimum impact degree representation value, the terminal determines that the first light source to be replaced has not been found, and returns to the step of determining the intersecting light sources of the cell from multiple light sources in sequence.
[0098] In some embodiments, the terminal can determine candidate light sources from multiple light sources in sequence, determine cells that have an intersection relationship with the candidate light source on a preset plane from each cell of the two-dimensional grid, and when the number of light sources included in the current light source cluster of the determined cell is less than the preset number, add the candidate light source to the current light source cluster of the determined cell; when the number of light sources included in the current light source cluster of the determined cell reaches the preset number, the terminal determines an influence characterization value of the candidate light source on the determined cell, searches for a second light source to be replaced from the current light source cluster of the determined cell, the influence characterization value of the second light source to be replaced on the determined cell is less than the influence characterization value of the candidate light source on the determined cell, removes the found second light source to be replaced from the current light source cluster of the determined cell, adds the candidate light source to the current light source cluster of the determined cell, and returns to the step of determining candidate light sources from multiple light sources in sequence until multiple light sources are traversed. After traversing multiple light sources, the terminal can determine the current light source cluster of each cell in the two-dimensional grid as the target light source cluster of each cell.
[0099] Specifically, the terminal can determine the minimum influence degree characterization value from the influence degree characterization values corresponding to the current light source cluster of the determined cell. The influence degree characterization values refer to the influence degree characterization values of 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 characterization value of the candidate light source for the determined cell with the minimum influence degree characterization value. When the influence degree characterization value of the candidate light source for the determined cell is greater than the minimum influence degree characterization value, the light source corresponding to the minimum influence degree characterization value is determined as the second light source to be replaced that has been found. When the influence degree characterization value of the candidate light source for the determined cell is less than or equal to the minimum influence degree characterization value, the terminal determines that the second light source to be replaced has not been found. 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 sources with larger influence representation values are retained in the target light source cluster of the cell, which is conducive to accurate rendering and improves rendering effect.
[0100] In some embodiments, the clustering method includes at least one of a first clustering method or a second clustering method, the first clustering method is different from the second clustering method, and the first clustering method and the second clustering method are respectively applicable to a situation where there are relatively few light sources or the GPU has relatively strong parallel computing capabilities, and a situation where there are particularly many light sources or the GPU has slightly weak parallel computing capabilities. Before clustering, the terminal can determine the selected clustering method, and the selected clustering method can be automatically selected by the terminal according to the number of light sources or the GPU's parallel computing capabilities, or can be manually selected.
[0101] Among them, when the selected clustering method is the first clustering method, for each cell in the two-dimensional grid, the terminal can determine the intersecting light sources of the cell from multiple light sources in turn. The intersecting light sources of the cell refer to the light sources whose projection areas of the illumination areas on the preset plane intersect with the cell. When the number of light sources included in the current light source cluster of the cell is less than the preset number, the intersecting light sources are added to the current light source cluster of the cell, and the step of determining the intersecting light sources of the cell from multiple light sources in turn is returned until multiple light sources are traversed. When multiple light sources are traversed, the current light source cluster of the cell is determined as the target light source cluster of the cell.
[0102] Among them, when the selected clustering method is the second clustering method, the terminal can determine the candidate light source from multiple light sources in turn, determine the cells that have an intersection relationship with the candidate light source on the preset plane from each cell of the two-dimensional grid, and when the number of light sources included in the current light source cluster of the determined cell is less than the preset number, add the candidate light source to the current light source cluster of the determined cell, and return to the step of determining the candidate light source from multiple light sources in turn until multiple light sources are traversed. After traversing multiple light sources, the current light source cluster of each cell in the two-dimensional grid is determined as the target light source cluster of each cell.
[0103] In this embodiment, the target light source cluster of the cell is quickly determined by traversing the light sources, thereby improving clustering efficiency.
[0104] In some embodiments, determining a matching light source cluster that has a lighting effect on a pixel point from among the target light source clusters corresponding to each cell includes: 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 target light source cluster corresponding to the target cell as the matching light source cluster that has a lighting effect on the pixel point.
[0105] 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.
[0106] In this embodiment, the matching light source cluster having illumination influence on the pixel point is accurately determined through the projection position.
[0107] In some embodiments, the method also includes: combining the light source touch information of each light source in the matching light source cluster of the pixel point with the light source touch information of the pixel point respectively; performing shadow rendering on the virtual scene based on the light source touch information, and obtaining the shadow rendering result includes: for each pixel point in the screen space, when the matching light source cluster of the pixel point includes the light source participating in the shadow rendering, obtaining the light source touch information of the light source participating in the shadow rendering with respect to the pixel point from the cluster touch information of the pixel point; performing shadow rendering based on the light source touch information of the light source participating in the shadow rendering with respect to the pixel point, and obtaining the shadow rendering result.
[0108] Among them, the cluster reach information of the pixel point includes the light source reach information of each light source in the matching light source cluster of the pixel point for the pixel point. The cluster reach information of the pixel point is generated before shadow rendering. There can be one or more light sources participating in shadow rendering. For each light source participating in shadow rendering, shadow rendering can be performed using the method provided in this embodiment. The light source participating in shadow rendering refers to the light source actually to be drawn in the GPU delay pipeline.
[0109] Specifically, before shadow rendering, for each pixel, the terminal can combine the light source contact information of each light source in the matching light source cluster of the pixel with respect to the pixel to form the cluster contact information of the pixel. When performing shadow rendering, the light source contact information of the light source participating in shadow rendering with respect to the pixel is obtained from the cluster contact information of the pixel, and shadow rendering is performed based on the light source contact information of the light source participating in shadow rendering with respect to the pixel to obtain the shadow rendering result.
[0110] 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.
[0111] In this embodiment, the light source contact information of the light source participating in shadow rendering for the pixel point is obtained from the cluster contact information of the pixel point, so that the light source contact information can be obtained quickly, thereby improving the rendering efficiency.
[0112] In some embodiments, Figure 7 As shown, a shadow rendering method is provided, which can be executed by a terminal or jointly by a terminal and a server. The method is applied to a terminal as an example for description, and includes the following steps:
[0113] Step 702: distribute two-dimensional grids on a preset plane in the world space where the virtual scene is located.
[0114] Step 704 , clustering the multiple light sources in the virtual scene according to the cells in the two-dimensional grid to obtain target light source clusters corresponding to the cells.
[0115] There is an intersection relationship between the projection area of the illumination area of the light source in the target light source cluster on the preset plane and the corresponding cell.
[0116] Step 706 : for each pixel point in the screen space, determine a matching light source cluster having an illumination effect on the pixel point from a plurality of target light source clusters.
[0117] Step 708: for each pixel point in the screen space, determine the direction from the world space position of the pixel point to the world space position of the target light source, and obtain the ray tracing direction.
[0118] Among them, the light source reach information represents whether the target light source generates illumination for the world space position of the pixel point.
[0119] Step 710, determining the world space position of the pixel point as the starting position of the ray tracing, and determining the ending position of the ray tracing based on the ray tracing direction and the preset tracing distance.
[0120] Step 712, determining the number of ray tracing steps according to 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.
[0121] The preset tracing distance is the distance between the starting position of the ray tracing and the ending position of the ray tracing.
[0122] Step 714, starting from the world space position of the pixel point, determine multiple sampling positions along the ray tracing direction.
[0123] 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.
[0124] Step 716 : for each sampling position, determine the difference between the depth value of the sampling position and the depth value of the screen space position corresponding to the sampling position, and obtain the depth difference of the sampling position.
[0125] Step 718, obtaining the light source contact information of the target light source for the pixel point according to the depth difference of each sampling position.
[0126] Step 720, for each pixel point in the screen space, when the matching light source cluster of the pixel point includes a light source participating in shadow rendering, obtain the light source touch information of the light source participating in shadow rendering for the pixel point from the cluster touch information of the pixel point.
[0127] Step 722, shadow rendering is performed on the pixel point based on the light source contact information of the light source participating in the shadow rendering to obtain a shadow rendering result.
[0128] In this embodiment, light source reach information is determined based on ray tracing and light sources in the virtual scene are clustered. When there are many light sources in the virtual scene, shadow rendering can be quickly implemented, thereby improving shadow rendering efficiency.
[0129] The shadow rendering method provided in this application can be applied to any scene that needs to render shadows, especially scenes with many light sources, including but not limited to scenes such as film and television special effects, games, mirror simulation, visual design, VR (Virtual Reality), industrial simulation, and digital cultural creation. Through the shadow rendering method of this application, the efficiency of shadow rendering can be improved in scenes such as film and television special effects, visual design, games, mirror simulation, VR, industrial simulation, and digital cultural creation.
[0130] The shadow rendering method provided by the present application is applied to digital cultural creation, and can realize the simulation of things with cultural representative significance, especially things illuminated by more light sources. For example, it can realize the simulation of the Great Wall. There are usually more lights on the Great Wall, and lights are usually installed around the Great Wall. By rendering the shadows generated by more lights, the real lighting effect of the Great Wall under the illumination of more lights can be reflected. Specifically, for each pixel point in the screen space, the target light source corresponding to the pixel point is determined from multiple light sources in the digital Great Wall scene, and ray tracing is performed based on the world space position of the target light source and the world space position of the pixel point to obtain the light source contact information of the target light source for the pixel point, and the shadow rendering of the digital Great Wall scene is performed based on the light source contact information to obtain the shadow rendering result of the digital Great Wall. Therefore, the shadow rendering method provided by the present application not only presents the real lighting effect of the digital Great Wall under the illumination of more lights, but also improves the efficiency of shadow rendering in the digital Great Wall.
[0131] For the game scene, the terminal can determine the target light source corresponding to each pixel point in the screen space from multiple light sources in the game scene. The world space position of the pixel point in the world space where the game scene is located is located in the illumination area of the target light source corresponding to the pixel point. Ray tracing is performed based on the world space position of the target light source and the world space position of the pixel point to obtain the light source contact information of the target light source for the pixel point. The light source contact information indicates whether the target light source generates light for the world space position of the pixel point. Shadow rendering is performed on the game scene based on the light source contact information to obtain the shadow rendering result. This improves the rendering efficiency of shadows in the game scene.
[0132] For optimized rendering of VR scenes, the terminal can determine the target light source corresponding to each pixel point in the screen space from multiple light sources in the VR scene. The world space position of the pixel point in the world space where the VR scene is located is located in the illumination area of the target light source corresponding to the pixel point. Ray tracing is performed based on the world space position of the target light source and the world space position of the pixel point to obtain the light source contact information of the target light source for the pixel point. The light source contact information indicates whether the target light source generates light for the world space position of the pixel point. Shadow rendering is performed on the VR scene based on the light source contact information to obtain the shadow rendering result. This improves the rendering efficiency of shadows in VR scenes.
[0133] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0134] Based on the same inventive concept, the embodiment of the present application also provides a shadow rendering device for implementing the shadow rendering method involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in one or more shadow rendering device embodiments provided below can refer to the limitations of the shadow rendering method above, and will not be repeated here.
[0135] In some embodiments, Figure 8 As shown, a shadow rendering device is provided, including: a light source determination module 802, an information acquisition module 804 and a shadow rendering module 806, wherein:
[0136] The light source determination module 802 is used to determine, for each pixel point in the screen space, a target light source corresponding to the pixel point from multiple light sources in the virtual scene; the world space position of the pixel point in the world space where the virtual scene is located is located within the illumination area of the target light source corresponding to the pixel point.
[0137] The information acquisition module 804 is used to 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; the light source contact information indicates whether the target light source generates light for the world space position of the pixel point.
[0138] The shadow rendering module 806 is used to perform shadow rendering on the virtual scene based on the light source reach information to obtain a shadow rendering result.
[0139] In some embodiments, the information acquisition module 804 is also used to 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; determine the number of ray tracing steps according to the starting position of ray tracing and the ending position of ray tracing; perform ray tracing according to the number of ray tracing steps to obtain the light source touch information of the target light source for the pixel point.
[0140] In some embodiments, the information acquisition module 804 is also used to 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; determine the world space position of the pixel point as the starting position of the ray tracing; and determine the end position of the ray tracing based on the ray tracing direction and the preset tracing distance.
[0141] In some embodiments, the information acquisition module 804 is also used to 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; determine the tracing step factor based on the distance between the converted starting position and the converted ending position; determine the ray tracing steps according to the tracing step factor and the tracing step threshold.
[0142] In some embodiments, the information acquisition module 804 is also used to determine the ray tracing step size based on a preset tracing distance and the number of ray tracing steps; starting from the world space position of the pixel point, multiple sampling positions are determined along the ray tracing direction; the length of the interval between two adjacent sampling positions in the ray tracing direction is the ray tracing step size, and the number of sampling positions is the ray tracing steps; for each sampling position, the difference between the depth value of the sampling position and the depth value of the screen space position corresponding to the sampling position is determined to obtain the depth difference of the sampling position; according to the depth difference of each sampling position, the light source reach information of the target light source for the pixel point is obtained.
[0143] In some embodiments, the information acquisition module 804 is also used to determine a depth difference threshold based on the depth value of the starting position of the ray tracing and the depth value of the ending position of the ray tracing; when the depth difference at any sampling position is less than or equal to the depth difference threshold, the light source touch information of the target light source for the pixel point is determined to be a first preset value; the first preset value indicates that the target light source does not generate illumination for the world space position of the pixel point; when the depth difference at each sampling position is greater than the depth difference threshold, the light source touch information of the target light source for the pixel point is determined to be a second preset value; the second preset value indicates that the target light source generates illumination for the world space of the pixel point.
[0144] In some embodiments, the information acquisition module 804 is also used to determine the depth value of the starting position of the ray tracing to obtain the starting depth value, and determine the depth value of the ending position of the ray tracing to obtain the ending depth value; determine the difference between the starting depth value and the ending depth value to obtain the total depth difference; determine the depth difference threshold based on the total depth difference and the number of ray tracing steps.
[0145] In some embodiments, the light source determination module 802 is also used to distribute a two-dimensional grid on a preset plane in the world space where the virtual scene is located; cluster multiple light sources in the virtual scene according to each cell in the two-dimensional grid to obtain a target light source cluster corresponding to each cell; there is an intersection relationship between the illumination area of the light source in the target light source cluster and the projection area on the preset plane and the corresponding cell; determine a matching light source cluster that has a lighting effect on the pixel point from the target light source clusters corresponding to each cell; and determine the target light source corresponding to the pixel point from the matching light source clusters that have a lighting effect on the pixel point.
[0146] In some embodiments, the light source determination module 802 is also used to obtain a target light source cluster for each cell in the two-dimensional grid based on a light source among multiple light sources that has an intersection relationship with the cell; wherein, having an intersection relationship with the cell means that a projection area of the illumination area on a preset plane intersects with the cell, and the number of light sources in the target light source cluster is less than or equal to a preset number.
[0147] In some embodiments, the light source determination module 802 is also used to determine the intersecting light sources of the cell from multiple light sources in sequence; the intersecting light sources of the cell refer to the light sources whose projection areas of the illumination area on the preset plane intersect with the cell; when the number of light sources included in the current light source cluster of the cell is less than the preset number, the intersecting light sources are added to the current light source cluster of the cell; return to the step of determining the intersecting light sources of the cell from multiple light sources in sequence until multiple light sources are traversed; when multiple light sources are traversed, the current light source cluster of the cell is determined as the target light source cluster of the cell.
[0148] In some embodiments, the light source determination module 802 is further used to determine the cell to which the projection position of the world space position of the pixel point on the preset plane belongs, and obtain the target cell; and determine the target light source cluster corresponding to the target cell as the matching light source cluster that has an illumination effect on the pixel point.
[0149] In some embodiments, the device is also used to: combine the light source touch information of each light source in the matching light source cluster of the pixel point for the pixel point into cluster touch information of the pixel point; the shadow rendering module 806 is also used to, for each pixel point in the screen space, obtain the light source touch information of the light source participating in the shadow rendering for the pixel point from the cluster touch information of the pixel point when the matching light source cluster of the pixel point includes the light source participating in the shadow rendering; perform shadow rendering based on the light source touch information of the light source participating in the shadow rendering for the pixel point to obtain a shadow rendering result.
[0150] Each module in the above shadow rendering device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0151] In some embodiments, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Fig. 9 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data involved in the shadow rendering method. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a shadow rendering method is implemented.
[0152] In some embodiments, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Fig.10As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface, the display unit and the input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a shadow rendering method is implemented. The display unit of the computer device is used to form a visually visible image, and can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer covered on the display screen, or a button, trackball or touchpad set on the computer device casing, or an external keyboard, touchpad or mouse, etc.
[0153] Those skilled in the art will understand that Fig. 9 and Fig.10 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0154] In some embodiments, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned shadow rendering method when executing the computer program.
[0155] In some embodiments, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned shadow rendering method are implemented.
[0156] In some embodiments, a computer program product is provided, including a computer program, which implements the steps in the above shadow rendering method when executed by a processor.
[0157] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0158] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0159] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0160] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A shadow rendering method, characterized in that: The method comprises: For each pixel point in the screen space, a target light source corresponding to the pixel point is determined from multiple light sources in the virtual scene; the world space position of the pixel point in the world space where the virtual scene is located is located in the illumination area of the target light source corresponding to the pixel point; Performing ray tracing based on the world space position of the target light source and the world space position of the pixel point to obtain light source contact information of the target light source for the pixel point; the light source contact information indicates whether the target light source generates illumination for the world space position of the pixel point; Shadow rendering is performed on the virtual scene based on the light source reach information to obtain a shadow rendering result.
2. The method according to claim 1, characterized in that: The performing 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 includes: Determining a starting position of the ray tracing and an ending position of the ray tracing based on a world space position of the target light source and a world space position of the pixel point; Determining the number of ray tracing steps according to the starting position of the ray tracing and the ending position of the ray tracing; Ray tracing is performed according to the ray tracing steps to obtain light source contact information of the target light source for the pixel point.
3. The method according to claim 2, characterized in that The determining the starting position and the ending position of the ray tracing based on the world space position of the target light source and the world space position of the pixel point comprises: Determine a direction from the world space position of the pixel point to the world space position of the target light source to obtain a ray tracing direction; Determining the world space position of the pixel as the starting position of the ray tracing; The termination position of the ray tracing is determined based on the ray tracing direction and the preset tracing distance.
4. The method according to claim 3, characterized in that Determining the number of ray tracing steps according to the starting position of the ray tracing and the ending position of the ray tracing comprises: Converting the starting position of the ray tracing to the target two-dimensional space to obtain a converted starting position, and converting the ending position of the ray tracing to the target two-dimensional space to obtain a converted ending position; Determining a tracking step factor based on a distance between the converted starting position and the converted ending position; The number of ray tracing steps is determined according to the tracing step factor and the tracing step threshold.
5. The method according to claim 3, characterized in that: The performing ray tracing according to the ray tracing steps to obtain the light source contact information of the target light source for the pixel point includes: Determine a ray tracing step length based on the preset tracing distance and the ray tracing step number; Starting from the world space position of the pixel point, a plurality of sampling positions are determined along the ray tracing direction; 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 the sampling positions is the ray tracing step number; For each of the sampling positions, determining a difference between a depth value of the sampling position and a depth value of a screen space position corresponding to the sampling position, to obtain a depth difference value of the sampling position; According to the depth difference of each of the sampling positions, light source contact information of the target light source for the pixel point is obtained.
6. The method according to claim 5, characterized in that The obtaining, according to the depth difference of each sampling position, the light source contact information of the target light source for the pixel point comprises: Determining a depth difference threshold based on a depth value at a starting position of the ray tracing and a depth value at a terminating position of the ray tracing; When the depth difference at any of the sampling positions is less than or equal to the depth difference threshold, determining that the light source contact information of the target light source for the pixel point is a first preset value; the first preset value indicates that the target light source does not generate illumination for the world space position of the pixel point; When the depth difference at each sampling position is greater than the depth difference threshold, it is determined that the light source reach information of the target light source for the pixel point is a second preset value; the second preset value represents that the target light source generates illumination for the world space of the pixel point.
7. The method according to claim 6, characterized in that The determining of the depth difference threshold based on the depth value of the starting position of the ray tracing and the depth value of the ending position of the ray tracing comprises: Determine the depth value of the starting position of the ray tracing to obtain a starting depth value, and determine the depth value of the ending position of the ray tracing to obtain an ending depth value; Determine the difference between the starting depth value and the ending depth value to obtain a total depth difference; A depth difference threshold is determined based on the total depth difference value and the number of ray tracing steps.
8. The method according to any one of claims 1 to 7, characterized in that: The step of determining the target light source corresponding to the pixel point from a plurality of light sources in the virtual scene comprises: Distributing a two-dimensional grid on a preset plane in the world space where the virtual scene is located; Clustering the multiple light sources in the virtual scene according to the cells in the two-dimensional grid to obtain target light source clusters corresponding to the cells; an illumination area of the light source in the target light source cluster has an intersection relationship with a projection area on the preset plane and the corresponding cell; Determine a matching light source cluster having an illumination effect on the pixel point from the target light source clusters corresponding to each of the cells; A target light source corresponding to the pixel point is determined from a matching light source cluster having an illumination influence on the pixel point.
9. The method according to claim 8, characterized in that The clustering of the multiple light sources in the virtual scene according to each cell in the two-dimensional grid to obtain the target light source clusters corresponding to each cell includes: For each cell in the two-dimensional grid, based on light sources among the multiple light sources that have an intersection relationship with the cell, a target light source cluster of the cell is obtained; The existence of an intersection relationship with the cell means that a projection area of the illumination area on the preset plane intersects with the cell, and the number of light sources in the target light source cluster is less than or equal to a preset number.
10. The method according to claim 9, characterized in that The obtaining of the target light source cluster of the cell based on the light sources intersecting with the cell among the plurality of light sources comprises: Determining the intersecting light sources of the cell from the multiple light sources in sequence; the intersecting light sources of the cell refer to the light sources whose projection areas of the illumination areas on the preset plane intersect with the cell; When the number of light sources included in the current light source cluster of the cell is less than the preset number, adding the intersecting light source to the current light source cluster of the cell; Returning to the step of sequentially determining the intersecting light sources of the cell from the multiple light sources until the multiple light sources are traversed; In the case of traversing the multiple light sources, the current light source cluster of the cell is determined as the target light source cluster of the cell.
11. The method according to claim 8, characterized in that The step of determining the matching light source cluster having illumination influence on the pixel point from the target light source clusters respectively corresponding to the cells comprises: Determine the cell to which the projection position of the world space position of the pixel point on the preset plane belongs, and obtain the target cell; The target light source cluster corresponding to the target cell is determined as a matching light source cluster having an illumination influence on the pixel point.
12. The method according to claim 8, characterized in that The method further comprises: Combining the light source contact information of each light source in the matching light source cluster of the pixel point with respect to the pixel point into the cluster contact information of the pixel point; The shadow rendering of the virtual scene based on the light source reach information to obtain the shadow rendering result includes: For each pixel point in the screen space, when the matching light source cluster of the pixel point includes a light source participating in shadow rendering, obtaining 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; Shadow rendering is performed based on the light source contact information of the pixel point of the light source participating in the shadow rendering to obtain a shadow rendering result.
13. A shadow rendering device, characterized in that: The device comprises: A light source determination module is used to determine, for each pixel point in the screen space, a target light source corresponding to the pixel point from multiple light sources in the virtual scene; the world space position of the pixel point in the world space where the virtual scene is located is located in the illumination area of the target light source corresponding to the pixel point; an information obtaining module, configured to 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 light source contact information of the target light source for the pixel point; the light source contact information indicates whether the target light source generates illumination for the world space position of the pixel point; A shadow rendering module is used to perform shadow rendering on the virtual scene based on the light source reach information to obtain a shadow rendering result.
14. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 12 are implemented.
15. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 12 are implemented.
16. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 12 are implemented.
Citation Information
Cited By
Shadow rendering method and apparatus, computer device, and storage medium
EP4632682A1
