An illumination map baking method, system and storage medium

By dividing the 3D scene into task blocks and performing unified occlusion detection during lightmap baking, a unified lightmap is generated, which solves the problems of inconsistent shadows and low efficiency caused by independent rendering of terrain and static objects, and achieves efficient and unified lightmap generation.

CN122115678APending Publication Date: 2026-05-29BEIJING GAMEASE AGE DIGITAL TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING GAMEASE AGE DIGITAL TECH CO LTD
Filing Date
2026-04-29
Publication Date
2026-05-29

Smart Images

  • Figure CN122115678A_ABST
    Figure CN122115678A_ABST
Patent Text Reader

Abstract

The application discloses a light map baking method and system and a storage medium, and relates to the field of image processing.The method comprises the following steps: acquiring light source description data of each target light source in a target three-dimensional scene, dividing a terrain area into a plurality of baking task blocks, and establishing a spatial correspondence relationship with static objects; uniformly detecting occlusion of the baking task blocks and the static objects having the spatial correspondence relationship; generating light attenuation amounts representing occlusion of the baking task blocks by the static objects and / or the terrain; and generating a unified light map covering the terrain area and the static objects based on the light attenuation amounts. Through unified light source data and a block architecture, the application realizes collaborative baking of the terrain and the static objects, avoids the phenomenon of inconsistent shadow style, obvious seams, shadow discontinuity and light leakage caused by independent rendering, and eliminates redundant calculation, thereby improving baking consistency while ensuring baking efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of image processing technology, and in particular to a method, system and storage medium for lightmap baking. Background Technology

[0002] With the continuous evolution of 3D graphics processing and real-time rendering technologies, applications such as digital twins, virtual reality, and high-quality video games are increasingly demanding realistic scene lighting and shadow effects. In order to balance rendering performance and visual accuracy with limited hardware resources and to reduce the overhead of real-time shadows, the industry has also developed a solution that uses lightmaps to pre-calculate lighting for some static objects. By baking static shadows and indirect lighting offline, the results are stored in textures, and the lightmaps are directly sampled during game runtime, thereby reducing the pressure of real-time lighting and shadow calculations.

[0003] However, existing lightmapping methods still suffer from low baking consistency and inefficiency in practical applications. Specifically, when dealing with complex scenes containing various types of objects such as terrain and buildings, the terrain system and static mesh objects are usually treated as independent modules in the existing baking pipeline. This leads to inconsistent styles or obvious seams in the generated texture results between terrain shadows and static object shadows, easily causing physical inconsistencies such as shadow breaks and light leaks at the boundary between the two. Furthermore, since existing lightmapping methods render the terrain system and static mesh objects independently, this not only increases the complexity and time cost of baking calculations but also leads to decreased resource allocation accuracy due to the lack of a unified tile rendering mechanism, severely reducing baking efficiency. Therefore, how to improve baking consistency while ensuring baking efficiency has become an urgent problem to be solved. Summary of the Invention

[0004] In view of the above problems, this application provides a method, system, and storage medium for baking lightmaps to improve baking consistency while ensuring baking efficiency. The specific solution is as follows:

[0005] The first aspect of this application provides a method for baking lightmaps, including:

[0006] Obtain light source description data for each target light source participating in baking within the target 3D scene;

[0007] Based on the terrain data of the target 3D scene, the terrain region of the target 3D scene is divided into multiple baking task blocks, and a spatial correspondence between the baking task blocks and static objects in the target 3D scene is established.

[0008] Based on the light source description data and the terrain data, a unified occlusion detection operation is performed on the baking task block and the static object with the spatial correspondence. Based on the occlusion detection results and the light source description data, a light attenuation amount characterizing the baking task block caused by the static object and / or terrain occlusion is generated.

[0009] Based on the light attenuation of each of the baking task blocks, a uniform lightmap covering the terrain area and each of the static objects is generated.

[0010] In one possible implementation, based on the terrain data of the target 3D scene, the terrain region of the target 3D scene is divided into multiple baking task blocks, including:

[0011] Obtain the terrain data and the corresponding rendered terrain instance;

[0012] Based on the rendered terrain instance, the terrain region is mapped to a preset spatial grid to obtain multiple baking task blocks, and at least one terrain sampling point is constructed within the baking task blocks based on the terrain data.

[0013] In one possible implementation, the step of performing a unified occlusion detection operation on the baking task block and the static object having the spatial correspondence based on the light source description data and the terrain data, and generating an illumination attenuation amount characterizing the baking task block due to occlusion by the static object and / or terrain based on the occlusion detection result and the light source description data, includes:

[0014] The unified occlusion detection operation and the acquisition of the light attenuation are performed synchronously on each of the baking task blocks using a preset parallel thread.

[0015] In one possible implementation, the unified occlusion detection operation includes:

[0016] Based on the terrain data, at least one terrain sampling point is constructed within the baking task block;

[0017] For each terrain sampling point within the baking task block: construct detection rays from the terrain sampling points to each target light source based on the light source description data, and perform intersection detection on each detection ray based on the terrain data and static objects of each baking task block, and output the occlusion coefficient corresponding to each target light source based on the intersection detection.

[0018] In one possible implementation, generating the illumination attenuation amount characterizing the baking task block due to occlusion by the static object and / or terrain, based on the occlusion detection results and the light source description data, includes:

[0019] For each terrain sampling point within the baking task block: based on the occlusion coefficient corresponding to the target light source and the light source description data, calculate the single light source illumination attenuation corresponding to the target light source; sum the illumination attenuation of each single light source to obtain the illumination attenuation of the terrain sampling point;

[0020] The set of illumination attenuation values ​​at each of the terrain sampling points is determined as the illumination attenuation value of the baking task block.

[0021] In one possible implementation, generating a unified lightmap covering the terrain region and each of the static objects based on the light attenuation of each of the baking task blocks includes:

[0022] Based on the light attenuation, terrain data, and light source description data of the baking task block, terrain shadow compensation operation is performed on the baking task block to obtain the initial light map of each baking task block after terrain shadow compensation.

[0023] The initial lighting map is subjected to neighborhood smoothing filtering to obtain the unified lighting map.

[0024] In one possible implementation, the terrain shadow compensation operation includes:

[0025] The baking task blocks are mapped to the light source clipping space using a preset light source view projection matrix. Based on the light attenuation, terrain data, and light source description data of the baking task blocks, the rendering texture coordinates and depth values ​​of the terrain sampling points and other pixels in each baking task block after mapping to the light source clipping space are obtained.

[0026] For each of the terrain sampling points: taking the terrain sampling point as the center, the pixel with the smallest depth value among the other pixels adjacent to the terrain sampling point is determined as the sampling point corresponding to the terrain sampling point; the sampling point is mapped back to world space using a preset inverse light source view projection matrix, and a dot product operation is performed based on the normal vector of the sampling point and each light source direction vector, wherein the light source direction vector is the direction vector passing through a target light source and the terrain sampling point; when the dot product operation result indicates that the sampling point is occluded, attenuation compensation is performed on the illumination attenuation amount corresponding to the terrain sampling point and the target light source when occluded, based on a preset compensation amount.

[0027] In one possible implementation, acquiring light source description data including each target light source participating in baking within the target 3D scene includes:

[0028] The light source information of each light source in the target 3D scene is traversed, and the light source that represents a static light source and casts a shadow is determined as the target light source.

[0029] Based on the light source type and diffuse color identifier in the light source information, light source description data including description data of each target light source is generated.

[0030] A second aspect of this application provides a lightmap baking system, the lightmap baking system comprising:

[0031] The data acquisition module is used to acquire light source description data, including the light source description data of each target light source participating in baking within the target 3D scene;

[0032] The block division module is used to divide the terrain region of the target 3D scene into multiple baking task blocks based on the terrain data of the target 3D scene, and to establish the spatial correspondence between the baking task blocks and static objects in the target 3D scene.

[0033] The attenuation calculation module is used to perform a unified occlusion detection operation on the baking task block and the static object with the spatial correspondence based on the light source description data and the terrain data, and generate the light attenuation amount characterizing the baking task block occluded by the static object and / or terrain based on the occlusion detection result and the light source description data.

[0034] The lighting baking module is used to generate a unified lighting map covering the terrain area and each of the static objects based on the lighting attenuation of each of the baking task blocks.

[0035] In one possible implementation, the block partitioning module is configured as follows:

[0036] Obtain the terrain data and the corresponding rendered terrain instance;

[0037] Based on the rendered terrain instance, the terrain region is mapped to a preset spatial grid to obtain multiple baking task blocks, and at least one terrain sampling point is constructed within the baking task blocks based on the terrain data.

[0038] In one possible implementation, the attenuation calculation module is configured as follows:

[0039] The unified occlusion detection operation and the acquisition of the light attenuation are performed synchronously on each of the baking task blocks using a preset parallel thread.

[0040] In one possible implementation, the attenuation calculation module is configured to perform the unified occlusion detection operation as follows:

[0041] Based on the terrain data, at least one terrain sampling point is constructed within the baking task block;

[0042] For each terrain sampling point within the baking task block: construct detection rays from the terrain sampling points to each target light source based on the light source description data, and perform intersection detection on each detection ray based on the terrain data and static objects of each baking task block, and output the occlusion coefficient corresponding to each target light source based on the intersection detection.

[0043] In one possible implementation, the attenuation calculation module is set to generate the illumination attenuation amount characterizing the baking task block due to occlusion by the static object and / or terrain based on the occlusion detection results and the light source description data:

[0044] For each terrain sampling point within the baking task block: based on the occlusion coefficient corresponding to the target light source and the light source description data, calculate the single light source illumination attenuation corresponding to the target light source; sum the illumination attenuation of each single light source to obtain the illumination attenuation of the terrain sampling point;

[0045] The set of illumination attenuation values ​​at each of the terrain sampling points is determined as the illumination attenuation value of the baking task block.

[0046] In one possible implementation, the lighting baking module is configured to generate a uniform lightmap covering the terrain region and each of the static objects based on the lighting attenuation of each of the baking task blocks:

[0047] Based on the light attenuation, terrain data, and light source description data of the baking task block, terrain shadow compensation operation is performed on the baking task block to obtain the initial light map of each baking task block after terrain shadow compensation.

[0048] The initial lighting map is subjected to neighborhood smoothing filtering to obtain the unified lighting map.

[0049] In one possible implementation, the lighting baking module is configured to perform terrain shadow compensation operations as follows:

[0050] The baking task blocks are mapped to the light source clipping space using a preset light source view projection matrix. Based on the light attenuation, terrain data, and light source description data of the baking task blocks, the rendering texture coordinates and depth values ​​of the terrain sampling points and other pixels in each baking task block after mapping to the light source clipping space are obtained.

[0051] For each of the terrain sampling points: taking the terrain sampling point as the center, the pixel with the smallest depth value among the other pixels adjacent to the terrain sampling point is determined as the sampling point corresponding to the terrain sampling point; the sampling point is mapped back to world space using a preset inverse light source view projection matrix, and a dot product operation is performed based on the normal vector of the sampling point and each light source direction vector, wherein the light source direction vector is the direction vector passing through a target light source and the terrain sampling point; when the dot product operation result indicates that the sampling point is occluded, attenuation compensation is performed on the illumination attenuation amount corresponding to the terrain sampling point and the target light source when occluded, based on a preset compensation amount.

[0052] In one possible implementation, the data acquisition module is configured as follows:

[0053] The light source information of each light source in the target 3D scene is traversed, and the light source that represents a static light source and casts a shadow is determined as the target light source.

[0054] Based on the light source type and diffuse color identifier in the light source information, light source description data including description data of each target light source is generated.

[0055] A third aspect of this application provides a computer storage medium carrying one or more computer programs that, when executed by an electronic device, enable the electronic device to perform the lightmap baking method described in the first aspect or any implementation thereof.

[0056] By employing the aforementioned technical solution, this application provides a lightmap baking method, system, and storage medium. Through configuration, it acquires light source description data for each target light source participating in baking within the target 3D scene, providing unified light source data for full-scene baking. Subsequently, by configuring terrain data based on the target 3D scene, the terrain region of the target 3D scene is divided into multiple baking task blocks, and a spatial correspondence is established between the baking task blocks and static objects within the target 3D scene. This achieves the binding of the terrain system and static mesh objects, constructing a unified baking framework. Furthermore, by configuring light source description data and terrain data, a unified occlusion detection operation is performed on the baking task blocks and static objects with spatial correspondence. Based on the occlusion detection results and light source description data, a light attenuation amount characterizing the baking task blocks occluded by static objects and / or terrain is generated. This allows for the synchronous calculation of occlusion between the terrain itself and static objects using the same set of judgment logic. This avoids baking consistency problems such as inconsistent shadow styles, obvious seams, shadow breaks, and light leaks caused by independent rendering in existing technologies. Simultaneously, it eliminates redundant calculations caused by independent rendering, reducing the complexity and time cost of baking calculations. Finally, by configuring the illumination attenuation based on each baking task block, a unified lightmap covering the terrain area and each static object is generated, achieving a unified output for baking across the entire scene. This solves the problem of low baking consistency caused by separate baking of terrain and static mesh objects. At the same time, the unified baking mechanism improves resource allocation accuracy and increases baking efficiency. Therefore, this application improves baking consistency while ensuring baking efficiency. Attached Figure Description

[0057] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and the originals and elements are not necessarily drawn to scale.

[0058] Figure 1 A flowchart of a lightmap baking method provided in this application;

[0059] Figure 2 A schematic diagram of the architecture of an integrated lightmap baking system provided in this application;

[0060] Figure 3 A unified lighting map provided for this application;

[0061] Figure 4 A flowchart of a lightmap baking method provided in this application;

[0062] Figure 5 A block diagram of a lightmap baking system provided in this application;

[0063] Figure 6 This is a schematic diagram of the structure of an electronic device provided in this application. Detailed Implementation

[0064] The embodiments of this application are described below with reference to the accompanying drawings. The terminology used in the implementation section of this application is for explaining specific embodiments only and is not intended to limit the scope of this application.

[0065] The embodiments of this application will now be described with reference to the accompanying drawings. Those skilled in the art will recognize that, with technological advancements and the emergence of new scenarios, the technical solutions provided in the embodiments of this application are equally applicable to similar technical problems.

[0066] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such terms are interchangeable where appropriate; this is merely a way of distinguishing objects with the same attributes in the embodiments of this application. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion, so that a process, method, system, product, or apparatus that comprises a series of elements is not necessarily limited to those elements, but may include other elements not explicitly listed or inherent to those processes, methods, products, or apparatuses.

[0067] As mentioned earlier, in traditional lightmap baking techniques, when dealing with complex scenes containing various types of objects such as terrain and buildings, the terrain system and static mesh objects are treated as independent modules in the baking pipeline. This results in inconsistent styles or obvious seams between the shadows of terrain and static objects in the generated texture results, producing physical inconsistencies such as shadow breaks and light leaks at the boundaries. Specifically, shadow breaks manifest as discontinuous shadows at the boundaries between terrain and static objects, while light leaks manifest as unexpected bright spots in non-shadowed areas. Furthermore, due to the independent rendering mechanisms of the terrain system and static mesh objects, the complexity and time cost of baking calculations increase, while the lack of a unified tile rendering mechanism leads to decreased resource allocation accuracy and reduced baking efficiency.

[0068] For example, in digital twin city modeling applications, the target 3D scene includes large-area terrain (such as urban parks and road networks) and static buildings (such as residential buildings and commercial centers). Terrain data is stored as heightmaps, and static objects are imported as mesh models. During the baking process, seams appear at the boundaries between terrain shadows and building shadows, resulting in shadow discontinuities and light leaks; these shadow discontinuities are particularly noticeable at the intersections of roads and buildings. Furthermore, because the baking tasks for terrain and static objects are scheduled separately, GPU resource allocation is uncoordinated, leading to some computing units being idle while others are overloaded, thus prolonging the overall baking time.

[0069] If these issues are not addressed, inconsistent shadows will reduce the realism of scene rendering and negatively impact user experience; low baking efficiency will increase development cycles and place higher demands on hardware resources; in real-time rendering applications, it will lead to unstable frame rates and affect the smoothness of interaction; in the long run, these problems will hinder the development of advanced applications such as digital twins and virtual reality. Therefore, improving baking consistency and efficiency has become an urgent technical challenge.

[0070] The first aspect of this application provides a method for baking lightmaps, the flowchart of which is shown below. Figure 1 As shown, the lightmap baking method includes:

[0071] S101. Obtain light source description data including each target light source participating in baking within the target 3D scene.

[0072] It should be noted that in practical applications, baking is a core function in computer graphics, especially in the field of 3D rendering, and its core function is to improve visual details through texture mapping.

[0073] It should be noted that, in practical application scenarios, the aforementioned target light source is a static light source generated within the aforementioned target 3D scene to produce projected shadows. The aforementioned light source description data can be data characterizing the light source attributes of the target light source, and its data types include, but are not limited to, illumination direction, light source type, and diffuse color. This application obtains light source description data for each target light source participating in baking within the target 3D scene through configuration, providing unified light source data for full-scene baking.

[0074] It should be noted that in practical application scenarios, the aforementioned target 3D scene refers to a scene that requires the generation of corresponding light maps, such as a game scene.

[0075] S102. Based on the terrain data of the target 3D scene, divide the terrain area of ​​the target 3D scene into multiple baking task blocks, and establish the spatial correspondence between the baking task blocks and the static objects in the target 3D scene.

[0076] It should be noted that in practical applications, terrain data can refer to the raw data set describing the geometry, height distribution, and texture mapping information of the terrain in the target 3D scene. This typically includes terrain height maps, normal maps, and rendering instance information. A baked task block is the smallest processing unit after dividing the overall terrain area according to preset rules; in this embodiment, it can be called a Tile. It is the basic granularity for parallel lighting calculations. Spatial correspondence can refer to the association mapping between each baked task block and its surrounding static objects that may cause occlusion, used to determine which static objects need to be detected when calculating the lighting of that block.

[0077] It should be noted that in practical applications, the aforementioned baking task blocks can be obtained by mapping terrain regions to a preset spatial mesh, based on terrain data and its corresponding rendered terrain instances. Specifically, firstly, the terrain data object and its rendered terrain instance are obtained from the scene manager, and the rendered terrain instance is set to lighting baking mode to allow the use of complete mesh and normal data in the calculation. Next, based on the mesh size of the terrain in the X / Z directions, a preset tile size is selected as the dividing unit, and the continuous terrain surface is cut into multiple independent rectangular or irregular polygon blocks. Within each baking task block, at least one terrain sampling point is also constructed based on the terrain data. These sampling points will serve as the starting point for subsequent ray tracing. When establishing spatial correspondences, the spatial bounding box of each block can be analyzed to retrieve all static objects located near or within the projection range of the bounding box, and these objects are bound to the block. For example, if a block is located on the north side of a mountain peak, a spatial correspondence will be established between the block and static objects such as rock models and tree models on the north side of the mountain peak. This block-based and association mechanism decomposes the massive global occlusion detection problem into multiple local sub-tasks, reducing the amount of data required for a single computation and improving baking efficiency. Furthermore, by configuring terrain data based on the target 3D scene, the terrain region of the target 3D scene is divided into multiple baking task blocks, and a spatial correspondence is established between the baking task blocks and static objects within the target 3D scene. This achieves the binding of terrain and static mesh objects, constructing a unified baking framework and providing a data foundation for subsequent unified processing of static objects and baking task blocks, as well as the generation of unified lightmaps.

[0078] S103. Based on light source description data and terrain data, perform a unified occlusion detection operation on baking task blocks and static objects with spatial correspondence, and generate a light attenuation amount characterizing the baking task blocks occluded by static objects and / or terrain based on the occlusion detection results and light source description data.

[0079] It should be noted that, in practical applications, the aforementioned unified occlusion detection operation refers to performing the same occlusion detection operation on each baking task block and each static object with spatial correspondence. This occlusion detection operation is used to determine whether the optical fiber received by the baking task block is occluded by terrain and / or static objects. This application configures a unified occlusion detection operation on baking task blocks and static objects with spatial correspondence based on light source description data and terrain data. Based on the occlusion detection results and light source description data, it generates a light attenuation amount characterizing the occlusion of the baking task block by static objects and / or terrain. This allows for the synchronous calculation of occlusion by the terrain itself and static objects using the same set of judgment logic, avoiding baking consistency problems such as inconsistent shadow styles, obvious seams, shadow breaks, and light leaks caused by independent rendering in existing technologies. It also eliminates redundant calculations caused by independent rendering, reducing the complexity and time cost of baking calculations. It should be noted that, in practical applications, the aforementioned light attenuation amount can characterize the degree of reduction in the light intensity received by each pixel within the baking task block after being occluded by static objects and / or terrain. The light attenuation amount can be the light attenuation amount of a selected pixel within the baking task block, or it can be the collection of light attenuation amounts of all pixels within the baking task block.

[0080] S104. Based on the light attenuation of each baking task block, generate a unified light map covering the terrain area and each static object.

[0081] It should be noted that, in practical applications, the aforementioned unified lightmap is a light texture image covering the entire terrain area and all static objects. This application generates a unified lightmap covering the terrain area and all static objects by configuring the light attenuation amount based on each baking task block, achieving unified output for baking across the entire scene. This solves the problem of low baking consistency caused by separate baking of terrain and static mesh objects, and improves resource allocation accuracy and baking efficiency by relying on a unified baking mechanism.

[0082] In one possible implementation, since existing lightmap methods render terrain systems and static mesh objects independently, existing baking is usually a distributed process involving multiple systems. After each system completes its operation, an operator summarizes the various types of data or processing results, which also reduces baking efficiency. Therefore, to adapt to the lightmap baking method provided by the first aspect and any implementation of the first aspect of this application, this application also provides an integrated lightmap baking system. The architectural diagram of this integrated lightmap baking system can be shown as follows: Figure 2As shown, this integrated lightmap baking system includes: a rendering engine namespace (Ogre), an intermediate connection component (TerrainLightmapOptionDialog), a terrain management namespace (Fairy), a BakeMeshParam structure, and a threadFuncParams structure. The rendering engine namespace utilizes the GPU to accelerate the baking process and provides baking-related functions. The intermediate connection component collects user configuration parameters to drive the baking process. The terrain management namespace provides the geometric data of the target 3D scene. The rendering engine namespace includes the classes shown in Table 1. The terrain management namespace includes the classes shown in Table 2.

[0083] Table 1

[0084]

[0085] Table 2

[0086]

[0087] It should be noted that the BakeMeshParam structure mentioned above includes the classes shown in Table 3.

[0088] Table 3

[0089]

[0090] It should be noted that the above threadFuncParams structure includes the following classes as shown in Table 4.

[0091] Table 4

[0092]

[0093] This application provides unified light source data for full-scene baking by configuring and acquiring light source description data for each target light source participating in baking within the target 3D scene. Subsequently, by configuring terrain data based on the target 3D scene, the terrain region of the target 3D scene is divided into multiple baking task blocks, and a spatial correspondence between the baking task blocks and static objects within the target 3D scene is established, realizing the binding of terrain and static mesh objects and constructing a unified baking framework. Furthermore, by configuring light source description data and terrain data, a unified occlusion detection operation is performed on the baking task blocks and static objects with spatial correspondence. Based on the occlusion detection results and light source description data, the amount of light attenuation representing the occlusion of the baking task blocks by static objects and / or terrain is generated. Thus, the occlusion calculation of the terrain itself and static objects is completed synchronously using the same set of judgment logic, avoiding baking consistency problems such as inconsistent shadow styles, obvious seams, shadow breaks, and light leaks caused by independent rendering in existing technologies. At the same time, it eliminates the redundant calculation caused by independent rendering of the two, reducing the complexity and time cost of baking calculation. Finally, by configuring the illumination attenuation based on each baking task block, a unified lightmap covering the terrain area and each static object is generated, achieving a unified output for baking across the entire scene. This solves the problem of low baking consistency caused by separate baking of terrain and static mesh objects. At the same time, the unified baking mechanism improves resource allocation accuracy and increases baking efficiency. Therefore, this application improves baking consistency while ensuring baking efficiency.

[0094] In one possible implementation, based on the terrain data of the target 3D scene, the terrain region of the target 3D scene is divided into multiple baking task blocks, including:

[0095] Obtain terrain data and the corresponding rendered terrain instance;

[0096] Based on the rendered terrain instance, the terrain region is mapped to a preset spatial grid to obtain multiple baking task blocks, and at least one terrain sampling point is constructed within the baking task block based on the terrain data.

[0097] It's important to note that in practical applications, terrain data refers to a digital representation describing the geometry, texture, and height of terrain in a 3D scene. It can exist in various forms, such as a heightmap, which uses grayscale values ​​to represent terrain height; or a Triangulated Irregular Network (TIN), which approximates the terrain surface using a series of irregular triangles. Terrain data provides fundamental geometric information for terrain region division and subsequent lighting calculations. A rendered terrain instance refers to a geometric representation of terrain data that has been processed and optimized in the graphics rendering pipeline and can be directly used for rendering. It typically includes information such as the terrain's geometric mesh, material properties, and texture maps, serving as the direct basis for the terrain's presentation on the screen. A rendered terrain instance can be a mesh object composed of vertex buffers and index buffers, which may be optimized using LOD (Level of Detail) technology; or a GPU-based procedural terrain generation and rendering object, whose geometric details are dynamically generated at runtime.

[0098] It's important to note that in practical applications, a predefined spatial grid is a predefined structure used to organize and manage 3D spatial data. It divides continuous space into a series of discrete, regular or irregular units. The predefined spatial grid can be a uniform 2D grid, such as one based on tiles of fixed size, with each grid unit corresponding to a baking task block; or it can be an adaptive grid structure, such as the leaf nodes of a quadtree or octree, whose density can be adjusted according to the complexity of the terrain. A baking task block refers to an independent processing unit into which a terrain region is divided. Each block can independently perform illumination baking calculations, facilitating parallel processing and improving baking efficiency. Terrain sampling points are discrete locations selected within the baking task block for illumination calculations. These points represent illumination information at specific locations within the block and are the actual execution points for calculating illumination attenuation. Terrain sampling points can be multiple points evenly distributed within each baking task block, such as sampling at fixed intervals on the XZ plane of the block and obtaining the corresponding height values; or points selected within the block based on an importance sampling strategy (such as increasing the sampling density in areas with large slope changes).

[0099] It should be noted that this application ensures that the division of terrain regions is based on actual renderable geometric information by acquiring terrain data and corresponding rendered terrain instances, thereby guaranteeing the accuracy of the division and consistency with visual representation. Based on this, the terrain regions are mapped to a preset spatial grid based on the rendered terrain instances, effectively dividing continuous and complex terrain regions into baking task blocks suitable for parallel processing. This allows each baking task block to accurately correspond to a specific part of the terrain, providing clear boundaries and a data foundation for subsequent unified occlusion detection operations.

[0100] Furthermore, this application configures at least one terrain sampling point to be built in each baking task block, providing a reliable computational basis for subsequent accurate calculation of illumination attenuation, thereby making the final generated lighting map more detailed and realistic, effectively solving the problems of low efficiency and insufficient accuracy that may exist in traditional terrain division.

[0101] In one possible implementation, based on light source description data and terrain data, a unified occlusion detection operation is performed on baking task blocks and static objects with spatial correspondence. Based on the occlusion detection results and light source description data, a characterization of the illumination attenuation of the baking task blocks due to occlusion by static objects and / or terrain is generated, including:

[0102] A pre-defined parallel thread is used to synchronously perform a unified occlusion detection operation and obtain the amount of light attenuation for each baking task block.

[0103] It should be noted that in practical applications, the aforementioned pre-defined parallel threads refer to multiple execution units that can run simultaneously during the execution of a computer program to improve processing efficiency. These threads can share the resources of the process but have independent execution paths. Their implementation methods can include, but are not limited to: utilizing the parallel computing capabilities of a multi-core central processing unit (CPU) and managing threads through libraries such as OpenMP and Intel TBB (Threading Building Blocks); or utilizing the massively parallel computing capabilities of a graphics processing unit (GPU) and programming through frameworks such as CUDA and OpenCL to distribute computational tasks across thousands of processing cores for parallel execution.

[0104] It should be noted that, in practical applications, the aforementioned simultaneous execution of unified occlusion detection and illumination attenuation acquisition refers to a parallel computing environment where multiple pre-defined parallel threads simultaneously perform unified occlusion detection on different baking task blocks, and calculate and acquire the corresponding illumination attenuation based on the detection results and light source description data. This simultaneous execution does not mean that all threads execute the exact same instructions at the same time, but rather that they logically perform their respective computational tasks simultaneously, without interfering with each other or exchanging data through a coordination mechanism, thereby jointly advancing the overall computation progress.

[0105] It should be noted that in practical applications, this application introduces pre-defined parallel threads to enable the simultaneous execution of unified occlusion detection and illumination attenuation calculations for each baking task block. Specifically, after acquiring light source description data and terrain data, dividing the baking task blocks into multiple blocks, and establishing their spatial correspondence with static objects, these baking task blocks are no longer processed sequentially one by one. Instead, multiple pre-defined parallel threads are created or scheduled based on available computing resources (e.g., the number of CPU cores or GPU stream processors). Each parallel thread is assigned one or a group of baking task blocks, responsible for performing unified occlusion detection operations on them, and calculating the illumination attenuation of the block based on the detection results and light source description data. Since these threads run in parallel, they can process different baking task blocks simultaneously, thereby shortening the overall computation time. This parallel processing mechanism effectively utilizes the multi-core or many-core architecture of modern computing hardware, transforming the originally time-consuming serial computation into efficient parallel computation, improving the efficiency of unified occlusion detection and illumination attenuation calculation during lightmap baking, and thus improving the baking efficiency of lightmap baking.

[0106] In one possible implementation, the aforementioned pre-defined parallel threads can employ a GPU-based parallel computing framework. For example, technologies such as NVIDIA CUDA or Khronos OpenCL can be used to submit the occlusion detection and illumination attenuation calculation tasks for each baked task block as an independent computational unit (such as a thread block in CUDA or a workgroup in OpenCL) to the GPU. The GPU's thousands of stream processors can simultaneously process a large number of these computational units, with each stream processor responsible for the detection and calculation of one or more terrain sampling points. Specifically, for a 3D scene containing N baked task blocks, N or more parallel threads (or computational cores on the GPU) can be launched, with each thread responsible for one baked task block. Each thread independently reads the terrain data, static object data, and light source description data of its assigned baked task block, then performs operations such as ray casting and intersection detection to determine occlusion and calculates illumination attenuation based on light source characteristics. All these threads run simultaneously on the GPU, and after completing the calculations for their respective blocks, the results are aggregated to efficiently generate the illumination attenuation values ​​for all baked task blocks.

[0107] In one possible implementation, the unified occlusion detection operation described above includes:

[0108] Construct at least one terrain sampling point within the baking task block based on terrain data;

[0109] For each terrain sampling point within the baking task block: construct detection rays from the terrain sampling points to each target light source based on the light source description data, and perform intersection detection on each detection ray based on the terrain data and static objects of each baking task block, and output the occlusion coefficient corresponding to each target light source based on the intersection detection.

[0110] It should be noted that, in practical applications, the aforementioned terrain sampling points can be selected as discrete terrain points within the baking task block. These discrete terrain points are used to discretize the continuous terrain surface into computable units, thereby enabling refined detection of illumination occlusion within the terrain area. In practical applications, terrain sampling points can be evenly distributed within the baking task block based on a preset sampling density, for example, constructing sampling points at the center or vertex of each grid cell; alternatively, adaptive sampling can be performed based on the complexity of the terrain, for example, increasing the density of sampling points in areas with large terrain undulations and rich details, while appropriately reducing the number of sampling points in flat areas to balance computational accuracy and efficiency.

[0111] It should be noted that in practical applications, the aforementioned detection rays are virtual rays pointing from terrain sampling points to various target light sources. Their function is to simulate the path of light propagating from the light source to the sampling point, used to determine whether there are obstructions along this path. When constructing the detection ray, the vector pointing from the sampling point to the light source can be calculated based on the 3D coordinates of the terrain sampling point and the 3D position or direction of the target light source, and this vector is used as the direction of the detection ray. For example, for a point light source, the ray direction is the vector from the sampling point to the light source; for directional light, the ray direction is the vector opposite to the direction of the light source.

[0112] It should be noted that in practical applications, the intersection detection described above is the process of determining whether the detection ray collides with objects in the scene (including terrain data and static objects). Its function is to determine whether the ray path is obstructed. Intersection detection can utilize various spatial acceleration structures (such as bounding box hierarchy BVH, octree, or KD tree) to improve efficiency. It determines whether the ray is blocked before reaching the target light source by performing intersection operations on the geometric representations (such as triangular meshes) of the detection ray and all potentially occluding objects in the scene.

[0113] It should be noted that in practical applications, the aforementioned occlusion coefficient is a numerical value characterizing the degree of occlusion of a specific terrain sampling point by a particular light source. Its function is to quantify the occlusion effect and provide basic data for subsequent calculations of illumination attenuation. The occlusion coefficient can be a binary quantity; for example, when the detection ray intersects any object, the occlusion coefficient is 0 (indicating complete occlusion); when the detection ray does not intersect any object, the occlusion coefficient is 1 (indicating no occlusion). In more complex implementations, the occlusion coefficient can also be a floating-point number between 0 and 1 to support semi-transparent occlusion or soft shadow effects.

[0114] In one possible implementation, the process of obtaining the occlusion coefficient can be as follows: A terrain sampling point is constructed at each vertex of the terrain mesh. For one of these sampling points, assume there are three target light sources. For the first target light source, a detection ray is constructed from the terrain sampling point toward the light source. Then, intersection detection is performed on this detection ray with the terrain mesh within the baking task block and with all static objects in the scene (such as a tree or a rock). If the ray is detected to intersect with a triangular facet of a tree before reaching the light source, the light source is determined to be occluded, and the corresponding occlusion coefficient is output as 0. Next, the above process is repeated for the second target light source; if the detection ray does not intersect with any object, the occlusion coefficient is output as 1. A similar operation is performed for the third target light source. In this way, the occlusion coefficient corresponding to each target light source can be obtained for the terrain sampling point. This process is executed in parallel on all terrain sampling points within the baking task block to improve efficiency.

[0115] This application configures the construction of terrain sampling points within the baking task block and constructs detection rays for each sampling point and each target light source. Then, it performs unified intersection detection on these detection rays, thus realizing the occlusion of each terrain sampling point by static objects and / or the terrain itself. By performing unified intersection detection on terrain data and static objects, it ensures that all potential occlusion sources are considered, avoiding calculation errors in illumination attenuation caused by missed occlusions, and improving the baking quality of the final unified lightmap.

[0116] In one possible implementation, the above unified occlusion detection operation can be implemented in a practical application scenario as follows: Based on the number of available CPU cores, create a preset parallel thread; within each working thread, perform the following operations in a loop: obtain the current block number jobId from the task number generator jobIDGen using an atomic addition operation; if jobId is greater than or equal to the total number of tasks numJobs, exit the loop; calculate the start and end indices of the baking task block in the terrain grid based on the block number; within the current block, traverse each grid cell and its internal subdivision sampling points, sampling in the [0,1) interval with a fixed step size to obtain higher baking accuracy; for each terrain sampling point: call the terrain data object's interface getPositionAtGrid to obtain the position of the terrain sampling point in world space; calculate the ray direction from the terrain sampling point to the light source based on the current light source position vector, and normalize this direction; for the ray origin... A slight offset is made to avoid numerical interference with the terrain surface itself; first, the ray intersection interface of the terrain data object is called to determine whether the ray is blocked by the terrain itself; if it is not blocked by the terrain, the ray is submitted to the ray query interface of the scene manager to obtain the intersection result with the static objects in the scene; the occlusion coefficient is calculated based on the distance of the nearest collision point, the light source type, and the preset occlusion rules; the light attenuation is calculated based on the occlusion coefficient and the current light source intensity; the current grayscale value of the corresponding terrain sampling point is retrieved from the lightmap buffer, converted to an integer in the range [0, 255] and written in a decrementing manner; if the ray is blocked by the terrain, it can be regarded as having an occlusion coefficient of 1, and the light attenuation is written directly based on the light source intensity for complete or partial attenuation; in each worker thread, a temporary pixel cache used for this task is maintained, and all temporarily allocated memory is released after the block processing is completed to avoid memory leaks; when the thread completes the update of all terrain sampling points in the current block, the jobsDone atomic counter is incremented by one for overall progress statistics.

[0117] In one possible implementation, based on occlusion detection results and light source description data, a characterization of the illumination attenuation of the baking task block due to occlusion by static objects and / or terrain is generated, including:

[0118] For each terrain sampling point within the baking task block: based on the occlusion coefficient and light source description data corresponding to the target light source, calculate the single light source illumination attenuation corresponding to the target light source; superimpose the illumination attenuation of each single light source to obtain the illumination attenuation of the terrain sampling point;

[0119] The collection of illumination attenuation at each terrain sampling point is determined as the illumination attenuation of the baking task block.

[0120] It should be noted that, in practical applications, the above calculation of the single-source illumination attenuation corresponding to the target light source aims to quantify the degree to which a single target light source weakens the illumination intensity of a specific terrain sampling point. This can be achieved by multiplying the original illumination intensity of the target light source (e.g., an intensity value obtained from light source description data) by the transmittance calculated based on the occlusion coefficient (e.g., 1 minus the occlusion coefficient); or by directly subtracting the illumination contribution of the occluded portion from the original illumination intensity of the target light source based on the occlusion coefficient. This calculation ensures that the illumination intensity received by each terrain sampling point from each target light source accurately reflects whether it is occluded.

[0121] It should be noted that in practical applications, the above-mentioned summing of the illumination attenuation of each individual light source to obtain the illumination attenuation of the terrain sampling point aims to comprehensively consider the total illumination attenuation of a single terrain sampling point from all target light sources. This can be achieved by: summing the illumination attenuation of each individual light source obtained from all target light sources for that terrain sampling point; or by performing a weighted summation of the illumination attenuation of each individual light source according to a preset weight (e.g., based on light source distance or importance). Through this summation operation, the total illumination attenuation of the terrain sampling point under the influence of all target light sources can be obtained.

[0122] It should be noted that, in practical applications, the aforementioned step of determining the set of illumination attenuation values ​​from various terrain sampling points as the illumination attenuation value for the baking task block aims to integrate discrete terrain sampling point data to characterize the illumination attenuation state of the entire baking task block. This can be achieved by: directly using the illumination attenuation values ​​of all terrain sampling points within the baking task block as a dataset, or by performing some statistical processing (e.g., average, maximum, minimum, or median) on the illumination attenuation values ​​of all terrain sampling points within the baking task block to obtain a representative value as the illumination attenuation value for the baking task block. This set or representative value can comprehensively reflect the illumination attenuation distribution within the baking task block.

[0123] It should be noted that this application, after configuring the occlusion coefficients of each terrain sampling point pointing to each target light source, calculates the single-source illumination attenuation received by each terrain sampling point from each target light source, and further superimposes these single-source illumination attenuation amounts to accurately obtain the total illumination attenuation amount of each terrain sampling point. Subsequently, the illumination attenuation amounts of these terrain sampling points are aggregated into a set to characterize the illumination attenuation situation of the entire baking task block, ensuring accurate capture of illumination attenuation under complex occlusion environments. This provides an accurate data foundation for the subsequent generation of a unified illumination map covering the terrain area and static objects, thereby improving the image quality of the final generated unified illumination map.

[0124] In one possible implementation, the above method for obtaining the illumination attenuation of a terrain sampling point can be as follows: Assume there is a terrain sampling point P within a certain baking task block. Through the previous unified occlusion detection operation, the occlusion coefficient of the terrain sampling point P pointing towards the target light source L1 is 0.7, and the occlusion coefficient pointing towards the target light source L2 is 0.3. Meanwhile, from the light source description data, it is known that the original illumination intensity of the target light source L1 is I1, and the original illumination intensity of the target light source L2 is I2. At this point, the single-source illumination attenuation obtained by the terrain sampling point P from the target light source L1 can be calculated as (1 - 0.7) * I1 = 0.3 * I1, and the single-source illumination attenuation obtained from the target light source L2 is (1 - 0.3) * I2 = 0.7 * I2. Then, these two single-source illumination attenuation values ​​are added together to obtain the total illumination attenuation of the terrain sampling point P as (0.3 * I1) + (0.7 * I2). Repeat the above calculation process for all terrain sampling points within the baking task block. Finally, the total light attenuation of each of the terrain sampling points is collected to form a light attenuation set, which is then determined as the light attenuation of the baking task block.

[0125] In one possible implementation, a unified lightmap covering the terrain area and all static objects is generated based on the light attenuation of each baking task block, including:

[0126] Based on the light attenuation, terrain data, and light source description data of the baking task blocks, terrain shadow compensation operations are performed on the baking task blocks respectively to obtain the initial light map of each baking task block including the terrain shadow compensation.

[0127] The initial lightmap is subjected to neighborhood smoothing filtering to obtain a uniform lightmap.

[0128] It should be noted that in practical applications, the aforementioned terrain shadow compensation operation is used to correct or adjust the light attenuation caused by terrain occlusion, ensuring the accuracy and realism of the unified lightmap. In the target 3D scene, the undulations and complexity of the terrain may cause certain areas to be occluded by themselves or the surrounding terrain, resulting in shadows. If these shadows are not accurately compensated, the obtained unified lightmap may show unnatural dark areas or hard edges. Therefore, this application configures the light attenuation amount, terrain data, and light source description data based on the baked task blocks, and performs terrain shadow compensation operations on the baked task blocks separately, thereby ensuring the realism of the shadows in each baked task block in the initial lightmap.

[0129] It should be noted that, in practical applications, the aforementioned neighborhood smoothing filtering is an image processing technique used to eliminate noise, jagged edges, or discontinuities in the lightmap, making the lighting transition more natural and smooth. During the lightmap baking process, due to factors such as sampling accuracy, calculation errors, or block stitching, local unevenness or abrupt changes may occur in the unified lightmap. Therefore, this application improves the image quality of the obtained unified lightmap by configuring neighborhood smoothing filtering to improve the smoothness of pixel transitions at the seams of each baking task block.

[0130] In one possible implementation, the developers of this application provided, as follows: Figure 3 The example shown is a unified lightmap. Existing lightmap baking schemes only calculate lightmaps for static mesh objects, lacking unified baking and management for both terrain and static objects. This can easily lead to inconsistent shadow styles or noticeable seams between the two. However, [the following text appears to be a separate, unrelated section:] ...a unified lightmap... Figure 3 As shown in the unified lightmap, this application constructs a unified baking framework that includes terrain and static objects, performs unified occlusion detection on baking task blocks and static objects with spatial correspondence, and generates a unified lightmap covering the terrain area and each static object by configuring the light attenuation amount based on each baking task block. This achieves unified output of baking across the entire scene, solves the defect of low baking consistency caused by separate baking of terrain and static mesh objects, and makes the shadow effects of terrain and static objects consistent and without obvious boundaries.

[0131] In one possible implementation, the terrain shadow compensation operation includes:

[0132] Using a preset light source view projection matrix, each baking task block is mapped to the light source clipping space. Based on the light attenuation, terrain data, and light source description data of the baking task block, the rendering texture coordinates and depth values ​​of the terrain sampling points and other pixels in each baking task block are obtained after being mapped to the light source clipping space.

[0133] For each terrain sampling point: Taking the terrain sampling point as the center, the pixel with the smallest depth value among the other pixels adjacent to the terrain sampling point is determined as the sampling point corresponding to the terrain sampling point; the sampling point is mapped back to world space using a preset inverse light source view projection matrix, and a dot product operation is performed based on the normal vector of the sampling point and the direction vector of each light source, where the direction vector of the light source is the direction vector passing through a target light source and the terrain sampling point; when the dot product operation result indicates that the sampling point is occluded, attenuation compensation is performed on the illumination attenuation corresponding to the terrain sampling point and the target light source when occluded based on a preset compensation amount.

[0134] It should be noted that, in practical applications, the aforementioned preset light source view projection matrix is ​​a mathematical transformation matrix used to transform points in the three-dimensional world coordinate system into a two-dimensional clipping space from the light source's perspective. It can be dynamically generated by combining the light source's observation matrix and projection matrix, or pre-calculated and stored, to transform the geometry in the scene from world space to the space seen by the light source's "eyes" so as to determine which areas are occluded.

[0135] It should be noted that in practical applications, the aforementioned light source clipping space is a three-dimensional space transformed by the light source view projection matrix. Its coordinates are usually normalized to the range of [-1, 1] for subsequent clipping and depth testing, providing a standardized space for easy depth comparison and shadow calculation. Render texture coordinates are used to locate the two-dimensional coordinates of pixels in the texture map, typically ranging from [0, 1]. They can be obtained by further transforming the light source clipping space coordinates to texture space, or they can be UV coordinates predefined for terrain vertices, used to read depth information or shadow values ​​at corresponding locations from the depth map or shadow map.

[0136] It should be noted that in practical applications, the above depth value represents the distance from a pixel to the observer (in this case, the light source). It is obtained during the rendering process by normalizing the Z component of the vertex coordinates and writing it into the depth buffer, or by calculating the intersection of ray projection or the geometry and the light source's view frustum. It is used to determine whether a point is occluded by other objects.

[0137] It should be noted that in practical applications, the aforementioned "other pixels" refer to other rendered pixels in the light source clipping space that are adjacent to or located within the same baking task block of the terrain sampling point, excluding the currently processed terrain sampling point. This is used to find the nearest surface that might occlude or affect the lighting of the current terrain sampling point within a local area. The sampling point corresponding to the one with the smallest depth value is determined, aiming to find the surface point adjacent to the current terrain sampling point and closest to the light source from the light source's perspective. This helps identify local geometry that might occlude the terrain sampling point or find a more accurate reference point for shadow compensation.

[0138] It should be noted that, in practical applications, the aforementioned preset inverse light source view projection matrix is ​​the inverse of the light source view projection matrix. It is used to convert points in the light source clipping space back to the world coordinate system so that subsequent dot product operations of the normal vector and the light source direction vector can be performed.

[0139] It should be noted that in practical applications, the above normal vector is a unit vector perpendicular to the tangent of the surface where the sampling point is located, indicating the orientation of the surface. It can be calculated from the gradient of the terrain height map or stored in the vertex data of the model to calculate the angle between the light and the surface.

[0140] It should be noted that in practical applications, the light source direction vector mentioned above is a unit vector pointing from the sampling point to the target light source. It is fixed for parallel light, and for point light sources or spotlights, it is a vector from the sampling point to the position of the light source. It is then normalized and used to perform a dot product with the normal vector to determine whether the light can directly illuminate the surface.

[0141] It should be noted that in practical applications, the dot product operation is the inner product of two vectors, and the result is a scalar used to determine the relative direction of the light ray and the surface normal. When the dot product result is less than or equal to 0, it usually means that the point is in shadow or that the light ray cannot reach it directly. In this case, the dot product result indicates that the sampling point is occluded.

[0142] It should be noted that in practical application scenarios, the above-mentioned preset compensation amount is a predefined value or function used to adjust the light attenuation amount. It can be an empirical value, a function calculated based on parameters such as ambient light intensity and indirect light intensity, or a lookup table used to simulate indirect lighting or soft shadow effects by increasing the light attenuation amount when occlusion is detected.

[0143] In one possible implementation, the above terrain shadow compensation operation can be implemented in a real-world scenario as follows: for each light source and each terrain block, the block is rendered off-screen on the GPU side; on the CPU side, the floating-point buffer is read or mapped so that it can be sampled in subsequent correction processes. For each terrain sampling point, when considering terrain and other geometric occlusion, the following operations are performed: The world space position of the sampling point is transformed to the light clipping space using the light view projection matrix, and further converted into rendering texture coordinates and depth values; in the rendering texture, several adjacent pixels are sampled centered on the texture coordinates corresponding to the sampling point, and the world space position and depth data of these pixels stored in the floating-point buffer are retrieved; the depth values ​​of these pixels are compared, and the one with the smallest depth or the most obvious occlusion is selected as the representative sample; the world space position of the representative sampling point is transformed back to world space using the inverse projection view matrix; the normal vector at that location is obtained by calling the terrain data object interface, and a dot product is performed with the light direction vector and the sampling point normal vector respectively; if the sampling point has backlighting or an invalid depth value, it is determined that the sampling point is occluded by terrain or other geometry; in the case of occlusion, the illumination value of the sampling point is attenuated again, thereby compensating for shadows caused by terrain geometry on the basis of static object occlusion. After the terrain shadow compensation of the current baking task block is completed, the corresponding floating-point buffer is marked as idle for use by other blocks.

[0144] It should be noted that this application maps each baking task block to the light source clipping space to obtain the depth information of terrain sampling points and their adjacent pixels, and identifies the sampling point closest to the light source. Then, this sampling point is mapped back to world space, and the dot product of its normal vector and the light source direction vector is calculated. When the dot product result indicates that the sampling point is occluded, attenuation compensation is applied to the illumination attenuation of the terrain sampling point. This makes terrain shadow compensation no longer a simple global or coarse adjustment, but a refined processing for each terrain sampling point, combining its local geometric features and its relative relationship with the light source. In this way, accurate detection and targeted compensation of subtle occlusions and self-shadow areas on each baking task block are achieved, thereby avoiding overly harsh or unnatural shadow areas and improving the generation quality of subsequent lightmaps of the same type.

[0145] In one possible implementation, the construction process of the above floating-point buffer can be as follows: create one or more off-screen rendering textures with fixed resolution; obtain a hardware pixel buffer for each off-screen rendering texture and retrieve the corresponding rendering target object from it; create a dedicated camera object for each rendering target, and configure its view matrix and projection matrix in subsequent steps to observe the terrain from the light source's perspective; add a viewport to each rendering target and configure the viewport attributes as follows: background color is white, shadows are disabled, overlays are disabled, skyboxes are disabled, and only pure geometry rendering is retained; at the same time, in order to improve parallelism and resource reuse efficiency, this invention pre-allocates multiple floating-point buffers, each buffer is matched with a rendering texture / camera, and is used to store the world space coordinates and depth information rendered from the light source's perspective; maintain a status flag for each floating-point buffer inside the method to indicate whether the current buffer is idle, so as to support multi-threaded polling and reuse of the buffer.

[0146] In one possible implementation, light source description data of each target light source participating in baking within the target 3D scene is obtained, including:

[0147] Traverse the light source information of each light source in the target 3D scene, and determine the light source that represents a static light source and casts a shadow as the target light source;

[0148] Based on the light source type and diffuse reflection color identifier in the light source information, light source description data including description data of each target light source is generated.

[0149] It should be noted that in practical application scenarios, the above light source information can be obtained through the scene management interface.

[0150] It should be noted that in practical applications, the determination of the target light source can be achieved by reading the attribute identifiers of each light source one by one. These attribute identifiers include at least an "IsStatic" flag and a "CastShadows" flag. Only when both the "IsStatic" and "CastShadows" flags of a light source are true is that light source determined as a target light source and included in the subsequent baking process; conversely, dynamic light sources (such as a character holding a torch or the headlights of a moving vehicle) or ambient lighting that does not produce shadows will be automatically excluded. This filtering mechanism ensures that baking resources are consumed only on light sources with fixed positions that significantly contribute to scene shadows, avoiding invalid calculations. For example, in an outdoor scene containing 50 light sources, if only 12 light sources simultaneously meet both static and cast shadow conditions after traversal, then only these 12 light sources are established as target light sources, and the remaining 38 dynamic or non-cast shadow light sources do not participate in the construction of baking data.

[0151] Furthermore, the aforementioned light source types mainly include: directional light, point light, and spotlight. The diffuse color identifiers are typically floating-point values ​​for the red, green, and blue channels. The method for generating light source description data can be as follows: For different types of light sources, a unified four-dimensional vector is constructed to represent their spatial characteristics. For directional light, its world space direction vector is read, inverted, and then used to construct a four-dimensional vector to represent the direction at infinity. For point light and spotlight, their world space position coordinates are read and used to construct a four-dimensional vector to represent the local light source. Subsequently, according to a preset brightness weighting formula, the diffuse color identifier of the target light source is converted into a single-channel grayscale intensity value or retained as an RGB intensity vector. Finally, the four-dimensional spatial vectors of all target light sources are stored in the light source position array, and the corresponding intensity values ​​are stored in the light source intensity array, forming complete light source description data. This unified abstraction process eliminates the differences in mathematical expression between different light source types, eliminating the need to write branch logic for each light source in subsequent illumination attenuation calculations. This significantly reduces algorithm complexity and improves the execution efficiency of GPU or CPU parallel computing.

[0152] To facilitate understanding of the lightmap baking method provided in the first aspect and any implementation thereof of this application, an explanation is provided here in conjunction with one possible implementation of this application:

[0153] like Figure 4 The diagram shows a flowchart of a lightmap baking method. The specific steps are as follows:

[0154] Step S401: Obtain light source description data, including the light sources of each target light source participating in baking within the target 3D scene. Then trigger step S402.

[0155] Step S402: Obtain terrain data and the corresponding rendered terrain instance. Then trigger step S403.

[0156] Step S403: Map the terrain region to a preset spatial grid based on the rendered terrain instance to obtain multiple baking task blocks, and construct at least one terrain sampling point within each baking task block based on the terrain data. Then, step S404 is triggered.

[0157] Step S404: A pre-defined parallel thread is used to synchronously perform a unified occlusion detection operation and obtain the illumination attenuation amount for each baking task block. This triggers step S405.

[0158] Step S405: For each terrain sampling point within the baking task block: based on the occlusion coefficient and light source description data corresponding to the target light source, calculate the single-light source illumination attenuation corresponding to the target light source; superimpose the illumination attenuation of each single light source to obtain the illumination attenuation of the terrain sampling point; determine the set of illumination attenuation of each terrain sampling point as the illumination attenuation of each baking task block. Then, trigger step S406.

[0159] Step S406: Based on the illumination attenuation, terrain data, and light source description data of the baking task blocks, perform terrain shadow compensation operations on each baking task block to obtain the initial lightmap of each baking task block including the terrain shadow compensation. Then, step S407 is triggered.

[0160] Step S407: Perform neighborhood smoothing filtering on the initial lighting map to obtain a uniform lighting map.

[0161] It should be noted that, in practical application scenarios, steps S402 and S403 are possible implementations of step S102. Steps S404 and S405 are possible implementations of step S103. Steps S406 and S407 are possible implementations of step S104.

[0162] A second aspect of this application provides a lightmap baking system, the block diagram of which is shown below. Figure 5 As shown, the lightmap baking system includes:

[0163] The data acquisition module 501 is used to acquire light source description data, including the light source description data of each target light source participating in baking within the target 3D scene;

[0164] The block division module 502 is used to divide the terrain region of the target 3D scene into multiple baking task blocks based on the terrain data of the target 3D scene, and to establish the spatial correspondence between the baking task blocks and the static objects in the target 3D scene.

[0165] The attenuation calculation module 503 is used to perform a unified occlusion detection operation on baking task blocks and static objects with spatial correspondence based on light source description data and terrain data, and generate the illumination attenuation amount characterizing the baking task block occluded by static objects and / or terrain based on the occlusion detection results and light source description data.

[0166] The lighting baking module 504 is used to generate a unified lighting map covering the terrain area and each static object based on the lighting attenuation of each baking task block.

[0167] In one possible implementation, the block partitioning module 502 is configured as follows:

[0168] Obtain terrain data and the corresponding rendered terrain instance;

[0169] Based on the rendered terrain instance, the terrain region is mapped to a preset spatial grid to obtain multiple baking task blocks, and at least one terrain sampling point is constructed within the baking task block based on the terrain data.

[0170] In one possible implementation, the attenuation calculation module 503 is configured as follows:

[0171] A pre-defined parallel thread is used to synchronously perform a unified occlusion detection operation and obtain the amount of light attenuation for each baking task block.

[0172] In one possible implementation, the attenuation calculation module 503 is configured to perform the uniform occlusion detection operation as follows:

[0173] Construct at least one terrain sampling point within the baking task block based on terrain data;

[0174] For each terrain sampling point within the baking task block: construct detection rays from the terrain sampling points to each target light source based on the light source description data, and perform intersection detection on each detection ray based on the terrain data and static objects of each baking task block, and output the occlusion coefficient corresponding to each target light source based on the intersection detection.

[0175] In one possible implementation, the attenuation calculation module 503 is configured to generate the illumination attenuation of the baking task block due to occlusion by static objects and / or terrain based on the occlusion detection results and light source description data:

[0176] For each terrain sampling point within the baking task block: based on the occlusion coefficient and light source description data corresponding to the target light source, calculate the single light source illumination attenuation corresponding to the target light source; superimpose the illumination attenuation of each single light source to obtain the illumination attenuation of the terrain sampling point;

[0177] The collection of illumination attenuation at each terrain sampling point is determined as the illumination attenuation of the baking task block.

[0178] In one possible implementation, the lighting baking module 504 is set to generate a unified lightmap covering the terrain area and each static object based on the lighting attenuation of each baking task block:

[0179] Based on the light attenuation, terrain data, and light source description data of the baking task blocks, terrain shadow compensation operations are performed on the baking task blocks respectively to obtain the initial light map of each baking task block including the terrain shadow compensation.

[0180] The initial lightmap is processed by neighborhood smoothing filtering to obtain a uniform lightmap.

[0181] In one possible implementation, the lighting baking module 504 is configured to perform terrain shadow compensation operations as follows:

[0182] Using a preset light source view projection matrix, each baking task block is mapped to the light source clipping space. Based on the light attenuation, terrain data, and light source description data of the baking task block, the rendering texture coordinates and depth values ​​of the terrain sampling points and other pixels in each baking task block are obtained after being mapped to the light source clipping space.

[0183] For each terrain sampling point: Taking the terrain sampling point as the center, the pixel with the smallest depth value among the other pixels adjacent to the terrain sampling point is determined as the sampling point corresponding to the terrain sampling point; the sampling point is mapped back to world space using a preset inverse light source view projection matrix, and a dot product operation is performed based on the normal vector of the sampling point and the direction vector of each light source, where the direction vector of the light source is the direction vector passing through a target light source and the terrain sampling point; when the dot product operation result indicates that the sampling point is occluded, attenuation compensation is performed on the illumination attenuation corresponding to the terrain sampling point and the target light source when occluded based on a preset compensation amount.

[0184] In one possible implementation, the data acquisition module 501 is configured as follows:

[0185] Traverse the light source information of each light source in the target 3D scene, and determine the light source that represents a static light source and casts a shadow as the target light source;

[0186] Based on the light source type and diffuse reflection color identifier in the light source information, light source description data including description data of each target light source is generated.

[0187] A third aspect of this application provides a computer storage medium carrying one or more computer programs, which, when executed by an electronic device, enable the electronic device to perform the lightmap baking method described in the first aspect or any implementation thereof.

[0188] This application also provides an electronic device in its embodiments. (See reference...) Figure 6 The diagram illustrates a structural schematic suitable for implementing the electronic device in the embodiments of this application. The electronic device in the embodiments of this application may include, but is not limited to, fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Figure 6 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0189] like Figure 6As shown, the electronic device may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 608 into a random access memory (RAM) 603. When the electronic device is powered on, the RAM 603 also stores various programs and data required for the operation of the electronic device. The processing unit 601, ROM 602, and RAM 603 are interconnected via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0190] Typically, the following devices can be connected to I / O interface 605: input devices 606 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 607 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 608 including, for example, memory cards, hard drives, etc.; and communication devices 609. Communication device 609 allows electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 6 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown. More or fewer devices may be implemented or have alternatively.

[0191] It should also be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. In addition, in the device embodiment drawings provided in this application, the connection relationship between modules indicates that they have a communication connection, which can be implemented as one or more communication buses or signal lines.

[0192] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware, or it can be implemented by special-purpose hardware including application-specific integrated circuits, special-purpose CPUs, special-purpose memory, special-purpose components, etc. Generally, any function performed by a computer program can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be diverse, such as analog circuits, digital circuits, or special-purpose circuits. However, for this application, software program implementation is more often the preferred implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a readable storage medium, such as a computer floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk, or optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, training equipment, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0193] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product.

[0194] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, training device, or data center to another website, computer, training device, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state drives (SSDs)).

Claims

1. A method for baking lightmaps, characterized in that, include: Obtain light source description data for each target light source participating in baking within the target 3D scene; Based on the terrain data of the target 3D scene, the terrain region of the target 3D scene is divided into multiple baking task blocks, and a spatial correspondence between the baking task blocks and static objects in the target 3D scene is established. Based on the light source description data and the terrain data, a unified occlusion detection operation is performed on the baking task block and the static object with the spatial correspondence. Based on the occlusion detection results and the light source description data, a light attenuation amount characterizing the baking task block caused by the static object and / or terrain occlusion is generated. Based on the light attenuation of each of the baking task blocks, a uniform lightmap covering the terrain area and each of the static objects is generated.

2. The lightmap baking method according to claim 1, characterized in that, Based on the terrain data of the target 3D scene, the terrain region of the target 3D scene is divided into multiple baking task blocks, including: Obtain the terrain data and the corresponding rendered terrain instance; Based on the rendered terrain instance, the terrain region is mapped to a preset spatial grid to obtain multiple baking task blocks, and at least one terrain sampling point is constructed within the baking task blocks based on the terrain data.

3. The lightmap baking method according to claim 1, characterized in that, The step involves performing a unified occlusion detection operation on the baking task block and the static object that have the spatial correspondence, based on the light source description data and the terrain data. Based on the occlusion detection results and the light source description data, a light attenuation amount characterizing the baking task block's illumination due to occlusion by the static object and / or terrain is generated, including: The unified occlusion detection operation and the acquisition of the light attenuation are performed synchronously on each of the baking task blocks using a preset parallel thread.

4. The lightmap baking method according to claim 1 or 3, characterized in that, The unified occlusion detection operation includes: Based on the terrain data, at least one terrain sampling point is constructed within the baking task block; For each terrain sampling point within the baking task block: construct detection rays from the terrain sampling points to each target light source based on the light source description data, and perform intersection detection on each detection ray based on the terrain data and static objects of each baking task block, and output the occlusion coefficient corresponding to each target light source based on the intersection detection.

5. The lightmap baking method according to claim 4, characterized in that, The step of generating the illumination attenuation amount characterizing the baking task block due to occlusion by the static object and / or terrain based on the occlusion detection results and the light source description data includes: For each terrain sampling point within the baking task block: based on the occlusion coefficient corresponding to the target light source and the light source description data, calculate the single light source illumination attenuation corresponding to the target light source; sum the illumination attenuation of each single light source to obtain the illumination attenuation of the terrain sampling point; The set of illumination attenuation values ​​at each of the terrain sampling points is determined as the illumination attenuation value of the baking task block.

6. The lightmap baking method according to claim 1, characterized in that, The process of generating a unified lightmap covering the terrain region and each of the static objects based on the light attenuation of each of the baking task blocks includes: Based on the light attenuation, terrain data, and light source description data of the baking task block, terrain shadow compensation operation is performed on the baking task block to obtain the initial light map of each baking task block after terrain shadow compensation. The initial lighting map is subjected to neighborhood smoothing filtering to obtain the unified lighting map.

7. The lightmap baking method according to claim 6, characterized in that, The terrain shadow compensation operation includes: The baking task blocks are mapped to the light source clipping space using a preset light source view projection matrix. Based on the light attenuation, terrain data, and light source description data of the baking task blocks, the rendering texture coordinates and depth values ​​of the terrain sampling points and other pixels in each baking task block after mapping to the light source clipping space are obtained. For each of the terrain sampling points: taking the terrain sampling point as the center, the pixel with the smallest depth value among the other pixels adjacent to the terrain sampling point is determined as the sampling point corresponding to the terrain sampling point; the sampling point is mapped back to world space using a preset inverse light source view projection matrix, and a dot product operation is performed based on the normal vector of the sampling point and each light source direction vector, wherein the light source direction vector is the direction vector passing through a target light source and the terrain sampling point; when the dot product operation result indicates that the sampling point is occluded, attenuation compensation is performed on the illumination attenuation amount corresponding to the terrain sampling point and the target light source when occluded, based on a preset compensation amount.

8. The lightmap baking method according to claim 1, characterized in that, The acquisition of light source description data, including the light source description data of each target light source participating in baking within the target 3D scene, includes: The light source information of each light source in the target 3D scene is traversed, and the light source that represents a static light source and casts a shadow is determined as the target light source. Based on the light source type and diffuse color identifier in the light source information, light source description data including description data of each target light source is generated.

9. A lightmap baking system, characterized in that, The lightmap baking system includes: The data acquisition module is used to acquire light source description data, including the light source description data of each target light source participating in baking within the target 3D scene; The block division module is used to divide the terrain region of the target 3D scene into multiple baking task blocks based on the terrain data of the target 3D scene, and to establish the spatial correspondence between the baking task blocks and static objects in the target 3D scene. The attenuation calculation module is used to perform a unified occlusion detection operation on the baking task block and the static object with the spatial correspondence based on the light source description data and the terrain data, and generate the light attenuation amount characterizing the baking task block occluded by the static object and / or terrain based on the occlusion detection result and the light source description data. The lighting baking module is used to generate a unified lighting map covering the terrain area and each of the static objects based on the lighting attenuation of each of the baking task blocks.

10. A computer storage medium, characterized in that, The storage medium carries one or more computer programs that, when executed by an electronic device, enable the electronic device to implement the lightmap baking method as described in any one of claims 1 to 8.