Light map generation method and device, storage medium and electronic equipment
Patent Information
- Application Number
- CN202510581866.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-30
- Publication Date
- 2026-10-30
AI Technical Summary
[0005]本发明实施例提供了一种光照贴图的生成方法和装置、存储介质及电子设备,以至少解决光照贴图的信息存储效率较低的技术问题
[0024]根据本发明实施例的又一方面,还提供了一种电子设备,包括存储器和处理器,上述存储器中存储有计算机程序,上述处理器被设置为通过上述计算机程序执行上述的光照贴图的生成方法或上述虚拟对象的渲染方法。
Smart Images

Figure CN123015797A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computers, and more specifically, to a method and apparatus for generating light maps, a storage medium, and an electronic device. Background Technology
[0002] In the rendering process of virtual scenes, pre-baked lightmaps are usually used to simulate lighting effects.
[0003] Because the lightmaps obtained using related technologies need to maintain a fixed aspect ratio, the proportion of the texture area remains constant when the number of objects to be baked remains unchanged. This results in a low effective texture area ratio, leading to low storage efficiency. In other words, existing lightmaps suffer from the technical problem of low information storage efficiency.
[0004] There is currently no effective solution to the above problems. Summary of the Invention
[0005] This invention provides a method and apparatus for generating light maps, a storage medium, and an electronic device to at least solve the technical problem of low information storage efficiency of light maps.
[0006] According to one aspect of the present invention, a method for generating a lightmap is provided, comprising: adding an auxiliary virtual object to a current virtual scene, wherein the virtual scene includes at least one target virtual object to be baked; performing an object unfolding operation on the auxiliary virtual object and the at least one target virtual object to obtain a first virtual plane, wherein the first virtual plane includes a target object region matching the at least one target virtual object and an auxiliary object region matching the auxiliary virtual object; if the auxiliary object region satisfies a target condition, determining the target object region in the first virtual plane as a second virtual plane; and determining a target lightmap based on the second virtual plane, wherein the target lightmap is used to render the at least one virtual object in the virtual scene.
[0007] According to another aspect of the present invention, a method for rendering a virtual object is provided, comprising: acquiring a target lighting map matching a target virtual scene, wherein the target lighting map is determined based on a second virtual plane, the second virtual plane being a target object region determined from a first virtual plane, the first virtual plane including the target object region and an auxiliary object region, the target object region matching at least one target virtual object, and the auxiliary object region matching an auxiliary virtual object; acquiring a set of position information matching the target lighting map, wherein the set of position information includes target offset information and target scaling information corresponding to at least one of the target virtual objects respectively; upon detecting a rendering instruction for a current virtual object among at least one of the target virtual objects, determining a current region bounding box from the target lighting map based on the target offset information and the target scaling information corresponding to the current virtual object; and rendering the current virtual object in the virtual scene based on the lighting information indicated by the current region bounding box.
[0008] According to another aspect of the present invention, a lightmap generation apparatus is also provided, comprising: an adding unit for adding auxiliary virtual objects in a current virtual scene, wherein the virtual scene includes at least one target virtual object to be baked; an unfolding unit for performing an object unfolding operation on the auxiliary virtual objects and at least one target virtual object to obtain a first virtual plane, wherein the first virtual plane includes a target object region matching at least one target virtual object and an auxiliary object region matching the auxiliary virtual object; a determining unit for determining the target object region in the first virtual plane as a second virtual plane if the auxiliary object region satisfies a target condition; and a baking unit for determining a target lightmap based on the second virtual plane, wherein the target lightmap is used to render at least one virtual object in the virtual scene.
[0009] Optionally, the above-mentioned adding unit includes: an acquisition module, configured to acquire the surface area parameters corresponding to at least one of the target virtual objects respectively; a determination module, configured to determine a reference surface area parameter based on the summation result of at least one of the surface area parameters; and an adding module, configured to add the auxiliary virtual object of the target shape to the current virtual scene based on the reference surface area parameter, wherein the current surface area parameter corresponding to the auxiliary virtual object is less than or equal to the reference surface area parameter.
[0010] Optionally, the acquisition module is used to: determine the surface area parameter based on the grid area of the plurality of object grids corresponding to the target virtual object; or determine the surface area parameter based on the bounding box area of the reference bounding box corresponding to the target virtual object, wherein the reference bounding box is used to accommodate the plurality of object grids corresponding to the target virtual object.
[0011] Optionally, the above-mentioned adding module is used to: obtain target size information, wherein the target size information is used to indicate the aspect ratio of the target object region, and the target object region is a first rectangular region in the first virtual plane; determine auxiliary size information of the auxiliary object region according to the texture size information corresponding to the first virtual plane and the target size information, wherein the auxiliary object region is a second rectangular region in the first virtual plane, and the target object region and the auxiliary object region form the first virtual plane with equal length and width; add the auxiliary virtual object of the target shape in the current virtual scene according to the reference surface area parameter, wherein the target shape of the auxiliary virtual object matches the auxiliary size information.
[0012] Optionally, the above-mentioned lightmap generation apparatus further includes: a condition matching unit, configured to determine that the auxiliary object region satisfies the target condition when the long side of the auxiliary object region matches the texture edge of the first virtual plane and the area ratio of the target object region to the auxiliary object region is greater than or equal to a target threshold, wherein the target threshold is determined based on the historical ratio corresponding to each of multiple historical object unfolding operations; to determine that the auxiliary object region does not satisfy the target condition when the long side of the auxiliary object region matches the texture edge of the first virtual plane and the area ratio of the target object region to the auxiliary object region is less than the target threshold; and to determine that the auxiliary object region does not satisfy the target condition when the long side of the auxiliary object region does not match the first virtual plane.
[0013] Optionally, the above-mentioned lightmap generation apparatus is further configured to: update the reference surface area parameter when the auxiliary object region does not meet the target conditions, wherein the updated reference surface area parameter is smaller than the original reference surface area parameter; add the auxiliary virtual object of the target shape in the current virtual scene according to the updated reference surface area parameter; and determine the target lightmap according to the updated auxiliary virtual object.
[0014] Optionally, the above-mentioned lightmap generation apparatus is further configured to: obtain a vertex set corresponding to at least one first virtual object in the first virtual scene; determine a mesh set corresponding to at least one first virtual object based on the at least one vertex set; determine mesh normals corresponding to multiple mesh objects in the at least one mesh set; and determine the current virtual scene based on the vertex set corresponding to at least one first virtual object, wherein the mesh set includes a mesh normal set of multiple mesh normals.
[0015] Optionally, the baking unit is configured to: perform a baking operation on the current virtual scene according to the first virtual plane to obtain a reference light map when the proportion of the number of valid pixels corresponding to the valid object area in the second virtual plane is greater than or equal to the target value; and determine the target light map according to the map area in the reference light map that matches the second virtual plane.
[0016] Optionally, the baking unit is further configured to: obtain the target pixel count; determine multiple candidate texture size information based on the target pixel threshold, wherein the number of illumination pixels included in the candidate light map corresponding to the candidate texture size information is less than or equal to the target pixel count; determine auxiliary size information corresponding to each of the multiple candidate light map sizes, wherein the auxiliary size information is used to indicate the aspect ratio of the auxiliary object region; determine the second virtual plane corresponding to each of the multiple candidate virtual scenes based on the multiple auxiliary size information, wherein the multiple candidate virtual scenes include the current virtual scene; and determine the target value based on the number of effective pixels corresponding to each of the multiple second virtual planes.
[0017] Optionally, the baking unit is further configured to: obtain the sum of the grid areas of the plurality of virtual grids included in the second virtual plane; determine a first area proportion of the plurality of virtual grids in the first virtual plane based on the sum of the grid areas; determine a second area proportion of the plurality of virtual grids in the second virtual plane based on the ratio between the first virtual area of the first virtual plane and the second virtual area of the second virtual plane; and determine the number of effective pixels corresponding to the second virtual plane based on the second area proportion and candidate texture size information matching the second virtual plane.
[0018] Optionally, the above-mentioned lightmap generation apparatus further includes: a position acquisition unit, configured to determine a bounding box corresponding to each of the at least one of the target virtual objects based on the object regions matched by each of the at least one of the target virtual objects in the second virtual plane, wherein the region range of the bounding box includes the object regions; and to determine target offset information and target scaling information corresponding to each of the at least one of the target virtual objects based on the at least one of the bounding boxes, wherein the target offset information and the target scaling information are used to determine lighting information matching the target virtual objects from the target lightmap.
[0019] Optionally, the position acquisition unit is configured to: determine the first coordinate of the first vertex of the bounding box in the second virtual plane as the target offset information; and determine the target scaling information based on the coordinate difference between the second coordinate of the second vertex of the bounding box in the second virtual plane and the first coordinate, wherein the first vertex and the second vertex are two vertices on the diagonal of the bounding box.
[0020] Optionally, the above-mentioned lightmap generation apparatus further includes: a filtering unit, configured to, when the target virtual scene includes multiple target virtual objects, determine multiple object combinations corresponding to the multiple target virtual objects, wherein the object combination includes at least one of the target virtual objects; determine the second virtual plane corresponding to each of the multiple object combinations; determine a target object combination from the multiple object combinations based on the comparison results between the multiple second virtual planes; and determine the target lightmap based on the target object combination.
[0021] According to another aspect of the present invention, a rendering apparatus for a virtual object is also provided, comprising: a first acquisition unit, configured to acquire a target lighting map matching a target virtual scene, wherein the target lighting map is determined based on a second virtual plane, the second virtual plane being a target object region determined from a first virtual plane, the first virtual plane including the target object region and an auxiliary object region, the target object region matching at least one target virtual object, and the auxiliary object region matching an auxiliary virtual object; a second acquisition unit, configured to acquire a set of position information matching the target lighting map, wherein the set of position information includes target offset information and target scaling information corresponding to at least one of the target virtual objects respectively; a determination unit, configured to, upon detecting a rendering instruction for a current virtual object among at least one of the target virtual objects, determine a current region bounding box from the target lighting map based on the target offset information and the target scaling information corresponding to the current virtual object; and a rendering unit, configured to render the current virtual object in the virtual scene based on the lighting information indicated by the current region bounding box.
[0022] According to another aspect of the present invention, a computer-readable storage medium is also provided, wherein a computer program is stored in the computer program, wherein the computer program is configured to execute the above-described method for generating lightmaps or the above-described method for rendering virtual objects at runtime.
[0023] According to another aspect of the embodiments of this application, a computer program product is provided, comprising a computer program / instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer program / instructions from the computer-readable storage medium and executes the computer program / instructions, causing the computer device to perform the lightmap generation method or the virtual object rendering method described above.
[0024] According to another aspect of the present invention, an electronic device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the above-described method for generating lightmaps or the above-described method for rendering virtual objects through the computer program.
[0025] In this embodiment of the invention, an auxiliary virtual object is introduced into the virtual scene and performs an object unfolding operation together with the target object. Through the above object unfolding operation, the first virtual plane will respectively contain the unfolded areas of the target object and the auxiliary object. By filtering the auxiliary object area according to conditions, the part with a suitable proportion to the target object area can be identified and filled with a specific shape into the first virtual plane.
[0026] Furthermore, during the baking process to determine the target lighting region, only the second virtual plane corresponding to the target object region is retained to determine the final lightmap. Correspondingly, the baking results for the auxiliary object regions are discarded. This method ensures that the final generated lightmap is rich in usable lighting information, effectively solving the problem of low lightmap storage efficiency. By optimizing the lightmap generation process, storage efficiency is improved while maintaining rendering quality. Attached Figure Description
[0027] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:
[0028] Figure 1 This is a schematic diagram of the hardware environment for an optional method of generating a lightmap according to an embodiment of the present invention;
[0029] Figure 2 This is a flowchart of an optional method for generating a lightmap according to an embodiment of the present invention;
[0030] Figure 3 This is a schematic diagram of an optional method for generating a lightmap according to an embodiment of the present invention;
[0031] Figure 4 This is a schematic diagram of another optional method for generating a lightmap according to an embodiment of the present invention;
[0032] Figure 5 This is a schematic diagram of another optional method for generating a lightmap according to an embodiment of the present invention;
[0033] Figure 6 This is a flowchart of another optional method for generating a lightmap according to an embodiment of the present invention;
[0034] Figure 7 This is a flowchart of another optional method for generating a lightmap according to an embodiment of the present invention;
[0035] Figure 8 This is a flowchart of another optional method for generating a lightmap according to an embodiment of the present invention;
[0036] Figure 9 This is a flowchart of another optional method for generating a lightmap according to an embodiment of the present invention;
[0037] Figure 10 This is a schematic diagram of another optional method for generating a lightmap according to an embodiment of the present invention;
[0038] Figure 11This is a schematic diagram of another optional method for generating a lightmap according to an embodiment of the present invention;
[0039] Figure 12 This is a flowchart of an optional virtual object rendering method according to an embodiment of the present invention;
[0040] Figure 13 This is a schematic diagram of an optional lightmap generation apparatus according to an embodiment of the present invention;
[0041] Figure 14 This is a schematic diagram of the structure of an optional electronic device according to an embodiment of the present invention;
[0042] Figure 15 This is a schematic diagram of the structure of an optional virtual object rendering device according to an embodiment of the present invention;
[0043] Figure 16 This is a schematic diagram of the structure of another optional electronic device according to an embodiment of the present invention. Detailed Implementation
[0044] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0045] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0046] The following explains the technical terms used in this application:
[0047] GI (Global Illumination): Global illumination is used to simulate the interaction between direct and indirect light sources in a scene to produce more realistic and natural lighting effects.
[0048] Baking: In computer graphics, baking is a pre-computation technique that pre-computes and stores complex lighting, texture, and other information in a texture map so that it can be used directly during real-time rendering, thereby improving rendering efficiency.
[0049] A lightmap is a texture that stores lighting information and is typically used for baking global illumination. Each pixel in a lightmap corresponds to a surface location in the scene and records the lighting information at that location. During real-time rendering, the lighting information of object surfaces in the scene is obtained by querying the lightmap.
[0050] UV2: This refers to the second set of UV coordinates on the object's surface, used to store the coordinate information of the lightmap. Compared to the first set of UV coordinates (UV1), which is mainly used for texture mapping, UV2 is typically used for global illumination rendering and other special effects calculations.
[0051] ScaleAndOffset: Typically used to describe scaling and offset operations on texture coordinates. It primarily adjusts how textures are displayed on a model surface. It consists of two parts: Scale and Offset.
[0052] Scale: Controls the scaling ratio of the texture in the U and V directions. By adjusting the scaling value, the texture can be repeated or stretched on the model surface.
[0053] Offset: Controls the amount of offset of the texture in the U and V directions. By adjusting the offset value, the texture can be moved on the surface of the model.
[0054] Lightmap UVs: In computer graphics and 3D modeling, lightmap UVs are texture coordinates used to store lighting information. They are typically used for static lighting calculations to improve rendering performance and visual quality.
[0055] Bounding box: In the embodiments of this application, the bounding box refers to a simple rectangular shape used to enclose the boundary of a two-dimensional graphic or image.
[0056] According to one aspect of the present invention, a method for generating a lightmap is provided, which may be applied, but is not limited to, methods for generating lightmaps. Figure 1The lightmap generation system in the hardware environment shown may include, but is not limited to, terminal device 102, network 104, server 106, database 108, and terminal device 110. Terminal device 110 runs a target client (taking a game application client capable of displaying a virtual scene as an example), and terminal device 102 runs a configuration client for configuring the rendering effects of objects in the virtual scene. Terminal devices 102 and 110 each include a human-computer interaction screen, a processor, and a memory. The human-computer interaction screen in terminal device 110 is used to display the virtual scene and also to provide a human-computer interaction interface to receive human-computer interaction operations for controlling a controlled virtual character in the virtual scene, which will complete game tasks set in the virtual scene. The processor is used to generate interaction instructions in response to the aforementioned human-computer interaction operations and send these instructions to the server. The memory is used to store relevant attribute data, such as object attribute information of the controlled virtual character and attribute information of the virtual items it holds. This attribute information may include, but is not limited to, information used to identify its identity and current location.
[0057] In addition, server 106 includes a processing engine, which is used to perform storage or retrieval operations on database 108. Specifically, the processing engine reads the virtual scene information of each virtual character and the operation information it performs from database 108; the processing engine is also used to read the lighting map information corresponding to the virtual scene from database 108.
[0058] Assumption Figure 1 The terminal device 110 runs a client for displaying a virtual scene, and the terminal device 102 runs a configuration client for configuring a target lighting map matched to the virtual scene. The specific process of this embodiment is as follows: Steps S102 to S108 are executed by the terminal device 102 to add an auxiliary virtual object to the current virtual scene, wherein the virtual scene includes at least one target virtual object to be baked; an object expansion operation is performed on the auxiliary virtual object and at least one target virtual object to obtain a first virtual plane, wherein the first virtual plane includes a target object region matching at least one target virtual object and an auxiliary object region matching the auxiliary virtual object; if the auxiliary object region meets the target conditions, the target object region in the first virtual plane is determined as a second virtual plane; a target lighting map is determined according to the second virtual plane, wherein the target lighting map is used to render at least one virtual object in the virtual scene; then, as in step S110, the terminal device 102 sends the target lighting map to the server 106 through the network 104.
[0059] Next, server 106 executes S112, forwarding the target lighting map to terminal device 110 via network 104; finally, during the operation of the game application on terminal device 110, S114 is executed to render the target virtual object based on the target lighting map.
[0060] Optionally, in this embodiment, the terminal device 110 can be a terminal device configured with a target client, which may include, but is not limited to, at least one of the following: mobile phone (such as Android phone, iOS phone, etc.), laptop computer, tablet computer, PDA, MID (Mobile Internet Devices), PAD, desktop computer, smart TV, etc. The target client can be a video client, instant messaging client, browser client, educational client, or other client that supports providing shooting game tasks. The network may include, but is not limited to, wired network and wireless network, wherein the wired network includes: local area network, metropolitan area network, and wide area network, and the wireless network includes: Bluetooth, WIFI, and other networks that enable wireless communication. The server may be a single server, a server cluster composed of multiple servers, or a cloud server. The above is only an example, and no limitation is made in this embodiment.
[0061] Optionally, in this embodiment, the above-described method for generating lightmaps can be applied, but is not limited to, to game-type terminal applications (APPs) that complete predetermined social game tasks in a virtual scene, such as virtual combat game applications in Multiplayer Online Battle Arena (MOBA) applications. The aforementioned social game tasks can be, but are not limited to, game tasks completed by the current player through virtual social interaction between virtual characters in the generated virtual scene and virtual characters controlled by other players via human-computer interaction lightmap generation. The above-described method for generating lightmaps can also be applied to large-scale multiplayer online role-playing game (MMORPG) terminal applications, where the current player can complete social game tasks from the first-person perspective of a virtual character through role-playing, for example, completing game tasks together with other virtual characters. These social game tasks can, but are not limited to, run as plugins or mini-programs within the application (such as a non-standalone game APP), or run within the application (such as a standalone game APP) in a game engine. The types of game applications mentioned above may include, but are not limited to, at least one of the following: two-dimensional (2D) game applications, three-dimensional (3D) game applications, virtual reality (VR) game applications, augmented reality (AR) game applications, and mixed reality (MR) game applications. This is merely an example, and this embodiment does not impose any limitations on it.
[0062] In this embodiment of the invention, an auxiliary virtual object is introduced into the virtual scene and performs an object unfolding operation together with the target object. Through the above object unfolding operation, the first virtual plane will respectively contain the unfolded areas of the target object and the auxiliary object. By filtering the auxiliary object area according to conditions, the part with a suitable proportion to the target object area can be identified and filled with a specific shape into the first virtual plane.
[0063] Furthermore, during the baking process to determine the target lighting region, only the second virtual plane corresponding to the target object region is retained to determine the final lightmap. Correspondingly, the baking results for the auxiliary object regions are discarded. This method ensures that the final generated lightmap is rich in usable lighting information, effectively solving the problem of low lightmap storage efficiency. By optimizing the lightmap generation process, storage efficiency is improved while maintaining rendering quality.
[0064] In the process of rendering virtual objects in a virtual scene, the virtual objects in the virtual scene are usually baked based on the 3D model. This process pre-calculates and stores complex lighting, texture and other information in the light map corresponding to the virtual scene. Then, the light map can be directly used in real-time rendering to achieve the lighting effect rendering of the virtual objects in the virtual scene.
[0065] It should be noted that, in the embodiments of this application, the information stored in the aforementioned lightmap can be the light intensity and shadow information of various surfaces in the virtual scene under different lighting conditions. This information is obtained through pre-calculation during the baking process. Specifically, it may include, but is not limited to, one or more of the following: light intensity information, shadow information, indirect lighting information, lighting direction information, and energy attenuation information. Specifically, the light intensity information indicates the light intensity received by each surface in the virtual scene under specific lighting conditions, and can be represented by color values (such as RGB), where the brightness of the color represents the intensity of the light; the shadow information indicates the depth and direction of shadow areas in the virtual scene; the indirect lighting information indicates the effect of indirect lighting (such as ambient light, reflected light, etc.) on each surface in the virtual scene to simulate global illumination effects; the lighting direction information simulates reflection and refraction effects; and the energy attenuation information indicates the attenuation of light with distance.
[0066] like Figure 3 As shown, the current virtual scene 302 includes multiple virtual objects, including the first virtual object 304. The first lightmap 306 obtained by baking the current virtual scene 302 using a conventional baking method is typically output in a square shape, storing the lighting information corresponding to each virtual object in different regions. It is evident that, because the area proportions corresponding to the lighting information of each virtual object are different in the first lightmap 306, even in a fixed-shape first lightmap 306, there are still a large number of areas that do not contain any effective lighting information. Therefore, the lightmaps determined by existing baking methods suffer from low information storage efficiency.
[0067] In this embodiment, by adding auxiliary virtual objects to the virtual scene, the texture areas corresponding to each target virtual object can be concentrated in a rectangular area. As shown in the second lighting map 308, this embodiment allows multiple texture areas storing effective lighting information to be concentrated in the second texture area 312 within the rectangular area. Correspondingly, the first texture area 310 is used to store the texture information corresponding to the auxiliary virtual objects. Furthermore, the second texture area 312 can be extracted as the target lighting map 314. It is evident that the proportion of effective lighting areas stored in the target lighting map 314 is significantly increased, thereby solving the problem of low lighting map storage efficiency.
[0068] As an optional implementation method, such as Figure 2 As shown, the method for generating the above-mentioned lightmap may include the following steps:
[0069] S202, Add auxiliary virtual objects to the current virtual scene, wherein the current virtual scene includes at least one target virtual object to be baked;
[0070] S204, Perform an object unfolding operation on the auxiliary virtual object and at least one target virtual object to obtain a first virtual plane, wherein the first virtual plane includes a target object region that matches at least one target virtual object and an auxiliary object region that matches the auxiliary virtual object;
[0071] S206, if the auxiliary object region meets the target conditions, the target object region in the first virtual plane is determined as the second virtual plane;
[0072] S208, determine a target lightmap based on the second virtual plane, wherein the target lightmap is used to render at least one virtual object in the virtual scene.
[0073] It should be noted that the above steps in this application can be applied to the development process of virtual scenes, and the above implementation method can be embodied in a development plugin for a virtual scene development application. In the process of generating lightmaps based on the above development plugin, scene information can be configured first, including the placement of objects in the scene, light source parameter settings, and camera parameter settings. Then, the above development plugin is triggered through interface operations, and then, in the process of generating lightmaps, steps S202 to S208 are applied to improve the generation quality of lightmaps and the storage density of lighting information.
[0074] In the above embodiments of this application, the current virtual scene in step S202 may include, but is not limited to, a virtual game scene in a game application, or a virtual reality scene in a virtual reality interactive application used to provide users with interactive operations with virtual objects.
[0075] Optionally, the aforementioned current virtual scene can also be a pre-baked virtual scene of the aforementioned virtual game scene or virtual reality scene. That is, to improve the efficiency of lightmap generation, the aforementioned virtual game scene or virtual reality scene can be pre-processed to obtain a reference virtual scene. It is understood that the amount of data included in the pre-processed reference virtual scene can be smaller than the actual virtual game scene or virtual reality scene, thereby improving the processing efficiency during the baking process.
[0076] In step S202 above, the current virtual scene may include at least one target virtual object to be baked. Furthermore, the current virtual scene may further include added auxiliary virtual objects. The object type of the auxiliary virtual object may be the same as or different from the object type of the target virtual object. For example, if the object types are the same, and the target virtual object is a virtual character object in the virtual scene, the auxiliary virtual object may also be a virtual character object; if the target virtual object is a virtual prop object in the virtual scene, the auxiliary virtual object may also be a virtual prop object. If the object types are different, and the target virtual object is a virtual character object in the virtual scene, the auxiliary virtual object may be a virtual prop object or a virtual geometry object.
[0077] In a preferred embodiment, to control the combination of the auxiliary object region (for matching the auxiliary virtual object) and the target object region (for matching the target virtual object) at an appropriate ratio to bake a lightmap of the target shape, the auxiliary virtual object can be set as a virtual planar object in the virtual scene. This ensures that the shape of the auxiliary object region obtained after performing object unfolding or baking operations on the virtual planar object remains a rectangle. Thus, the lightmap of the target shape can be obtained by combining the first rectangular auxiliary object region and the second rectangular target object region.
[0078] It should be noted that the first virtual plane in step S204 above can specifically be a lightmap UV plane used to store lighting information, thereby obtaining a lightmap. In the above embodiment, the positional relationship between the target object region matched with the target virtual object and the auxiliary object region matched with the auxiliary virtual object can be analyzed based on the lightmap UV plane.
[0079] It should be further noted that, in the above embodiments, the target object region matching the target virtual object can be a texture region used to store the lighting information of at least one target virtual object, and the auxiliary object region matching the auxiliary virtual object can be a texture region used to store auxiliary lighting information.
[0080] In step S206 above, the target conditions that the auxiliary object region needs to meet can be determined according to specific optimization objectives. For example, if the optimization objective is that the proportion of the lighting information region included in the target lighting map is greater than or equal to a certain threshold, the target conditions that the auxiliary object region needs to meet can be determined according to the threshold conditions. For example, the ratio of the area of the auxiliary object region to the area of the target object region may be less than or equal to a first threshold. Correspondingly, the target condition may also be that the ratio of the area of the auxiliary object region to the area of the first virtual plane is less than or equal to a second threshold, thereby ensuring that the area of the target object region accounts for a certain proportion in the first virtual plane.
[0081] Optionally, when the optimization objective is to maximize the proportion of the target object region's area in the first virtual plane, that is, the optimization objective can be: to determine an auxiliary virtual object of appropriate size and the corresponding auxiliary object region, so that the target object region's area accounts for the largest proportion in the first virtual plane.
[0082] In this embodiment, to achieve the aforementioned optimization objective, it is necessary to control the first virtual plane that combines the target object region and the auxiliary object region to form the target shape (i.e., a square). Furthermore, it is necessary to maximize the proportion of the target object region within the first virtual plane. This can be achieved by controlling the auxiliary object region to occupy a fixed area within the first virtual plane, and by adjusting the surface area ratio of the auxiliary and target virtual objects, thereby indirectly adjusting the area proportion between the target object region and the auxiliary object region within the first virtual plane. Since the surface area of the target virtual object remains constant, adjusting the area of the auxiliary virtual object can adjust the proportion of the auxiliary object region, which is equivalent to adjusting the proportion of the target object region.
[0083] The following section provides further explanation of how to adjust the area of auxiliary virtual objects.
[0084] In one alternative implementation, an auxiliary virtual object of the target shape is added to the current virtual scene, including:
[0085] S1, Obtain target size information, wherein the target size information is used to indicate the aspect ratio of the target object region, and the target object region is a first rectangular region in the first virtual plane;
[0086] S2, determine the auxiliary size information of the auxiliary object area based on the texture size information and target size information corresponding to the first virtual plane, wherein the auxiliary object area is the second rectangular area in the first virtual plane, and the target object area and the auxiliary object area form a first virtual plane with equal length and width;
[0087] S3, add an auxiliary virtual object of the target shape in the current virtual scene according to the reference surface area parameter, wherein the target shape of the auxiliary virtual object matches the auxiliary size information.
[0088] In the above embodiments, when the auxiliary virtual object is a rectangular plane, the object shape corresponding to the auxiliary virtual object, i.e. the aspect ratio, can be determined through the above embodiments. Specifically, the auxiliary size information corresponding to the auxiliary virtual object can be determined according to the target size information indicated by the optimization target and the texture size information corresponding to the first virtual plane.
[0089] Specifically, suppose the current optimization goal is to determine a target lightmap for a rectangular region with an aspect ratio of 3:2, and the proportion of the lighting information area included in this lightmap needs to be determined to be the maximum value. Since the default lightmap obtained from the baking operation is a rectangle with an aspect ratio of 1:1, i.e., a square, it can be determined that the shape of the auxiliary object region corresponding to the auxiliary virtual object is a rectangle with an aspect ratio of 3:1. Thus, under the condition of achieving the optimization goal, the auxiliary object region and the target object region can exactly fill the first virtual plane of the square.
[0090] Having determined the aspect ratio of the auxiliary virtual object, the following explains the method for determining the surface area of the auxiliary virtual object.
[0091] In one alternative implementation, adding auxiliary virtual objects to the current virtual scene includes:
[0092] S1, obtain the surface area parameters corresponding to at least one target virtual object respectively;
[0093] S2, determine the reference surface area parameter based on the cumulative result of at least one surface area parameter;
[0094] S3, add an auxiliary virtual object of the target shape in the current virtual scene according to the reference surface area parameter, wherein the current surface area parameter corresponding to the auxiliary virtual object is less than or equal to the reference surface area parameter.
[0095] It is understood that, in the above implementation, the current surface area parameter of the auxiliary virtual object can be determined based on the total area parameter of at least one target virtual object. Specifically, the surface area parameters of each of the at least one target virtual object can be summed to obtain a reference surface area parameter. Then, the optimization range of the current surface area parameter of the auxiliary virtual object can be controlled based on the reference surface area parameter, that is, the current surface area parameter of the auxiliary virtual object can be controlled to be less than or equal to the reference surface area parameter.
[0096] It should be noted that obtaining the surface area parameters of at least one target virtual object can be achieved using one of the following two methods:
[0097] Method 1: Determine the surface area parameter based on the grid area of multiple object grids corresponding to the target virtual object;
[0098] Method 2: Determine the surface area parameter based on the bounding box area of the reference bounding box corresponding to the target virtual object. The reference bounding box is used to accommodate multiple object meshes corresponding to the target virtual object.
[0099] In the above acquisition method one, the above surface area parameter can be determined directly based on the cumulative result of the grid area of the object grid corresponding to each target virtual object, and then the above reference surface area parameter can be determined based on multiple surface area parameters.
[0100] In the second acquisition method described above, the surface area parameter can be determined based on the bounding box area of the reference bounding box corresponding to the target virtual object. In this embodiment, a bounding box refers to a rectangular shape used to enclose the boundary of a two-dimensional graphic or image. Correspondingly, the reference bounding box corresponding to the target virtual object can be a two-dimensional image used to enclose the entire mesh of the target virtual object.
[0101] When the reference bounding box is specifically a square bounding box, the side length of the bounding box can be determined by taking the square root of the sum of the grid areas of the target virtual objects' meshes. Then, the reference surface area parameter is determined by summing the areas of the bounding boxes corresponding to the squares of each target virtual object.
[0102] It is understandable that, in the process of modeling virtual objects in the aforementioned virtual scene, the spatial characteristics such as shape and size of the virtual objects can be described based on multiple object meshes of the same or different shapes. These object meshes can be geometric shapes with an area less than or equal to the target area, such as triangles or quadrilaterals. For example, the object mesh can specifically be a mesh, namely a triangular mesh, used to model continuous curved surfaces, planes, and other objects in the virtual space.
[0103] Through the above-described embodiments of this application, the current surface area parameter of the auxiliary virtual object can be constrained based on the cumulative result of the area of the bounding box corresponding to each of the multiple target virtual objects, thereby improving the efficiency of the search process for optimization results.
[0104] Once the shape and area of the auxiliary virtual object are determined, the auxiliary virtual object can be added to the current virtual scene, and a first virtual plane can be obtained according to the object unwrapping operation in step S204 above. Specifically, the first virtual plane can be a lightmap UV plane, which indicates the object area used to bake the lighting information for different virtual objects.
[0105] The following further explains the method for determining the conditions of the auxiliary object region. In an optional implementation, before determining the target object region in the first virtual plane as the second virtual plane when the auxiliary object region meets the target conditions, the method further includes:
[0106] Case 1: If the long side of the auxiliary object region matches the texture edge of the first virtual plane, and the area ratio of the target object region to the auxiliary object region is greater than or equal to the target threshold, the auxiliary object region is determined to meet the target condition. The target threshold is determined based on the historical ratio corresponding to each of the multiple historical object expansion operations.
[0107] Case 2: If the long side of the auxiliary object region matches the texture edge of the first virtual plane, and the area ratio of the target object region to the auxiliary object region is less than the target threshold, then the auxiliary object region is determined not to meet the target condition.
[0108] Case 3: If the long side of the auxiliary object region does not match the first virtual plane, it is determined that the auxiliary object region does not meet the target conditions.
[0109] The subsequent operations corresponding to the embodiments of this application also differ depending on the specific circumstances. In one optional embodiment, after adding an auxiliary virtual object of the target shape in the current virtual scene based on the reference surface area parameter, the method further includes:
[0110] S1, If the auxiliary object area does not meet the target conditions, update the reference surface area parameter, wherein the updated reference surface area parameter is less than the original reference surface area parameter.
[0111] S2, add an auxiliary virtual object of the target shape in the current virtual scene based on the updated reference surface area parameters;
[0112] S3 determines the target lightmap based on the updated auxiliary virtual object.
[0113] The following combination Figure 4The above-mentioned scenarios and corresponding processing methods will be further explained. Assuming the auxiliary virtual object's shape is determined to be a rectangle with an aspect ratio of 3:1, and its area is determined to be a first area value, an object unfolding operation is performed based on the auxiliary virtual object and multiple target virtual objects to obtain the first virtual plane, which can be as follows: Figure 4 As shown in Figure (a) of the document. Figure 4 In Figure (a), since the surface area corresponding to the auxiliary virtual object is determined based on the sum of the surface areas corresponding to the multiple target virtual objects, the area of the auxiliary object region corresponding to the auxiliary virtual object is also the largest object region in the first virtual plane, namely the first auxiliary object region 402. Correspondingly, the first target object region 404 used for baking multiple target virtual objects is unfolded into a smaller region in the first virtual plane with a fixed shape and size due to the surface area ratio. Assume that the area ratio between the first target object region 404 and the first auxiliary object region 402 is a first value.
[0114] Next, given that the area of the auxiliary virtual object is determined to be the second area value (the second area value is less than the first area value), an object unfolding operation is performed based on the auxiliary virtual object and multiple target virtual objects to obtain the first virtual plane, which can be obtained as follows: Figure 4 As shown in Figure (b) of the table. Figure 4 In Figure (b), because the surface area corresponding to the auxiliary virtual object is relatively smaller than that of the virtual object... Figure 4 The surface area corresponding to Figure (a) in the figure decreases. Although the area of the auxiliary object region corresponding to the auxiliary virtual object is still the largest object region in the first virtual plane, namely the second auxiliary object region 406, the area of the object region occupied by the second target object region 408 used to bake multiple target virtual objects increases due to the surface area ratio. That is, it is assumed that the area ratio between the second target object region 408 and the second auxiliary object region 406 increases to the second value.
[0115] Furthermore, if the area of the auxiliary virtual object is determined to be a third area value (the third area value is less than the second area value), an object unfolding operation can be performed based on the auxiliary virtual object and multiple target virtual objects to obtain the first virtual plane as follows: Figure 4 As shown in Figure (c). Figure 4 In Figure (c), because the surface area corresponding to the auxiliary virtual object is relatively smaller than that of the virtual object... Figure 4 The surface area corresponding to Figure (b) in the figure decreases, that is, the third auxiliary object region 409 is obtained. However, the surface area ratio of the third target object region 410 used to bake multiple target virtual objects increases the area of the object region occupied. That is, it is assumed that the area ratio between the third target object region 410 and the third auxiliary object region 409 increases to the third value.
[0116] Furthermore, if the area of the auxiliary virtual object is determined to be a fourth area value (the fourth area value is less than the third area value), an object unfolding operation can be performed based on the auxiliary virtual object and multiple target virtual objects to obtain the first virtual plane as follows: Figure 4 As shown in Figure (d) in the diagram. Figure 4 In Figure (d), the surface area corresponding to the auxiliary virtual object is relatively smaller than that of the main virtual object. Figure 4 The surface area corresponding to image (c) is further reduced, resulting in the fourth auxiliary object region 412. According to the unfolding algorithm, the fourth auxiliary object region 412 cannot occupy an entire texture edge. Furthermore, due to the surface area ratio of the fourth target object region 414 when baking multiple target virtual objects, the area of the occupied object region further increases; that is, assuming the area ratio between the fourth target object region 414 and the fourth auxiliary object region 412 increases to a fourth value.
[0117] Clearly, in the four unfolding methods described above, the area ratio between the target object region and the auxiliary object region gradually increases, but... Figure 4 In Figure (d), the fourth auxiliary object region 412 cannot occupy an entire texture edge, which will make the subsequent operation of trimming the light map more complicated, and the description of the target object region will also become more complicated. Therefore, it meets the above conditions. In the case that the long side of the auxiliary object region does not match the first virtual plane, it is determined that the auxiliary object region does not meet the target conditions.
[0118] and Figure 4 In Figure (c), the third auxiliary object region 409 can occupy an entire texture edge, and the area ratio between the target object region and the auxiliary object region is the maximum value that satisfies the edge length condition. Therefore, it meets the above condition one. When the long side of the auxiliary object region matches the texture edge of the first virtual plane, and the area ratio between the target object region and the auxiliary object region is greater than or equal to the target threshold, it is determined that the auxiliary object region meets the target condition. Among them, the above target threshold can be determined as the second value mentioned above based on the above multiple expansion operations.
[0119] It should be noted that the above process for determining the second virtual plane can be as follows: given multiple current surface area parameters that are smaller than the reference surface area parameter (i.e., the total area of the bounding boxes corresponding to the multiple target virtual objects), auxiliary virtual objects are added in multiple current virtual scenes based on the multiple current surface area parameters, and expanded to obtain their respective first virtual planes. Then, based on the above conditions, an auxiliary object region that meets the target conditions is determined, and based on the auxiliary object region that meets the target conditions, the second virtual plane is determined from the first virtual plane.
[0120] In another alternative implementation, the process of determining the second virtual plane described above may involve determining an auxiliary object region that meets the target conditions by gradually decreasing the current surface area parameter while setting a first area change step size, and then determining the second virtual plane from the first virtual plane based on the auxiliary object region that meets the target conditions.
[0121] In another alternative implementation, the process of determining the second virtual plane described above may involve gradually increasing the current surface area parameter (with the termination condition being that the current surface area parameter is less than or equal to the reference surface area parameter) by setting a second area change step size, thereby determining an auxiliary object region that meets the target conditions, and determining the second virtual plane from the first virtual plane based on the auxiliary object region that meets the target conditions.
[0122] For example Figure 5 As shown, the area of the auxiliary virtual object can be determined as the fifth area value based on the area of the bounding box corresponding to a target virtual object. Then, an object unfolding operation is performed based on the auxiliary virtual object and multiple target virtual objects to obtain the first virtual plane, which can be obtained as follows: Figure 5 As shown in Figure (a) of the document. Figure 5 In Figure (a), it is assumed that the area ratio between the first target object region 504 and the first auxiliary object region 502 is the fifth value;
[0123] Next, the area of the auxiliary virtual object can be increased to a sixth area value, and an object unfolding operation can be performed based on the auxiliary virtual object and multiple target virtual objects to obtain the first virtual plane as shown below. Figure 5 As shown in Figure (b) of the table. Figure 5 In Figure (b), assuming the area ratio between the second target object region 508 and the second auxiliary object region 506 is a sixth value; then, the object area of the auxiliary virtual object can be increased to a seventh area value, and an object expansion operation is performed based on the auxiliary virtual object and multiple target virtual objects to obtain the first virtual plane as shown below. Figure 5 As shown in Figure (c). Figure 5 In Figure (c), assuming the area ratio between the third target object region 510 and the third auxiliary object region 509 is the seventh value; then, the object area of the auxiliary virtual object can be increased to the eighth area value, and an object expansion operation is performed based on the auxiliary virtual object and multiple target virtual objects to obtain the first virtual plane as shown below. Figure 5 As shown in Figure (d) in the diagram. Figure 5 In Figure (d), it is assumed that the area ratio between the fourth target object region 514 and the fourth auxiliary object region 512 is the eighth value.
[0124] Based on the principles and methods described above, an auxiliary object region that meets the target conditions can also be determined, and a second virtual plane can be determined from the first virtual plane based on the auxiliary object region that meets the target conditions.
[0125] In another alternative implementation, when the area of the auxiliary virtual object is adjusted based on the changing step size, the changing step size can also be dynamically adjusted based on relevant parameters.
[0126] Continuing with the example of defining the shape of the auxiliary virtual object as a rectangle with an aspect ratio of 3:1, and the target object area as a rectangle with an aspect ratio of 3:2, it can be determined that the area ratio between the auxiliary object area and the target object area should be close to 1:2.
[0127] By gradually increasing or decreasing the adjustment as described above, the area change step size can be dynamically adjusted based on the difference between the current area ratio and the target area ratio of 1:2 in the current step. If the difference between the current area ratio and the target area ratio decreases, the area change step size can be dynamically decreased synchronously based on the configured change coefficient; if the difference between the current area ratio and the target area ratio increases, the area change step size can be dynamically increased synchronously based on the configured change coefficient.
[0128] Through the above-described embodiments of this application, the area of the auxiliary virtual object can be dynamically adjusted to quickly find the optimal solution when the aspect ratio of the target light map is determined, thereby determining the corresponding second virtual plane and the corresponding baked target light map.
[0129] In one alternative implementation, before adding auxiliary virtual objects to the current virtual scene, the method further includes:
[0130] S1, Obtain the vertex set corresponding to at least one first virtual object in the first virtual scene;
[0131] S2, determine the mesh set corresponding to at least one first virtual object based on at least one vertex set;
[0132] S3, determine the mesh normals corresponding to each of the multiple mesh objects in at least one mesh set;
[0133] S4. Determine the current virtual scene based on the vertex set and mesh set corresponding to at least one first virtual object, including the mesh normal set of multiple mesh normals.
[0134] In the above embodiments, the current virtual scene can be a reference scene obtained by performing an object merging operation based on a first virtual scene (e.g., a virtual scene in a game). Specifically, a baked proxy model can be obtained by performing a model merging operation based on the relevant identification information and model information of the virtual objects included in the first virtual scene, and then the current virtual scene can be indicated based on the baked proxy model.
[0135] The following combination Figure 6 The above model merging operation is explained in detail. In the embodiment of this application, firstly, an object list corresponding to all static objects in the scene is obtained, and then the vertices, triangle indices, and normals of the static object list are merged respectively.
[0136] S602, Obtain a static scene;
[0137] S604, merge vertices;
[0138] For all vertices of a static first virtual object, add them to a new vertex list newV. Simultaneously, perform a coordinate transformation operation on each vertex using the result of the model.MultiplyPoint3x4 method.
[0139] S606, merge triangle vertex indices;
[0140] For each first virtual object to be merged, merge its vertex indices and record the number of vertices in the new vertex list newV (offset). During the merging process, the offset needs to be added to the original first virtual object's index to ensure the correctness of the triangle indices in the merged model.
[0141] It should be noted that during the process of merging the vertex indices of the triangles, the area of each triangle can be accumulated to obtain the total triangle area of the model. The square root of the total triangle area is then used to determine the side length of the bounding box corresponding to the first virtual object. Simultaneously, a new variable, QuadSize, is used to record the sum of the sizes of each bounding box, serving as the initial current surface area parameter. In subsequent operations, the size of the auxiliary virtual objects can be adjusted based on the QuadSize variable.
[0142] S608, merge normals; it should be noted that during the merging process, the normal transformation matrix is the transpose of the inverse of the model transformation matrix.
[0143] S610, create a new Mesh, assign the merged data to the new Mesh, and obtain the agent baking model corresponding to the current virtual scene.
[0144] Assign the merged vertex, triangle indices, and normals to the new mesh. Optionally, you can set the index format of the new model to UInt32 to avoid indexing errors when the scene has more than 65535 vertices. Next, use SubMeshDescriptor to set the submesh for the new model.
[0145] The specific implementation process for setting up a submesh can be referenced in the following pseudocode description:
[0146] " / / submeshIndices records the vertex indices of each submesh;
[0147] For i from 0to submeshIndices.Count:
[0148] subMeshOffest=new SubMeshDescriptor();
[0149] SetSubMesh();
[0150] Specifically, in the implementation described in the pseudocode above, the vertex indices of each submesh can be recorded by creating a `submeshIndices` parameter; then, a loop is executed to traverse the array from 0 to the length of the `submeshIndices` array. Simultaneously, a `SubMeshDescriptor` instance is created, and in each loop iteration, a new `SubMeshDescriptor` instance is created and assigned to the variable `subMeshOffset`. Finally, the `SetSubMesh` method can be called to set the submesh using the `subMeshOffset` instance.
[0151] The above-described embodiments of this application allow multiple static objects to be merged into a single model, reducing model switching and computational load during rendering, thereby improving rendering efficiency. By merging vertices, triangle vertex indices, and normals, redundancy in vertex data can be reduced, and a new mesh can be created to store this merged data. Finally, by setting the SubMeshDescriptor, it can be ensured that the merged model can be correctly displayed during rendering.
[0152] Simultaneously, during the merging process, the surface area of each static object is statistically calculated to assist in controlling the size of subsequent virtual objects.
[0153] Having determined the baking agent model according to the above implementation method, the following will further explain steps S202 to S206 with specific examples.
[0154] In the embodiments of this application, the rectangular size of the target light map can be predetermined, for example, 2496px*1664px.
[0155] To ensure that static virtual objects in the scene occupy the preset size in the lightmap, an auxiliary object region can be added to occupy any extra space in the lightmap. For example, if the selected size is 2496px * 1664px, and the aspect ratio of the chosen rectangle is 3:2, then adding an auxiliary object region with an aspect ratio of 3:1 will allow the auxiliary object region to occupy 2496px * 832px pixels in the final lightmap. Furthermore, based on the texture packing algorithm involved in the baking process, the auxiliary object region can be positioned in the lower left corner of the lightmap, facilitating lightmap cropping and obtaining the target lightmap with the highest information content.
[0156] In determining the actual size of the auxiliary virtual object, in order to ensure that the auxiliary object region corresponding to the auxiliary virtual object occupies the required position in the lightmap, the actual size of the auxiliary virtual object can be set to the QuadSize obtained in the above implementation. Then, the auxiliary virtual object is added to the previously generated baked proxy model, and the lightmap UV of the baked proxy model can be generated using the Unwrapping method.
[0157] In one specific implementation, the above-described method of generating the lightmap UVs of the baked proxy model using the Unwrapping method can be achieved as indicated by the following pseudocode definition:
[0158] "void GenerateSecondaryUVSet(Mesh src,UnwrapParam settings)";
[0159] The pseudocode above defines a function method called `GenerateSecondaryUVSet`, which generates a second set of UV coordinates for a 3D model's mesh. These UV coordinates are used to map 2D images (such as texture maps) onto the surface of the 3D model.
[0160] The function method described above takes a first parameter, `Mesh src`, of type `Mesh`. This parameter indicates that the 3D model mesh (i.e., the virtual mesh used to render the target virtual object) from which the second set of UV coordinates is requested should be used as the input source.
[0161] The function method described above takes a second parameter, `UnwrapParam settings`, which is of type `UnwrapParam` and is used to indicate the parameter settings related to the object unwrapping operation. The `settings` parameter specifies the configuration information for adjusting the object unwrapping method.
[0162] Next, the size of the auxiliary virtual object is continuously reduced so that the proportion of the auxiliary object region in the lightmap UV of the baked proxy model is reduced in the result of two consecutive lightmap UV generation.
[0163] For example, if the currently selected size is 2496px * 1664px, which is a final result where the length is greater than the width, ideally, the auxiliary object region should occupy the bottom third of the model's lightmap UVs. Therefore, the proportion of the auxiliary object region's lightmap UVs in the horizontal dimension should theoretically be 100%. By continuously reducing the size of the auxiliary virtual object, the proportion occupied by the auxiliary object region will decrease from 100% to less than 100% after a certain reduction in the size of the auxiliary virtual object. This allows the previously selected auxiliary virtual object to be identified as the desired auxiliary virtual object, and the corresponding auxiliary object region to be identified as the desired auxiliary object region.
[0164] Through the above-described embodiments of this application, when the aspect ratio of the target lightmap is determined, by adding auxiliary virtual objects, the objects in the original scene can be made to have a pre-set rectangular ratio in the lightmap, which increases the actual occupancy rate and the number of pixels used in the lightmap, and also makes the lightmap not limited to a square shape, and its information organization form becomes more flexible.
[0165] In the embodiments of this application, during the process of generating the target lighting map, a rectangular target lighting map with a specific aspect ratio that can carry the most lighting information can be further determined under a fixed number of pixel thresholds.
[0166] In an optional implementation, when the proportion of the number of valid pixels corresponding to the valid object region in the second virtual plane is greater than or equal to the target value, before performing a baking operation on the current virtual scene according to the second virtual plane and performing a baking operation on the current virtual scene according to the first virtual plane to obtain the reference lightmap, the method further includes:
[0167] S1, obtain the target pixel count;
[0168] S2, determine multiple candidate texture size information based on the target pixel threshold, wherein the number of lighting pixels included in the candidate lighting texture corresponding to the candidate texture size information is less than or equal to the number of target pixels;
[0169] S3, determine the auxiliary dimension information corresponding to each of the multiple candidate lightmap dimensions, wherein the auxiliary dimension information is used to indicate the aspect ratio of the auxiliary object region;
[0170] S4. Based on multiple auxiliary size information, determine the second virtual plane corresponding to each of the multiple candidate virtual scenes, wherein the multiple candidate virtual scenes include the current virtual scene;
[0171] S4. Determine the target value based on the number of valid pixels corresponding to each of the multiple second virtual planes.
[0172] For example, with a video memory budget of 2048px * 2048px (4,194,304 pixels), multiple candidate texture sizes can be determined to indicate the aspect ratio of the final target lightmap. For instance, with an aspect ratio of 23:43, the corresponding pixel combination is 1472px * 2752px, with a cumulative pixel count of 4,050,944, which is less than the video memory budget. Similarly, with an aspect ratio of 41:24, the corresponding pixel combination is 2624px * 1536px, with a cumulative pixel count of 4,030,464, which is also less than the video memory budget. With an aspect ratio of 12:21, the corresponding pixel combination is 1536px * 2688px, with a cumulative pixel count of 4,128,768, which is also less than the video memory budget. This pattern continues, allowing for the determination of multiple candidate texture sizes within the same video memory budget.
[0173] It is understandable that for each of the above candidate texture size information, the corresponding auxiliary size information of the auxiliary object area can be determined. For example, for candidate texture size information of 1472px*2752px, its corresponding auxiliary size information can be determined as 1280px*2752px; for candidate texture size information of 2624px*1536px, its corresponding auxiliary size information can be determined as 2624px*1088px; and for candidate texture size information of 1536px*2688px, its corresponding auxiliary size information can be determined as 1152px*2688px.
[0174] For each auxiliary object region with auxiliary dimension information, the object shape and size of its corresponding auxiliary virtual object can be determined, and then the corresponding second virtual plane can be determined according to the above implementation method.
[0175] In one alternative implementation, when multiple second virtual planes are determined based on multiple candidate texture size information, the target lighting map can be determined based on the second virtual planes as follows:
[0176] S1, if the number of valid pixels corresponding to the valid object area in the second virtual plane is greater than or equal to the target value, perform a baking operation on the current virtual scene according to the first virtual plane to obtain a reference light map;
[0177] S2, determine the target lightmap based on the texture area in the reference lightmap that matches the second virtual plane.
[0178] In the above embodiments of this application, the target second virtual plane can be determined from multiple second virtual planes based on the comparison result between the number of effective pixels corresponding to the second virtual plane and the target value, and then the target light map can be obtained according to the baking operation.
[0179] The target value mentioned above can be a preset value or a value determined based on the size information of multiple candidate textures.
[0180] For example, based on the size information of multiple candidate textures, a corresponding second virtual plane is determined for each. Then, based on the corresponding second virtual plane, the number of effective pixels for each is determined. These effective pixel counts are then sorted from highest to lowest, and the second highest count is determined as the target value. In other words, the second virtual plane with the highest number of effective pixels can be determined as the target second virtual plane, and the corresponding target lightmap can be identified.
[0181] The following further explains the method for determining the number of effective pixels. In an optional implementation, before performing a baking operation on the current virtual scene according to the first virtual plane to obtain the reference lightmap, when the number of effective pixels corresponding to the effective object region in the second virtual plane is greater than or equal to the target value, the method further includes:
[0182] S1, obtain the sum of the grid areas of multiple virtual grids included in the second virtual plane;
[0183] S2, based on the sum of the grid areas, determine the first area proportion of multiple virtual grids in the first virtual plane;
[0184] S3, based on the ratio between the first virtual area of the first virtual plane and the second virtual area of the second virtual plane, determine the second area proportion of the multiple virtual grids in the second virtual plane;
[0185] S4. Based on the second area ratio and the candidate texture size information matching the second virtual plane, determine the number of effective pixels corresponding to the second virtual plane.
[0186] In this embodiment, since the first virtual plane is usually set to a plane with a length and width of 1 unit, the grid area of multiple virtual grids in the first virtual plane is accumulated to directly determine the proportion of the grid area of multiple virtual grids in the first virtual plane.
[0187] Since the second virtual plane is a virtual plane extracted from the first virtual plane, the area ratio of multiple virtual grids in the second virtual plane can be determined based on the ratio of the grid area of multiple virtual grids in the first virtual plane and the area relationship between the second virtual plane and the first virtual plane.
[0188] Finally, based on the area ratio and the corresponding candidate texture size information, the number of effective pixels is determined.
[0189] In one specific implementation, the virtual mesh can be a triangular mesh. The method for determining the proportion of the mesh area of multiple virtual meshes in the first virtual plane can be implemented as described in the following pseudocode snippet:
[0190]
[0191] In the above implementation, firstly, a new UV coordinate array uv2 and an array triangle defining the vertex indices of triangles need to be prepared. Next, the Occupancy function is called, passing in the prepared uv2 and triangle arrays, and simultaneously defining a variable area to record the accumulated area of each triangle mesh.
[0192] Next, the process iterates through all the triangular meshes. For the currently traversed triangular mesh, the UV coordinates of the three vertices are first obtained. Then, the cross product of vectors u2-u1 and u3-u1 is calculated using the formula crossProduct. It can be understood that the magnitude of the cross product can be used to determine the area of the current triangular mesh, and the calculated area of a single triangular mesh is recorded using uArea. Specifically, half the magnitude of the cross product can be used to calculate and determine the area of the current triangular mesh.
[0193] Finally, the area value returned by the function can be used to indicate the proportion of the grid area of multiple triangular meshes in the first virtual plane.
[0194] The following combination Figure 7 The specific process for determining the proportion of the grid area of the aforementioned multiple virtual grids in the first virtual plane is explained in detail.
[0195] S702, obtain the list of second texture coordinates corresponding to multiple vertices in the current virtual object;
[0196] S704, retrieve the values List[i] from the list in order of index i;
[0197] Execute judgment S706 to check if the list traversal is complete; if the traversal is complete, determine the corresponding area percentage information based on the area.
[0198] If the traversal is not complete, execute S708 to obtain the second texture coordinate information u1, u2, u3 of all three vertices of a triangular mesh;
[0199] S710, determine the area of the triangular mesh based on the cross product of u1, u2, u3;
[0200] In the above steps, for the uv2 list and the triangle list, traverse each triangle to obtain the uv2 coordinates u1, u2, u3 of the three points of the triangle, and then use the cross product to calculate the area of the triangle.
[0201] S712, use area to accumulate the area of the triangle;
[0202] Execute step S714 to obtain the next sequence number i; then, continue to execute step S704.
[0203] In the above implementation, the UV coordinates of the new model (i.e., the baking proxy model) are determined according to the above implementation. A list of static object lists is obtained when merging the models. Then, the original UV coordinates of the lightmap for each static object are transformed to determine the updated UV coordinates. Furthermore, the proportion of the updated UV coordinates of each static object in the new model's lightmap is calculated based on the updated UV coordinates.
[0204] exist Figure 7 In the illustrated implementation, since the first virtual plane is usually set to a plane with a length and width of 1 unit, the proportion of the grid area of the multiple virtual grids in the first virtual plane can be directly determined by summing the grid areas of the multiple virtual grids in the first virtual plane.
[0205] Next, after converting the above proportions into ratios, multiplying them by the initially preset size yields the effective pixel count. For example, based on... Figure 7 When the area of the multiple virtual grids determined by the method shown accounts for 1 / 2 of the area in the first virtual plane, since the area of the second virtual plane accounts for 2 / 3 of the area in the first virtual plane, the area of the multiple virtual grids in the second virtual plane is determined to be 3 / 4, or 75%, based on the ratio between 1 / 2 and 2 / 3.
[0206] Given that the corresponding candidate texture size is determined to be 2496px*1664px, and based on the occupancy ratio of 75%, the effective number of pixels corresponding to the above candidate texture size is determined to be 3115008.
[0207] Through the above-described embodiments of this application, the effective pixel count corresponding to each candidate texture size information can be determined, and the candidate texture size with the largest effective pixel count can be determined as the target size of the target lighting texture. It also matches the virtual plane size of the second virtual plane, and subsequent baking operations are performed according to the second virtual plane.
[0208] Specifically, in the baking settings, the size of the lightmap can be set to the dimensions corresponding to the maximum number of effective pixels. Then, the `gameObject.SetActive(false)` method is used to hide all virtual objects before merging the models (i.e., in the first virtual scene), retaining only the merged baked proxy model. The baked proxy model is set to `ContributeGI`, meaning it contributes lighting to generate the lightmap. Next, the `Lightmapping.Bake()` method is used to generate a reference lightmap based on the first virtual plane.
[0209] After baking and generating the reference lightmap corresponding to the first virtual plane, the reference lightmap is cropped according to the target size corresponding to the target lightmap determined in the above embodiment, that is, the texture area obtained from the auxiliary virtual object is cropped out. Continuing with the example of a preset size of 2496px*1664px, since the size of the directly baked reference lightmap is 2496x2496, the texture area corresponding to the auxiliary virtual object, that is, one-third of the texture area in the reference lightmap, is extracted from the reference lightmap to obtain the target lightmap.
[0210] In one specific implementation, the method of obtaining the target lightmap by cropping from the reference lightmap can be implemented using the following pseudocode:
[0211] " / / inputFilePath is the path to the texture to be cropped, and outputFilePath is the path to the texture after cropping;
[0212] / / width and height are the dimensions after cropping;
[0213] tex2d = LoadAssetAtPath <texture2d>(inputFilePath);
[0214] colors=tex2d.GetPixels(0,0,(int)(width),(int)(height));
[0215] texNew=new Texture2D((int)width),(int)(height),RGB24,false);
[0216] texNew.SetPixels(colors);
[0217] texNew.Apply();
[0218] In the above implementation, the reference texture file located at the inputFilePath path is first loaded using the LoadAssetAtPath function and stored in the tex2d variable. Here, Texture2D indicates the class in the Unity engine used to handle 2D textures;
[0219] Next, use the GetPixels method to retrieve pixel data from the tex2d variable. In the GetPixels method, you need to specify the starting position (i.e., (0,0)) and dimensions (width and height) of the pixels to be retrieved. The retrieved pixel data is stored in the colors array.
[0220] Furthermore, a new Texture2D object, texNew, is created, with its dimensions specified by width and height. Since width and height are the clipped dimensions, this step allows the reference lightmap to be clipped to obtain the target lightmap. It should be noted that in the above implementation, the Texture2D object uses the RGB24 format, meaning each pixel uses 24 bits of color depth. The false parameter indicates that the pixel texture in the current Texture2D object does not have an alpha channel.
[0221] Next, the SetPixels method is used to apply the pixel data colors obtained in the previous steps to the newly created texture map texNew, and the Apply method is called to make the changes to the texNew texture map take effect.
[0222] Through the above-described embodiments of this application, by cropping the auxiliary object region of the baking proxy model, the target lightmap can be a pre-defined rectangle, thereby increasing the actual occupancy rate and pixel usage of the lightmap. Simultaneously, since the lightmap is no longer limited to a square shape, the flexibility of lightmap generation and transmission is also improved.
[0223] In the case of baking the target lightmap, the position and scaling information of each target virtual object in the target lightmap can be pre-stored to enable dynamic rendering of the target virtual objects based on the pre-stored position and scaling information during the rendering process.
[0224] The following further explains the method of pre-storing the position and scaling information of each target virtual object in the target lightmap. In an optional implementation, after determining the target lightmap based on the second virtual plane, the method further includes:
[0225] S1, based on the object regions matched by at least one target virtual object in the second virtual plane, determine the region bounding box corresponding to each of the at least one virtual object, wherein the region range of the region bounding box includes the object region;
[0226] S2, based on at least one region bounding box, determine target offset information and target scaling information corresponding to at least one target virtual object, wherein the target offset information and target scaling information are used to determine the lighting information matching the target virtual object from the target lightmap.
[0227] It is understood that, in the embodiments of this application, the position information matching the target virtual object can be determined in the second virtual plane based on the relevant coordinate parameters of the bounding box of each target virtual object. The position information may include target offset information and target scaling information.
[0228] Furthermore, the above-mentioned determination of target offset information and target scaling information corresponding to at least one target virtual object based on at least one region bounding box includes:
[0229] S1, determine the first coordinate of the first vertex of the region bounding box in the second virtual plane as the target offset information;
[0230] S2, determine the target scaling information based on the coordinate difference between the second coordinate and the first coordinate of the second vertex of the region bounding box in the second virtual plane, where the first vertex and the second vertex are two vertices on the diagonal of the region bounding box.
[0231] In the above implementation, the coordinate information of the bottom left corner of the region bounding box can be determined as offset information, and the scaling information can be determined based on the coordinate difference between the top left corner and the bottom left corner.
[0232] The following combination Figure 8 The method for determining the location and scaling information of the target virtual object is further explained. Based on the UV coordinates of the baked proxy model's lightmap obtained in the above implementation, the list of static objects during model merging can be traversed, and then the updated UV coordinates of each static object can be determined. Next, by calculating the bounding box of the updated UV coordinates of each static object, the scaling and offset information of the updated UV coordinates of the current static object within the model's lightmap can be determined. The specific method for determining the bounding box and the corresponding coordinate information is as follows:
[0233] S802, Get the list of texture coordinates corresponding to multiple vertices in the current virtual object;
[0234] S804 uses the min parameter to store the bottom left corner point and the max parameter to store the top right corner point;
[0235] S806, retrieve the values List[i] from the texture coordinate list in index order;
[0236] Execute condition S808 to check if the list traversal is complete; if the traversal is complete, execute S810 to return the min and max parameters.
[0237] If the traversal is not complete, execute the assignment operation S808-1, min = Min(min, List[i]); continue to execute the assignment operation S808-2, max = Max(max, List[i]); and execute S808-3 to get the next index i. Then, repeat step S806.
[0238] pass Figure 8 The process shown iterates through all coordinate points in the UV coordinates of the lightmap corresponding to the current virtual object, using `min` to record the bottom-left corner and `max` to record the top-right corner. The final scale is equal to `max - min`, and the final offset is equal to `min`.
[0239] In one specific implementation, the offset and scaling parameters for each virtual object can be determined using the following pseudocode snippet:
[0240]
[0241] In the above implementation, the bottom-left and top-right vertices corresponding to a set of UV coordinates can be calculated using the UVBoundingBox function. The minimum and maximum values of these UV coordinates can be found using the bounding box function, thereby determining their range in UV space, and subsequently determining the scaling and offset parameters of the lighting area corresponding to the target virtual object in the target lightmap.
[0242] In the above implementation, the bounding box function can accept a two-dimensional vector array uv as a parameter, which contains a series of UV coordinates.
[0243] Next, two vectors, min and max, are initialized to store the minimum and maximum values of the UV coordinates, respectively. During initialization, they are assigned the initial values Vector2(1,1) and Vector2(0,0). This is understandable, as the valid range of UV coordinates is typically [0,1], choosing these initial values ensures that any valid UV coordinate can be used to update the aforementioned variables.
[0244] During the traversal, the input UV coordinate array uv is traversed. For each UV coordinate uv2, the min variable is updated using the min function to ensure that min always contains the current smallest UV coordinate; at the same time, the max variable is updated using the max function to ensure that max always contains the current largest UV coordinate.
[0245] Finally, the bounding box function returns two vectors, min and max, which represent the minimum UV coordinates (bottom left corner) and the maximum UV coordinates (top right corner) of the UV region of the current virtual object's ray map, respectively.
[0246] Furthermore, in the process of determining the scaling information Scale and the offset information Offset, the scaling information Scale is equal to max – min, and the final determined offset information Offset is equal to min.
[0247] Then, the scale and offset information for each static object are stored in a file, such as a .json file. This file stores the scale and offset information for each static object, along with the path to the target lightmap. This allows for dynamic rendering of the target virtual objects in the virtual scene during the rendering process, based on the target lightmap and the corresponding scale and offset information.
[0248] Optionally, the baking proxy scene model corresponding to the current virtual scene obtained according to the above merging operation can then be deleted; and all static object models used to indicate the target virtual object in the first scene model corresponding to the original first virtual scene can be set to visible.
[0249] The following combination Figure 9 and Figure 10 The process of generating a light map according to this application is described.
[0250] S902, Obtain a static scene;
[0251] S904, pre-determines the proportion and size information of some rectangles based on pixel thresholds;
[0252] For example, with a video memory budget of 2048px * 2048px (4,194,304 pixels), multiple candidate texture sizes can be determined to indicate the aspect ratio of the final target lightmap. For instance, with an aspect ratio of 23:43, the corresponding pixel combination is 1472px * 2752px, with a cumulative pixel count of 4,050,944, which is less than the video memory budget. Similarly, with an aspect ratio of 41:24, the corresponding pixel combination is 2624px * 1536px, with a cumulative pixel count of 4,030,464, which is also less than the video memory budget. With an aspect ratio of 12:21, the corresponding pixel combination is 1536px * 2688px, with a cumulative pixel count of 4,128,768, which is also less than the video memory budget. This pattern continues, allowing for the determination of multiple candidate texture sizes within the same video memory budget.
[0253] It is understandable that for each of the above candidate texture size information, the corresponding auxiliary size information of the auxiliary object area can be determined. For example, for candidate texture size information of 1472px*2752px, its corresponding auxiliary size information can be determined as 1280px*2752px; for candidate texture size information of 2624px*1536px, its corresponding auxiliary size information can be determined as 2624px*1088px; and for candidate texture size information of 1536px*2688px, its corresponding auxiliary size information can be determined as 1152px*2688px.
[0254] S906 generates multiple baking proxy models based on multiple rectangle proportions and size information;
[0255] For each candidate texture size mentioned above, a corresponding baked proxy model can be generated. For example, based on the relevant identifiers and model information of the virtual objects included in the first virtual scene, a baked proxy model is obtained through a model merging operation. Specifically, it can be based on... Figure 6 The process shown establishes the baking agent model.
[0256] like Figure 10 As shown in Figure (a), the static scene 1000 corresponding to the baking proxy model determined according to the above implementation method may include multiple target virtual objects to be rendered.
[0257] S908, add an auxiliary object of appropriate size to the baking proxy model to generate the first virtual plane corresponding to the baking proxy model;
[0258] Specifically, in determining the actual size of the auxiliary virtual object, in order to ensure that the auxiliary object region corresponding to the auxiliary virtual object occupies exactly the required position in the lightmap, the actual size of the auxiliary virtual object can first be set to the above-mentioned... Figure 6 The QuadSize obtained in the illustrated implementation is then used to add the auxiliary virtual object to the previously generated baked proxy model. The lightmap UV of the baked proxy model can then be generated using the Unwrapping method.
[0259] Next, the size of the auxiliary virtual object is continuously reduced so that the proportion of the auxiliary object region in the lightmap UV of the baked proxy model is reduced in the result of two consecutive lightmap UV generation.
[0260] For example, if the currently selected size is 2496px * 1664px, which is a final result where the length is greater than the width, ideally, the auxiliary object region should occupy the bottom third of the model's lightmap UVs. Therefore, the proportion of the auxiliary object region's lightmap UVs in the horizontal dimension should theoretically be 100%. By continuously reducing the size of the auxiliary virtual object, the proportion occupied by the auxiliary object region will decrease from 100% to less than 100% after a certain reduction in the size of the auxiliary virtual object. This allows the previously selected auxiliary virtual object to be identified as the desired auxiliary virtual object, and the corresponding auxiliary object region to be identified as the desired auxiliary object region.
[0261] If a suitable auxiliary virtual object is determined according to the above implementation method, it can be as follows: Figure 10 As shown in Figure (b), an auxiliary virtual object 1002 of the target size and shape is added to the static scene.
[0262] S910 determines the target proportion and size information from the proportions and sizes of multiple rectangles based on the comparison results of the effective pixel counts corresponding to each of the multiple rectangles.
[0263] For a rectangle, determining its corresponding effective pixel count can be done as follows: Figure 7 The implementation method shown is adopted. Since the first virtual plane is usually set as a plane with a length and width of 1 unit, the proportion of the grid area of multiple virtual grids in the first virtual plane can be directly determined by summing the grid areas of multiple virtual grids in the first virtual plane.
[0264] Next, after converting the above proportions into ratios, multiplying them by the initially preset size yields the effective pixel count. For example, based on... Figure 7 When the area of the multiple virtual grids determined by the method shown accounts for 1 / 2 of the area in the first virtual plane, since the area of the second virtual plane accounts for 2 / 3 of the area in the first virtual plane, the area of the multiple virtual grids in the second virtual plane is determined to be 3 / 4, or 75%, based on the ratio between 1 / 2 and 2 / 3.
[0265] Given that the corresponding candidate texture size is determined to be 2496px*1664px, and based on the proportion of 75%, the effective number of pixels corresponding to the above candidate texture size is determined to be 3115008.
[0266] S912, bakes according to the target scale and size information to obtain a reference light map;
[0267] Assumption Figure 10 Image (b) in the diagram corresponds to the rectangle with the highest number of effective pixels. Then, we can proceed as follows... Figure 10 The baking operation is performed on diagram (b) to obtain... Figure 10 The reference lighting map shown in Figure (c) includes a target object region 1004 for storing lighting information corresponding to the target virtual object and an auxiliary object region 1006 for storing lighting information corresponding to auxiliary virtual objects.
[0268] S914, the reference lightmap is cropped to obtain the target lightmap; from Figure 10 After cropping the auxiliary object area in Figure (c), you can obtain the following: Figure 10 The target lighting map 1008 is shown in (d) in the image.
[0269] S916, saves the target light map and the corresponding object position information.
[0270] In the embodiments of this application, the following can be adopted: Figure 8 The process shown determines the position and scaling information of each target virtual object. With the UV coordinates of the baked proxy model's lightmap obtained, the list of static objects during model merging can be traversed, and then... Figure 8 The method shown determines the updated UV coordinates of the lightmap for each static object. Then, by calculating the bounding box of the updated UV coordinates of each static object, the scaling and offset information of the updated UV coordinates of the current static object within the model's lightmap UV coordinates can be determined.
[0271] Through the above-described embodiments of this application, by cropping the position of the auxiliary object area of the baked proxy model, the lightmap can be a pre-defined rectangle, which increases the actual occupancy rate and pixel usage of the lightmap and improves the flexibility of the lightmap size. In addition, the scaling and offset information of the baked lightmap and static objects can be dynamically stored, thereby realizing dynamic rendering during the rendering process.
[0272] In one alternative implementation, it further includes:
[0273] S1, when the target virtual scene includes multiple target virtual objects, determine multiple object combinations corresponding to the multiple target virtual objects, wherein the object combination includes at least one target virtual object;
[0274] S2, determine the second virtual plane corresponding to each of the multiple object combinations;
[0275] S3, Based on the comparison results between multiple second virtual planes, determine the target object combination from multiple object combinations;
[0276] S4, determine the target lightmap based on the target object combination.
[0277] In this embodiment of the application, the number of objects included in a target lighting map can also be determined according to the above embodiments.
[0278] For example Figure 11 As shown, assuming that the virtual scene 1100 includes 4 virtual objects to be baked, there are multiple ways to combine the objects. For example, in the first way of combining the objects, the lighting information of the virtual object numbered 1 can be stored in a lightmap; in the second way of combining the objects, the lighting information of the virtual objects numbered 1 and 2 can be stored in a lightmap, and so on, there can be 15 ways to combine them.
[0279] For each combination, it can be based on... Figure 9 Steps S902 to S910 show how the target scale and size information of the target light map corresponding to each combination method are determined. Next, the number of effective pixels in the second virtual plane corresponding to each combination method is compared, and the combination method with the highest number of effective pixels is determined as the target combination method. Multiple target virtual objects are then packaged according to the target combination method, and a target light map that matches the target scale and size corresponding to the multiple target virtual objects is generated.
[0280] Through the above-described embodiments of this application, when there are multiple virtual objects to be baked, multiple object combinations can be obtained through the above-described embodiments of this application, and according to... Figure 9 The implementation shown determines the number of effective pixels corresponding to each object combination, and then determines the optimal object combination based on the comparison result of the number of effective pixels, thereby improving the efficiency of packaging and baking virtual objects to be baked in the virtual scene and increasing the information density of the light map.
[0281] In an optional implementation, this application also provides a method for rendering virtual objects, including:
[0282] S1, obtain a target lighting map that matches the target virtual scene, wherein the target lighting map is determined based on a second virtual plane, the second virtual plane is a target object region determined from a first virtual plane, the first virtual plane includes a target object region and an auxiliary object region, the target object region matches at least one target virtual object, and the auxiliary object region matches an auxiliary virtual object;
[0283] S2, obtain a set of position information matching the target light map, wherein the set of position information includes target offset information and target scaling information corresponding to at least one target virtual object respectively;
[0284] S3, when a rendering instruction for the current virtual object in at least one target virtual object is detected, the current region bounding box is determined from the target lightmap based on the target offset information and target scaling information corresponding to the current virtual object;
[0285] S4: Render the current virtual object in the virtual scene based on the lighting information indicated by the current region bounding box.
[0286] It is understood that the above implementation method can be applied to clients that can render and display virtual scenes in real time, such as game clients, AR application clients, and VR application clients.
[0287] Taking a game client as an example, when rendering game scenes, the above-mentioned methods can be used... Figure 9 The JSON file generated by the illustrated implementation is loaded, and the lightmaps within it are applied to the scene. This JSON file stores the scale and offset parameters of various virtual objects in the game scene. During the rendering process of a specific virtual object, the corresponding texture area can be retrieved from the lightmap based on the scale and offset parameters and applied to the corresponding static virtual model, thereby ensuring that these models are correctly positioned in the lightmap.
[0288] Specifically, first, a JSON file containing lightmap information is read; then, the target lightmap data in the file is assigned to each virtual object in the scene.
[0289] During the process of setting static model parameters, it is possible to determine whether to obtain the corresponding lightmap for rendering based on the scaling and offset information of each static object in the scene, according to the display status of each static object.
[0290] The above method for dynamically rendering static objects in a virtual scene can be implemented as indicated by the following pseudocode snippet:
[0291]
[0292] In the above implementation, if the current virtual object needs to be rendered in the virtual scene, it is first made visible by calling the SetActive(true) method;
[0293] Next, via GetComponent <meshrenderer>The `()` method retrieves the MeshRenderer component of the static object.
[0294] Then, set a new lightmap index, mr.lightmapIndex, for this MeshRenderer component to point to the correct lightmap area.
[0295] Finally, based on the scaling and offset parameters provided in the JSON file, adjust the corresponding properties of MeshRenderer to ensure that the corresponding lighting information is found in the accurate position and area of the target lightmap. Specifically, when setting the ScaleOffset property of the MeshRenderer component, relevant information can be obtained from the JSON file through the res[i] data, where x, y, z, and w can indicate the values of the obtained scaling and offset parameters, respectively.
[0296] The following combination Figure 12 The rendering process of virtual objects is explained in detail.
[0297] First, execute S1202 to obtain a list of objects, List; then execute S1204 to retrieve the values List[i] from the list List in order of index i.
[0298] Execute judgment S1206 to check if the list traversal is complete; if the traversal is complete, indicate that the rendering information corresponding to each virtual object has been configured, and then execute S1208 to return a new object list List;
[0299] If the traversal is not complete, execute S1208-1 to set the current object to be visible; S1208-2 to set a new lightmap index; S1208-3 to set a new scale and offset; S1208-4 to get the next index i; then return to step S1204.
[0300] By following the steps above, when rendering the current virtual object is required, the static model in the scene can be displayed correctly based on the accurate offset and scaling information in the target lightmap, thereby achieving a high-quality dynamic scene rendering effect.
[0301] The lightmap generation method and virtual object rendering method provided in the above embodiments of this application offer a pre-baked, dynamically loaded lightmap optimization method suitable for virtual scene rendering engines. Specifically, a static scene can be obtained, and by pre-determining some fixed rectangular sizes, static objects within the scene requiring lightmap baking are generated as new baking proxy models for each rectangular size not exceeding the video memory budget. To ensure that the final generated lightmap has a pre-fixed rectangular size, an auxiliary virtual object can be added to the static scene, making the objects in the original scene appear as pre-defined rectangular proportions in the lightmap.
[0302] Next, the UV mapping of the baked proxy model is automatically generated using the object unpacking method. The actual number of pixels used by the current baked proxy model is calculated. Then, the above operation is performed on several pre-determined rectangular sizes, and the final actual number of pixels used for each rectangular size is calculated. The model with the highest actual number of pixels used is selected as the actual baked proxy model for the current scene.
[0303] During lightmap generation, a reference lightmap is generated through light baking. The target lightmap is then obtained by cropping the reference lightmap, which is a pre-defined rectangle. Next, the lightmap and the ScaleAndOffset of each object in the baked proxy model are saved. The final output is the saved lightmap and the ScaleAndOffset of each object in the texture proxy model. Finally, when loading the scene, the lightmap and ScaleAndOffset are dynamically assigned to each object, achieving dynamic lightmap loading.
[0304] By implementing the above methods, the use of video memory is effectively controlled and resource waste is avoided by pre-determining the rectangle size and selecting the model with the highest actual number of pixels used. In addition, dynamically loading the lightmap and ScaleAndOffset parameters reduces the amount of computation during scene loading and improves loading efficiency.
[0305] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the present invention is not limited to the described order of actions, because according to the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to the present invention.
[0306] According to another aspect of the present invention, an apparatus for generating a lightmap for implementing the above-described lightmap generation method is also provided. For example... Figure 13 As shown, the device includes:
[0307] Adding unit 1302 is used to add auxiliary virtual objects in the current virtual scene, wherein the virtual scene includes at least one target virtual object to be baked;
[0308] The expansion unit 1304 is used to perform an object expansion operation on the auxiliary virtual object and at least one target virtual object to obtain a first virtual plane, wherein the first virtual plane includes a target object region that matches at least one target virtual object and an auxiliary object region that matches the auxiliary virtual object.
[0309] The determining unit 1306 is used to determine the target object region in the first virtual plane as the second virtual plane when the auxiliary object region meets the target conditions.
[0310] Baking unit 1308 is used to determine a target light map based on the second virtual plane, wherein the target light map is used to render at least one virtual object in the virtual scene.
[0311] Optionally, the adding unit 1302 includes: an acquisition module, configured to acquire the surface area parameters corresponding to at least one of the target virtual objects respectively; a determination module, configured to determine a reference surface area parameter based on the summation of at least one of the surface area parameters; and an adding module, configured to add the auxiliary virtual object of the target shape to the current virtual scene based on the reference surface area parameter, wherein the current surface area parameter corresponding to the auxiliary virtual object is less than or equal to the reference surface area parameter.
[0312] Optionally, the acquisition module is used to: determine the surface area parameter based on the grid area of the plurality of object grids corresponding to the target virtual object; or determine the surface area parameter based on the bounding box area of the reference bounding box corresponding to the target virtual object, wherein the reference bounding box is used to accommodate the plurality of object grids corresponding to the target virtual object.
[0313] Optionally, the above-mentioned adding module is used to: obtain target size information, wherein the target size information is used to indicate the aspect ratio of the target object region, and the target object region is a first rectangular region in the first virtual plane; determine auxiliary size information of the auxiliary object region according to the texture size information corresponding to the first virtual plane and the target size information, wherein the auxiliary object region is a second rectangular region in the first virtual plane, and the target object region and the auxiliary object region form the first virtual plane with equal length and width; add the auxiliary virtual object of the target shape in the current virtual scene according to the reference surface area parameter, wherein the target shape of the auxiliary virtual object matches the auxiliary size information.
[0314] Optionally, the above-mentioned lightmap generation apparatus further includes: a condition matching unit, configured to determine that the auxiliary object region satisfies the target condition when the long side of the auxiliary object region matches the texture edge of the first virtual plane and the area ratio of the target object region to the auxiliary object region is greater than or equal to a target threshold, wherein the target threshold is determined based on the historical ratio corresponding to each of multiple historical object unfolding operations; to determine that the auxiliary object region does not satisfy the target condition when the long side of the auxiliary object region matches the texture edge of the first virtual plane and the area ratio of the target object region to the auxiliary object region is less than the target threshold; and to determine that the auxiliary object region does not satisfy the target condition when the long side of the auxiliary object region does not match the first virtual plane.
[0315] Optionally, the above-mentioned lightmap generation apparatus is further configured to: update the reference surface area parameter when the auxiliary object region does not meet the target conditions, wherein the updated reference surface area parameter is smaller than the original reference surface area parameter; add the auxiliary virtual object of the target shape in the current virtual scene according to the updated reference surface area parameter; and determine the target lightmap according to the updated auxiliary virtual object.
[0316] Optionally, the above-mentioned lightmap generation apparatus is further configured to: obtain a vertex set corresponding to at least one first virtual object in the first virtual scene; determine a mesh set corresponding to at least one first virtual object based on the at least one vertex set; determine mesh normals corresponding to multiple mesh objects in the at least one mesh set; and determine the current virtual scene based on the vertex set corresponding to at least one first virtual object, wherein the mesh set includes a mesh normal set of multiple mesh normals.
[0317] Optionally, the baking unit 1308 is configured to: perform a baking operation on the current virtual scene according to the first virtual plane to obtain a reference light map when the proportion of the number of effective pixels corresponding to the effective object area in the second virtual plane is greater than or equal to the target value; and determine the target light map according to the map area in the reference light map that matches the second virtual plane.
[0318] Optionally, the baking unit 1308 is further configured to: obtain the target pixel count; determine multiple candidate texture size information based on the target pixel threshold, wherein the number of illumination pixels included in the candidate light map corresponding to the candidate texture size information is less than or equal to the target pixel count; determine auxiliary size information corresponding to each of the multiple candidate light map sizes, wherein the auxiliary size information is used to indicate the aspect ratio of the auxiliary object region; determine the second virtual plane corresponding to each of the multiple candidate virtual scenes based on the multiple auxiliary size information, wherein the multiple candidate virtual scenes include the current virtual scene; and determine the target value based on the number of effective pixels corresponding to each of the multiple second virtual planes.
[0319] Optionally, the baking unit 1308 is further configured to: obtain the sum of the grid areas of the plurality of virtual grids included in the second virtual plane; determine a first area ratio of the plurality of virtual grids in the first virtual plane based on the sum of the grid areas; determine a second area ratio of the plurality of virtual grids in the second virtual plane based on the ratio between the first virtual area of the first virtual plane and the second virtual area of the second virtual plane; and determine the number of effective pixels corresponding to the second virtual plane based on the second area ratio and the candidate texture size information matching the second virtual plane.
[0320] Optionally, the above-mentioned lightmap generation apparatus further includes: a position acquisition unit, configured to determine a bounding box corresponding to each of the at least one of the target virtual objects based on the object regions matched by each of the at least one of the target virtual objects in the second virtual plane, wherein the region range of the bounding box includes the object regions; and to determine target offset information and target scaling information corresponding to each of the at least one of the target virtual objects based on the at least one of the bounding boxes, wherein the target offset information and the target scaling information are used to determine lighting information matching the target virtual objects from the target lightmap.
[0321] Optionally, the position acquisition unit is configured to: determine the first coordinate of the first vertex of the bounding box in the second virtual plane as the target offset information; and determine the target scaling information based on the coordinate difference between the second coordinate of the second vertex of the bounding box in the second virtual plane and the first coordinate, wherein the first vertex and the second vertex are two vertices on the diagonal of the bounding box.
[0322] Optionally, the above-mentioned lightmap generation apparatus further includes: a filtering unit, configured to, when the target virtual scene includes multiple target virtual objects, determine multiple object combinations corresponding to the multiple target virtual objects, wherein the object combination includes at least one of the target virtual objects; determine the second virtual plane corresponding to each of the multiple object combinations; determine a target object combination from the multiple object combinations based on the comparison results between the multiple second virtual planes; and determine the target lightmap based on the target object combination.
[0323] Optionally, in this embodiment, the implementation of each of the above-mentioned unit modules can be referred to the above-mentioned method embodiments, which will not be repeated here.
[0324] According to another aspect of the present invention, an electronic device for implementing the above-described method for generating a lightmap is also provided. This electronic device may be... Figure 14 The terminal device or server shown. This embodiment uses this electronic device as an example for illustration. Figure 14 As shown, the electronic device includes a memory 1402 and a processor 1404. The memory 1402 stores a computer program, and the processor 1404 is configured to execute the steps of any of the above method embodiments via the computer program.
[0325] Optionally, in this embodiment, the aforementioned electronic device may be located in at least one of a plurality of network devices in a computer network.
[0326] Optionally, in this embodiment, the processor can be configured to perform the following steps via a computer program:
[0327] S1, add auxiliary virtual objects to the current virtual scene, wherein the virtual scene includes at least one target virtual object to be baked;
[0328] S2, Perform an object expansion operation on the auxiliary virtual object and at least one target virtual object to obtain a first virtual plane, wherein the first virtual plane includes a target object region matching at least one target virtual object and an auxiliary object region matching the auxiliary virtual object;
[0329] S3, if the auxiliary object region meets the target conditions, the target object region in the first virtual plane is determined as the second virtual plane;
[0330] S4, determine a target lighting map based on the second virtual plane, wherein the target lighting map is used to render at least one virtual object in the virtual scene.
[0331] Alternatively, as those skilled in the art will understand, Figure 14 The structure shown is for illustrative purposes only. Electronic devices can also be smartphones (such as Android phones, iOS phones, etc.), tablets, PDAs, mobile internet devices (MIDs), PADs, and other terminal devices. Figure 14 This does not limit the structure of the aforementioned electronic devices or electronic equipment. For example, electronic devices or electronic equipment may also include components that are more... Figure 14 The more or fewer components shown (such as network interfaces, etc.), or having the same Figure 14 The different configurations shown.
[0332] The memory 1402 can be used to store software programs and modules, such as the program instructions / modules corresponding to the method and apparatus for generating lightmaps in this embodiment of the invention. The processor 1404 executes various functional applications and data processing by running the software programs and modules stored in the memory 1402, thereby realizing the aforementioned method for generating lightmaps. The memory 1402 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 1402 may further include memory remotely located relative to the processor 1404, and these remote memories can be connected to the terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. Specifically, the memory 1402 may be used, but is not limited to, to store information such as various elements in the scene and lightmap generation information. As an example, such as... Figure 14 As shown, the memory 1402 may include, but is not limited to, the adding unit 1302, the unfolding unit 1304, the determining unit 1306, and the baking unit 1308 from the lightmap generation apparatus described above. Furthermore, it may include, but is not limited to, other module units from the lightmap generation apparatus described above, which will not be elaborated upon in this example.
[0333] Optionally, the transmission device 1406 described above is used to receive or send data via a network. Specific examples of the network described above may include wired networks and wireless networks. In one example, the transmission device 1406 includes a Network Interface Controller (NIC), which can be connected to other network devices and routers via a network cable to communicate with the Internet or a local area network. In another example, the transmission device 1406 is a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0334] In addition, the aforementioned electronic device also includes: a display 1408 for displaying a virtual scene in the interface; and a connection bus 1410 for connecting various module components in the aforementioned electronic device.
[0335] According to another aspect of the present invention, a rendering apparatus for a virtual object is also provided for implementing the above-described rendering method for virtual objects. For example... Figure 15 As shown, the device includes:
[0336] The first acquisition unit 1502 is used to acquire a target lighting map that matches the target virtual scene. The target lighting map is determined based on a second virtual plane. The second virtual plane is a target object region determined from a first virtual plane. The first virtual plane includes the target object region and an auxiliary object region. The target object region matches at least one target virtual object, and the auxiliary object region matches an auxiliary virtual object.
[0337] The second acquisition unit 1504 is used to acquire a set of position information matching the target lighting map, wherein the set of position information includes target offset information and target scaling information corresponding to at least one of the target virtual objects respectively;
[0338] The determining unit 1506 is configured to determine the current region bounding box from the target light map based on the target offset information and the target scaling information corresponding to the current virtual object when a rendering instruction for at least one of the aforementioned target virtual objects is detected.
[0339] The rendering unit 1508 is used to render the current virtual object in the virtual scene according to the lighting information indicated by the current region bounding box.
[0340] Optionally, in this embodiment, the implementation of each of the above-mentioned unit modules can be referred to the above-mentioned method embodiments, which will not be repeated here.
[0341] According to another aspect of the present invention, an electronic device for implementing the above-described rendering method for virtual objects is also provided. This electronic device may be... Figure 16 The terminal device or server shown. This embodiment uses this electronic device as an example for illustration. Figure 16 As shown, the electronic device includes a memory 1602 and a processor 1604. The memory 1602 stores a computer program, and the processor 1604 is configured to execute the steps of any of the above method embodiments via the computer program.
[0342] Optionally, in this embodiment, the aforementioned electronic device may be located in at least one of a plurality of network devices in a computer network.
[0343] Optionally, in this embodiment, the processor can be configured to perform the following steps via a computer program:
[0344] S1, obtain a target lighting map that matches the target virtual scene, wherein the target lighting map is determined based on a second virtual plane, the second virtual plane is a target object region determined from a first virtual plane, the first virtual plane includes the target object region and an auxiliary object region, the target object region matches at least one target virtual object, and the auxiliary object region matches an auxiliary virtual object.
[0345] S2, obtain a set of position information that matches the above-mentioned target lighting map, wherein the set of position information includes target offset information and target scaling information corresponding to at least one of the above-mentioned target virtual objects respectively;
[0346] S3, when a rendering instruction for the current virtual object in at least one of the aforementioned target virtual objects is detected, the current region bounding box is determined from the aforementioned target lightmap based on the aforementioned target offset information and the aforementioned target scaling information corresponding to the aforementioned current virtual object;
[0347] S4. Render the current virtual object in the virtual scene according to the lighting information indicated by the current region bounding box.
[0348] Alternatively, as those skilled in the art will understand, Figure 16 The structure shown is for illustrative purposes only. Electronic devices can also be smartphones (such as Android phones, iOS phones, etc.), tablets, PDAs, mobile internet devices (MIDs), PADs, and other terminal devices. Figure 16 This does not limit the structure of the aforementioned electronic devices or electronic equipment. For example, electronic devices or electronic equipment may also include components that are more... Figure 16 The more or fewer components shown (such as network interfaces, etc.), or having the same Figure 16 The different configurations shown.
[0349] The memory 1602 can be used to store software programs and modules, such as the program instructions / modules corresponding to the virtual object rendering method and apparatus in this embodiment of the invention. The processor 1604 executes various functional applications and data processing by running the software programs and modules stored in the memory 1602, thereby implementing the aforementioned virtual object rendering method. The memory 1602 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 1602 may further include memory remotely located relative to the processor 1604, and these remote memories can be connected to the terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. Specifically, the memory 1602 may be used, but is not limited to, to store information such as the rendering information of various elements in the scene and virtual objects. As an example, such as... Figure 16 As shown, the memory 1602 may include, but is not limited to, the first acquisition unit 1502, the second acquisition unit 1504, the determination unit 1506, and the rendering unit 1508 of the virtual object rendering device. Furthermore, it may include, but is not limited to, other module units of the virtual object rendering device, which will not be elaborated upon in this example.
[0350] Optionally, the transmission device 1606 described above is used to receive or send data via a network. Specific examples of the network described above may include wired networks and wireless networks. In one example, the transmission device 1606 includes a Network Interface Controller (NIC), which can be connected to other network devices and a router via a network cable to communicate with the Internet or a local area network. In another example, the transmission device 1606 is a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0351] In addition, the aforementioned electronic device also includes: a display 1608 for displaying a virtual scene in the interface; and a connection bus 1610 for connecting various module components in the aforementioned electronic device.
[0352] In other embodiments, the aforementioned terminal device or server can be a node in a distributed system, wherein the distributed system can be a blockchain system, which is a distributed system formed by connecting multiple nodes through network communication. The nodes can form a peer-to-peer network, and any form of computing device, such as a server, terminal, or other electronic device, can become a node in the blockchain system by joining this peer-to-peer network.
[0353] According to one aspect of this application, a computer program product is provided, comprising a computer program / instructions containing program code for performing the methods shown in the flowchart. In such embodiments, the computer program can be downloaded and installed from a network via a communication component, and / or installed from a removable medium. When the computer program is executed by a central processing unit, it performs various functions provided in embodiments of this application.
[0354] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0355] According to one aspect of this application, a computer-readable storage medium is provided, wherein a processor of a computer device reads computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, causing the computer device to perform the rendering method of the virtual object described above.
[0356] Optionally, in this embodiment, the computer-readable storage medium may be configured to store a computer program for performing the following steps:
[0357] S1, add auxiliary virtual objects to the current virtual scene, wherein the virtual scene includes at least one target virtual object to be baked;
[0358] S2, Perform an object expansion operation on the auxiliary virtual object and at least one target virtual object to obtain a first virtual plane, wherein the first virtual plane includes a target object region matching at least one target virtual object and an auxiliary object region matching the auxiliary virtual object;
[0359] S3, if the auxiliary object region meets the target conditions, the target object region in the first virtual plane is determined as the second virtual plane;
[0360] S4, determine a target lighting map based on the second virtual plane, wherein the target lighting map is used to render at least one virtual object in the virtual scene.
[0361] Optionally, in this embodiment, the computer-readable storage medium may also be configured to store a computer program for performing the following steps:
[0362] S1, obtain a target lighting map that matches the target virtual scene, wherein the target lighting map is determined based on a second virtual plane, the second virtual plane is a target object region determined from a first virtual plane, the first virtual plane includes the target object region and an auxiliary object region, the target object region matches at least one target virtual object, and the auxiliary object region matches an auxiliary virtual object.
[0363] S2, obtain a set of position information that matches the above-mentioned target lighting map, wherein the set of position information includes target offset information and target scaling information corresponding to at least one of the above-mentioned target virtual objects respectively;
[0364] S3, when a rendering instruction for the current virtual object in at least one of the aforementioned target virtual objects is detected, the current region bounding box is determined from the aforementioned target lightmap based on the aforementioned target offset information and the aforementioned target scaling information corresponding to the aforementioned current virtual object;
[0365] S4. Render the current virtual object in the virtual scene according to the lighting information indicated by the current region bounding box.
[0366] Optionally, in this embodiment, those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing the hardware related to the terminal device. The program can be stored in a computer-readable storage medium, which may include: flash drive, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0367] If the integrated units in the above embodiments are implemented as software functional units and sold or used as independent products, they can be stored in the aforementioned computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause one or more computer devices (which may be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.
[0368] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0369] In the several embodiments provided in this application, it should be understood that the disclosed client can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, indirect coupling or communication connection between units or modules, and may be electrical or other forms.
[0370] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0371] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0372] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.< / meshrenderer>
Claims
1. A method for generating a lightmap, characterized in that, include: Add auxiliary virtual objects to the current virtual scene, wherein the current virtual scene includes at least one target virtual object to be baked; An object expansion operation is performed on the auxiliary virtual object and at least one of the target virtual objects to obtain a first virtual plane, wherein the first virtual plane includes a target object region that matches at least one of the target virtual objects and an auxiliary object region that matches the auxiliary virtual object; If the auxiliary object region meets the target conditions, the target object region in the first virtual plane is determined as the second virtual plane; A target lightmap is determined based on the second virtual plane, wherein the target lightmap is used to render at least one virtual object in the virtual scene.
2. The method according to claim 1, characterized in that, Add auxiliary virtual objects to the current virtual scene, including: Obtain the surface area parameters corresponding to at least one of the target virtual objects respectively; A reference surface area parameter is determined based on the summation of at least one of the surface area parameters. Add the auxiliary virtual object of the target shape in the current virtual scene according to the reference surface area parameter, wherein the current surface area parameter corresponding to the auxiliary virtual object is less than or equal to the reference surface area parameter.
3. The method according to claim 2, characterized in that, The step of obtaining at least one surface area parameter corresponding to each of the target virtual objects includes one of the following: The surface area parameter is determined based on the grid area of multiple object grids corresponding to the target virtual object; The surface area parameter is determined based on the bounding box area of the reference bounding box corresponding to the target virtual object, wherein the reference bounding box is used to accommodate multiple object meshes corresponding to the target virtual object.
4. The method according to claim 2, characterized in that, The step of adding the auxiliary virtual object of the target shape in the current virtual scene according to the reference surface area parameter includes: Obtain target size information, wherein the target size information is used to indicate the aspect ratio of the target object region, and the target object region is a first rectangular region in the first virtual plane; Based on the texture size information corresponding to the first virtual plane and the target size information, the auxiliary size information of the auxiliary object area is determined, wherein the auxiliary object area is a second rectangular area in the first virtual plane, and the target object area and the auxiliary object area form the first virtual plane with equal length and width; The auxiliary virtual object of the target shape is added to the current virtual scene according to the reference surface area parameter, wherein the target shape of the auxiliary virtual object matches the auxiliary size information.
5. The method according to claim 4, characterized in that, Before determining the target object region in the first virtual plane as the second virtual plane when the auxiliary object region meets the target conditions, the method further includes: If the long side of the auxiliary object region matches the texture edge of the first virtual plane, and the area ratio of the target object region to the auxiliary object region is greater than or equal to the target threshold, the auxiliary object region is determined to meet the target condition. The target threshold is determined based on the historical ratio corresponding to each of the multiple historical object expansion operations. If the long side of the auxiliary object region matches the texture edge of the first virtual plane, and the area ratio of the target object region to the auxiliary object region is less than the target threshold, then the auxiliary object region is determined not to meet the target condition. If the long side of the auxiliary object region does not match the first virtual plane, it is determined that the auxiliary object region does not meet the target condition.
6. The method according to claim 4, characterized in that, After adding the auxiliary virtual object of the target shape to the current virtual scene according to the reference surface area parameter, the method further includes: If the auxiliary object region does not meet the target condition, the reference surface area parameter is updated, wherein the updated reference surface area parameter is smaller than the original reference surface area parameter. Add the auxiliary virtual object of the target shape to the current virtual scene according to the updated reference surface area parameters; The target lightmap is determined based on the updated auxiliary virtual object.
7. The method according to claim 2, characterized in that, Before adding auxiliary virtual objects to the current virtual scene, the process also includes: Obtain the vertex set corresponding to at least one first virtual object in the first virtual scene; At least one mesh set corresponding to each of the first virtual objects is determined based on at least one of the vertex sets; Determine the mesh normals corresponding to each of the multiple mesh objects in at least one of the mesh sets; The current virtual scene is determined based on the vertex set corresponding to at least one of the first virtual objects, and the mesh set, which includes a mesh normal set of multiple mesh normals.
8. The method according to claim 1, characterized in that, The step of determining the target lighting map based on the second virtual plane includes: If the number of valid pixels corresponding to the valid object region in the second virtual plane is greater than or equal to the target value, a baking operation is performed on the current virtual scene according to the first virtual plane to obtain a reference light map. The target lighting map is determined based on the mapping region in the reference lighting map that matches the second virtual plane.
9. The method according to claim 8, characterized in that, If the number of valid pixels corresponding to the valid object region in the second virtual plane is greater than or equal to the target value, a baking operation is performed on the current virtual scene according to the second virtual plane. Before performing a baking operation on the current virtual scene according to the first virtual plane to obtain the reference lightmap, the process further includes: Get the number of target pixels; Multiple candidate texture size information are determined based on the target pixel threshold, wherein the number of lighting pixels included in the candidate lighting texture corresponding to the candidate texture size information is less than or equal to the number of target pixels; Determine auxiliary size information corresponding to each of the multiple candidate lightmap sizes, wherein the auxiliary size information is used to indicate the aspect ratio of the auxiliary object region; Based on the multiple auxiliary size information, a second virtual plane corresponding to each of the multiple candidate virtual scenes is determined, wherein the multiple candidate virtual scenes include the current virtual scene; The target value is determined based on the number of effective pixels corresponding to each of the multiple second virtual planes.
10. The method according to claim 8, characterized in that, If the number of valid pixels corresponding to the valid object region in the second virtual plane is greater than or equal to the target value, before performing a baking operation on the current virtual scene according to the first virtual plane to obtain the reference lightmap, the process further includes: Obtain the sum of the grid areas of the multiple virtual grids included in the second virtual plane; Based on the sum of the grid areas, determine the first area percentage of the multiple virtual grids in the first virtual plane; Based on the ratio between the first virtual area of the first virtual plane and the second virtual area of the second virtual plane, the second area ratio of the plurality of virtual grids in the second virtual plane is determined; Based on the second area ratio and the candidate texture size information matching the second virtual plane, the number of effective pixels corresponding to the second virtual plane is determined.
11. The method according to claim 1, characterized in that, After determining the target lighting map based on the second virtual plane, the process also includes: Based on the object regions that match at least one of the target virtual objects in the second virtual plane, a region bounding box corresponding to each of the at least one virtual object is determined, wherein the region range of the region bounding box includes the object region; Based on at least one of the region bounding boxes, target offset information and target scaling information corresponding to at least one of the target virtual objects are determined, wherein the target offset information and the target scaling information are used to determine lighting information matching the target virtual object from the target lightmap.
12. The method according to claim 11, characterized in that, Based on at least one of the said region bounding boxes, determine the target offset information and target scaling information corresponding to each of the at least one said target virtual object, including: The first coordinate of the first vertex of the region bounding box in the second virtual plane is determined as the target offset information; The target scaling information is determined based on the coordinate difference between the second coordinate of the second vertex of the region bounding box in the second virtual plane and the first coordinate, wherein the first vertex and the second vertex are two vertices on the diagonal of the region bounding box.
13. The method according to any one of claims 1 to 12, characterized in that, Also includes: In the case where the target virtual scene includes multiple target virtual objects, multiple object combinations corresponding to the multiple target virtual objects are determined, wherein the object combination includes at least one of the target virtual objects; Determine the second virtual plane corresponding to each of the multiple object combinations; Based on the comparison results between the multiple second virtual planes, a target object combination is determined from the multiple object combinations; The target lighting map is determined based on the target object combination.
14. A method for rendering virtual objects, characterized in that, include: Obtain a target lighting map that matches the target virtual scene, wherein the target lighting map is determined based on a second virtual plane, the second virtual plane is a target object region determined from a first virtual plane, the first virtual plane includes the target object region and an auxiliary object region, the target object region matches at least one target virtual object, and the auxiliary object region matches an auxiliary virtual object; Obtain a set of position information that matches the target light map, wherein the set of position information includes target offset information and target scaling information corresponding to at least one of the target virtual objects respectively; Upon detecting a rendering instruction for the current virtual object in at least one of the target virtual objects, the current region bounding box is determined from the target lightmap based on the target offset information and the target scaling information corresponding to the current virtual object; The current virtual object in the virtual scene is rendered based on the lighting information indicated by the current region bounding box.
15. An apparatus for generating a lightmap, characterized in that, include: An adding unit is used to add auxiliary virtual objects to the current virtual scene, wherein the virtual scene includes at least one target virtual object to be baked; An expansion unit is configured to perform an object expansion operation on the auxiliary virtual object and at least one target virtual object to obtain a first virtual plane, wherein the first virtual plane includes a target object region matching at least one target virtual object and an auxiliary object region matching the auxiliary virtual object; The determining unit is configured to determine the target object region in the first virtual plane as the second virtual plane when the auxiliary object region meets the target conditions; A baking unit is configured to determine a target lightmap based on the second virtual plane, wherein the target lightmap is used to render at least one virtual object in the virtual scene.
16. A rendering apparatus for virtual objects, characterized in that, include: The first acquisition unit is used to acquire a target lighting map that matches the target virtual scene. The target lighting map is determined based on a second virtual plane. The second virtual plane is a target object region determined from a first virtual plane. The first virtual plane includes the target object region and an auxiliary object region. The target object region matches at least one target virtual object, and the auxiliary object region matches an auxiliary virtual object. The second acquisition unit is used to acquire a set of position information matching the target lighting map, wherein the set of position information includes target offset information and target scaling information corresponding to at least one of the target virtual objects respectively; A determining unit is configured to, upon detecting a rendering instruction for a current virtual object in at least one of the target virtual objects, determine the current region bounding box from the target lightmap based on the target offset information and the target scaling information corresponding to the current virtual object; The rendering unit is used to render the current virtual object in the virtual scene according to the lighting information indicated by the current region bounding box.
17. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein the program, when executed, performs the method of any one of claims 1 to 13 or 14.
18. A computer program product comprising a computer program / instructions, characterized in that, When executed by a processor, the computer program / instructions implement the steps of the method described in any one of claims 1 to 13 or 14.
19. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to execute the method of any one of claims 1 to 13 or 14 through the computer program.
