Shadow rendering method and device, electronic equipment and storage medium
By dividing the target level area and calculating the target projection matrix in shadow rendering, and aligning and processing the projection camera coordinates, the problem of unstable shadow rendering is solved, and the stability of the shadow results and the stability of the shadow effect in the observation screen are achieved.
Patent Information
- Application Number
- CN202410853030.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-27
- Publication Date
- 2024-09-10
AI Technical Summary
When rendering shadows in the prior art, the movement of the projection camera causes an unstable determination of whether a pixel is in shadow, causing shadow jitter in the observation picture of the observation camera.
By dividing the virtual scene into target level areas, calculating the target projection matrix of each area, and aligning the coordinates of the projection camera, a stable shadow map is generated to ensure that the depth value of each pixel is in the target level area. unchanged to avoid jumps in judgment results.
It achieves the stability of shadow rendering, avoids shadow jitter in the observation camera screen, and ensures the stability and consistency of shadow results.
Smart Images

Figure CN118628640A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of graphics processing technology, and in particular to a shadow rendering method, device, electronic equipment and storage medium. Background Art
[0002] In the field of computer graphics and game development, shadow rendering is an important technology that can realistically represent virtual scenes. Shadow rendering of virtual scenes can usually use shadow mapping technology.
[0003] In the prior art, when shadow rendering is performed using shadow mapping technology, first, a shadow map is generated for a scene area of a virtual scene, and the shadow map is used to record the depth value of each object in the scene area from the angle of the light source of the directional light; then, for each pixel point in the scene area from the perspective of the observation camera, the position information of the pixel point in the light source coordinate system is determined, and the depth value of the pixel point in the light source coordinate system is determined based on the position information, and the depth value of the pixel point in the light source coordinate system is compared with the depth value of the pixel point in the shadow map to determine whether the pixel point is in the shadow, and the pixel point is assigned a corresponding pixel value according to the determination result.
[0004] In order to be more practical, there is also a cascade shadow mapping solution in the related art. For each pixel, the depth value of the pixel in the shadow map under the light source perspective is mapped to a predetermined range (such as (0,1)) of the target level area to which the pixel belongs through a projection mapping relationship to obtain a shadow map of the target level area; for each pixel, the depth value of the pixel in the light source coordinate system is compared with the depth value of the pixel in the shadow map of the target level area to which it belongs to determine whether the pixel is in the shadow, so as to generate shadow results of different degrees of refinement. Among them, the target level area to which the pixel belongs is a level area obtained by dividing the scene area based on the distance from the observation camera.
[0005] However, in the prior art, the projection mapping relationship changes as the projection camera moves, and each pixel point can be approximated as a "continuously" moving pixel point during the movement of the projection camera; in this way, when determining whether a pixel point is in a shadow, the continuous depth value of the pixel point in the light source coordinate system is used to compare with the discrete depth value corresponding to the pixel point in the shadow map of the target level area of the pixel point, resulting in a jump in the obtained judgment result, making the calculated shadow result unstable, and ultimately causing the shadow in the observation screen of the observation camera to produce a jittering effect. Summary of the invention
[0006] The purpose of the embodiments of the present invention is to provide a shadow rendering method, device, electronic device and storage medium to generate a stable shadow map to ensure the stability of the shadow in the observation picture of the observation camera. The specific technical solution is as follows:
[0007] In a first aspect, an embodiment of the present invention provides a shadow rendering method, the method comprising:
[0008] Determine each target hierarchical region of the scene area to be rendered of the virtual scene; wherein each target hierarchical region is: each hierarchical region obtained by dividing the scene area based on the distance from the observation camera;
[0009] For each target level region, determining the coordinates of the projection camera of the target level region in the world coordinate system of the virtual scene as the first coordinates;
[0010] Determine a second coordinate corresponding to the first coordinate in the light source coordinate system of the virtual scene, and align the second coordinate according to a plurality of alignment coordinates in the target level area to obtain a third coordinate;
[0011] The coordinate corresponding to the third coordinate in the world coordinate system of the virtual scene is used as the corrected coordinate information of the projection camera, and based on the corrected coordinate information, a target projection matrix corresponding to the projection camera is calculated; wherein the target projection matrix is used to represent a corrected projection mapping relationship of projecting the depth value to the target hierarchical area to generate a shadow map of the target hierarchical area;
[0012] Based on the target projection matrix corresponding to the projection camera and the target depth data, each pixel point of the target hierarchical area is assigned a value to obtain a shadow result corresponding to the target hierarchical area; wherein the target depth data is used to represent: the depth value of each object in the virtual scene from the perspective of the light source of the directional light;
[0013] In response to obtaining the shadow results corresponding to the respective target level regions, an observation picture of the scene area by the observation camera is rendered and generated based on the shadow results corresponding to the respective target level regions.
[0014] Optionally, the plurality of alignment coordinates under the target hierarchical region are determined based on a preset unit size under the target hierarchical region.
[0015] Optionally, the method for determining the multiple alignment coordinates under the target level area includes:
[0016] Each coordinate in the target hierarchical region that is a multiple of a preset unit size is determined as a plurality of alignment coordinates in the target hierarchical region.
[0017] Optionally, the aligning the second coordinate according to a plurality of alignment coordinates in the target hierarchical area to obtain a third coordinate includes:
[0018] Determine a coordinate among a plurality of alignment coordinates under the target level area that is closest to and smaller than the second coordinate;
[0019] The determined coordinates are used as coordinates after the second coordinates are aligned to obtain third coordinates.
[0020] Optionally, a method for determining the preset unit size under the target level area includes:
[0021] Calculate the preset unit size of the target hierarchical area based on the size of the window of the target hierarchical area, the window size of the preset three-dimensional grid, the size of the shadow map of the preset three-dimensional grid, and the size of the preset three-dimensional grid in the XY axis plane of the light source coordinate system;
[0022] There are multiple preset three-dimensional grids, which are pre-divided according to the light source direction of the directional light in the virtual scene; each preset three-dimensional grid has a shadow map corresponding to the depth value of the object in the preset three-dimensional grid.
[0023] Optionally, the target depth data includes: shadow maps corresponding to each of a plurality of preset three-dimensional grids;
[0024] The plurality of preset three-dimensional grids are pre-divided according to the light source direction of the directional light in the virtual scene; each preset three-dimensional grid has a shadow map corresponding to the depth value of the object in the preset three-dimensional grid.
[0025] Optionally, assigning values to each pixel point of the target hierarchical area based on the target projection matrix corresponding to the projection camera and the target depth data to obtain a shadow result corresponding to the target hierarchical area includes:
[0026] Determine the preset three-dimensional grid to which each pixel point in the target level area belongs;
[0027] Based on the coordinates of the X and Y axes of each pixel point in the preset three-dimensional grid to which it belongs, sampling is performed from the shadow map of the preset three-dimensional grid to which it belongs, so as to obtain the depth value of each pixel point in the shadow map corresponding to the preset three-dimensional grid to which it belongs;
[0028] According to the target projection matrix, the distances between the near and far planes of the preset three-dimensional grid to which each pixel point in the target hierarchical area belongs, and the distances between the near and far planes of the target hierarchical area, the depth value of each pixel point in the shadow map corresponding to the preset three-dimensional grid to which it belongs is mapped to the target hierarchical area to obtain a shadow map of the target hierarchical area;
[0029] For each pixel in the target level area, based on the coordinates of each pixel in the light source coordinate system and the shadow map of the target level area, obtain a depth value of each pixel in the light source coordinate system and a depth value of each pixel in the shadow map of the target level area;
[0030] Compare the depth value of each pixel in the light source coordinate system with the depth value of each pixel in the shadow map of the target level area to obtain a determination result of whether each pixel is in the shadow;
[0031] Based on the determination result of whether each pixel point is in the shadow, a corresponding pixel value is assigned to each pixel point to obtain the shadow result corresponding to the target level area.
[0032] Optionally, calculating a target projection matrix corresponding to the projection camera based on the corrected coordinate information includes:
[0033] Based on the corrected coordinate information, calculating a translation matrix corresponding to the corrected coordinate information;
[0034] The product of the obtained translation matrix and the initial projection matrix is calculated to obtain a target projection matrix corresponding to the projection camera; wherein the initial projection matrix is the projection matrix corresponding to the first coordinate.
[0035] Optionally, each target level area of the scene area is a cube area;
[0036] The step of determining the coordinates of the projection camera of the target level area in the world coordinate system of the virtual scene as the first coordinates includes:
[0037] Determine the coordinates of the center point of the target plane of the target hierarchical area as the coordinates of the projection camera of the target hierarchical area in the world coordinate system of the virtual scene;
[0038] The target plane is a plane, among the planes in the target level area, which is perpendicular to the direction of the directional light and closest to the light source of the directional light.
[0039] Optionally, the rendering and generating, based on the shadow results corresponding to each target level area, an observation picture of the scene area by the observation camera includes:
[0040] The shadow results corresponding to each target level area are passed to the rendering pipeline, so that the rendering pipeline renders the shadow results corresponding to each target level area, so as to render and generate an observation picture of the scene area by the observation camera.
[0041] In a second aspect, an embodiment of the present invention provides a shadow rendering device, the device comprising:
[0042] A first determination module is used to determine each target hierarchical region of a scene area to be rendered of a virtual scene; wherein each target hierarchical region is: each hierarchical region obtained by dividing the scene area based on a distance from an observation camera;
[0043] A second determination module is used to determine, for each target level region, a coordinate of a projection camera of the target level region in the world coordinate system of the virtual scene as a first coordinate;
[0044] an alignment module, used to determine a second coordinate corresponding to the first coordinate in the light source coordinate system of the virtual scene, and align the second coordinate according to a plurality of alignment coordinates in the target hierarchical area to obtain a third coordinate;
[0045] A calculation module, used to use the coordinates corresponding to the third coordinate in the world coordinate system of the virtual scene as the corrected coordinate information of the projection camera, and calculate the target projection matrix corresponding to the projection camera based on the corrected coordinate information; wherein the target projection matrix is used to represent the corrected projection mapping relationship of projecting the depth value to the target hierarchical area to generate a shadow map of the target hierarchical area;
[0046] An assignment module is used to assign values to each pixel point in the target hierarchical area based on the target projection matrix corresponding to the projection camera and the target depth data to obtain a shadow result corresponding to the target hierarchical area; wherein the target depth data is used to represent: the depth value of each object in the virtual scene from the perspective of the light source of the directional light;
[0047] The rendering module is used for rendering and generating an observation picture of the scene area by the observation camera based on the shadow results corresponding to the target level areas in response to obtaining the shadow results corresponding to the target level areas.
[0048] In a third aspect, an embodiment of the present invention provides an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
[0049] Memory, used to store computer programs;
[0050] The processor is used to implement any of the shadow rendering methods when executing a program stored in the memory.
[0051] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, any of the shadow rendering methods described above is implemented.
[0052] An embodiment of the present invention further provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any of the above-mentioned shadow rendering methods.
[0053] Beneficial effects of the embodiments of the present invention:
[0054] The shadow rendering method provided by the embodiment of the present invention divides the scene area to be rendered of the virtual scene into various target level areas based on the distance from the observation camera. For each level area, the target projection matrix of each target level area can be calculated so as to subsequently generate the shadow result corresponding to the target level area; specifically, the target projection matrix of the target level area can be calculated based on the position of the projection camera of the target level area. The first coordinate of the projection camera of the target level area in the world coordinate system can be determined first, and the second coordinate corresponding to the first coordinate in the light source coordinate system can be determined. To ensure the stability of the generated shadow, the second coordinate is aligned according to multiple alignment coordinates under the target level area to obtain a third coordinate. The coordinate corresponding to the third coordinate in the world coordinate system is the corrected coordinate information of the projection camera. Based on the corrected coordinate information, the target projection matrix corresponding to the projection camera can be calculated; through the target projection matrix and the target depth data, each pixel point in the target level area can be assigned a value to obtain the shadow result corresponding to the target level area. After obtaining the shadow results corresponding to each target level area, the observation screen of the observation camera relative to the scene area can be rendered according to the shadow results of each target level area. Among them, the target projection matrix of the target hierarchical area is used to characterize the corrected projection mapping relationship of projecting the depth value to the target hierarchical area to generate the shadow map of the target hierarchical area. By aligning, regardless of whether the projection camera moves, the uncorrected first coordinate of the projection camera is aligned to the corrected coordinate information, that is, the projection camera is equivalent to being at the corrected coordinate information all the time. At this time, when the shadow map corresponding to the target hierarchical area is generated using the obtained target projection matrix, the depth value of each pixel in the shadow map of the target hierarchical area is stable, and the result of determining whether the pixel is in the shadow will not jump, and a stable shadow result can be obtained, and the shadow in the observation screen of the generated observation camera will not produce a jitter effect. It can be seen that a stable shadow result can be generated through this solution to ensure the stability of the shadow in the observation screen of the observation camera.
[0055] Of course, it is not necessary to achieve all of the advantages described above at the same time to implement any product or method of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other embodiments can also be obtained based on these drawings.
[0057] Figure 1 A schematic diagram of a flow chart of a shadow rendering method provided by an embodiment of the present invention;
[0058] Figure 2 A schematic diagram of dividing a scene area into target level areas provided by an embodiment of the present invention;
[0059] Figure 3 Another schematic diagram of dividing a scene area into target level areas provided by an embodiment of the present invention;
[0060] Figure 4 A schematic diagram of a preset three-dimensional grid provided in an embodiment of the present invention;
[0061] Figure 5 A schematic diagram of dividing a scene area into a plurality of preset three-dimensional grids provided in an embodiment of the present invention;
[0062] Figure 6 A schematic diagram of the principle of shadow mapping provided by an embodiment of the present invention;
[0063] Figure 7 Another schematic diagram of dividing a scene area into a plurality of preset three-dimensional grids provided by an embodiment of the present invention;
[0064] Figure 8 A schematic structural diagram of a shadow rendering device provided by an embodiment of the present invention;
[0065] Fig. 9 A block diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0066] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field based on the present invention belong to the scope of protection of the present invention.
[0067] For ease of understanding, the professional terms involved in the present invention are first introduced below.
[0068] Directional Light: A common type of light source in computer graphics, generally used to simulate sunlight. Directional light is parallel at all positions, and a direction vector is usually used to represent the propagation direction.
[0069] Shadow Mapping: Generally used in the field of computer graphics to generate shadow effects in real time. It renders objects from the perspective of the light source and stores the rendered depth value in a shadow map. Then, when rendering the scene, it renders the scene from the observer's perspective. For each rendered pixel, the position information of the pixel is transformed from the world coordinate system to the light source coordinate system, and the depth value of the pixel in the light source coordinate system is determined based on the position information. The depth value in the light source coordinate system and the depth value of the pixel in the shadow map are compared to determine whether the pixel is in the shadow, and the pixel value corresponding to the pixel is assigned according to the determination result to generate a shadow map corresponding to the viewing angle of the observation camera. The principle of shadow mapping is as follows: Figure 6 As shown in the figure, the left side renders the object from the perspective of the directional light source, and stores the rendered depth value (i.e., the projected shadow) in a shadow map. The shadow map records the depth value of each object from the perspective of the light source. However, due to reasons such as resolution, the shadow map only records the depth value of objects in a certain range of the virtual scene. In the right side of the camera perspective, point P is converted to the light source coordinate system to obtain a depth Z value of 0.9 (the depth value in the light source coordinate system, i.e., the coordinate value of the Z axis of point P after transformation in the light source coordinate system), i.e., the depth of P = 0.9. After conversion, the coordinates of the X and Y axes in the light source coordinate system are sampled from the shadow map from the light source perspective, and the shadow depth value recorded at the corresponding point C from the light source perspective is 0.4 (the depth value in the shadow map), that is, C depth = 0.4. By comparing the depth value 0.9 in the light source coordinate system with the sampled depth value 0.4 in the shadow map, it can be determined whether point P is in the shadow (comparison finds that the depth value 0.9 of point P in the light source coordinate system is greater than the depth value 0.4 of point C recorded in the shadow map, indicating that point P is blocked, and point P is in the shadow).
[0070] Orthogonal Projection: A commonly used camera model in computer graphics, used to render scenes. Orthogonal projection is a parallel projection. When an object is projected onto a projection plane, its size remains the same regardless of the distance, and there is no perspective effect. Orthogonal projection is used when rendering the depth of a scene from a directional light perspective. This projection method is often used in some 3D modeling or CAD software.
[0071] Cascaded Shadow Mapping: A technique for real-time rendering of shadows, mainly used in scenes that require large-scale and high-quality shadows. Its basic principle is to divide the scene into multiple levels from near to far according to the distance to the viewing angle, and calculate the corresponding shadow map for each level. Usually the shadow map of the near level has a higher resolution and a smaller range, while the shadow map of the far level has a lower resolution and a larger shadow range.
[0072] Shadow baking: A method of pre-calculating shadows by pre-calculating and storing shadow information in a static scene, that is, pre-generating shadow information for the static scene, and then quickly calculating shadows based on this pre-generated shadow information during rendering.
[0073] Light source coordinate system: A Cartesian coordinate system is formed by taking the direction of the directional light source as the Z axis and selecting a pair of mutually perpendicular orthogonal axes as the X and Y axes on a plane perpendicular to the light source direction.
[0074] Light World Bounding (LWB): In the light source coordinate system, the bounding box range formed by scene objects. The bounding box is generally a rectangular parallelepiped with three sides (length, width and height) parallel to the three reference axes of the light source coordinate system.
[0075] Light World Cell (LWC): In the light source coordinate system, the grid unit divided by LWB according to the set division parameters is an independent unit for shadow depth map rendering (that is, an independent unit that is part of the overall depth map of the virtual scene). Each LWC has its own orthogonal projection camera parameters.
[0076] In the field of computer graphics and game development, shadow rendering is an important technology to provide realistic scene performance. Directional light, such as sunlight, is a common scene lighting type in graphics rendering. It covers a large area, so many objects need to be included when rendering directional light shadows, which puts a lot of rendering pressure. Rendering a large number of objects in the scene covered by directional light shadows often greatly reduces the frame rate of the rendered picture and reduces the user experience.
[0077] Therefore, a technology called Cascaded Shadow Mapping was created. Its basic principle is to divide the virtual scene from near to far into several levels according to the distance from the observation camera, and calculate the corresponding shadow map for each level. Usually, the shadow map of the near level has higher precision but covers a smaller range, while the shadow map of the far level has lower resolution but covers a larger range. This method is very consistent with the characteristic that the farther the shadow is, the less details are needed. It is the embodiment of the idea of Level of Detail (LOD) in shadow rendering.
[0078] Cascaded shadow mapping takes into account the needs of rendering details of different precisions at near and far distances, while also providing better performance than ordinary shadow mapping. However, even with the use of cascaded shadow mapping technology, real-time rendering of directional light shadows is still a very expensive computing task on low- and medium-configuration devices, or when mobile computing resources are limited, due to constraints such as device performance, power consumption, and heat dissipation.
[0079] The corresponding technology to real-time rendering of shadows is called shadow baking. Shadow baking is a method of pre-calculating shadows, which pre-calculates and stores shadow information in static scenes, and then quickly calculates shadows based on these pre-generated shadow information at runtime, thereby improving the rendering frame rate performance of the picture.
[0080] However, in the related art, usually only cascade shadow mapping is used for real-time shadow rendering, and the generated shadows will also produce a jitter effect. Based on this, the embodiments of the present invention provide a shadow rendering method, device, electronic device and storage medium to generate stable shadow results and ensure the stability of the shadows in the observation picture of the observation camera.
[0081] A shadow rendering method provided by the present invention is introduced below.
[0082] Among them, a shadow rendering method provided by an embodiment of the present invention can be applied to a three-dimensional engine, and the three-dimensional engine can be used as a 3D software. In practical applications, the three-dimensional engine can be set in an electronic device, and the electronic device can be a terminal device or a server. Exemplarily, the terminal device can be a mobile phone, a computer, etc. The present invention does not limit the specific form of the electronic device. A shadow rendering method provided by the present invention can be applied to any scene with the need to render and generate shadows, for example: for a scene area in a virtual scene, it is necessary to generate a rendering screen of the scene area for the observer's perspective, and the rendering screen contains a scene with a shadow effect.
[0083] A shadow rendering method provided by an embodiment of the present invention may include the following steps:
[0084] Determine each target hierarchical region of the scene area to be rendered of the virtual scene; wherein each target hierarchical region is: each hierarchical region obtained by dividing the scene area based on the distance from the observation camera;
[0085] For each target level region, determining the coordinates of the projection camera of the target level region in the world coordinate system of the virtual scene as the first coordinates;
[0086] Determine a second coordinate corresponding to the first coordinate in the light source coordinate system of the virtual scene, and align the second coordinate according to a plurality of alignment coordinates in the target level area to obtain a third coordinate;
[0087] The coordinate corresponding to the third coordinate in the world coordinate system of the virtual scene is used as the corrected coordinate information of the projection camera, and based on the corrected coordinate information, a target projection matrix corresponding to the projection camera is calculated; wherein the target projection matrix is used to represent a corrected projection mapping relationship of projecting the depth value to the target hierarchical area to generate a shadow map of the target hierarchical area;
[0088] Based on the target projection matrix corresponding to the projection camera and the target depth data, each pixel point of the target hierarchical area is assigned a value to obtain a shadow result corresponding to the target hierarchical area; wherein the target depth data is used to represent: the depth value of each object in the virtual scene from the perspective of the light source of the directional light;
[0089] In response to obtaining the shadow results corresponding to the respective target level regions, an observation picture of the scene area by the observation camera is rendered and generated based on the shadow results corresponding to the respective target level regions.
[0090] The shadow rendering method provided by the embodiment of the present invention divides the scene area to be rendered of the virtual scene into various target level areas based on the distance from the observation camera. For each level area, the target projection matrix of each target level area can be calculated so as to subsequently generate the shadow result corresponding to the target level area; specifically, the target projection matrix of the target level area can be calculated based on the position of the projection camera of the target level area. The first coordinate of the projection camera of the target level area in the world coordinate system can be determined first, and the second coordinate corresponding to the first coordinate in the light source coordinate system can be determined. To ensure the stability of the generated shadow, the second coordinate is aligned according to multiple alignment coordinates under the target level area to obtain a third coordinate. The coordinate corresponding to the third coordinate in the world coordinate system is the corrected coordinate information of the projection camera. Based on the corrected coordinate information, the target projection matrix corresponding to the projection camera can be calculated; through the target projection matrix and the target depth data, each pixel point in the target level area can be assigned a value to obtain the shadow result corresponding to the target level area. After obtaining the shadow results corresponding to each target level area, the observation screen of the observation camera relative to the scene area can be rendered according to the shadow results of each target level area. Among them, the target projection matrix of the target hierarchical area is used to characterize the corrected projection mapping relationship of projecting the depth value to the target hierarchical area to generate the shadow map of the target hierarchical area. By aligning, regardless of whether the projection camera moves, the uncorrected first coordinate of the projection camera is aligned to the corrected coordinate information, that is, the projection camera is equivalent to being at the corrected coordinate information all the time. At this time, when the shadow map corresponding to the target hierarchical area is generated using the obtained target projection matrix, the depth value of each pixel in the shadow map of the target hierarchical area is stable, and the result of determining whether the pixel is in the shadow will not jump, and a stable shadow result can be obtained, and the shadow in the observation screen of the generated observation camera will not produce a jitter effect. It can be seen that a stable shadow result can be generated through this solution to ensure the stability of the shadow in the observation screen of the observation camera.
[0091] A shadow rendering method provided by the present invention is exemplarily introduced below with reference to the accompanying drawings.
[0092] like Figure 1 As shown, a shadow rendering method provided by the present invention may include the following steps:
[0093] S101: Determine each target level area of the scene area to be rendered of the virtual scene;
[0094] Wherein, each target level region is: each level region obtained by dividing the scene region based on the distance from the observation camera;
[0095] The shadow rendering method provided by the present invention is implemented based on cascaded shadow mapping. The present invention can generate shadow results of different levels of areas to meet the requirements of rendering fineness at different distances. First, the target level areas of the scene area to be rendered in the virtual scene can be determined.
[0096] Each target level area can be obtained by dividing the scene area based on the distance from the observation camera. Of course, when dividing each target level area, the direction of the directional light in the virtual scene also needs to be considered; Figure 2 As shown, c is the position of the observation camera, the observation direction is to the right, the direction of the directional light is perpendicular to the near plane of each hierarchical area, and the scene area is divided based on the distance from the observation camera to obtain the target hierarchical areas: Cascade0, Cascade1, Cascade2, and Cascade3. Among them, adjacent target hierarchical areas may have intersection areas, and the intersection area can be configured to belong to a target hierarchical area, for example: for the intersection area of Cascade0 and Cascade1, the area can be configured to belong to Cascade0; for the intersection area of Cascade1 and Cascade2, the area can be configured to belong to Cascade1.
[0097] In addition, it should be noted that there may be multiple directional light sources in the virtual scene, and they are distributed in different areas that do not affect each other. In different areas, due to the different directions of the directional light sources, the division of different areas into multiple target level areas may be different. It is sufficient to ensure that there are near planes and far planes in the multiple target level areas that are perpendicular to the corresponding directional light source directions. The present invention is not limited to this.
[0098] S102: for each target level region, determining the coordinates of the projection camera of the target level region in the world coordinate system of the virtual scene as the first coordinates;
[0099] For each target level area, when generating the shadow result of the target level area, the target projection matrix of the target level area can be determined. Therefore, it is necessary to determine the coordinates of the projection camera of the target level area in the world coordinate system of the virtual scene as the first coordinate.
[0100] Exemplarily, each target level area of the scene area is a cube area;
[0101] The step of determining the coordinates of the projection camera of the target level area in the world coordinate system of the virtual scene as the first coordinates includes:
[0102] Determine the coordinates of the center point of the target plane of the target hierarchical area as the coordinates of the projection camera of the target hierarchical area in the world coordinate system of the virtual scene;
[0103] The target plane is a plane, among the planes in the target level area, which is perpendicular to the direction of the directional light and closest to the light source of the directional light.
[0104] In the present invention, each target hierarchical region is divided into a cubic region. When determining the coordinates of the projection camera of the target hierarchical region in the world coordinate system, the coordinates of the center point of the plane in the target hierarchical region that is perpendicular to the direction of the directional light and closest to the light source of the directional light can be determined as the first coordinate. The target plane can also be called the near plane of the target hierarchical region and the directional light.
[0105] like Figure 2 As shown, for each target level area Cascade0, Cascade1, Cascade2, and Cascade3, the center points of their near planes are S0, S1, S2, and S3, respectively, that is, the first coordinate of Cascade0 is S0, the first coordinate of Cascade1 is S1, the first coordinate of Cascade2 is S2, and the first coordinate of Cascade3 is S3.
[0106] Another way to divide each target level area is as follows Figure 3 As shown, different grayscales represent different target level areas, and the target level areas from the center to the edge are Cascade0, Cascade1, Cascade2, and Cascade3 respectively.
[0107] S103: Determine a second coordinate corresponding to the first coordinate in the light source coordinate system of the virtual scene, and align the second coordinate according to a plurality of alignment coordinates in the target hierarchical area to obtain a third coordinate;
[0108] In order to solve the problem of the jitter of the shadows generated by the projection mapping relationship of the projection camera in the related art, in the present invention, when calculating the coordinates of the projection camera, the projection camera can be aligned, and the coordinate calculation for the projection camera is based on the light source coordinate system. After determining the first coordinate, the second coordinate corresponding to the first coordinate in the light source coordinate system of the virtual scene is first determined. Among them, the world coordinate system of the virtual scene and the light source coordinate system have a mapping relationship, and the first coordinate can be mapped to the light source coordinate system to quickly obtain the second coordinate.
[0109] The projection camera may be stationary or moving, that is, the second coordinate may be fixed or changeable. In the present invention, no matter whether the projection camera moves or not, the second coordinate of the projection camera is aligned to the fixed alignment coordinate to obtain the third coordinate.
[0110] Optionally, the plurality of alignment coordinates under the target hierarchical region are determined based on a preset unit size under the target hierarchical region.
[0111] Exemplarily, the method for determining the multiple alignment coordinates under the target level area includes:
[0112] Each coordinate in the target hierarchical region that is a multiple of a preset unit size is determined as a plurality of alignment coordinates in the target hierarchical region.
[0113] In the present invention, multiple alignment coordinates under the target hierarchical area can be determined based on the preset unit size under the target hierarchical area. The preset unit sizes of different target hierarchical areas may be different. For example, the preset unit size of Cascade0 is 1, the preset unit size of Cascade1 is 2, and so on. The present invention is not limited to this.
[0114] The multiple alignment coordinates under the target level area can be understood as the alignment coordinates in the X-axis or Y-axis direction of the light source coordinate system. The multiple alignment coordinates of the target level area can be the coordinates under the target level area in the X-axis direction that are multiples of the preset unit size, and the coordinates under the target level area in the Y-axis direction that are multiples of the preset unit size.
[0115] For example, for the target level area Cascade0, the preset unit size is 1, and in the X-axis direction of the light source coordinate system, the coordinates on the X-axis that are multiples of the preset unit size are: 1, 2, 3, 4...; in the Y-axis direction of the light source coordinate system, the coordinates on the Y-axis that are multiples of the preset unit size are: 1, 2, 3, 4... For the target level area Cascade1, the preset unit size is 2, and in the X-axis direction of the light source coordinate system, the coordinates on the X-axis that are multiples of the preset unit size are: 2, 4, 6, 8...; in the Y-axis direction of the light source coordinate system, the coordinates on the Y-axis that are multiples of the preset unit size are: 2, 4, 6, 8...
[0116] In addition, the method for determining the preset unit size under the target level area includes:
[0117] Calculate the preset unit size of the target hierarchical area based on the size of the window of the target hierarchical area, the window size of the preset three-dimensional grid, the size of the shadow map of the preset three-dimensional grid, and the size of the preset three-dimensional grid in the XY axis plane of the light source coordinate system;
[0118] There are multiple preset three-dimensional grids, which are pre-divided according to the light source direction of the directional light in the virtual scene; each preset three-dimensional grid has a shadow map corresponding to the depth value of the object in the preset three-dimensional grid.
[0119] It should be noted that the preset unit size under the target level area is used to align the coordinates of the projection camera to correct the position of the projection camera and calculate the corrected target projection matrix. The target projection matrix is used to map the depth values of the pixels in the target level area to generate a shadow map of the target level area. In the present invention, a shadow map representing the depth values of objects in the virtual scene can be generated in advance. To ensure that the shadow map is clear, the virtual scene can be divided into a plurality of preset three-dimensional grids in advance according to the light source direction of the directional light in the virtual scene, and a shadow map of the depth values of the objects in each preset three-dimensional grid is generated.
[0120] When a shadow map of the target hierarchical area is subsequently generated, the depth value in the shadow map of the preset three-dimensional grid in the target hierarchical area is mapped to the target hierarchical area. The preset unit size of the target hierarchical area can be calculated based on the size of the window of the target hierarchical area, the window size of the preset three-dimensional grid, the size of the shadow map of the preset three-dimensional grid, and the size of the preset three-dimensional grid in the XY axis plane of the light source coordinate system.
[0121] For example, the preset unit size under the target level area can be calculated according to the following formula:
[0122] AlignSize=(ShadowCellSize / ShadowCellMapSize)*(CascadedWindowSize / ShadowCellWindowSize);
[0123] Among them, AlignSize is the preset unit size, CascadedWindowSize is the size of the window of the target hierarchical area, ShadowCellWindowSize is the window size of the preset three-dimensional grid, ShadowCellMapSize is the size of the shadow map of the preset three-dimensional grid, and ShadowCellSize is the size of the preset three-dimensional grid in the XY axis plane of the light source coordinate system.
[0124] Then, the second coordinate is aligned according to the plurality of alignment coordinates under the target level area to obtain a third coordinate, including:
[0125] Determine a coordinate among a plurality of alignment coordinates under the target level area that is closest to and smaller than the second coordinate;
[0126] The determined coordinates are used as coordinates after the second coordinates are aligned to obtain third coordinates.
[0127] When the second coordinate is aligned, the second coordinate is aligned downward, that is, the second coordinate is aligned to the coordinate that is closest to and smaller than the second coordinate among multiple alignment coordinates. The coordinate that is closest to and smaller than the second coordinate among multiple alignment coordinates is the third coordinate after the alignment.
[0128] Exemplarily, for the target level area Cascade0, the multiple alignment coordinates for the X-axis are 1, 2, 3, 4..., if the coordinate of the second coordinate with respect to the X-axis is 2.1, then the coordinate of the X-axis in the third coordinate after the alignment process is 2, if the coordinate of the second coordinate with respect to the X-axis is 2.2, then the coordinate of the X-axis in the third coordinate after the alignment process is 2, if the coordinate of the second coordinate with respect to the X-axis is 1.9, then the coordinate of the X-axis in the third coordinate after the alignment process is 1.
[0129] Through the alignment process, it is equivalent to aligning the second coordinate in the range of (1,2) in the X-axis direction to 1, aligning the second coordinate in the range of (2,3) in the X-axis direction to 2, aligning the second coordinate in the range of (3,4) in the X-axis direction to 3... At this time, regardless of whether the projection camera moves, the projection camera is equivalent to moving at a fixed position interval in the X-axis direction, that is, jumping from 1 to 2, from 2 to 3, from 3 to 4... in the X-axis direction.
[0130] In the prior art, the target projection matrix of the projection camera is calculated based on the movement of the projection camera. For the X-axis direction, if the projection camera moves from 1 to 4, it moves step by step. At this time, when the projection camera determines whether each pixel in the observation camera is in the shadow, each pixel is approximated as a continuously moving pixel. The continuously moving pixel is compared with the discretized depth value corresponding to the pixel in the shadow map (the depth value of the pixel in the shadow map is also obtained by sampling the discretized depth value in the shadow map through the coordinates of the continuously moving pixel). The judgment result will jump, which will eventually cause the generated shadow to have a jitter effect. In the present invention, the projection camera is aligned, and the projection camera is equivalent to jumping from a fixed position point during the movement. If the projection camera moves from 1 to 4, the projection camera is equivalent to jumping from 1 to 2, then from 2 to 3, and then from 3 to 4. The process of (1,2) is equivalent to being fixed at 1, the process of (2,3) is equivalent to being fixed at 2, and the process of (3,4) is equivalent to being fixed at 3. In this way, the position interval of the pixel point can be made stable relative to the discretized depth value corresponding to the pixel, and a stable shadow result can be obtained.
[0131] S104: using the coordinates corresponding to the third coordinate in the world coordinate system of the virtual scene as corrected coordinate information of the projection camera, and calculating a target projection matrix corresponding to the projection camera based on the corrected coordinate information;
[0132] The target projection matrix is used to represent the corrected projection mapping relationship of projecting the depth value to the target hierarchical area to generate a shadow map of the target hierarchical area;
[0133] After determining the third coordinate after the alignment process, the coordinate corresponding to the third coordinate in the world coordinate system of the virtual scene can be used as the corrected coordinate information of the projection camera, and the target projection matrix corresponding to the projection camera is calculated based on the corrected coordinate information.
[0134] Exemplarily, the calculating the target projection matrix corresponding to the projection camera based on the corrected coordinate information includes:
[0135] Based on the corrected coordinate information, calculating a translation matrix corresponding to the corrected coordinate information;
[0136] The product of the obtained translation matrix and the initial projection matrix is calculated to obtain a target projection matrix corresponding to the projection camera; wherein the initial projection matrix is the projection matrix corresponding to the first coordinate.
[0137] It should be noted that, based on the corrected coordinate information of the projection camera, the translation matrix corresponding to the corrected coordinate information can be calculated first, and the product of the initial projection matrix and the calculated translation matrix is the target projection matrix; wherein, the initial projection matrix is the projection matrix corresponding to the first coordinate before correction, and can also be called the original projection matrix. The calculation method of the initial projection matrix and the translation matrix corresponding to the corrected coordinate information is similar to the prior art and will not be repeated here.
[0138] S105: assigning values to each pixel point in the target hierarchical area based on the target projection matrix corresponding to the projection camera and the target depth data, to obtain a shadow result corresponding to the target hierarchical area;
[0139] The target depth data is used to represent: the depth value of each object in the virtual scene from the perspective of the light source of the directional light;
[0140] After obtaining the target projection matrix of the projection camera, each pixel point in the target level area can be assigned a value to obtain the shadow result corresponding to the target level area.
[0141] Specifically, assigning values to each pixel point in the target hierarchical area based on the target projection matrix corresponding to the projection camera and the target depth data to obtain the shadow result corresponding to the target hierarchical area includes:
[0142] Determine the preset three-dimensional grid to which each pixel point in the target level area belongs;
[0143] Based on the coordinates of the X and Y axes of each pixel point in the preset three-dimensional grid to which it belongs, sampling is performed from the shadow map of the preset three-dimensional grid to which it belongs, so as to obtain the depth value of each pixel point in the shadow map corresponding to the preset three-dimensional grid to which it belongs;
[0144] According to the target projection matrix, the distances between the near and far planes of the preset three-dimensional grid to which each pixel point in the target hierarchical area belongs, and the distances between the near and far planes of the target hierarchical area, the depth value of each pixel point in the shadow map corresponding to the preset three-dimensional grid to which it belongs is mapped to the target hierarchical area to obtain a shadow map of the target hierarchical area;
[0145] For each pixel in the target level area, based on the coordinates of each pixel in the light source coordinate system and the shadow map of the target level area, obtain a depth value of each pixel in the light source coordinate system and a depth value of each pixel in the shadow map of the target level area;
[0146] Compare the depth value of each pixel in the light source coordinate system with the depth value of each pixel in the shadow map of the target level area to obtain a determination result of whether each pixel is in the shadow;
[0147] Based on the determination result of whether each pixel point is in the shadow, a corresponding pixel value is assigned to each pixel point to obtain the shadow result corresponding to the target level area.
[0148] In the present invention, the virtual scene is divided into preset three-dimensional grids, and the preset three-dimensional grids have shadow maps of depth values of objects contained therein. When generating the shadow corresponding to the target hierarchical area, the preset three-dimensional grid to which each pixel point in the target hierarchical area belongs can be first determined (it can be determined according to the position of the pixel point and the range of the preset three-dimensional grid, according to their inclusion relationship, etc.), and then, according to the target projection matrix, the distance between the far and near planes of the preset three-dimensional grid described by each pixel point in the target hierarchical area, and the distance between the far and near planes of the target hierarchical area, the depth value of each pixel point in the shadow map corresponding to the preset three-dimensional grid to which it belongs is mapped to the target hierarchical area, so as to obtain the shadow map of the target hierarchical area, and the shadow map of the target hierarchical area is used to record the depth values of each pixel point in the target hierarchical area; wherein, when generating the shadow map of the target hierarchical area, it is equivalent to using the target projection matrix to map the far and near planes of each preset three-dimensional grid in the target hierarchical area. The depth between the faces is mapped to the depth between the near and far planes of the target level area. For example, for any preset 3D grid in the target level area, under the dimension of the preset 3D grid, the depth of its near plane is 0, and the depth of its far plane is 1 (that is, under the dimension of the preset 3D grid, the distance between the near and far planes of the preset 3D grid is 1), and under the dimension of the target level area, the depth of the near plane of the target level area is 0, and the depth of the far plane of the target level area is 1 (that is, under the dimension of the target level area, the distance between the near and far planes of the target level area is 1). Through the target projection matrix, the depth value within the range of (0,1) of the preset 3D grid is mapped to the depth range of (0,1) of the target level area. Then, in the dimension of the target level area, the depth range of the mapped preset 3D grid may be (0,0.1) and so on. The depth range of each preset 3D grid after mapping is part or all of the depth range of the target level area.
[0149] In the present invention, the characteristic that the observation accuracy of shadows gradually decreases from near to far is used to generate a shadow map of each target level area. The shadow map of each target level area covers an increasingly larger range from near to far, and naturally has the characteristic of filtering smoothness. The shadow map of the target level area can be used to determine whether each pixel point in the target level area is in the shadow, and a shadow result of the target level area is generated. In the generated shadow, the edge of the shadow area to the bright area has a smooth transition as the target level area moves from near to far. Specifically, for each pixel point in the target level area, the pixel point can be converted to the light source coordinate system to obtain the coordinates of the pixel point in the light source coordinate system, wherein the Z-axis coordinate is the pixel point in the light source coordinate system. The depth value of the pixel in the light source coordinate system is then sampled from the shadow map of the target level area using the coordinates of the pixel about the X and Y axes in the light source coordinate system to obtain the depth value of the pixel in the shadow map; the depth value of each pixel in the light source coordinate system is compared with the depth value of each pixel in the shadow map of the target level area to obtain the determination result of whether each pixel is in the shadow. For example, for any pixel under the viewing angle of the observation camera, if the depth value of the pixel in the light source coordinate system is less than or equal to the depth value of the pixel in the shadow map of the target level area, it means that the pixel is not blocked, and the determination result of the pixel is not in the shadow is obtained; otherwise, it means that the pixel is blocked, and the determination result of the pixel is in the shadow is obtained. Finally, based on the determination result of whether each pixel is in the shadow, the corresponding pixel value is assigned to the pixel. For example, if the determination result indicates that it is not in the shadow, the corresponding pixel value not in the shadow is assigned to the pixel. If the determination result indicates that it is in the shadow, the corresponding pixel value in the shadow is assigned to the pixel (for example, the pixel value is black, gray, etc.).
[0150] S106: In response to obtaining the shadow results corresponding to the respective target level regions, rendering and generating an observation picture of the scene area by the observation camera based on the shadow results corresponding to the respective target level regions.
[0151] After obtaining the shadow results corresponding to each target level area, shadow rendering can be performed on each target level area based on the shadow results corresponding to each target level area to generate an observation screen of the observation camera for the scene area.
[0152] Exemplarily, the rendering and generating, based on the shadow results corresponding to each target level area, an observation picture of the scene area by the observation camera includes:
[0153] The shadow results corresponding to each target level area are passed to the rendering pipeline, so that the rendering pipeline renders the shadow results corresponding to each target level area, so as to render and generate an observation picture of the scene area by the observation camera.
[0154] In the present invention, the rendering pipeline in the three-dimensional engine serves as a rendering module, which can render and generate observation images, etc. The shadow results corresponding to the target level area can be passed to the rendering pipeline, so that the rendering pipeline renders the shadow results corresponding to each target level area, and generates an observation image of the scene area for the observation camera. Among them, in the generated observation image, the objects, shadows of objects, terrains, shadows of terrains, etc. are generated with different degrees of refinement according to different target level areas, and the present invention does not limit this.
[0155] The shadow rendering method provided by the embodiment of the present invention divides the scene area to be rendered of the virtual scene into various target level areas based on the distance from the observation camera. For each level area, the target projection matrix of each target level area can be calculated so as to subsequently generate the shadow result corresponding to the target level area; specifically, the target projection matrix of the target level area can be calculated based on the position of the projection camera of the target level area. The first coordinate of the projection camera of the target level area in the world coordinate system can be determined first, and the second coordinate corresponding to the first coordinate in the light source coordinate system can be determined. To ensure the stability of the generated shadow, the second coordinate is aligned according to multiple alignment coordinates under the target level area to obtain a third coordinate. The coordinate corresponding to the third coordinate in the world coordinate system is the corrected coordinate information of the projection camera. Based on the corrected coordinate information, the target projection matrix corresponding to the projection camera can be calculated; through the target projection matrix and the target depth data, each pixel point in the target level area can be assigned a value to obtain the shadow result corresponding to the target level area. After obtaining the shadow results corresponding to each target level area, the observation screen of the observation camera relative to the scene area can be rendered according to the shadow results of each target level area. Among them, the target projection matrix of the target hierarchical area is used to characterize the corrected projection mapping relationship of projecting the depth value to the target hierarchical area to generate the shadow map of the target hierarchical area. By aligning, regardless of whether the projection camera moves, the uncorrected first coordinate of the projection camera is aligned to the corrected coordinate information, that is, the projection camera is equivalent to being at the corrected coordinate information all the time. At this time, when the shadow map corresponding to the target hierarchical area is generated using the obtained target projection matrix, the depth value of each pixel in the shadow map of the target hierarchical area is stable, and the result of determining whether the pixel is in the shadow will not jump, and a stable shadow result can be obtained, and the shadow in the observation screen of the generated observation camera will not produce a jitter effect. It can be seen that a stable shadow result can be generated through this solution to ensure the stability of the shadow in the observation screen of the observation camera.
[0156] Optionally, in another embodiment of the present invention, the target depth data includes: shadow maps corresponding to each of a plurality of preset three-dimensional grids;
[0157] The plurality of preset three-dimensional grids are pre-divided according to the light source direction of the directional light in the virtual scene; each preset three-dimensional grid has a shadow map corresponding to the depth value of the object in the preset three-dimensional grid.
[0158] In the present invention, the target depth data may be shadow maps corresponding to a plurality of preset three-dimensional grids, the preset three-dimensional grids being pre-divided according to the light source direction of the directional light in the virtual scene, each preset three-dimensional grid having a shadow map corresponding to the depth value of the object in the three-dimensional grid, and of course, each preset three-dimensional grid may also have camera parameters of a projection camera used in generating the corresponding shadow map, such as: the window size of the projection camera, the position of the projection camera, the distance between the near and far planes of the projection camera, etc.; when each preset three-dimensional grid generates the corresponding shadow map, the minimum depth value and the maximum depth value in the preset three-dimensional grid may be respectively mapped to the near plane (a plane perpendicular to the light source direction and close to the light source position) and the far plane (a plane perpendicular to the light source direction and far from the light source position) of the preset three-dimensional grid, and according to the difference between the minimum depth value and the maximum depth value, and the distance between the near and far planes, other depth values in the preset three-dimensional grid are mapped between the near and far planes. Exemplarily, the distance between the near and far planes may be defaulted to 1, which is equivalent to mapping the depth value of the object in the preset three-dimensional grid to the range of (0, 1) for subsequent mapping when generating the shadow map of the target hierarchical area.
[0159] The size of the preset three-dimensional grid can be determined according to the fineness of the pixels to be rendered. In the light source coordinate system, the virtual scene is divided into a plurality of preset three-dimensional grids. The range of each preset three-dimensional grid is as follows: Figure 7 As shown, each preset three-dimensional grid may have different sizes and shapes, each preset three-dimensional grid is a cubic grid, and there are two planes perpendicular to the direction of the directional light. Of course, in order to facilitate the division of the virtual scene, each preset three-dimensional grid may have the same size, shape, etc., and the present invention does not limit this.
[0160] In one implementation, a certain scene area LWB (light source world range) of a virtual scene, such as Figure 5 As shown, according to the direction of the directional light and the size of the preset three-dimensional grid, the scene area can be divided into multiple light source world units: LWC_0, LWC_1, LWC_2, wherein each preset three-dimensional grid has a near plane (LWC_0 near plane, LWC_1 near plane, LWC_2 near plane), a far plane (LWC_0 far plane, LWC_1 far plane, LWC_2 far plane), and the size of each preset three-dimensional grid can be understood as the range of the projection camera corresponding to the preset three-dimensional grid; in addition, for each preset three-dimensional grid, as Figure 4As shown, the projection camera window size of the preset three-dimensional grid is the size represented by the length and width of the near plane perpendicular to the direction of the directional light, and the position of the projection camera is the center of the near plane.
[0161] The virtual scene is divided into multiple preset 3D grids, and shadow baking is performed. The shadow maps of the multiple preset 3D grids can include the depth data of objects in each area of the virtual scene, without having to generate the overall shadow map of a certain area in the virtual scene in real time. In addition, the pre-generated shadow maps of the multiple preset 3D grids and the projection camera data can make it possible for shadow rendering to not be constrained by performance, power consumption and heat dissipation, thereby greatly reducing the cost of shadow rendering.
[0162] A shadow rendering method provided by the present invention is introduced below in conjunction with a specific embodiment.
[0163] Among them, the present invention provides a first shadow rendering method comprising: generating shadow data offline and reconstructing a cascaded shadow map;
[0164] The steps to generate shadow data offline include:
[0165] 1. Configure the area range of the virtual scene where shadows are to be generated (i.e. the scene area mentioned above), and select the type of objects to be shadowed, for example: most of the static objects, terrain objects, and trees and vegetation whose shadows you want to be static in the configured area (generally speaking, vegetation has a large number of mesh faces and high complexity, which brings great rendering pressure. Usually, you can choose to configure its shadow as static. If there is a large deformation range or vegetation that has a great impact on the picture, you can choose to exclude it);
[0166] 2. According to the directional configuration of the directional light of the virtual scene, calculate the light source world range LWB (i.e., bounding box range) in the light source coordinate system, which includes each object to be shadowed;
[0167] 3. According to the size of the grid unit configured to generate the shadow (the size of the grid unit is determined according to the fineness of the pixel), the light source world range LWB of the light source coordinate system is divided into a number of light source world units LWC (i.e., a plurality of preset three-dimensional grids) under the light source coordinate system. Among them, the configured area range may be very large. If the depth value of the object in the entire area range is directly generated into a shadow map, the resolution of this shadow map may exceed the maximum image size allowed by the actual system or display calculation program. Therefore, in the present invention, the scene to be baked (i.e., the light source world range LWB) is divided into a number of light source world units LWC according to the configured shadow grid unit size.
[0168] 4. Generate depth data of the depth values of objects contained in each light source world unit LWC, and traverse each light source world unit LWC, and record the parameters of its orthogonal camera (the projection camera is taken as an orthogonal camera in this application) (the depth data of each light source world unit LWC is generated by its corresponding orthogonal camera), for example: the distance between the far and near planes, the baking window size (the size represented by the length and width of the projection plane of the orthogonal camera), the position of the orthogonal camera, etc.
[0169] 5. Store the generated depth data of each light source world unit LWC and the parameters of the orthographic camera (necessary metadata for constructing shadow information), for example, compress and store them in an asset file.
[0170] The steps to rebuild a cascaded shadow map are:
[0171] 1. Transfer the depth data of each LWC of the offline generated scene, as well as the meta information such as the parameters of the orthogonal camera used by the LWC to generate shadows (such as the camera's near and far plane information, the baked window size, and the camera's position, etc.) to the graphics card memory;
[0172] 2. Calculate the orthogonal camera parameters of several levels of cascaded shadows according to the direction of the light source of the directional light and the parameters of the orthogonal camera of the LWC, that is, calculate the target projection matrix of each target level area (wherein, if the projection matrix is calculated in the manner of the prior art, then when reconstructing the shadow, when sampling the depth data generated offline in the graphics card shader program, that is, using the coordinates of the pixel point to sample from the shadow map to determine the depth value of the pixel point in the shadow map, the final reconstructed shadow will jitter due to the sampling error. The following camera parameter calculation process is the key step proposed by the present invention to solve the shadow jitter phenomenon):
[0173] a. According to the characteristic that the larger the range covered by the cascade shadow camera from near to far, the orthogonal camera required for each target level area is calculated, which is recorded as Camera0 (the specific level configuration and calculation algorithm depend on the scene size, the final picture effect and the machine operation efficiency, and have a certain degree of flexibility). The position of the orthogonal camera of the target level area calculated at this time is recorded as P0; (wherein, the number of pixels contained in each target level area is the same. Since the range of the target level area in the distance becomes larger, the pixel distribution becomes sparse, resulting in blurred rendering effect of the target level area in the distance).
[0174] b. Transform the orthogonal camera position P0 calculated in step a to the light source coordinate system and record the position as P1, that is, the first coordinate is P1;
[0175] c. Calculate the alignment size (i.e., the preset unit size) AlignSize under the target hierarchy area. The calculation method is: AlignSize = (ShadowCellSize / ShadowCellMapSize)*(CascadedWindowSize / ShadowCellWindowSize). Among them, ShadowCellSize: the size of the divided LWC grid unit in the XY direction in the light source coordinate system (that is, the size of the preset three-dimensional grid in the XY axis plane of the light source coordinate system), is a parameter containing two components; ShadowCellMapSize: the length and width of the shadow map of the baked LWC grid unit (the specific size depends on the configuration, the typical size is 1024*1024 or 2048*2048, that is, the size of the shadow map of the preset three-dimensional grid); CascadedWindowSize: the window size of the orthogonal camera corresponding to the target level area to be calculated, which is also the size in the XY direction in the light source coordinate system (that is, the size of the window of the target level area); ShadowCellWindowSize: the window size of the orthogonal camera corresponding to the baked LWC grid unit (that is, the window size of the preset three-dimensional grid).
[0176] d. Calculate the position P2 of point P1 after alignment. P2 = floor(P1 / AlignSize)*AlignSize. Floor is a function that rounds down real data; where floor(P1 / AlignSize) represents the integer multiple of the alignment size of P1 on the X-axis or Y-axis, and P2 is the coordinate of the target level area that is closest to and smaller than P1 and is an integer multiple of the alignment size, i.e., the third coordinate.
[0177] e. Transform point P2 to the position in the original world coordinate system to obtain P3 (i.e. the corrected coordinates);
[0178] f. Use the P3 position as the position of the corrected orthogonal camera in the target level area, that is, update the new position of Camera0 to P3, and then calculate the corrected orthogonal projection matrix of Camera0 (that is, the target projection matrix in the target level area) based on P3;
[0179] 3. Perform reconstruction calculation of cascaded shadow data in the graphics card shader program (which can be performed on the execution unit of the graphics card's ComputeShader or Pixel Shader), reconstruct the depth value based on the offline generated shadow data and the orthogonal projection matrix of each target level area, that is, map the depth data of each light source world unit LWC baked offline to the corresponding target level area, generate the shadow map of each target level area, and for each pixel point in the observation angle, determine whether the pixel point is in the shadow based on the depth value of the pixel point in the light source coordinate system and the depth value recorded in the shadow map of the corresponding target level area, and obtain the shadow result of each target level area. Among them, when generating the shadow map of each target level area, it is equivalent to mapping the depth value in the offline generated shadow data to the depth value in the target level area through the orthogonal projection matrix, and generating the shadow map of the target level area.
[0180] 4. After generating cascaded shadows (i.e., the shadow results of each target level area), the cascaded shadows can be rendered using the rendering pipeline to complete the shadow rendering process.
[0181] The embodiment of the present invention proposes a method for using offline generated shadow data to reconstruct cascade shadow camera parameters and finally generate the cascade shadows to be constructed (shadow results of each target level area).
[0182] First, the solution of the present invention is used to reconstruct cascaded shadows. When testing the same scene on the same machine, it only takes about 0.2ms to construct cascaded shadows through the written graphics card shader program (that is, the projection matrix in the original shader program is modified to the orthogonal projection matrix corrected by the present application, that is, the target projection matrix). If the cascaded shadows are rendered directly according to the solution of the prior art, it will take 4 to 5 ms or even more.
[0183] Secondly, the data source of the cascaded shadow map constructed in the present application is the shadow data generated offline. Compared with the real-time calculation of the objects contained in the cascaded shadow camera (since the range of the cascaded shadow camera constructed in real time is limited, for example, when the inclination angle of the directional light is too large, a very high object in the distance will cast a shadow in the near observation area, and the shadow of the object should actually be calculated, but according to the solution of the prior art, the object is not at all in the cascaded shadow camera, that is, the shadow of the object will not be generated), the present invention will not cause the situation where objects that may cause shadows are missing, and the stability of the reconstructed shadows is greatly improved.
[0184] In the technical solution, a key innovation of using offline shadow data to reconstruct cascaded shadow maps is to correct the position of the camera in the prior art for calculating cascaded shadows according to the camera parameters used for offline baked shadows, thereby solving the jitter problem of the reconstructed shadows. In essence, the shadow data in the shadow map is generated according to a certain orthogonal camera setting position, and a certain map size is limited data, which is a discretized data. The method for calculating the cascaded shadow camera in the prior art is to follow the position movement of the main observation camera to calculate, which can be approximately regarded as a kind of "continuous" motion data (essentially non-continuous, but the minimum resolution or accuracy is far greater than the accuracy of the offline generated data); using such continuous input sampling points to sample discrete data to determine the depth value of the pixel in the shadow map, coupled with the weighted method of linear filtering used for shadow map sampling, the sampling result jumps, resulting in jitter in the reconstructed shadow. In the present invention, the orthogonal camera of the cascaded shadow is aligned to a value with a fixed interval, which can make the position interval of the sampling point stable relative to the discrete information, thereby generating a stable reconstructed shadow.
[0185] Based on the above method embodiment, the embodiment of the present invention also provides a shadow rendering device, such as Figure 8 As shown, the device comprises:
[0186] The first determination module 810 is used to determine each target hierarchical region of the scene area to be rendered of the virtual scene; wherein each target hierarchical region is: each hierarchical region obtained by dividing the scene area based on the distance from the observation camera;
[0187] A second determination module 820 is used to determine, for each target hierarchical region, a coordinate of a projection camera of the target hierarchical region in the world coordinate system of the virtual scene as a first coordinate;
[0188] An alignment module 830 is used to determine a second coordinate corresponding to the first coordinate in the light source coordinate system of the virtual scene, and align the second coordinate according to a plurality of alignment coordinates in the target level area to obtain a third coordinate;
[0189] A calculation module 840 is used to use the coordinates corresponding to the third coordinate in the world coordinate system of the virtual scene as the corrected coordinate information of the projection camera, and calculate the target projection matrix corresponding to the projection camera based on the corrected coordinate information; wherein the target projection matrix is used to represent the corrected projection mapping relationship of projecting the depth value to the target hierarchical area to generate a shadow map of the target hierarchical area;
[0190] The assignment module 850 is used to assign values to each pixel point of the target hierarchical area based on the target projection matrix corresponding to the projection camera and the target depth data to obtain the shadow result corresponding to the target hierarchical area; wherein the target depth data is used to represent: the depth value of each object in the virtual scene from the perspective of the light source of the directional light;
[0191] The rendering module 860 is used for rendering and generating an observation picture of the scene area by the observation camera based on the shadow results corresponding to the target level areas in response to obtaining the shadow results corresponding to the target level areas.
[0192] The shadow rendering device provided by the embodiment of the present invention divides the scene area to be rendered of the virtual scene into various target level areas based on the distance from the observation camera. For each level area, the target projection matrix of each target level area can be calculated so as to subsequently generate the shadow result corresponding to the target level area; specifically, the target projection matrix of the target level area can be calculated based on the position of the projection camera of the target level area. The first coordinate of the projection camera of the target level area in the world coordinate system can be determined first, and the second coordinate corresponding to the first coordinate in the light source coordinate system can be determined. To ensure the stability of the generated shadow, the second coordinate is aligned according to multiple alignment coordinates under the target level area to obtain a third coordinate. The coordinate corresponding to the third coordinate in the world coordinate system is the corrected coordinate information of the projection camera. Based on the corrected coordinate information, the target projection matrix corresponding to the projection camera can be calculated; through the target projection matrix and the target depth data, each pixel point in the target level area can be assigned a value to obtain the shadow result corresponding to the target level area. After the shadow results corresponding to each target level area are obtained, the observation screen of the observation camera relative to the scene area can be rendered according to the shadow results of each target level area. Among them, the target projection matrix of the target hierarchical area is used to characterize the corrected projection mapping relationship of projecting the depth value to the target hierarchical area to generate the shadow map of the target hierarchical area. By aligning, regardless of whether the projection camera moves, the uncorrected first coordinate of the projection camera is aligned to the corrected coordinate information, that is, the projection camera is equivalent to being at the corrected coordinate information all the time. At this time, when the shadow map corresponding to the target hierarchical area is generated using the obtained target projection matrix, the depth value of each pixel in the shadow map of the target hierarchical area is stable, and the result of determining whether the pixel is in the shadow will not jump, and a stable shadow result can be obtained, and the shadow in the observation screen of the generated observation camera will not produce a jitter effect. It can be seen that a stable shadow result can be generated through this solution to ensure the stability of the shadow in the observation screen of the observation camera.
[0193] Optionally, the method for determining the multiple alignment coordinates under the target level area includes:
[0194] Each coordinate in the target hierarchical region that is a multiple of a preset unit size is determined as a plurality of alignment coordinates in the target hierarchical region.
[0195] Optionally, the alignment module is specifically used to:
[0196] Determine a coordinate among a plurality of alignment coordinates under the target level area that is closest to and smaller than the second coordinate;
[0197] The determined coordinates are used as coordinates after the second coordinates are aligned to obtain third coordinates.
[0198] Optionally, a method for determining the preset unit size under the target level area includes:
[0199] Calculate the preset unit size of the target hierarchical area based on the size of the window of the target hierarchical area, the window size of the preset three-dimensional grid, the size of the shadow map of the preset three-dimensional grid, and the size of the preset three-dimensional grid in the XY axis plane of the light source coordinate system;
[0200] There are multiple preset three-dimensional grids, which are pre-divided according to the light source direction of the directional light in the virtual scene; each preset three-dimensional grid has a shadow map corresponding to the depth value of the object in the preset three-dimensional grid.
[0201] Optionally, the target depth data includes: shadow maps corresponding to each of a plurality of preset three-dimensional grids;
[0202] The plurality of preset three-dimensional grids are pre-divided according to the light source direction of the directional light in the virtual scene; each preset three-dimensional grid has a shadow map corresponding to the depth value of the object in the preset three-dimensional grid.
[0203] Optionally, the assignment module is specifically used to:
[0204] Determine the preset three-dimensional grid to which each pixel point in the target level area belongs;
[0205] Based on the coordinates of the X and Y axes of each pixel point in the preset three-dimensional grid to which it belongs, sampling is performed from the shadow map of the preset three-dimensional grid to which it belongs, so as to obtain the depth value of each pixel point in the shadow map corresponding to the preset three-dimensional grid to which it belongs;
[0206] According to the target projection matrix, the distances between the near and far planes of the preset three-dimensional grid to which each pixel point in the target hierarchical area belongs, and the distances between the near and far planes of the target hierarchical area, the depth value of each pixel point in the shadow map corresponding to the preset three-dimensional grid to which it belongs is mapped to the target hierarchical area to obtain a shadow map of the target hierarchical area;
[0207] For each pixel in the target level area, based on the coordinates of each pixel in the light source coordinate system and the shadow map of the target level area, obtain a depth value of each pixel in the light source coordinate system and a depth value of each pixel in the shadow map of the target level area;
[0208] Compare the depth value of each pixel in the light source coordinate system with the depth value of each pixel in the shadow map of the target level area to obtain a determination result of whether each pixel is in the shadow;
[0209] Based on the determination result of whether each pixel point is in the shadow, a corresponding pixel value is assigned to each pixel point to obtain the shadow result corresponding to the target level area.
[0210] Optionally, the calculation module is specifically used to:
[0211] Based on the corrected coordinate information, calculating a translation matrix corresponding to the corrected coordinate information;
[0212] The product of the obtained translation matrix and the initial projection matrix is calculated to obtain a target projection matrix corresponding to the projection camera; wherein the initial projection matrix is the projection matrix corresponding to the first coordinate.
[0213] Optionally, each target level area of the scene area is a cube area;
[0214] The second determining module is specifically used to:
[0215] Determine the coordinates of the center point of the target plane of the target hierarchical area as the coordinates of the projection camera of the target hierarchical area in the world coordinate system of the virtual scene;
[0216] The target plane is a plane, among the planes in the target level area, which is perpendicular to the direction of the directional light and closest to the light source of the directional light.
[0217] Optionally, the rendering module is specifically used to:
[0218] The shadow results corresponding to each target level area are passed to the rendering pipeline, so that the rendering pipeline renders the shadow results corresponding to each target level area, so as to render and generate an observation picture of the scene area by the observation camera.
[0219] The embodiment of the present invention further provides an electronic device, such as Fig. 9 As shown, it includes a processor 901 , a communication interface 902 , a memory 903 and a communication bus 904 , wherein the processor 901 , the communication interface 902 , and the memory 903 communicate with each other via the communication bus 904 .
[0220] Memory 903, used for storing computer programs;
[0221] The processor 901 is used to implement any of the above-mentioned shadow rendering methods when executing the program stored in the memory 903.
[0222] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0223] The communication interface is used for communication between the above electronic device and other devices.
[0224] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0225] The above-mentioned processor 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, discrete hardware components.
[0226] In another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned shadow rendering methods are implemented.
[0227] In another embodiment of the present invention, a computer program product including instructions is provided, which, when executed on a computer, enables the computer to execute any shadow rendering method in the above embodiments.
[0228] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.
[0229] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0230] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0231] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. A shadow rendering method, characterized in that: The method comprises: Determine each target hierarchical region of the scene area to be rendered of the virtual scene; wherein each target hierarchical region is: each hierarchical region obtained by dividing the scene area based on the distance from the observation camera; For each target level region, determining the coordinates of the projection camera of the target level region in the world coordinate system of the virtual scene as the first coordinates; Determine a second coordinate corresponding to the first coordinate in the light source coordinate system of the virtual scene, and align the second coordinate according to a plurality of alignment coordinates in the target level area to obtain a third coordinate; The coordinate corresponding to the third coordinate in the world coordinate system of the virtual scene is used as the corrected coordinate information of the projection camera, and based on the corrected coordinate information, a target projection matrix corresponding to the projection camera is calculated; wherein the target projection matrix is used to represent a corrected projection mapping relationship of projecting the depth value to the target hierarchical area to generate a shadow map of the target hierarchical area; Based on the target projection matrix corresponding to the projection camera and the target depth data, each pixel point of the target hierarchical area is assigned a value to obtain a shadow result corresponding to the target hierarchical area; wherein the target depth data is used to represent: the depth value of each object in the virtual scene from the perspective of the light source of the directional light; In response to obtaining the shadow results corresponding to the respective target level regions, an observation picture of the scene area by the observation camera is rendered and generated based on the shadow results corresponding to the respective target level regions.
2. The method according to claim 1, characterized in that The multiple alignment coordinates under the target hierarchical area are determined based on a preset unit size under the target hierarchical area. The method for determining the multiple alignment coordinates under the target hierarchical area includes: Each coordinate in the target hierarchical region that is a multiple of a preset unit size is determined as a plurality of alignment coordinates in the target hierarchical region.
3. The method according to claim 1, characterized in that The step of aligning the second coordinates according to the plurality of alignment coordinates under the target level region to obtain the third coordinates includes: Determine a coordinate among a plurality of alignment coordinates under the target level area that is closest to and smaller than the second coordinate; The determined coordinates are used as coordinates after the second coordinates are aligned to obtain third coordinates.
4. The method according to claim 2, characterized in that: Methods for determining the preset unit size under the target level area include: Calculate the preset unit size of the target hierarchical area based on the size of the window of the target hierarchical area, the window size of the preset three-dimensional grid, the size of the shadow map of the preset three-dimensional grid, and the size of the preset three-dimensional grid in the XY axis plane of the light source coordinate system; There are multiple preset three-dimensional grids, which are pre-divided according to the light source direction of the directional light in the virtual scene; each preset three-dimensional grid has a shadow map corresponding to the depth value of the object in the preset three-dimensional grid.
5. The method according to claim 1, characterized in that The target depth data includes: shadow maps corresponding to each of a plurality of preset three-dimensional grids; wherein the plurality of preset three-dimensional grids are pre-divided according to the light source direction of the directional light in the virtual scene; each preset three-dimensional grid has a shadow map corresponding to the depth value of the object in the preset three-dimensional grid, The assigning of values to each pixel point of the target hierarchical area based on the target projection matrix corresponding to the projection camera and the target depth data to obtain the shadow result corresponding to the target hierarchical area includes: Determine the preset three-dimensional grid to which each pixel point in the target level area belongs; Based on the coordinates of the X and Y axes of each pixel point in the preset three-dimensional grid to which it belongs, sampling is performed from the shadow map of the preset three-dimensional grid to which it belongs, so as to obtain the depth value of each pixel point in the shadow map corresponding to the preset three-dimensional grid to which it belongs; According to the target projection matrix, the distances between the near and far planes of the preset three-dimensional grid to which each pixel point in the target hierarchical area belongs, and the distances between the near and far planes of the target hierarchical area, the depth value of each pixel point in the shadow map corresponding to the preset three-dimensional grid to which it belongs is mapped to the target hierarchical area to obtain a shadow map of the target hierarchical area; For each pixel in the target level area, based on the coordinates of each pixel in the light source coordinate system and the shadow map of the target level area, obtain a depth value of each pixel in the light source coordinate system and a depth value of each pixel in the shadow map of the target level area; Compare the depth value of each pixel in the light source coordinate system with the depth value of each pixel in the shadow map of the target level area to obtain a determination result of whether each pixel is in the shadow; Based on the determination result of whether each pixel point is in the shadow, a corresponding pixel value is assigned to each pixel point to obtain the shadow result corresponding to the target level area.
6. The method according to claim 1, characterized in that The calculating the target projection matrix corresponding to the projection camera based on the corrected coordinate information includes: Based on the corrected coordinate information, calculating a translation matrix corresponding to the corrected coordinate information; The product of the obtained translation matrix and the initial projection matrix is calculated to obtain a target projection matrix corresponding to the projection camera; wherein the initial projection matrix is the projection matrix corresponding to the first coordinate.
7. The method according to claim 1, characterized in that Each target level area of the scene area is a cube area; The step of determining the coordinates of the projection camera of the target level area in the world coordinate system of the virtual scene as the first coordinates includes: Determine the coordinates of the center point of the target plane of the target hierarchical area as the coordinates of the projection camera of the target hierarchical area in the world coordinate system of the virtual scene; The target plane is a plane, among the planes in the target level area, which is perpendicular to the direction of the directional light and closest to the light source of the directional light.
8. A shadow rendering device, characterized in that: The device comprises: A first determination module is used to determine each target hierarchical region of a scene area to be rendered of a virtual scene; wherein each target hierarchical region is: each hierarchical region obtained by dividing the scene area based on a distance from an observation camera; A second determination module is used to determine, for each target level region, a coordinate of a projection camera of the target level region in the world coordinate system of the virtual scene as a first coordinate; an alignment module, used to determine a second coordinate corresponding to the first coordinate in the light source coordinate system of the virtual scene, and align the second coordinate according to a plurality of alignment coordinates in the target hierarchical area to obtain a third coordinate; A calculation module, used to use the coordinates corresponding to the third coordinate in the world coordinate system of the virtual scene as the corrected coordinate information of the projection camera, and calculate the target projection matrix corresponding to the projection camera based on the corrected coordinate information; wherein the target projection matrix is used to represent the corrected projection mapping relationship of projecting the depth value to the target hierarchical area to generate a shadow map of the target hierarchical area; An assignment module is used to assign values to each pixel point in the target hierarchical area based on the target projection matrix corresponding to the projection camera and the target depth data to obtain a shadow result corresponding to the target hierarchical area; wherein the target depth data is used to represent: the depth value of each object in the virtual scene from the perspective of the light source of the directional light; The rendering module is used for rendering and generating an observation picture of the scene area by the observation camera based on the shadow results corresponding to the target level areas in response to obtaining the shadow results corresponding to the target level areas.
9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing any of the methods described in claims 1-7 when executing a program stored in a memory.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
