Shadow map baking method, device, equipment and computer readable storage medium

By computing and storing the distance field shadow data of the shadow map in parallel, the problem of low shadow map baking efficiency is solved, and more efficient virtual scene rendering is achieved.

CN112734900BActive Publication Date: 2024-08-23TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110104608.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-01-26
Publication Date
2024-08-23
Estimated Expiration
2041-01-26

AI Technical Summary

Technical Problem

In the existing technology, the baking efficiency of shadow maps is low and the calculation takes a long time, resulting in low shadow rendering efficiency.

Method used

By obtaining object information and light source information in the virtual scene, the appropriate texture resolution is calculated, and based on this information, parallel calculation and storage of distance field shadow data are performed to increase computing density and reduce data transmission batches.

Benefits of technology

The efficiency of shadow map baking is improved, the calculation time is significantly reduced, and the rendering performance of virtual scenes is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112734900B
    Figure CN112734900B
Patent Text Reader

Abstract

The present application provides a method, device, equipment and computer-readable storage medium for baking shadow maps; the method includes: obtaining at least one object information, light source information and a first resolution in a virtual scene; the first resolution is a specified map resolution; according to at least one object information, at least one second resolution is determined, and the second resolution represents the map resolution calculated based on the object information in the virtual scene; based on the light source information, at least one object information, the first resolution and at least one second resolution, at least one distance field shadow data corresponding to the at least one object information is calculated; at least one distance field shadow data is stored in a map of the first resolution, and a distance field shadow map corresponding to each object information in the at least one object information is obtained. Through the present application, the efficiency of baking shadow maps can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to graphics processing technology, and in particular to a method, device, equipment and computer-readable storage medium for baking shadow maps. Background Art

[0002] Shadow effects can greatly improve the level of virtual scene images and enhance the realism of virtual scenes. Shadow effects are obtained by rendering shadows in the corresponding virtual scenes. In related technologies, most of the shadows are pre-baked onto a map, and then the shadow map is directly used for rendering. In practical applications, distance field shadow maps are usually baked for virtual scenes. However, the calculation of the distance field shadow map method in related technologies takes a long time, which makes the efficiency of shadow map baking low. Summary of the invention

[0003] Embodiments of the present application provide a method, apparatus, device, and computer-readable storage medium for baking shadow maps, which can improve the efficiency of baking shadow maps.

[0004] The technical solution of the embodiment of the present application is implemented as follows:

[0005] The present application embodiment provides a method for baking a shadow map, including:

[0006] Acquire at least one object information, light source information and a first resolution in a virtual scene; the first resolution is a specified texture resolution;

[0007] Determining at least one second resolution based on the at least one object information, the second resolution representing a texture resolution calculated based on the object information in the virtual scene;

[0008] Calculate at least one distance field shadow data corresponding to the at least one object information based on the light source information, the at least one object information, the first resolution and the at least one second resolution;

[0009] The at least one distance field shadow data is stored in a map of the first resolution, and a distance field shadow map corresponding to each object information in the at least one object information is obtained.

[0010] An embodiment of the present application provides a shadow map baking device, including:

[0011] An information acquisition module, used to acquire at least one object information, light source information and a first resolution in a virtual scene; the first resolution is a specified texture resolution;

[0012] A resolution determination module, configured to determine at least one second resolution according to the at least one object information, wherein the second resolution represents a texture resolution calculated according to the object information in the virtual scene;

[0013] a data calculation module, configured to calculate at least one distance field shadow data corresponding to the at least one object information based on the light source information, the at least one object information, the first resolution and the at least one second resolution;

[0014] The map generation module is used to store the at least one distance field shadow data in the map of the first resolution to obtain a distance field shadow map corresponding to each object information in the at least one object information.

[0015] In some embodiments of the present application, the data calculation module is further used to calculate the ratio of the at least one second resolution to the first resolution to obtain at least one supersampling parameter; the supersampling parameter characterizes the conversion relationship between the first resolution and the second resolution; using the light source information, the at least one object information and the at least one second resolution, at least one shadow edge corresponding to the at least one object information is determined; based on the at least one supersampling parameter, the distance from the pixel center of the first resolution to the at least one shadow edge is calculated to obtain the at least one distance field shadow data.

[0016] In some embodiments of the present application, the light source information includes multiple sub-light source information; the data calculation module is also used to screen out corresponding matching light source information from the multiple sub-light source information for each object information in the at least one object information; the matching light source information represents the information of the sub-light source that causes illumination or shadow effects on the object; the target second resolution corresponding to each object information is selected from the at least one second resolution, and each object information is rasterized at the target second resolution to obtain the rasterized pixels of each object information; according to the position of the texel corresponding to the rasterized pixel and the matching light source information, the shadow edge corresponding to each object information is extracted at the same time; the position of the texel is obtained by expanding the texture coordinates of each object information; when the shadow edge extraction of the at least one object information is completed, the at least one shadow edge corresponding to the at least one object information is obtained.

[0017] In some embodiments of the present application, the data calculation module is also used to perform shadow coverage judgment on the texels corresponding to the rasterized pixels of each object information at the same time based on the matching light source information and the position of the texels to obtain shadow coverage information; the shadow coverage information represents whether the texel is in the shadow; and using the shadow coverage information, the shadow edges corresponding to each object information are extracted respectively.

[0018] In some embodiments of the present application, the data calculation module is further used to calculate, based on the at least one supersampling parameter, at the same time, the distance from the pixel center of the first resolution to each of the at least one shadow edge to obtain the distance field shadow data corresponding to each shadow edge; when the calculation of the distance field shadow data for the at least one shadow edge is completed, the at least one distance field shadow data is obtained.

[0019] In some embodiments of the present application, the data calculation module is further used to extract a target supersampling parameter corresponding to each shadow edge from the at least one supersampling parameter; at the same time, based on the target supersampling parameter corresponding to each shadow edge, calculate the minimum distance from the pixel center of the first resolution to each shadow edge; and use the minimum distance as the distance field shadow data corresponding to each shadow edge.

[0020] In some embodiments of the present application, the data calculation module is also used to divide the pixels of the first resolution into blocks according to the target oversampling coefficient to obtain at least one sub-pixel block; perform parallel calculation on the distance from the at least one sub-pixel block to the current shadow edge to obtain at least one shadow distance corresponding to the at least one sub-pixel block; the current shadow edge is any one of the at least one shadow edges; select the minimum shadow distance from the at least one shadow distance corresponding to the at least one sub-pixel block as the minimum distance from the pixel center of the first resolution to the current shadow edge; when the minimum distance is determined for each of the shadow edges, the minimum distance from the pixel center of the first resolution to each shadow edge is obtained.

[0021] In some embodiments of the present application, the data calculation module is also used to extract multiple matching pixels corresponding to each sub-pixel block in the at least one sub-pixel block from each pixel of the second resolution based on the pixels of the first resolution; filter out shadow pixels belonging to the current shadow edge from the multiple matching pixels; calculate the distance from each sub-pixel block to the shadow pixels respectively to obtain the shadow distance corresponding to each sub-pixel block; when the shadow distance calculation is completed for the at least one sub-pixel block, the at least one shadow distance is obtained.

[0022] In some embodiments of the present application, the data calculation module is also used to select adjacent pixels for pixels of the first resolution; extract a pixel set corresponding to the adjacent pixels from each pixel of the second resolution; extract pixels from the pixel set that are at the same position as the pixels of each sub-pixel block at the first resolution, and obtain multiple matching pixels corresponding to each sub-pixel block.

[0023] In some embodiments of the present application, the first resolution includes a plurality of first sub-resolutions; the shadow map baking device further includes: an information classification module;

[0024] The information classification module is used to classify the at least one object information by using the multiple first sub-resolutions and the at least one second resolution to obtain multiple object information sets;

[0025] The data calculation module is further configured to calculate distance field shadow data for the object information in each object information set at the same time based on the light source information, the object information in each object information set, the first sub-resolution corresponding to each object information set, and the second resolution corresponding to each object information in each object information set, so as to obtain a distance field shadow data set corresponding to each object information set; and to form the at least one distance field shadow data corresponding to the at least one object information by using the distance field shadow data in the distance field shadow data set corresponding to each object information set.

[0026] In some embodiments of the present application, the data calculation module is also used to classify the at least one object information using the multiple first sub-resolutions to obtain multiple initial object information sets; compare the second resolutions corresponding to the object information in the current initial object information set with the first resolution corresponding to the current initial object information set to obtain the classification coefficient corresponding to the object information; the current initial object information set is any one of the multiple initial object information sets; based on the classification coefficients corresponding to the object information, classify the object information in the current initial object information set to obtain one or more current intermediate object information sets corresponding to the current initial object information set; when the determination of one or more intermediate object information sets is completed for each initial object information set, the multiple object information sets are obtained.

[0027] The embodiment of the present application provides a shadow map baking device, including:

[0028] A memory for storing baking instructions for executable shadow maps;

[0029] The processor is used to implement the shadow map baking method provided in the embodiment of the present application when executing the executable shadow map baking instruction stored in the memory.

[0030] An embodiment of the present application provides a computer-readable storage medium storing executable shadow map baking instructions, which is used to cause a processor to execute and implement the shadow map baking method provided in the embodiment of the present application.

[0031] The embodiments of the present application have the following beneficial effects: after obtaining at least one object information, light source information, and a first resolution, the shadow map baking device will first calculate at least one second resolution based on the at least one object information, and then calculate the distance field shadow data corresponding to the at least one object information based on the light source information, the object information, the first resolution, and the at least one second resolution, and store the calculated at least one distance field shadow data on the map, thereby realizing the calculation of the distance field shadow field data based on the map resolution corresponding to each object information, improving the calculation density, reducing the data transmission batches, and ultimately improving the efficiency of shadow map baking. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1 It is a schematic diagram of the shadow effect of the shadow map algorithm;

[0033] Figure 2 This is a schematic diagram of the shadow effect of the shadow map algorithm in the case of high-resolution mapping;

[0034] Figure 3 This is a schematic diagram of a distance field shadow map;

[0035] Figure 4 is an optional architecture diagram of a shadow map baking system 100 provided in an embodiment of the present application;

[0036] Figure 5 is a schematic diagram of the structure of a shadow map baking device provided in an embodiment of the present application;

[0037] Figure 6 This is an optional process diagram of the shadow map baking method provided in the embodiment of the present application. Figure 1 ;

[0038] Figure 7 This is an optional process diagram of the shadow map baking method provided in the embodiment of the present application. Figure 2 ;

[0039] Figure 8 is a schematic diagram comparing the first resolution and the second resolution provided in an embodiment of the present application;

[0040] Fig. 9is a schematic diagram of the index relationship between object information and sub-light source information provided in an embodiment of the present application;

[0041] Fig.10 is a schematic diagram of a pixel center and a shadow edge at a first resolution provided in an embodiment of the present application;

[0042] Fig.11 It is a block diagram provided in an embodiment of the present application;

[0043] Fig.12 is a schematic diagram of calculating shadow distance provided by an embodiment of the present application;

[0044] Fig.13 is a schematic diagram of classifying each object information in the current initial object information set provided by an embodiment of the present application;

[0045] Fig.14 It is the effect of the shadow of the embodiment of the present application;

[0046] Fig.15 A code debugging diagram of a shadow map baking method in the related art is shown;

[0047] Fig.16 A code debugging diagram of a shadow map baking method according to an embodiment of the present application is shown. DETAILED DESCRIPTION

[0048] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.

[0049] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it can be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0050] In the following description, the terms "first\second" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.

[0051] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0052] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.

[0053] 1) Cloud Technology refers to a hosting technology that unifies hardware, software, network and other resources within a wide area network or local area network to achieve data computing, storage, processing and sharing.

[0054] Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model. It can form a resource pool, which can be used on demand and is flexible and convenient. Cloud computing technology will become an important support. The backend services of the technical network system require a large amount of computing and storage resources, such as video websites, picture websites and more portal websites. With the rapid development and application of the Internet industry, in the future, each item may have its own identification mark, which needs to be transmitted to the backend system for logical processing. Data of different levels will be processed separately. All kinds of industry data need strong system backing support, which can only be achieved through cloud computing.

[0055] 2) Shadow map baking refers to preprocessing and storing the more complex shadow data before rendering the virtual scene, that is, baking it onto the map for direct use when rendering the virtual scene.

[0056] 3) Light source, which can create lighting and shadow effects for objects in the virtual scene, is an important factor in the rendering of the virtual scene. In the rendering of the virtual scene, there are mainly three different types of light sources: parallel light, point light source, and spotlight.

[0057] 4) Ray tracing is a technology used in computer graphics to render virtual scenes. When rendering, rays are emitted from each pixel in the image to the virtual scene, and then the intersection points between the objects in the virtual scene and the virtual scene are calculated, and then shaded and rendered. Ray tracing can render highly realistic virtual scenes, but the computational overhead of ray tracing is also relatively high.

[0058] 5) Shadow Maps algorithm: In the rendering of virtual scenes, shadow maps are often used to represent shadows. The main process of the shadow map algorithm is as follows: first, based on the perspective of the light source, the virtual scene is rendered to obtain the surface distance closest to the light source and store it on the map; then, during normal rendering, the distance from the rendered object surface to the light source is calculated to determine whether the object is in the shadow.

[0059] 6) Distance field shadow map, that is, the distance field shadow data is stored in the map. The distance field shadow data describes the distance from the center of the pixel to the edge of the shadow.

[0060] 7) Signed Distance Function: In the measurement control, there is a set A. The signed distance field function is used to define the shortest distance from a given point X to the edge of set A. If X is on the inside of set A, the function value is greater than 0; as X approaches the edge, the function value also approaches 0; when X is on the outside of A, the function value is less than 0. The signed distance field function can be defined as X is on the inside, the function value is less than 0, and X is on the outside, the function value is greater than 0.

[0061] 8) Texel, short for Texture Pixel, is the basic unit of texture mapping. Just like a picture is composed of a group of pixels, in texture space, a texture map is composed of a group of texels.

[0062] 9) Data transmission batch (Batch). In virtual scene rendering, the rendering data is submitted to the graphics processing unit (GPU) for rendering once, which is called a Batch. In the application, whether it is rendering a point, a triangle, or a complex model with a high number of faces, it is a rendering Batch. Due to the call of the driver layer, the number of batches has a great relationship with the rendering performance. For example, for a scene with the same number of 1 million triangles, the performance of rendering according to 100 batches is much higher than that of rendering according to 10,000 batches. Therefore, in order to speed up the rendering performance, usually a Batch needs to submit enough triangles for rendering. Similarly, when using a general parallel computing architecture for baking or other general GPU calculations, the submission of a computing task is also a Batch.

[0063] 10) Compute Unified Device Architecture (CUDA) is a model that enables parallel programming. Based on a set of application programming interfaces (APIs) provided by CUDA, parallel units can be used on the GPU to perform parallel calculations, thereby achieving computing acceleration.

[0064] CUDA programming involves two parts, namely the rendering core code (Kernel) and the running code (Host code). The Kernel is used to perform general calculations on the GPU, and the Host code is used to prepare the Kernel running data, pass the data to the graphics card, and call the Kernel for calculations, thereby obtaining the final result from the GPU.

[0065] 11) The CUDA-based ray tracing framework (Optix) uploads virtual scene data to the GPU and uses the GPU's ray tracing core to achieve hardware acceleration of ray tracing, thereby greatly improving the efficiency of ray tracing.

[0066] Shadow effects can greatly improve the level of virtual scene images and enhance the realism of virtual scenes. Shadow effects are obtained by rendering shadows in the corresponding virtual scenes. However, shadow rendering is very complex. Therefore, in related technologies, most of them pre-bake shadows onto maps, and then directly use texture sampling during shadow rendering to obtain the lighting and shadow information of objects in the virtual scene. This method has low computational overhead, but is limited by file size limitations, and the resolution of baked maps is usually low, resulting in a greater sense of jaggedness.

[0067] For example, Figure 1 This is a schematic diagram of the shadow effect of the shadow map algorithm, see Figure 1 ,When the resolution of the texture is 128×128, it can be clearly seen that the shadow in the virtual scene has a more obvious jagged feel, for example Figure 1 The areas pointed by the middle arrows have obvious aliasing, which is difficult to eliminate through filtering.

[0068] In this case, the jaggedness of the shadow can be reduced by increasing the resolution of the texture. However, increasing the resolution of the texture will increase the video memory required for processing, the size of the file package, etc. For example, when the resolution of the texture is increased to 256×256, the size of the file package needs to be increased by 4 times, but the shadow in the virtual scene still has visible jaggedness. Figure 2 This is a schematic diagram of the shadow effect of the shadow map algorithm under high-resolution mapping. It can be seen that Figure 2 The area pointed by the middle arrow still has fine sawtooth, but compared with Figure 1 The sawtooth in Figure 2 Although the amplitude of the aliasing is reduced, it is still not eliminated.

[0069] Compared with the shadow map algorithm, the distance field shadow algorithm can significantly reduce the aliasing of shadows in the case of low-resolution maps. The distance field shadow map stores distance field shadow data, which describes the distance from the center of the pixel to the edge of the shadow. For example, Figure 3 is a diagram of a distance field shadow map. Figure 3 , each square (each square filled with black dots) represents a pixel in the texture, and each pixel stores the encoded distance field shadow data. In order to calculate the distance field shadow data, each pixel needs to be subdivided into high-resolution sub-pixels (corresponding to the black dots in each square in the figure). Figure 3 The triangle area 3-1 in represents the shaded area. Figure 3 For pixel 3-2 in the image, the distance from the pixel to the shadow edge is the length of the perpendicular line from the center of pixel 3-2 (i.e. point 3-3) to the lower left edge 3-11 of the triangle area 3-1. In practical applications, since the shadow edge is usually an irregular shape, the shortest distance from the pixel center (i.e. point 3-3) to the sub-pixel at the shadow edge is approximated as the distance from the pixel center to the shadow edge, that is, the shortest distance from the pixel center to the sub-pixel at the shadow edge is taken as the distance field shadow data and stored in each pixel of the map. Figure 3 That is, among the four distances of the four sub-pixels from the pixel center (i.e., point 3-3) to the shadow edge, the shortest distance 3-4 is selected as the distance from the pixel center to the shadow edge, thereby obtaining the distance field shadow data.

[0070] It can be seen that the baking process of the distance field shadow map includes the following steps:

[0071] S1. Expand the model data of the object according to the texture coordinates, and rasterize it at a high resolution (high resolution is the resolution at which the object is represented in the object space) to obtain at least one texel data, each texel data corresponds to a sub-pixel, and the texel data stores the position information of the object.

[0072] S2. In the GPU, for each texel, a ray is sent from its position to the light source to calculate whether the texel is in shadow.

[0073] S3. Determine the shadow edge of the object based on whether the texel and surrounding texels are in the shadow.

[0074] S4. For each pixel, expand outward from its center, search for high-resolution shadow edge sub-pixels, and calculate the shortest distance.

[0075] S5. Store the shortest distance in the corresponding pixel on the map.

[0076] In a virtual scene, the distance field shadow map is baked more than once. For example, there are M objects in the virtual scene, and each object receives shadow projections from N light sources on average. Then the virtual scene needs to be baked M×N times. Each time the distance field shadow map is baked, 4 CUDA initiation operations need to be called, so the final number of batches is 4×M×N. In addition, the resolution of the distance field shadow map is usually very low (due to the file package volume, etc., a lower resolution map needs to be selected), which makes the GPU calculation density low. It can be seen that in the related technology, when obtaining the distance field shadow map for the virtual scene, the calculation density is low and the data transmission batches are large, which makes the calculation of the distance field shadow map time-consuming, and ultimately makes the reference baking efficiency low.

[0077] The embodiments of the present application provide a method, device, equipment and computer-readable storage medium for baking shadow maps, which can improve the efficiency of baking shadow maps. The following describes an exemplary application of the baking device for shadow maps provided by the embodiments of the present application. The baking device for shadow maps provided by the embodiments of the present application can be implemented as a terminal or a server. Among them, the server can be an independent server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The terminal can be a smart phone, a tablet computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited to this. The terminal and the server can be directly or indirectly connected via wired or wireless communication, and this application is not limited here.

[0078] It should be noted that in the embodiment of the present application, the shadow map baking device can be implemented as a server alone or as a terminal alone, so that all steps of the shadow map baking method provided in the embodiment of the present application are completed on the server or the terminal. In the embodiment of the present application, the shadow map baking device can also be implemented as a device cluster composed of a server and a terminal at the same time. At this time, some steps in the shadow map baking method provided in the embodiment of the present application are implemented on the server side, and other steps are implemented on the terminal side. Below, an exemplary application of the shadow map baking device will be described.

[0079] See also Figure 4 , Figure 4It is an optional architectural diagram of a shadow map baking system 100 provided in an embodiment of the present application. To implement a baking application that supports a shadow map, a terminal 200 (terminal 200-1 and terminal 200-2 are shown as examples) is connected to a shadow map baking device 400 via a network 300. The network 300 may be a wide area network or a local area network, or a combination of the two.

[0080] Terminal 200-1 is used to generate object information, light source information (such as characters, environment information, light source information, etc. in the game scene) in the virtual scene and specify a first resolution. That is, the designer can design the parameters of the virtual scene through the design tool on the graphical interface 200-11 of the terminal 200-1, generate model data of objects in the virtual scene, that is, generate object information, and specify the parameters of the light source in the virtual scene, that is, generate light source information, and at the same time, specify the resolution of the map used for shadow map baking, that is, specify the resolution of the distance field shadow map, and obtain the first resolution. Then, terminal 200-1 sends at least one object information, light source information and first resolution of the virtual scene to the baking device 400 of the shadow map. The baking device 400 of the shadow map stores at least one object information, light source information and first resolution in the virtual scene for use when the baking of the shadow map starts.

[0081] After the baking process of the shadow map starts, the baking device 400 of the shadow map obtains at least one object information, light source information and first resolution information in the virtual scene, wherein the first resolution information is the map resolution of the specified distance field shadow. The baking device 400 of the shadow map determines the second resolution according to the at least one object information, and the second resolution represents the map resolution calculated for the information of the object in the virtual scene. The baking device 400 of the shadow map calculates at least one distance field shadow data corresponding to the at least one object information based on the light source information, at least one object information, the first resolution and at least one second resolution, and stores the at least one distance field shadow data in the map of the first resolution, and obtains the distance field shadow map corresponding to each object in the at least one object, thereby completing the baking process of the shadow map.

[0082] Afterwards, the shadow map baking device 400 can send the distance field shadow map to the terminal 200-2 (for example, through the game installation package). When the terminal 200-2 starts the rendering of the virtual scene (for example, when starting the game), it calls the distance field shadow map and displays the rendering result on the graphical interface 200-21, thereby realizing the rendering of the virtual scene.

[0083] See also Figure 5 , Figure 5 is a schematic diagram of the structure of a shadow map baking device provided in an embodiment of the present application, Figure 5 The shadow map baking device 400 shown includes: at least one processor 410, a memory 450, at least one network interface 420 and a user interface 430. The various components in the terminal 400 are coupled together through a bus system 440. It can be understood that the bus system 440 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 440 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 440 is not described in detail. Figure 5 Various buses are labeled as bus system 440 .

[0084] Processor 410 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.

[0085] The user interface 430 includes one or more output devices 431 that enable presentation of media content, including one or more speakers and / or one or more visual display screens. The user interface 430 also includes one or more input devices 432, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.

[0086] The memory 450 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard disk drives, optical disk drives, etc. The memory 450 may optionally include one or more storage devices that are physically remote from the processor 410.

[0087] The memory 450 includes a volatile memory or a non-volatile memory, and may also include both volatile and non-volatile memories. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 450 described in the embodiments of the present application is intended to include any suitable type of memory.

[0088] In some embodiments, memory 450 can store data to support various operations, examples of which include programs, modules, and data structures, or a subset or superset thereof, as exemplarily described below.

[0089] Operating system 451, including system programs for processing various basic system services and performing hardware-related tasks, such as a framework layer, a core library layer, a driver layer, etc., for implementing various basic services and processing hardware-based tasks;

[0090] A network communication module 452, for reaching other computing devices via one or more (wired or wireless) network interfaces 420, exemplary network interfaces 420 include: Bluetooth, Wireless Fidelity (Wi-Fi), and Universal Serial Bus (USB);

[0091] a presentation module 453 for enabling presentation of information via one or more output devices 431 (e.g., display screen, speaker, etc.) associated with the user interface 430 (e.g., a user interface for operating peripherals and displaying content and information);

[0092] The input processing module 454 is used to detect one or more user inputs or interactions from one of the one or more input devices 432 and translate the detected inputs or interactions.

[0093] In some embodiments, the device provided in the embodiments of the present application can be implemented in software. Figure 5 A shadow map baking device 455 stored in the memory 450 is shown, which may be software in the form of a program and a plug-in, etc., and includes the following software modules: an information acquisition module 4551, a resolution determination module 4552, a data calculation module 4553, a map generation module 4554, and an information classification module 4555. These modules are logical, and therefore can be arbitrarily combined or further split according to the functions implemented. The functions of each module will be described below.

[0094] In other embodiments, the shadow map baking device provided in the embodiments of the present application can be implemented in hardware. As an example, the shadow map baking device provided in the embodiments of the present application can be a processor in the form of a hardware decoding processor, which is programmed to execute the shadow map baking method provided in the embodiments of the present application. For example, the processor in the form of a hardware decoding processor can adopt one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs) or other electronic components.

[0095] Exemplarily, an embodiment of the present application provides a shadow map baking device, including:

[0096] A memory for storing baking instructions for executable shadow maps;

[0097] The processor is used to implement the shadow map baking method provided in the embodiment of the present application when executing the executable shadow map baking instruction stored in the memory.

[0098] Below, the method for baking shadow maps provided in the embodiment of the present application will be described in combination with the exemplary application and implementation of the baking device for shadow maps provided in the embodiment of the present application.

[0099] See also Figure 6 , Figure 6 This is an optional process diagram of the shadow map baking method provided in the embodiment of the present application. Figure 1 , will combine Figure 6 The steps shown are explained.

[0100] S101: Acquire at least one object information, light source information, and a first resolution in a virtual scene.

[0101] The embodiment of the present application is implemented in a scene where a shadow map is baked for a virtual scene, and more specifically, in a scene where distance field shadow data is baked into a map. When starting to bake a shadow map, the baking device for the shadow map will first obtain information about each object in the virtual scene, obtain at least one object information, and simultaneously obtain light source information and a first resolution of the virtual scene, so as to start baking the shadow map based on these data later. The first resolution is a specified map resolution.

[0102] It should be noted that the at least one object information, light source information and first resolution of the virtual scene obtained by the baking device of the shadow map may be received from the terminal, or may be automatically generated by itself according to the requirements input by the designer. In some embodiments, the baking device of the shadow map may immediately obtain the at least one object information, light source information and first resolution after receiving the at least one object information, light source information and first resolution of the virtual scene sent by the terminal to start the baking process of the shadow map, or may store the at least one object information, light source information and first resolution of the virtual scene sent by the terminal in the storage space, and only start to obtain the at least one object information, light source information and first resolution at a specified time or after receiving the instruction of the designer, thereby starting the baking process of the shadow map.

[0103] It is understandable that at least one object information of a virtual scene refers to the model data corresponding to each object in the virtual scene, and each object information includes the object's position, normal, surface area, size, etc. The light source information of a virtual scene refers to the parameters of the light source in the virtual scene, which includes the light source's position, intensity, color, illumination range, etc.

[0104] It should be noted that the light source information does not refer to the parameters of a specific light source, but is a general term for the parameters of all light sources in the virtual scene, that is, the light source information may include multiple sub-light source information, each sub-light source information corresponds to a light source in the virtual scene.

[0105] It should be noted that the first resolution is a general term for the specified texture resolution, and does not specifically refer to a resolution. In other words, the first resolution may actually include one or more first sub-resolutions, and each first sub-resolution is specified. Especially for some virtual scenes, it is usually necessary to comprehensively consider the effects under different resolutions during design. Therefore, there will be multiple specified texture resolutions, that is, the first resolution will contain multiple first sub-resolutions. Each first sub-resolution in the first resolution can be a resolution specified by the designer or a default resolution. Furthermore, the value of the first sub-resolution can be 128×128, or 64×64, and can also be set to other values ​​according to actual needs, which is not limited in this application.

[0106] In the embodiment of the present application, the virtual scene may be a game scene, a CG animation scene, or other scenes that need to be rendered, which is not limited in the embodiment of the present application.

[0107] S102: Determine at least one second resolution according to at least one object information.

[0108] After obtaining the object information of the virtual scene, the shadow map baking device will first extract the surface area of ​​each object from each object information, and then multiply it by the surface area of ​​the object according to the resolution representation requirement per square meter of the object space, so as to obtain the resolution of the map required to fully unfold each object. The shadow map baking device records the resolution calculated for each object as the second resolution, so that the shadow map baking device can obtain at least one second resolution. That is to say, in the embodiment of the present application, the second resolution represents the map resolution calculated based on the object information in the virtual scene.

[0109] Furthermore, the second resolution is calculated based on the surface area of ​​the object. For example, assuming that in the object space, 100*100 pixels are required to represent each square meter, and for an object, the surface area is 2 square meters, then the texture resolution required for the object when unfolding is 200*200.

[0110] It should be noted that the second resolution calculated based on the surface area is the most basic and lowest resolution for baking and rendering, which is generally higher. The first resolution is limited by factors such as the size of the installation package and will not be too high. Therefore, the first resolution will be smaller than the second resolution and has a certain multiple relationship with the second resolution, that is, the second resolution can be obtained by supersampling the first resolution, and the first resolution can be obtained by sampling the second resolution.

[0111] S103: Calculate at least one distance field shadow data corresponding to the at least one object information based on the light source information, the at least one object information, the first resolution, and the at least one second resolution.

[0112] After calculating at least one second resolution, the shadow map baking device will combine the light source information, each object information, the first resolution and each second resolution to calculate the distance field shadow data for each object in the virtual scene in parallel. That is to say, in the embodiment of the present application, the shadow map baking device uses the light source information, at least one object information, the first resolution and at least one second resolution to calculate the distance field shadow data for all objects in the virtual scene at the same time. Exemplarily, when there are N objects in the virtual scene, the shadow map baking device can simultaneously calculate the distance field shadow data of N objects in parallel, thereby baking the shadows of N objects at the same time. In this way, the parallelism is increased to N times the original, which will inevitably increase the calculation density and reduce the number of data transmission batches, which will ultimately improve the search efficiency of the distance field shadow data.

[0113] It should be noted that, in some embodiments of the present application, when the first resolution includes only one first sub-resolution, the shadow map baking device can only perform parallel calculations of distance field shadow data for each object in the virtual scene. When the first resolution includes multiple first sub-resolutions, the shadow map baking device can search for distance field shadow data of each object in the virtual scene for each first sub-resolution one by one; the shadow map baking device can also search for distance field shadow data of each object in the virtual scene in parallel for each first sub-resolution (in this case, there are two layers of parallel calculations, one layer for each first sub-resolution, and one layer for each object in each first sub-resolution), thereby further improving the calculation efficiency of distance field shadow data.

[0114] That is to say, when the first resolution includes N first sub-resolutions, the shadow map baking device essentially needs to bake out the distance field shadow map of the virtual scene for the N first sub-resolutions, thereby obtaining N distance field shadow maps. At this time, the shadow map baking device can generate corresponding distance field shadow maps one by one for the N first sub-resolutions, or can generate corresponding distance field shadow maps for the N first sub-resolutions at the same time.

[0115] S104: Store at least one distance field shadow data in a map of the first resolution to obtain a distance field shadow map corresponding to each object information in the at least one object information.

[0116] After obtaining at least one distance field shadow data corresponding to at least one object information, the shadow map baking device can store the obtained at least one distance field shadow data on a map of the first resolution, so that the map storing the distance field shadow data of each object in the virtual scene is used as a distance field shadow map. In this way, the shadow device can obtain the distance field shadow map corresponding to each object in the virtual scene.

[0117] In the embodiment of the present application, after obtaining at least one object information, light source information, and a first resolution, the shadow map baking device will first calculate at least one second resolution based on the at least one object information, and then based on the light source information, the object information, the first resolution and the at least one second resolution, perform a parallel search for the distance field shadow data corresponding to the at least one object information, and store the at least one distance field shadow data searched in parallel on the map, thereby achieving the simultaneous improvement of the map resolution corresponding to each object in the virtual scene for multiple objects to calculate the distance field shadow data, improve the calculation density, reduce data transmission batches, and ultimately improve the efficiency of shadow map baking.

[0118] See also Figure 7 , Figure 7 This is an optional process diagram of the shadow map baking method provided in the embodiment of the present application. Figure 2 In some embodiments of the present application, based on the light source information, at least one object information, the first resolution and the at least one second resolution, at least one distance field shadow data corresponding to the at least one object information is calculated, that is, the specific implementation process of S103 may include: S1031-S1033, as follows:

[0119] S1031. Calculate the ratio of at least one second resolution to the first resolution to obtain at least one supersampling parameter.

[0120] When baking the distance field shadow map, the shortest distance from the center of the first pixel to the edge of the shadow is calculated, and the shadow edge is generally calculated based on the second resolution, that is, the map resolution calculated based on the surface area of ​​the object. When the shadow map baking device searches for distance field shadow data in parallel, it is necessary to first use at least one second resolution as the numerator and the first resolution as the denominator for comparison, and the obtained ratio is the supersampling parameter, thereby obtaining at least one supersampling parameter corresponding to at least one second resolution. It should be noted that the supersampling parameter characterizes the conversion relationship between the first resolution and the second resolution, that is, it indicates how many times the second resolution can be obtained by supersampling the first resolution.

[0121] It should be noted that, since there is a correspondence between the second resolution and the object information, the supersampling parameters calculated based on the second resolution also have a correspondence with the object information, that is, at least one supersampling parameter and at least one object information also have a one-to-one correspondence.

[0122] For example, the present application embodiment provides a comparison diagram of the first resolution and the second resolution, see Figure 8 , triangle 8-1 is the object, the area formed by the black squares is the shadow corresponding to the object, the large square formed by 3×3 small squares (such as square 8-2) is a pixel of the first resolution, and each small square (such as square 8-3) is a pixel of the second resolution. It can be seen that there is a corresponding relationship between the pixels of the first resolution and the pixels of the second resolution, that is, 3×3 pixels of the second resolution can form a pixel of the first resolution.

[0123] S1032: Determine at least one shadow edge corresponding to the at least one object information by using the light source information, the at least one object information and the at least one second resolution.

[0124] To search the distance field shadow data of each object in parallel, it is necessary to first determine the shadow edges corresponding to each object in parallel. The shadow map baking device first simultaneously rasterizes each object information in the at least one object information at the second resolution corresponding to it, and then extracts the shadow edge corresponding to each object information based on the texel data obtained after rasterization. When the shadow map baking device determines the corresponding shadow edges for all the object information, at least one shadow edge corresponding to the at least one object information is obtained.

[0125] S1033. Calculate the distance from the center of a pixel of the first resolution to at least one shadow edge based on at least one supersampling parameter to obtain at least one distance field shadow data.

[0126] The shadow map baking device then searches for the shadow edge corresponding to each object information from the center of the first pixel according to the supersampling parameter corresponding to each object information, and then calculates the distance from the center of the first pixel to the shadow edge corresponding to each object information, thereby obtaining the distance field shadow data corresponding to each object information. When the parallel calculation of the distance from the center of the pixel of the first resolution to at least one shadow edge is completed, the shadow map baking device can obtain at least one distance field shadow data.

[0127] In an embodiment of the present application, a shadow map baking device can first calculate at least one supersampling parameter using at least one second resolution and the first resolution, and use light source information, at least one object information and at least one second resolution to determine the corresponding shadow edge for each object information in parallel. Finally, the supersampling parameter corresponding to each object information is used to perform a parallel search for the distance from the pixel center of the first resolution to each shadow edge. When the parallel search is completed, at least one distance field shadow data can be obtained, thereby realizing a parallel search of at least one distance field shadow data, improving the degree of parallelism, and thus improving the efficiency of shadow map baking.

[0128] In some embodiments of the present application, the light source information of the virtual scene includes a plurality of sub-light source information; using the light source information, at least one object information and at least one second resolution, determining at least one shadow edge corresponding to at least one object information, that is, the specific implementation process of S1032, may include: S1032a-S1032d, as follows:

[0129] S1032a: For each object information in the at least one object information, select corresponding matching light source information from the plurality of sub-light source information.

[0130] The light source information of the virtual scene includes multiple sub-light source information, but not every object will be affected by all light sources. Therefore, the shadow map baking device needs to find the sub-light source information that can affect the corresponding object from multiple sub-light sources for each object information, and use these light source information as the matching light source information corresponding to each object information. It should be noted that the impact of a sub-light source on an object refers to bringing light to the object or causing a shadow to appear on the object. Therefore, the matching light source information represents the information of the sub-light source that causes light or shadow to the object.

[0131] It is understandable that the shadow map baking device determines whether a sub-light source affects an object based on the type of sub-light source. For example, when a sub-light source is sunlight, it will affect all objects, so the matching light source information corresponding to each object information will include this sub-light source. When a sub-light source is a point light source or a spotlight, the shadow map baking device will determine whether the object is within the influence radius of this sub-light source. When the object is within the influence radius, the matching light source information of the object information corresponding to the object will include the sub-light source information corresponding to this sub-light source, otherwise, this sub-light source information will not be included.

[0132] It should be noted that, in the embodiment of the present application, the shadow map baking device determines the corresponding matching light source information for each object information, which is actually to establish an index relationship between the object information and the sub-light source, so that when determining the shadow edge, each object information can be quickly indexed to the sub-light source information that can affect it.

[0133] For example, Fig. 9 is a schematic diagram of the index relationship between object information and sub-light source information provided by the embodiment of the present application. Fig. 9 There are M object information 9-1 and N sub-light sources. Each object information is represented by a layer, and all sub-light source information constitutes an N-row light source list 9-2. The shadow map baking device extracts the sub-light sources that affect each object information, thereby obtaining matching light source information. For example, for object information A, the matching light source information is the information of light source a and sub-light source b. For object information B, the matching light source information is the information of sub-light source b and sub-light source c. For object information C, the matching light source information is the information of sub-light source b. For object information D, the matching light source information is the information of sub-light source c. And so on, until the matching light source information is determined for all object information, and then it is possible to generate an index table 9-3 between the object information and the sub-light source information, where the index table has a total of P rows.

[0134] S1032b. Select a target second resolution corresponding to each object information from at least one second resolution, and rasterize each object information at the target second resolution to obtain rasterized pixels of each object information.

[0135] The shadow map baking device selects the second resolution corresponding to each object information from at least one second resolution according to the correspondence between the object information and the second resolution, and records the selected second resolution as the target second resolution. After that, each vertex of the shadow map baking device object is mapped to the pixel of the map of the first resolution, and then the pixels between each vertex are rasterized to obtain the rasterized pixel.

[0136] S1032c, extracting the shadow edge corresponding to each object information at the same time according to the position of the texel corresponding to the rasterized pixel and the matching light source information.

[0137] It should be noted that there is a correspondence between rasterized pixels and texels, and this correspondence is determined during the design. The shadow map baking device expands the object information according to the texture coordinates to obtain the position of the texel. In other words, the position of the texel is obtained by expanding the texture coordinates of each object information.

[0138] S1032d: When the extraction of the shadow edge of at least one object information is completed, at least one shadow edge corresponding to the at least one object information is obtained.

[0139] When the shadow map baking device completes the extraction of shadow edges for all object information through parallel tasks, at least one shadow edge corresponding to at least one object information can be obtained.

[0140] In an embodiment of the present application, a shadow map baking device can first determine matching light source information for each object information, rasterize each object information at the corresponding target second resolution, and then extract the shadow edge of each object in parallel based on the position of the texel corresponding to the rasterized pixel obtained by rasterization and the matching light source information, thereby increasing the parallelism during shadow edge extraction, improving the calculation density, reducing data transmission batches, and thus improving the efficiency of shadow map baking.

[0141] In some embodiments of the present application, based on the position of the texel corresponding to the rasterized pixel and the matching light source information, the shadow edge corresponding to each object information is extracted at the same time, that is, the specific implementation process of S1032c may include: S201-S202, as follows:

[0142] S201, based on the matching light source information and the position of the texel, at the same time, perform shadow judgment on the texel corresponding to the rasterized pixel of each object information to obtain shadow coverage information;

[0143] The shadow map baking device emits rays from the position of the texel corresponding to the rasterized pixel to the matching light source information, thereby calculating the intersection of the object and the virtual scene, and then judging whether the texel is in the shadow according to the position of the intersection, that is, judging whether the texel corresponding to the rasterized pixel of each object information is covered by the shadow, thereby obtaining the shadow coverage information. In other words, the shadow coverage information represents whether the texel is in the shadow.

[0144] S202: Using the shadow coverage information, respectively extract the shadow edge corresponding to each object information.

[0145] After determining the shadow coverage information of the texels, the shadow map baking device can determine a shadow boundary based on which texels are in the shadow and which are not in the shadow. This boundary is the shadow edge. In this way, the shadow map baking device can extract the corresponding shadow edge for each object information.

[0146] In the embodiment of the present application, the shadow map baking device can determine whether the texel corresponding to the rasterized pixel of each object information is in the shadow according to the matching light source information and the position of the texel, and then extract the shadow edge corresponding to each object information according to whether the texel is in the shadow. In this way, the shadow map baking device completes the extraction of the shadow edge corresponding to each object information.

[0147] In some embodiments of the present application, based on at least one supersampling coefficient, the distance from the pixel center of the first resolution to at least one shadow edge is calculated to obtain at least one distance field shadow data, that is, the specific implementation process of S1033 may include: S1033a-S1033b, as follows:

[0148] S1033a. Based on at least one supersampling parameter, calculate the distance from the pixel center of the first resolution to each shadow edge of at least one shadow edge at the same time to obtain distance field shadow data corresponding to each shadow edge.

[0149] S1033b: When the calculation of the distance field shadow data for at least one shadow edge is completed, at least one distance field shadow data is obtained.

[0150] Since there is a correspondence between at least one supersampling parameter and at least one second resolution, and at least one second resolution is determined based on at least one object information, there is a correspondence between at least one supersampling parameter and at least one object information. At the same time, there is a correspondence between at least one shadow edge and at least one object information, and thus, there is also a correspondence between at least one supersampling parameter and at least one shadow edge. The shadow map baking device selects the supersampling parameter corresponding to each shadow edge from at least one supersampling parameter based on this correspondence, and then searches the distance from the pixel center of the first resolution to each shadow edge based on the supersampling parameter corresponding to each shadow edge, thereby obtaining the distance field shadow data corresponding to each shadow edge. When the shadow map baking device completes the search for distance field shadow data for all shadow edges, there will be at least one distance field shadow data.

[0151] In an embodiment of the present application, a shadow map baking device can search for distance field shadow data for each shadow edge based on at least one supersampling parameter, thereby enabling parallel extraction of at least one distance field shadow data, thereby improving parallelism, increasing computing density, reducing data transmission batches, and ultimately improving the efficiency of shadow map baking.

[0152] In some embodiments of the present application, based on at least one supersampling parameter, the distance from the pixel center of the first resolution to each shadow edge of at least one shadow edge is calculated at the same time to obtain distance field shadow data corresponding to each shadow edge, that is, the specific implementation process of S1033a may include: S301-S303, as follows:

[0153] S301. Extract a target supersampling parameter corresponding to each shadow edge from at least one supersampling parameter.

[0154] The shadow map baking device first determines a supersampling parameter corresponding to each shadow edge based on the correspondence between at least one supersampling parameter and at least one shadow edge, and records this supersampling parameter as a target supersampling parameter.

[0155] S302: At the same time, based on the target supersampling parameter corresponding to each shadow edge, calculate the minimum distance from the pixel center of the first resolution to each shadow edge.

[0156] Illustratively, the present application embodiment provides a schematic diagram of a pixel center and a shadow edge at a first resolution. Fig.10 , the shadow is composed of black grids, point P is the pixel center of the first resolution, and the baking device of the shadow map actually requires the minimum distance from point P to the edge of the shadow composed of black grids.

[0157] S303: Use the minimum distance as distance field shadow data corresponding to each shadow edge.

[0158] At the same time, the shadow map baking device starts to calculate the minimum distance from the pixel center of the first resolution to each shadow edge based on the target supersampling parameter corresponding to each shadow edge. Among them, the calculation of the minimum distance corresponding to a single shadow edge is a separate calculation task. Therefore, when the shadow map baking device calculates the minimum distance corresponding to each shadow edge, it performs the number of shadow edges, that is, the number of object information, calculation tasks in parallel. Therefore, the parallelism will become times the number of original object information (that is, when the object information is N, the parallelism becomes N times). Finally, the shadow map baking device uses the searched minimum distance as the distance field shadow data, thereby obtaining at least one distance field shadow data.

[0159] In an embodiment of the present application, the shadow map baking device can extract the target supersampling parameter corresponding to each shadow edge from at least one supersampling parameter, and then at the same time, start to calculate the minimum distance from the pixel center of the first resolution to each shadow edge based on the target supersampling parameter, and use the minimum distance as the distance field shadow data of each shadow edge. In this way, the shadow map baking device completes the search process of the distance field shadow data.

[0160] In some embodiments of the present application, based on the supersampling coefficient corresponding to each shadow edge, the minimum distance from the pixel center of the first resolution to each shadow edge is calculated, that is, the specific implementation process of S302 may include: S3021-S3024, as follows:

[0161] S3021. Divide the pixels of the first resolution into blocks according to the target supersampling coefficient to obtain at least one sub-texel block.

[0162] The shadow map baking device evenly blocks the pixels of the first resolution according to the target supersampling parameter, and records each sub-block as a sub-pixel block, thereby obtaining at least one pixel block. It should be noted that the sub-pixel block obtained by the shadow map baking device after the block division is the same size as the pixel of the second resolution.

[0163] For example, Fig.11 This is a block diagram provided in an embodiment of the present application. The shadow map baking device decomposes the pixel 11-1 of the first resolution into 3×3 small blocks, thereby obtaining 9 sub-pixel blocks. The pixel center of the first resolution is located in the most central sub-pixel block among the 9 sub-pixel blocks.

[0164] S3022. Perform parallel calculation on the distance from at least one sub-pixel block to the current shadow edge to obtain at least one shadow distance corresponding to the at least one sub-pixel block.

[0165] The current shadow edge is any one of the at least one shadow edge.

[0166] The shadow map baking device selects one of the at least one shadow edge as the current shadow edge, and then calculates the distance from each sub-pixel block to the current shadow edge to obtain the shadow edge corresponding to each sub-pixel block. When the shadow edges of all sub-pixel blocks are calculated, at least one shadow distance will be obtained.

[0167] S3023. Select a minimum shadow distance from at least one shadow distance corresponding to at least one sub-pixel block as the minimum distance from the pixel center of the first resolution to the current shadow edge.

[0168] S3024: When the minimum distance is determined for each shadow edge, the minimum distance from the pixel center of the first resolution to each shadow edge is obtained.

[0169] After obtaining at least one shadow distance corresponding to at least one sub-pixel block, the shadow map baking device compares the at least one shadow distance to determine the minimum shadow distance, and then selects the minimum shadow distance as the minimum distance corresponding to the current shadow edge. After the shadow map baking device determines the minimum distance for each shadow edge, the minimum distance from the pixel center of the first resolution to each shadow edge can be obtained.

[0170] It should be noted that in the embodiment of the present application, calculating the shadow from the sub-pixel block to the shadow edge is actually sharing the search process of the minimum distance to each sub-pixel block. However, the search process corresponding to each sub-texel block can actually be performed in parallel, thereby improving the parallelism of the search for the minimum distance to the shadow edge and further improving the efficiency of shadow map baking.

[0171] In an embodiment of the present application, a shadow map baking device can divide pixels of a first resolution into blocks to obtain at least one sub-pixel block, and then calculate in parallel the distance from at least one sub-pixel block to a shadow edge, thereby selecting the minimum distance from the center of a pixel of the first resolution to each shadow edge. In this way, the degree of parallelism during the minimum distance search can be increased, further improving the efficiency of shadow map baking.

[0172] In some embodiments of the present application, the distance from at least one sub-pixel block to the current sub-shadow edge is calculated in parallel to obtain at least one shadow distance corresponding to the at least one sub-pixel block, that is, the specific implementation process of S2022 may include: S3022a-S3022d, as follows:

[0173] S3022a. Extract, from pixels of the second resolution according to the pixels of the first resolution, a plurality of matching pixels corresponding to each sub-pixel block in at least one sub-pixel block.

[0174] The shadow map baking device initially selects some pixels for each sub-pixel block from each pixel of the second resolution based on the pixels of the first resolution, and uses these pixels as matching pixels, thereby obtaining a plurality of matching pixels.

[0175] It should be noted that the shadow map baking device can determine the pixels corresponding to each sub-pixel block in each pixel of the second resolution, and then use the adjacent pixels of the pixels corresponding to each sub-pixel block as matching pixels. The shadow map baking device can also first select some pixels that have a specific regularity with the pixels of the first resolution from each pixel of the second resolution, and then select multiple matching pixels from these pixels. For example, from the pixel set corresponding to the pixels of the first resolution in each pixel of the second resolution (the pixels in the pixel set can just form the pixels of the first resolution), select the pixels whose position in the pixel set is the same as the position of the pixels of a sub-pixel block in the first resolution as matching pixels.

[0176] S3022b. Filter out shadow pixels corresponding to the current shadow edge from multiple matching pixels.

[0177] Next, the shadow map baking device determines whether each matching pixel belongs to the current shadow edge, and selects the matching pixels belonging to the current shadow edge as shadow pixels.

[0178] S3022c. Calculate the distance from each sub-pixel block to the shadow pixel respectively to obtain the shadow distance corresponding to each sub-pixel block.

[0179] It can be understood that the distance from each sub-pixel block to the shadow pixel can be expressed by the number of pixels between the shadow pixel and the pixels corresponding to each sub-pixel block in each pixel of the second resolution, and can also be expressed by the straight-line distance between the shadow pixel and the pixels corresponding to each sub-pixel block in each pixel of the second resolution.

[0180] S3022d: When the calculation of the shadow distance for at least one sub-pixel block is completed, at least one shadow distance is obtained.

[0181] When the shadow map baking device calculates the corresponding shadow distances for all sub-pixel blocks, at least one shadow distance corresponding to at least one sub-pixel block is obtained.

[0182] For example, Fig.12 Schematic diagram of calculating shadow distance provided by the embodiment of the present application. Fig.12 As shown, the black grids form the shadows, and the grids filled with point clouds are the matching pixels determined by the shadow map baking device for each sub-pixel block. The grids filled with diagonal lines are a sub-pixel block, and point P is the pixel center of the first resolution. The shadow map baking device calculates the distance of this sub-pixel block, that is, the grid 12-1 filled with point clouds, when the grids filled with horizontal lines are at the edge of the shadows formed by the black grids. This distance is the shadow distance.

[0183] In an embodiment of the present application, a shadow map baking device can first filter out a plurality of matching pixels for each sub-pixel block from each pixel of the second resolution based on the pixel center of the first resolution, and then filter out the matching pixels belonging to the current shadow edge from the plurality of matching pixels to obtain shadow pixels, thereby calculating the distance from each sub-pixel block to the corresponding shadow pixel. In this way, at least one shadow distance can be obtained, thereby realizing the process of distributing the distance search to each sub-pixel block and improving the parallelism during the distance search.

[0184] In some embodiments of the present application, based on the pixels of the first resolution, a plurality of matching pixels corresponding to each sub-pixel block in at least one sub-pixel block are extracted from each pixel of the second resolution, that is, a specific implementation process of S3022a may include: S401-S403, as follows:

[0185] S401 . For pixels of a first resolution, select adjacent pixels.

[0186] The shadow map baking device selects pixels around a pixel of the first resolution from each pixel of the first resolution, and these pixels are neighboring pixels.

[0187] It can be understood that in the embodiment of the present application, the shadow map baking device can select the four pixels above, below, left and right of the pixel of the first resolution as adjacent pixels, or can select all the eight pixels around the first resolution as adjacent pixels.

[0188] S402: Extract a pixel set corresponding to adjacent pixels from each pixel of the second resolution.

[0189] Next, the shadow map baking device selects a set of pixels that can form adjacent pixels from each pixel of the second resolution based on the correspondence between the pixels of the first resolution and the pixels of the second resolution.

[0190] For example, see Fig.12 , an adjacent pixel of a pixel of the first resolution is 12-2, and the pixel set of the second resolution corresponding to this adjacent pixel is the 9 small squares in the adjacent pixel 12-2 (these 9 small squares are all pixels in the second resolution). The baking device of the shadow map selects these pixels and combines them as the pixels corresponding to the adjacent pixel.

[0191] S403 : Extract pixels in the pixel set that are located at the same position as the pixels of each sub-pixel block at the first resolution, to obtain a plurality of matching pixels corresponding to each sub-pixel block.

[0192] The shadow map baking device first determines the position of the pixels of each sub-pixel block at the first resolution, and then extracts the pixels at the same position in the pixel set. The extracted pixels are the matching pixels corresponding to each sub-pixel block.

[0193] For example, see Fig.12 The small grid 12-3 (sub-pixel block) filled with diagonal lines is located at the upper left corner of the pixel of the first resolution, and the adjacent pixels are the 8 3×3 large grids around the pixel 12-4 of the first resolution. The shadow map baking device selects the pixel in the upper left corner of each large grid as the matching pixel.

[0194] In an embodiment of the present application, the shadow map baking device can first select adjacent pixels for pixels of the first resolution, then extract a pixel set corresponding to the adjacent pixels from each pixel of the second resolution, and then extract pixels from the pixel set that have the same position as each pixel block in the pixels of the first resolution. In this way, the shadow map baking device can complete the extraction of matching pixels to facilitate the subsequent extraction of shadow pixels from the matching pixels.

[0195] In some embodiments of the present application, the first resolution includes multiple first sub-resolutions. In this case, the shadow map baking device can group at least one object information and search for distance field shadow data for the object information in each group of object information in parallel, thereby further improving the degree of parallelism. Therefore, based on the light source information, at least one object information, the first resolution and at least one second resolution, at least one distance field shadow data corresponding to the at least one object information is calculated, that is, the specific implementation process of S103 can include S1034-S1036, as follows:

[0196] S1034. Classify at least one object information by using the multiple first sub-resolutions and the at least one second resolution to obtain multiple object information sets.

[0197] In an embodiment of the present application, a shadow map baking device can divide at least one object information into different object information sets based on multiple first sub-resolutions and at least one second resolution, wherein the first sub-resolution of each object information in each object information set is the same, the second resolution is the same, and thus the multiple relationship between the first sub-resolution and the second resolution is also the same. That is, the embodiment of the present application first uses the first sub-resolution to perform a preliminary classification of at least one object information, and then further uses the second resolution to perform classification on the object information set obtained by the preliminary classification, thereby obtaining one or more object information sets. Thus, each object information set has its corresponding first sub-resolution and second resolution.

[0198] It should be noted that, in the embodiment of the present application, the number of object information sets and the number of first sub-resolutions are not necessarily the same.

[0199] S1035. Based on the light source information, the object information in each object information set, the first sub-resolution corresponding to each object information set, and the second resolution corresponding to each object information set, distance field shadow data is calculated for each object information in each object information set at the same time to obtain a distance field shadow data set corresponding to each object information set.

[0200] Since the first sub-resolution corresponding to each object information in each object information set is the same, and the second resolution is also the same, the shadow map baking device determines the distance field shadow data for each object information set in parallel based on the light source information, the object information in each object information set, and the first sub-resolution and second resolution corresponding to each object information set, and processes each object information set in parallel. It should be noted that when processing each object information set in parallel, each object information in each object information set can be processed one by one in sequence (in this case, there is only one layer of parallelism) or in parallel (in this case, there are two layers of parallelism).

[0201] It can be understood that the process of performing distance field shadow search on each object information in each object information set in the embodiment of the present application can be implemented according to steps S1031-S1033, which will not be repeated here, except that each object information set is performed in parallel.

[0202] It should be noted that after each object information in each object information set performs a distance field shadow search, a distance field shadow data will be determined, and the shadow map baking device combines the distance field shadow data corresponding to each object information in each object information set together to obtain a distance field shadow data set corresponding to each object information set. In other words, the distance field shadow data set corresponding to each object information set includes the distance field shadow data corresponding to each object information in each object information set.

[0203] S1036. Use the distance field shadow data in the distance field shadow data set corresponding to each object information set to compose at least one distance field shadow data corresponding to at least one object information.

[0204] When the shadow map baking device completes the search for distance field shadows for object information in all object information sets, it actually completes the search for distance field shadows for at least one object information. Thus, the distance field shadow data in the distance field shadow data set corresponding to each object information set obtained by the shadow map baking device can constitute at least one distance field shadow data.

[0205] In an embodiment of the present application, when the first resolution includes multiple first sub-resolutions, the shadow map baking device can divide at least one object information into one or more object information sets based on the multiple first sub-resolutions and at least one second resolution, thereby performing a distance field shadow search process for the object information on all object information sets in parallel, further improving the parallelism of the distance field shadow search.

[0206] In some embodiments of the present application, at least one object information is classified by using the multiple first sub-resolutions and the at least one second resolution to obtain multiple object information sets, that is, the specific implementation process of S1034 may include: S1034a-S1034d, as follows:

[0207] S1034a. Classify at least one sub-object information using multiple first sub-resolutions to obtain multiple initial object information sets.

[0208] The shadow map baking device first performs preliminary classification of at least one sub-object information according to multiple first sub-resolutions, thereby obtaining an initial object information set with the same number as the first sub-resolutions.

[0209] It should be noted that, in some embodiments of the present application, when the shadow map baking device is implemented as a terminal and a server at the same time, this step can be completed in the terminal, so that the server only needs to receive the object information in each initial object information set.

[0210] S1034b. Compare each second resolution corresponding to each piece of object information in the current initial object information set with the first sub-resolution corresponding to the current initial object information set to obtain a classification coefficient corresponding to each piece of object information.

[0211] The current initial object information set is any one of multiple initial object information sets.

[0212] The shadow map baking device selects one of the multiple initial object information sets as the current initial information set, and then uses the second resolution corresponding to each object information in the current initial object information set to compare with the first sub-resolution, so as to calculate the classification coefficient corresponding to each object information.

[0213] It can be understood that the shadow map baking device can use the second resolution as the denominator and the first sub-resolution as the numerator to obtain the classification coefficient; the shadow map baking device can also use the second resolution as the numerator and the first sub-resolution as the denominator for comparison. At this time, the ratio is actually the supersampling coefficient, that is, the classification coefficient corresponding to each object information can also be the supersampling coefficient corresponding to each object information.

[0214] S1034c. Classify each object information in the current initial object information set according to the classification coefficient corresponding to each object information, and obtain one or more current intermediate object information sets corresponding to the current initial object information set.

[0215] Exemplarily, the present application embodiment provides a schematic diagram for classifying each object information in the current initial object information set, see Fig.13 , there are three initial object information sets, namely set 13-1, set 13-2 and set 13-3. Among them, set 13-1 is the current initial object information set, and the shadow map baking device uses the supersampling coefficient of each object information in this object information set as the classification coefficient to classify each object information in this object information set. Fig.13 It can be seen that the object information in the current object information set can be divided into 4 categories based on 3 times oversampling coefficient, 5 times oversampling coefficient, 7 times oversampling data, and 11 times oversampling coefficient. Each category at this time is the intermediate object information set.

[0216] S1034d: When one or more intermediate object information sets are determined for each initial object information set, multiple object information sets are obtained.

[0217] When the shadow map baking device determines one or more intermediate object information sets for each initial object information set, each initial object information can be integrated with the corresponding one or more intermediate object information sets to obtain multiple object information sets.

[0218] In an embodiment of the present application, a shadow map baking device may first use multiple first sub-resolutions to preliminarily classify at least one object information, and then use the second resolution corresponding to each object information in each initial object information set to classify each object information in each initial object information set. In this way, the shadow map baking device can obtain one or more object information sets.

[0219] The following is an explanation of an exemplary application of the embodiments of the present application in a practical application scenario.

[0220] The embodiment of the present application is implemented when the shadows in the game scene are pre-baked into a map. The baking of the shadow map is mainly divided into the following steps:

[0221] Step 1. The terminal collects model data of all objects in the game scene (at least one object information), and groups the objects based on the low-resolution resolution set by the user (the user may set multiple different low-resolution resolutions, and each low-resolution resolution is the first sub-resolution) (grouping to obtain multiple initial object information sets). The low-resolution resolutions in the same group are the same and are transmitted to the baking server in groups (the baking device of the shadow map is implemented as both the terminal and the baking server, that is, preliminary classification is performed corresponding to the terminal, and the server only receives the object information in each preliminary object information set).

[0222] Step 2. After obtaining the grouping, the baking server calculates the supersampling parameter (the supersampling parameter at this time is the classification coefficient) based on the size data of the object and the low-resolution resolution (first calculate the second resolution according to the surface area of ​​the object information, and then calculate the classification coefficient according to the second resolution and the first sub-resolution), and subdivides it into more detailed subgroups (multiple object information sets) according to the supersampling coefficient. The low-resolution resolution and supersampling coefficient of each subgroup are the same (the first resolution and the second resolution of the object information in each object information set are the same, so the multiple relationship between the first resolution and the second resolution is the same).

[0223] Step 3: For all objects in the subgroup (each object information in each initial object information set), high-resolution rasterization is performed, and the texels store position data and normal data. At the same time, for each object, the light source that affects the object is collected.

[0224] Step 4: Transmit the position data and discovery data of multiple objects, each object is 1 layer, and organize all light sources that affect the objects in the subgroup into an array and transmit it to the GPU (i.e., start calculating the distance field shadow data for each object information set in parallel).

[0225] Step 5: Within each subgroup, establish index information of a layered distance field shadow map. The index information of each layer of the distance field shadow map corresponds to a combination of an object and a light source that affects the object (i.e., the object information in each object information set determines the matching light source).

[0226] Step 6: For each layer of data, obtain the corresponding light source data and object data according to the index and determine the shadow edge.

[0227] Step 7: Calculate the distance field shadow of each layer of high resolution (second resolution).

[0228] Step 8: downsample each layer of data to obtain low-resolution distance field shadows (distance field shadow data) for each layer.

[0229] Step 9: Bake the distance field shadows into the low-resolution texture (bake into the first-resolution texture).

[0230] It can be seen that the above process is to process all subgroups in parallel, and at the same time, for each object in each subgroup, the distance field shadow data of each object is calculated in parallel.

[0231] Furthermore, the distance field shadow for each object in the subgroup can be calculated as follows:

[0232] S501, upload various information in the game scene (including the light source information and at least one object information of the virtual scene) and the baking kernel (processing program code) to the GPU (i.e., the parallel computing unit in the baking device of the shadow map). For each object in the game scene, there is a distance field shadow map corresponding to each light source (the distance field shadow map corresponding to each object information). Based on the low-resolution resolution (first resolution) set by the user and the actual size of the object (the surface area of ​​the object), the high-resolution resolution (second resolution) is calculated, and the supersampling coefficient (supersampling parameter) is calculated.

[0233] S502 , rasterizing the object's position, normal and other data to a high resolution (the object information is rasterized at the corresponding target second resolution), and uploading to the GPU.

[0234] S503. In the GPU, distance field shadows are calculated using the following two sub-steps:

[0235] S5031. Emit rays from the position of each texel at high resolution (the position of the texel corresponding to the rasterized pixel) to the light source, and calculate whether the texel is in the shadow (shadow coverage information).

[0236] S5032. Based on the result of S5031, calculate the position of the shadow edge (use the shadow coverage information to extract the shadow edge corresponding to each object). In the GPU, it is necessary to calculate the distance from the low-resolution pixel center (the pixel center of the first resolution) to the position of the shadow edge.

[0237] Since the search range is large and the low-resolution resolution is small, it is not suitable for GPU operation. In actual operation, each pixel is first divided into blocks (at least one sub-pixel block is obtained) according to the supersampling coefficient, and the distance of each sub-block (at least one shadow distance) is calculated respectively, so as to spread the calculation to each sub-block. Fig.12In the figure, the small grids filled with point clouds only need to process the small grids filled with diagonal lines, determine whether they are at the edge of the shadow, and calculate the distance. Other sub-blocks also only search their corresponding square areas. The distances of each sub-block are merged, that is, the shortest distance is taken as the low-resolution distance field shadow (distance field shadow data).

[0238] At this point, the distance field shadow map for each object in the subgroup is complete.

[0239] The effectiveness of shadow map baking is measured by the aliasing of the final shadows. Fig.14 This is the shadow effect of the embodiment of the present application, from Fig.14 It can be seen that there is no jagged feeling on the edge of the shadow. Fig.14 The area pointed by the middle arrow shows smooth lines without obvious or fine aliasing, so the shadow map baking method of the embodiment of the present application can ensure the shadow effect.

[0240] The efficiency of baking shadow maps is measured by the processing time and the number of simultaneous GPU and CPU activations. Fig.15 , Fig.15 The code debugging diagram of the baking method of the shadow map in the related art is shown. Fig.15 It can be seen that in the related art, the stage duration (Stages Duration) is 2337.319s, the category duration (Category Duration) is 2337.692s, and the number of starts is 14456 times. Fig.16 The code debugging diagram of the baking method of the shadow map of the embodiment of the present application is shown. Fig.16 It can be seen that the stage duration (Stages Duration) is reduced to 107.972s, the category duration (Category Duration) becomes 108.025s, and the number of startups is reduced to 186 times. Therefore, compared with the related art, the shadow map baking method provided in the embodiment of the present application is about 20 times faster and the number of startups is reduced by about 80 times. It can be seen that the shadow map baking method provided in the embodiment of the present application improves the calculation density, reduces the data transmission batches, and greatly improves the efficiency of shadow map baking.

[0241] The shadow map baking method of the embodiment of the present application can be adapted to a variety of game scenes. Table 1 shows the shadow map baking efficiency changes of the shadow map baking method of the embodiment of the present application in different game scenes:

[0242] Table 1

[0243] Game scene Related technologies This application Temple of the Sun 60s 10s Infiltrator 2400s 120s 2K*2K large terrain 72000s 5000s

[0244] As can be seen from Table 1, in the game scene of the Temple of the Sun, the baking of the shadow map of the related technology takes about 60 seconds, while the present application only takes 10 seconds. In the game scene of the Infiltrator, the baking of the shadow map of the related technology takes 2400 seconds, while the present application only takes 12 seconds. In the game scene of a 2K*2K large terrain, the baking of the shadow map of the related technology takes 72000 seconds, while the present application only takes 5000 seconds. It can be seen that compared with the related art, the baking method of the shadow map of the present application can greatly improve the efficiency of the baking of the shadow map in any game scene.

[0245] The following continues to describe an exemplary structure of a shadow map baking device 455 provided in an embodiment of the present application implemented as a software module. In some embodiments, Figure 5 As shown, the software modules stored in the shadow map baking device 455 of the memory 450 may include:

[0246] The information acquisition module 4551 is used to acquire at least one object information, light source information and a first resolution in the virtual scene; the first resolution is a specified texture resolution;

[0247] A resolution determination module 4552, configured to determine at least one second resolution according to the at least one object information, wherein the second resolution represents a texture resolution calculated according to the object information in the virtual scene;

[0248] A data calculation module 4553, configured to calculate at least one distance field shadow data corresponding to the at least one object information based on the light source information, the at least one object information, the first resolution and the at least one second resolution;

[0249] The map generation module 4554 is used to store the at least one distance field shadow data in the map of the first resolution, and obtain a distance field shadow map corresponding to each object information in the at least one object information.

[0250] In some embodiments of the present application, the data calculation module 4553 is further used to calculate the ratio of the at least one second resolution to the first resolution to obtain at least one supersampling parameter; the supersampling parameter characterizes the conversion relationship between the first resolution and the second resolution; using the light source information, the at least one object information and the at least one second resolution, determine at least one shadow edge corresponding to the at least one object information; based on the at least one supersampling parameter, calculate the distance from the pixel center of the first resolution to the at least one shadow edge to obtain the at least one distance field shadow data.

[0251] In some embodiments of the present application, the light source information includes multiple sub-light source information; the data calculation module 4553 is also used to screen out corresponding matching light source information from the multiple sub-light source information for each object information in the at least one object information; the matching light source information represents the information of the sub-light source that causes illumination or shadow effects on the object; the target second resolution corresponding to each object information is selected from the at least one second resolution, and each object information is rasterized at the target second resolution to obtain the rasterized pixels of each object information; according to the position of the texel corresponding to the rasterized pixel and the matching light source information, the shadow edge corresponding to each object information is extracted at the same time; the position of the texel is obtained by expanding the texture coordinates of each object information; when the shadow edge extraction of the at least one object information is completed, the at least one shadow edge corresponding to the at least one object information is obtained.

[0252] In some embodiments of the present application, the data calculation module 4553 is also used to perform shadow coverage judgment on the texels corresponding to the rasterized pixels of each object information at the same time based on the matching light source information and the position of the texels, to obtain shadow coverage information; the shadow coverage information represents whether the texel is in the shadow; and using the shadow coverage information, the shadow edges corresponding to each object information are extracted respectively.

[0253] In some embodiments of the present application, the data calculation module 4553 is further used to calculate the distance from the pixel center of the first resolution to each of the at least one shadow edge at the same time based on the at least one supersampling parameter, to obtain the distance field shadow data corresponding to each shadow edge; when the calculation of the distance field shadow data for the at least one shadow edge is completed, the at least one distance field shadow data is obtained.

[0254] In some embodiments of the present application, the data calculation module 4553 is further used to extract the target supersampling parameter corresponding to each shadow edge from the at least one supersampling parameter; at the same time, based on the target supersampling parameter corresponding to each shadow edge, calculate the minimum distance from the pixel center of the first resolution to each shadow edge; and use the minimum distance as the distance field shadow data corresponding to each shadow edge.

[0255] In some embodiments of the present application, the data calculation module 4553 is also used to divide the pixels of the first resolution into blocks according to the target oversampling coefficient to obtain at least one sub-pixel block; perform parallel calculation on the distance from the at least one sub-pixel block to the current shadow edge to obtain at least one shadow distance corresponding to the at least one sub-pixel block; the current shadow edge is any one of the at least one shadow edges; select the minimum shadow distance from the at least one shadow distance corresponding to the at least one sub-pixel block as the minimum distance from the pixel center of the first resolution to the current shadow edge; when the minimum distance is determined for each of the shadow edges, the minimum distance from the pixel center of the first resolution to each shadow edge is obtained.

[0256] In some embodiments of the present application, the data calculation module 4553 is also used to extract multiple matching pixels corresponding to each sub-pixel block in the at least one sub-pixel block from each pixel of the second resolution based on the pixels of the first resolution; filter out shadow pixels belonging to the current shadow edge from the multiple matching pixels; calculate the distance from each sub-pixel block to the shadow pixels respectively to obtain the shadow distance corresponding to each sub-pixel block; when the shadow distance calculation is completed for the at least one sub-pixel block, the at least one shadow distance is obtained.

[0257] In some embodiments of the present application, the data calculation module 4553 is also used to select adjacent pixels for pixels of the first resolution; extract a pixel set corresponding to the adjacent pixels from each pixel of the second resolution; extract pixels from the pixel set that are at the same position as the pixels of each sub-pixel block at the first resolution, and obtain multiple matching pixels corresponding to each sub-pixel block.

[0258] In some embodiments of the present application, the first resolution includes a plurality of first sub-resolutions; the shadow map baking device 455 further includes: an information classification module 4555;

[0259] The information classification module 4555 is used to classify the at least one object information by using the multiple first sub-resolutions and the at least one second resolution to obtain multiple object information sets;

[0260] The data calculation module 4553 is further used to calculate the distance field shadow data for the object information in each object information set at the same time based on the light source information, the object information in each object information set, the first sub-resolution corresponding to each object information set, and the second resolution corresponding to each object information in each object information set, so as to obtain a distance field shadow data set corresponding to each object information set; and use the distance field shadow data in the distance field shadow data set corresponding to each object information set to form the at least one distance field shadow data corresponding to the at least one object information.

[0261] In some embodiments of the present application, the data calculation module 4553 is also used to classify the at least one object information using the multiple first sub-resolutions to obtain multiple initial object information sets; compare the second resolutions corresponding to the individual object information in the current initial object information set with the first resolution corresponding to the current initial object information set to obtain the classification coefficient corresponding to the individual object information; the current initial object information set is any one of the multiple initial object information sets; based on the classification coefficients corresponding to the individual object information, classify the individual object information in the current initial object information set to obtain one or more current intermediate object information sets corresponding to the current initial object information set; when the determination of one or more intermediate object information sets is completed for each initial object information set, the multiple object information sets are obtained.

[0262] The embodiment of the present application provides a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the above-mentioned shadow map baking method of the embodiment of the present application.

[0263] The present application embodiment provides a computer-readable storage medium storing executable instructions, wherein executable shadow map baking instructions are stored. When the executable shadow map baking instructions are executed by a processor, the processor will be caused to execute the shadow map baking method provided by the present application embodiment, for example, Figure 6 The method shown.

[0264] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface storage, optical disk, or CD-ROM; or it may be various devices including one or any combination of the above memories.

[0265] In some embodiments, the baking instructions for executable shadow maps may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a standalone program or as a module, component, subroutine or other unit suitable for use in a computing environment.

[0266] As an example, the baking instructions for an executable shadow map may, but do not necessarily, correspond to a file in a file system, and may be stored as part of a file that stores other programs or data, such as in one or more scripts in a Hyper Text Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions).

[0267] As an example, executable shadow map baking instructions may be deployed to execute on one computing device, or on multiple computing devices located at one site, or on multiple computing devices distributed at multiple sites and interconnected by a communication network.

[0268] The above is only an embodiment of the present application and is not intended to limit the protection scope of the present application. Any modifications, equivalent substitutions and improvements made within the spirit and scope of the present application are included in the protection scope of the present application.

Claims

1. A method for baking a shadow map, characterized in that: include: Acquire at least one object information, light source information and a first resolution in a virtual scene; The first resolution is a specified texture resolution; Determining at least one second resolution based on the at least one object information, the second resolution representing a texture resolution calculated based on the object information in the virtual scene; Calculate at least one distance field shadow data corresponding to the at least one object information based on the light source information, the at least one object information, the first resolution and the at least one second resolution; Storing the at least one distance field shadow data in a map of the first resolution, and obtaining a distance field shadow map corresponding to each object information in the at least one object information; The first resolution includes a plurality of first sub-resolutions; and the calculating, based on the light source information, the at least one object information, the first resolution and the at least one second resolution, at least one distance field shadow data corresponding to the at least one object information comprises: Using the multiple first sub-resolutions and the at least one second resolution, classify the at least one object information to obtain multiple object information sets; Based on the light source information, the object information in each object information set, the first sub-resolution corresponding to each object information set, and the second resolution corresponding to each object information in each object information set, calculating the distance field shadow data for the object information in each object information set at the same time to obtain a distance field shadow data set corresponding to each object information set; The at least one distance field shadow data corresponding to the at least one object information is composed by using the distance field shadow data in the distance field shadow data set corresponding to each object information set.

2. The method according to claim 1, characterized in that The calculating, based on the light source information, the at least one object information, the first resolution and the at least one second resolution, at least one distance field shadow data corresponding to the at least one object information further includes: Calculating the ratio of the at least one second resolution to the first resolution to obtain at least one supersampling parameter; the supersampling parameter represents the conversion relationship between the first resolution and the second resolution; Determine at least one shadow edge corresponding to the at least one object information by using the light source information, the at least one object information and the at least one second resolution; Based on the at least one supersampling parameter, a distance from a pixel center of the first resolution to the at least one shadow edge is calculated to obtain the at least one distance field shadow data.

3. The method according to claim 2, characterized in that The light source information includes a plurality of sub-light source information; and using the light source information, the at least one object information and the at least one second resolution to determine at least one shadow edge corresponding to the at least one object information includes: For each object information in the at least one object information, corresponding matching light source information is screened out from the plurality of sub-light source information; the matching light source information represents information of the sub-light source causing illumination or shadow effects on the object; Selecting a target second resolution corresponding to each piece of object information from the at least one second resolution, and rasterizing each piece of object information at the target second resolution to obtain rasterized pixels of each piece of object information; According to the position of the texel corresponding to the rasterized pixel and the matching light source information, the shadow edge corresponding to each object information is extracted at the same time; the position of the texel is obtained by expanding the texture coordinates of each object information; When the shadow edge extraction is completed for the at least one object information, the at least one shadow edge corresponding to the at least one object information is obtained.

4. The method according to claim 3, characterized in that The extracting the shadow edge corresponding to each object information at the same time according to the position of the texel corresponding to the rasterized pixel and the matching light source information includes: According to the matching light source information and the position of the texel, at the same time, a shadow coverage judgment is performed on the texel corresponding to the rasterized pixel of each object information to obtain shadow coverage information; the shadow coverage information indicates whether the texel is in the shadow; The shadow coverage information is used to extract the shadow edges corresponding to each object information.

5. The method according to any one of claims 2 to 4, characterized in that: The calculating, based on the at least one supersampling coefficient, a distance from a pixel center of the first resolution to the at least one shadow edge to obtain the at least one distance field shadow data comprises: Based on the at least one supersampling parameter, calculating at the same time a distance from a pixel center of the first resolution to each of the at least one shadow edge to obtain distance field shadow data corresponding to each shadow edge; When the calculation of the distance field shadow data is completed for the at least one shadow edge, the at least one distance field shadow data is obtained.

6. The method according to claim 5, characterized in that The calculating, based on the at least one supersampling parameter, at the same time, the distance from the pixel center of the first resolution to each of the at least one shadow edge to obtain distance field shadow data corresponding to each shadow edge includes: Extracting a target supersampling parameter corresponding to each shadow edge from the at least one supersampling parameter; At the same time, based on the target supersampling parameter corresponding to each shadow edge, calculating the minimum distance from the center of the pixel of the first resolution to each shadow edge; The minimum distance is used as the distance field shadow data corresponding to each shadow edge.

7. The method according to claim 6, characterized in that The calculating, based on the target supersampling coefficient corresponding to each shadow edge, the minimum distance from the pixel center of the first resolution to each shadow edge comprises: Dividing the pixels of the first resolution into blocks according to the target supersampling coefficient to obtain at least one sub-pixel block; Performing parallel calculation on the distance from the at least one sub-pixel block to the current shadow edge to obtain at least one shadow distance corresponding to the at least one sub-pixel block; the current shadow edge is any one of the at least one shadow edge; Selecting a minimum shadow distance from the at least one shadow distance corresponding to the at least one sub-pixel block as the minimum distance from the pixel center of the first resolution to the current shadow edge; When the minimum distance is determined for each shadow edge, the minimum distance from the center of the pixel of the first resolution to each shadow edge is obtained.

8. The method according to claim 7, characterized in that The performing parallel calculation on the distance from the at least one sub-pixel block to the current shadow edge to obtain at least one shadow distance corresponding to the at least one sub-pixel block includes: Extracting, from each pixel of the second resolution according to the pixel of the first resolution, a plurality of matching pixels corresponding to each sub-pixel block in the at least one sub-pixel block; Filtering out shadow pixels belonging to the current shadow edge from the multiple matching pixels; Calculating the distance from each sub-pixel block to the shadow pixel respectively to obtain the shadow distance corresponding to each sub-pixel block; When the calculation of the shadow distance for the at least one sub-pixel block is completed, the at least one shadow distance is obtained.

9. The method according to claim 8, characterized in that The step of extracting, from each pixel of the second resolution according to the pixel of the first resolution, a plurality of matching pixels corresponding to each sub-pixel block in the at least one sub-pixel block comprises: For the pixels of the first resolution, selecting adjacent pixels; Extracting, from each pixel of the second resolution, a pixel set corresponding to the adjacent pixels; Pixels in the pixel set that are located at the same position as the pixels of each sub-pixel block at the first resolution are extracted to obtain a plurality of matching pixels corresponding to each sub-pixel block.

10. The method according to claim 1, characterized in that The method of classifying the at least one object information by using the multiple first sub-resolutions and the at least one second resolution to obtain multiple object information sets includes: Using the multiple first sub-resolutions, classify the at least one object information to obtain multiple initial object information sets; Comparing each second resolution corresponding to each object information in the current initial object information set with the first resolution corresponding to the current initial object information set, to obtain a classification coefficient corresponding to each object information; the current initial object information set is any one of the multiple initial object information sets; Classifying each object information in the current initial object information set according to the classification coefficient corresponding to each object information to obtain one or more current intermediate object information sets corresponding to the current initial object information set; When one or more intermediate object information sets are determined for each initial object information set, the multiple object information sets are obtained.

11. A shadow map baking device, characterized in that: include: An information acquisition module, used to acquire at least one object information, light source information and a first resolution in a virtual scene; The first resolution is a specified texture resolution; A resolution determination module, configured to determine at least one second resolution according to the at least one object information, wherein the second resolution represents a texture resolution calculated according to the object information in the virtual scene; A data calculation module, configured to calculate at least one distance field shadow data corresponding to the at least one object information based on the light source information, the at least one object information, the first resolution and the at least one second resolution; wherein the first resolution includes a plurality of first sub-resolutions; the calculating at least one distance field shadow data corresponding to the at least one object information based on the light source information, the at least one object information, the first resolution and the at least one second resolution comprises: classifying the at least one object information by using the plurality of first sub-resolutions and the at least one second resolution to obtain a plurality of object information sets; calculating the distance field shadow data for the object information in each object information set at the same time based on the light source information, the object information in each object information set, the first sub-resolution corresponding to each object information set and the second resolution corresponding to each object information in each object information set to obtain a distance field shadow data set corresponding to each object information set; and forming the at least one distance field shadow data corresponding to the at least one object information by using the distance field shadow data in the distance field shadow data set corresponding to each object information set; The map generation module is used to store the at least one distance field shadow data in the map of the first resolution to obtain a distance field shadow map corresponding to each object information in the at least one object information.

12. A shadow map baking device, characterized in that: include: A memory for storing baking instructions for executable shadow maps; A processor, configured to implement the method of any one of claims 1 to 10 when executing baking instructions for executable shadow maps stored in the memory.

13. A computer-readable storage medium, characterized in that: The method stores baking instructions for executable shadow maps, which are used to implement the method described in any one of claims 1 to 10 when executed by a processor.

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