Shadow processing method and device based on virtual scene, equipment and storage medium
By generating distance field information for virtual scenes, the problem of low efficiency in shadow baking is solved, and efficient shadow effect representation is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2023-05-25
- Publication Date
- 2026-07-31
AI Technical Summary
In the existing technology, the quality of the shadow map depends on its size during the shadow baking process. When the size is large, the baking time is too long, making it impossible to balance baking efficiency and shadow effect.
By generating distance field information for the virtual scene, indicating the minimum distance between each location point and the shadow boundary, the traditional shadow map is used to represent shadows, thus improving baking efficiency.
While maintaining the shadow effect, the size requirement of the shadow map was reduced, and the efficiency of shadow baking was improved.
Smart Images

Figure CN119027570B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of graphics processing technology, and in particular to a shadow processing method, apparatus, device and storage medium based on virtual scenes. Background Technology
[0002] In the development of applications that run virtual scenes, shadow baking is an important step in developing the shadow effects of that virtual scene.
[0003] In related technologies, shadow baking is usually based on the element models and lightmaps in the virtual scene to generate a shadow map in the UV space. The pixel value of each pixel in the shadow map is used to indicate whether the position point of that pixel in the virtual scene is in the shadow area.
[0004] However, in the above scheme, the quality of the shadow map depends on the size of the shadow map. When the size of the shadow map is large, it will result in a long baking time, thus making it impossible to balance baking efficiency and shadow effect. Summary of the Invention
[0005] This application provides a shadow processing method, apparatus, device, and storage medium based on a virtual scene, which can improve baking efficiency while ensuring shadow effects. The technical solution is as follows:
[0006] On the one hand, a shadow processing method based on a virtual scene is provided, the method comprising:
[0007] Acquire first scene data of the virtual scene, which includes scene elements, light sources, and light maps in the virtual scene;
[0008] Based on the scene data, shadow information of the virtual scene is generated; the shadow information is used to indicate the position of shadows in the virtual scene.
[0009] The distance field information of the virtual scene is generated based on the shadow information; the distance field information is used to indicate the minimum distance between each position point in the virtual scene and the boundary of the shadow in the virtual scene; the distance field information is used to generate the shadow in the scene when rendering the scene of the virtual scene.
[0010] On the one hand, a shadow processing method based on a virtual scene is provided, the method comprising:
[0011] Acquire second scene data of the virtual scene, including the shadow map of the virtual scene; the shadow map is the distance field information of the virtual scene, and the distance field information is used to indicate the minimum distance between each position point in the virtual scene and the boundary of the shadow in the virtual scene;
[0012] Based on the distance field information, the shadow position in the virtual scene is obtained;
[0013] Based on the shadow positions in the virtual scene, a scene image of the virtual scene is rendered, and the scene image contains shadows.
[0014] On the other hand, a shadow processing device based on a virtual scene is provided, the device comprising:
[0015] The scene data acquisition module is used to acquire the first scene data of the virtual scene, which includes scene elements, light sources and light maps in the virtual scene.
[0016] A shadow information acquisition module is used to generate shadow information of the virtual scene based on the scene data; the shadow information is used to indicate the position of shadows in the virtual scene.
[0017] The distance field acquisition module is used to generate distance field information of the virtual scene based on the shadow information; the distance field information is used to indicate the minimum distance between each position point in the virtual scene and the boundary of the shadow in the virtual scene; the distance field information is used to generate the shadow in the scene image when rendering the scene image of the virtual scene.
[0018] In one possible implementation, the shadow information includes a grayscale image obtained by unfolding the shadows in the virtual scene in UV space; the grayscale value of each pixel in the grayscale image is used to indicate the percentage of the shadow portion in the region corresponding to the pixel.
[0019] The distance field acquisition module is used for,
[0020] Based on the grayscale image, calculate the minimum distance between the center of each pixel in the grayscale image and the boundary of the shadow in the grayscale image;
[0021] The distance field information is generated based on the minimum distance between the center of each pixel in the grayscale image and the boundary of the shadow in the grayscale image.
[0022] In one possible implementation, the distance field acquisition module is used to calculate, for a first pixel in the grayscale image with a grayscale value greater than 0 and less than 1, the minimum distance between the center of the pixel and the boundary of the shadow in the grayscale image based on the grayscale value of the pixel.
[0023] In one possible implementation, the distance field acquisition module is used to obtain, for a second pixel in the grayscale image with a grayscale value equal to 0 or 1, the minimum distance between the center of the second pixel and the boundary of the shadow in the grayscale image by updating distance information through neighboring pixels.
[0024] In one possible implementation, the distance field acquisition module is used to obtain the minimum distance between the center of the second pixel and the boundary of the shadow in the grayscale image by updating distance information through neighboring pixels based on the light map, so that the distance information is updated to adjacent pixels on the same object surface.
[0025] In one possible implementation, the device further includes:
[0026] A seam information acquisition module is used to acquire seam information of the grayscale image, wherein the seam information is used to indicate the pixel point at the location of the corresponding seam in the grayscale image;
[0027] Jump information is generated based on the seam information. The jump information is used to indicate the jump relationship between pixels that are not adjacent in the grayscale image but are adjacent in the virtual scene.
[0028] In one possible implementation, the distance field acquisition module is configured to, in response to the second pixel being a non-adjacent pixel in the grayscale image but adjacent in the virtual scene, update the neighboring pixels of the second pixel based on the jump information, and then obtain the minimum distance between the center of the second pixel and the boundary of the shadow in the grayscale image by updating the distance information of the neighboring pixels.
[0029] In one possible implementation, the shadow information acquisition module is used to,
[0030] The virtual scene is constructed based on the first scene data;
[0031] Based on the constructed virtual scene, the shadow positions in the virtual scene are obtained by ray detection.
[0032] The shadow information is generated based on the shadow position in the virtual scene.
[0033] In one possible implementation, the shadow information acquisition module is used to,
[0034] Based on the first position point in the virtual scene, obtain the vertex position and normal information of the triangle face where the first position point is located, and obtain the second position point on the smooth surface of the triangle face corresponding to the first position point;
[0035] Ray detection is performed starting from the second location point to determine whether the first location point belongs to a shadow location in the virtual scene.
[0036] In one possible implementation, the shadow information acquisition module is used to,
[0037] Unfold the geometry in the virtual scene in the lightmap space to obtain the pixel coordinates of the geometry in the lightmap space;
[0038] Based on the pixel coordinates of the geometry in the lightmap space, the shadow position in the virtual scene is obtained by ray detection.
[0039] On the other hand, a shadow processing device based on a virtual scene is provided, the device comprising:
[0040] The scene data acquisition module is used to acquire second scene data of the virtual scene, namely the shadow map of the virtual scene; the shadow map is the distance field information of the virtual scene, and the distance field information is used to indicate the minimum distance between each position point in the virtual scene and the boundary of the shadow in the virtual scene;
[0041] The shadow position acquisition module is used to acquire the shadow position in the virtual scene based on the distance field information;
[0042] The rendering module is used to render a scene image of the virtual scene based on the shadow positions in the virtual scene, the scene image containing shadows.
[0043] On the other hand, a computer device is provided, the computer device including a processor and a memory, the memory storing at least one computer instruction, the at least one computer instruction being loaded and executed by the processor to implement the above-described shadow processing method based on a virtual scene.
[0044] On the other hand, a computer-readable storage medium is provided, wherein at least one computer instruction is stored in the computer-readable storage medium, the computer instruction being loaded and executed by a processor to implement the above-described shadow processing method based on a virtual scene.
[0045] On the other hand, a computer program product or computer program is provided, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the virtual scene-based shadow processing method provided in the various optional implementations described above.
[0046] The technical solution provided in this application may include the following beneficial effects:
[0047] During the shadow baking process, distance field information for representing shadows is generated based on the shadow information in the virtual scene. In other words, the shadow map is stored by a distance field that indicates the minimum distance between each position point in the virtual scene and the boundary of the shadow in the virtual scene. Since the distance field does not directly represent the shadow through pixel values, but through distance information, it can represent high-quality shadow maps without requiring large-size shadow maps, thereby improving baking efficiency while ensuring shadow effects. Attached Figure Description
[0048] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0049] Figure 1 This is a schematic diagram of a system according to an exemplary embodiment of this application;
[0050] Figure 2 This is a flowchart illustrating a shadow processing method based on a virtual scene, as shown in an exemplary embodiment of this application;
[0051] Figure 3 This is a flowchart illustrating a shadow processing method based on a virtual scene, as shown in an exemplary embodiment of this application;
[0052] Figure 4 This is a schematic diagram of the overall baking process involved in the embodiments of this application;
[0053] Figure 5 This is a schematic diagram illustrating the shading error involved in this application;
[0054] Figure 6 This is a schematic diagram illustrating the determination of the starting point for X-ray detection involved in this application;
[0055] Figure 7 This is a diagram showing the effect of the correction of the X-ray detection starting point involved in this application;
[0056] Figure 8 This is a schematic diagram of SDF generation involved in this application;
[0057] Figure 9 This is a schematic diagram of the shaded seam involved in an embodiment of this application;
[0058] Figure 10 This is a schematic diagram of the shaded seam involved in an embodiment of this application;
[0059] Figure 11 This is a schematic diagram of the SDF shaded seam involved in the embodiments of this application;
[0060] Figure 12 These are the revised renderings related to this application;
[0061] Figure 13 This is a flowchart illustrating a shadow processing method based on a virtual scene, as shown in an exemplary embodiment of this application;
[0062] Figures 14 to 16 These are renderings showing the effects of using the baking technology proposed in this application in some game scenes;
[0063] Figure 17 This is a block diagram of a shadow processing apparatus based on a virtual scene provided in one embodiment of this application;
[0064] Figure 18 This is a block diagram of a shadow processing apparatus based on a virtual scene provided in one embodiment of this application;
[0065] Figure 19 A structural block diagram of a computer device illustrated in an exemplary embodiment of this application is shown. Detailed Implementation
[0066] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0067] It should be understood that "multiple" as used in this article refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.
[0068] This application provides a method for shadow baking and shadow rendering in a virtual scene. For ease of understanding, the following explains several terms used in this application.
[0069] 1) SDF: Full name Signed Distance Field, a directed distance field that stores the nearest distance from each point to the graphic. It is often used for vector font rendering in game development.
[0070] 2) Phong Tessellation: Modern 3D engines used in real-time applications provide shadows, employing modulated normals, textures, and tone mapping to hide the lack of high-order continuity within shapes—artifacts are only preserved on internal contours and outlines if the surface geometry is not smooth. The basic idea of this paper is to apply a purely local refinement strategy, causing the geometry to dilate sufficiently to avoid these artifacts. Our technique is a geometric version of Phong normal interpolation, applied not to the normals but to the vertex locations. We call this strategy Phong Tessellation.
[0071] 3) OptiX: A GPU-accelerated ray detection library, first developed around 2009. Computation is offloaded to the GPU through low-level or high-level Application Programming Interfaces (APIs) introduced by Compute Unified Device Architecture (CUDA). OptiX is an "algorithm" API, meaning it is designed to encapsulate entire algorithms, with ray detection being a part of it, not just ray detection itself. This means the OptiX engine can execute larger algorithms with great flexibility without requiring changes to the application side.
[0072] 4) Shadow Mask: In blended lighting mode, it can bake the shadows of objects and automatically blend real-time shadows.
[0073] Figure 1 This illustration shows a schematic diagram of the system used in the shadow processing method based on a virtual scene provided in an exemplary embodiment of this application, such as... Figure 1 As shown, the system includes: server 110 and terminal 120.
[0074] Among them, the aforementioned server 110 can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.
[0075] The aforementioned terminal 120 can be a terminal device with network connectivity and data processing capabilities. For example, terminal 120 can be a smartphone, tablet computer, e-book reader, smart glasses, smartwatch, smart TV, laptop computer, desktop computer, etc.
[0076] Optionally, the system described above includes one or more servers 110 and multiple terminals 120. This application embodiment does not limit the number of servers 110 and terminals 120.
[0077] The terminal and server are connected via a communication network. Optionally, the communication network can be a wired network or a wireless network.
[0078] The aforementioned terminals and / or servers may store / run tools for shadow baking (such as virtual engines and virtual engine plugins), applications that run virtual scenes, etc.
[0079] For example, the aforementioned application can be configured in the server 110. The terminal 120 can upload the scene data that needs to be baked in the virtual scene to the server 110. After the server 110 performs shadow baking, it returns the baking result to the terminal 120.
[0080] For example, the server 110 may be equipped with an application installation package, and the terminal 120 may download the application installation package from the server 110 and install the application; subsequently, the terminal 120 may use the application to perform shadow baking, or the terminal 120 may use the application to run a virtual scene.
[0081] Figure 1 Only one terminal is shown, but in different embodiments, multiple other terminals can access server 110. Optionally, one or more terminals may also be terminals corresponding to developers, on which a development and editing platform for developing the aforementioned application is installed. Developers can edit and update the aforementioned application on the terminal and transmit the updated application installation package to server 110 via wired or wireless network. Terminal 120 can download the application installation package from server 110 to update the application.
[0082] Optionally, the aforementioned wireless or wired networks use standard communication technologies and / or protocols. The network is typically the Internet, but can also be any network, including but not limited to Local Area Networks (LANs), Metropolitan Area Networks (MANs), Wide Area Networks (WANs), mobile, wired or wireless networks, private networks, or any combination of virtual private networks. In some embodiments, technologies and / or formats including Hyper Text Markup Language (HTML), Extensible Markup Language (XML), etc., are used to represent data exchanged over the network. Conventional encryption technologies such as Secure Socket Layer (SSL), Transport Layer Security (TLS), Virtual Private Networks (VPNs), and Internet Protocol Security (IPsec) can also be used to encrypt all or some links. In other embodiments, customized and / or dedicated data communication technologies can be used to replace or supplement the aforementioned data communication technologies. This application does not impose any limitations.
[0083] Figure 2 The present application illustrates a flowchart of a shadow processing method based on a virtual scene, as shown in an exemplary embodiment. This method is executed by a computer device, which can be implemented as a terminal or a server. Figure 1 The terminal 120 or server 110 shown, such as Figure 2 As shown, this shadow processing method based on a virtual scene includes the following steps:
[0084] Step 210: Obtain the first scene data of the virtual scene, which includes scene elements, light sources, and light maps in the virtual scene.
[0085] In this embodiment of the application, when performing shadow baking offline, the computer device can export scene data such as scene elements, light sources, light maps, and materials in the virtual scene.
[0086] For example, developers can use a virtual engine to develop virtual scenes. When performing shadow baking, the computer device first exports scene data such as scene elements, light sources, light maps, and materials from the virtual engine so that shadow baking can be performed later through a baker.
[0087] The aforementioned scene elements may include model information of various elements in the virtual scene. This model information may include model data, such as the position of the model in the virtual scene, the vertex coordinates and normal directions of each triangle facet in the model, etc.
[0088] The elements in the aforementioned virtual scene may include virtual objects, virtual animals, virtual characters, virtual buildings, virtual vegetation, and other elements.
[0089] The data for the light sources in the aforementioned virtual scene may include the position, shape, and size of the light sources in the virtual scene.
[0090] Step 220: Based on the scene data, generate shadow information for the virtual scene; the shadow information is used to indicate the position of shadows in the virtual scene.
[0091] In one possible implementation, the aforementioned shadow position may include the position information of the shadow in the virtual scene, such as the coordinate information of the shadow in the virtual scene.
[0092] In another possible implementation, the shadow position mentioned above can include the position information of the shadow in the virtual scene after it is unfolded into the UV space, such as the pixel coordinates of the shadow in the virtual scene after it is unfolded into the UV space.
[0093] Step 230: Generate distance field information of the virtual scene based on shadow information; the distance field information is used to indicate the minimum distance between each position point in the virtual scene and the boundary of the shadow in the virtual scene; the distance field information is used to generate shadows in the scene when rendering the scene of the virtual scene.
[0094] In this embodiment, a distance field is used instead of the shadow map obtained by the traditional baking process. Since the distance field only requires a small amount of data to accurately indicate the shadow position in the virtual scene, the amount of data that the baking process needs to process is smaller than that of the traditional shadow map, which can effectively improve the baking efficiency.
[0095] The aforementioned distance field information can be SDF information.
[0096] In summary, the solution shown in this application generates distance field information to represent shadows based on shadow information in the virtual scene during the shadow baking process. That is, the shadow map is stored by a distance field that indicates the minimum distance between each position point in the virtual scene and the boundary of the shadow in the virtual scene. Since the distance field does not directly represent the shadow through pixel values, but through distance information, it can represent high-quality shadow maps without requiring large-size shadow maps, thereby improving baking efficiency while ensuring shadow effects.
[0097] Figure 3 A flowchart illustrating a shadow processing method based on a virtual scene provided in an exemplary embodiment of this application is shown. This method can be executed by a computer device. That is, in Figure 2 In the illustrated embodiment, step 220 can be implemented as steps 220a to 220c, and step 230 can be implemented as steps 230a and 230b:
[0098] Step 220a: Construct a virtual scene based on the first scene data.
[0099] In this embodiment of the application, during the shadow baking process, the computer device can first construct a virtual scene based on the first scene data, including constructing various scene elements in the virtual scene, and then importing the constructed virtual scene into the baking program.
[0100] Step 220b: Based on the constructed virtual scene, obtain the shadow positions in the virtual scene using raycasting.
[0101] In this embodiment of the application, the computer device can obtain the shadow position in the virtual scene by using a baking program and ray detection.
[0102] For example, a computer device emits light from a point on a scene element in a virtual scene towards a light source in the virtual scene. If the light is occluded by geometry in the virtual scene, then the point is determined to be within the shadow of the virtual scene, meaning that the point belongs to the shadow position in the virtual scene.
[0103] In one possible implementation, based on the constructed virtual scene, the shadow positions in the virtual scene are obtained through raycasting, including:
[0104] Based on the first position point in the virtual scene, obtain the vertex position and normal information of the triangle face where the first position point is located, and obtain the second position point on the smooth surface of the triangle face corresponding to the first position point;
[0105] Ray detection is performed starting from the second location point to determine whether the first location point belongs to a shadow location in the virtual scene.
[0106] In virtual scenes, the models of three-dimensional scene elements are usually composed of several triangles. The accuracy of the model depends on the size of the triangles that make up the model. The larger the size of the triangles, the lower the accuracy of the model.
[0107] During raycasting, if raycasting is triggered directly from the model surface (that is, using the points on the triangular surface of the model as the starting point for raycasting), it will cause the edges of the shadows to appear jagged, and the larger the size of the triangle, the stronger the jaggedness.
[0108] In this embodiment, during ray detection, the computer device can calculate the position point B on the smooth surface corresponding to the triangle containing position point A on the surface of the scene element, based on the vertex position and normal information of the triangle. For example, the position point B on the smooth surface can be calculated using the Phong Tessellation algorithm, and ray detection can begin from position point B. This approach can simulate the starting point of ray detection as accurately as possible, improving the accuracy of ray detection, reducing the jaggedness of shadow edges, and thus improving shadow quality.
[0109] In one possible implementation, based on the constructed virtual scene, the shadow positions in the virtual scene are obtained through raycasting, including:
[0110] Unfold the geometry in the virtual scene in the lightmap space to obtain the pixel coordinates of the geometry in the lightmap space;
[0111] Based on the pixel coordinates of the geometry in the lightmap space, the shadow position in the virtual scene is obtained through ray detection.
[0112] The computer device can unfold the geometry in the virtual scene in the lightmap space using a GPU-accelerated ray detection library, obtain the pixel coordinates of the geometry in the lightmap space, and then perform ray detection in the lightmap space from the pixel coordinates of the geometry to obtain the shadow position in the virtual scene, thereby improving the efficiency of ray detection.
[0113] For example, the aforementioned GPU-accelerated ray detection library could be a ray detection library such as OptiX.
[0114] Step 220c: Generate shadow information based on the shadow position in the virtual scene; the shadow information includes a grayscale image obtained by unfolding the shadow position in the virtual scene in UV space.
[0115] In the grayscale image above, the grayscale value of each pixel is used to indicate the percentage of the shadow area in the corresponding region of the pixel.
[0116] In this embodiment of the application, each pixel in the grayscale image can correspond to multiple adjacent location points in the virtual scene. Correspondingly, the grayscale value of each pixel in the grayscale image can be the proportion of the location points belonging to the shadow area among the multiple location points. That is to say, the grayscale value of each pixel in the grayscale image is in the range of 0 to 1. A value range of 0 indicates that none of the location points corresponding to the pixel belong to the shadow area, and a value range of 0 indicates that all the location points corresponding to the pixel belong to the shadow area.
[0117] In this embodiment of the application, the computer device reconstructs a virtual scene and performs light detection in the reconstructed virtual scene to obtain the accurate position of the shadow in the virtual scene, thereby ensuring the accuracy of the subsequent representation of the shadow position by the distance field.
[0118] Step 230a: Based on the grayscale image, calculate the minimum distance between the center of each pixel in the grayscale image and the boundary of the shadow in the grayscale image.
[0119] In this embodiment of the application, the computer device can convert a grayscale image into a directed distance field (SDF).
[0120] In one possible implementation, based on the grayscale image, the minimum distance between the center of each pixel in the grayscale image and the boundary of the shadow in the grayscale image is calculated, including:
[0121] For the first pixel in a grayscale image with a grayscale value greater than 0 and less than 1, calculate the minimum distance between the center of the pixel and the boundary of the shadow in the grayscale image based on the grayscale value of the pixel.
[0122] In this embodiment of the application, for a first pixel with a gray value greater than 0 and less than 1, since the boundary of the shadow is located inside the first pixel, the computer device can calculate the minimum distance between the center of the first pixel and the boundary of the shadow in the grayscale image by using the gray value of the first pixel.
[0123] Since grayscale values are used to indicate the percentage of the shadow area in the region corresponding to a pixel, when the grayscale value of the first pixel is greater than 0 and less than 1, it means that part of the region of the first pixel is a shadow area and the other part is a non-shadow area. Assuming that the region corresponding to the first pixel is a square region, and assuming that the boundary of the shadow is parallel to one side of the square region, then given the grayscale value, the vertical distance between the center point of the first pixel and the boundary of the shadow can be calculated geometrically. This vertical distance is the minimum distance between the center of the first pixel and the boundary of the shadow in the grayscale image.
[0124] Alternatively, it can be assumed that the boundary of the shadow is parallel to the diagonal of the square region. In this case, the vertical distance between the center point of the first pixel and the boundary of the shadow can also be calculated using geometric methods.
[0125] The above method provides a way to directly calculate the minimum distance between the pixel containing the shadow boundary and the shadow boundary using grayscale values, ensuring the accuracy of the subsequent representation of the shadow position using distance field information.
[0126] In one possible implementation, based on the grayscale image, the minimum distance between the center of each pixel in the grayscale image and the boundary of the shadow in the grayscale image is calculated, including:
[0127] For the second pixel in the grayscale image with a grayscale value of 0 or 1, the minimum distance between the center of the second pixel and the boundary of the shadow in the grayscale image is obtained by updating the distance information of neighboring pixels.
[0128] In this embodiment of the application, for a second pixel with a grayscale value of 0 or 1, since the boundary of the shadow is outside the first pixel, the computer device needs to find the pixel closest to the second pixel and containing the boundary of the shadow by jumping to neighboring pixels, and then calculate the minimum distance between the center of the second pixel and the boundary of the shadow in the grayscale image. This process can be called "nearby pixel update distance information".
[0129] In one possible implementation, during the process of "updating distance information for neighboring pixels", the computer device can start from a pixel with a grayscale value greater than 0 and less than 1 and jump to neighboring pixels in sequence. At the same time, the distance between the current pixel and the boundary of the shadow in the grayscale image is accumulated to the pixel that has been jumped to, thereby obtaining the minimum distance between each pixel and the boundary of the shadow in the grayscale image.
[0130] The above scheme provides a method to indirectly calculate the minimum distance between a pixel that does not contain a shadow boundary and the shadow boundary by updating distance information through neighboring pixels, thus ensuring the accuracy of the subsequent representation of the shadow position using distance field information.
[0131] In one possible implementation, for a second pixel in a grayscale image with a grayscale value of 0 or 1, the minimum distance between the center of the second pixel and the boundary of the shadow in the grayscale image is obtained by updating distance information through neighboring pixels, including:
[0132] Based on light mapping, the minimum distance between the center of the second pixel and the boundary of the shadow in the grayscale image is obtained by updating distance information through neighboring pixels, so that the distance information is updated to the adjacent pixels on the same object surface.
[0133] In this embodiment, since virtual elements in a virtual scene may be isolated from each other, and after the geometry of a virtual element is unfolded into the lightmap space, one or more pixels corresponding to that virtual element in the lightmap space may be adjacent to pixels that do not belong to that virtual element. For the aforementioned pixels, if during the "nearby pixel distance information update" process, a jump is made directly to an adjacent pixel, and the adjacent pixel does not belong to the same pixel element as the current pixel, then the minimum distance calculation between the pixel and the boundary of the shadow in the grayscale image will occur, resulting in errors in the shadows generated during subsequent rendering. To address this, the computer device can, based on the lightmap, control the jumps between pixels to be performed on adjacent pixels corresponding to the same object surface during the "nearby pixel distance information update" process. That is, during the jump from one pixel to another, the jump is made to an adjacent pixel belonging to the same object surface, thereby improving the accuracy of representing the shadow position through distance field information and ensuring the accuracy of the shadows generated during subsequent rendering.
[0134] In one possible implementation, the above method also includes:
[0135] Obtain the seam information of the grayscale image. The seam information is used to indicate the pixel point at the location of the corresponding seam in the grayscale image.
[0136] Jump information is generated based on seam information. Jump information is used to indicate the jump relationship between pixels that are not adjacent in the grayscale image but are adjacent in the virtual scene.
[0137] For the second pixel in the grayscale image, where the grayscale value is 0 or 1, the minimum distance between the center of the second pixel and the boundary of the shadow in the grayscale image is obtained by updating distance information through neighboring pixels, including:
[0138] In response to the fact that the second pixel is a non-adjacent pixel in the grayscale image but an adjacent pixel in the virtual scene, after updating the neighboring pixels of the second pixel based on the jump information, the minimum distance between the center of the second pixel and the boundary of the shadow in the grayscale image is obtained by updating the distance information of the neighboring pixels.
[0139] In this embodiment, seams are generated when the geometry of a virtual element is unfolded into the lightmap space. That is, in the grayscale image, two adjacent pixels at the seam position may not be adjacent in the virtual scene. In this embodiment, when the computer device performs the "nearby pixel update distance information" process, it can determine the jump relationship between the pixels corresponding to the seam position based on the seam information. When jumping from one pixel at the seam position to another pixel, the jump can be performed according to the jump relationship between the pixels corresponding to the seam position. This ensures the accuracy of calculating the minimum distance between the pixel in the grayscale image and the shadow boundary, thereby improving the accuracy of representing the shadow position through the distance field information and ensuring the accuracy of the shadow generated in the subsequent rendering process.
[0140] The aforementioned jump information may include the correspondence between each pixel located at the seam in the grayscale image and its non-adjacent pixels in the grayscale image but adjacent pixels in the virtual scene. Optionally, the correspondence can be represented by the correspondence between the coordinates of two pixels in the grayscale image.
[0141] Step 230b: Generate distance field information based on the minimum distance between the center of each pixel in the grayscale image and the boundary of the shadow in the grayscale image.
[0142] In this embodiment of the application, during the process of shadow baking, after obtaining the position of the shadow in the virtual scene, the computer device unfolds the position of the shadow in the three-dimensional virtual scene into the UV space to obtain a grayscale image representing the position of the shadow in the UV space, and then generates distance field information representing the position of the shadow from the grayscale image. This realizes the transformation of the position of the shadow in the three-dimensional virtual scene into distance field information based on the two-dimensional coordinate system of UV space, thereby greatly compressing the space required to store the position of the shadow in the three-dimensional virtual scene.
[0143] After generating the aforementioned distance field information, the computer device can use this distance field information as a shadow map of the virtual scene and import it into the virtual engine so that developers can use the shadow map for subsequent development processes.
[0144] Please refer to Figure 4 This illustrates a schematic diagram of the overall baking process involved in an embodiment of this application. Figure 4 As shown, taking Unity engine as an example, the process can be arbitrarily as follows:
[0145] S41, Export Scene.
[0146] First, the computer device exports the scene, along with various materials, light sources, and lightmap information from Unity.
[0147] S42, Baking.
[0148] Then, the computer device launches the baker process to read the exported information.
[0149] S43, Import Scene.
[0150] Then, the computer equipment builds the scene and various necessary node data in the baking process.
[0151] S44, Create a light detection library scene.
[0152] Then, the computer device creates a ray detection library scene using the ray detection library.
[0153] S45, detect shadows.
[0154] The computer device performs ray detection to calculate shadows in a ray detection library scene and generates multiple ray detection results by offsetting the position within pixels.
[0155] S46, generate SDF.
[0156] The computer equipment calculates the grayscale value based on the ray detection results of the shadow detection and finally generates an SDF image.
[0157] S47, Repairing seams.
[0158] During or after the computer equipment calculates the grayscale image and generates the SDF image, it can repair the seam position through jump information or other means.
[0159] S48, output shadow map.
[0160] The computer device outputs the above SDF image as a shadow map to Unity.
[0161] S49, the virtual engine outputs shadow maps.
[0162] Computer equipment outputs shadow maps through a virtual engine for real-time rendering during subsequent virtual scene display.
[0163] exist Figure 4 In this context, the process of calculating shadow rays is as follows:
[0164] This step requires generating a grayscale image of the shadow, which means constructing a detection ray for each pixel in the Lightmap. If the ray is blocked, it means the pixel is in the shadow; otherwise, it is outside the shadow.
[0165] In the above steps, the most important thing is how to determine the starting point of the ray. The approach of this solution is to construct another set of geometry in Optic. The coordinates of these geometry are unfolded in Lightmap space. Therefore, we can first construct a ray using pixel coordinates to perform ray detection on these geometry in Lightmap space, and then calculate its position in world space based on the detected triangular faces and the transformation matrix of the object.
[0166] Another issue with ray initiation is the Bias / Terminator; please refer to [reference needed]. Figure 5 The diagram showing the shadow error indicates that if the detection starts directly from the coordinates on the triangular face, a clear shadow error 51 will appear on the curved surface.
[0167] This is because the triangular facet-based data structure is itself an approximation of the surface; therefore, directly constructing rays from the positional information of the triangular faces is inaccurate. Please refer to [reference needed]. Figure 6 The diagram showing the determination of the starting point for X-ray detection is as follows: Figure 7 The image shown is an example of the effect after the correction of the ray detection starting point. Figure 6 As shown, the model surface in the virtual scene is composed of several triangular facets. This scheme calculates the position 63 of a smooth sphere based on the vertex positions 61 and normal information 62 of the triangular facets using the Phong Tessellation algorithm, and uses the position of the smooth sphere as the starting point for ray detection. Figure 7 As shown, the shadow position 71 obtained after the ray detection starting point correction is smoother.
[0168] Please refer to Figure 8 The above-mentioned SDF generation diagram illustrates the process. Figure 4 The process of generating SDF (Signed Distance Field) is as follows:
[0169] After obtaining the shadow information represented by grayscale values, distance information can be inferred from these grayscale values. The distance inferred from grayscale values is within a single pixel. For pixels on the boundary, the correct distance value can be obtained. However, for pixels completely within or outside the boundary, we need to search for surrounding pixels to find the nearest boundary and calculate the distance value. The distance information is updated by using neighboring pixels, and the number of iterations is limited by a maximum distance. During the iterative update process, information from the light map is used to ensure that only distance information on the same object surface is updated to surrounding pixels.
[0170] Seam issues are one of the most common problems in Lightmap baking. Please refer to [link / reference]. Figure 9 This illustrates a schematic diagram of a shaded seam according to an embodiment of this application. Figure 9As shown, seam 91 is caused by the fact that when an object's surface is unfolded onto a Lightmap, it may have spatial continuity but not UV discontinuity. Moreover, due to the interpolation sampling when using the Lightmap, even if each pixel obtains a completely consistent and correct baking result, seams will still occur. This is because to eliminate seams, the values of the pixels around the seam must be able to keep the interpolation results consistent. This seam problem is particularly noticeable in the transition areas of shadows.
[0171] A common solution is to generate Stitch Points on the seam, which are points distributed along the seam. Because the UVs on both sides of these points are discontinuous, there are two interpolation methods for the values of these points, and both should yield the same result. Therefore, the pixel values around the Stitch Points can be used as variables, and the difference in the interpolation results mentioned above can be used as error values. Then, the optimal solution is calculated using least squares. The error values also need to be factored with the offset limit of the current pixel value to prevent the value at the seam from deviating too much from the original pixel value. Please refer to [reference needed]. Figure 10 The diagram illustrates a shadow seam according to an embodiment of this application.
[0172] The above solution addresses the interpolation inconsistency issue at the seam, which is sufficient for general Irradiance maps. However, for SDF (Surface Mount Data Function), the UV discontinuity at the seam introduces other problems: the seam interrupts the diffusion of SDF to surrounding pixels. Because the UVs are discontinuous, the correct SDF value cannot be obtained directly from surrounding pixels. For example, as shown in the image below, the shadow on the right clearly does not match the shadow on the left. This is because the boundary of the right shadow is right at the edge of the seam, therefore, the usual SDF algorithm based on diffusion from surrounding pixels cannot obtain the correct distance value. Please refer to [reference needed]. Figure 11 This illustrates a schematic diagram of the SDF shaded seam according to an embodiment of this application. Figure 11 As shown, after seam 1101 is expanded into UV space, the pixels at the seam are continuous and the shadow at the seam is normal; however, after seam 1102 is expanded into UV space, the pixels at the seam are discontinuous and the shadow at the seam is not displayed correctly.
[0173] This scheme generates transition information between pixels based on the previously obtained Seam information. This information includes the corresponding pixel coordinates that are continuous in world space but discontinuous in UV space. When calculating SDF, the transition information is used to reposition the pixel, allowing the distance information of the shadow boundary to spread to pixels that are discontinuous in UV space, thus obtaining the correct SDF value. The corrected effect is as follows: Figure 12 As shown.
[0174] Figure 13 The present application illustrates a flowchart of a shadow processing method based on a virtual scene, as shown in an exemplary embodiment. This method is executed by a computer device, which can be implemented as a terminal or a server. Figure 1 The terminal 120 or server 110 shown, such as Figure 13 As shown, this shadow processing method based on a virtual scene includes the following steps:
[0175] Step 1301: Obtain the second scene data of the virtual scene, the shadow map of the virtual scene; the shadow map is the distance field information of the virtual scene, and the distance field information is used to indicate the minimum distance between each position point in the virtual scene and the boundary of the shadow in the virtual scene.
[0176] The method for generating the aforementioned shadow map can be referenced. Figure 2 or Figure 3 The descriptions in the illustrated embodiments will not be repeated here.
[0177] Step 1302: Obtain the shadow position in the virtual scene based on the distance field information.
[0178] In this embodiment of the application, during the rendering of a virtual scene, the computer device can restore the coordinate position of the shadow in the virtual scene (such as the three-dimensional coordinate position of the shadow in the virtual scene) based on the aforementioned distance field information.
[0179] Step 1303: Render a scene image of the virtual scene based on the shadow position in the virtual scene. The scene image contains shadows.
[0180] Once the computer device obtains the coordinates of the shadow in the virtual scene, it can calculate the coordinates of the shadow in the scene image (two-dimensional coordinates, such as pixel positions), render the scene image containing the shadow based on the coordinates of the shadow in the scene image, and output and display the scene image.
[0181] In summary, the solution shown in this application generates distance field information to represent shadows based on shadow information in the virtual scene during the shadow baking process. That is, the shadow map is stored by a distance field that indicates the minimum distance between each position point in the virtual scene and the boundary of the shadow in the virtual scene. Since the distance field does not directly represent the shadow through pixel values, but through distance information, it can represent high-quality shadow maps without requiring large-size shadow maps, thereby improving baking efficiency while ensuring shadow effects.
[0182] Furthermore, since shadow effects can be guaranteed without using large shadow maps, large shadow maps can avoid occupying too much memory during virtual scene operation, thereby optimizing resource consumption during virtual scene operation and improving the smoothness of virtual scene operation.
[0183] To improve the visual appeal of a product, the quality of shadows is crucial, but to balance development costs and game performance, simply increasing the size of the lightmap is not an option.
[0184] This technical solution utilizes the Optix ray detection library to accelerate baking speed, employs Phong tessellation technology to resolve the bias / terminator problem in shadows, and uses the SDF data format to store the Shadow Mask lightmap. This reduces shadow jaggedness and improves image quality without increasing lightmap size or runtime overhead.
[0185] Please refer to Figures 14 to 16 The paper demonstrates the effects of using the novel ShadowMask baking technology proposed in this application in some game scenes. The Shadow Mask used in the entire scene is 1024x1024 pixels, which is used for baking a scene of 250m*100m size. It can be seen that there is no obvious jaggedness at the edges of the shadows in the image, and the outline of the shadows cast by the leaves on the ground is clearly visible. The new Shadow Mask baking technology can significantly reduce the jaggedness at the edges of shadows and improve the quality of shadows. In the snow scene, the edges of the shadows are also clear and distinct without jaggedness.
[0186] Figure 17 The diagram illustrates a block diagram of a shadow processing apparatus based on a virtual scene, as shown in an exemplary embodiment of this application. This apparatus can be used to perform actions such as... Figure 2 or Figure 3 All or part of the steps in the method shown; such as Figure 17 As shown, the device includes:
[0187] The scene data acquisition module 1701 is used to acquire the first scene data of the virtual scene, which includes scene elements, light sources and light maps in the virtual scene.
[0188] The shadow information acquisition module 1702 is used to generate shadow information of the virtual scene based on the scene data; the shadow information is used to indicate the position of shadows in the virtual scene.
[0189] The distance field acquisition module 1703 is used to generate distance field information of the virtual scene based on the shadow information; the distance field information is used to indicate the minimum distance between each position point in the virtual scene and the boundary of the shadow in the virtual scene; the distance field information is used to generate the shadow in the scene when rendering the scene of the virtual scene.
[0190] In one possible implementation, the shadow information includes a grayscale image obtained by unfolding the shadows in the virtual scene in UV space; the grayscale value of each pixel in the grayscale image is used to indicate the percentage of the shadow portion in the region corresponding to the pixel.
[0191] The distance field acquisition module 1703 is used for,
[0192] Based on the grayscale image, calculate the minimum distance between the center of each pixel in the grayscale image and the boundary of the shadow in the grayscale image;
[0193] The distance field information is generated based on the minimum distance between the center of each pixel in the grayscale image and the boundary of the shadow in the grayscale image.
[0194] In one possible implementation, the distance field acquisition module 1703 is used to calculate, based on the gray value of a first pixel in the grayscale image, the minimum distance between the center of the first pixel and the boundary of the shadow in the grayscale image.
[0195] In one possible implementation, the distance field acquisition module 1703 is used to obtain, for a second pixel in the grayscale image whose grayscale value is equal to 0 or 1, the minimum distance between the center of the second pixel and the boundary of the shadow in the grayscale image by updating distance information through neighboring pixels.
[0196] In one possible implementation, the distance field acquisition module 1703 is used to obtain the minimum distance between the center of the second pixel and the boundary of the shadow in the grayscale image by updating distance information through neighboring pixels based on the light map, so that the distance information is updated to adjacent pixels on the same object surface.
[0197] In one possible implementation, the device further includes:
[0198] A seam information acquisition module is used to acquire seam information of the grayscale image, wherein the seam information is used to indicate the pixel point at the location of the corresponding seam in the grayscale image;
[0199] Jump information is generated based on the seam information. The jump information is used to indicate the jump relationship between pixels that are not adjacent in the grayscale image but are adjacent in the virtual scene.
[0200] In one possible implementation, the distance field acquisition module 1703 is configured to, in response to the second pixel being a non-adjacent pixel in the grayscale image but adjacent in the virtual scene, update the neighboring pixels of the second pixel based on the jump information, and then obtain the minimum distance between the center of the second pixel and the boundary of the shadow in the grayscale image by updating the distance information through the neighboring pixels.
[0201] In one possible implementation, the shadow information acquisition module 1702 is used to,
[0202] The virtual scene is constructed based on the first scene data;
[0203] Based on the constructed virtual scene, the shadow positions in the virtual scene are obtained by ray detection.
[0204] The shadow information is generated based on the shadow position in the virtual scene.
[0205] In one possible implementation, the shadow information acquisition module 1702 is used to,
[0206] Based on the first position point in the virtual scene, obtain the vertex position and normal information of the triangle face where the first position point is located, and obtain the second position point on the smooth surface of the triangle face corresponding to the first position point;
[0207] Ray detection is performed starting from the second location point to determine whether the first location point belongs to a shadow location in the virtual scene.
[0208] In one possible implementation, the shadow information acquisition module 1702 is used to,
[0209] Unfold the geometry in the virtual scene in the lightmap space to obtain the pixel coordinates of the geometry in the lightmap space;
[0210] Based on the pixel coordinates of the geometry in the lightmap space, the shadow position in the virtual scene is obtained by ray detection.
[0211] In summary, the solution shown in this application generates distance field information to represent shadows based on shadow information in the virtual scene during the shadow baking process. That is, the shadow map is stored by a distance field that indicates the minimum distance between each position point in the virtual scene and the boundary of the shadow in the virtual scene. Since the distance field does not directly represent the shadow through pixel values, but through distance information, it can represent high-quality shadow maps without requiring large-size shadow maps, thereby improving baking efficiency while ensuring shadow effects.
[0212] Figure 18 The diagram illustrates a block diagram of a shadow processing apparatus based on a virtual scene, as shown in an exemplary embodiment of this application. This apparatus can be used to perform actions such as... Figure 13 All or part of the steps in the method shown; such as Figure 18 As shown, the device includes:
[0213] The scene data acquisition module 1801 is used to acquire second scene data of a virtual scene, including a shadow map of the virtual scene; the shadow map is distance field information of the virtual scene, and the distance field information is used to indicate the minimum distance between each position point in the virtual scene and the boundary of the shadow in the virtual scene;
[0214] The shadow position acquisition module 1802 is used to acquire the shadow position in the virtual scene based on the distance field information;
[0215] The rendering module 1803 is used to render a scene image of the virtual scene based on the shadow position in the virtual scene, the scene image containing shadows.
[0216] In summary, the solution shown in this application generates distance field information to represent shadows based on shadow information in the virtual scene during the shadow baking process. That is, the shadow map is stored by a distance field that indicates the minimum distance between each position point in the virtual scene and the boundary of the shadow in the virtual scene. Since the distance field does not directly represent the shadow through pixel values, but through distance information, it can represent high-quality shadow maps without requiring large-size shadow maps, thereby improving baking efficiency while ensuring shadow effects.
[0217] Furthermore, since shadow effects can be guaranteed without using large shadow maps, large shadow maps can avoid occupying too much memory during virtual scene operation, thereby optimizing resource consumption during virtual scene operation and improving the smoothness of virtual scene operation.
[0218] Figure 19A structural block diagram of a computer device 1900 illustrating an exemplary embodiment of this application is shown. This computer device can be implemented as a server or terminal as described above in this application. The computer device 1900 includes a Central Processing Unit (CPU) 1901, a system memory 1904 including Random Access Memory (RAM) 1902 and Read-Only Memory (ROM) 1903, and a system bus 1905 connecting the system memory 1904 and the CPU 1901. The computer device 1900 also includes a mass storage device 1906 for storing an operating system 1909, application programs 1910, and other program modules 1911.
[0219] The mass storage device 1906 is connected to the central processing unit 1901 via a mass storage controller (not shown) connected to the system bus 1905. The mass storage device 1906 and its associated computer-readable media provide non-volatile storage for the computer device 1900. That is, the mass storage device 1906 may include computer-readable media (not shown) such as a hard disk or a compact disc read-only memory (CD-ROM) drive.
[0220] Without loss of generality, the computer-readable medium may include computer storage media and communication media. Computer storage media include volatile and non-volatile, removable and non-removable media implemented using any method or technology for storing information such as computer-readable instructions, data structures, program modules, or other data. Computer storage media include RAM, ROM, erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other solid-state storage technologies, CD-ROM, digital versatile disc (DVD) or other optical storage, magnetic tape cassettes, magnetic tape, disk storage, or other magnetic storage devices. Of course, those skilled in the art will recognize that the computer storage medium is not limited to the above-mentioned types. The system memory 1904 and mass storage device 1906 described above can be collectively referred to as memory.
[0221] According to various embodiments of this disclosure, the computer device 1900 can also be connected to a remote computer on a network, such as the Internet. That is, the computer device 1900 can be connected to a network 1908 via a network interface unit 1907 connected to the system bus 1905, or the network interface unit 1907 can be used to connect to other types of networks or remote computer systems (not shown).
[0222] The memory also includes at least one computer instruction stored in the memory, and the central processing unit 1901 executes the at least one computer instruction to implement all or part of the steps in the methods shown in the above embodiments.
[0223] In one exemplary embodiment, a computer-readable storage medium is also provided for storing at least one computer instruction, which is loaded and executed by a processor to implement all or part of the steps in the virtual scene-based shadow processing method described above. For example, the computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a compact disc read-only memory (CD-ROM), magnetic tape, floppy disk, or optical data storage device, etc.
[0224] In one exemplary embodiment, a computer program product or computer program is also provided, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform all or part of the steps in the virtual scene-based shadow processing method described above.
[0225] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.
[0226] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope.
Claims
1. A method for shadow processing based on a virtual scene, characterized in that, The method includes: Acquire first scene data of the virtual scene, which includes scene elements, light sources, and light maps in the virtual scene; Based on the first scene data, shadow information of the virtual scene is generated; the shadow information is used to indicate the shadow position in the virtual scene; the shadow information includes a grayscale image obtained by unfolding the shadow in the virtual scene in UV space; the grayscale value of each pixel in the grayscale image is used to indicate the percentage of the shadow part in the corresponding area of the pixel to the corresponding area of the pixel. Obtain the seam information of the grayscale image, wherein the seam information is used to indicate the pixel point at the location of the corresponding seam in the grayscale image; Jump information is generated based on the seam information. The jump information is used to indicate the jump relationship between pixels that are not adjacent in the grayscale image but are adjacent in the virtual scene. For the second pixel in the grayscale image, where the grayscale value is equal to 0 or 1, in response to the second pixel being a non-adjacent pixel in the grayscale image but an adjacent pixel in the virtual scene, after updating the neighboring pixels of the second pixel based on the jump information, the minimum distance between the center of the second pixel and the boundary of the shadow in the grayscale image is obtained by updating the distance information of the neighboring pixels. Based on the minimum distance between the center of each pixel in the grayscale image and the boundary of the shadow in the grayscale image, distance field information of the virtual scene is generated; the distance field information is used to indicate the minimum distance between each position point in the virtual scene and the boundary of the shadow in the virtual scene; the distance field information is used to generate shadows in the scene image when rendering the scene image of the virtual scene.
2. The method of claim 1, wherein, The method further includes: For the first pixel in the grayscale image with a grayscale value greater than 0 and less than 1, the minimum distance between the center of the first pixel and the boundary of the shadow in the grayscale image is calculated based on the grayscale value of the first pixel.
3. The method of claim 1, wherein, The method of obtaining the minimum distance between the center of the second pixel and the boundary of the shadow in the grayscale image by updating distance information through neighboring pixels includes: Based on the light map, the minimum distance between the center of the second pixel and the boundary of the shadow in the grayscale image is obtained by updating the distance information through neighboring pixels, so that the distance information is updated to the adjacent pixels on the same object surface.
4. The method of claim 1, wherein, The step of generating shadow information for the virtual scene based on the first scene data includes: The virtual scene is constructed based on the first scene data; Based on the constructed virtual scene, the shadow positions in the virtual scene are obtained by ray detection. The shadow information is generated based on the shadow position in the virtual scene.
5. The method of claim 4, wherein, The virtual scene, based on the constructed virtual scene, obtains the shadow positions in the virtual scene using raycasting, including: Based on the first position point in the virtual scene, obtain the vertex position and normal information of the triangle face where the first position point is located, and obtain the second position point on the smooth surface of the triangle face corresponding to the first position point; Ray detection is performed starting from the second location point to determine whether the first location point belongs to a shadow location in the virtual scene.
6. The method of claim 4, wherein, The virtual scene, based on the constructed virtual scene, obtains the shadow positions in the virtual scene using raycasting, including: Unfold the geometry in the virtual scene in the lightmap space to obtain the pixel coordinates of the geometry in the lightmap space; Based on the pixel coordinates of the geometry in the lightmap space, the shadow position in the virtual scene is obtained by ray detection.
7. A shadow processing method based on a virtual scene, characterized in that, The method includes: Obtain a shadow map of a virtual scene; the shadow map is the distance field information of the virtual scene, and the distance field information is used to indicate the minimum distance between each position point in the virtual scene and the boundary of the shadow in the virtual scene; Based on the distance field information, the shadow position in the virtual scene is obtained; Based on the shadow positions in the virtual scene, render a scene image of the virtual scene, the scene image containing shadows; The distance field information is generated offline in the following manner: The process involves: acquiring first scene data of the virtual scene, which includes scene elements, light sources, and lightmaps; generating shadow information of the virtual scene based on the first scene data; the shadow information indicating the shadow positions in the virtual scene; the shadow information including a grayscale image obtained by unfolding the shadows in the virtual scene in UV space; the grayscale value of each pixel in the grayscale image indicating the percentage of the shadow portion in the corresponding region of the pixel; acquiring seam information of the grayscale image, which indicates the pixel at the location of the corresponding seam in the grayscale image; and generating a shadow map based on the seam information. Jump information, which indicates the jump relationship between non-adjacent pixels in the grayscale image but adjacent pixels in the virtual scene; for a second pixel in the grayscale image with a grayscale value of 0 or 1, in response to the second pixel being a non-adjacent pixel in the grayscale image but adjacent pixels in the virtual scene, after updating the neighboring pixels of the second pixel based on the jump information, the minimum distance between the center of the second pixel and the boundary of the shadow in the grayscale image is obtained by updating the distance information of the neighboring pixels; the distance field information is generated based on the minimum distance between the center of each pixel in the grayscale image and the boundary of the shadow in the grayscale image.
8. A shadow processing device based on a virtual scene, characterized in that, The device includes: The scene data acquisition module is used to acquire the first scene data of the virtual scene, which includes scene elements, light sources and light maps in the virtual scene. A shadow information acquisition module is used to generate shadow information of the virtual scene based on the first scene data; the shadow information is used to indicate the shadow position in the virtual scene; the shadow information includes a grayscale image obtained by unfolding the shadow in the virtual scene in UV space; the grayscale value of each pixel in the grayscale image is used to indicate the percentage of the shadow part in the corresponding area of the pixel to the corresponding area of the pixel. A seam information acquisition module is used to acquire seam information of the grayscale image, wherein the seam information is used to indicate the pixel at the location of the corresponding seam in the grayscale image; and to generate jump information based on the seam information, wherein the jump information is used to indicate the jump relationship between pixels that are not adjacent in the grayscale image but are adjacent in the virtual scene. The distance field acquisition module is used to, for a second pixel in the grayscale image with a grayscale value equal to 0 or 1, in response to the second pixel being a non-adjacent pixel in the grayscale image but adjacent in the virtual scene, update the neighboring pixels of the second pixel based on the jump information, and then obtain the minimum distance between the center of the second pixel and the boundary of the shadow in the grayscale image by updating the distance information through neighboring pixels; based on the minimum distance between the center of each pixel in the grayscale image and the boundary of the shadow in the grayscale image, generate distance field information of the virtual scene; the distance field information is used to indicate the minimum distance between each position point in the virtual scene and the boundary of the shadow in the virtual scene; the distance field information is used to generate shadows in the scene image when rendering the scene image of the virtual scene.
9. A shadow processing device based on a virtual scene, characterized in that, The device includes: The scene data acquisition module is used to acquire the shadow map of the virtual scene; the shadow map is the distance field information of the virtual scene, and the distance field information is used to indicate the minimum distance between each position point in the virtual scene and the boundary of the shadow in the virtual scene; The shadow position acquisition module is used to acquire the shadow position in the virtual scene based on the distance field information; A rendering module is used to render a scene image of the virtual scene based on the shadow positions in the virtual scene, the scene image containing shadows; The distance field information is generated offline in the following manner: The process involves: acquiring first scene data of the virtual scene, which includes scene elements, light sources, and lightmaps; generating shadow information of the virtual scene based on the first scene data; the shadow information indicating the shadow positions in the virtual scene; the shadow information including a grayscale image obtained by unfolding the shadows in the virtual scene in UV space; the grayscale value of each pixel in the grayscale image indicating the percentage of the shadow portion in the corresponding region of the pixel; acquiring seam information of the grayscale image, which indicates the pixel at the location of the corresponding seam in the grayscale image; and generating a shadow map based on the seam information. Jump information, which indicates the jump relationship between non-adjacent pixels in the grayscale image but adjacent pixels in the virtual scene; for a second pixel in the grayscale image with a grayscale value of 0 or 1, in response to the second pixel being a non-adjacent pixel in the grayscale image but adjacent pixels in the virtual scene, after updating the neighboring pixels of the second pixel based on the jump information, the minimum distance between the center of the second pixel and the boundary of the shadow in the grayscale image is obtained by updating the distance information of the neighboring pixels; the distance field information is generated based on the minimum distance between the center of each pixel in the grayscale image and the boundary of the shadow in the grayscale image.
10. A computer device, comprising: The computer device includes a processor and a memory, the memory storing at least one computer instruction, which is loaded and executed by the processor to implement the shadow processing method based on a virtual scene as described in any one of claims 1 to 7.
11. A computer readable storage medium, characterized in that, The computer-readable storage medium stores at least one computer instruction, which is loaded and executed by a processor to implement the shadow processing method based on a virtual scene as described in any one of claims 1 to 7.
12. A computer program product, characterised in that, The computer program product includes computer instructions stored in a computer-readable storage medium; the computer instructions are read and executed by a processor of a computer device to implement the shadow processing method based on a virtual scene as described in any one of claims 1 to 7.