Virtual scene rendering method and device, terminal equipment and medium

By loading prefab components and binding lighting information in SLG games, and combining them with a planar shadow projection algorithm, the problem of high performance requirements for dynamic lighting and shadow calculation in SLG games is solved, achieving high-quality lighting effects and a good gaming experience on low-configuration devices.

CN120900206APending Publication Date: 2025-11-07SHENZHEN YOUMI TECHNOLOGY CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202511147467.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-15
Publication Date
2025-11-07

AI Technical Summary

Technical Problem

In existing SLG games, the high computational requirements of real-time dynamic lighting and shadow technology lead to screen stuttering. On the other hand, game scenes using pre-baked lighting and shadow technology lack lighting and shadows for dynamic objects, affecting the player's gaming experience.

Method used

By loading pre-built prefab components, the lighting information of static objects is bound to the prefab, and a planar shadow projection algorithm is used to render shadows on dynamic objects, thus achieving the fusion of baked lighting for static objects and real-time lighting for dynamic objects.

Benefits of technology

High-quality virtual scene lighting effects were achieved on low-configuration devices, enhancing the player's gaming experience, reducing computational load and error rate, and improving development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120900206A_ABST
    Figure CN120900206A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of virtual reality rendering, in particular to a virtual scene rendering method and device, terminal equipment and a medium. The method comprises the following steps: loading a pre-constructed preform assembly; the preform assembly comprises at least one dynamic object and at least one static object in the scene to be rendered; illumination information of all static objects is bound on the prefabricated body assembly; performing shadow rendering on the at least one static object according to the bound illumination information; and performing shadow rendering on the at least one dynamic object by adopting a plane shadow projection algorithm. According to the method, the illumination baking information is directly mounted on the preform assembly, so that the illumination information can be obtained without baking the static object in the scene again, shadow rendering is performed on the dynamic object by adopting the plane shadow projection algorithm, the dynamic object also has real-time illumination, and the scene is more real. Therefore, the dynamic shadow and the baking shadow in the existing virtual scene can be effectively fused, and the playing experience of a low-configuration equipment user is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of virtual reality rendering, in particular to a virtual scene rendering method and device, a terminal equipment and a medium. BACKGROUND

[0002] SLG is the abbreviation of "Simulation & Strategy Game", and its full name in Chinese is "Strategy Game" or "Strategy Simulation Game".

[0003] A more realistic light source is generally required in the current SLG game, and the "real-time dynamic light and shadow" technology or the "pre-baking light and shadow" technology is usually used to present the light and shadow effect in the game scene. Although the game scene using the "real-time dynamic light and shadow" technology can bring a good experience to the player, it requires high game device configuration and high computing performance, otherwise it is easy to cause frame freezing. The game scene using the "pre-baking light and shadow" technology reduces the requirement of game device configuration, but the dynamic objects in the game scene do not have corresponding light and shadow, which seriously affects the playing experience of the player. SUMMARY

[0004] Therefore, the present application provides a virtual scene rendering method, device, terminal equipment and medium, which can effectively fuse the dynamic shadow and the baked shadow in the existing virtual scene, and improve the playing experience of the user of the low-configuration device.

[0005] In a first aspect, the present application provides a virtual scene rendering method, which comprises: loading a prefabricated component pre-constructed; the prefabricated component comprises at least one dynamic object and at least one static object in a scene to be rendered; the prefabricated component is bound with the light information of all the static objects; performing shadow rendering on the at least one static object according to the bound light information; performing shadow rendering on the at least one dynamic object by using a planar shadow projection algorithm.

[0006] In some embodiments, the method constructs the prefabricated component in the following way: finding all target objects in the scene that mount a preset baking script, and executing the baking script; for each target object, performing light baking on at least one static object in the target object through the baking script, and binding the light information of the at least one static object baked to the corresponding target object; storing each target object with bound light information as a corresponding prefabricated component.

[0007] In some embodiments, the way of constructing the prefabricated body assembly further comprises: Before baking the target object, the target object to be baked and its included sub-objects are marked as static meshes, obtaining at least one static object; The light mode of the scene where the prefabricated body assembly is located is set to a baking mode or a mixed mode; Mount the baking script for each target object.

[0008] In some embodiments, the light information includes renderer information, color light maps and normal light maps; The light baking of at least one static object in the target object by the baking script, and the binding of the light information of the at least one static object obtained by baking to the corresponding target object, comprises: The baking script creates a local renderer container for storing renderer information, a local color light map container for storing color light maps and a local normal light map container for storing normal light maps for the target object associated with the binding, and after the baking is completed, all renderers of the corresponding static object are obtained, all color light maps and all normal light maps are obtained according to the light map index, and stored in the corresponding container, and each container is bound to the corresponding target object.

[0009] In some embodiments, the obtaining of all color light maps and all normal light maps according to the light map index comprises: For each renderer, check whether the light map index of the renderer is valid; if valid, obtain the color light map of the renderer according to the light map index; Check whether the light map offset scale of the renderer is valid; if valid, obtain the normal light map of the renderer according to the light map index.

[0010] In some embodiments, the shadow rendering of the at least one static object according to the bound light information comprises: For each static object, obtain each renderer of the static object from the local renderer container bound to the corresponding target object, and obtain the corresponding color light map and normal light map from the local color light map container and local normal light map container according to the light map index carried by each renderer; Based on the color light map and the normal light map, the surface of the static object is subjected to shadow mixing processing in the pixel shader associated with the static object, and the rendering result is output.

[0011] In some embodiments, the shadow rendering of the at least one dynamic object by using the planar shadow projection algorithm comprises: obtaining a main light source direction and a projection matrix in a world coordinate system; transforming model vertices of the dynamic object to a light source space in a vertex shader by using the main light source direction and the projection matrix; performing one drawing on a model of the dynamic object based on the model vertices in the light source space to obtain single-color and transparent shadow information; performing alpha blending on the shadow information and a scene to adjust a color of the shadow and output a rendering result.

[0012] In a second aspect, an embodiment of the present application provides a virtual scene rendering device, comprising: a loading module configured to load a prefabricated body component constructed in advance; the prefabricated body component comprises at least one dynamic object and at least one static object in a scene to be rendered; the prefabricated body component is bound with illumination information of all the static objects; a static object rendering module configured to perform shadow rendering on the at least one static object according to the bound illumination information; a dynamic object rendering module configured to perform shadow rendering on the at least one dynamic object by using a planar shadow projection algorithm.

[0013] In a third aspect, an embodiment of the present application provides a terminal device, which comprises a processor and a memory; the memory stores a computer program; and the processor is configured to execute the computer program to implement the virtual scene rendering method provided in the first aspect of the present application.

[0014] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, which stores a computer program; when the computer program is executed on a processor, the virtual scene rendering method provided in the first aspect of the present application is implemented.

[0015] The embodiments of the present application have the following beneficial effects: Firstly, a prefabricated body component is loaded in the application, the prefabricated body component includes at least one dynamic object and at least one static object, and the prefabricated body component is bound with the lighting information of all the static objects; then, the at least one static object is shadow rendered according to the bound lighting information; finally, the at least one dynamic object is shadow rendered by using a plane shadow projection algorithm. The application directly mounts the lighting baking information to the prefabricated body component, ensures that the static objects in the scene can obtain the lighting information without baking again, and reduces the calculation amount. Meanwhile, the lighting information is unbound from the scene file, the lighting information is statically bound with the prefabricated body, and the error rate is reduced. In addition, the dynamic objects are shadow rendered by using the plane shadow projection algorithm, so that the dynamic objects also have real-time lighting, and the scene is more realistic. Therefore, the application can effectively fuse the dynamic shadow and the baked shadow in the existing virtual scene, and improves the playing experience of the users of the low-configuration devices. BRIEF DESCRIPTION OF DRAWINGS

[0016] In order to more clearly illustrate the technical solutions of the embodiments of the application, the following will briefly introduce the drawings needed to be used in the embodiments. It should be understood that the following drawings only show some of the embodiments of the application, and therefore should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can also be obtained without creative labor on the basis of these drawings.

[0017] Figure 1 A flow chart of a virtual scene rendering method of an embodiment of the application is shown; Figure 2 A scene diagram of scene whitening mentioned in the virtual scene rendering method of an embodiment of the application is shown; Figure 3 A scene diagram of scene blackening mentioned in the virtual scene rendering method of an embodiment of the application is shown; Figure 4 A scene diagram of only baked light mentioned in the virtual scene rendering method of an embodiment of the application is shown; Figure 5 Another scene diagram of only baked light mentioned in the virtual scene rendering method of an embodiment of the application is shown; Figure 6 A scene diagram of simultaneously existing baked light and real-time lighting mentioned in the virtual scene rendering method of an embodiment of the application is shown; Figure 7 A scene diagram of simultaneously existing baked light and real-time lighting realized in the virtual scene rendering method of an embodiment of the application is shown. DETAILED DESCRIPTION

[0018] The technical solutions in the embodiments of the present application will be clearly and completely described with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all of the embodiments of the present application.

[0019] The components of the embodiments of the present application generally described and illustrated herein can be arranged and designed in a variety of different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by a person of ordinary skill in the art without creative work fall within the scope of the present application.

[0020] Hereinafter, the terms "include", "have", and their conjugates used in the various embodiments of the present application are only intended to denote that specific features, numbers, steps, operations, elements, components, or combinations thereof are present, and should not be construed as excluding the presence or addition of one or more other features, numbers, steps, operations, elements, components, or combinations thereof. In addition, the terms "first", "second", "third", and the like are only used to distinguish descriptions, and cannot be understood as indicating or implying relative importance.

[0021] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art to which the various embodiments of the present application belong. The terms (such as those defined in commonly used dictionaries) will be interpreted as having a meaning that is the same as the contextual meaning in the relevant technical field and will not be interpreted as having an idealized or overly formal meaning, unless clearly defined in the various embodiments of the present application.

[0022] Some embodiments of the present application will be described in detail below with reference to the accompanying drawings. The following embodiments and features in the embodiments can be combined with each other without conflict.

[0023] In order to effectively fuse dynamic shadows and baked shadows in an existing virtual scene and improve the playing experience of users of low-configuration devices, the present application provides a virtual scene rendering method and device, a terminal device, and a medium.

[0024] The present application ensures high-quality baked shadow lighting effects of static scenes and real-time dynamic shadows of dynamic objects in a scene, has low requirements for game device configurations, and improves the playing experience of players.

[0025] The virtual scene rendering method will be described below in combination with some specific embodiments.

[0026] Figure 1 A flowchart of the virtual scene rendering method of the embodiments of the present application is shown. Exemplarily, the virtual scene rendering method comprises the following steps: S100, loading a pre-constructed prefab component; the prefab component comprises at least one dynamic object and at least one static object in a scene to be rendered; the prefab component is bound with lighting information of all static objects.

[0027] The prefab component (prefab for short) is a reusable scene object template, the prefab comprises a plurality of sub-objects and is associated together based on a tree structure form, and each sub-object can be marked as a static object or a dynamic object through a marking manner. The dynamic object is an object that can perform a certain action behavior through a script control at runtime of the scene.

[0028] If the development platform adopts unity, then the prefab is a reusable scene object template in Unity, which can be a collection of one or more GameObjects and their components (such as Transform, MeshRenderer, Collider, Script, etc.), and represents an entity with a specific function or appearance.

[0029] In the prior art, the lighting information of a scene is strongly bound with a game scene file scene.unity, and the lighting information of the scene will be incorrect if it is separated from the scene file. In the present application, the lighting information of all static objects under the prefab is bound to the prefab, and the lighting information is decoupled from the scene file to avoid errors in the lighting information. In the prior art, if it is necessary to ensure complete scene baked lighting information, the scene file scene.unity with lighting information needs to be directly loaded, and the pre-baked prefab cannot be loaded alone. The lighting information will be incorrect if the prefab is loaded alone.

[0030] In addition, in the prior art, a scene file scene.unity is directly loaded, although the scene file scene.unity can carry the scene baked light information, but the program side still needs to develop again on the basis of the scene file scene.unity in the subsequent development process, at this time, the secondary development work of the program also has a strong binding with the scene file scene.unity, thereby causing the secondary development work and the baked light information to have a high coupling degree. At this time, if the art side modifies the scene and re-bakes to generate a new scene file, the secondary development work of the program in the original scene file still needs to be redone once in the new scene file, for example, a new mounted prefab in the scene, a newly added other script and the like, thereby causing a low development efficiency. Therefore, decoupling the light information from the scene file can also improve the development efficiency.

[0031] In an implementation, in order to facilitate reuse, the preset function is packaged in the prefab in the embodiment of the application. The method constructs the prefab component in the following manner: S110, before baking the target object, marking the target object and the included sub-objects which need to be baked as static meshes, to obtain at least one static object. Selecting the objects (such as terrain and building) which need to accept light baking and marking as static meshes, for example, in Unity, marking the GameObject (corresponding to the target object or the sub-object) as a “Static” type to realize the “static object” behavior.

[0032] S120, setting the light mode of the scene as a baked mode or a mixed mode.

[0033] The scene can be a scene established by the art side, and the art side creates the prefab and renders the prefab in the scene. The scene can also be used for secondary development of the function by the program side.

[0034] The scene development platform (for example, Unity) supports three light modes (Light Mode): Baked mode, light is completely baked into a light map, and dynamic objects do not accept light (only receive light probe interpolation); Mixed mode, static objects accept baked light, and dynamic objects accept real-time light (such as shadow and directional light); Realtime mode, all light is calculated at runtime, and no light map is used.

[0035] For example, if the scene development platform is Unity, then the target object or the sub-object is ensured to be marked as a static mesh (Static Mesh).

[0036] S130, mount the baking script for each target object. The target object is a primary node object, which can include multiple child objects or no child objects.

[0037] S140, find all target objects in the scene that mount the preset baking script, and execute the baking script. The scene can be a scene created by the art side, or a scene jointly developed by the art side and the program development side. In order to improve development efficiency, in the embodiment of the application, the art side creates a prefab in the scene created by itself and bakes, and then exports the baked prefab and the lighting information obtained by baking. The program side directly uses the exported prefab and the lighting information obtained by baking.

[0038] S150, for each target object, the lighting baking script is used to perform lighting baking on at least one static object in the target object, and the lighting information of the at least one static object obtained by baking is bound to the corresponding target object.

[0039] In other words, the baking script is a script constructed by the application, which is used to perform lighting baking on at least one static object in the target object, and bind the lighting information of the at least one static object obtained by baking to the corresponding target object.

[0040] S160, store each target object with bound lighting information as a corresponding prefab component, respectively.

[0041] Further, in order to improve reusability, the prefab component can also be exported for reuse by other scenes. In the prior art, when exporting a prefab with lighting baking map in unity project development, the lighting information error occurs (for example, the scene is white, as shown in Figure 2 ); or after exporting the game project as an APK package, the lighting information error occurs (the scene is black, as shown in Figure 3 ), and the whole pre-baking process lacks ease of use and stability in industrial production.

[0042] Saving the above lighting information to the prefab ensures that the lighting information is decoupled from the scene file. Even if it is separated from the original scene file, the baked lighting effect can be correctly loaded. After the art side completes baking, the prefab is exported, and the program side can use the resource with lighting information without re-baking or loading the scene.

[0043] In an embodiment, the lighting information includes renderer information, color light map, and normal light map. Color light map (Color Lightmap): records lighting color and intensity information. Normal light map (Normal Lightmap): records the influence of lighting on the surface normal direction.

[0044] To facilitate decoupling of lighting information and scene files, it is understood that at least one static object in the target object is subjected to lighting baking through a baking script, and lighting information of the at least one static object obtained by baking is bound to the corresponding target object, including: S151, create a local renderer container for storing renderer information, a local color light map container for storing color light maps, and a local normal light map container for storing normal light maps for the target object associated with the binding through the baking script, and after baking is completed, all renderers of the corresponding static object are obtained respectively, all color light maps and all normal light maps are obtained according to the light map index, and are stored in the corresponding container, and each container is bound to the corresponding target object.

[0045] The light map index (lightmapIndex) is a property of the MeshRenderer component of the mesh renderer in Unity, indicating which light map (Lightmap) is used by the renderer. It is an integer index value (`int`), corresponding to the subscript of the global light map array in the Unity lighting system. Each MeshRenderer (referred to as renderer) can have a lightmapIndex, pointing to a light map.

[0046] Exemplarily, in the lighting baking stage, lighting and shadow calculation is performed on the static object using methods such as ray tracing (path tracing), to generate color light maps (Color Lightmap) and normal light maps (NormalLightmap) respectively.

[0047] Exemplarily, the local renderer container, the local color light map container and the local normal light map container include but are not limited to lists, for example, a renderer list, a color light map list and a normal light map list.

[0048] It is understood that the embodiments of the present application first obtain all target objects in the current scene that are mounted with a baking script (BakeSLGSceneLightMap), and prepare for generating lighting information, and the specific steps are as follows: (a): find all target objects in the scene that are mounted with the BakeSLGSceneLightMap script; (b): traverse all game objects gameobject corresponding to the target objects found in (a) to prepare for generating lighting information; (c): create a renderer list for storing renderer information through the BakeSLGSceneLightMap script; (d) : Create a list of Color Lightmap by BakeSLGSceneLightMap script to store Color Lightmap. (e) : Create a list of Normal Lightmap by BakeSLGSceneLightMap script to store Normal Lightmap.

[0049] The Bake script is used to create a local Renderer Container, a local Color Lightmap Container and a local Normal Lightmap Container for its binding target object. Each target object corresponds to a set of local Renderer Container, local Color Lightmap Container and local Normal Lightmap Container.

[0050] Secondly, during the light baking process, Unity will bake lightmaps for static objects according to the light settings. After baking, the light information will be saved in the `Assets / Lightmaps / ` directory, and the selected static object can view its MeshRenderer component contains: lightmapIndex (lightmap index) attribute and lightmapScaleOffset (UV scale and offset parameters) attribute.

[0051] Understandably, the local Renderer Container is used to record all the MeshRenderer components involved in the light baking and their related lightmap index, offset scaling and other information. After baking, the program needs to know which objects use which lightmap. Each MeshRenderer needs to bind the corresponding lightmap (color + normal) and its sampling area in the map (`lightmapScaleOffset`). Provide data structure support for saving light information to Prefab in the future.

[0052] The Color Lightmap Container is used to store the Color Lightmap (LightmapColor) exported from the Unity light baking system. Color Lightmap records the color brightness information of the object surface in the scene due to the influence of light (including indirect light). At runtime or when exporting Prefab, these maps will be bound to the corresponding MeshRenderer, so as to present the baked lighting effect without using real-time light. Avoid the problem of losing Unity default lightmap or scene black / white.

[0053] Lightmap Normal container, used to store the Lightmap Normal exported from the Unity Lightmap baking system. Lightmap Normal records the influence of light on the object's surface normal direction, used to achieve more realistic lighting reflection effects (such as concave-convex feeling, material feeling). In light baking, normal map can enhance the lighting performance of object surface at different angles, and improve the visual realism. Unlike color lightmap, normal lightmap constitutes complete lighting information, which is used for subsequent binding to the prefab. Figure 1

[0054] In the prefab export stage: save the lightmap resources (`textureColor`, `textureDir`) together with `rendererInfos` to the prefab (Prefab). Exemplarily, according to the current needs of SLG games, the art side can stably generate a scene prefab scene.prefab with light information after baking. The program side can directly use the prefab loading method to load the scene prefab scene.prefab after getting the prefab generated by the art side, and does not need to change the already written unity code. In the prior art, if the unity scene file scene.unity is used, it will greatly affect the already developed program functions, at this time the cooperation degree of art workflow and program workflow is very low, which is very unfavorable for regular process development work.

[0055] In the prefab loading stage, directly use these light information without re-baking or relying on the original scene file. The lightmapIndex of all MeshRenderer is correctly saved in the prefab, and the Unity runtime can correctly use these lightmaps.

[0056] Further, in order to improve accuracy, all color lightmaps and all normal lightmaps are obtained according to the lightmap index, including: For each renderer, check whether the lightmap index of the renderer is valid; if valid, obtain the color lightmap of the renderer according to the lightmap index; Check whether the lightmap offset scale of the renderer is valid; if valid, obtain the normal lightmap of the renderer according to the lightmap index.

[0057] Exemplarily, generate the light information corresponding to each static object: (a): Get all rendering components in each target object and its child objects, GetComponentsInChildren <meshrenderer>(), which retrieves all renderers for the target object; (b): Iterate through all the renderers obtained in step a and check each renderer; (c): Check if each renderer in b has a valid lightmap index. The lightmap index is provided by the Unity renderer component. Each MeshRenderer has a lightmap index lightmapIndex. If it is invalid, the value is -1.

[0058] (d): Check if the lightmap offset scaling of the renderer in step c is valid. The lightmap offset scaling is a property of each MeshRenderer, namely MeshRenderer.lightmapScaleOffset. If renderer.lightmapScaleOffset is not equal to Vector4.zero, the value of the lightmap offset scaling is considered valid; if it is equal to Vector4.zero, it is invalid.

[0059] (e): If the lightmap offset scaling value in step d is valid, then obtain the color lightmap through MeshRenderer.lightmapIndex; (f): If the lightmap in step d is valid, then the normal lightmap is obtained by getting MeshRenderer.lightmapIndex. (g): If the color lightmap and normal lightmap mentioned above are not yet stored in the color lightmap list and normal lightmap list, then add them to the corresponding lists respectively. That is, the color lightmap is stored in the color lightmap list, and the normal lightmap is stored in the normal lightmap list.

[0060] (h): Adds renderer information to the renderer list, completing the addition of lighting information for a target object. For example, the renderer information list includes multiple renderers, such as Element0, Element1, Element2, etc. The color lightmap list (LM Color) includes a color lightmap, such as Element0. The normal lightmap list (LM Dir) includes a normal lightmap, such as Element0.

[0061] S200, render shadows for at least one static object based on the bound lighting information.

[0062] Shadows are the result of mutual occlusion between light and objects. For static objects, shadows are usually pre-computed and stored in light maps during the baking stage to avoid the high overhead of real-time shadow computation at runtime.

[0063] In an embodiment, the shadow rendering for the at least one static object according to the bound light information comprises: S210, for each static object, obtaining each renderer of the static object from the local renderer container bound to the corresponding target object, and obtaining the corresponding color light map and normal light map from the local color light map container and the local normal light map container according to the light map index carried by each renderer; S220, performing shadow blending processing on the surface of the static object in the pixel shader associated with the static object based on the color light map and the normal light map, and outputting the rendering result.

[0064] Exemplarily, in the shadow rendering stage, the color light map and the normal light map are loaded. In the pixel shader: the normal direction of the current surface is sampled from the normal light map; the dot product of the normal direction and the light source direction is calculated to determine the light intensity of the point; the color superposition is performed by combining the light intensity and the color information in the color light map. S300, the shadow rendering for the at least one dynamic object is performed by using a planar shadow projection algorithm.

[0065] It can be understood that the shadow rendering for the at least one dynamic object by using the planar shadow projection algorithm comprises: S310, obtaining the main light source direction and the projection matrix in the world coordinate system. The main light source direction (LightDirection): For a directional light, the direction is a fixed vector (such as `(0,-1,0)`); For a point light / spot light, the direction is determined by the light source position to the object vertex.

[0066] The projection matrix in the world coordinate system (Projection Matrix in World Space): The projection matrix is used to convert an object from the world space to the perspective space of the light source (i.e. the space of the "light source camera"). In shadow rendering, a "light source camera" is usually constructed, and its view matrix and projection matrix jointly determine the projection mode of the shadow. For planar projection shadow, an orthographic projection or parallel projection is usually used to construct this matrix.

[0067] S320, transform the model vertex of the dynamic object to the light source space in the vertex shader using the main light source direction and the projection matrix.

[0068] In the vertex shader, the model vertex is transformed from the model space to the light source space for subsequent projection calculation; this step is the key of "projection" and determines the position and direction of the shadow. In the vertex shader, the main light source direction is used to construct the view matrix and the projection matrix of the light source. Through these matrices, the object can be converted from the world space to the light source space for subsequent shadow judgment (such as Shadow Mapping, Shadow Coord judgment, etc.).

[0069] S330, based on the model vertex in the light source space, draw the model of the dynamic object once to obtain monochrome and transparent shadow information.

[0070] For example, a special material (Shadow Material) is used to draw the object, in which the material color is black or dark gray; the rendering mode is Alpha Blend; ZWrite Off can be turned off to avoid conflict with the original model; the drawing result is a "flattened" shadow outline on the plane.

[0071] S340, alpha blending the shadow information with the scene to adjust the color of the shadow and output the rendering result. Alpha blending includes color superposition, edge blur processing or tone adjustment.

[0072] For example, the shadow image is alpha blended with the main scene image; it can be realized through RenderTexture or screen space blending; it supports adjusting the shadow color (such as blue, dark gray, semi-transparent red, etc.) to match different scene atmospheres; post-processing (blur, edge enhancement) can be added to improve the visual quality.

[0073] The method of the embodiment of the application is applied to 2D or 3D real-time rendering scenes in the Unity engine.

[0074] The method of the embodiment of the application is compared and described below in combination with the prior art: S410, the static scene is not added with real-time lighting, only with baked light. Advantage: the light and shadow information of the scene is rich in layers, and the shadow is also a soft shadow, as shown in Figure 4 .

[0075] S420, the static scene is not added with real-time lighting, only with baked light. Disadvantage: the dynamic object has no real-time lighting information and no shadow, as shown in Figure 5 .

[0076] S430, static scene adds real-time lighting, also has baked light, which can solve the problem of no lighting information for dynamic objects. Disadvantages: dynamic real-time lighting information is superimposed on the static scene, and the scene lighting is wrong, as shown in Figure 6 .

[0077] S440, static scene adds real-time lighting, also has baked light. The static scene is layered with dynamic objects, and real-time lighting only renders dynamic objects without affecting the static scene; dynamic objects use flat shadows (non-shadow map generated shadows). In the embodiment of the application, the baked light and flat shadow technologies are fused, that is, the static scene can obtain very good visual effects, and the lighting of dynamic objects can be supported, as shown in Figure 7 .

[0078] The core point in the embodiment of the application is the work done by the BakeSLGSceneLightMap.cs script, which directly mounts the lighting information (baked information) to the prefab. The essence of this work is to unbind the lighting information from the scene file scene.unity and statically bind the lighting information to the prefab.

[0079] The method of the embodiment of the application can improve the realism of the lighting performance of the SLG scene; reduce the runtime GPU calculation pressure and improve the frame rate; decouple the work flow coupling of the art and the program by exporting the prefab, reduce the cooperation cost of the art and the program; strong scalability, support for subsequent access to PBR, light tracing baking and other advanced features.

[0080] The application also provides a virtual scene rendering device. Illustratively, the virtual scene rendering device comprises a loading module, a static object rendering module and a dynamic object rendering module.

[0081] The loading module is configured to load a pre-constructed prefab component; the prefab component comprises at least one dynamic object and at least one static object in a scene to be rendered; and the lighting information of all the static objects is bound to the prefab component; The static object rendering module is configured to perform shadow rendering on the at least one static object according to the bound lighting information; The dynamic object rendering module is configured to perform shadow rendering on the at least one dynamic object by using a flat shadow projection algorithm.

[0082] It can be understood that the device of the embodiment corresponds to the virtual scene rendering method of the above-mentioned embodiment, and the optional items in the above-mentioned embodiment are also applicable to the embodiment, so the description is not repeated here.

[0083] The application further provides a terminal device. The terminal device exemplarily comprises a processor and a memory. The memory stores a computer program. The processor executes the computer program, so that the terminal device performs the functions of the modules in the virtual scene rendering method or the virtual scene rendering device.

[0084] The processor can be an integrated circuit chip with a processing capability of signals. The processor can be a general processor, including a central processing unit (CPU), a graphics processing unit (GPU), a network processor (NP), a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, a discrete gate or transistor logic device, a discrete hardware component, or at least one of the above. The general processor can be a microprocessor or any conventional processor, etc., which can implement or execute the disclosed methods, steps and logic block diagrams in the embodiments of the application.

[0085] The memory can be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM) and the like. The memory is used to store a computer program. After receiving an execution instruction, the processor can execute the computer program accordingly.

[0086] The application further provides a computer readable storage medium for storing the computer program used in the terminal device. For example, the computer readable storage medium can include, but is not limited to, a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk and various program code storage media.

[0087] In several embodiments provided in the present application, it should be understood that the disclosed apparatus and method can also be implemented by other means. The apparatus embodiments described above are only illustrative, for example, the flowcharts and structural diagrams in the drawings show the possible implementation architecture, function and operation of the apparatus, method and computer program product according to the embodiments of the present application. In this regard, each block in the flowchart or block diagram can represent a module, a program segment or a part of code, which contains one or more executable instructions for implementing the specified logic function. It should also be noted that in alternative implementation, the functions noted in the block can also occur in different order from that noted in the drawings. For example, two consecutive blocks can actually be executed substantially in parallel, and sometimes they can be executed in reverse order, depending on the functions involved. It should also be noted that each block in the structural diagram and / or flowchart, and the combination of blocks in the structural diagram and / or flowchart, can be implemented by a dedicated hardware-based system for executing the specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.

[0088] In addition, each functional module or unit in the embodiments of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0089] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application can be embodied in the form of a software product, which is stored in a storage medium and includes a number of instructions for causing a computer device (which can be a smart phone, a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the embodiments of the present application.

[0090] The above description is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art can easily think of changes or replacements within the technical scope disclosed in the present application, which should be covered within the protection scope of the present application.< / meshrenderer> ​

Claims

1. A method of rendering a virtual scene, the method comprising: The method comprises: loading a pre-constructed prefabricated component; the prefabricated component comprises at least one dynamic object and at least one static object in a scene to be rendered; all the static objects are bound with illumination information on the prefabricated component; shadow rendering is performed on the at least one static object according to the bound illumination information; a planar shadow projection algorithm is used to perform shadow rendering on the at least one dynamic object.

2. The virtual scene rendering method of claim 1, wherein, The method uses the following method to construct the prefabricated component: finding all target objects in a scene on which a preset baking script is mounted, and executing the baking script; for each target object, performing illumination baking on at least one static object in the target object through the baking script, and binding the illumination information of the at least one static object obtained by baking to the corresponding target object; storing each target object with bound illumination information as a corresponding prefabricated component.

3. The virtual scene rendering method of claim 2, wherein, The method for constructing the prefabricated component further comprises: before baking the target object, marking the target object and its included sub-objects that need to be baked as static meshes to obtain at least one static object; setting the illumination mode of the scene in which the prefabricated component is located to a baking mode or a mixed mode; mounting the baking script for each target object.

4. The virtual scene rendering method of claim 3, wherein, The illumination information comprises renderer information, color light map and normal light map; The method for performing illumination baking on at least one static object in the target object through the baking script and binding the illumination information of the at least one static object obtained by baking to the corresponding target object comprises: creating, by the baking script, a local renderer container for storing renderer information, a local color light map container for storing color light maps and a local normal light map container for storing normal light maps for the target object associated with the binding, and after baking is completed, obtaining all renderers of the corresponding static object, obtaining all color light maps and all normal light maps according to light map indexes, storing them in the corresponding containers, and binding each container to the corresponding target object.

5. The virtual scene rendering method of claim 4, wherein, The method for obtaining all color light maps and all normal light maps according to light map indexes comprises: for each renderer, checking whether the light map index of the renderer is valid; if valid, obtaining the color light map of the renderer according to the light map index; checking whether the light map offset scale of the renderer is valid; if valid, obtaining the normal light map of the renderer according to the light map index.

6. The method of Claim 1, wherein, The method for performing shadow rendering on the at least one static object according to the bound illumination information comprises: for each static object, obtaining each renderer of the static object from the local renderer container bound to the corresponding target object, and obtaining the corresponding color light map and normal light map from the local color light map container and local normal light map container according to the light map index carried by each renderer; Based on the color light map and the normal light map, a surface of the static object is shadow mixed in a pixel shader associated with the static object, and a rendering result is output.

7. The virtual scene rendering method of claim 1, wherein, The shadow rendering of the at least one dynamic object by using the planar shadow projection algorithm comprises: obtaining a main light source direction and a projection matrix in a world coordinate system; transforming model vertices of the dynamic object to a light source space in a vertex shader by using the main light source direction and the projection matrix; performing one drawing on a model of the dynamic object based on the model vertices in the light source space, to obtain single-color and transparent shadow information; performing alpha blending on the shadow information and a scene, to adjust a color of the shadow and output a rendering result.

8. A virtual scene rendering apparatus, characterized by comprising: comprise: a loading module configured to load a prefabricated body component constructed in advance; the prefabricated body component comprises at least one dynamic object and at least one static object in a scene to be rendered; lighting information of all the static objects is bound on the prefabricated body component; a static object rendering module configured to perform shadow rendering on the at least one static object according to the bound lighting information; a dynamic object rendering module configured to perform shadow rendering on the at least one dynamic object by using a planar shadow projection algorithm.

9. A terminal device, comprising: The terminal device comprises a processor and a memory, the memory stores a computer program, and the processor is configured to execute the computer program to implement the virtual scene rendering method in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer program is stored in the memory and is executed on the processor to implement the virtual scene rendering method in any one of claims 1-7.

Citation Information

Cited By

  • Illumination data processing method

    CN121330157A