Lighting baking method and apparatus for virtual scene, computer device and storage medium
By performing scene division of virtual scenes and traversing the target nodes, determining the set of baked elements for lighting baking, the problem of excessive data and calculation amount in lighting baking of large virtual scenes is solved, and stability and efficiency are improved.
Patent Information
- Application Number
- PCT/CN2024/110157
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-12-25
- Filing Date
- 2024-08-06
- Publication Date
- 2025-07-03
AI Technical Summary
When the prior art light baking of larger virtual scenes, the data amount and calculation amount are too large, resulting in poor lighting baking stability and limited by hardware resources.
By segmenting the virtual scene, a scene tree structure is generated, and the target nodes are traversed according to the structural hierarchy relationship. When the number of elements of the target node and the number of elements of the descendants meet the conditions, the baking element set is determined and illuminated baking is performed to reduce the number of scene elements participating in illuminated baking, and reduce the memory usage.
It improves the stability and efficiency of lighting baking, can be applied to computer equipment with different hardware resources, and reduces the memory usage rate.
Smart Images

Figure CN2024110157_03072025_PF_FP_ABST
Abstract
Description
Lighting baking method, device, computer equipment and storage medium for virtual scenes
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on December 25, 2023, with application number 2023118117413, and invention name “Lighting baking method, device, computer equipment and storage medium for virtual scenes”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of computer technology, and in particular to a method, apparatus, computer device, storage medium, and computer program product for baking lighting for a virtual scene. Background Art
[0003] With the development of computer technology, users have higher and higher requirements for the game's visual display effects.
[0004] During game development, because real lighting rendering takes a long time, the lighting information of direct and indirect light sources in the scene is usually calculated and saved offline. This process is called light baking. In related technologies, light baking for the game's virtual scene mostly involves light baking for the entire virtual scene. However, related technologies can only be used for light baking of smaller virtual scenes. When the virtual scene is large, the amount of data and calculation involved in light baking is large, which is limited by hardware resources, resulting in poor light baking stability.
[0005] Summary of the Invention
[0006] According to various embodiments provided in the present application, a method, apparatus, computer device, computer-readable storage medium, and computer program product for baking lighting for a virtual scene are provided.
[0007] In a first aspect, the present application provides a lighting baking method for a virtual scene, performed by a computer device, the method comprising:
[0008] Obtain scene elements of the virtual scene; divide the virtual scene according to the scene elements to obtain a scene tree structure; traverse to the target node in the spatial nodes of the scene tree structure according to the structural hierarchy; when it is determined that the target node meets the baking conditions based on the number of elements of the target node and the number of elements of the descendant nodes of the target node, determine the baking element set based on the scene elements of the target node, the scene elements of the ancestor node of the target node and the scene elements of the descendant nodes; and perform lighting baking on the baking element set to obtain lighting information of the baking element set.
[0009] In a second aspect, the present application also provides a lighting baking device for a virtual scene. The device comprises:
[0010] A scene element acquisition module is used to acquire scene elements of a virtual scene;
[0011] A scene division module is used to divide the virtual scene according to scene elements to obtain a scene tree structure;
[0012] The node traversal module is used to traverse the spatial nodes of the scene tree structure to the target node according to the structural hierarchy relationship;
[0013] a baking element set acquisition module, used for the baking element set determination module, configured to determine the baking element set based on the scene elements of the target node, the scene elements of the ancestor node of the target node, and the scene elements of the descendant nodes when it is determined that the target node meets the baking conditions based on the number of elements of the target node and the number of elements of the descendant nodes of the target node; and
[0014] The lighting baking module is used to perform lighting baking on the baking element set to obtain the lighting information of the baking element set.
[0015] In a third aspect, the present application further provides a computer device comprising a memory and one or more processors, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processors, the one or more processors perform the following steps:
[0016] Obtain scene elements of the virtual scene; divide the virtual scene according to the scene elements to obtain a scene tree structure; traverse to the target node in the spatial nodes of the scene tree structure according to the structural hierarchy; when it is determined that the target node meets the baking conditions based on the number of elements of the target node and the number of elements of the descendant nodes of the target node, determine the baking element set based on the scene elements of the target node, the scene elements of the ancestor node of the target node and the scene elements of the descendant nodes; and perform lighting baking on the baked element set to obtain lighting information of the baked element set.
[0017] In a fourth aspect, the present application further provides one or more non-volatile readable storage media having computer-readable instructions stored thereon, wherein when the computer-readable instructions are executed by the processor, the following steps are implemented:
[0018] Obtain scene elements of the virtual scene; divide the virtual scene according to the scene elements to obtain a scene tree structure; traverse to the target node in the spatial nodes of the scene tree structure according to the structural hierarchy; when it is determined that the target node meets the baking conditions based on the number of elements of the target node and the number of elements of the descendant nodes of the target node, determine the baking element set based on the scene elements of the target node, the scene elements of the ancestor node of the target node and the scene elements of the descendant nodes; and perform lighting baking on the baking element set to obtain lighting information of the baking element set.
[0019] In a fifth aspect, the present application further provides a computer program product. The computer program product includes computer-readable instructions, which, when executed by a processor, implement the following steps:
[0020] Obtain scene elements of the virtual scene; divide the virtual scene according to the scene elements to obtain a scene tree structure; traverse to the target node in the spatial nodes of the scene tree structure according to the structural hierarchy; when it is determined that the target node meets the baking conditions based on the number of elements of the target node and the number of elements of the descendant nodes of the target node, determine the baking element set based on the scene elements of the target node, the scene elements of the ancestor node of the target node and the scene elements of the descendant nodes; and perform lighting baking on the baking element set to obtain lighting information of the baking element set.
[0021] The details of one or more embodiments of the present application are set forth in the following drawings and description. Other features, objects, and advantages of the present application will become apparent from the description, drawings, and claims. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] To more clearly illustrate the technical solutions of the embodiments of this application, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are merely exemplary embodiments of this application, and those skilled in the art can derive other drawings based on these drawings without inventive effort.
[0023] FIG1 is a diagram illustrating an application environment of a lighting baking method for a virtual scene according to an embodiment;
[0024] FIG2 a is a schematic diagram of a lighting baking method for a virtual scene in one embodiment;
[0025] FIG2 b is a schematic diagram of a flow chart of a lighting baking method for a virtual scene in one embodiment;
[0026] FIG3 is a schematic diagram of scene elements of a virtual scene in one embodiment;
[0027] FIG4 is a schematic diagram of a scene structure tree in one embodiment;
[0028] FIG5 is a schematic diagram of a process for determining a baking element set in one embodiment;
[0029] FIG6 is a schematic diagram of obtaining a baked element set based on location information of scene elements of an ancestor node in one embodiment;
[0030] FIG7 is a schematic diagram of obtaining a baked element set based on position information of scene elements of an ancestor node in another embodiment;
[0031] FIG8 is a schematic diagram of a process for obtaining a scene tree structure in one embodiment;
[0032] FIG9 is a schematic diagram of a configuration interface for light baking in one embodiment;
[0033] FIG10 is a schematic diagram of updating an initial scene tree structure in one embodiment;
[0034] FIG11 is a schematic diagram showing how lighting information is stored according to preset sub-scenes in one embodiment;
[0035] FIG12 is a schematic diagram of a scene for performing lighting baking on a virtual scene of an open world game in one embodiment;
[0036] FIG13 is a schematic diagram comparing the effects of performing light baking on the entire virtual scene and performing light baking using the method provided in an embodiment of the present application;
[0037] FIG14 is a schematic flow chart of a lighting baking method for a virtual scene in another embodiment;
[0038] FIG15 is a block diagram of a lighting baking device for a virtual scene according to one embodiment;
[0039] FIG16 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0040] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0041] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0042] It should be noted that in the following description, the terms "first, second and third" 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 and third" 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.
[0043] The lighting baking method for a virtual scene provided in an embodiment of the present application can be applied in the application environment shown in FIG1 .
[0044] The terminal 102 communicates with the server 104 via a network. The data storage system can store data that the server 104 needs to process. The data storage system can be integrated with the server 104 or placed on a cloud or other network server. The lighting baking method for the virtual scene can be executed by the terminal 102 or the server 104, or by the terminal 102 and the server 104 working together.
[0045] Taking the lighting baking method of a virtual scene executed by terminal 102 as an example, terminal 102 can obtain scene elements of the virtual scene; scene elements include scene objects, light map tasks and light probe tasks; terminal 102 can divide the virtual scene according to the scene elements to obtain a scene tree structure; terminal 102 can traverse to the target node in the spatial nodes of the scene tree structure according to the structural hierarchical relationship; when it is determined that the target node meets the baking conditions based on the number of elements of the target node and the number of elements of the descendant nodes of the target node, terminal 102 can determine the baking element set based on the scene elements of the target node, the scene elements of the ancestor node of the target node and the scene elements of the descendant nodes; terminal 102 can perform lighting baking on the baking element set to obtain lighting information of the baking element set; terminal 102 can also obtain lighting information of all scene elements in a preset sub-scene of the virtual scene based on the lighting information of the baking element set, and save the lighting information of all scene elements in the preset sub-scene.
[0046] The terminal 102 may be a smartphone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, IoT device, or portable wearable device. IoT device may be a smart speaker, smart TV, smart air conditioner, or smart car device. Portable wearable device may be a smart watch, smart bracelet, or head-mounted device.
[0047] The server 104 may be an independent physical server or a service node in a blockchain system, where each service node in the blockchain system forms a peer-to-peer network.
[0048] In addition, server 104 can also be a server cluster composed of multiple physical servers, and can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.
[0049] The terminal 102 and the server 104 may be connected via Bluetooth, USB (Universal Serial Bus), or a network, and this application does not impose any limitation thereto.
[0050] In some embodiments, as shown in FIG2a and FIG2b , a method for baking lighting for a virtual scene is provided. The method is described by taking a computer device as an example. The computer device may be the server or terminal in FIG1 , and includes the following steps:
[0051] Step 202: Acquire scene elements of the virtual scene.
[0052] Among them, the virtual scene is the scene in the game application. When the computer device runs the game application, the virtual scene can be displayed, and the virtual characters in the game can move in the virtual scene; the virtual scene is a scene simulated by the real environment. For example, the virtual scene can include a virtual indoor environment, urban scene, natural scene, etc.
[0053] A gaming application can be an application that runs a linear game or an application that runs an open-world game. In linear games, the game levels are unfolded sequentially, and players can complete the game levels according to the task line. In open-world games, the game levels can be unfolded at the player's choice, and players can move freely in the virtual scene.
[0054] Scene elements are the elements required for lighting baking of virtual scenes. As shown in Figure 3, the scene elements of a virtual scene include: scene objects and lighting tasks, where scene objects can be static virtual objects and static light sources in the virtual scene, and lighting tasks can be light map tasks and light probe tasks.
[0055] Virtual objects are different from real objects. Virtual objects are obtained by simulating real objects. Static virtual objects are virtual objects with fixed positions in virtual scenes. For example, static virtual objects can be houses and road signs in virtual city scenes (virtual scenes), or rocks and trees in virtual natural scenes (virtual scenes). Static light sources are light sources with fixed positions in virtual scenes. For example, they can be candles and table lamps in virtual indoor environments (virtual scenes); they can also be street lights and decorative light sources in houses in virtual city scenes (virtual scenes).
[0056] A lightmap task can be understood as a task that determines the lighting information corresponding to a blank lightmap. A blank lightmap can be associated with a scene object, indicating that the lightmap task is used to determine the lighting information on the surface of the scene object. A lightmap task is bound to a blank lightmap, and the spatial position of the blank lightmap in the virtual scene is the spatial position of the lightmap task in the virtual scene.
[0057] It should be noted that the lighting information of the surface of the scene object can be obtained through lighting baking, and the lighting information of the surface of the scene object can be saved in a blank light map to obtain the light map of the scene object in the virtual scene.
[0058] The lighting probe task can be understood as the task of calculating the lighting information corresponding to the blank lighting probe; the blank lighting probe can be set at any spatial position in the virtual scene, indicating that the lighting probe task is used to determine the lighting information of the spatial position of the blank lighting probe; the lighting probe task is bound to the blank lighting probe, and the spatial position of the blank lighting probe in the virtual scene is the spatial position of the lighting probe task in the virtual scene; exemplarily, the lighting probe task can be set around the scene object, or on the scene object, or evenly set in the virtual scene, for example, the lighting probe task can be evenly set in the virtual scene at preset intervals, or can be evenly set in certain sub-scenes in the virtual scene at preset intervals.
[0059] It should be noted that the lighting information of the spatial position of the lighting probe task can be obtained through lighting baking, and the lighting information of the spatial position of the lighting probe task can be saved in a blank lighting probe to obtain the lighting probe in the virtual scene.
[0060] In some embodiments, the scene elements include scene objects, light mapping tasks and light probe tasks, which are all pre-set in the virtual scene during game design. When setting the scene elements, the spatial position information of the scene elements in the virtual scene is recorded, and the computer device obtains the spatial position information of the scene elements in the virtual scene. Based on the spatial position information of the scene elements, the scene elements of the virtual scene are obtained; through the pre-set spatial position information of the scene elements, the scene elements of the virtual scene can be accurately obtained.
[0061] Step 204 : Divide the virtual scene into scenes according to the scene elements to obtain a scene tree structure.
[0062] The scene tree structure is a tree structure including a root node, intermediate nodes and leaf nodes. Each node in the scene tree structure corresponds to a spatial area in the virtual scene, and at least one node in the scene tree structure includes a scene element.
[0063] The scene tree structure can be a quadtree structure, an octree structure, or a hierarchical bounding box tree structure.
[0064] In some embodiments, the scene tree structure is a quadtree structure; a root node of the scene tree structure is generated according to the virtual scene, that is, the spatial area corresponding to the root node is the entire virtual scene, and for each scene element in the virtual scene, the spatial position information of the scene element is obtained, and the volume of the scene element is determined according to the spatial position information of the scene element. When the volume of the scene element is less than one-quarter of the volume of the spatial area corresponding to the root node, the root node is split into four child nodes; according to the spatial position information of the scene element, a child node to be processed is determined in the four child nodes; when the volume of the scene element is less than one-quarter of the volume of the spatial area corresponding to the child node to be processed, the child node to be processed is continued to be split. child node; when the volume of the scene element is not less than one-fourth of the volume of the spatial area corresponding to the child node to be processed, the child node to be processed is used as the child node to be processed corresponding to the scene element, and the scene element is added to its corresponding child node to be processed; for each scene element, the above process of adding the scene element to the child node to be processed is performed, and after all scene elements of the virtual scene are added to their respective corresponding child nodes to be processed, a scene tree structure is obtained; dividing the scene in the form of a quadtree structure can improve the efficiency of constructing the scene tree structure, and subsequently when obtaining the baked element set in the scene tree structure of the quadtree structure, the efficiency of obtaining the baked element set can also be improved.
[0065] It should be noted that the process of dividing the virtual scene according to the scene elements to obtain the scene tree structure is to split the nodes layer by layer based on the root node, and in the process of splitting the nodes layer by layer, add the scene elements to their corresponding nodes to gradually generate the scene tree structure of the virtual scene.
[0066] In some embodiments, the scene tree structure is an octree structure, and the process of dividing the virtual scene according to the scene elements to obtain the scene tree structure of the octree structure is similar to the process of obtaining the scene tree structure of the binary tree structure and the quadtree structure mentioned above. The difference is that it is judged whether the volume of the scene element is less than one-eighth of the volume of the spatial area corresponding to the node, and when the volume of the scene element is less than one-eighth of the volume of the spatial area corresponding to the node, the node is split into eight child nodes; therefore, the process of dividing the virtual scene according to the scene elements to obtain the scene tree structure of the octree structure can refer to the above process of obtaining the scene tree structure of the quadtree structure; by dividing the scene in the form of the octree structure, the scene elements can be finely divided into the subspaces of the virtual scene. When the baked element set is subsequently obtained in the scene tree structure of the octree structure, the situation of repeatedly dividing the same scene element into different baked element sets can be avoided, thereby improving the accuracy of obtaining the baked element set.
[0067] In some embodiments, the scene tree structure is a hierarchical bounding box tree structure; the bounding box of each scene element in the virtual scene is determined, and a root node of the scene tree structure is generated, where the root node represents the bounding box that surrounds the entire virtual scene, and the center of the bounding box corresponding to the root node is used as a dividing boundary. The bounding box of the scene element on one side of the center is divided into a child node of the root node, and the bounding box of the scene element on the other side of the center is divided into another child node of the root node. For each child node of the root node, the center of the bounding box corresponding to the child node is used as a dividing boundary, and the bounding box corresponding to the scene element included in the bounding box corresponding to the child node is node-divided until the bounding box corresponding to the divided child node is the bounding box corresponding to the scene element, thereby obtaining a scene tree structure; by performing scene division in the form of a hierarchical bounding box tree structure, the scene tree structure can be quickly established, thereby improving the efficiency of constructing the scene tree structure. Subsequently, when obtaining a baked element set in the scene tree structure of the hierarchical bounding box tree, the amount of computation involved is relatively small, thereby improving the efficiency of obtaining the baked element set.
[0068] Step 206: traverse the spatial nodes in the scene tree structure to the target node according to the structural hierarchical relationship.
[0069] Among them, the structural hierarchical relationship is the hierarchical relationship between each spatial node in the scene tree structure; illustratively, in the scene tree structure, the hierarchy of the ancestor node is higher than the hierarchy of the child node; it can be understood that the child node is obtained by splitting the ancestor node.
[0070] Traversing according to the structural hierarchy relationship can be traversing in order from high to low levels; for example, the root node is at the first level, and the child nodes of the root node are at the second level. Traversing according to the structural hierarchy relationship is to traverse the root node first and then the child nodes.
[0071] The target node is a spatial node in the scene tree structure, and the currently traversed spatial node is used as the target node.
[0072] In some embodiments, the computer device traverses the spatial nodes of the scene tree structure to the target node according to the structural hierarchy, starting from the root node and traversing downward layer by layer according to the structural hierarchy; that is, in the first traversal round, the root node is used as the target node to be traversed, and for other traversal rounds except the first traversal round, when there is a spatial node that belongs to the same level as the target node obtained in the previous traversal round and has not been traversed, the target node is traversed in the spatial nodes that have not been traversed; when there is no spatial node that belongs to the same level as the target node obtained in the previous traversal round and has not been traversed, the target node is traversed in the child nodes of the target node obtained in the previous traversal round. In this way, the target node is traversed downward layer by layer according to the structural hierarchy, so that the number of elements in the target node and its descendant nodes traversed subsequently also decreases layer by layer, so as to quickly obtain a baked element set that meets the hardware processing capabilities.
[0073] Exemplarily, the scene tree structure is a quadtree structure as an example for explanation; in the first traversal round, the root node of the scene tree structure is used as the target node obtained by traversal; in the second traversal round, since there is no spatial node that belongs to the same level as the root node and has not been traversed, the target node is traversed among the child nodes of each node, for example, the first child node of the root node of the scene tree structure is used as the target node obtained by traversal; in the third traversal round, since there is still a spatial node that belongs to the same level as the target node of the second traversal round and has not been traversed, the target node is traversed among the spatial nodes that have not been traversed, and the second child node of the root node of the scene tree structure is used as the target node obtained by traversal.
[0074] In some embodiments, a computer device obtains a current traversal round, and traverses the spatial nodes of a scene tree structure according to the current traversal round to obtain a target node; specifically, each spatial node of the scene tree structure has its own corresponding node number, and the node number is determined based on a structural hierarchical relationship. When the computer device traverses each spatial node according to the structural hierarchical relationship, the spatial node whose node number is consistent with the current traversal round can be used as the target node; the target node is traversed based on the correspondence between the current traversal round and the node number, thereby improving the efficiency of traversing to obtain the target node.
[0075] Exemplarily, the scene tree structure is a quadtree structure as an example for explanation; the node number of the root node is 1, the node numbers of the four child nodes of the root node are 2, 3, 4 and 5 respectively, the node codes of the four child nodes of the spatial node with node number 2 are 6, 7, 8 and 9 respectively, and so on, the node number of each spatial node in the scene tree structure can be determined; in the first traversal round (the current traversal round is 1), the root node is the target node traversed, and in the second traversal round (the current traversal round is 2), the spatial node with node code 2 is the target node traversed.
[0076] Step 208 : When it is determined that the target node meets the baking condition based on the number of elements of the target node and the number of elements of its descendant nodes, a baking element set is determined based on the scene elements of the target node, the scene elements of its ancestor nodes, and the scene elements of its descendant nodes.
[0077] Among them, the number of elements of the target node refers to the total number of scene elements included in the target node; the scene elements included in the target node are scene elements in the corresponding spatial area of the target node in the virtual scene. The scene elements can be scene objects and lighting tasks. Therefore, the number of elements of the target node is the total number of scene objects and lighting tasks in the corresponding spatial area of the target node in the virtual scene; for example, the corresponding spatial area of the target node in the virtual scene includes scene object A and the lighting map task of scene object A, then the number of elements of the target node is 2.
[0078] The descendant nodes of the target node include all spatial nodes in the subtree structure of the target node. The subtree structure of the target node is a tree structure composed of spatial nodes obtained by node splitting based on the target node in the scene tree structure; exemplarily, when the target node is the root node in the scene tree structure, the descendant nodes of the root node include all spatial nodes in the scene tree structure except the root node, and all spatial nodes in the scene tree structure except the root node constitute the subtree structure of the target node.
[0079] The number of elements of the descendant nodes of the target node refers to the total number of scene elements included in each spatial node in the subtree structure of the target node; specifically, for each spatial node in the subtree structure of the target node, the total number of scene objects and lighting tasks in the corresponding spatial area of the spatial node in the virtual scene is used as the number of elements of the spatial node, and the sum of the number of elements of all spatial nodes in the subtree structure is the number of elements of the descendant nodes of the target node.
[0080] For example, the target node has four child nodes, two of which have four grandchild nodes respectively, and the target node's grandchild nodes include 12 nodes. The total number of scene elements included in each of the 12 nodes is the number of elements in the target node's grandchild nodes.
[0081] The baking condition may be that the total number of elements of the target node and the number of elements of the descendant nodes falls within a preset number interval, and the total number within the preset number interval is smaller than the total number not within the preset number interval.
[0082] The baking condition may also be that the total number of elements of the target node, the number of elements of the descendant nodes of the target node, and the number of elements of the ancestor nodes of the target node falls within a preset number range.
[0083] The ancestor nodes of the target node include the parent node of the target node and the ancestor node of the parent node; when the target node is not the root node in the scene tree structure, the ancestor nodes of the target node include the root node; exemplarily, the target node is a spatial node at the third level in the scene tree structure, and the ancestor nodes of the target node include: the parent node of the target node at the second level, and the root node at the first level.
[0084] The baked element set may include the scene elements of the target node, the scene elements of the ancestor node of the target node, and the scene elements of the descendant nodes of the target node; or it may include the scene elements of the target node, some scene elements of the ancestor node, and the scene elements of the descendant nodes.
[0085] It should be noted that step 208 is applicable to the case where the scene tree structure is a quadtree structure or an octree structure; when the scene tree structure is a quadtree structure or an octree structure, the scene elements included in all spatial nodes in the scene tree structure constitute all scene elements in the virtual scene, that is, each spatial node in the scene tree structure includes some scene elements in the virtual scene; therefore, the sum of the scene elements of the target node, the ancestor node and the descendant nodes of the target node may be some scene elements in the virtual scene; traversing the target node according to the structural hierarchy, when the level of the target node is lower, the number of descendant nodes of the target node is smaller, and then the sum of the number of elements of the target node and the descendant nodes of the target node is smaller, and then the number of scene elements in the baked element set is smaller, so traversing the target node according to the structural hierarchy is to reduce the number of scene elements in the obtained baked element set, so that the number of scene elements participating in a lighting bake is smaller, which can reduce the memory occupancy rate during the lighting baking process.
[0086] The computer device obtains the number of elements of the target node and the number of elements of the target node's descendant nodes. When it is determined that the target node meets the baking conditions based on the number of elements of the target node and the number of elements of the target node's descendant nodes, the computer device obtains the scene elements of the target node, the scene elements of the ancestor node of the target node, and the scene elements of the descendant nodes of the target node. The scene elements of the target node, the scene elements of the ancestor node of the target node, and the scene elements of the descendant nodes of the target node constitute a baking element set.
[0087] When the target node meets the baking conditions, the scene elements of the ancestor node of the target node are obtained. Among the scene elements of the ancestor node, some scene elements whose center points belong to the spatial area corresponding to the target node are obtained. The baking element set is composed of the partial scene elements obtained from the scene elements of the ancestor node, the scene elements of the target node, and the scene elements of the descendant nodes of the target node.
[0088] When the target node has no ancestor node, that is, when the target node is the root node of the scene tree structure, the baking element set is determined according to the scene elements of the target node and the scene elements of the descendant nodes of the target node.
[0089] When it is determined that the target node does not meet the baking conditions based on the number of elements of the target node and the number of elements of the target node's descendant nodes, return to the step of traversing to the target node in the spatial nodes of the scene tree structure according to the structural hierarchy relationship until the traversed target node meets the baking conditions, and determine the baking element set based on the target node.
[0090] It should be noted that when the target node meets the baking conditions, lighting baking is performed on the baking element set consisting of the scene elements of the target node, the scene elements of the ancestor node of the target node, and the scene elements of the descendant nodes, so that the number of scene elements participating in one lighting baking falls within the preset number range, that is, the number of scene elements participating in one lighting baking is small, which can reduce the video memory occupancy rate during the lighting baking process.
[0091] In some embodiments, when the scene structure tree is a hierarchical bounding box tree structure, after traversing the target node in the spatial nodes of the scene tree structure according to the structural hierarchy, it is determined whether the number of elements of the target node belongs to a preset number range. If it does, it is determined that the target node meets the baking conditions, and the baking element set is determined based on the scene elements contained in the target node; when the scene structure tree is a hierarchical bounding box tree structure, it is not necessary to combine the descendant nodes of the target node to determine whether the target node meets the baking conditions, nor is it necessary to determine the baking element set based on the scene elements of the descendant nodes and ancestor nodes of the target node, thereby improving the efficiency of obtaining the baking element set.
[0092] It should be noted that when the scene structure tree is a hierarchical bounding box tree structure, the root node includes all scene elements in the virtual scene, the sum of the scene elements included in each child node of the root node is all scene elements in the virtual scene, and the sum of the scene elements included in all leaf nodes is also all scene elements in the virtual scene; traversing the target node in the spatial node of the scene tree structure according to the structural hierarchy, the lower the level of the traversed target node, the fewer elements of the target node, and thus the fewer scene elements in the baked element set. Therefore, traversing the target node according to the structural hierarchy can reduce the number of scene elements in the baked element set, so that the number of scene elements participating in a lighting baking is smaller, which can reduce the video memory occupancy during the lighting baking process.
[0093] In the above case, when the target node meets the baking conditions, the baking element set obtained based on the target node corresponds to the target node; after executing step 206, return to executing step 204 until all scene elements in the scene tree structure tree exist in the baking element set. In this way, the baking element set corresponding to each target node that meets the baking conditions can be obtained.
[0094] Exemplarily, all scene elements in the scene tree structure tree are: scene element e1, scene element e2, ..., scene element en. When the traversed target node d1 meets the baking conditions, the baking element set corresponding to the target node d1 includes: scene element e1, scene element e2, ..., scene element ei; when the traversed target node d2 meets the baking conditions, the baking element set corresponding to the target node d2 includes: scene element ei+1, scene element ei+2, ..., scene element ej; when the traversed target node d3 meets the baking conditions, the baking element set corresponding to the target node d3 includes: scene element ej+1, scene element ej+2, ..., scene element en, wherein the collection of scene elements included in the baking element set corresponding to the target node d1, the baking element set corresponding to the target node d2, and the baking element set corresponding to the target node d3 are all scene elements in the virtual scene.
[0095] Step 210: Perform lighting baking on the baked element set to obtain lighting information of the baked element set.
[0096] Among them, light baking is the process of calculating the lighting information of the surface of scene objects and the lighting information of each spatial position in the virtual scene based on the light source settings and scene object settings in the virtual scene. In actual applications, the lighting information of the virtual scene can be calculated in advance through light baking. When the game application is running, the virtual scene can be rendered according to the pre-calculated lighting information to show the lighting effect of the virtual scene.
[0097] A baking element set includes at least one scene element, which can be a scene object, a light map task, and a light probe task.
[0098] The lighting information of the baked element set includes the lighting information corresponding to the light map task and the lighting information corresponding to the light probe task in the baked element set; among them, the lighting information corresponding to the light map task is the lighting information of the surface of the scene object associated with it, that is, obtaining the lighting information corresponding to the light map task can be understood as obtaining the light map of the scene object associated with it; the lighting information corresponding to the light probe task is the lighting information of the spatial position of the light probe task in the virtual scene, that is, obtaining the lighting information corresponding to the light probe task can be understood as obtaining the light probe.
[0099] Among them, scene objects are associated with light mapping tasks. When the baking element set includes scene objects and associated light mapping tasks, light baking is performed on the baking element set. It can be understood as the process of performing lighting calculations on the surface of the scene objects based on the light mapping tasks and obtaining the light mapping of the scene objects.
[0100] Among them, the lighting probe task corresponds to the spatial position in the virtual scene. When the baking element set includes the lighting probe task, the baking element set is light-baked, which can be understood as the process of performing lighting calculation on the spatial position corresponding to the lighting probe task in the virtual scene to obtain the lighting probe.
[0101] For example, the baking element set P1 includes the scene object A and the light map task m1 of the scene object A. By performing light baking on the baking element set P1, the lighting information of the surface of the scene object A can be calculated, and the light map mapA, light map mapA of the scene object A can be obtained; for another example, the baking element set P2 includes the light probe task b1 and the light probe task b2. By performing light baking on the baking element set P2, the lighting information of the spatial position of the light probe task b1 in the virtual scene can be calculated, that is, the light probe b1 is obtained, and the lighting information of the spatial position of the light probe task b2 in the virtual scene can be calculated, that is, the light probe b2 is obtained.
[0102] When there are multiple target nodes that meet the baking condition, correspondingly, multiple baking element sets can be obtained according to the multiple target nodes.
[0103] In some embodiments, for each baking element set corresponding to each target node that meets the baking conditions, lighting baking is performed on each baking element set in turn, and lighting information corresponding to the light map task and the lighting information corresponding to the light probe task in each baking element set are obtained in turn; the computer device performs lighting baking on one baking element set each time, which can reduce the video memory occupancy rate during the lighting baking process.
[0104] After the computer device completes lighting baking and obtains lighting information, it can save the lighting information. In one possible implementation method, the computer device can save the lighting information of all baked element sets to the local memory when the lighting information of all baked element sets is obtained, that is, when the lighting information of the entire virtual scene is obtained, so that when the lighting information of the scene elements is needed later, the lighting information can be obtained from the local memory. This method can ensure the integrity of the lighting information of the virtual scene.
[0105] In another possible implementation, since the computer device performs lighting baking on one baking element set at a time, the computer device can save the lighting information of the baking element set in the local memory each time it obtains the lighting information of the baking element set. After the lighting information of all baking element sets is saved in the local memory, the local memory stores the lighting information of the virtual scene, and the required lighting information can be obtained from the local memory. This method can perform lighting baking while saving lighting information, can realize parallel processing of lighting information, and improve the efficiency of saving lighting information of the virtual scene.
[0106] In another possible implementation, each time the computer device obtains lighting information for a baked element set, it obtains lighting information belonging to each preset sub-scene in the virtual scene from the lighting information of the baked element set; the virtual scene includes multiple preset sub-scenes, and the virtual scene is a scene in a game application. The preset sub-scene can be understood as the scene corresponding to the level in the game.
[0107] When the lighting information of all scene elements in a preset sub-scene is obtained, the lighting information of the preset sub-scene is saved. In this way, after the lighting information of all preset sub-scenes in the virtual scene is saved to the local memory, the local memory stores the lighting information of the virtual scene, and the required lighting information can be obtained from the local memory. This method can perform lighting baking while saving lighting information, and can realize parallel processing of lighting information, thereby improving the efficiency of saving lighting information of the virtual scene. In addition, the lighting information saved in the local memory is saved according to the preset sub-scenes in the virtual scene elements. When the lighting information of the preset sub-scene is needed, the lighting information of the preset sub-scene can be quickly obtained from the local memory. In related technologies, lighting baking is mostly used for smaller virtual scenes. When the virtual scene is large, the amount of data and calculation involved in lighting baking is large, and the hardware resources of the computer equipment performing lighting baking are high, making it difficult to ensure the stability of lighting baking.
[0108] In the above-mentioned lighting baking method for a virtual scene, scene elements of the virtual scene are divided to obtain a scene tree structure, the target node is traversed in the scene tree structure, and when the number of elements of the target node and the descendant nodes of the target node meets the baking conditions, the baking element set is determined according to the baking elements respectively included in the target node, the ancestor node of the target node and the descendant nodes, so that the number of scene elements in the baking element set is small, and lighting baking is performed on the baking element set, so that the number of scene elements participating in one lighting baking is small, which can reduce the video memory occupancy rate during the lighting baking process and improve the stability of lighting baking.
[0109] In some embodiments, after traversing the spatial nodes of the scene tree structure according to the structural hierarchy to the target node, the process further includes: obtaining the number of elements of the target node and the number of elements of the target node's descendant nodes; summing the number of elements of the target node and the number of elements of the descendant nodes to obtain a total number of elements; and determining that the target node meets the baking conditions when the total number of elements falls within a preset number interval. By setting a preset number interval, the number of object elements in the baked element set can be limited, that is, the number of scene elements participating in the sequential lighting baking can be limited, so that lighting baking can be applied to computer devices with different hardware resources and the stability of lighting baking is guaranteed.
[0110] Among them, the total number of elements belonging to the preset number range is less than the total number of elements not belonging to the preset number range; when performing light baking, the more the total number of elements, the higher the hardware resources required for light baking. Since the total number of elements belonging to the preset number range is small, the baking conditions can be used to limit the number of scene elements participating in light baking, thereby reducing the hardware resources required for light baking.
[0111] The preset number interval can be determined according to the hardware resource conditions of the computer device that performs light baking. For example, when the hardware computing power of the computer device is low, the number in the preset number interval can be set to be smaller. When the hardware computing power of the computer device is high, the number in the preset number interval can be set to be larger. In this way, the baking element set can be adaptively divided according to the hardware resources of the computer device, so that light baking can be applied to computer devices with different hardware resources.
[0112] For the traversed target node, the computer device obtains the number of scene elements in the target node, obtains the number of scene elements of each descendant node of the target node, takes the sum of the number of scene elements of each descendant node as the number of elements of the descendant nodes of the target node, sums the number of scene elements in the target node and the number of elements of the descendant nodes to obtain the total number of elements. When the total number of elements falls within a preset number range, it is determined that the target node meets the baking conditions.
[0113] Exemplarily, the preset number interval is [1, 20], and the scene structure tree is shown in Figure 4. When the traversed target node is d1, the descendant nodes of the target node d1 include: spatial node d2, spatial node d3, spatial node d4, spatial node d5, spatial node d6, spatial node d7, spatial node d8, spatial node d9, spatial node d10, spatial node d11, spatial node d12 and spatial node d13; the number of elements of the target node d1 is 5, the number of elements of the descendant nodes of the target node d1 is 30, and the total number of elements is 35. Since the total number of elements 35 does not belong to the preset number interval: [1, 20], the target node d1 does not meet the baking conditions.
[0114] When the traversed target node is d2, the descendant nodes of target node d2 include: spatial node d6, spatial node d7, spatial node d8, and spatial node d9. The number of elements in target node d2 is 5, the number of elements in the descendant nodes of target node d2 is 10, and the total number of elements is 15. Since the total number of elements 10 falls within the preset number range: [1, 20], target node d2 meets the baking conditions.
[0115] In the above embodiment, the number of elements of the target node and the number of elements of the descendant nodes are summed to obtain the total number of elements. When the total number of elements falls within a preset number interval, it is determined that the target node meets the baking conditions. The number of object elements in the baking element set can be limited by setting the preset number interval, that is, the number of scene elements participating in sequential lighting baking is limited, so that lighting baking can be applied to computer devices with different hardware resources and the stability of lighting baking is guaranteed.
[0116] In some embodiments, as shown in FIG5 , a baking element set is determined based on the scene elements of a target node, the scene elements of an ancestor node of the target node, and the scene elements of descendant nodes, including: step 501, obtaining location information corresponding to the scene elements of the ancestor node of the target node; step 502, selecting a scene element to be baked from the scene elements of the ancestor node based on the location information; and step 503, determining a baking element set based on the scene elements to be baked, the scene elements of the target node, and the scene elements of the descendant nodes. In this way, the scene elements of the ancestor node can be divided into different baking element sets, limiting the number of scene elements in the baking element sets, allowing light baking to be applied to computer devices with different hardware resources, and ensuring the stability of light baking.
[0117] Among them, the position information corresponding to the scene element can represent the position of the scene element in the virtual scene; in one implementation method, the position information is the position information of the center point of the scene element in the virtual scene; in another implementation method, the position information can include the position coordinates of each vertex of the bounding box of the scene element in the virtual scene.
[0118] The scene elements to be baked may be part or all of the scene elements of the ancestor node corresponding to the target node; the baking element set includes the scene elements to be baked, the scene elements of the target node, and the scene elements of the descendant nodes.
[0119] In some embodiments, the position information is the position information of the center point of the scene element in the virtual scene; for each scene element of the ancestor node, the computer device obtains the position information of the center point of the scene element in the virtual scene, and if the position information is in the spatial area corresponding to the target node in the virtual scene, the scene element is used as the scene element to be baked corresponding to the target node; the scene element to be baked, the scene element of the target node and the scene element of the descendant node are combined to obtain a baked element set; based on the positional relationship between the center point of the scene element and the spatial area corresponding to the target node in the virtual scene, the scene element to be baked can be quickly determined.
[0120] In some embodiments, the position information includes the position coordinates of each vertex of the bounding box of the scene element in the virtual scene; the computer device obtains each scene element of the ancestor node of the target node, and for each scene element of the ancestor node, the computing device obtains the position coordinates of each vertex of the bounding box of the scene element in the virtual scene, if each position coordinate is within the spatial area corresponding to the target node in the virtual scene, then the scene element is used as the scene element to be baked; or if more than half of the position coordinates are within the spatial area corresponding to the target node in the scene element, then the scene element is used as the scene element to be baked; the scene element to be baked, the scene element of the target node and the scene element of the descendant node are combined to obtain a baking element set; the scene element to be baked is determined based on the positional relationship between each vertex of the bounding box of the scene element and the spatial area corresponding to the target node in the virtual scene, which can avoid dividing the same scene element into different baking element sets, thereby avoiding repeated baking of lighting tasks and improving the efficiency of lighting baking.
[0121] Exemplarily, as shown in Figure 6, the target node d1 corresponds to the spatial area A in the virtual scene. For the scene element e1 of the ancestor node d2 of the target node d1, the position coordinates of each vertex of the bounding box of the scene element e1 in the virtual scene are all within the spatial area A, then the scene element e1 is used as the scene element to be baked; for the scene element e2 of the ancestor node d2 of the target node d1, the position coordinates of each vertex of the bounding box of the scene element e2 in the virtual scene are not within the spatial area A, then the scene element e2 is not the scene element to be baked; the baking element set includes: the scene element e1, the scene element of the target node d1, and the scene elements of the child nodes d3, d4, d5 and d6 of the target node d1, among which the child nodes d3, d4, d5 and d6 are descendant nodes of the target node d1.
[0122] In the above embodiment, based on the position information of the scene elements of the ancestor node, the scene elements to be baked in the baking element set corresponding to the target node are obtained from the scene elements of the ancestor node. In this way, the scene elements of the ancestor node can be divided into baking element sets corresponding to different target nodes, avoiding the division of all scene elements of the ancestor node into the same baking element set, limiting the number of scene elements in the baking element set, so that lighting baking can be applied to computer devices with different hardware resources, and ensuring the stability of lighting baking.
[0123] In some embodiments, obtaining position information corresponding to a scene element of an ancestor node of a target node includes: traversing the scene elements of the ancestor node of the target node to obtain the target scene element; obtaining position information of the center point of the target scene element in the virtual scene; and selecting a scene element to be baked from the scene elements of the ancestor node based on the position information, including: when the position information belongs to the node space of the target node, selecting the target scene element as the scene element to be baked. Determining whether the target scene element is a scene element to be baked based on the positional relationship between the center point of the target scene element and the node space of the target node reduces the amount of position information involved in selecting the scene element to be baked, thereby improving the efficiency of selecting the scene element to be baked.
[0124] Among them, the position information is the position coordinates of the center point of the target scene element in the virtual scene; the node space of the target node represents the corresponding spatial area of the target node in the virtual scene.
[0125] The computer device obtains each scene element of the ancestor node of the target node, traverses each scene element to obtain the target scene element, obtains the position information of the center point of the target scene element in the virtual scene, obtains the position information of the node space of the target node in the virtual scene corresponding to the spatial area, and judges whether the center point of the target scene element is within the node space of the target node based on the position information of the center point in the virtual scene and the position information of the node space in the virtual scene corresponding to the spatial area, and if the center point of the target scene element is within the node space of the target node, the target scene element is used as the scene element to be baked. It can be understood that when the center point of the target scene element is within the node space of the target node, it means that most of the content of the target scene element is within the node space of the target node, so the target scene element can be used as the scene element to be baked in the set of baking elements corresponding to the target node.
[0126] Exemplarily, as shown in Figure 6, the target node d1 corresponds to the spatial area A in the virtual scene. For the scene element e1 of the ancestor node d1 of the target node d1, the position information of the center point of the scene element e1 is within the spatial area A, then the scene element e1 is used as the scene element to be baked; for the scene element e2 of the ancestor node d1 of the target node d1, the position information of the center point of the scene element e2 is not within the spatial area A, then the scene element e2 is not the scene element to be baked; the baking element set includes: the scene element e1, the scene element of the target node d1, and the scene elements of the child nodes d3, d4, d5 and d6 of the target node d1, wherein the child nodes d3, d4, d5 and d6 are descendant nodes of the target node d1.
[0127] In the above embodiment, it is only necessary to determine whether the target scene element is the scene element to be baked based on the positional relationship between the center point of the target scene element and the node space of the target node, thereby reducing the amount of positional information involved in selecting the scene element to be baked, thereby reducing the amount of calculation required for selecting the scene element to be baked, and improving the efficiency of selecting the scene element to be baked.
[0128] In some embodiments, the lighting baking method for a virtual scene further includes: obtaining position information corresponding to scene elements of an ancestor node of a target node; and determining a baking element set based on the scene elements of the target node, the scene elements of the ancestor node of the target node, and the scene elements of the descendant nodes, including: when no scene elements to be baked are selected from the scene elements of the ancestor node based on the position information, determining the baking element set based on the scene elements of the target node and the scene elements of the descendant nodes. The baking element set does not include the scene elements of the ancestor node, thereby limiting the number of scene elements in the baking element set, enabling lighting baking to be applied to computer devices with different hardware resources and ensuring the stability of lighting baking.
[0129] The position information corresponding to the scene element of the ancestor node may include the position coordinates of the center point of the scene element in the virtual scene; or, may also include the position coordinates of each vertex of the bounding box of the scene element in the virtual scene.
[0130] When no scene element to be baked is selected from the scene elements of the ancestor node according to the position information, the baking element set includes the scene elements of the target node and the scene elements of the descendant nodes.
[0131] Among them, the process of obtaining the position information corresponding to the scene element of the ancestor node of the target node is the same as the process of obtaining the position information corresponding to the scene element of the ancestor node of the target node in the previous embodiment. Therefore, you can refer to the previous embodiment for the description of obtaining the position information corresponding to the scene element of the ancestor node of the target node.
[0132] The position information may be the position information of the center point of the scene element in the virtual scene; for each scene element of the ancestor node, the computer device obtains the position information of the center point of the scene element in the virtual scene; if the position information does not belong to the node space of the target node, the scene element is not the baked scene element of the target node; if the position information of the center point of each scene element in the ancestor node does not belong to the node space of the target node, it means that when the scene element to be baked is not selected from the scene elements of the ancestor node based on the position information, the baked element set includes the scene elements of the target node and the scene elements of the descendant nodes.
[0133] The position information may also include the position coordinates of each vertex of the bounding box of the scene element in the virtual scene; for each scene element of the ancestor node, the computing device obtains the position coordinates of each vertex of the bounding box of the scene element in the virtual scene. If each position coordinate is not within the corresponding spatial area of the target node in the virtual scene, the scene element is not the scene element to be baked of the target node; if each scene element in the ancestor node is not the scene element to be baked of the target node, it means that when the scene element to be baked is not selected from the scene elements of the ancestor node based on the position information, the baking element set includes the scene elements of the target node and the scene elements of the descendant nodes.
[0134] Exemplarily, as shown in Figure 7, the target node d7 corresponds to the spatial area B in the virtual scene. For the scene element e3 of the ancestor node d8 of the target node d7, the position information of the center point of the scene element e3 is not in the spatial area B, then the scene element e3 is not the scene element to be baked; for the scene element e4 of the ancestor node d8, the position information of the center point of the scene element e4 is not in the spatial area B, then the scene element e4 is not the scene element to be baked, all the scene elements (e3 and e4) of the ancestor node d8 are not scene elements to be baked, then the baking element set includes: the scene element of the target node d7, the scene elements of the child nodes d9, d10, d11 and d12 of the target node d7, among which the child nodes d9, d10, d11 and d12 are descendant nodes of the target node d1.
[0135] In the above embodiment, when the scene elements to be baked are not selected from the scene elements of the ancestor node, the baking element set is determined based on the scene elements of the target node and the scene elements of the descendant nodes, thereby limiting the number of scene elements in the baking element set, so that lighting baking can be applied to computer devices with different hardware resources and ensuring the stability of lighting baking.
[0136] In some embodiments, as shown in FIG8 , a virtual scene is divided according to scene elements to obtain a scene tree structure, including: step 801, generating an initial scene tree structure; step 802, obtaining a scene element to be added from the scene elements, traversing the initial node corresponding to the scene element to be added in the initial scene tree structure, and obtaining the node type of the initial node; step 803A, in the case where the node type is a leaf node type, when the scene element to be added does not meet the element adding condition, splitting the initial node to obtain a child node to update the initial scene tree structure, selecting the child node corresponding to the scene element to be added from the split child nodes as the initial node, and returning to the step of obtaining the node type of the initial node; step 803B, in the case where the node type is a leaf node type, when the scene element to be added meets the element adding condition, adding the scene element to be added to the initial node to update the initial scene tree structure, and returning to the step of traversing the scene elements to obtain the scene element to be added; step 804, after completing the traversal of the scene elements, using the updated initial scene tree structure as the scene tree structure. The scene tree structure enables the fine division of scene elements into subspaces of the virtual scene. When subsequently obtaining the baking element set for lighting baking based on the scene tree structure, it can avoid repeatedly dividing the same scene element into different baking element sets, thereby reducing repeated baking tasks in lighting baking, saving hardware resources, and improving lighting baking efficiency.
[0137] The generated initial scene tree structure includes a root node, which can be understood as generating a root node corresponding to a virtual scene, and the root node is used as the initial scene tree structure; the scene element to be added is a scene element among the scene elements of the virtual scene.
[0138] It should be noted that dividing the virtual scene according to scene elements to obtain a scene tree structure refers to splitting the nodes in the initial scene tree structure, and in the process of node splitting, adding scene elements to the nodes of the initial scene tree structure to obtain the scene tree structure; adding a scene element to the nodes of the initial scene tree structure may involve multiple node splitting, multiple updates of the initial nodes, and multiple updates of the initial scene tree structure.
[0139] The node type of the initial node refers to the node type of the initial node in the current initial scene tree structure. The node type is a leaf node type, or it is not a leaf node type. When the node type of the initial node is a leaf node type, it means that the initial node is a leaf node in the current initial scene tree structure, or it means that the initial node has no child nodes in the current initial scene tree structure.
[0140] When the first scene element to be added is added to the initial scene tree structure, the initial node obtained for the first time is the root node. Since the root node included in the current initial scene tree structure has no child nodes, the node type of the initial node is a leaf node type.
[0141] The element adding condition is the condition for adding the scene element to be added to the initial node, and whether the scene element to be added meets the element adding condition can be determined based on the initial node; illustratively, the element adding condition can be that the space corresponding to the scene element to be added in the virtual scene occupies a preset percentage of the space corresponding to the initial node in the virtual scene; or, the element adding condition can be that, when the element type of the scene element to be added is the first type, the space corresponding to the scene element to be added in the virtual scene occupies a first preset percentage of the space corresponding to the initial node in the virtual scene; or, the element adding condition can be that, when the element type of the scene element to be added is the second type, the space corresponding to the scene element to be added in the virtual scene occupies a second preset percentage of the space corresponding to the initial node in the virtual scene.
[0142] Among them, when the element type of the scene element to be added is the first type, it means that the scene element to be added is a scene object. When the element type of the scene element to be added is the second type, it means that the scene element to be added is a light map task or a light probe task.
[0143] It should be noted that, in the above examples, the specific values of the preset percentage, the first preset percentage and the second preset percentage can be set according to requirements, and the embodiments of the present application do not limit this.
[0144] When the scene tree structure is a quadtree structure, four child nodes can be obtained by splitting the initial node; when the scene tree structure is an octree structure, eight child nodes can be obtained by splitting the initial node.
[0145] The computer device generates a root node corresponding to the virtual scene and uses the root node as the initial scene tree structure; traverses the scene elements of the virtual scene to obtain the scene elements to be added, uses the root node as the initial node, and obtains the node type of the initial node as a leaf node type.
[0146] The computer device determines whether the scene element to be added meets the element adding conditions based on the initial node. When the scene element to be added does not meet the element adding conditions, the initial node is split to obtain child nodes, so as to update the initial scene tree structure. The updated initial scene tree structure includes the initial node and the child nodes obtained by splitting the initial node; the corresponding child node of the scene element to be added is selected from the child nodes obtained by splitting as the initial node, that is, the initial node is replaced with the corresponding child node of the scene element to be added; wherein, the corresponding child node of the scene element to be added refers to the child node of the scene element to be added in the corresponding spatial area in the virtual scene.
[0147] For ease of explanation, the initial node before node splitting is recorded as the first initial node, and the corresponding child node of the scene element is recorded as the second initial node; after selecting the second initial node, the step of obtaining the node type of the initial node is returned. Since the second initial node is obtained by node splitting the first initial node, the second initial node has no child nodes, so the type of the second initial node is a leaf node type; the computer device determines whether the scene element to be added meets the element addition condition based on the second initial node. When the scene element to be added meets the element addition condition, the scene element to be added is added to the second initial node to update the initial scene tree structure, and returns to the step of traversing the scene elements to obtain the scene element to be added, so as to add the next scene element to be added obtained by the traversal to the initial node. Similarly, adding the next scene element to be added obtained by the traversal to the initial node may involve multiple node splitting, multiple updates of the initial node, and multiple updates of the initial scene tree structure. After completing the traversal of all scene elements in the virtual scene, that is, after all scene elements are added to the initial node, the updated initial scene tree structure is used as the scene tree structure.
[0148] In some embodiments, since the illumination of a scene element may be affected by surrounding scene elements, such as causing occlusion or bounce, the scene element may be expanded to prevent the illumination of the scene element from being affected by surrounding scene elements. The computer device expands the scene element and uses the expanded scene element to update the scene element.
[0149] Expanding scene elements includes expanding scene objects, light mapping tasks, and light probe tasks; specifically, the computer device can obtain a bounding box of the scene object, expand the bounding box of the scene object according to the lighting expansion coefficient to obtain the expanded scene object, obtain a light mapping task, expand the light mapping task according to the lighting expansion coefficient to obtain the expanded light mapping task, obtain a light probe task, expand the light probe task according to the lighting expansion coefficient to obtain the expanded light probe task.
[0150] Among them, the lighting expansion coefficient can be the number of lighting expansion grids or the multiple of lighting expansion grids; the grid is a unit for measuring the size of the space occupied by scene elements in the virtual scene; taking the expansion of scene objects as an example, the bounding box of the scene object is expanded according to the lighting expansion coefficient, and the length and width of the bounding box of the scene object can be expanded according to the number of lighting expansion grids or the multiple of lighting expansion grids.
[0151] Expanding the length and width of the scene object's bounding box according to the number of lighting expansion grids may involve increasing the length and width of the scene object's bounding box by the number of lighting expansion grids; expanding the length and width of the scene object's bounding box according to the lighting expansion grid multiple may involve multiplying the length and width of the scene object's bounding box by the lighting expansion grid multiple.
[0152] Exemplarily, a computer device can set the lighting expansion coefficient through the lighting baking configuration interface, as shown in FIG9 , wherein the lighting expansion grid multiplier is 1, and the number of lighting expansion grids is 100; the length and width of the bounding box of the scene object are both 2000 grids, the number of lighting expansion grids is 100, and the length and width of the bounding box of the expanded scene object are both 2100 grids.
[0153] In some embodiments, the scene tree structure is a quadtree structure; the computer device uses the horizontal plane of the virtual scene as the scene division plane, and divides the virtual scene according to the scene division plane; the horizontal plane of the virtual scene is the plane formed by the X-axis and the Y-axis for creating the virtual scene; the bounding box, light map task and light probe task of the scene object are determined in the scene division plane, and the virtual scene is divided according to the bounding box, light map task and light probe task of the scene object in the scene division plane to obtain a quadtree scene tree structure; dividing the scene in the form of a quadtree structure can improve the efficiency of constructing the scene tree structure, and subsequently when obtaining the baked element set in the scene tree structure of the quadtree structure, the efficiency of obtaining the baked element set can also be improved.
[0154] In some embodiments, the scene tree structure is an octree structure; the computer device divides the space corresponding to the virtual scene according to the scene elements of the virtual scene; the space corresponding to the virtual scene is the space formed by the X-axis, Y-axis and Z-axis for creating the virtual scene; the bounding box, light map task and light probe task of the scene object are determined in the space corresponding to the virtual scene, and the bounding box, light map task and light probe task of the scene object in the space corresponding to the virtual scene are divided to obtain an octree scene tree structure; by performing scene division in the form of the octree structure, the scene elements can be finely divided into subspaces of the virtual scene, and when the baked element set is subsequently obtained in the scene tree structure of the octree structure, the situation of repeatedly dividing the same scene element into different baked element sets can be avoided, thereby improving the accuracy of obtaining the baked element set.
[0155] Take the case where the scene tree structure is a quadtree structure and the scene element to be added obtained by the first traversal is added to the initial node as an example for explanation; as shown in FIG10 , the initial scene tree structure t1 is generated, and the initial scene tree structure t1 includes a root node d1. After the scene element to be added e1 is obtained by traversal, the root node d1 is used as the initial node; the node type of the initial node d1 is a leaf node type, and it is judged according to the initial node d1 whether the scene element to be added e1 meets the element adding condition. When the element adding condition is not met, the initial node d1 is split to obtain child nodes d2, d3, d4 and d5. The initial scene tree structure t1 is updated to the initial scene tree structure t2; the child node d2 corresponding to the scene element e1 to be added is selected from the child nodes d2, d3, d4 and d5, the child node d2 is used as the initial node, and the step of obtaining the node type of the initial node is returned; the node type of the initial node d2 is a leaf node type, and whether the scene element e1 to be added meets the element adding condition is judged according to the initial node d2. When the element adding condition is met, the scene element e1 to be added is added to the initial node d2, so as to update the initial scene tree structure t2 to the initial scene tree structure t3.
[0156] In the above embodiment, the nodes in the initial scene tree structure are split, and in the process of node splitting, scene elements are added to the nodes of the initial scene tree structure to obtain a scene tree structure, so as to facilitate the subsequent acquisition of a baking element set for lighting baking based on the scene tree structure. Since the scene tree structure realizes the fine division of scene elements into subspaces of the virtual scene, when the baking element set for lighting baking is subsequently obtained based on the scene tree structure, it is possible to avoid repeatedly dividing the same scene element into different baking element sets, thereby reducing repeated baking tasks in lighting baking, saving hardware resources, and improving lighting baking efficiency.
[0157] In some embodiments, the element addition condition includes a first element addition condition; after obtaining the node type of the initial node, the condition further includes: when the node type is a leaf node type, obtaining the node space of the target node, the element type and element space of the scene element to be added; when the element type is an object type and the node space meets the first space division condition, determining that the scene element to be added does not meet the first element addition condition. By using different methods to determine whether the scene element to be added does not meet the element addition condition according to the element type of the scene element to be added, it is possible to achieve targeted element addition to scene objects, light map tasks, and light probe tasks, thereby improving the accuracy of scene division.
[0158] Among them, the node space of the target node is the space corresponding to the target node in the virtual scene, and the element space of the scene element to be added is the space occupied by the scene element to be added in the virtual scene; the element type of the scene element to be added can be an object type or a lighting task type; when the element type of the scene element to be added is an object type, it means that the scene element to be added is a scene object.
[0159] In some embodiments, after obtaining the node space of the target node, the element type and element space of the scene element to be added, it also includes: obtaining a preset space size interval; when the size of the node space does not belong to the preset control size interval, determining that the node space meets the first space division condition.
[0160] Specifically, the node space satisfies the first space division condition, which may be that the size of the node space does not belong to the preset space size interval, and the size of the node space that does not belong to the preset space size interval is larger than the size of the node space that does not belong to the preset space size interval; exemplarily, the preset space size interval is [0, minimum space size of child nodes], when the size of the node space is larger than the minimum space size of child nodes, the node space satisfies the first space division condition; the minimum space size of child nodes can be set according to actual needs.
[0161] For the initial node, when the node type of the initial node is a leaf node type, the element type of the scene element to be added is obtained. If the element type of the scene element to be added is an object type, and the size of the node space of the initial node does not belong to the preset space size range, it is determined that the scene element to be added does not meet the first element addition condition.
[0162] In some embodiments, the element addition condition includes a second element addition condition; after obtaining the node type of the initial node, it also includes: when the node type is a leaf node type, obtaining the node space of the target node, the element type and element space of the scene element to be added; and when the element type is a lighting task type, and the element space and the node space meet the second space division condition, determining that the scene element to be added does not meet the second element addition condition. According to the element type of the scene element to be added, different methods are used to determine whether the scene element to be added does not meet the element addition condition, so that elements can be added to scene objects, light map tasks, and light probe tasks in a targeted manner, thereby improving the accuracy of scene division.
[0163] When the element type of the scene element to be added is a lighting task type, it indicates that the scene element to be added is a light map task or a light probe task.
[0164] In some embodiments, after obtaining the node space of the target node, the element type and element space of the scene element to be added, it also includes: obtaining a third preset percentage; and when the proportion of the element space occupying the node space does not reach the third preset percentage, determining that the element space and the node space meet the second space division condition.
[0165] The fact that the proportion of the element space to the node space does not reach the third preset percentage may indicate that the element space occupies a relatively small space in the node space. The third preset percentage may be set according to actual needs, and for example, may be 80%.
[0166] For the initial node, when the node type of the initial node is a leaf node type, obtain the element type of the scene element to be added. If the element type of the scene element to be added is a lighting task type, and the element space of the scene element to be added does not occupy a proportion of the node space that reaches the third preset percentage, it is determined that the scene element to be added does not meet the second element adding condition.
[0167] When the scene element to be added does not meet the first element adding condition, or does not meet the second element adding condition, the initial node is split.
[0168] In the above embodiment, according to the element type of the scene element to be added, different methods are used to determine whether the scene element to be added meets the element addition conditions, so that targeted element addition can be performed on scene objects, light map tasks and light probe tasks, thereby improving the accuracy of scene division.
[0169] In some embodiments, the element adding condition includes a first element adding condition; after obtaining the node type of the initial node, it also includes: when the node type is a leaf node type, obtaining the node space of the target node, the element type and element space of the scene element to be added; when the element type is an object type and the node space does not meet the first space division condition, determining that the scene element to be added meets the first element adding condition; according to the element type of the scene element to be added, different methods are used to determine that the scene element to be added does not meet the element adding condition, so as to achieve targeted element addition to scene objects, light map tasks and light probe tasks, thereby improving the accuracy of scene division.
[0170] In some embodiments, the element addition condition includes a second element addition condition; after obtaining the node type of the initial node, it also includes: when the node type is a leaf node type, obtaining the node space of the target node, the element type and element space of the scene element to be added; when the element type is a lighting task type, and the element space and node space do not meet the second space division condition, determining that the scene element to be added meets the second element addition condition. According to the element type of the scene element to be added, different methods are used to determine whether the scene element to be added does not meet the element addition condition, so that elements can be added to scene objects, light map tasks, and light probe tasks in a targeted manner, thereby improving the accuracy of scene division.
[0171] Among them, the node space does not meet the first space division condition, which may be that the size of the node space belongs to the preset space size interval, and the size of the node space belonging to the preset space size interval is smaller than the size of the node space that does not belong to the preset space size interval; exemplarily, the preset space size interval is [0, minimum space size of child nodes], when the size of the node space is less than or equal to the minimum space size of child nodes, the node space does not meet the first space division condition.
[0172] The element space and the node space may not satisfy the second space division condition if the proportion of the element space occupying the node space reaches a third preset percentage. The third preset percentage may indicate that the element space occupies a larger space in the node space. The third preset percentage may be set based on actual needs and, for example, may be 80%.
[0173] It should be noted that when the element type is a lighting task type, the scene element to be added will be affected by the light bounce of the surrounding elements. If the proportion of the element space occupied by the node space reaches the third preset percentage, it means that all elements in the node space except the scene element to be added will cause light bounce effects on the scene element to be added. In this case, the initial node can be skipped and the scene element to be added can be directly added to the initial node. The light bounce effects of other elements on the scene element to be added can be retained, making the lighting baking of the scene element to be added more accurate.
[0174] For the initial node, when the node type of the initial node is a leaf node type, the element type of the scene element to be added is obtained. If the element type of the scene element to be added is an object type, and the size of the node space of the initial node belongs to the preset space size range, it is determined that the scene element to be added meets the first element adding condition; if the element type of the scene element to be added is a lighting task type, and the element space of the scene element to be added occupies a proportion of the node space that reaches a third preset percentage, it is determined that the scene element to be added meets the second element adding condition.
[0175] When the scene element to be added meets the first element adding condition or meets the second element adding condition, the scene element to be added is added to the initial node.
[0176] In the above embodiment, according to the element type of the scene element to be added, different methods are used to determine whether the scene element to be added meets the element addition conditions, so that targeted element addition can be performed on scene objects, light map tasks and light probe tasks, thereby improving the accuracy of scene division.
[0177] In some embodiments, after obtaining the node type of the initial node, the method further includes: when the node type is not a leaf node type, obtaining the target child node corresponding to the scene element to be added from each child node of the target node; when the number of target child nodes does not meet the intersection condition, using the target child node as the initial node obtained by traversal, and returning to the step of obtaining the node type of the initial node. The nodes for adding the scene element to be added can be determined layer by layer in the initial scene tree structure, thereby achieving a fine division of the scene elements into the subspace of the virtual scene. When subsequently obtaining the baking element set for light baking based on the scene tree structure, the situation of repeatedly dividing the same scene element into different baking element sets can be avoided, thereby reducing repeated baking tasks in light baking, saving hardware resources, and improving the efficiency and stability of light baking.
[0178] When the initial node has child nodes, the node type of the initial node is not a leaf node type.
[0179] In the process of adding the first scene element to be added to the initial scene tree structure, the initial scene structure tree may be updated, such as splitting the root node to obtain child nodes. Therefore, when the second scene element to be added is added to the initial scene tree structure, the initial node obtained for the first time is the root node. The root node included in the current initial scene tree structure may have child nodes, so the node type of the initial node may not be a leaf node type.
[0180] The target sub-node is a sub-node whose node space intersects with the element space of the scene element to be added; the target sub-node satisfies the intersection condition, which means that there are at least two target sub-nodes, each corresponding to a node space, which intersects with the element space of the scene element to be added. Therefore, the number of target sub-nodes that meets the intersection condition can be that the number of target sub-nodes is greater than 1. On the contrary, the number of target sub-nodes that does not meet the intersection condition can be that the number of target sub-nodes is equal to 1.
[0181] When the initial node has child nodes, it is determined that the node type of the target node is not a leaf node type, and the computer device obtains the node space of each child node of the target node, and obtains the element space of the scene element to be added. For the node space of each child node, when the node space of the child node intersects with the element space of the scene element to be added, the child node is used as the target child node; the computer device counts the number of target child nodes, and when the number of target child nodes is equal to 1, it is determined that the number of target nodes does not meet the intersection condition, and this target child node is used as the initial node, that is, the initial node is updated, and the step of obtaining the node type of the initial node is returned; it can be understood that after returning to the step of obtaining the node type of the initial node, the node type of the initial node may be a leaf node type, or may not be a leaf node type.
[0182] Exemplarily, when the scene element e2 to be added is obtained by traversing the scene elements, the initial scene tree structure is shown in Figure 10, and the root node d1 of the initial scene tree structure is used as the initial node. The initial node d1 has child nodes, so the node type of the initial node d1 is not a leaf node type, and the child nodes of the initial node d1 are obtained, namely: child node d2, child node d3, child node d4 and child node d4. For each child node of the initial node d1, it is determined whether the node space of the child node intersects with the element space of the scene element e2 to be added. If so, the child node is used as the target child node. In this example, the target child node includes the child node d2; the computer device counts the number of target child nodes to be 1, determines that the number of target child nodes does not meet the intersection condition, and uses the child node d2 as the initial node, and continues to obtain the node type of the initial node d2; in this example, the node type of the initial node d2 is a leaf node type, and the computer device determines whether the scene element e2 to be added meets the element addition condition.
[0183] When the scene element e2 to be added meets the element adding condition, the scene element e2 to be added is added to the initial node d2; and the process returns to the step of traversing the scene elements to obtain the scene element to be added.
[0184] When the scene element e2 to be added does not meet the element adding conditions, the initial node d2 is split, and the child node of the scene element to be added is obtained from the child node obtained by the split, and the obtained child node is used as the initial node. In this way, the initial node for adding the scene element e2 to be added can be obtained by layer-by-layer node splitting, and then the step of traversing the scene elements to obtain the scene element to be added is returned.
[0185] After adding the initial node of the scene element e2 to be added, traversing to obtain the scene element e3 to be added, processing the scene element e3 to be added according to the above process, and adding the scene element e3 to be added to the initial node.
[0186] In the above embodiment, when the node type is not a leaf node type, and the number of target child nodes of the scene elements to be added in the child nodes of the initial node does not meet the intersection condition, the target child node is used as the initial node, and the step of obtaining the node type of the initial node is returned to execute. The nodes for adding the scene elements to be added can be determined layer by layer in the initial scene tree structure, thereby realizing a fine division of the scene elements into the subspace of the virtual scene. When the baking element set for lighting baking is subsequently obtained based on the scene tree structure, the situation of repeatedly dividing the same scene element into different baking element sets can be avoided, thereby reducing repeated baking tasks in lighting baking, saving hardware resources, and improving the efficiency of lighting baking and the stability of lighting baking.
[0187] In some embodiments, when the node type is not a leaf node type, after obtaining the target child node corresponding to the scene element to be added from each child node of the target node, the method further includes: when the number of target child nodes meets the intersection condition, adding the scene element to be added to the initial node to update the initial scene tree structure, and returning to the step of traversing the scene elements to obtain the scene element to be added. This avoids the scene element to be added from being repeatedly added to different child nodes, thereby reducing repeated baking tasks in light baking, saving hardware resources, and improving light baking efficiency.
[0188] The number of target child nodes satisfies the intersection condition, which means that the number of target child nodes is greater than 1.
[0189] In some embodiments, when the initial node has child nodes, it is determined that the node type of the target node is not a leaf node type, the computer device obtains the node space of each child node of the target node, and obtains the element space of the scene element to be added. For the node space of each child node, when the node space of the child node intersects with the element space of the scene element to be added, the child node is used as the target child node; the computer device counts the number of target child nodes, and when the number of target child nodes is greater than 1, it is determined that the number of target nodes meets the intersection condition, the scene element to be added is added to the initial node, and the step of traversing the scene elements to obtain the scene element to be added is returned to execute, so as to perform the above process on the next scene element to be added, and add the next scene element to be added to the node of the initial scene tree structure.
[0190] It should be noted that when the number of child nodes of the initial node whose node space intersects with the element space of the scene element to be added is greater than 1, if the scene element to be added is added to the child node of the initial node, the scene element to be added will be repeatedly added to the child node, and then there will be repeated scene elements in the baking element set, resulting in repeated baking tasks in lighting baking.
[0191] Exemplarily, when the scene element e2 to be added is obtained by traversing the scene elements, the initial scene tree structure is shown as t3 in Figure 10, and the root node d1 of the initial scene tree structure is used as the initial node. The initial node d1 has child nodes, so the node type of the initial node d1 is not a leaf node type, and the child nodes of the initial node d1 are obtained, which are: child node d2, child node d3, child node d4 and child node d4. For each child node of the initial node d1, it is determined whether the node space of the child node intersects with the element space of the scene element e2 to be added. If so, the child node is used as the target child node. In this example, the target child node includes child node d2 and child node d3; the computer device counts the number of target child nodes to be 2, determines that the number of target child nodes meets the intersection condition, adds the scene element e2 to be added to the initial node d2, and returns to execute the step of traversing the scene elements to obtain the scene element to be added.
[0192] After adding the initial node of the scene element e2 to be added, traversing to obtain the scene element e3 to be added, processing the scene element e3 to be added according to the above process, and adding the scene element e3 to be added to the initial node.
[0193] In the above embodiment, when the number of target child nodes meets the intersection condition, the scene elements to be added are added to the initial node, which avoids the scene elements to be added being repeatedly added to different child nodes, thereby reducing the repeated baking tasks in light baking, saving hardware resources, and improving light baking efficiency.
[0194] In some embodiments, after obtaining the lighting information of the baked element set, the method further includes: obtaining the lighting information of all scene elements in a preset sub-scene of the virtual scene based on the lighting information of the baked element set, and saving the lighting information of all scene elements in the preset sub-scene. In this way, by performing lighting baking while saving lighting information, parallel processing of lighting information is achieved, thereby improving the efficiency of saving lighting information for the virtual scene. In addition, the lighting information saved in the local memory is saved according to the preset sub-scene in the virtual scene element. When the lighting information of the preset sub-scene is needed, the lighting information of the preset sub-scene can be quickly obtained from the local memory.
[0195] Among them, the number of preset sub-scenes can be multiple, each preset sub-scene is a partial scene in the virtual scene, and the virtual scene includes multiple preset sub-scenes; in actual applications, the game includes multiple levels, and the virtual scene of the game includes multiple preset sub-scenes corresponding to each level; or, the game includes multiple sub-maps, and the virtual scene of the game includes multiple preset sub-scenes corresponding to each sub-map.
[0196] The lighting information of all scene elements in the preset sub-scene includes the lighting information corresponding to the light mapping task in the preset sub-scene and the lighting information corresponding to the light probe task in the preset sub-scene; the lighting information corresponding to the light mapping task in the preset sub-scene is the lighting information of the surface of the scene object associated with the light mapping task in the preset sub-scene, and the lighting information corresponding to the light probe task in the preset sub-scene is the lighting information of the spatial position of the light probe task in the preset sub-scene.
[0197] In some embodiments, the computer device performs lighting baking on each baking element set in turn, and obtains the lighting information of each baking element set in turn; each time the lighting information of a baking element set is obtained, the lighting information belonging to each preset sub-scene is obtained from the lighting information of the baking element set, and after each complete lighting information of a preset sub-scene is obtained, the complete lighting information of the preset sub-scene is saved to the local memory, so that when the lighting information of the scene element is needed later, the lighting information can be obtained from the memory; after each lighting information of a preset sub-scene is saved, the memory resources required to store the lighting information of the preset sub-scene can be released in time, so that when saving the lighting information of other preset sub-scenes, there is sufficient available memory space, avoiding insufficient memory when saving the lighting information of the entire virtual scene.
[0198] For example, after obtaining the lighting information of the baked element set B1, the first part of the lighting information of the preset sub-scene L1 and the first part of the lighting information of the preset sub-scene L2 can be obtained from the lighting information of the baked element set B1; after obtaining the lighting information of the baked element set B2, the second part of the lighting information of the preset sub-scene L1 and the first part of the lighting information of the preset sub-scene L3 can be obtained from the lighting information of the baked element set B2; based on the first part of the lighting information of the preset sub-scene L1 and the second part of the lighting information of the preset sub-scene L1, the complete lighting information of the preset sub-scene L1 is obtained. It can be understood that the complete lighting information of the preset sub-scene L1 is obtained from the lighting information of the baked element set B1 and the baked element set B2; the computer device saves the complete lighting information of the preset sub-scene L1.
[0199] In the above embodiment, lighting baking is performed while lighting information is saved, which realizes parallel processing of lighting information and improves the efficiency of saving lighting information of the virtual scene. In addition, the lighting information saved in the local memory is saved according to the preset sub-scene in the virtual scene element. When the lighting information of the preset sub-scene is needed, the lighting information of the preset sub-scene can be quickly obtained from the local memory.
[0200] In some embodiments, the number of preset sub-scenes is at least two; based on the lighting information of the baked element set, the lighting information of all scene elements in the preset sub-scenes of the virtual scene is obtained, and the lighting information of all scene elements in the preset sub-scenes is saved, including: obtaining the sub-scene identifier of each scene element in the baked element set; in the lighting information of each scene element in the baked element set, obtaining the lighting information of the scene elements in each preset sub-scene based on each sub-scene identifier; when the lighting information of all scene elements in any preset sub-scene is obtained, the lighting information of all scene elements in any preset sub-scene is saved. Saving the lighting information of the preset sub-scene while performing lighting baking avoids the problem of insufficient memory when saving the lighting information of the entire virtual scene, compared to saving the lighting information of the entire virtual scene after obtaining the lighting information of the entire virtual scene, and solves the problem of hardware resource limitations in lighting baking for the virtual scene.
[0201] Among them, the sub-scene identifier is used to reflect the preset sub-scene to which the scene element belongs; for example, when the scene element e1 belongs to the preset sub-scene level1, the sub-scene identifier of the scene element e1 can be level1; when the scene element e2 belongs to the preset sub-scene level2, the sub-scene identifier of the scene element e2 can be level2; it should be noted that level can represent a level in the game, and the preset sub-scene level1 can be the sub-scene of the first level in the virtual scene of the game.
[0202] The computer device may pre-assign a subscene identifier to each scene element and generate a lighting information set for each preset subscene. The lighting information set for each preset subscene includes the subscene identifiers of the scene elements in the preset subscene. It should be noted that the subscene identifiers of the scene elements in the lighting information set for the preset subscene are specifically the subscene identifiers of the lightmap task and the subscene identifiers of the light probe task in the preset subscene.
[0203] The lighting information of the baked element set includes the lighting information of the light map task and the lighting information of the light probe task. The computer device obtains the subscene identifier of the light map task and the subscene identifier of the light probe task, and divides the lighting information of the light map task and the lighting information of the light probe task into the lighting information set of each preset subscene according to the subscene identifier in the lighting information set of each preset subscene. When the lighting information set of a preset subscene includes the lighting information of all light map tasks and light probe tasks in the preset subscene, the lighting information set of the preset subscene is saved to the memory.
[0204] In some embodiments, after the lighting information of all scene elements in any preset sub-scene is saved, the memory resources used to store the lighting information of the preset sub-scene are released; wherein, the releasing of the memory resources used to store the lighting information of the preset sub-scene can be that the computer device transmits the lighting information of the preset sub-scene to a storage server or an external storage device, so that the computer device has sufficient memory resources to save the lighting information of other preset sub-scenes, avoiding the situation of insufficient memory when saving the lighting information, and solving the problem of lighting baking of virtual scenes being limited by hardware resources.
[0205] For example, in the related art, usually after all lighting baking tasks of the virtual scene are completed, all lighting information of the obtained virtual scene is exported to the local memory. However, in the embodiment of the present application, as shown in FIG11 , the number of baking element sets determined according to the scene tree structure can be multiple: baking element set H1, baking element set H2, ..., baking element set Hn; multiple baking element sets are sequentially light-baked, and each time the lighting baking of a baking element set is completed, the lighting information of the baking element set is divided into the lighting information sets of each preset sub-scene. In the process of sequentially baking the lighting of each baking element set, the lighting information of the baking element set can be gradually divided into the lighting information sets of each preset sub-scene. Obtain the complete lighting information of each preset sub-scene. Whenever the complete lighting information of a preset sub-scene is obtained, first save the complete lighting information of the preset sub-scene and release the memory resources used to store the complete lighting information of the preset sub-scene. For example, when all the lighting information of the preset sub-scene level 1 is obtained, save all the lighting information of the preset sub-scene level 1 to the local memory and release the memory resources used to store the lighting information of the preset sub-scene level 1. When all the lighting information of the preset sub-scene level 2 is obtained, save all the lighting information of the preset sub-scene level 2 to the local memory.
[0206] In the above embodiment, the lighting information of the preset sub-scene can be saved while performing lighting baking. Compared with saving the lighting information of the entire virtual scene after obtaining the lighting information of the entire virtual scene, it avoids the situation of insufficient memory when saving the lighting information of the entire virtual scene, and solves the problem of hardware resource limitations for lighting baking of the virtual scene.
[0207] In some embodiments, as shown in FIG12 , the lighting baking method for a virtual scene can be applied to a scene of performing lighting baking on a virtual scene of an open world game.
[0208] Obtain each scene element in the virtual scene of the open world game, including scene objects, lighting baking tasks and lighting probe tasks in the virtual scene, divide the virtual scene of the open world game according to the scene elements, and obtain a scene tree structure with a quadtree structure. The scene tree structure includes multiple spatial nodes, and some or all of the multiple spatial nodes include at least one scene element. The scene tree structure can be referred to in Figure 4.
[0209] The target node d2 is obtained by traversing the spatial nodes of the scene tree structure. When it is determined that the target node d2 meets the baking conditions based on the number of elements in the target node d2 and the number of elements in the descendant nodes of the target node d2, the baking element set H1 is determined based on the scene elements of the target node d2, the scene elements of the ancestor node of the target node d2, and the scene elements of the descendant nodes. In this example, the ancestor node of the target node d2 is the node d1, and the descendant nodes of the target node d2 are the node d6, the node d7, the node d8, and the node d9. The baking element set H1 includes: scene element e1, scene element e2, scene element e3, and scene element e4.
[0210] In the same way, it can be determined that the baked element set H2 of the target node d3 includes: scene element e5, scene element e6, scene element e7 and scene element e8.
[0211] Perform lighting baking on the baked element set H1 and the baked element set H2 in sequence. After obtaining the lighting information of the baked element set H1, obtain the lighting information of the scene elements in the preset sub-scene level 1 and the lighting information of the scene elements in the preset sub-scene level 2 from the lighting information of the baked element set H1.
[0212] In this example, the scene elements in the preset sub-scene level 1 include scene element e1 and scene element e2; the scene elements in the preset sub-scene level 2 include scene element e3, scene element e4, scene element e5, scene element e6, scene element e7, and scene element e8.
[0213] According to the lighting information of the baked element set H1, all lighting information of the preset sub-scene level 1 can be obtained, the lighting information of the preset sub-scene level 1 can be saved, and the memory resources used to store the lighting information of the preset sub-scene level 1 can be released.
[0214] According to the lighting information of the baked element set H1, the lighting information of scene elements e3 and scene elements e4 in the preset sub-scene level2 can be obtained. After completing the lighting baking of the baked element set H2, the lighting information of the baked element set H2 is obtained, and the lighting information of scene elements e5, scene elements e6, scene elements e7 and scene elements e8 in the preset sub-scene level2 can be obtained, and then all the lighting information of the preset sub-scene level2 is obtained, and the lighting information of the preset sub-scene level2 is saved.
[0215] In actual applications, a virtual scene of an open game is designed with 520,000 light mapping tasks and 2.7 million scene objects. The effect of directly performing light baking on the entire virtual scene and using the method provided in the embodiment of the present application for light baking is compared as shown in Figure 13. In each dotted box in Figure 13, the left side shows the situation of performing light baking on all scene elements of the virtual scene, and the right side shows the situation of performing light baking using the method provided in the embodiment of the present application. Obviously, the method provided in the embodiment of the present application can greatly reduce the video memory occupancy and the memory occupancy. The method provided in the embodiment of the present application can be applied to low-end graphics cards (graphics cards with lower processing power) based on the video memory and memory occupancy of the method provided in the embodiment of the present application. In addition, the method provided in the embodiment of the present application can also greatly reduce the time spent on light baking and saving lighting information, thereby improving the efficiency of light baking.
[0216] In some embodiments, as shown in FIG14 , a lighting baking method for a virtual scene includes:
[0217] Step 1401: Acquire scene elements of a virtual scene and generate an initial scene tree structure;
[0218] Step 1402: traverse the scene elements to obtain the scene elements to be added, and use the root node in the initial scene tree structure as the initial node;
[0219] Step 1403, obtaining the node type of the initial node;
[0220] Step 1404A1: When the node type is a leaf node type, obtain the node space of the target node, the element type and element space of the scene element to be added; obtain a preset space size interval; when the size of the node space does not fall within the preset control size interval, determine that the node space meets the first space division condition; obtain a third preset percentage; when the proportion of the element space occupying the node space does not reach the third preset percentage, determine that the element space and the node space meet the second space division condition; when the element type is an object type and the node space meets the first space division condition, determine that the scene element to be added does not meet the first element addition condition; or when the element type is a lighting task type and the element space and the node space meet the second space division condition, determine that the scene element to be added does not meet the second element addition condition; split the initial node to obtain child nodes to update the initial scene tree structure, select the child node corresponding to the scene element to be added from the child nodes obtained by splitting as the initial node, and return to step 1403 for execution;
[0221] Step 1404A2: If the node type is a leaf node type, obtain the node space of the target node, the element type, and the element space of the scene element to be added; if the element type is an object type and the node space does not meet the first space division condition, determine that the scene element to be added meets the first element addition condition; or, if the element type is a lighting task type and the element space and the node space do not meet the second space division condition, determine that the scene element to be added meets the second element addition condition; add the scene element to be added to the initial node to update the initial scene tree structure, and return to step 1402.
[0222] Step 1404B1: If the node type is not a leaf node type, obtain the target child node corresponding to the scene element to be added from each child node of the target node; if the number of target child nodes does not meet the intersection condition, use the target child node as the initial node obtained by traversal, and return to step 1403;
[0223] Step 1404B2: When the number of target child nodes meets the intersection condition, the scene element to be added is added to the initial node to update the initial scene tree structure, and the process returns to step 1402.
[0224] Step 1405: After traversing the scene elements, the updated initial scene tree structure is used as the scene tree structure. Traverse the spatial nodes of the scene tree structure according to the hierarchical relationship to the target node. The number of elements in the target node and the number of elements in its descendant nodes are obtained. The total number of elements in the target node and the number of elements in its descendant nodes are summed to obtain the total number of elements. If the total number of elements falls within a preset number range, the target node is determined to meet the baking conditions.
[0225] Step 1406: traverse the scene elements of the ancestor node of the target node to obtain the target scene element; obtain the position information of the center point of the target scene element in the virtual scene;
[0226] In step 1407A, when the location information belongs to the node space of the target node, the target scene element is used as the scene element to be baked; and a baking element set is determined based on the scene element to be baked, the scene element of the target node, and the scene elements of the descendant nodes.
[0227] Step 1407B: When no scene elements to be baked are selected from the scene elements of the ancestor node according to the position information, a baking element set is determined based on the scene elements of the target node and the scene elements of the descendant nodes.
[0228] Step 1408: Perform lighting baking on the baked element set to obtain lighting information of the baked element set; obtain the sub-scene identifier of each scene element in the baked element set; in the lighting information of each scene element in the baked element set, obtain the lighting information of the scene elements in each preset sub-scene based on each sub-scene identifier; when the lighting information of all scene elements in any preset sub-scene is obtained, save the lighting information of all scene elements in any preset sub-scene.
[0229] In the above-mentioned lighting baking method for a virtual scene, scene elements of the virtual scene are divided to obtain a scene tree structure, the target node is traversed in the scene tree structure, and when the number of elements of the target node and the descendant nodes of the target node meets the baking conditions, the baking element set is determined according to the baking elements respectively included in the target node, the ancestor node of the target node and the descendant nodes, so that the number of scene elements in the baking element set is small, and lighting baking is performed on the baking element set, so that the number of scene elements participating in one lighting baking is small, which can reduce the video memory occupancy rate during the lighting baking process and improve the stability of lighting baking.
[0230] It should be understood that, although the various steps in the flowcharts involved in the various embodiments described above are displayed in sequence according to the instructions of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowcharts involved in the various embodiments described above can include multiple steps or multiple stages, and these steps or stages are not necessarily executed and completed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of steps or stages in other steps.
[0231] Based on the same inventive concept, embodiments of the present application also provide a virtual scene lighting baking device for implementing the aforementioned virtual scene lighting baking method. The solution provided by this device is similar to the solution described in the aforementioned method. Therefore, the specific limitations of the following embodiments of the virtual scene lighting baking device can be found in the aforementioned limitations of the virtual scene lighting baking method and will not be further elaborated here.
[0232] In some embodiments, as shown in FIG15 , a lighting baking device for a virtual scene is provided, including: a scene element acquisition module 1501, a scene division module 1502, a node traversal module 1503, a baking element set acquisition module 1504, and a lighting baking module 1505, wherein:
[0233] A scene element acquisition module 1501 is used to acquire scene elements of a virtual scene;
[0234] A scene division module 1502 is used to divide the virtual scene according to scene elements to obtain a scene tree structure;
[0235] The node traversal module 1503 is used to traverse the spatial nodes of the scene tree structure to the target node according to the structural hierarchical relationship;
[0236] A baked element set acquisition module 1504 is configured to determine a baked element set based on scene elements of the target node, scene elements of its ancestor nodes, and scene elements of its descendant nodes when the target node is determined to meet baking conditions based on the number of elements of the target node and the number of elements of its descendant nodes.
[0237] The lighting baking module 1505 is used to perform lighting baking on the baking element set to obtain lighting information of the baking element set.
[0238] In the above-mentioned lighting baking device for the virtual scene, the scene elements of the virtual scene are divided to obtain a scene tree structure, the target node is traversed in the scene tree structure, and when the number of elements of the target node and the descendant nodes of the target node meets the baking conditions, the baking element set is determined according to the baking elements respectively included in the target node, the ancestor node of the target node and the descendant nodes, so that the number of scene elements in the baking element set is small, and the baking element set is light-baked, so that the number of scene elements participating in one lighting baking is small, which can reduce the video memory occupancy rate during the lighting baking process and improve the stability of the lighting baking.
[0239] In some embodiments, the lighting baking device for a virtual scene further includes: a baking condition determination module, configured to obtain the number of elements of a target node and the number of elements of descendant nodes of the target node; summing the number of elements of the target node and the number of elements of the descendant nodes to obtain a total number of elements; and determining that the target node meets the baking conditions when the total number of elements falls within a preset number range.
[0240] In some embodiments, the baking element set acquisition module 1504 is further used to obtain the position information corresponding to the scene elements of the ancestor node of the target node; select the scene elements to be baked from the scene elements of the ancestor node according to the position information; and determine the baking element set according to the scene elements to be baked, the scene elements of the target node, and the scene elements of the descendant nodes.
[0241] In some embodiments, the baking element set acquisition module 1504 is further used to traverse the scene elements of the ancestor node of the target node to obtain the target scene element; obtain the position information of the center point of the target scene element in the virtual scene; when the position information belongs to the node space of the target node, use the target scene element as the scene element to be baked.
[0242] In some embodiments, the baked element set acquisition module 1504 is further configured to acquire position information corresponding to a scene element of an ancestor node of the target node;
[0243] When no scene elements to be baked are selected from the scene elements of the ancestor node according to the position information, a baking element set is determined according to the scene elements of the target node and the scene elements of the descendant nodes.
[0244] In some embodiments, the scene division module 1502 is also used to generate an initial scene tree structure; traverse the scene elements to obtain the scene elements to be added, and use the root node in the initial scene tree structure as the initial node; obtain the node type of the initial node; in the case where the node type is a leaf node type, when the scene element to be added does not meet the element adding condition, the initial node is split to obtain child nodes to update the initial scene tree structure, and the child node corresponding to the scene element to be added is selected from the child nodes obtained by the split as the initial node, and the step of obtaining the node type of the initial node is returned; when the scene element to be added meets the element adding condition, the scene element to be added is added to the initial node to update the initial scene tree structure, and the step of traversing the scene elements to obtain the scene element to be added is returned; after completing the traversal of the scene elements, the updated initial scene tree structure is used as the scene tree structure.
[0245] In some embodiments, the element adding condition includes a first element adding condition; the scene division module 1502 is also used to obtain the node space of the target node, the element type and element space of the scene element to be added when the node type is a leaf node type; when the element type is an object type and the node space satisfies the first space division condition, it is determined that the scene element to be added does not satisfy the first element adding condition.
[0246] In some embodiments, the element adding condition includes a first element adding condition or a second element adding condition; the scene division module 1502 is also used to obtain the node space of the target node, the element type and element space of the scene element to be added when the node type is a leaf node type; when the element type is a lighting task type, and the element space and the node space meet the second space division condition, it is determined that the scene element to be added does not meet the second element adding condition.
[0247] In some embodiments, the element adding condition includes a first element adding condition; the scene division module 1502 is also used to obtain the node space of the target node, the element type and element space of the scene element to be added when the node type is a leaf node type; when the element type is an object type and the node space does not meet the first space division condition, it is determined that the scene element to be added meets the first element adding condition.
[0248] In some embodiments, the element adding condition includes a second element adding condition; the scene division module 1502 is also used to obtain the node space of the target node, the element type and element space of the scene element to be added when the node type is a leaf node type; when the element type is a lighting task type, and the element space and the node space do not meet the second space division condition, it is determined that the scene element to be added meets the second element adding condition.
[0249] In some embodiments, the scene division module 1502 is further configured to obtain a preset space size interval; and when the size of the node space does not belong to the preset control size interval, determine that the node space meets the first space division condition.
[0250] In some embodiments, the scene division module 1502 is further configured to obtain a third preset percentage; and when the proportion of the element space occupying the node space does not reach the third preset percentage, determine that the element space and the node space meet the second space division condition.
[0251] In some embodiments, the scene division module 1502 is also used to obtain the target child node corresponding to the scene element to be added from each child node of the target node when the node type is not a leaf node type; when the number of target child nodes does not meet the intersection condition, the target child node is used as the initial node obtained by traversal, and the step of obtaining the node type of the initial node is returned.
[0252] In some embodiments, the scene division module 1502 is also used to add the scene element to be added to the initial node when the number of target child nodes meets the intersection condition to update the initial scene tree structure, and return to execute the step of traversing the scene elements to obtain the scene element to be added.
[0253] In some embodiments, the lighting baking device for a virtual scene further includes: a lighting information saving module, which is used to obtain the lighting information of all scene elements in a preset sub-scene of the virtual scene based on the lighting information of the baking element set, and save the lighting information of all scene elements in the preset sub-scene.
[0254] In some embodiments, the number of preset sub-scenes is at least two; the lighting information saving module is further used to obtain the sub-scene identifier of each scene element in the baked element set; in the lighting information of each scene element in the baked element set, the lighting information of the scene elements in each preset sub-scene is obtained according to each sub-scene identifier; when the lighting information of all scene elements in any preset sub-scene is obtained, the lighting information of all scene elements in any preset sub-scene is saved.
[0255] Each module in the aforementioned virtual scene lighting baking apparatus can be implemented in whole or in part through software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor within a computer device in the form of hardware, or can be stored in a computer device's memory in the form of software, allowing the processor to call and execute the corresponding operations of each module.
[0256] In some embodiments, a computer device is provided. The computer device can be either a server or a terminal. The server is used for illustration, and its internal structure diagram can be shown in FIG16 . The computer device includes a processor, memory, an input / output (I / O) interface, and a communication interface. The processor, memory, and I / O interface are connected via a system bus, and the communication interface is connected to the system bus via the I / O interface. The processor of the computer device provides computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operating system and computer program in the non-volatile storage medium. The database of the computer device stores data related to a lighting baking method for a virtual scene. The I / O interface of the computer device is used to exchange information between the processor and external devices. The communication interface of the computer device is used to communicate with an external terminal via a network connection. When executed by the processor, the computer program implements a lighting baking method for a virtual scene.
[0257] Those skilled in the art will understand that the structure shown in Figure 16 is merely a block diagram of a portion of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0258] In some embodiments, a computer device is provided, including a memory and a processor. The memory stores a computer program, and the processor implements the steps of the above-mentioned virtual scene lighting baking method when executing the computer program.
[0259] In some embodiments, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned virtual scene lighting baking method are implemented.
[0260] In some embodiments, a computer program product is provided, including a computer program, which implements the steps of the above-mentioned virtual scene lighting baking method when executed by a processor.
[0261] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0262] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, database or other media used in the embodiments provided in this application may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory may include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in the various embodiments provided herein may include at least one of a relational database and a non-relational database. Non-relational databases may include, but are not limited to, distributed databases based on blockchains. The processor involved in the various embodiments provided herein may be, but are not limited to, a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic unit, a data processing logic unit based on quantum computing, and the like.
[0263] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0264] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present application. It should be noted that a person of ordinary skill in the art may make various modifications and improvements without departing from the spirit of the present application, and these modifications and improvements fall within the scope of protection of the present application. Therefore, the scope of protection of the present application shall be determined by the appended claims.
Claims
1. A method for baking lighting in a virtual scene, wherein, Executed by a computer device, the method includes: Obtain the scene elements of the virtual scene; Perform scene division on the virtual scene according to the scene elements to obtain a scene tree structure; Traverse to a target node in the spatial nodes of the scene tree structure according to the structural hierarchy relationship; When it is determined that the target node meets the baking condition based on the number of elements of the target node and the number of elements of the descendant nodes of the target node, determine a baking element set according to the scene elements of the target node, the scene elements of the ancestor nodes of the target node, and the scene elements of the descendant nodes; and Perform light baking on the baking element set to obtain the light information of the baking element set.
2. The method according to claim 1, wherein, After traversing to the target node in the spatial nodes of the scene tree structure according to the structural hierarchy relationship, it further includes: Obtain the number of elements of the target node and the number of elements of the descendant nodes of the target node; Perform a summation process on the number of elements of the target node and the number of elements of the descendant nodes to obtain the total number of elements; and When the total number of elements belongs to a preset number range, determine that the target node meets the baking condition.
3. The method according to claim 1 or 2, wherein Determining the baking element set according to the scene elements of the target node, the scene elements of the ancestor nodes of the target node, and the scene elements of the descendant nodes includes: Obtain the position information corresponding to the scene elements of the ancestor nodes of the target node; Select the scene elements to be baked from the scene elements of the ancestor nodes according to the position information; and Determine the baking element set according to the scene elements to be baked, the scene elements of the target node, and the scene elements of the descendant nodes.
4. The method according to claim 3, wherein, Obtaining the position information corresponding to the scene elements of the ancestor nodes of the target node includes: Traverse in the scene elements of the ancestor nodes of the target node to obtain the target scene elements; Obtain the position information of the center point of the target scene element in the virtual scene; Selecting the scene elements to be baked from the scene elements of the ancestor nodes according to the position information includes: When the position information belongs to the node space of the target node, use the target scene element as the scene element to be baked.
5. The method according to any one of claims 1 to 4, wherein The method further includes: Obtain the position information corresponding to the scene elements of the ancestor nodes of the target node; Determining the baking element set according to the scene elements of the target node, the scene elements of the ancestor nodes of the target node, and the scene elements of the descendant nodes includes: When no scene elements to be baked are selected from the scene elements of the ancestor nodes according to the position information, determine the baking element set according to the scene elements of the target node and the scene elements of the descendant nodes.
6. The method according to any one of claims 1 to 5, wherein Performing scene division on the virtual scene according to the scene elements to obtain a scene tree structure includes: Generate an initial scene tree structure; Traverse in the scene elements to obtain the scene elements to be added, and use the root node in the initial scene tree structure as the initial node; Obtain the node type of the initial node; When the node type is the leaf node type and the to-be-added scene element does not meet the element addition condition, the initial node is split into child nodes to update the initial scene tree structure. Among the split child nodes, the child node corresponding to the to-be-added scene element is selected as the initial node, and the step of obtaining the node type of the initial node is returned and executed. When the to-be-added scene element meets the element addition condition, the to-be-added scene element is added to the initial node to update the initial scene tree structure, and the step of traversing the scene elements to obtain the to-be-added scene element is returned and executed; and After completing the traversal of the scene elements, the updated initial scene tree structure is used as the scene tree structure. The element addition condition includes the first element addition condition; after obtaining the node type of the initial node, it further includes:
7. The method according to claim 6, wherein, When the node type is the leaf node type, obtain the node space of the target node, the element type and the element space of the to-be-added scene element; and When the element type is the object type and the node space meets the first space division condition, it is determined that the to-be-added scene element does not meet the first element addition condition. The element addition condition includes the second element addition condition; after obtaining the node type of the initial node, it further includes:
8. The method according to claim 6, wherein When the node type is the leaf node type, obtain the node space of the target node, the element type and the element space of the to-be-added scene element; and When the element type is the lighting task type and the element space and the node space meet the second space division condition, it is determined that the to-be-added scene element does not meet the second element addition condition. The element addition condition includes the first element addition condition; after obtaining the node type of the initial node, it further includes:
9. The method according to claim 6, wherein, When the node type is the leaf node type, obtain the node space of the target node, the element type and the element space of the to-be-added scene element; and When the element type is the object type and the node space does not meet the first space division condition, it is determined that the to-be-added scene element meets the first element addition condition. The element addition condition includes the second element addition condition; after obtaining the node type of the initial node, it further includes:
10. The method according to claim 6, wherein, When the node type is the leaf node type, obtain the node space of the target node, the element type and the element space of the to-be-added scene element; and When the element type is the lighting task type and the element space and the node space do not meet the second space division condition, it is determined that the to-be-added scene element meets the second element addition condition. After obtaining the node space of the target node, the element type and the element space of the to-be-added scene element, it further includes:
11. The method according to claim 7 or 9, wherein, Obtain the preset space size range; and When the size of the node space does not belong to the preset control size range, it is determined that the node space meets the first space division condition. 12. The method according to claim 8 or 10, wherein After obtaining the node space of the target node, the element type of the scene element to be added, and the element space, the following steps are further included: Obtaining a third preset percentage; and When the proportion of the element space occupying the node space does not reach the third preset percentage, it is determined that the element space and the node space satisfy the second space division condition.
13. The method according to claim 6, wherein After obtaining the node type of the initial node, the following steps are further included: In the case where the node type is not a leaf node type, obtaining a target child node corresponding to the scene element to be added among the child nodes of the target node; and When the number of the target child nodes does not meet the intersection condition, using the target child node as the initial node obtained by traversal, and returning to execute the step of obtaining the node type of the initial node.
14. The method according to claim 13, wherein, After obtaining the target child node corresponding to the scene element to be added among the child nodes of the target node in the case where the node type is not a leaf node type, the following steps are further included: When the number of the target child nodes meets the intersection condition, adding the scene element to be added to the initial node to update the initial scene tree structure, and returning to execute the step of traversing the scene elements to obtain the scene element to be added.
15. The method according to any one of claims 1 to 14, wherein After obtaining the lighting information of the baking element set, the following steps are further included: Obtaining the lighting information of all scene elements in the preset sub-scene of the virtual scene based on the lighting information of the baking element set, and saving the lighting information of all scene elements in the preset sub-scene.
16. The method according to claim 15, wherein, The number of the preset sub-scenes is at least two; The obtaining the lighting information of all scene elements in the preset sub-scene of the virtual scene based on the lighting information of the baking element set, and saving the lighting information of all scene elements in the preset sub-scene includes: Obtaining the sub-scene identifier of each scene element in the baking element set; Among the lighting information of each scene element in the baking element set, obtaining the lighting information of the scene elements in each preset sub-scene according to each sub-scene identifier; and When obtaining the lighting information of all scene elements in any one of the preset sub-scenes, saving the lighting information of all scene elements in any one of the preset sub-scenes.
17. An illumination baking device for a virtual scene, wherein, The device includes: A scene element obtaining module, configured to obtain the scene elements of the virtual scene; A scene division module, configured to divide the virtual scene according to the scene elements to obtain a scene tree structure; A node traversal module, configured to traverse to a target node in the space nodes of the scene tree structure according to the structural hierarchy relationship; A baking element set obtaining module, a baking element set determining module, configured to determine a baking element set according to the scene elements of the target node, the scene elements of the ancestor nodes of the target node, and the scene elements of the descendant nodes when it is determined that the target node meets the baking condition according to the number of elements of the target node and the number of elements of the descendant nodes of the target node; and A lighting baking module, configured to perform lighting baking on the baking element set to obtain the lighting information of the baking element set.
18. A computer device, comprising a memory and one or more processors, the memory storing computer-readable instructions, which when executed by the processors, cause the one or more processors to perform the steps of the method according to any one of claims 1 to 16.
19. One or more non-volatile readable storage media, having stored thereon computer-readable instructions, which when executed by the processors, cause the one or more processors to implement the steps of the method according to any one of claims 1 to 16.
20. A computer-readable instruction product, comprising computer-readable instructions, which when executed by a processor, implement the steps of the method according to any one of claims 1 to 16.
Citation Information
Patent Citations
Method and system for real-time rendering of large-scale scene of 3D game
CN106485776A
Method for removing models in game scene and device thereof, equipment and storage medium
CN113769382A
Dynamic resolving method, device and equipment of object and storage medium
CN115841500A
Rendering processing method and device, equipment and medium
CN116740255A