A method and apparatus for dynamic generation of large-scale static shadows
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-08
- Publication Date
- 2026-08-14
AI Technical Summary
常见的技术方案包括:基于美术制作的阴影面片、基于光照图的静态阴影、基于ShadowMap的阴影方案、基于距离场的阴影实现,基于阴影体的阴影渲染等,这些方案都各有应用场景的限制,并不适用于所有的应用场景
[0016]在本申请中,以虚拟纹理Virtual Texture为核心,生成了全局阴影贴图的虚拟纹理,在虚拟纹理中分配空间进行阴影的渲染处理。其中,在进行新的地面阴影渲染时,将虚拟纹理整体赋予更新后的Mesh的材质进行单Drawcall渲染,使得一次渲染即可覆盖整个地面阴影,通过该方式,渲染场景中的每个静态物体的阴影仅当注册时渲染一次,无需每帧进行重复渲染且采样时无额外计算。同时,本申请实施例还通过虚拟纹理的方式支持自阴影,即实时生成光照图到虚拟纹理提供给需要的物体。在本申请中,上述所有处理均在运行时实现,可以根据具体的需求实现软阴影、自阴影等效果的灵活开关控制,不受硬件资源的限制,扩展性较高。
Smart Images

Figure CN115147534B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer image processing technology, and in particular to a method, apparatus, computing device, and computer-readable storage medium for dynamically generating large-scale static shadows. Background Technology
[0002] In mobile games, the implementation of shadows is crucial. Due to the hardware limitations of mobile platforms, balancing power consumption and rendering quality is often a key consideration in technical solutions. Common solutions include: shadow patches based on art creation, static shadows based on lightmaps, shadow maps, distance field-based shadows, and shadow volume-based shadow rendering. Each of these solutions has its own limitations and is not suitable for all scenarios. Therefore, in specific situations, more efficient shadow rendering methods are needed. Summary of the Invention
[0003] The purpose of this invention is to provide a method, apparatus, computing device, and readable storage medium for dynamically generating large-scale static shadows.
[0004] To address the above problems, a first aspect of the present invention provides a method for dynamically generating large-scale static shadows, comprising:
[0005] During runtime:
[0006] Initialize virtual textures for the shadows of static objects;
[0007] When a static object is added to the rendering scene, the shadow of the static object is rendered onto the corresponding virtual texture;
[0008] When a static object leaves the rendering scene, the rendered textures in the virtual texture are released.
[0009] According to another aspect of the present invention, a dynamic generation apparatus for large-scale static shadows is provided, comprising:
[0010] The initialization module is used to initialize virtual textures for the shadows of static objects;
[0011] The rendering module is used to render the shadows of static objects onto the corresponding virtual textures when static objects are added to the rendering scene.
[0012] The management module is used to release the rendered textures in the virtual texture when a static object leaves the rendering scene.
[0013] According to another aspect of the present invention, a computing device is provided, including a memory, a processor, and computer instructions stored in the memory and executable on the processor, characterized in that the processor executes the instructions to implement the steps of any of the methods described above.
[0014] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the instructions, when executed by a processor, implement the steps of any of the methods described above.
[0015] The above-described technical solution of the present invention has the following beneficial technical effects:
[0016] In this application, a virtual texture is used as the core to generate a global shadow map. Space is allocated within the virtual texture for shadow rendering. Specifically, when rendering a new ground shadow, the entire virtual texture is assigned to the updated Mesh material for single-drawcall rendering, allowing a single rendering to cover the entire ground shadow. In this way, the shadow of each static object in the scene is rendered only once upon registration, eliminating the need for repeated rendering every frame and requiring no additional calculations during sampling. Furthermore, this application also supports self-shadowing via virtual textures, i.e., real-time generation of lightmaps to the virtual texture for use by the required objects. In this application, all the above processing is implemented at runtime, allowing for flexible on / off control of soft shadows, self-shadows, and other effects according to specific needs, without being limited by hardware resources and exhibiting high scalability. Attached Figure Description
[0017] Figure 1 This is a schematic diagram of the user interface for 2.5D games in the existing technology;
[0018] Figure 2 This is a structural block diagram of the computing device provided in the embodiments of this application;
[0019] Figure 3 This is a flowchart of a method for dynamically generating large-scale static shadows provided in an embodiment of this application;
[0020] Figure 4a This is a schematic diagram illustrating the rendering of the shadow of a static object onto a virtual texture, provided in an embodiment of this application.
[0021] Figure 4b This is a schematic diagram illustrating the rendering of the ground shadow of a static object onto a virtual texture, as provided in an embodiment of this application.
[0022] Figure 5 This is a schematic diagram of single drawcall rendering based on a ground shadow mesh provided in an embodiment of this application;
[0023] Figure 6This is a schematic diagram of the structure of a dynamic generation device for large-scale static shadows provided in an embodiment of this application. Detailed Implementation
[0024] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to specific embodiments and the accompanying drawings. It should be understood that these descriptions are merely exemplary and not intended to limit the scope of the invention. Furthermore, descriptions of well-known structures and techniques are omitted in the following description to avoid unnecessarily obscuring the concept of the invention.
[0025] Many specific details are set forth in the following description to provide a full understanding of this application. However, this application can be implemented in many other ways different from those described herein, and those skilled in the art can make similar extensions without departing from the spirit of this application; therefore, this application is not limited to the specific embodiments disclosed below.
[0026] The terminology used in one or more embodiments of this application is for the purpose of describing particular embodiments only and is not intended to limit the scope of one or more embodiments of this application. The singular forms “a,” “the,” and “the” used in one or more embodiments of this application and in the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” used in one or more embodiments of this application refers to and includes any or all possible combinations of one or more associated listed items.
[0027] It should be understood that although the terms first, second, etc., may be used to describe various information in one or more embodiments of this application, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, first may also be referred to as second without departing from the scope of one or more embodiments of this application, and similarly, second may also be referred to as first. Depending on the context, the word "if" as used herein may be interpreted as "in response to a determination".
[0028] In the gaming industry, 2.5D games typically refer to video games that confine game content to a two-dimensional planar scene using a 3D engine. These games have a fixed game perspective that cannot be freely switched, such as... Figure 1 As shown.
[0029] In 2.5D game scenes, there are numerous static objects. Static objects here refer to objects without animation, such as buildings. Unlike the general concept of static objects, these static objects can be dynamically added to or removed from the game scene. That is, static objects requiring shadows may be added or removed at any time. Therefore, the shadows of these static objects need to be dynamically managed. Shadows should increase as static objects are added and decrease as they are removed; when the static objects remain unchanged, the shadows should remain unchanged. Furthermore, in such games, a large number of static objects requiring shadows may appear on the screen simultaneously, requiring high performance and efficiency for rendering, and avoiding excessive reliance on hardware configuration. Moreover, to achieve different levels of effect under different hardware environments, the shadow rendering solution should be scalable, providing better rendering effects on high-performance hardware environments, such as supporting self-shadows and soft shadows.
[0030] To achieve the above objectives, embodiments of this application provide a method and apparatus for dynamically generating large-scale static shadows, a computing device, and a computer-readable storage medium, which will be described in detail in the following embodiments.
[0031] Figure 2 A structural block diagram of a computing device 100 according to an embodiment of this application is shown. The components of the computing device 100 include, but are not limited to, a memory 110 and a processor 120. The processor 120 is connected to the memory 110 via a bus 130, and a database 150 is used to store data.
[0032] The computing device 100 also includes an access device 140, which enables the computing device 100 to communicate via one or more networks 160. Examples of these networks include a Public Switched Telephone Network (PSTN), a Local Area Network (LAN), a Wide Area Network (WAN), a Personal Area Network (PAN), or a combination of communication networks such as the Internet. The access device 140 may include one or more of any type of wired or wireless network interface (e.g., a Network Interface Card (NIC)), such as an IEEE 802.11 Wireless Local Area Network (WLAN) interface, a Wi-MAX interface, an Ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a Bluetooth interface, a Near Field Communication (NFC) interface, and so on.
[0033] In one embodiment of this application, the aforementioned components of the computing device 100 and Figure 2 Other components, not shown, can also be connected to each other, for example, via a bus. It should be understood that... Figure 2 The block diagram of the computing device shown is for illustrative purposes only and is not intended to limit the scope of this application. Those skilled in the art can add or replace other components as needed.
[0034] The computing device 100 can be any type of stationary or mobile computing device, including mobile computers or mobile computing devices (e.g., tablet computers, personal digital assistants, laptop computers, notebook computers, netbooks, etc.), mobile phones (e.g., smartphones), wearable computing devices (e.g., smartwatches, smart glasses, etc.) or other types of mobile devices, or stationary computing devices such as desktop computers or PCs. The computing device 100 can also be a mobile or stationary server.
[0035] Among them, processor 120 can execute Figure 3 The steps in a method for dynamically generating large-scale static shadows are shown. Figure 3 A flowchart of a method for dynamically generating large-scale static shadows according to an embodiment of this application is shown, including steps 302 to 308.
[0036] S302: Initialize a virtual texture for the shadow of a static object.
[0037] In one alternative implementation, a virtual texture (VT) is initialized for the shadow when shadow rendering begins at runtime.
[0038] Furthermore, two virtual textures are initialized for the ground shadow and self-shadow of the static object, respectively. The first virtual texture is VT1, corresponding to the ground shadow of the static object, and the second virtual texture is VT2, corresponding to the self-shadow of the static object. The resolution of the virtual textures is RGB8.
[0039] Furthermore, a dynamic ground shadow mesh is reserved.
[0040] In another alternative implementation, a prefab is configured for the static object before initializing the virtual texture for the shadow of the static object. Specifically, in the development engine, a prefab is generated for each type of static object that needs to cast shadows, such as buildings and trees, and shadow-related parameters, such as shadow size, distance offset, and whether self-shadow is needed, are configured on the prefab.
[0041] S304: When a static object is added to the rendering scene, the shadow of the static object is rendered into the corresponding virtual texture;
[0042] In one alternative implementation, when a new static object is added to the current game scene, the shadow of the static object is rendered onto the render target texture and then copied to a specified location of the virtual texture VT.
[0043] The size of the rendering target texture (Render Texture) is the same as the size of the virtual texture (Tile).
[0044] Furthermore, after rendering the shadow to the target texture, post-rendering can be used to enhance the rendering effect according to the configuration parameters, such as adding soft shadow effects through blurring.
[0045] In one alternative implementation, when a new static object is added to the current game scene, the ground shadow of that static object is rendered into the first virtual texture VT1.
[0046] Specifically, during ground shadow rendering, the ground shadow is rendered onto the render target texture (Render Texture), and then copied to a specified location on the first virtual texture (VT1), such as... Figures 4a-4b As shown. The specified location is an empty position within the first virtual texture VT1.
[0047] Furthermore, ground shadows are generated using depthless orthographic projection or other projection methods.
[0048] Furthermore, the entire ground shadow mesh is updated based on the configured projection parameters and the rendering result of the first virtual texture VT1;
[0049] Then, after assigning the first virtual texture VT1 to the updated ground shadow mesh material, a single drawcall rendering of the ground shadow is performed, such as... Figure 5 As shown.
[0050] In another alternative implementation, when a new static object is added to the current game scene, its self-shadow is rendered into the second virtual texture VT2. Specifically, during self-shadow rendering, the self-shadow is rendered onto the render texture according to the lightmap UV settings of the prefab in texture space, and then copied to a specified location in the second virtual texture VT2, such as... Figure 4a As shown, the specified position is an empty position in the second virtual texture VT2.
[0051] Furthermore, the rendering offset parameters of the self-shadow in the second virtual texture VT2 are fed back to the object material of the new static object, so that the rendering result in the second virtual texture VT2 is used as a dynamic lightmap to complete the self-shadow rendering of the static object.
[0052] S306: When a static object leaves the rendering scene, the rendered texture in the virtual texture is released.
[0053] In one alternative implementation, when an existing static object leaves the current game scene due to user actions, the rendering result of the static object in the virtual texture is released.
[0054] Specifically, when requesting the release of rendering results in a virtual texture, the tiles that need to be released in the virtual texture are marked and then released uniformly, thereby reducing the number of times the virtual texture is updated.
[0055] In another alternative implementation, when the original static object leaves the current game scene due to the user's operation, the ground shadow rendering result of the static object in the first virtual texture VT1 is released.
[0056] Specifically, based on the release result of the first virtual texture VT1, the shadow patches of the removed static objects are deleted from the ground shadow mesh, and the ground shadow mesh is dynamically updated.
[0057] In another alternative implementation, when the original static object leaves the current game scene due to the user's operation, the self-shadow rendering result of the static object in the second virtual texture VT2 is released, and the lightmap settings on the static object are removed.
[0058] In another embodiment of this application, when the static objects in the game scene do not change, the ground shadow is rendered in each frame of the game using the currently generated ground shadow mesh and the current first virtual texture VT1; for static objects with self-shadows, the second virtual texture VT2 is used as a dynamic lightmap for shadow overlay during self-shadow rendering.
[0059] In the above embodiments of this application, a virtual texture is used as the core to generate a virtual texture with a global shadow map. Space is allocated in the virtual texture for shadow rendering. Specifically, when rendering a new ground shadow, the real-time generated ground shadow is copied to the first virtual texture, and the ground shadow mesh is dynamically updated. Then, the first virtual texture is assigned the material of the updated mesh for single-drawcall rendering, allowing a single rendering to cover the entire ground shadow. In this way, the shadow of each static object in the rendering scene is rendered only once upon registration, eliminating the need for repeated rendering every frame and requiring no additional calculations during sampling. Because shadows are allocated using a virtual texture, the utilization rate of the entire rendering texture is also high, resulting in a better display effect than existing shadow rendering methods and avoiding common problems such as jitter. Furthermore, this application also supports self-shadowing through virtual textures, i.e., real-time generation of lightmaps to the virtual texture for use by the required objects. In this application, all the above processing is implemented at runtime, allowing for flexible on / off control of soft shadows, self-shadows, and other effects according to specific needs, without being limited by hardware resources and exhibiting high scalability.
[0060] Corresponding to the above method embodiments, this application also provides an embodiment of a dynamic generation apparatus for large-scale static shadows, such as... Figure 6 As shown, the device includes:
[0061] The initialization module is used to initialize virtual textures for the shadows of static objects;
[0062] The rendering module is used to render the shadows of static objects onto the corresponding virtual textures when static objects are added to the rendering scene.
[0063] The management module is used to release the rendered textures in the virtual texture when a static object leaves the rendering scene.
[0064] The above is a schematic scheme of a dynamic generation device for large-scale static shadows according to this embodiment. It should be noted that the technical solution of this dynamic generation device for large-scale static shadows belongs to the same concept as the technical solution of the dynamic generation method for large-scale static shadows described above. For details not described in detail in the technical solution of this dynamic generation device for large-scale static shadows, please refer to the description of the technical solution of the dynamic generation method for large-scale static shadows described above.
[0065] In one embodiment of this application, a computing device is also provided, including a memory, a processor, and computer instructions stored in the memory and executable on the processor, wherein the processor executes the instructions to implement the steps of the dynamic generation method for large-scale static shadows.
[0066] The above is an illustrative scheme of a computing device according to this embodiment. It should be noted that the technical solution of this computing device and the technical solution of the above-described dynamic generation method for large-scale static shadows belong to the same concept. For details not described in detail in the technical solution of the computing device, please refer to the description of the technical solution of the above-described dynamic generation method for large-scale static shadows.
[0067] An embodiment of this application also provides a computer-readable storage medium storing computer instructions that, when executed by a processor, implement the steps of the dynamic generation method for large-scale static shadows as described above.
[0068] The above is an illustrative scheme of a computer-readable storage medium according to this embodiment. It should be noted that the technical solution of this storage medium belongs to the same concept as the technical solution of the above-described dynamic generation method for large-scale static shadows. For details not described in detail in the technical solution of the storage medium, please refer to the description of the technical solution of the above-described dynamic generation method for large-scale static shadows.
[0069] It should be understood that the specific embodiments described above are merely illustrative or explanatory of the principles of the invention and do not constitute a limitation thereof. Therefore, any modifications, equivalent substitutions, improvements, etc., made without departing from the spirit and scope of the invention should be included within the protection scope of the invention. Furthermore, the appended claims are intended to cover all variations and modifications falling within the scope and boundaries of the appended claims, or equivalent forms of such scope and boundaries.
[0070] The above is an illustrative scheme of a computer-readable storage medium according to this embodiment. It should be noted that the technical solution of this storage medium belongs to the same concept as the technical solution of the method for ensuring the security of enterprise login credentials described above. Details not described in detail in the technical solution of the storage medium can be found in the description of the technical solution of the method for ensuring the security of enterprise login credentials described above.
[0071] The foregoing has described specific embodiments of this application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired results. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0072] Computer instructions include computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. Computer-readable media can include: any entity or device capable of carrying computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in computer-readable media can be appropriately added to or removed according to the requirements of legislation and patent practice in a jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.
[0073] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0074] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0075] The preferred embodiments disclosed above are merely illustrative of this application. The optional embodiments do not exhaustively describe all details, nor do they limit the invention to specific implementations. Clearly, many modifications and variations can be made based on the content of this application. These embodiments are selected and specifically described in this application to better explain the principles and practical applications of this application, thereby enabling those skilled in the art to better understand and utilize this application. This application is limited only by the claims and their full scope and equivalents.
Claims
1. A method for dynamically generating large-scale static shadows, characterized in that, include: Initializing a virtual texture for the shadow of a static object includes: initializing a first virtual texture for the ground shadow of the static object; initializing a second virtual texture for the self-shadow of the static object; reserving a dynamic ground shadow mesh; and before initializing the virtual texture for the shadow of the static object, it also includes: configuring a prefab for the static object in the configuration phase, and configuring shadow-related parameters on the prefab. When a static object is added to the rendering scene, its shadow is rendered onto the corresponding virtual texture, including: When a new static object is added to the current rendering scene, the ground shadow of the new static object is rendered, the ground shadow is rendered onto the rendering target texture, and then copied to the specified position of the first virtual texture; the ground shadow mesh is updated according to the projection parameters and the rendering result of the first virtual texture, and then the material of the updated ground shadow mesh is assigned to the first virtual texture as a whole to render the ground shadow. In texture space, the self-shadow is rendered onto the rendering texture according to the lightmap texture coordinates of the prefab, and copied to the specified position of the second virtual texture; the rendering offset parameter of the self-shadow in the second virtual texture is fed back to the object material of the new static object, so that the rendering result of the second virtual texture is used as a dynamic lightmap to complete the self-shadow rendering of the new static object. When static objects in the rendering scene do not change, ground shadows are rendered in each frame using the currently generated ground shadow mesh and the first virtual texture; for static objects with self-shadows, the second virtual texture is used as a dynamic lightmap for shadow overlay when rendering self-shadows. When a static object leaves the rendering scene, the rendered textures in the virtual texture are released.
2. The method according to claim 1, wherein, The size of the rendering target texture is the same as the size of the virtual texture tile.
3. The method according to claim 2, wherein, After rendering the shadows onto the target texture, post-processing is used to enhance the rendering effect according to the configuration.
4. The method according to claim 1, wherein releasing the rendered texture in the virtual texture when the static object leaves the rendering scene includes: When releasing the rendering results in the virtual texture, the tiles that need to be released in the virtual texture are marked and then released uniformly.
5. A dynamic generation device for large-scale static shadows, characterized in that, include: An initialization module is used to configure a prefab for a static object during the configuration phase, and to configure shadow-related parameters on the prefab; And initialize virtual textures for the shadows of static objects, including: initializing a first virtual texture for the ground shadow of static objects; initializing a second virtual texture for the self-shadow of static objects; reserving dynamic ground shadow meshes; The rendering module is used to render the shadows of static objects onto corresponding virtual textures when a static object is added to the rendering scene. This includes: when a new static object is added to the current rendering scene, rendering the ground shadow of the new static object onto a rendering target texture, and then copying it to a specified position on a first virtual texture; updating the ground shadow mesh according to projection parameters and the rendering result of the first virtual texture; then assigning the entire first virtual texture to the material of the updated ground shadow mesh for ground shadow rendering; rendering self-shadows onto a rendering texture according to the lightmap texture coordinates of a prefab in texture space, and copying it to a specified position on a second virtual texture; and feeding back the rendering offset parameters of the self-shadows in the second virtual texture to the object material of the new static object, thereby using the rendering result of the second virtual texture as a dynamic lightmap to complete the self-shadow rendering of the new static object. The frame rendering module is used to render ground shadows in each frame using the currently generated ground shadow mesh and the first virtual texture when the static objects in the rendering scene do not change; for static objects with self-shadows, the second virtual texture is used as a dynamic lightmap for shadow overlay when rendering the self-shadow. The management module is used to release the rendered textures in the virtual texture when a static object leaves the rendering scene.
6. A computing device, comprising a memory, a processor, and computer instructions stored in the memory and executable on the processor, characterized in that, When the processor executes the instructions, it implements the steps of the method according to any one of claims 1-4.
7. A computer-readable storage medium storing computer instructions, characterized in that, When executed by the processor, this instruction implements the steps of the method according to any one of claims 1-4.