Shadow map generation method, device and electronic equipment
By dividing the spherical space into hemispherical spaces and performing projection mapping, the problem of depth information loss in the mapping process of shadow maps is solved, the utilization rate of shadow maps is improved, and the performance and effect of point light source shadow rendering are enhanced.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NETEASE (HANGZHOU) NETWORK CO LTD
- Filing Date
- 2023-03-15
- Publication Date
- 2026-07-14
AI Technical Summary
In existing technologies, shadow mapping results in the loss of depth information when mapping 3D space to a 2D plane, and the utilization rate of shadow mapping is low, which affects the performance and effect of point light source shadow rendering.
The spherical space is divided into hemispherical spaces. Scene depth data on the hemispherical surface is collected and recorded onto a plane based on projection relationships to form an initial shadow map. Then, the data in the initial shadow map is mapped to a rectangular area to improve the utilization rate of the shadow map.
By reducing the loss of depth information, the utilization rate of shadow maps is improved, thereby enhancing the performance and effect of point light source shadow rendering.
Smart Images

Figure CN116440498B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of game technology, and in particular to a method, apparatus and electronic device for generating shadow maps. Background Technology
[0002] When rendering virtual scenes, shadow effects are typically required. For a point light source, the light emitted illuminates all directions of the virtual scene. In related technologies, a sphere can be placed centered on the point light source. An orthographic camera can be used to capture the depth information of the scene within the sphere, and this information is rasterized onto a texture map called a shadow map. During scene rendering, the depth information in the shadow map is sampled, and then used to determine whether the scene location of a screen pixel is occluded. If occlusion occurs, lighting is not applied, thus creating the shadow effect.
[0003] However, since shadow mapping maps the depth information in three-dimensional space onto a two-dimensional plane, it results in the loss of depth information. At the same time, only a roughly circular area in the shadow map records depth information, leading to a large amount of map area being wasted. The utilization rate of shadow maps is low, which affects the performance and effect of point light source shadow rendering. Summary of the Invention
[0004] In view of this, the purpose of the present invention is to provide a method, apparatus and electronic device for generating shadow maps, so as to improve the utilization rate of shadow maps and enhance the performance and effect of point light source shadow rendering.
[0005] In a first aspect, embodiments of the present invention provide a method for generating a shadow map, the method comprising: determining a target point light source in a virtual scene and determining the spherical space covered by the light emitted by the target point light source; dividing the spherical space into a hemispherical space; collecting scene depth data of various positions on the hemispherical surface corresponding to the hemispherical space; recording the scene depth data on the plane based on the projection relationship of the positions on the hemispherical surface onto the plane to obtain an initial shadow map; wherein the scene depth data in the initial shadow map forms a circular planar region; and mapping the scene depth data in the initial shadow map to the rectangular planar region based on the mapping relationship between the circular planar region and the rectangular planar region to obtain a final shadow map.
[0006] Secondly, embodiments of the present invention also provide a shadow map generation apparatus, the apparatus comprising: a first confirmation module, configured to determine a target point light source in a virtual scene and determine the spherical space covered by the light emitted by the target point light source; a first division module, configured to divide the spherical space into a hemispherical space; a first recording module, configured to collect scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space, and record the scene depth data on the plane based on the projection relationship of the position points on the hemispherical surface onto the plane to obtain an initial shadow map; wherein the scene depth data in the initial shadow map forms a circular planar region; and a first mapping module, configured to map the scene depth data in the initial shadow map to the rectangular region based on the mapping relationship between the circular planar region and the rectangular planar region to obtain a final shadow map.
[0007] Thirdly, embodiments of the present invention provide an electronic device, including a processor and a memory, wherein the memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the above-described method for generating shadow maps.
[0008] Fourthly, embodiments of the present invention provide a machine-readable storage medium storing machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions cause the processor to implement the above-described method for generating shadow maps.
[0009] The embodiments of the present invention bring the following beneficial effects:
[0010] The aforementioned shadow map generation method, apparatus, and electronic device determine a target point light source in a virtual scene and the spherical space covered by the light emitted by the target point light source; divide the spherical space into hemispherical spaces; collect scene depth data of various positions on the hemispherical surface corresponding to the hemispherical space; and record the scene depth data on the plane based on the projection relationship of the positions on the hemispherical surface onto the plane to obtain an initial shadow map; wherein the scene depth data in the initial shadow map forms a circular planar region; and based on the mapping relationship between the circular planar region and the rectangular planar region, map the scene depth data in the initial shadow map onto the rectangular region to obtain the final shadow map. In this method, the spherical space covered by the light emitted from the target point light source is divided into hemispherical spaces. Based on the projection relationship between the position points on the hemispherical surface and the plane, the scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space is recorded on the plane to form a circular plane region. Then, the scene depth data is mapped to a rectangular region to obtain the final shadow map. In this method, mapping the hemispherical surface to a circular plane and then to a rectangular plane reduces the loss of depth information and improves the utilization rate of the shadow map. More spatial depth information is recorded through the rectangular map, thereby enhancing the performance and effect of point light source shadow rendering.
[0011] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention are realized and obtained in accordance with the structures particularly pointed out in the description, claims and drawings.
[0012] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0013] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0014] Figure 1 This is a schematic diagram illustrating the acquisition of scene depth information of a scene covered by a point light source, as provided in an embodiment of the present invention.
[0015] Figure 2 This is a schematic diagram illustrating the acquisition of a shadow map according to an embodiment of the present invention;
[0016] Figure 3 A schematic diagram of the projection of a spherical space covered by light emitted from a point light source, provided in an embodiment of the present invention;
[0017] Figure 4 This is a schematic diagram illustrating the refraction of light by a convex lens according to an embodiment of the present invention.
[0018] Figure 5 A flowchart illustrating a method for generating a shadow map according to an embodiment of the present invention;
[0019] Figure 6 This is a schematic diagram of an equal-area mapping process provided in an embodiment of the present invention;
[0020] Figure 7 A schematic diagram illustrating the mapping of a position point on a spherical surface to a plane, provided as an embodiment of the present invention;
[0021] Figure 8 This is a schematic diagram illustrating the conversion between a circular projection area and a square projection area, provided in an embodiment of the present invention.
[0022] Figure 9 This is a schematic diagram illustrating the division of a spherical space into hemispherical spaces according to an embodiment of the present invention.
[0023] Figure 10 A schematic diagram of a shadow map generation device provided in an embodiment of the present invention;
[0024] Figure 11 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0026] First, let's introduce the terms used in the embodiments of this application:
[0027] 1. Draw Primitive
[0028] Abbreviated as DP, in the dx9 era, DrawPrimitive was abbreviated as DP, which corresponds to Unity DrawCall. It is the CPU (Central Processing Unit) calling the underlying graphics interface. Each rendering needs to call the underlying interface once. The number of DPs determines the CPU load in the rendering process. A high number of DPs will overwhelm the CPU, thus causing the game's rendering frame rate to drop.
[0029] 2. UV coordinates
[0030] UV mapping is a planar representation of the surface of a 3D model used to easily wrap textures. U and V refer to the horizontal and vertical axes in 2D space. UV coordinates mean that all image files are two-dimensional planes, with the horizontal direction being U and the vertical direction being V. Through this two-dimensional UV coordinate system, any pixel on the image can be located.
[0031] In real-time game rendering, shadows are an essential effect. Currently, a common real-time shadow rendering solution involves generating multiple different shadow maps for object models in the game scene. This is done by placing a camera at the light source location to capture the scene's depth information, then rasterizing this depth information onto a single texture map to obtain the shadow map. When actually rendering the object, the shadow map is sampled to determine if the light at the screen pixel's location is occluded. If occlusion occurs, lighting shading is not applied, thus creating the shadow effect.
[0032] The shadow mapping method differs for different types of light sources. For example, parallel sunlight is orthographically mapped; light from point sources and spotlights is perspective-mapped. When acquiring shadow mapping information, directional lights and spotlights only require one camera, while point sources, because they illuminate in all directions, cannot acquire omnidirectional shadow information with just one camera.
[0033] In related technologies, cubic shadow mapping can be used to obtain the shadow map of a point light source. This method involves placing a cube around the point light source, such as... Figure 1 As shown, six cameras are placed along the point light source in six directions: Pos x, Neg x, Pos y, Neg y, Pos z, and Neg z, respectively, to collect scene depth information in each direction of the point light source, resulting in six shadow maps. Taking the Pos z direction as an example, the shadow map obtained in this direction is as follows. Figure 2 As shown, this method uses six shadow maps to map depth information from three-dimensional space onto a two-dimensional plane texture.
[0034] However, this method has the following drawbacks: 1) It requires six shadow cameras to perform six batches of shadow casting, which can easily interrupt the batching of object models, leading to an increase in dynamic range (dp) and increasing the CPU load in the rendering process; 2) Since the actual point light range of a point light source is a sphere with a positive Gaussian curvature, the accuracy of mapping the sphere to the plane is reduced, making it impossible to project the sphere onto the plane in a completely lossless manner. Increasing the resolution of each shadow map to reduce this loss would result in excessive bandwidth usage and increased system resource consumption.
[0035] To avoid these problems, related technologies can also obtain the shadow map of a point light source using the Dual Paraboloid Shadow Mapping (DPSM) method. In this method, a sphere is set around the point light source, and the area covered by the light emitted from the point light source is divided into two hemispheres, such as... Figure 3 As shown, each projection is performed once using an orthographic camera. During projection calculation, a parabolic transformation is applied to the vertices in the vertex shader and stored in the shadow map. A parabolic transformation is also performed during the generation of UV coordinates when sampling the shadow map. This method leverages the characteristic that light rays refracted by a convex lens emanating from the focal point become parallel after passing through the parabolic surface, as shown... Figure 4 As shown, by optimizing the mapping itself, the number of shadow cameras is reduced, thus lowering the loss from spherical to planar mapping. However, in this approach, only the central, approximately circular area of the generated shadow map is utilized, while the areas near the four corners are wasted, resulting in low utilization of the shadow map and affecting the performance and effect of point light source shadow rendering.
[0036] Based on this, embodiments of the present invention provide a method, apparatus, and electronic device for generating shadow maps. This technology can be applied to point light source shadow rendering in game scenes or other virtual scenes.
[0037] To facilitate understanding of this embodiment, a method for generating a shadow map disclosed in this invention will first be described in detail, such as... Figure 5 As shown, the method includes the following steps:
[0038] Step S502: Determine the target point light source in the virtual scene, and determine the spherical space covered by the light emitted by the target point light source;
[0039] The aforementioned point light source emits light uniformly from a single point into the surrounding space, illuminating a sphere of the virtual scene. Here, a target point light source within the virtual scene is acquired, and a spherical space is constructed centered on this target point light source, enclosing the virtual scene illuminated by it. The virtual scene within this spherical space can contain both static and dynamic models, such as moving character models, stationary plant models, wall models, and stone models. Each point on the curved surface of the spherical space corresponds to the depth data of these virtual scene elements from the point light source.
[0040] Step S504: Divide the spherical space into hemispherical spaces;
[0041] Here, a spherical space is divided into two hemispherical spaces, which means that the virtual scene illuminated by the point light source is divided into hemispherical spaces. It should be noted that the division method can be based on the dynamic and static states of the models in the virtual scene.
[0042] Step S506: Collect scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space. Based on the projection relationship of the position points in the hemispherical surface onto the plane, record the scene depth data on the plane to obtain the initial shadow map; wherein, the scene depth data in the initial shadow map forms a circular planar region.
[0043] In this step, rendering is performed from the perspective of the light source's position. The scene depth data of the virtual scene illuminated by the point light source, relative to the light source, is recorded on a plane to obtain the corresponding shadow map. Here, considering that the mapping from a sphere to a plane is not linear, the scene depth data stored uniformly on the sphere will be unevenly mapped onto the plane, especially at the edges of the sphere where the data differences will be greater. Therefore, a camera can be used to first collect scene depth data at various points on the hemispherical surface corresponding to the split hemispherical space. Based on the projection relationship between the points on the hemispherical surface and the plane, the scene depth data is recorded on the projection points on the plane to obtain the initial shadow map. The scene depth data in the initial shadow map forms a circular planar region.
[0044] In this method, scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space is collected. Based on the projection relationship of the position points in the hemispherical surface onto the plane, the scene depth data of the virtual scene illuminated by the point light source from the light source is recorded in the plane to obtain the corresponding initial shadow map, which improves the accuracy of mapping scene depth data of each position point on the surface to the plane.
[0045] Step S506: Based on the mapping relationship between the circular planar region and the rectangular planar region, map the scene depth data in the initial shadow map to the rectangular region to obtain the final shadow map.
[0046] After mapping from the curved surface to the plane, only the central circular area of the initial rectangular shadow map records scene depth data, resulting in a significant waste of texture area. Therefore, to improve the utilization rate of the shadow map, this step remaps the scene depth data corresponding to the projection points in the initial shadow map, mapping the scene depth data from the initial shadow map onto the rectangular area to obtain the final shadow map. Real-time shadow rendering is then achieved by sampling and rendering the shadow map.
[0047] In this method, the scene depth data corresponding to the projection points in the initial shadow map is mapped to a rectangular area, which improves the utilization rate of the shadow map and further enhances the performance and effect of point light source shadow rendering.
[0048] The above-described method for generating shadow maps involves determining a target point light source in a virtual scene and defining the spherical space covered by the light emitted from that source; dividing the spherical space into hemispherical spaces; collecting scene depth data from various points on the hemispherical surface corresponding to the hemispherical space; and recording the scene depth data onto the plane based on the projection relationship between the points on the hemispherical surface and the plane to obtain an initial shadow map; wherein the scene depth data in the initial shadow map forms a circular planar region; and mapping the scene depth data in the initial shadow map onto the rectangular planar region based on the mapping relationship between the circular planar region and the rectangular planar region to obtain the final shadow map. In this method, the spherical space covered by the light emitted from the target point light source is divided into hemispherical spaces. Based on the projection relationship between the position points on the hemispherical surface and the plane, the scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space is recorded on the plane to form a circular plane region. Then, the scene depth data is mapped to a rectangular region to obtain the final shadow map. In this method, mapping the hemispherical surface to a circular plane and then to a rectangular plane reduces the loss of depth information and improves the utilization rate of the shadow map. More spatial depth information is recorded through the rectangular map, thereby enhancing the performance and effect of point light source shadow rendering.
[0049] The following embodiments provide a way to implement an initial shadow map.
[0050] Specifically, the projection points of the positions in the hemispherical surface onto the plane are determined by equal area mapping; the scene depth data corresponding to the positions in the hemispherical surface are recorded on the projection points on the plane.
[0051] The above process of equal area mapping can be described as follows: Figure 6 As shown, equal-area mapping, also known as Lambert's Equal Area mapping, involves first placing a complete sphere on the mapping plane. The point where the sphere is tangent to the plane is called the south pole, and the point symmetrical to the south pole through the center of the sphere is called the north pole. Then, a unique circle is found centered at the south pole, passing through a point on the sphere and perpendicular to the plane. The point where this circle intersects the plane is the projection point of the position point on the entire sphere onto the plane. In this way, equal-area mapping can record the scene depth data corresponding to the position points on the entire sphere onto the projection points on the plane. However, in the mapping process of a complete sphere, as... Figure 7 As shown, for a very small circular point on the entire sphere, if it is located in front or behind the sphere and mapped from the sphere to the plane, it is basically still a circle. However, if it is located in the edge regions such as the left, top, right, or bottom, it will be stretched into an ellipse when mapped to the plane, causing data distortion. Therefore, in this embodiment, the spherical space covered by the light emitted from the target point light source is divided into hemispherical spaces. The projection points of the position points in the hemispherical surface onto the plane are considered separately, which effectively reduces the mapping deformation of each edge position point of the hemisphere. Furthermore, the scene depth data corresponding to the position points in the hemispherical surface is recorded on the projection points on the plane, which improves the accuracy of the scene depth data mapped from the position points to the scene depth data on the plane.
[0052] In one specific implementation, this embodiment can provide a hemispherical mapping formula, namely,
[0053]
[0054]
[0055] Where, the upper equation represents the formula for mapping from a sphere to a circle, and the lower equation represents the formula for mapping from a circle to a sphere; (x, y, z) is... Figure 6 The coordinates of a point on the curved surface of the Northern Hemisphere where the North Pole is located; (x, y) is... Figure 6 The coordinates of the projection point on the initial shadow map plane after mapping.
[0056] The above method records the scene depth data corresponding to the position points in the hemispherical surface into the projection points on the plane by equal area mapping, forming a circular planar region and obtaining the initial shadow map. This method effectively reduces the mapping deformation of edge position points and improves the accuracy of the mapped scene depth data.
[0057] The following embodiments provide a way to implement the final shadow map.
[0058] Specifically, the mapping points of the projection points in the initial shadow map are determined in the rectangular planar region by means of elliptical mapping; the scene depth data corresponding to the projection points in the initial shadow map are recorded in the mapping points in the rectangular planar region.
[0059] The aforementioned rectangular planar region can be a square planar region. In one specific implementation, this embodiment can provide a mapping formula, namely,
[0060]
[0061]
[0062]
[0063] The first two formulas represent the mapping formulas from a circular projection area to a square planar area, and the third and fourth formulas represent the mapping formulas from a square planar area to a circular projection area; (x, y) are the coordinates of the projection point in the initial shadow map; (u, v) are the coordinates of the projection point in the final shadow map after elliptical mapping.
[0064] Accordingly, the above mapping process, such as Figure 8 As shown. Process ① is the process of projecting a circular projection area onto a square planar area; process ② is the process of projecting a square planar projection area onto a circular projection area.
[0065] Elliptical mapping, also known as Elliptical Grid Mapping, determines the mapping points of the projection points in the initial shadow map within a rectangular planar region. The scene depth data corresponding to the points on the hemispherical surface is then recorded on the projection points on the plane to obtain the final shadow map. This improves the utilization rate of the shadow map and further enhances the performance and effect of point light source shadow rendering.
[0066] It should be noted that when using a camera to collect scene depth data on the hemispherical surface corresponding to the hemispherical space, the camera's view frustum can be made to enclose the projected objects within the hemisphere as tightly as possible, so that the collected effective information fills the entire projection plane as much as possible, which can also improve the utilization rate of shadow maps.
[0067] To further improve the performance and effect of light source shadow rendering, the number of DPs can be reduced. This can be achieved by reducing the number of batches submitted by the engine per frame, thereby reducing the rendering pressure of shadows. Specifically, this can be achieved by batching objects or reducing the number of scene models that need to be projected, and by using fewer shadow cameras to collect depth information of the virtual scene. This is closely related to the way the spherical space surrounding the virtual scene is divided.
[0068] The following embodiments provide a specific implementation method for dividing a spherical space into hemispherical spaces. In this method, the division of the hemispherical space is related to the dynamic and static states of the model in the virtual scene.
[0069] In one specific approach, for a static model in a virtual scene, the spherical space is divided into hemispherical spaces according to the specified dimensions of the three-dimensional spatial coordinate system of the virtual scene.
[0070] In practice, for static models, the spherical space can be divided into two hemispheres according to the +y and -y directions in three-dimensional space, and two orthogonal projection cameras can be generated. The above method can collect the depth information of the virtual scene illuminated by the point light source by using the orthogonal projection camera, which reduces the CPU burden in the rendering process.
[0071] In another specific approach, for dynamic models in a virtual scene, the main camera's viewing frustum in the virtual scene is determined; based on the designated viewing frustum plane of the main camera's viewing frustum, the spherical space is divided into hemispherical spaces.
[0072] In this method, one of the two orthogonal cameras in the virtual scene is a master camera. The master camera's view frustum captures scene depth data and projects this data onto a plane. The master camera's view frustum has six view frustum planes: left, right, top, bottom, near, and far. Here, after determining the master camera's view frustum based on the current position of the dynamic model in the virtual scene, the spherical space needs to be divided into hemispherical spaces according to the designated view frustum plane. The designated view frustum plane is related to the relative position of the master camera's view frustum and the point light source.
[0073] In one scenario, if the target point light source is located inside the main camera's view frustum, and a portion of the spherical space is also located inside the main camera's view frustum, the view frustum plane closest to the target point light source is determined from among the multiple view frustum planes of the main camera's view frustum; a dividing plane passing through the target point light source is generated; wherein the dividing plane is parallel to the nearest view frustum plane; and the spherical space is divided into hemispherical spaces by the dividing plane.
[0074] In other words, when the target point light source is located inside the main camera's view frustum and part of the spherical space is also located inside the main camera's view frustum, find the view frustum plane that is closest to the target point light source within the main camera's view frustum. Then, determine the dividing plane that is parallel to the closest view frustum plane and passes through the target point light source. The spherical space is divided into hemispherical spaces by the dividing plane. In actual implementation, the view frustum plane that is closest to the target point light source can be translated to the position of the point light source to divide the spherical space, thus dividing the spherical space into hemispherical spaces.
[0075] In this method, one of the two hemispherical spaces is not intersected with the main camera's view frustum. Therefore, the depth information of this hemispherical space does not need to be processed. Only the hemispherical space that intersects with the main camera's view frustum needs to be processed.
[0076] Specifically, the target hemispherical space intersecting with the main camera's view frustum is determined; the clipping plane of the projection camera corresponding to the target hemispherical space is adjusted so that the clipping plane matches the main camera's view frustum.
[0077] In other words, the clipping plane of the projection camera corresponding to the target hemispherical space is adjusted so that the clipping plane matches the view frustum of the main camera. For example, the near and far clipping planes of the projection camera corresponding to the hemispherical space intersecting with the view frustum of the main camera are made to wrap the view frustum of the main camera as tightly as possible.
[0078] In this method, by making the dividing plane of the two hemispheres parallel to the plane of the nearest main camera's viewing cone, the number of projected objects in the hemisphere is reduced by adjusting the far clipping distance of the projection camera that intersects with the viewing cone, thereby reducing the number of projection objects (DPs).
[0079] In another case, if the target point light source is located outside the main camera's view frustum, and part of the spherical space is located inside the main camera's view frustum, the spherical space is divided into hemispherical spaces by a preset plane; wherein, the preset plane is used to control the main camera's view frustum to intersect with only one hemispherical space.
[0080] In other words, when the target point light source is located outside the main camera's viewing frustum and part of the spherical space is located inside the main camera's viewing frustum, the main camera's viewing frustum can be adjusted to intersect only one hemispherical space, thus dividing the spherical space into hemispherical spaces. A schematic diagram of this division method is shown below. Figure 9 As shown,
[0081] In this case, one less hemispherical projection can be used, and the main camera's view frustum can be more compact, enclosing the projected object within the hemisphere.
[0082] By updating the shadow map in real time according to the update conditions and sampling and rendering the shadow map, the effect of real-time shadow rendering can be achieved for virtual scenes illuminated by point light sources. The following embodiments provide the conditions and implementation methods for updating the final shadow map. Among them, the conditions and methods for updating the final shadow map vary depending on the dynamic or static state of the model in the virtual scene.
[0083] Specifically, for static models in a virtual scene, if the preset first update condition of the static model is triggered, the following steps are performed to update the final shadow map corresponding to the static model: A target point light source is determined in the virtual scene, and the spherical space covered by the light emitted by the target point light source is determined; the spherical space is divided into hemispherical spaces; scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space is collected; based on the projection relationship of the position points on the hemispherical surface onto the plane, the scene depth data is recorded on a two-dimensional plane to obtain an initial shadow map; wherein, the scene depth data in the initial shadow map forms a circular planar region; based on the mapping relationship between the circular planar region and the rectangular planar region, the scene depth data in the initial shadow map is mapped to the rectangular region to obtain the final shadow map.
[0084] The first update condition mentioned above is the trigger condition for updating the final shadow map corresponding to the static model. When the first update condition is triggered, the final shadow map of the static model is updated according to the following steps: Specifically, a target point light source is determined in the virtual scene, and the spherical space covered by the light emitted by the target point light source is determined; the spherical space is divided into hemispherical spaces; scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space is collected; according to the projection relationship of the position points in the hemispherical surface onto the plane, the scene depth data is recorded on the two-dimensional plane to obtain the initial shadow map; wherein, the scene depth data in the initial shadow map forms a circular planar region; according to the mapping relationship between the circular planar region and the rectangular planar region, the scene depth data in the initial shadow map is mapped to the rectangular region to obtain the updated final shadow map.
[0085] Here, the first update condition preset for the static model includes at least one of the following: the preset shadow map resolution of the static model changes; the position of the target point light source in the virtual scene changes; the spherical space covered by the light emitted by the target point light source changes, and the range of change of the spherical space exceeds a preset range threshold; the intersection state of the hemispherical space and the view frustum of the main camera in the virtual scene changes.
[0086] Regarding the resolution of shadow maps, it's important to note that since players pay less attention to the projection effect of the upper half of static objects, the projection doesn't need to be sharp and accurate. The resolution of the upper hemisphere can be set to half that of the lower hemisphere, for example, 512x512 dpi for the lower hemisphere and 256x256 dpi for the upper hemisphere. This reduces the CPU load during rendering without affecting the visual effect. Changes in the position of the target point light source in the virtual scene will alter the radius of the sphere generated by the point light, causing changes in the sphere space covered by the light emitted from the target point light source, thus affecting the final shadow map.
[0087] When at least one of the following changes occurs: the shadow map resolution, the position of the target point light source in the virtual scene, or the intersection state between the hemispherical space and the main camera's view frustum in the virtual scene, or when the range of change in the spherical space exceeds the range threshold, the final shadow map of the static model is updated.
[0088] In another scenario, for dynamic models in a virtual scene, based on the preset update rules of the dynamic model, the following steps are performed to update the final shadow map corresponding to the dynamic model: A target point light source is determined in the virtual scene, and the spherical space covered by the light emitted by the target point light source is determined; the spherical space is divided into hemispherical spaces; scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space is collected; based on the projection relationship of the position points on the hemispherical surface onto the plane, the scene depth data is recorded on a two-dimensional plane to obtain an initial shadow map; wherein, the scene depth data in the initial shadow map forms a circular planar region; based on the mapping relationship between the circular planar region and the rectangular planar region, the scene depth data in the initial shadow map is mapped to the rectangular region to obtain the final shadow map.
[0089] In other words, according to the preset update rules of the dynamic model, the final shadow map of the dynamic model is updated according to the following steps: Specifically, a target point light source is determined in the virtual scene, and the spherical space covered by the light emitted by the target point light source is determined; the spherical space is divided into hemispherical spaces; scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space is collected; based on the projection relationship of the position points in the hemispherical surface onto the plane, the scene depth data is recorded on the two-dimensional plane to obtain the initial shadow map; wherein, the scene depth data in the initial shadow map forms a circular planar region; based on the mapping relationship between the circular planar region and the rectangular planar region, the scene depth data in the initial shadow map is mapped to the rectangular region to obtain the final shadow map.
[0090] The dynamic model's preset update rules include at least one of the following: if the target point light source is located inside the main camera's view frustum in the virtual scene, the final shadow map corresponding to each hemispherical space is updated according to a preset frame rate; if the target point light source is located outside the main camera's view frustum in the simulated scene, the first hemispherical space intersecting with the main camera's view frustum is determined, and the final shadow map corresponding to the first hemispherical space is updated according to a preset frame rate.
[0091] For example, the update rules preset by the dynamic model include at least one of the following:
[0092] 1) Check "Cast Dynamic Shadow" for the point light;
[0093] 2) When the point light source is inside the view frustum of the main camera; both final shadow maps are updated. Here, the dynamic model can be understood as constantly moving, and it must be updated every frame to make the shadow move along with it.
[0094] 3) When the point light source is outside the main camera's view frustum, only the final shadow map of the hemispherical space intersecting with the view frustum is updated;
[0095] In this approach, for dynamic models, the orientation and clipping distance of the shadow camera can be adaptively adjusted to minimize the number of objects drawn and reduce the number of dynamic drawing operations (DP).
[0096] In addition, during the update process of the final shadow map corresponding to the dynamic model, it is also necessary to determine the hemispherical space to be updated based on the preset update rules of the dynamic model; update the first transformation matrix and the second transformation matrix corresponding to the hemispherical space to be updated; wherein, the first transformation matrix is used to: transform from the world coordinate space corresponding to the virtual scene to the view space of the shadow camera in the hemispherical space; the second transformation matrix is used to: transform from the view space of the shadow camera in the hemispherical space to the shadow camera clipping space; based on the updated first transformation matrix and the second transformation matrix, update the final shadow map corresponding to the hemispherical space to be updated.
[0097] In actual implementation, the parameter corresponding to the first transformation matrix is the World View Matrix; the parameter corresponding to the second transformation matrix is the Projection Matrix. Here, the World View Matrix and Projection Matrix corresponding to the two hemispherical spaces are updated, and the final shadow map corresponding to the hemispherical space to be updated is updated according to the updated two parameters.
[0098] For the corresponding method embodiments described above, see [link to relevant documentation]. Figure 10 The diagram shows a shadow map generation apparatus, which includes:
[0099] The first confirmation module 1002 is used to determine the target point light source in the virtual scene and determine the spherical space covered by the light emitted by the target point light source; the first division module 1004 is used to divide the spherical space into hemispherical spaces; the first recording module 1006 is used to collect scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space, and record the scene depth data on the plane based on the projection relationship of the position points in the hemispherical surface onto the plane to obtain the initial shadow map; wherein, the scene depth data in the initial shadow map forms a circular planar region; the first mapping module 1008 is used to map the scene depth data in the initial shadow map to the rectangular region based on the mapping relationship between the circular planar region and the rectangular planar region to obtain the final shadow map.
[0100] In this method, the spherical space covered by the light emitted from the target point light source is divided into hemispherical spaces. Based on the projection relationship between the position points in the hemispherical surface and the plane, the scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space is recorded on the plane to form a circular plane area. Then, the scene depth data is mapped to a rectangular area to obtain the final shadow map. This method improves the utilization rate of shadow maps and enhances the performance and effect of point light source shadow rendering.
[0101] The first recording module is also used to determine the projection point of the position point in the hemispherical surface onto the plane by means of equal area mapping; and to record the scene depth data corresponding to the position point in the hemispherical surface onto the projection point on the plane.
[0102] The first mapping module is also used to determine the mapping points of the projection points in the initial shadow map in the rectangular planar region by means of elliptical mapping; and to record the scene depth data corresponding to the projection points in the initial shadow map in the mapping points in the rectangular planar region.
[0103] The rectangular planar region mentioned above is actually a square planar region.
[0104] The first partitioning module is also used to divide the spherical space into hemispherical spaces for static models in the virtual scene according to the specified dimensions of the three-dimensional spatial coordinate system of the virtual scene.
[0105] The first partitioning module is also used to determine the main camera frustum in the virtual scene for dynamic models in the virtual scene; and to divide the spherical space into hemispherical spaces based on the specified frustum plane of the main camera frustum.
[0106] The aforementioned device further includes a second partitioning module, used to determine the closest viewing cone plane to the target point light source from among multiple viewing cone planes of the main camera if the target point light source is located inside the main camera's viewing cone and a portion of the spherical space is located inside the main camera's viewing cone; generate a partitioning plane passing through the target point light source; wherein the partitioning plane is parallel to the closest viewing cone plane; and divide the spherical space into a hemispherical space using the partitioning plane.
[0107] The aforementioned device also includes a first adjustment module for determining the target hemispherical space intersecting with the main camera's view frustum; and adjusting the clipping plane of the projection camera corresponding to the target hemispherical space so that the clipping plane matches the main camera's view frustum.
[0108] The aforementioned device also includes a third dividing module, used to divide the spherical space into a hemispherical space by a preset plane if the target point light source is located outside the main camera's viewing cone and a portion of the spherical space is located inside the main camera's viewing cone; wherein, the preset plane is used to control the main camera's viewing cone to intersect only one hemispherical space.
[0109] The aforementioned device further includes a first execution module, configured to, for a static model in the virtual scene, if a preset first update condition for the static model is triggered, continue to execute the following steps to update the final shadow map corresponding to the static model: determine a target point light source in the virtual scene and determine the spherical space covered by the light emitted by the target point light source; divide the spherical space into hemispherical spaces; collect scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space, and record the scene depth data on a two-dimensional plane based on the projection relationship of the position points in the hemispherical surface onto the plane to obtain an initial shadow map; wherein, the scene depth data in the initial shadow map forms a circular planar region; based on the mapping relationship between the circular planar region and the rectangular planar region, map the scene depth data in the initial shadow map to the rectangular region to obtain the final shadow map.
[0110] The first update condition preset for the aforementioned static model includes at least one of the following: the preset shadow map resolution of the aforementioned static model changes; the position of the aforementioned target point light source in the virtual scene changes; the spherical space covered by the light emitted by the aforementioned target point light source changes, and the range of change in the spherical space exceeds a preset range threshold; the intersection state of the hemispherical space and the main camera's view frustum in the virtual scene changes.
[0111] The aforementioned device further includes a second execution module, used to perform the following steps for the dynamic model in the virtual scene, based on the preset update rules of the dynamic model, to update the final shadow map corresponding to the dynamic model: determining the target point light source in the virtual scene and determining the spherical space covered by the light emitted by the target point light source; dividing the spherical space into hemispherical spaces; collecting scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space, and recording the scene depth data on a two-dimensional plane based on the projection relationship of the position points on the hemispherical surface onto the plane to obtain an initial shadow map; wherein, the scene depth data in the initial shadow map forms a circular planar region; based on the mapping relationship between the circular planar region and the rectangular planar region, mapping the scene depth data in the initial shadow map to the rectangular region to obtain the final shadow map.
[0112] The update rules preset by the above dynamic model include at least one of the following: if the target point light source is located inside the main camera's view frustum in the virtual scene, the final shadow map corresponding to each hemispherical space is updated according to the preset frame rate; if the target point light source is located outside the main camera's view frustum in the simulated scene, the first hemispherical space intersecting with the main camera's view frustum is determined, and the final shadow map corresponding to the first hemispherical space is updated according to the preset frame rate.
[0113] The aforementioned device further includes a first update module, used to determine the hemispherical space to be updated based on the update rules preset by the dynamic model; update the first transformation matrix and the second transformation matrix corresponding to the hemispherical space to be updated; wherein, the first transformation matrix is used to: transform from the world coordinate space corresponding to the virtual scene to the view space of the shadow camera in the hemispherical space; the second transformation matrix is used to: transform from the view space of the shadow camera in the hemispherical space to the shadow camera clipping space; and update the final shadow map corresponding to the hemispherical space to be updated based on the updated first transformation matrix and the second transformation matrix.
[0114] This embodiment also provides an electronic device, including a processor and a memory. The memory stores machine-executable instructions that can be executed by the processor. The processor executes the machine-executable instructions to implement the above-described shadow texture generation method. This electronic device can be a server or a terminal device.
[0115] See Figure 11 As shown, the electronic device includes a processor 100 and a memory 101. The memory 101 stores machine-executable instructions that can be executed by the processor 100. The processor 100 executes the machine-executable instructions to implement the above-described method for generating shadow maps.
[0116] Furthermore, Figure 11The illustrated electronic device also includes a bus 102 and a communication interface 103. The processor 100, communication interface 103, and memory 101 are connected via the bus 102. The memory 101 may include high-speed random access memory (RAM) or non-volatile memory, such as at least one disk drive. Communication between this system network element and at least one other network element is achieved through at least one communication interface 103 (which can be wired or wireless). The interface can utilize the Internet, wide area network, local area network, metropolitan area network, etc. The bus 102 can be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, Figure 11 The diagram uses only a single bidirectional arrow, but this does not imply a single bus or a single type of bus. Processor 100 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 100 or by instructions in software form. Processor 100 can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this invention can be directly manifested as execution by a hardware decoding processor, or execution by a combination of hardware and software modules in the decoding processor. The software module can reside in a readily available storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory 101, and the processor 100 reads the information from memory 101 and, in conjunction with its hardware, completes the steps of the method described in the foregoing embodiments.
[0117] In this method, the spherical space covered by the light emitted from the target point light source is divided into hemispherical spaces. Based on the projection relationship between the position points in the hemispherical surface and the plane, the scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space is recorded on the plane to form a circular plane area. Then, the scene depth data is mapped to a rectangular area to obtain the final shadow map. This method improves the utilization rate of shadow maps and enhances the performance and effect of point light source shadow rendering.
[0118] The processor in the aforementioned electronic device can perform the following operations of the shadow map generation method by executing machine-executable instructions: determining the projection point of the position point in the hemispherical surface onto the plane by means of equal area mapping; and recording the scene depth data corresponding to the position point in the hemispherical surface onto the projection point on the plane.
[0119] The processor in the aforementioned electronic device can perform the following operations of the shadow map generation method by executing machine-executable instructions: determining the mapping point of the projection point in the initial shadow map in the rectangular planar region by means of elliptical mapping; and recording the scene depth data corresponding to the projection point in the initial shadow map in the mapping point in the rectangular planar region.
[0120] The rectangular planar region mentioned above is actually a square planar region.
[0121] The processor in the aforementioned electronic device can perform the following operations of the shadow map generation method by executing machine-executable instructions: for a static model in a virtual scene, the spherical space is divided into hemispherical spaces according to the specified dimensions of the three-dimensional spatial coordinate system of the virtual scene.
[0122] The processor in the aforementioned electronic device can perform the following operations of the shadow map generation method by executing machine-executable instructions: for a dynamic model in a virtual scene, determine the main camera frustum in the virtual scene; based on the specified frustum plane of the main camera frustum, divide the spherical space into hemispherical spaces.
[0123] The processor in the aforementioned electronic device, by executing machine-executable instructions, can perform the following operations of the shadow map generation method described above: if the target point light source is located inside the view frustum of the main camera, and a portion of the spherical space is located inside the view frustum of the main camera, determine the view frustum plane closest to the target point light source from among the multiple view frustum planes of the main camera view frustum; generate a dividing plane passing through the target point light source; wherein the dividing plane is parallel to the nearest view frustum plane; divide the spherical space into a hemispherical space using the dividing plane.
[0124] The processor in the aforementioned electronic device can perform the following operations of the shadow map generation method by executing machine-executable instructions: determining the target hemispherical space intersecting with the main camera's view frustum; adjusting the clipping plane of the projection camera corresponding to the target hemispherical space so that the clipping plane matches the main camera's view frustum.
[0125] The processor in the aforementioned electronic device can perform the following operations of the shadow map generation method by executing machine-executable instructions: if the target point light source is located outside the main camera's view frustum and a portion of the spherical space is located inside the main camera's view frustum, the spherical space is divided into hemispherical spaces by a preset plane; wherein, the preset plane is used to: control the main camera's view frustum to intersect only one hemispherical space.
[0126] The processor in the aforementioned electronic device, by executing machine-executable instructions, can implement the following operations of the shadow map generation method described above: For a static model in the virtual scene, if the preset first update condition of the static model is triggered, the following steps are continued to update the final shadow map corresponding to the static model: Determine a target point light source in the virtual scene and determine the spherical space covered by the light emitted by the target point light source; divide the spherical space into hemispherical spaces; collect scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space; based on the projection relationship of the position points in the hemispherical surface onto the plane, record the scene depth data on a two-dimensional plane to obtain an initial shadow map; wherein, the scene depth data in the initial shadow map forms a circular planar region; based on the mapping relationship between the circular planar region and the rectangular planar region, map the scene depth data in the initial shadow map to the rectangular region to obtain the final shadow map.
[0127] The first update condition preset for the aforementioned static model includes at least one of the following: the preset shadow map resolution of the aforementioned static model changes; the position of the aforementioned target point light source in the virtual scene changes; the spherical space covered by the light emitted by the aforementioned target point light source changes, and the range of change in the spherical space exceeds a preset range threshold; the intersection state of the hemispherical space and the main camera's view frustum in the virtual scene changes.
[0128] The processor in the aforementioned electronic device, by executing machine-executable instructions, can perform the following operations of the shadow map generation method described above: For the dynamic model in the virtual scene, based on the preset update rules of the dynamic model, the following steps are performed to update the final shadow map corresponding to the dynamic model: Determine the target point light source in the virtual scene and determine the spherical space covered by the light emitted by the target point light source; Divide the spherical space into hemispherical spaces; Collect scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space; Based on the projection relationship of the position points in the hemispherical surface onto the plane, record the scene depth data on the two-dimensional plane to obtain the initial shadow map; The scene depth data in the initial shadow map forms a circular planar region; Based on the mapping relationship between the circular planar region and the rectangular planar region, map the scene depth data in the initial shadow map to the rectangular region to obtain the final shadow map.
[0129] The update rules preset by the above dynamic model include at least one of the following: if the target point light source is located inside the main camera's view frustum in the virtual scene, the final shadow map corresponding to each hemispherical space is updated according to the preset frame rate; if the target point light source is located outside the main camera's view frustum in the simulated scene, the first hemispherical space intersecting with the main camera's view frustum is determined, and the final shadow map corresponding to the first hemispherical space is updated according to the preset frame rate.
[0130] The processor in the aforementioned electronic device, by executing machine-executable instructions, can perform the following operations of the aforementioned shadow map generation method: determining the hemispherical space to be updated based on the update rules preset by the dynamic model; updating the first transformation matrix and the second transformation matrix corresponding to the hemispherical space to be updated; wherein, the first transformation matrix is used to: transform from the world coordinate space corresponding to the virtual scene to the view space of the shadow camera in the hemispherical space; the second transformation matrix is used to: transform from the view space of the shadow camera in the hemispherical space to the shadow camera clipping space; and updating the final shadow map corresponding to the hemispherical space to be updated based on the updated first transformation matrix and the second transformation matrix.
[0131] This embodiment also provides a machine-readable storage medium storing machine-executable instructions. When the machine-executable instructions are called and executed by the processor, the machine-executable instructions cause the processor to implement the above-described shadow map generation method.
[0132] In this method, the spherical space covered by the light emitted from the target point light source is divided into hemispherical spaces. Based on the projection relationship between the position points in the hemispherical surface and the plane, the scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space is recorded on the plane to form a circular plane area. Then, the scene depth data is mapped to a rectangular area to obtain the final shadow map. This method improves the utilization rate of shadow maps and enhances the performance and effect of point light source shadow rendering.
[0133] The machine-executable instructions stored in the aforementioned machine-readable storage medium can be executed to perform the following operations in the aforementioned shadow map generation method: determine the projection point of the position point in the aforementioned hemispherical surface onto the plane by means of equal area mapping; and record the scene depth data corresponding to the position point in the hemispherical surface onto the projection point on the plane.
[0134] The machine-executable instructions stored in the aforementioned machine-readable storage medium can be used to perform the following operations in the shadow map generation method: determining the mapping points of the projection points in the initial shadow map in the rectangular planar region by means of elliptical mapping; and recording the scene depth data corresponding to the projection points in the initial shadow map in the mapping points in the rectangular planar region.
[0135] The rectangular planar region mentioned above is actually a square planar region.
[0136] The machine-executable instructions stored in the aforementioned machine-readable storage medium can be used to perform the following operations in the above shadow map generation method: for a static model in a virtual scene, the spherical space is divided into hemispherical spaces according to the specified dimensions of the three-dimensional spatial coordinate system of the virtual scene.
[0137] The machine-executable instructions stored in the aforementioned machine-readable storage medium can be executed to perform the following operations in the shadow map generation method: for a dynamic model in a virtual scene, determine the main camera frustum in the virtual scene; based on the specified frustum plane of the main camera frustum, divide the spherical space into hemispherical spaces.
[0138] The machine-executable instructions stored in the aforementioned machine-readable storage medium can be executed to perform the following operations in the shadow map generation method: if the target point light source is located inside the view frustum of the main camera, and a portion of the spherical space is located inside the view frustum of the main camera, determine the view frustum plane closest to the target point light source from among the multiple view frustum planes of the main camera view frustum; generate a dividing plane passing through the target point light source; wherein the dividing plane is parallel to the nearest view frustum plane; divide the spherical space into hemispherical spaces using the dividing plane.
[0139] The machine-executable instructions stored in the aforementioned machine-readable storage medium can be executed to perform the following operations in the shadow map generation method: determine the target hemispherical space intersecting with the main camera's view frustum; adjust the clipping plane of the projection camera corresponding to the target hemispherical space so that the clipping plane matches the main camera's view frustum.
[0140] The machine-executable instructions stored in the aforementioned machine-readable storage medium can be executed to perform the following operations in the aforementioned shadow map generation method: if the target point light source is located outside the aforementioned main camera view frustum, and a portion of the spherical space is located inside the main camera view frustum, the spherical space is divided into hemispherical spaces by a preset plane; wherein, the preset plane is used to: control the main camera view frustum to intersect only one hemispherical space.
[0141] The machine-executable instructions stored in the aforementioned machine-readable storage medium can be executed to perform the following operations in the shadow map generation method: For a static model in the virtual scene, if the first preset update condition of the static model is triggered, the following steps are continued to update the final shadow map corresponding to the static model: Determine a target point light source in the virtual scene and determine the spherical space covered by the light emitted by the target point light source; divide the spherical space into hemispherical spaces; collect scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space; based on the projection relationship of the position points in the hemispherical surface onto the plane, record the scene depth data on the two-dimensional plane to obtain an initial shadow map; wherein, the scene depth data in the initial shadow map forms a circular planar region; based on the mapping relationship between the circular planar region and the rectangular planar region, map the scene depth data in the initial shadow map to the rectangular region to obtain the final shadow map.
[0142] The first update condition preset for the aforementioned static model includes at least one of the following: the preset shadow map resolution of the aforementioned static model changes; the position of the aforementioned target point light source in the virtual scene changes; the spherical space covered by the light emitted by the aforementioned target point light source changes, and the range of change in the spherical space exceeds a preset range threshold; the intersection state of the hemispherical space and the main camera's view frustum in the virtual scene changes.
[0143] The machine-executable instructions stored in the aforementioned machine-readable storage medium can be executed to perform the following operations in the shadow map generation method: For the dynamic model in the virtual scene, based on the preset update rules of the dynamic model, the following steps are performed to update the final shadow map corresponding to the dynamic model: Determine the target point light source in the virtual scene and determine the spherical space covered by the light emitted by the target point light source; Divide the spherical space into hemispherical spaces; Collect scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space; Based on the projection relationship of the position points in the hemispherical surface onto the plane, record the scene depth data on the two-dimensional plane to obtain the initial shadow map; The scene depth data in the initial shadow map forms a circular planar region; Based on the mapping relationship between the circular planar region and the rectangular planar region, map the scene depth data in the initial shadow map to the rectangular region to obtain the final shadow map.
[0144] The update rules preset by the above dynamic model include at least one of the following: if the target point light source is located inside the main camera's view frustum in the virtual scene, the final shadow map corresponding to each hemispherical space is updated according to the preset frame rate; if the target point light source is located outside the main camera's view frustum in the simulated scene, the first hemispherical space intersecting with the main camera's view frustum is determined, and the final shadow map corresponding to the first hemispherical space is updated according to the preset frame rate.
[0145] The machine-executable instructions stored in the aforementioned machine-readable storage medium can be executed to perform the following operations in the shadow map generation method: determining the hemispherical space to be updated based on the update rules preset by the dynamic model; updating the first transformation matrix and the second transformation matrix corresponding to the hemispherical space to be updated; wherein, the first transformation matrix is used to: transform from the world coordinate space corresponding to the virtual scene to the view space of the shadow camera in the hemispherical space; the second transformation matrix is used to: transform from the view space of the shadow camera in the hemispherical space to the shadow camera clipping space; and updating the final shadow map corresponding to the hemispherical space to be updated based on the updated first transformation matrix and the second transformation matrix.
[0146] The computer program product of the shadow mapping generation method, apparatus, electronic device and storage medium provided in the embodiments of the present invention includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the preceding method embodiments. For specific implementation, please refer to the method embodiments, which will not be repeated here.
[0147] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system and apparatus described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0148] Furthermore, in the description of the embodiments of the present invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in the present invention based on the specific circumstances.
[0149] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0150] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0151] Finally, it should be noted that the above embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for generating a shadow map, characterized in that, The method includes: In a virtual scene, a target point light source is identified, and the spherical space covered by the light emitted by the target point light source is determined. The spherical space is divided into hemispherical spaces; Scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space is collected. Based on the projection relationship of the position points in the hemispherical surface onto the plane, the scene depth data is recorded on the plane to obtain an initial shadow map; wherein, the scene depth data in the initial shadow map forms a circular planar region. Based on the mapping relationship between circular and rectangular planar regions, the scene depth data in the initial shadow map is mapped to the rectangular region to obtain the final shadow map; Based on the mapping relationship between circular and rectangular planar regions, after mapping the scene depth data in the initial shadow map to the rectangular region to obtain the final shadow map, the method further includes: For the dynamic model in the virtual scene, the final shadow map corresponding to the dynamic model is updated based on the preset update rules of the dynamic model. The update rules preset by the dynamic model include at least one of the following: If the target point light source is located inside the main camera's view frustum in the virtual scene, the final shadow map corresponding to each hemispherical space is updated according to a preset frame rate. If the target point light source is located outside the main camera's view frustum in the virtual scene, determine the first hemispherical space that intersects with the main camera's view frustum, and trigger the update of the final shadow map corresponding to the first hemispherical space according to a preset frame rate.
2. The method according to claim 1, characterized in that, Based on the projection relationship of the position points in the hemispherical surface onto the plane, the step of recording the scene depth data onto the plane to obtain the initial shadow map includes: The projection point of the position point in the hemispherical surface onto the plane is determined by the method of equal area mapping; The scene depth data corresponding to the position point in the hemispherical surface is recorded as the projection point on the plane.
3. The method according to claim 1, characterized in that, Based on the mapping relationship between circular and rectangular planar regions, the steps of mapping the scene depth data in the initial shadow map to the rectangular region to obtain the final shadow map include: The mapping points of the projection points in the initial shadow map within the rectangular planar region are determined by elliptical mapping. Record the scene depth data corresponding to the projection points in the initial shadow map at the mapping points in the rectangular planar region.
4. The method according to claim 1, characterized in that, The rectangular planar region is a square planar region.
5. The method according to claim 1, characterized in that, The step of dividing the spherical space into hemispherical spaces includes: For the static model in the virtual scene, the spherical space is divided into hemispherical spaces according to the specified dimensions of the three-dimensional spatial coordinate system of the virtual scene.
6. The method according to claim 1, characterized in that, The step of dividing the spherical space into hemispherical spaces includes: For the dynamic model in the virtual scene, determine the main camera frustum in the virtual scene; Based on the designated viewing cone plane of the main camera's viewing cone, the spherical space is divided into hemispherical spaces.
7. The method according to claim 6, characterized in that, The step of dividing the spherical space into hemispherical spaces based on a designated frustum plane of the main camera's frustum includes: If the target point light source is located inside the main camera's frustum, and a portion of the space in the sphere is located inside the main camera's frustum, determine the frustum plane closest to the target point light source from among the multiple frustum planes of the main camera's frustum; Generate a dividing plane passing through the target point light source; wherein the dividing plane is parallel to the nearest visual cone plane; The spherical space is divided into hemispherical spaces by the dividing plane.
8. The method according to claim 7, characterized in that, After the step of dividing the spherical space into hemispherical spaces using the dividing plane, the method further includes: Determine the target hemispherical space that intersects with the main camera's view frustum; Adjust the clipping plane of the projection camera corresponding to the target hemispherical space so that the clipping plane matches the view frustum of the main camera.
9. The method according to claim 6, characterized in that, The step of dividing the spherical space into hemispherical spaces based on a designated frustum plane of the main camera's frustum includes: If the target point light source is located outside the main camera's view frustum, and a portion of the spherical space is located inside the main camera's view frustum, the spherical space is divided into hemispherical spaces by a preset plane; wherein, the preset plane is used to control the main camera's view frustum to intersect with only one hemispherical space.
10. The method according to claim 1, characterized in that, Based on the mapping relationship between circular and rectangular planar regions, after mapping the scene depth data in the initial shadow map to the rectangular region to obtain the final shadow map, the method further includes: For the static model in the virtual scene, if the preset first update condition of the static model is triggered, the following steps are performed to update the final shadow texture corresponding to the static model: In a virtual scene, a target point light source is identified, and the spherical space covered by the light emitted by the target point light source is determined. The spherical space is divided into hemispherical spaces. Scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space is collected. Based on the projection relationship of the position points in the hemispherical surface onto the plane, the scene depth data is recorded on a two-dimensional plane to obtain an initial shadow map. The scene depth data in the initial shadow map forms a circular planar region. Based on the mapping relationship between the circular planar region and the rectangular planar region, the scene depth data in the initial shadow map is mapped to the rectangular region to obtain the final shadow map.
11. The method according to claim 10, characterized in that, The first update condition preset by the static model includes at least one of the following: The preset shadow map resolution of the static model changes; The position of the target point light source changes in the virtual scene; The spherical space covered by the light emitted from the target point light source changes, and the range of change in the spherical space exceeds a preset range threshold. The intersection state between the hemispherical space and the main camera's view frustum in the virtual scene changes.
12. The method according to claim 1, characterized in that, Based on the preset update rules of the dynamic model, the following steps are performed to update the final shadow map corresponding to the dynamic model, including: Based on the update rules preset in the dynamic model, the hemispherical space to be updated is determined; Update the first transformation matrix and the second transformation matrix corresponding to the hemispherical space to be updated; wherein, the first transformation matrix is used to: transform from the world coordinate space corresponding to the virtual scene to the view space of the shadow camera in the hemispherical space; the second transformation matrix is used to: transform from the view space of the shadow camera in the hemispherical space to the clipping space of the shadow camera; Based on the updated first transformation matrix and the second transformation matrix, the final shadow map corresponding to the hemispherical space to be updated is updated.
13. A shadow mapping generation apparatus, characterized in that, The device includes: The first confirmation module is used to determine the target point light source in the virtual scene and to determine the spherical space covered by the light emitted by the target point light source; The first partitioning module is used to divide the spherical space into hemispherical spaces; The first recording module is used to collect scene depth data of each position point on the hemispherical surface corresponding to the hemispherical space, and record the scene depth data on the plane based on the projection relationship of the position points in the hemispherical surface onto the plane to obtain an initial shadow map; wherein, the scene depth data in the initial shadow map forms a circular planar region; The first mapping module is used to map the scene depth data in the initial shadow map to the rectangular area based on the mapping relationship between the circular planar area and the rectangular planar area, so as to obtain the final shadow map; The second execution module is used to update the final shadow map corresponding to the dynamic model in the virtual scene based on the preset update rules of the dynamic model: wherein the preset update rules of the dynamic model include at least one of the following: if the target point light source is located inside the main camera's view frustum in the virtual scene, the final shadow map corresponding to each hemispherical space is updated according to a preset frame rate; if the target point light source is located outside the main camera's view frustum in the virtual scene, the first hemispherical space intersecting with the main camera's view frustum is determined, and the final shadow map corresponding to the first hemispherical space is updated according to a preset frame rate.
14. An electronic device, characterized in that, The method includes a processor and a memory, the memory storing machine-executable instructions that can be executed by the processor, the processor executing the machine-executable instructions to implement the shadow map generation method according to any one of claims 1-12.
15. A machine-readable storage medium, characterized in that, The machine-readable storage medium stores machine-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the shadow map generation method according to any one of claims 1-12.