Method, system and device for simulating dynamic shadow effect through static shadow
By baking shadow maps with transparent channels for the target object in a 3D scene and offsetting the shadow map when the object moves, the problem that static shadows cannot be suitable for moving objects is solved, achieving high-quality dynamic shadow rendering and performance improvements.
Patent Information
- Application Number
- CN202311248943.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-25
- Publication Date
- 2025-03-25
AI Technical Summary
In existing 3D scene renderings, static shadows cannot be used for moving objects, and dynamic shadows have insufficient effects and performance.
Simulate dynamic shadow effects by creating a shadow plane for the target object in a 3D scene, bake a shadow map with transparent channels, and calculate and offset the shadow map as the object moves.
It realizes high-quality shadow rendering of moving objects in 3D scenes, which not only improves shadow effect but also improves rendering performance.
Smart Images

Figure CN119693531A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the technical field of shadow processing, and in particular to a method, system and device for simulating dynamic shadow effects through static shadows. Background Art
[0002] In the existing 3D scene rendering, there are two major ways to achieve shadow effects: static shadows and dynamic shadows.
[0003] For static shadows: usually refers to the pre-calculation of the lights in the 3D scene by the modeling software before the program is run, and the generation of a picture containing shadow information. Then this shadow picture is attached to the surface of the object as a material map, thereby generating a shadow effect on the surface of the object. Figure 1 The picture below shows the floor after the static shadow is baked. Figure 2 Shown is the effect of the floor after using static shadows in a 3D scene.
[0004] Dynamic shadows: usually refers to the real-time calculation of the model and lighting information in the scene in each rendering frame when the program is running, and the generation of real-time shadow maps attached to the model surface. Figure 3 It shows that the cube forms a gray shadow on the ground under the illumination of the light source.
[0005] Static shadows can be baked in advance to obtain very soft and realistic shadow effects, and the performance occupied during rendering is almost negligible. Dynamic shadows do not need to be baked in advance, but shadow calculations are performed in each frame of the program, which consumes a high performance and the shadow effect obtained is far inferior to that of static shadows. However, the advantage of dynamic shadows is that when the position of objects in the scene changes, the correct shadow angle, shape and position can be calculated.
[0006] For the rendering of existing 3D scenes, static shadows are often used for baking rendering for objects whose positions do not change; dynamic shadows are used for baking rendering for objects whose positions change. However, there are more and more existing 3D scenes, and more and more objects in 3D scenes need to change their positions. If static shadows are used, the effect and performance are excellent, but they cannot be applied to movable objects; if dynamic shadows are used, although the correctness of the shadows is solved, the effect and performance are insufficient.
[0007] In view of this, how to overcome the defects of the existing technology and solve the problems of the existing technology is a difficult problem to be solved in this technical field. Summary of the invention
[0008] The embodiments of the present invention provide a method, system and device for simulating dynamic shadow effects through static shadows. When the method is used to render objects with moving characteristics in a 3D scene, static shadows plus shadow position offset calculation are used to replace conventional dynamic rendering, thereby achieving a dual improvement in effect and performance. The method can solve the problems in the prior art that static shadows cannot be applied to movable objects and that dynamic shadow effects and performance are insufficient.
[0009] The purpose of the embodiment of the present invention is achieved through the following technical solutions:
[0010] To solve the above technical problems, in a first aspect, an embodiment of the present invention provides a method for simulating dynamic shadow effects by static shadows, comprising:
[0011] Create a shadow plane at the bottom of the target object to receive the shadow, bake the shadow information of the target object onto the shadow plane, and bake out a shadow map with a transparent channel;
[0012] When the target object is loaded into the scene, the shadow map with the transparent channel of the target object is merged and superimposed with the scene color;
[0013] When the target object moves, the offset of the shadow map is calculated and the shadow map is offset accordingly to simulate the dynamic shadow effect.
[0014] In an optional implementation, baking the shadow information of the target object onto the shadow plane to bake out a shadow map with a transparent channel specifically includes:
[0015] Take the shadow plane as the object, perform shadow baking under global illumination, and bake the shadow information of the target object onto the shadow plane; use gray pixels for the shadowed part and transparent colors for the unshadowed part to bake out a shadow map with a transparent channel.
[0016] In an optional implementation, the step of fusing and superimposing the shadow map with a transparent channel of the target object with the scene color specifically includes:
[0017] The shadow map is fused and superimposed with the scene color by additive mixing. The shadow map without shadow is fused and superimposed with the scene color to present the scene color. The shadow map with shadow is fused and superimposed with the scene color to present the shadow effect.
[0018] In an optional implementation, when the target object moves, calculating the offset of the shadow map and offsetting the shadow map accordingly to achieve the simulation of the dynamic shadow effect specifically includes:
[0019] When the target object moves, the direction and distance of the target object's movement are obtained;
[0020] Calculate the direction and distance that the shadow map needs to move according to the direction and distance of the target object's movement;
[0021] The shadow map is moved according to the calculated direction and distance that the shadow map needs to move to simulate the dynamic shadow effect.
[0022] In an optional implementation, when the target object moves on the horizontal plane, the direction and distance in which the target object moves on the horizontal plane are acquired, and the direction and distance are used as the direction and distance in which the shadow map needs to move.
[0023] In an optional embodiment, when the target object moves on the vertical plane, the direction and distance of the target object moving on the vertical plane are obtained, the direction and distance of the shadow map are calculated according to the light source angle combined with trigonometric functions, and the direction and distance are used as the direction and distance that the shadow map needs to move.
[0024] In an optional implementation, when the light source angle is a and the target object moves a distance h on the vertical plane, the moving distance of the shadow map is h / tan(a).
[0025] In an optional implementation, when the target object moves upward on the vertical plane, the shadow map moves in a direction away from the target object; when the target object moves downward on the vertical plane, the shadow map moves in a direction close to the target object.
[0026] In an optional embodiment, when the target object moves on both the horizontal and vertical planes, the movement of the target object is divided into movement on the horizontal plane and movement on the vertical plane, and the direction and distance that the shadow map needs to move on the horizontal plane and the direction and distance that the shadow map needs to move on the vertical plane are calculated separately, and then superimposed to obtain the final direction and distance required to move.
[0027] In an optional implementation, for a plane with inconsistent heights, the step of fusing and superimposing the shadow map with a transparent channel of the target object with the scene color specifically includes:
[0028] The shadow map is projected onto a plane with inconsistent heights in a rectangular manner to form a cubic mapping area; for the part of the plane with inconsistent heights that overlaps with the mapping area, the shadow map is fused and superimposed with the scene color using additive mixing.
[0029] In an optional implementation, shadow maps of the target object at different angles are pre-baked, and when the angle of the target object changes, the shadow map at the corresponding angle is switched.
[0030] In an optional implementation, shadow maps of the target object under different light sources are pre-baked, and when the light source changes, the shadow map is switched to the shadow map under the corresponding light source.
[0031] In a second aspect, an embodiment of the present invention provides a system for simulating dynamic shadow effects through static shadows, which is used to implement the method for simulating dynamic shadow effects through static shadows as described in the first aspect, including a shadow baking module, a fusion overlay module, and a shadow offset module; wherein:
[0032] The shadow baking module is used to bake the shadow of the target object and bake out a shadow map with a transparent channel;
[0033] The fusion and overlay module is used to fuse and overlay the shadow map with a transparent channel of the target object with the scene color;
[0034] The shadow offset module is used to calculate the offset of the shadow map as the target object moves, and to make a corresponding offset to the shadow map to achieve the simulation of the dynamic shadow effect.
[0035] In a third aspect, an embodiment of the present invention provides a device for simulating dynamic shadow effects through static shadows, comprising at least one processor and a memory, wherein the at least one processor and the memory are connected via a data bus, and the memory stores instructions that can be executed by the at least one processor, and after the instructions are executed by the processor, are used to complete the method for simulating dynamic shadow effects through static shadows as described in the first aspect.
[0036] Compared with the prior art, the beneficial effects of the present invention are as follows: Different from the prior art, the embodiments of the present invention provide a method, system and device for simulating dynamic shadow effects through static shadows. When used to render objects with moving characteristics in a 3D scene, a shadow map with a transparent channel is first baked for the object, and then the shadow map and the scene color are merged and superimposed; when the object moves, the offset of the shadow map is calculated according to its movement mode, and the shadow map is offset accordingly, so that the effect of dynamic shadows can be achieved through the baking simulation of static shadows. By replacing conventional dynamic rendering with the method in the embodiments of the present invention, both effect and performance can be improved, and the problem that static shadows cannot be applied to movable objects and dynamic shadow effects and performance are insufficient in the prior art can be solved.
[0037] In addition, the shadow map baked by the embodiment of the present invention is a shadow map with a transparent channel, which is different from conventional baking. Conventional baking does not have a transparent area, and the original color of the model surface is written in the non-shadow part, while the embodiment of the present invention writes a transparent color in the non-shadow part. In this way, the ambient color can be expressed by superimposing calculation with the environment. The shadow map with a transparent channel in the embodiment of the present invention can be applied to more scenes, and there is no need to write different original colors specifically for different models, which is more convenient and practical.
[0038] Furthermore, for a plane with inconsistent heights, such as an uneven ground, the embodiment of the present invention projects the shadow map onto the uneven ground in a rectangular manner to form a cubic mapping area, and then uses an additive mixing method to fuse and superimpose the shadow map and the scene color on the portion of the uneven ground that overlaps with the mapping area. This method can achieve the effect of fitting the shadow map with the plane with inconsistent heights, instead of directly using the shadow map for mapping, where the shadow map and the ground do not actually overlap when viewed from the side. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements / modules and steps with the same reference numerals in the drawings are represented as similar elements / modules and steps. Unless otherwise specified, the figures in the drawings do not constitute proportional limitations.
[0040] Figure 1 This is a schematic diagram of a picture of a floor provided by the present invention after a static shadow is baked;
[0041] Figure 2 It is a schematic diagram of the effect of the floor after using static shadows in the 3D scene provided by the present invention;
[0042] Figure 3 is a schematic diagram of a gray shadow formed on the ground by a cube provided by the present invention under the illumination of a light source;
[0043] Figure 4 is a flowchart of a method for simulating dynamic shadow effects by static shadows provided in the first embodiment of the present invention;
[0044] Figure 5 is a schematic diagram of an extended flow chart of step S300 provided in the first embodiment of the present invention;
[0045] Figure 6 is a schematic diagram of shadow overlap provided by the first embodiment of the present invention;
[0046] Figure 7 Schematic diagram of the projection map range of the shadow map provided in the first embodiment of the present invention;
[0047] Figure 8 It is a schematic diagram of the projection mapping effect of the shadow map provided in the first embodiment of the present invention;
[0048] Fig. 9 This is an example diagram of a classroom scene provided by Embodiment 2 of the present invention;
[0049] Fig.10 is a plan view schematic diagram of shadow reception provided by Embodiment 2 of the present invention;
[0050] Fig.11 is a cross-sectional view of a shadow plate on a concave-convex plane provided by the second embodiment of the present invention;
[0051] Fig.12 is a schematic diagram of the projection mapping area provided by the second embodiment of the present invention;
[0052] Fig.13 This is a schematic diagram of the placement of the shadow plate provided in the second embodiment of the present invention;
[0053] Fig.14 is a schematic diagram of offset position calculation provided by Embodiment 2 of the present invention;
[0054] Fig.15 This is a block diagram of a system for simulating dynamic shadow effects through static shadows provided by Embodiment 3 of the present invention;
[0055] Fig.16 It is a schematic diagram of the structure of a device for simulating dynamic shadow effects through static shadows provided in Embodiment 4 of the present invention. DETAILED DESCRIPTION
[0056] The present invention is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those of ordinary skill in the art, several variations and improvements may be made without departing from the concept of the present invention. These all belong to the protection scope of the present invention.
[0057] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0058] It should be noted that, if there is no conflict, the various features in the embodiments of the present invention can be combined with each other, and all are within the protection scope of the present invention. In addition, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in a different order than the module division in the device or the order in the flow chart.
[0059] Unless otherwise defined, all technical and scientific terms used in this specification have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in this specification and in the specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. In addition, the technical features involved in each embodiment of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0060] In order to solve the problem that static shadows used in the prior art cannot be applied to movable objects, dynamic shadow effects are used, and performance is insufficient, the embodiments of the present invention provide a method, system, and device for simulating dynamic shadow effects through static shadows. When the method is applied to render objects with moving characteristics in a 3D scene, a shadow map with a transparent channel is first baked for the object, and then the shadow map and the scene color are merged and superimposed; when the object moves, the offset of the shadow map is calculated according to its movement mode, and the shadow map is offset accordingly, so that the effect of dynamic shadows can be achieved through the baking simulation of static shadows. Replacing conventional dynamic rendering with the method in the embodiments of the present invention can achieve a dual improvement in effect and performance, and can solve the problem that static shadows used in the prior art cannot be applied to movable objects, dynamic shadow effects are used, and performance is insufficient.
[0061] Specifically, the embodiments of the present invention are further described below in conjunction with the accompanying drawings.
[0062] Embodiment 1
[0063] The embodiment of the present invention provides a method for simulating dynamic shadow effects through static shadows, see Figure 4 , which shows a process of a method for simulating dynamic shadow effects by static shadows provided by an embodiment of the present invention. The method can be applied to render objects with moving characteristics in a 3D scene. The method for simulating dynamic shadow effects by static shadows includes but is not limited to the following steps:
[0064] Step S100: Create a shadow plane at the bottom of the target object for receiving shadows, bake the shadow information of the target object onto the shadow plane, and bake out a shadow map with a transparent channel. For this step, a patch can be directly created at the bottom of the target object as a shadow plane through modeling software to receive subsequent shadow rendering.
[0065] Step S200: When the target object is loaded into the scene, the shadow map with a transparent channel of the target object is fused and superimposed with the scene color. For this step, since the shadow map is a shadow map with a transparent channel and the non-shadow parts are all transparent, the shadow map can be fused and superimposed with the scene color.
[0066] Step S300: When the target object moves, the offset of the shadow map is calculated, and the shadow map is offset accordingly to simulate the dynamic shadow effect. For this step, each time the target object moves, the shadow map needs to be moved according to its movement, and then the shadow map is moved to simulate the effect of dynamic shadows. In this embodiment, the shadow map is actually baked using a static shadow method, which has the excellent effect and performance of static shadows, and at the same time achieves the effect of dynamic shadows, that is, it solves the problem in the prior art that static shadows cannot be applied to movable objects and that dynamic shadows have insufficient effects and performance.
[0067] Specifically, in an optional implementation of the preferred embodiment, the step S100 described in which the shadow information of the target object is baked onto the shadow plane and the shadow map with a transparent channel is baked specifically includes the following methods: taking the shadow plane as the object, performing shadow baking under global illumination, and baking the shadow information of the target object onto the shadow plane; using gray pixels for the shadowed part and transparent colors (in the RGBA color value, the value of A is 0) for the unshadowed part to bake out the shadow map with a transparent channel. It should be noted that the shadow map created here must be a shadow map with a transparent channel, so as to realize the superposition calculation of shadows and shadows, and the superposition calculation of shadows and the environment in subsequent steps. The shadow map baked by this embodiment is a shadow map with a transparent channel, which is different from conventional baking. Conventional baking does not have a transparent area, and the original color of the model surface is written in the non-shadow part, while the transparent color is written in the non-shadow part in this embodiment, so that the environmental color can be expressed by superposition calculation with the environment. The shadow map with a transparent channel in this embodiment can be applied to more scenes, and there is no need to write different original colors for different models, which is more convenient and practical.
[0068] In an optional implementation of the preferred embodiment, the step S200 of fusing and superimposing the shadow map with a transparent channel of the target object with the scene color specifically includes: using additive mixing to fuse and superimpose the shadow map with the scene color; wherein, the shadow-free part of the shadow map is fused and superimposed with the scene color to present the scene color; and the shadow-containing part of the shadow map is fused and superimposed with the scene color to present the shadow effect. It should be noted that when objects with transparent properties are rendered in the engine, there are usually several blending modes (superposition calculation methods): AlphaBlending (transparent blending), AdditiveBlending (additive blending), SubtractiveBlending (subtractive blending), and MultiplicativeBlending (multiplicative blending). This embodiment requires additive blending: the color expression at the same position = base map color + shadow color (gray); in this way, the base map (floor) color of the shadow area can be slightly grayer than other areas, achieving the shadow effect. It should be noted that there will be slight differences in the results of additive blending in different engines. Generally, it will be debugged step by step in actual use to obtain an approximate shadow effect, which is characterized by: when multiple shadows overlap, the rendered color will deepen. Effect reference Figure 6 As shown, the leftmost is an opaque cylinder, and the two transparent cylinders on the right (shadows) overlap partially, and the overlapping area is darker than the non-overlapping area. The two transparent cylinders on the right are regarded as shadow maps. When the two shadow maps overlap, the shadow part in the overlapping plate will be superimposed and become a darker color.
[0069] refer to Figure 5 As shown, in an optional implementation of the preferred embodiment, when the target object moves, the offset of the shadow map is calculated in step S300, and the shadow map is offset accordingly to achieve the simulation of the dynamic shadow effect, which specifically includes the following steps:
[0070] Step S301: When the target object moves, the direction and distance of the target object's movement are obtained. In this embodiment, the direction can be divided into a plane direction and a vertical direction. When the target object moves on a horizontal plane, the plane direction and distance of the target object's movement are obtained. The plane direction here can be understood as the angle of the target object's movement. For example, if the east is 0 degrees and the angle is calculated counterclockwise, then when the target object moves to the north, the angle of movement is 90 degrees, and when it moves to the south, the angle of movement is 270 degrees; when the target object moves on a vertical plane, the vertical direction and distance of the target object's movement are obtained. The vertical direction here can be understood as the change in height of the target object, which is divided into two types: rising and falling.
[0071] Step S302: Calculate the direction and distance that the shadow map needs to move according to the direction and distance that the target object moves.
[0072] Step S303: moving the shadow map according to the calculated direction and distance that the shadow map needs to move, so as to simulate the dynamic shadow effect.
[0073] The steps of step S302 and step S303 are divided into different situations according to different moving directions.
[0074] In an optional implementation of the preferred embodiment, when the target object moves on the horizontal plane, the direction and distance of the target object on the horizontal plane are obtained, and the direction and distance are used as the direction and distance that the shadow map needs to move. For example, if the target object moves one meter to the south (90 degrees), then the shadow map also moves one meter to the south (90 degrees) accordingly. Here, the movement of the shadow map is based on its previous position as a reference. If the target object is used as a reference, then during the movement of the target object on the horizontal plane, the position of the shadow map relative to the target object remains unchanged.
[0075] In an optional implementation of this preferred embodiment, when the target object moves on the vertical plane, the direction and distance of the target object moving on the vertical plane are obtained, the direction and distance of the shadow map are calculated according to the light source angle combined with trigonometric functions, and the direction and distance are used as the direction and distance that the shadow map needs to move. Specifically, when the light source angle is a and the distance the target object moves on the vertical plane is h, the moving distance of the shadow map is h / tan(a). When the target object moves upward on the vertical plane, the shadow map moves in the direction away from the target object; when the target object moves downward on the vertical plane, the shadow map moves in the direction close to the target object. For example, if the light source angle is 45 degrees, if the target object rises one centimeter on the vertical plane, then the shadow map needs to move one centimeter along the illumination direction to the side away from the target object; if the target object drops one centimeter on the vertical plane, then the shadow map needs to move one centimeter along the illumination direction to the side close to the target object.
[0076] The above two directions and distances are calculated separately for the target object moving on the horizontal plane and on the vertical plane. In actual application scenarios, there will be many scenes where the target objects move on both the horizontal plane and the vertical plane, that is, the displacement in three-dimensional space. In view of this situation, in an optional implementation of the preferred embodiment, when the target object moves on both the horizontal plane and the vertical plane, the movement of the target object is divided into movement on the horizontal plane and movement on the vertical plane, and the direction and distance that the shadow map needs to move on the horizontal plane and the direction and distance that it needs to move on the vertical plane are calculated separately, and then they are superimposed to obtain the final direction and distance that need to be moved. For example, when the light source angle is 45 degrees, the target object moves one meter toward the south (90 degrees in the horizontal plane) on the horizontal plane and rises one centimeter on the vertical plane. Then calculate the direction and distance that the shadow map needs to move on the horizontal plane, that is, the shadow map needs to move one meter toward the south (90 degrees in the horizontal plane), and the direction and distance that the shadow map needs to move on the vertical plane, that is, the shadow map needs to move one centimeter away from the target object along the direction of light. Superimpose these two required movements to get the final moving position. When superimposing, the lighting direction can also be converted into an angle on the horizontal plane, because the light source angle of 45 degrees in the previous example refers to the angle between the light source and the horizontal plane. After projecting it onto the horizontal plane, taking the east of the horizontal plane as 0 degrees, the relative angle of the lighting direction on the horizontal plane can be obtained. By superimposing the two angles and distances, the final angle and distance that the shadow map needs to move can be easily calculated; of course, when moving the shadow map, the final superposition result can be omitted, but the shadow map can be directly moved in the direction and distance calculated by the divided horizontal plane, and then the shadow map can be moved in the direction and distance calculated by the divided vertical plane. The shadow map can also be directly moved to the correct position. This movement can omit one calculation step, but has an extra movement operation. The movement method can be selected according to actual needs.
[0077] In an optional implementation of this preferred embodiment, the angle of the target object itself may also change. Generally, if the angle of the target object itself changes, the shadow map baked at the original angle will no longer be applicable. For example, when the target object rotates along the upward y-axis, even at the same light angle, different shadow effects will be produced. For this situation, this embodiment can pre-bake the shadow map of the target object itself at different angles, and when the angle of the target object itself changes, switch to the shadow map at the corresponding angle. Of course, this situation is only for the listed angle changes, or some important angle changes to pre-bake the shadow maps at these angles.
[0078] It should be noted that the mobile calculation methods involved in this embodiment are all calculation methods for the case where the light source scene does not change frequently and is parallel light, such as sunlight over a period of time. The above calculation under movement is accurate only when only parallel light is considered; if it is not parallel light, but a light source such as a lamp tube or a light bulb, it will produce different shadow effects as the position of the irradiated object changes. At this time, the previously baked shadow map cannot achieve this dynamic change. In this case, the shadow map must be baked dynamically. For the case where the light source changes, if the light source changes significantly during operation, but this situation can be listed, then the static map can also be baked and rendered for each situation, and the shadow map of the target object under different light sources is pre-baked. When the light source changes in the running scene, switch to the shadow map under the corresponding light source.
[0079] Regarding the mapping method of the shadow map, if the ground part to be mapped is a plane, then mapping can be performed directly. However, if the ground to be mapped is a non-planar ground with concave and convex features, the direct mapping method will have problems of cutting and being hidden or suspended in the air. In view of this situation, in an optional implementation of the preferred embodiment, for planes with inconsistent heights, the fusion and superposition of the shadow map with a transparent channel of the target object with the scene color specifically includes: projecting the shadow map in a rectangular manner onto the plane with inconsistent heights to form a cubic mapping area; for the portion of the plane with inconsistent heights that overlaps with the mapping area, an additive mixing method is used to fuse and superimpose the shadow map with the scene color. For the projection mapping method of the shadow map, refer to Figure 7 , Figure 8 As shown, its implementation principle is as follows: the pattern of the map is projected from the front of the character to the chest of the character in a rectangular range. Figure 7 The cube area in the middle of the chest is the calculation area of the projection map. The effect it produces is to project a lion image on the character's chest. Figure 8 As shown in the figure, the pattern produced by this projection method does not have a very complete rectangular outline because the pattern uses a transparent channel, that is, the non-lion graphic texture area is transparent, so during the rendering process, the texture of the clothes behind can be seen through the transparent color. Using this processing method, the shadow in the shadow map can be projected onto the uneven ground, thereby achieving the fusion effect of the shadow and the uneven ground.
[0080] In summary, this embodiment provides a method for simulating dynamic shadow effects through static shadows. When used to render objects with moving characteristics in a 3D scene, a shadow map with a transparent channel is first baked for the object, and then the shadow map and the scene color are merged and superimposed; when the object moves, the offset of the shadow map is calculated according to its movement mode, and the shadow map is offset accordingly, so that the effect of dynamic shadows can be achieved through the baking simulation of static shadows. By replacing conventional dynamic rendering with the method in this embodiment, both the effect and performance can be improved, and the problem that static shadows cannot be applied to movable objects and dynamic shadow effects and performance are insufficient in the prior art can be solved.
[0081] In addition, the shadow map baked by this embodiment is a shadow map with a transparent channel, which is different from conventional baking. Conventional baking does not have a transparent area, and the original color of the model surface is written in the non-shadow part, while this embodiment writes a transparent color in the non-shadow part. In this way, the ambient color can be expressed by superimposing calculation with the environment. The shadow map with a transparent channel in the embodiment of the present invention can be applied to more scenes, and there is no need to write different original colors for different models, which is more convenient and practical.
[0082] Furthermore, for planes with inconsistent heights, such as an uneven ground, this embodiment projects the shadow map onto the uneven ground in a rectangular manner to form a cubic mapping area, and then uses additive mixing to fuse and superimpose the shadow map with the scene color for the portion of the uneven ground that overlaps with the mapping area. This method can achieve the effect of fitting the shadow map with the planes with inconsistent heights, instead of directly using the shadow map for mapping, where the shadow map and the ground do not actually overlap when viewed from the side.
[0083] Embodiment 2
[0084] This embodiment takes a specific scenario as an example to explain in more detail the method of simulating dynamic shadow effects by static shadows in Embodiment 1.
[0085] Take rendering a classroom scene as an example. In actual business, the number and position of tables and chairs in different classroom scenes vary greatly, such as the number of rows and columns, the spacing, etc. Fig. 9As shown, when the number and position of tables and chairs change, in traditional shadow rendering technology, the shadows generated for the tables and chairs are often generated in the form of dynamic shadows. However, this method has high requirements on performance, and the shadow effect is also relatively rigid and unrealistic. In response to this situation, this embodiment simulates the dynamic shadow effect by means of static shadows, which can achieve a double improvement in effect and performance. The following uses the operation of a single table and chair as an example to illustrate the method of this embodiment. The operation of other tables and chairs can refer to the tables and chairs in the example.
[0086] First, take a single table and chair as the target object and create a shadow receiving plane at the bottom of the table and chair. You can use modeling software to directly create a patch at the bottom of the table and chair to receive subsequent shadow rendering. Fig.10 shown.
[0087] Then, taking the shadow plane as the object, shadow baking is performed under global illumination, and the shadow information of the tables and chairs can be baked onto the shadow plane. It should be noted when baking here: bake out a shadow map with a transparent channel, that is, the shadowed part uses gray pixels, and the shadowless part uses transparent colors (in the RGBA color value, the value of A is 0). The shadow map with a transparent channel is different from conventional baking in that there is no transparent area in conventional baking, and its non-shadow part is written with the original color of the model surface. However, the shadow map created here in this embodiment must be a shadow map with a transparent transparent channel, so as to realize the superposition calculation of shadows and shadows, and the superposition calculation of shadows and the environment in subsequent steps. When objects with transparent properties are rendered in the engine, there are usually several mixing modes (superposition calculation methods): transparent mixing, additive mixing, subtractive mixing, and multiplicative mixing. Additive mixing is needed here: the color performance at the same position = base map color + shadow color; this can make the base map (floor) color of the shadow area slightly darker than other areas, achieving the effect of shadows.
[0088] Next, you need to implement the binding of static shadows.
[0089] Method 1: Keep the shadow plane at the bottom of the desks and chairs. The shadow plane here is named "shadow board" and will be used in the following text. When the desk and chair model is loaded into the scene, since the shadow plane map is a transparent map, the non-shadow part is transparent, so the shadow board can be fused and superimposed with the color of the classroom floor (ambient color). Here, in the general rendering engine, there is a choice of fusion and superposition algorithm in the rendering process of transparent objects, which is generally called "blending mode of transparent objects". There will be slight differences in the results of fusion in different engines. Here, it is generally debugged step by step in actual use to get an effect similar to shadows. Its characteristics are: when multiple shadows overlap, the rendered color will deepen. That is, when two shadow boards overlap, the shadow parts in the overlapping boards will be superimposed to become a darker color.
[0090] When rendering, the transparent part is processed by overlay, which can calculate the color of the ambient color and shadow information by overlay.
[0091] When the tables and chairs move, the offset distance of the shadow board relative to the tables and chairs can be calculated according to the position of the light source, and the shadow board can be offset to a certain extent to achieve the effect of an approximately dynamic shadow moving with the object. Here, only the impact of the model movement under parallel light is considered. The shadow generated at this time will only be displaced due to the movement of the model, and the size of the shadow will not change. Because this embodiment is a classroom scene, only sunlight is considered here (the light angle remains unchanged). When the seats move horizontally, the relative positions of the shadow board and the tables and chairs remain unchanged.
[0092] Method 2: Method 1 uses a "shadow board" to solve the problem of shadow movement on a plane. However, when the floor is a non-planar floor with concave and convex features, the "shadow board" method will have problems such as cutting, hiding, or suspension. In this case, the "projection map" technology is needed to realize a "shadow board" that can meet the concave and convex plane.
[0093] refer to Fig.11 As shown, the seat is simplified into a cube for illustration. Fig.11 This is a cross-sectional view of a cube on a concave or convex plane, where EF is the shadow plate and ABCD is the cube object. If the projection mapping technique is not used, the shadow will float in the air. From the side, you can see that BF does not overlap with the ground. Reference Fig.12 As shown in the figure, EGHF is the decal area, and the shadow will be projected onto the ground so that it fits with the ground. This technology is mainly used to solve the problem that the transparent shadow does not fit the ground.
[0094] Finally, when the object moves, the position of the shadow board is calculated. The previous method binds the relative position of the shadow board to the seat. When the seat moves on the horizontal plane, the shadow board moves accordingly, keeping the relative position with the seat unchanged. Therefore, the calculation of the position of the shadow board here only needs to be calculated according to the height change of the object.
[0095] It should be noted that when the object is close to the ground, the shadow can be directly placed at the vertical point of the model center point on the ground. However, considering that on the sunny side, due to direct light, no shadow will be generated, so at the optimized angle, the shadow board will generally be more biased towards the actual shadow area, which can increase the shadow area ratio in the shadow board and save some performance. Fig.13 As shown, the sunlight is coming from the left side, so the shadow board can be moved a certain distance to the right based on the vertical point position of the center point of the model on the ground. After the movement, the leftmost side of the shadow board is still best to be on the left side of the seat model.
[0096] When the object is raised, the offset position of the shadow plate can be calculated based on the known light angle and the distance the object is raised, combined with trigonometric functions. Then the shadow plate is placed or the projection map is generated based on this position. Fig.14 As shown, the angle between the parallel light and the ground is a. When the height of the cube is increased to a height of h, the moving distance of the shadow plate is dis=h / tan(a), and the moving direction is the direction of the light, that is, the E1H direction in the figure. This calculation method is suitable for height changes. If the angle of the model is rotated along the upward y-axis, even at the same light angle, different shadow effects will be produced. If this is the case, the shadow map at this angle needs to be baked in advance. When the angle is rotated and switched, the shadow map at the corresponding angle is replaced.
[0097] In the above embodiment, only the classroom scene in the 3D world is used as an example. In fact, the method of this embodiment can be used as long as the scene where the 3D scene needs to render shadows. When the ground is flat, the shadow board map can be used to directly implement it. When the ground is uneven, the projection map technology can also be used to implement it. The more limited point of this embodiment is that it is suitable for scenes where the ambient light source does not frequently change significantly during operation. Because when the ambient light source frequently changes significantly, the static shadow results generated will actually change significantly, such as angle, diffusion degree, etc. If there are situations where significant changes occur during operation, but this situation can be listed, then the baking rendering of the static map can be performed for each situation. When the light source changes in the running scene, it is only necessary to replace the corresponding shadow map in the shadow board. Using the method of this embodiment, the high-performance dependence required for dynamic shadows and the limitation that static shadows cannot be applied to movable objects can be solved, and good lighting and shadow effects can be achieved with less performance overhead.
[0098] In summary, this embodiment provides a method for simulating dynamic shadow effects through static shadows. When used to render objects with moving characteristics in a 3D scene, a shadow map with a transparent channel is first baked for the object, and then the shadow map and the scene color are merged and superimposed; when the object moves, the offset of the shadow map is calculated according to its movement mode, and the shadow map is offset accordingly, so that the effect of dynamic shadows can be achieved through the baking simulation of static shadows. By replacing conventional dynamic rendering with the method in this embodiment, both the effect and performance can be improved, and the problem that static shadows cannot be applied to movable objects and dynamic shadow effects and performance are insufficient in the prior art can be solved.
[0099] In addition, the shadow map baked by this embodiment is a shadow map with a transparent channel, which is different from conventional baking. Conventional baking does not have a transparent area, and the original color of the model surface is written in the non-shadow part, while this embodiment writes a transparent color in the non-shadow part. In this way, the ambient color can be expressed by superimposing calculation with the environment. The shadow map with a transparent channel in the embodiment of the present invention can be applied to more scenes, and there is no need to write different original colors for different models, which is more convenient and practical.
[0100] Furthermore, for planes with inconsistent heights, such as an uneven ground, this embodiment projects the shadow map onto the uneven ground in a rectangular manner to form a cubic mapping area, and then uses additive mixing to fuse and superimpose the shadow map with the scene color for the portion of the uneven ground that overlaps with the mapping area. This method can achieve the effect of fitting the shadow map with the planes with inconsistent heights, instead of directly using the shadow map for mapping, where the shadow map and the ground do not actually overlap when viewed from the side.
[0101] Embodiment 3
[0102] like Fig.15 As shown, the present embodiment provides a system for simulating dynamic shadow effects through static shadows, and applies the method for simulating dynamic shadow effects through static shadows as described in Example 1. The system includes a shadow baking module, a fusion and overlay module, and a shadow offset module; wherein: the shadow baking module is used to perform shadow baking on the target object, and bake out a shadow map with a transparent channel; the fusion and overlay module is used to fuse and overlay the shadow map with a transparent channel of the target object with the scene color; the shadow offset module is used to calculate the offset of the shadow map as the target object moves, and make a corresponding offset to the shadow map to achieve the simulation of dynamic shadow effects.
[0103] Specifically, the shadow baking module may include a shadow plane establishment module and a shadow map baking module, wherein the shadow plane establishment module is used to create a shadow plane for receiving shadows at the bottom of the target object; for the shadow plane establishment module, the modeling software may be called to directly create a patch at the bottom of the target object as a shadow plane to undertake subsequent shadow rendering. The shadow map baking module is used to bake the shadow information of the target object onto the shadow plane and bake out a shadow map with a transparent channel; the shadow map baking module uses the shadow plane as an object and performs shadow baking under global illumination to bake the shadow information of the target object onto the shadow plane; gray pixels are used for the shadowed part and transparent colors are used for the unshadowed part to bake out a shadow map with a transparent channel. It should be noted that the shadow map created here must be one with a transparent channel, so as to realize the superposition calculation of shadows and shadows, and the superposition calculation of shadows and the environment in subsequent steps.
[0104] The fusion overlay module may include a mapping overlay module and a projection overlay module, wherein the mapping overlay module uses an additive mixing method to fuse and overlay the shadow map with the scene color; after superposition, the shadowless part of the shadow map is fused and overlaid with the scene color to present the scene color, and the shadowed part of the shadow map is fused and overlaid with the scene color to present the shadow effect. For the mapping method of the shadow map, if the ground part to be mapped is a plane, then the mapping can be directly performed using the mapping overlay module. However, if the ground to be mapped is a non-planar ground with concave and convex features, the direct mapping method will have the problem of cutting and being hidden or suspended in the air. In this case, it is necessary to use a projection overlay module for mapping. The projection overlay module projects the shadow map in a rectangular manner onto a plane with inconsistent heights to form a cubic mapping area. For the part of the plane with inconsistent heights that overlaps with the mapping area, an additive mixing method is used to merge and superimpose the shadow map with the scene color. This method can achieve the effect of fitting the shadow map with the plane with inconsistent heights, instead of using the shadow map directly for mapping, where the shadow map and the ground do not overlap when viewed from the side.
[0105] The shadow offset module may include a target object movement data acquisition module, a horizontal plane calculation module, a vertical plane calculation module, and an overlay calculation module, wherein the target object movement data acquisition module is used to obtain the direction and distance of the target object movement, and the direction may be divided into a plane direction and a vertical direction. When the target object moves on the horizontal plane, the plane direction and distance of the target object movement are obtained and handed over to the horizontal plane calculation module for calculation. The plane direction here can be understood as the angle of the target object movement. For example, if the east is 0 degrees and the angle is calculated counterclockwise, then when the target object moves to the north, the angle of movement is 90 degrees, and when it moves to the south, the angle of movement is 270 degrees; when the target object moves on the vertical plane, the vertical direction and distance of the target object movement are obtained and handed over to the vertical plane calculation module for calculation. The vertical direction here can be understood as the change in height of the target object, which is divided into two types: rising and falling. When the target object moves in the spatial range, the total direction and distance of the target object movement are obtained and handed over to the overlay calculation module for calculation.
[0106] When the target object moves on the horizontal plane, the horizontal plane calculation module obtains the direction and distance of the target object on the horizontal plane, and directly uses the direction and distance as the direction and distance that the shadow map needs to move. For example, if the target object moves one meter to the south (90 degrees), then the shadow map also moves one meter to the south (90 degrees) accordingly. The movement of the shadow map here is based on its previous position as a reference. If the target object is used as a reference, then during the movement of the target object on the horizontal plane, the position of the shadow map relative to the target object remains unchanged.
[0107] When the target object moves on the vertical plane, the vertical plane calculation module obtains the direction and distance of the target object moving on the vertical plane, calculates the direction and distance of the shadow map according to the light source angle combined with trigonometric functions, and uses the direction and distance as the direction and distance that the shadow map needs to move. Specifically, when the light source angle is a and the distance the target object moves on the vertical plane is h, the moving distance of the shadow map is h / tan(a). When the target object moves upward on the vertical plane, the shadow map moves away from the target object; when the target object moves downward on the vertical plane, the shadow map moves toward the target object. For example, if the light source angle is 45 degrees, if the target object rises one centimeter on the vertical plane, then the shadow map needs to move one centimeter along the lighting direction to the side away from the target object; if the target object drops one centimeter on the vertical plane, then the shadow map needs to move one centimeter along the lighting direction to the side close to the target object.
[0108] The above two directions and distances are calculated separately for the target object moving on the horizontal plane and on the vertical plane. In actual application scenarios, there will be many scenes where the target objects move on both the horizontal and vertical planes, that is, the displacement in three-dimensional space. In view of this situation, the superposition calculation module is used for calculation. When the target object moves on both the horizontal and vertical planes, the superposition calculation module divides the movement of the target object into movement on the horizontal plane and movement on the vertical plane, and calculates the direction and distance that the shadow map needs to move on the horizontal plane and the direction and distance that the shadow map needs to move on the vertical plane, respectively, and then superimposes them to obtain the final direction and distance that needs to be moved. The superposition calculation module can also directly call the horizontal plane calculation module and the vertical plane calculation module, let the horizontal plane calculation module calculate the direction and distance that the shadow map needs to move on the horizontal plane, let the vertical plane calculation module calculate the direction and distance that the shadow map needs to move on the vertical plane, and then superimpose the two to obtain the final direction and distance that needs to be moved. For example, when the light source angle is 45 degrees, the target object moves one meter toward the south (90 degrees in the horizontal plane) on the horizontal plane and rises one centimeter on the vertical plane. Then calculate the direction and distance that the shadow map needs to move on the horizontal plane, that is, the shadow map needs to move one meter toward the south (90 degrees in the horizontal plane), and the direction and distance that the shadow map needs to move on the vertical plane, that is, the shadow map needs to move one centimeter away from the target object along the direction of light. Superimpose these two required movements to get the final moving position. During superposition, the superposition calculation module can also convert the illumination direction into an angle on the horizontal plane. Because the light source angle of 45 degrees in the previous example refers to the angle between the light source and the horizontal plane, after projecting it onto the horizontal plane, taking the east of the horizontal plane as 0 degrees, the relative angle of the illumination direction on the horizontal plane can be obtained. By superimposing the two angles and distances, the final angle and distance that the shadow map needs to move can be easily calculated. Of course, when moving the shadow map, the final superposition result can be omitted. Instead, the shadow map is directly moved in the direction and distance calculated by the divided horizontal plane, and then the shadow map is moved in the direction and distance calculated by the divided vertical plane. The shadow map can also be directly moved to the correct position. Such movement can omit one calculation step, but has an extra movement operation. The movement method can be selected according to actual needs.
[0109] It should be noted that the angle of the target object itself may also change. Generally, if the angle of the target object itself changes, the shadow map baked at the original angle is no longer applicable. For example, when the target object rotates along the upward y-axis, even at the same light angle, different shadow effects will be produced. For this case, the present embodiment can pre-bake the shadow map of the target object itself at different angles through the shadow baking module, and when the angle of the target object itself changes, switch to the shadow map at the corresponding angle. Of course, this case is only for the listed angle changes, or some important angle changes to pre-bake the shadow maps at these angles. In addition, the mobile calculation method involved in this embodiment is a calculation method when the light source scene does not change frequently and is parallel light. For example, sunlight within a period of time, the calculation under the above movement is accurate only when only parallel light is considered; if it is not parallel light, but a light source such as a lamp tube or a light bulb, it will produce different shadow effects as the position of the irradiated object changes. At this time, the previously baked shadow map cannot achieve this dynamic change. In this case, the shadow map must be baked dynamically. As for the situation where the light source may change, if the light source changes significantly during operation, but this situation can be listed, you can also bake and render the static map for each situation, and use the shadow baking module to pre-bake the shadow map of the target object under different light sources. When the light source changes in the running scene, switch to the shadow map under the corresponding light source.
[0110] In summary, this embodiment provides a system for simulating dynamic shadow effects through static shadows. When used to render objects with moving characteristics in 3D scenes, a shadow map with a transparent channel is first baked for the object, and then the shadow map and the scene color are merged and superimposed; when the object moves, the offset of the shadow map is calculated according to its movement mode, and the shadow map is offset accordingly, so that the effect of dynamic shadows can be achieved through the baking simulation of static shadows. By replacing conventional dynamic rendering with the method in this embodiment, both the effect and performance can be improved, and the problem that static shadows cannot be applied to movable objects and dynamic shadow effects and performance are insufficient in the prior art can be solved.
[0111] In addition, the shadow map baked by this embodiment is a shadow map with a transparent channel, which is different from conventional baking. Conventional baking does not have a transparent area, and the original color of the model surface is written in the non-shadow part, while this embodiment writes a transparent color in the non-shadow part. In this way, the ambient color can be expressed by superimposing calculation with the environment. The shadow map with a transparent channel in the embodiment of the present invention can be applied to more scenes, and there is no need to write different original colors for different models, which is more convenient and practical.
[0112] Furthermore, for planes with inconsistent heights, such as an uneven ground, this embodiment projects the shadow map onto the uneven ground in a rectangular manner to form a cubic mapping area, and then uses additive mixing to fuse and superimpose the shadow map with the scene color for the portion of the uneven ground that overlaps with the mapping area. This method can achieve the effect of fitting the shadow map with the planes with inconsistent heights, instead of directly using the shadow map for mapping, where the shadow map and the ground do not actually overlap when viewed from the side.
[0113] Embodiment 4
[0114] The embodiment of the present invention also provides a device for simulating dynamic shadow effects through static shadows, see Fig.16 , which shows that it is possible to execute Figures 4 to 5 The hardware structure of the method for simulating dynamic shadow effects through static shadows.
[0115] The device for simulating dynamic shadow effects by static shadows comprises: at least one processor 11; and a memory 12 in communication with the at least one processor 11. Fig.16 The memory 12 stores instructions that can be executed by the at least one processor 11, and the instructions are executed by the at least one processor 11 so that the at least one processor 11 can perform the above Figures 1 to 11 The method of simulating dynamic shadow effects by static shadows. The processor 11 and the memory 12 can be connected via a bus or other means. Fig.16 The example of connecting through bus is taken in the following.
[0116] The memory 12, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs and modules, such as program instructions / modules corresponding to the method for simulating dynamic shadow effects by static shadows in the embodiment of the present invention. The processor 11 executes various functional applications and data processing of the server by running the non-volatile software programs, instructions and modules stored in the memory 12, that is, the method for simulating dynamic shadow effects by static shadows in the above method embodiment is realized.
[0117] The memory 12 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and application programs required for at least one function; the data storage area may store data created by the use of a system for simulating dynamic shadow effects through static shadows, etc. In addition, the memory 12 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 12 may optionally include a memory remotely arranged relative to the processor 11, and these remote memories may be connected to the system for simulating dynamic shadow effects through static shadows via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0118] The one or more modules are stored in the memory 12, and when executed by the one or more processors 11, perform the method of simulating dynamic shadow effects by static shadows in any of the above method embodiments, for example, perform the above described Figures 4 to 5 method steps.
[0119] The above product can execute the method provided by the embodiment of the present invention, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not described in detail in this embodiment, please refer to the method provided by the embodiment of the present invention.
[0120] The embodiment of the present invention further provides a non-volatile computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are executed by one or more processors, for example, to execute the above-described Figures 4 to 5 method steps.
[0121] The embodiment of the present invention further provides a computer program product, including a computer program stored on a non-volatile computer-readable storage medium, wherein the computer program includes program instructions, and when the program instructions are executed by a computer, the computer executes the method of simulating dynamic shadow effects by static shadows in any of the above method embodiments, for example, executing the above described Figures 4 to 5 method steps.
[0122] In summary, different from the prior art, the embodiments of the present invention provide a method, system and device for simulating dynamic shadow effects through static shadows. When used to render objects with moving characteristics in a 3D scene, a shadow map with a transparent channel is first baked for the object, and then the shadow map and the scene color are merged and superimposed; when the object moves, the offset of the shadow map is calculated according to its movement mode, and the shadow map is offset accordingly, so that the effect of dynamic shadows can be achieved through the baking simulation of static shadows. Replacing conventional dynamic rendering with the method in the embodiments of the present invention can achieve a dual improvement in effect and performance, and can solve the problem that static shadows in the prior art cannot be applied to movable objects, and dynamic shadow effects and performance are insufficient.
[0123] In addition, the shadow map baked by the embodiment of the present invention is a shadow map with a transparent channel, which is different from conventional baking. Conventional baking does not have a transparent area, and the original color of the model surface is written in the non-shadow part, while the embodiment of the present invention writes a transparent color in the non-shadow part. In this way, the ambient color can be expressed by superimposing calculation with the environment. The shadow map with a transparent channel in the embodiment of the present invention can be applied to more scenes, and there is no need to write different original colors specifically for different models, which is more convenient and practical.
[0124] Furthermore, for a plane with inconsistent heights, such as an uneven ground, the embodiment of the present invention projects the shadow map onto the uneven ground in a rectangular manner to form a cubic mapping area, and then uses an additive mixing method to fuse and superimpose the shadow map and the scene color on the portion of the uneven ground that overlaps with the mapping area. This method can achieve the effect of fitting the shadow map with the plane with inconsistent heights, instead of directly using the shadow map for mapping, where the shadow map and the ground do not actually overlap when viewed from the side.
[0125] It should be noted that the device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0126] Through the description of the above implementation methods, ordinary technicians in this field can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, it can also be implemented by hardware. Ordinary technicians in this field can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0127] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them. Under the concept of the present invention, the technical features in the above embodiments or different embodiments may also be combined, the steps may be implemented in any order, and there are many other changes in different aspects of the present invention as described above, which are not provided in detail for the sake of simplicity. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for simulating dynamic shadow effects by static shadows, characterized in that: include: Create a shadow plane at the bottom of the target object to receive the shadow, bake the shadow information of the target object onto the shadow plane, and bake out a shadow map with a transparent channel; When the target object is loaded into the scene, the shadow map with the transparent channel of the target object is merged and superimposed with the scene color; When the target object moves, the offset of the shadow map is calculated and the shadow map is offset accordingly to simulate the dynamic shadow effect.
2. The method for simulating dynamic shadow effects by static shadows according to claim 1, characterized in that: The step of baking the shadow information of the target object onto the shadow plane to bake out a shadow map with a transparent channel specifically includes: Take the shadow plane as the object and perform shadow baking under global illumination to bake the shadow information of the target object onto the shadow plane; use gray pixels for the shadowed part and transparent colors for the unshadowed part to bake out a shadow map with a transparent channel.
3. The method for simulating dynamic shadow effects by static shadows according to claim 2, characterized in that: The step of fusing and superimposing the shadow map with a transparent channel of the target object with the scene color specifically includes: The shadow map is fused and superimposed with the scene color by additive mixing. The shadow map without shadow is fused and superimposed with the scene color to present the scene color. The shadow map with shadow is fused and superimposed with the scene color to present the shadow effect.
4. The method for simulating dynamic shadow effects by static shadows according to claim 1, characterized in that: When the target object moves, calculating the offset of the shadow map and offsetting the shadow map accordingly to achieve the simulation of the dynamic shadow effect specifically includes: When the target object moves, the direction and distance of the target object's movement are obtained; Calculate the direction and distance that the shadow map needs to move according to the direction and distance of the target object's movement; The shadow map is moved according to the calculated direction and distance that the shadow map needs to move to simulate the dynamic shadow effect.
5. The method for simulating dynamic shadow effects by static shadows according to claim 4, characterized in that: When the target object moves on the horizontal plane, the direction and distance in which the target object moves on the horizontal plane are obtained, and the direction and distance are used as the direction and distance in which the shadow map needs to move.
6. The method for simulating dynamic shadow effects by static shadows according to claim 4, characterized in that: When the target object moves on the vertical plane, the direction and distance of the target object on the vertical plane are obtained, the direction and distance of the shadow map are calculated according to the light source angle combined with trigonometric functions, and the direction and distance are used as the direction and distance that the shadow map needs to move.
7. The method for simulating dynamic shadow effects by static shadows according to claim 6, characterized in that: When the light source angle is a and the target object moves a distance h on the vertical plane, the moving distance of the shadow map is h / tan(a).
8. The method for simulating dynamic shadow effects by static shadows according to claim 6, characterized in that: When the target object moves upward on the vertical plane, the shadow map moves away from the target object; when the target object moves downward on the vertical plane, the shadow map moves toward the target object.
9. The method for simulating dynamic shadow effects by static shadows according to claim 4, characterized in that: When the target object moves on both the horizontal and vertical planes, the movement of the target object is divided into movement on the horizontal plane and movement on the vertical plane. The direction and distance that the shadow map needs to move on the horizontal plane and the direction and distance that it needs to move on the vertical plane are calculated separately, and then superimposed to obtain the final direction and distance that needs to be moved.
10. The method for simulating dynamic shadow effects by static shadows according to any one of claims 1 to 9, characterized in that: For a plane with inconsistent height, the step of fusing and superimposing the shadow map with a transparent channel of the target object with the scene color specifically includes: The shadow map is projected onto a plane with inconsistent heights in a rectangular manner to form a cubic mapping area; for the part of the plane with inconsistent heights that overlaps with the mapping area, the shadow map is fused and superimposed with the scene color using additive mixing.
11. The method for simulating dynamic shadow effects by static shadows according to any one of claims 1 to 9, characterized in that: Pre-bake the shadow map of the target object at different angles. When the angle of the target object changes, switch to the shadow map at the corresponding angle.
12. The method for simulating dynamic shadow effects by static shadows according to any one of claims 1 to 9, characterized in that: Pre-bake the shadow map of the target object under different light sources. When the light source changes, switch to the shadow map under the corresponding light source.
13. A system for simulating dynamic shadow effects through static shadows, characterized in that: It includes shadow baking module, fusion overlay module and shadow offset module; among them: The shadow baking module is used to bake the shadow of the target object and bake out a shadow map with a transparent channel; The fusion and overlay module is used to fuse and overlay the shadow map with a transparent channel of the target object with the scene color; The shadow offset module is used to calculate the offset of the shadow map as the target object moves, and to make a corresponding offset to the shadow map to achieve the simulation of the dynamic shadow effect.
14. A device for simulating dynamic shadow effects by static shadows, characterized in that: It includes at least one processor and a memory, wherein the at least one processor and the memory are connected via a data bus, and the memory stores instructions that can be executed by the at least one processor, and after being executed by the processor, the instructions are used to complete the method of simulating dynamic shadow effects by static shadows as described in any one of claims 1-12.