Cascade shadow generation method and device, storage medium and computer equipment
By dividing cascade levels with the center of the target object and calculating the view cone range under the light source perspective, the problem of poor flexibility in traditional cascade shadow mapping in autonomous driving simulation is solved, and efficient and accurate shadow generation is achieved, suitable for multi-camera Real-time scene of sensors.
Patent Information
- Application Number
- CN202411072139.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-06
- Publication Date
- 2024-12-03
AI Technical Summary
Traditional cascading shadow mapping is poor in flexibility and low in computing efficiency in autonomous driving simulation scenarios, making it difficult to meet the real-time shadow mapping requirements of multi-camera sensors.
Use the center of the target object as the center of the circle to divide the cascade along the preset radius, calculate the view cone range under the light source's viewing angle, and generate cascade shadows based on this range to achieve the binding and consistency of the cascade level and the target object. , allowing shadow sharing between different viewpoints.
It improves the flexibility and generalization of cascading shadow generation, reduces computing resource consumption, avoids shadow jitter, improves real-time, efficiency, accuracy and stability, and enhances the effectiveness and reliability of scene simulation.
Smart Images

Figure CN119068105A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of autonomous driving simulation technology, and in particular to a cascade shadow generation method, device, storage medium and computer equipment. Background Art
[0002] In the simulation test of the autonomous driving system, accurate simulation of the shadow effect of the sensor image can make the simulation scene closer to the real scene, thereby enabling more accurate, effective and reliable testing of the autonomous driving system's visual perception and object detection functions, helping the autonomous driving system to better adapt to real-world driving scenarios.
[0003] In existing shadow calculations, Cascaded Shadow Maps (CSM) are usually used to divide the camera cone into multiple levels and generate multiple shadow maps. Each level uses shadow maps of different resolutions to improve the performance of shadows. However, in autonomous driving simulation scenarios, users usually need to simulate the sensor images of dozens of different camera sensors, while traditional CSM uses the camera cone as a benchmark for hierarchical division. For different cameras, repeated divisions are required and repeated calculations and resource binding are performed in engineering, etc., which consumes a lot of computing power, has low computing efficiency, and has poor flexibility and generalization. At the same time, since autonomous driving has high requirements for the accuracy of camera sensors, it also has high requirements for the quality and speed of shadow generation, which makes it difficult for traditional CSM to perform shadow mapping calculations on images collected by multiple camera sensors in real-time scenarios. Summary of the invention
[0004] The present application mainly provides a cascaded shadow generation method, device, storage medium and computer equipment, aiming to solve the technical problem of poor flexibility of traditional cascaded shadow mapping.
[0005] In order to solve the above technical problems, the technical solution adopted by the present application is: to provide a cascade shadow generation method. The cascade shadow generation method includes: taking the center of the target object as the center of the circle, dividing along a preset radius to form multiple cascade levels; calculating the frustum range of each cascade level under the perspective of the light source; based on the frustum range, rendering each cascade level from the perspective of the light source to generate a cascade shadow.
[0006] In some embodiments, the calculation of the viewing cone range of each of the cascaded levels under the perspective of the light source includes: determining an outer rectangle of each of the cascaded levels, and taking the outer rectangle as a corner point; calculating a minimum z value and a viewing cone width that surround all of the corner points from the perspective of the light source, wherein the minimum z value is a minimum distance value from the light source to the outer rectangle, and the viewing cone width is a width of the outer rectangle under the perspective of the light source; determining an observation matrix and a projection matrix of the cascaded level under the perspective of the light source based on the minimum z value and the viewing cone width; and determining the viewing cone range of each of the cascaded levels under the perspective of the light source based on the observation matrix and the projection matrix.
[0007] In some embodiments, determining the viewing cone range of each cascaded level under the perspective of the light source based on the observation matrix and the projection matrix includes: determining the viewing cone position information under the perspective of the light source based on the observation matrix; determining the viewing cone shape information under the perspective of the light source based on the projection matrix; and determining the viewing cone range based on the viewing cone position information and the viewing cone shape information.
[0008] In some embodiments, based on the viewing cone range, each of the cascade levels is rendered separately from the perspective of the light source to generate cascaded shadows, including: determining the cascaded shadow generation range corresponding to each of the cascade levels based on the viewing cone range; shadow mapping the scene within the cascaded shadow generation range from the perspective of the light source to obtain a corresponding shadow map; retaining the shadow map within the corresponding range of each of the cascade levels to obtain the cascaded shadows.
[0009] In some embodiments, based on the viewing cone range, each of the cascade levels is rendered separately from the perspective of the light source to generate cascaded shadows, and also includes: determining the cascade level to be tested based on the depth value of each pixel point within the coverage range of the cascade shadow; performing a shadow test on the cascade level to be tested to determine the degree of occlusion of each pixel point in the cascade level to be tested; and adjusting the shadow value of the cascade shadow of the cascade level to be tested based on the occlusion degree.
[0010] In some embodiments, the preset radius is not less than the distance from the viewpoint on the target object to the farthest point of the viewing cone corresponding to the viewpoint.
[0011] In some embodiments, the dividing along a preset radius to form a plurality of cascade levels includes: dividing the preset radius based on at least one of linear division, logarithmic division, and weighted mixed division to obtain the plurality of cascade levels.
[0012] In order to solve the above technical problems, another technical solution adopted in the present application is to provide a cascade shadow generating device, which includes: a division module, which is used to divide the target object into multiple cascade levels along a preset radius with the center of the circle as the center; a calculation module, which is used to calculate the cone range of each cascade level under the perspective of the light source; and a rendering module, which is used to render the scene of each cascade level from the perspective of the light source based on the cone range to generate cascade shadows.
[0013] In order to solve the above technical problems, another technical solution adopted by the present application is: providing a storage medium, on which program data is stored, characterized in that when the program data is executed by a processor, the steps of the cascade shadow generation method as mentioned above are implemented.
[0014] In order to solve the above technical problems, another technical solution adopted in the present application is: to provide a computer device, which includes a processor and a memory connected to each other, the memory stores a computer program, and when the processor executes the computer program, the steps of the cascade shadow generation method as mentioned above are implemented.
[0015] The beneficial effects of the present application are as follows: Different from the prior art, the present application discloses a cascade shadow generation method, device, storage medium and computer equipment. The present application can realize the binding of the cascade level with the target object by dividing the cascade level along the radius with the center of the target object as the center of the circle, and can maintain the consistency of each cascade level in all directions, so that when observing the simulation scene of each cascade level with the target object as the center, it also has consistency, so that the cones starting from different viewpoints can all fall within the range of the cascade level rendering, and realize the sharing of cascade shadows between different viewpoints, which is very flexible and generalized. When the geometric position of the target object has not changed or the change is small, the present application does not need to re-divide the cascade level and regenerate the cascade shadow, nor does it need to perform additional adjustment calculations on the viewpoint, which reduces the consumption of corresponding computing resources, avoids the jitter of the shadow, and improves the real-time, high efficiency, accuracy and stability of the cascade shadow generation, which is conducive to improving the effectiveness and reliability of scene simulation. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work, among which:
[0017] Figure 1 It is a schematic diagram of cascade shadows generated by the traditional cascade shadow generation method.
[0018] Figure 2 It is a flowchart of an embodiment of a cascade shadow generation method provided by the present application;
[0019] Figure 3 yes Figure 2 A structural diagram of an embodiment of the cascaded level divided in step 10 of the embodiment;
[0020] Figure 4 yes Figure 2 A schematic flow chart of an embodiment of step 20 in the embodiment;
[0021] Figure 5 yes Figure 4 A schematic diagram of an embodiment of a minimum z value in an embodiment;
[0022] Figure 6 yes Figure 4 A schematic diagram of an embodiment of a viewing cone width in an embodiment;
[0023] Figure 7 yes Figure 4 A schematic flow chart of an embodiment of step 24 in the embodiment;
[0024] Figure 8 yes Figure 2 A schematic flow chart of an embodiment of step 30 in the embodiment;
[0025] Fig. 9 yes Figure 8 A schematic diagram of a flow chart of an optional embodiment in the embodiment;
[0026] Fig.10 It is a structural schematic diagram of an embodiment of a cascade shadow generating device provided by the present application;
[0027] Fig.11 It is a structural schematic diagram of an embodiment of a storage medium provided by the present application;
[0028] Fig.12 It is a structural diagram of an embodiment of a computer device provided by the present application. DETAILED DESCRIPTION
[0029] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0030] The terms "first", "second", "third" in the embodiments of the present application are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Thus, the feature defined as "first", "second", "third" can expressly or implicitly include at least one of the features. In the description of the present application, the meaning of "multiple" is at least two, such as two, three, etc., unless otherwise clearly and specifically limited. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or devices.
[0031] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0032] See also Figure 1 , Figure 1 It is a schematic diagram of generating cascade shadows by the traditional cascade shadow generation method.
[0033] The traditional cascade shadow generation method divides the view frustum of the viewpoint into several cascade levels according to a certain ratio, e.g. Figure 1 There are three levels in Near, Middle and Far. Each cascade level corresponds to a sub-cone. Each level covers a different depth range and calculates the relevant shadow map from the perspective of the light source. For example Figure 1 Different levels of dotted boxes are covered in the image to provide different resolutions for near and far scenes. The near layers use higher resolutions to ensure clear details, while the far layers use lower resolutions to reduce the computational cost, thereby reducing the impact of unrealistic factors such as perspective aliasing on related simulation tasks.
[0034] However, the traditional cascade shadow generation method depends on the viewpoint parameters, and the near and far planes are determined by the viewpoint parameters to obtain the corresponding cascade levels. For example, in the autonomous driving simulation scenario, users usually need to simulate dozens of different camera sensors at the same time, and the parameters corresponding to different camera sensor parameters are used to determine the hierarchical division of the cone. In these cases, it is usually necessary to repeatedly divide the cascade levels corresponding to different camera sensors, and perform repeated calculations and resource binding in engineering, etc., which has extremely low calculation efficiency. In addition, due to the different viewpoints, the cascade shadows need to be recalculated and generated when the target object posture changes or the viewpoint angle changes. It is impossible to share cascade shadows between viewpoints, lacking flexibility and compatibility, resulting in the traditional cascade shadow generation method being difficult to apply to simulation tasks such as autonomous driving simulation, route simulation, and real-time vision simulation, which have high requirements for the real-time and accuracy of the simulation environment.
[0035] This application provides a cascade shadow generation method, see Figure 2 , Figure 2 : is a flow chart of an embodiment of a cascade shadow generation method provided by the present application, the cascade shadow generation method comprising:
[0036] Step 10: Taking the center of the target object as the center of the circle, divide it along the preset radius to form multiple cascade levels.
[0037] The target object is the object bound to the subsequently generated cascade shadows. The corresponding cascade shadows can be generated by performing regional segmentation calculations on the location of the target object itself. In different simulation environments, the target object can be the main vehicle in the autonomous driving simulation environment, the character in the game scene, or the core building in the architectural design simulation. The subsequent cascade shadow generation centered on the target object can make the target object the focus of vision and interaction, which is conducive to the corresponding processing and optimization of the target object and the simulation scene close to the target object in the simulation environment, thereby improving the realism of the simulation environment.
[0038] The preset radius is the distance extended from the center of the circle. The preset radius can be preset according to the visual range of the target object, the precision requirements of the simulation environment, the requirements of related simulation tasks, and the availability of computing resources. Dividing along the preset radius means segmenting the preset radius, and the areas formed by different segments around the center of the circle correspond to different cascade levels.
[0039] See also Figure 3 , Figure 3It is a structural diagram of an embodiment of a cascade hierarchy. Taking the center of the target object (Object) as the center of the circle, it is divided into three sections along a preset radius, thereby obtaining three cascade levels Near, Middle and Far, which are respectively the cascade level closest to the target object, the cascade level with a middle distance value, and the cascade level of the farthest part. Figure 3 The rounded isosceles trapezoid in the figure is a plane diagram of the viewing cone corresponding to the visible range of a certain viewpoint on the target object. The preset radius corresponding to the cascade level in this scheme needs to cover the visible range from any viewpoint on the target object, so that all viewpoints can use the same set of cascade levels and corresponding cascade shadow maps for calculation, without the need to generate shadow maps viewpoint by viewpoint, thereby improving the corresponding calculation efficiency.
[0040] It should be noted that Figure 3 For example only, there may be 2 cascade levels, 4 cascade levels, or more cascade levels. The preset radius may be a length value of hundreds of meters, a length value of kilometers, a length value of ten kilometers, or a length value of hundreds of kilometers. The specific segmentation of the preset radius may be equidistant or unequal, etc. As long as the cascade level segmentation is centered on the target object, it is understood to be within the protection scope of this solution.
[0041] Optionally, the preset radius is not less than the distance from the viewpoint on the target object to the farthest point of the viewing cone corresponding to the viewpoint.
[0042] The viewpoint on the target object corresponds to the task requirement of the target object, which can be the camera equipment on the main vehicle in the autonomous driving simulation environment, the visual range of the character in the game scene, or the observation position of the user in the architectural design simulation, etc. The farthest point of the cone of vision is the farthest point that can be observed from the viewpoint. By ensuring that the preset radius is not less than the distance from the viewpoint to the farthest point of the cone of vision, it can be ensured that from the viewpoint of the target object in the simulation environment, all objects or scenes within the visible range can be appropriately divided into corresponding cascade levels, thereby ensuring the comprehensiveness and accuracy of shadow generation, so that the viewpoint has corresponding shadow coverage from different angles of the center of the target object, and the sharing of cascade shadows is achieved between different viewpoints without adjusting and calculating the viewpoints one by one.
[0043] Optionally, dividing along a preset radius to form a plurality of cascade levels includes: dividing the preset radius based on a division method selected from linear division, logarithmic division and weighted mixed division to obtain a plurality of cascade levels.
[0044] Linear division is a way to divide the cascade level in an average manner. For example, the surrounding area is divided into several areas such as 0-100m, 100-200m, 200-300m, etc. with the center of the target object as the center of the circle; logarithmic division is to divide the rendering area of the cascade shadow by the logarithmic value of the distance between the far and near planes compared to the area where the cascade shadow is located. For example, the surrounding area is divided into several areas such as 0-9m, 9-30m, 30-300m, etc. with the center of the target object as the center of the circle; weighted hybrid division is to weighted average the linear division and the calculated division distance. The specific weight is selected according to the specific task. For example, the distance of the above linear division is weighted 2, and the distance of the above logarithmic division is weighted 1. Then, after the weighted hybrid division, the area range is 0-70m, 70-143m, and 143-300m. The values in this example are calculated by rounding off. The corresponding values can also be determined by other number-taking methods, such as rounding up, rounding down, and retaining significant digits. Among them, linear division is simple to calculate and the visual cone is uniform, but the visual effect may be rough in the near distance due to the low resolution. Logarithmic division can maximize the shadow refinement in the near distance, but it will be too rough in the far distance due to the large area. Therefore, weighted mixed division is preferred to obtain the cascade level.
[0045] Through the above-mentioned cascade level determination method, the cascade level and the subsequently generated cascade shadows can be bound to the target object, so that the subsequent generation of cascade shadows is more in line with the actual position and posture of the target object, and the realism and dynamic effect of the shadows are enhanced. Under the cascade level division method, the different division levels in the simulation environment viewed from any viewpoint of the target object are consistent in all directions. As long as the subsequent cascade shadows are covered within the range of the cone of view of all viewpoints, the cascade shadows can be shared between different viewpoints, which is conducive to improving the continuity and consistency of the subsequently generated shadows under different viewing angles, simplifying the generation logic of the cascade shadows, avoiding repeated cascade level divisions and subsequent repeated cascade shadow generation, which is conducive to the efficiency of the subsequent cascade shadow generation, reducing the consumption of computing resources, avoiding the jitter of the shadows, and improving the real-time, high efficiency, accuracy and stability of the cascade shadow generation, which is conducive to improving the effectiveness and reliability of the scene simulation.
[0046] Step 20: Calculate the frustum range of each cascade level from the perspective of the light source.
[0047] The frustum range under the perspective of the light source is the spatial area that the light source can illuminate and cast shadows. The light source can be the sun, street lights, or indoor lights, and its position, direction, and intensity determine the path and range of light propagation. The frustum range can be used to determine the area that the subsequently generated cascade shadows need to cover. By subsequently generating cascade shadows to cover the entire frustum range, it can be ensured that the frustum ranges corresponding to all viewpoints on the target object are covered, so that the ranges covered by the frustum of all viewpoints can determine the shadows of the environment viewed by the viewpoints through shadow mapping, thereby improving the authenticity and reliability of the corresponding simulation environment.
[0048] Optionally, see Figure 4 , calculate the frustum range of each cascade level under the perspective of the light source, which can be performed as follows:
[0049] Step 21: Determine the outer bounding rectangles of each cascade level and use the outer bounding rectangles as corner points.
[0050] Step 22: Calculate the minimum z value and frustum width that surrounds all corner points from the light source's perspective.
[0051] Step 23: Determine the viewing matrix and projection matrix of the cascaded hierarchy from the perspective of the light source based on the minimum z value and the frustum width.
[0052] Step 24: Determine the frustum range of each cascade level under the perspective of the light source based on the observation matrix and the projection matrix.
[0053] The outer rectangle of each cascade level refers to a rectangle that can contain the cascade level and has the smallest area. Since the cascade level is a centrally symmetrical circle, its outer rectangle is also centrally symmetrical, and the center of the outer rectangle coincides with the center of the cascade level. It is preferred to use an outer rectangle whose adjacent two sides are parallel or perpendicular to the moving direction of the target object for subsequent processing. The directionality of the outer rectangle can be determined without additional calculation, ensuring that its area is minimized and the uniqueness of the outer rectangle can also be ensured. The four vertices of the outer rectangle or more points on the edge are used as corner points for subsequent calculations.
[0054] For details about the outer rectangle, please refer to Figure 5 or Figure 6 The two cases listed in the two-dimensional and three-dimensional perspectives are: Figure 5 and Figure 6 In the example, only the outer bounding rectangle of the nearest cascade level Near is determined. During the execution of the above steps, the outer bounding rectangles of other cascade levels also need to be determined. Since the determination of the outer bounding rectangles of each cascade level is similar to that of the cascade level Near, it will not be repeated here.
[0055] The minimum z value is the minimum distance from the light source to the outer rectangle, see Figure 5, the minimum z value determines the starting depth of the cone from the perspective of the light source, which can determine the distance between the corresponding cascade level and the light source. Subsequently, the minimum z value can be used to determine whether the pixel points in the cascade level are blocked. The cone width is the width of the cone covering each corner of the outer rectangle from the perspective of the light source, see Figure 6 The frustum width determines the width of the frustum under the perspective of the light source, and can cover the range of shadows that can be generated by the cascaded level under the light source conditions. The minimum z value and frustum width can be determined according to the position and direction of the light source and the division of the cascaded level.
[0056] It should be noted that Figure 5 Figure 6 The enclosing rectangle, light source, corresponding minimum z value and viewing cone width are exemplary, and may be specifically obtained based on the relationship between different enclosing rectangles and light sources. For example, the light source may be directly above or obliquely above the enclosing rectangle, above the extended range of the enclosing rectangle, or above the extended range of the enclosing rectangle, etc., wherein, when the light source is directly above or obliquely above the enclosing rectangle, the obtained viewing cone width is equal to that of the enclosing rectangle, and the minimum z value is the distance between the perpendicular line or the midline of the light source and the enclosing rectangle.
[0057] Based on the minimum z value and the width of the cone, the corresponding view matrix (View Matrix) and projection matrix (Projection Matrix) can be obtained. Among them, the view matrix is used to define the transformation from the world coordinate system to the view coordinate system with the light source as the viewpoint. The view matrix usually contains the position, orientation, and possible rotation and scaling information of the light source. From the perspective of the light source, the view matrix converts the light source into a viewpoint. It determines how the light starts from the light source and observes each cascade level and its outer bounding rectangle. The projection matrix defines how to map the three-dimensional points in the view coordinate system to a two-dimensional plane to form the projection of the cone from the perspective of the light source.
[0058] In shadow mapping, by adjusting the viewing matrix, you can ensure that the light source's perspective is correctly pointed and captures the details of each cascade level. The projection matrix can project the scene from the light source's perspective onto a depth buffer or texture map, which is then used to determine whether an object in the scene is in shadow. The projection matrix determines which three-dimensional points will be clipped and which points will be included in the final two-dimensional plane, and represented by the corresponding depth value to ensure that all details within the frustum can be accurately mapped and preserved.
[0059] The observation matrix obtained above determines the position of the viewing cone, while the projection matrix determines the shape of the viewing cone. According to the observation matrix and the projection matrix, the six planes corresponding to the viewing cone of each cascade level can be extracted, namely the far and near planes of the viewing cone and the four upper, lower, left and right planes formed by connecting the far and near planes. Then, the spatial area corresponding to the viewing cone can be determined, and the range of the viewing cone of each cascade level under the perspective of the light source can be accurately determined.
[0060] Optionally, see Figure 7 , based on the observation matrix and the projection matrix, determine the frustum range of each cascade level under the perspective of the light source, which can be performed as follows:
[0061] Step 241: Determine the view cone position information under the perspective of the light source based on the observation matrix.
[0062] Step 242: Determine the cone shape information under the perspective of the light source based on the projection matrix.
[0063] Step 243: Determine the range of the view cone based on the view cone position information and the view cone shape information.
[0064] The observation matrix involves the position, orientation, and possible rotation information of the light source in the world coordinate system. By integrating this information into the observation matrix, the center position and orientation of the view cone from the perspective of the light source can be accurately calculated, so that the projection direction and range of the shadow can be determined later. The projection matrix contains the width and height of the field of view and the distance between the near and far planes of the view cone. These parameters together determine the shape of the view cone. Therefore, the view cone position information can be obtained based on the observation matrix, and the view cone shape information can be determined based on the projection matrix. According to the view cone position information and the view cone shape information, the range of the view cone can be determined.
[0065] By calculating the range of the viewing cone through the above method, the obtained viewing cone range not only includes all areas that need to be covered by shadows, but also ensures that the generation of shadows can accurately reflect information such as the position, direction and intensity of the light source, so that in the subsequent shadow generation process, the range corresponding to all viewpoints on the target object can be effectively covered, which is conducive to improving the authenticity and reliability of the simulation environment.
[0066] Step 30: Based on the frustum range, each cascade level is rendered from the perspective of the light source to generate cascade shadows.
[0067] The range of the viewing cone determines the area that needs to be rendered. Only objects within the range of the viewing cone will be rendered with corresponding shadows to improve rendering efficiency. Scene rendering from the perspective of the light source, that is, simulating a real shadow effect on the objects in the scene based on information such as the position, direction and intensity of the light source. The specific rendering method can be shadow mapping rendering, or it can be based on screen space shadow rendering technology (Screen Space Shadows), or shadow rendering technology based on ray tracing (Ray Tracing), etc. Rendering is performed according to specific task requirements and parameter indicators to obtain cascade shadows that can more realistically and reliably reflect the simulation environment.
[0068] Optionally, see Figure 8 , based on the frustum range, each cascade level is rendered from the perspective of the light source to generate cascade shadows, which can be performed as follows:
[0069] Step 31: Determine the cascade shadow coverage range corresponding to each cascade level based on the frustum range.
[0070] Step 32: Perform shadow mapping rendering on the scene within the cascade shadow generation range from the perspective of the light source to obtain the corresponding cascade shadow.
[0071] After obtaining the range of the view cone, the range that the light source can illuminate can be determined based on the range of the view cone, so that the corresponding cascade shadow coverage range can be set, so that the cascade shadow coverage range can cover all objects and their surroundings within the range of the view cone, thereby optimizing the subsequent rendering process and ensuring that the generated shadow map can be applied to multiple viewpoints or different parts of the scene. If the shadow map obtained by calculation can cover the area corresponding to all view cones, it means that the cascade shadows generated corresponding to the cascade level can be applied to the current cascade shadows to determine the corresponding simulation scene no matter where the target object is observed.
[0072] After obtaining the shadow coverage, the corresponding shadow mapping rendering can be performed. Among them, shadow mapping rendering relies on shadow mapping technology. Shadow mapping pre-calculates the depth information of the scene from the perspective of the light source and stores this information in one or more shadow maps. When rendering each frame, each pixel in the scene is projected from the viewpoint perspective back to the light source perspective and compared with the depth value in the shadow map. If the depth value corresponding to the pixel position projected back to the light source perspective is greater than or equal to the depth value of the same position in the shadow map, it means that the point is between the light source and the scene object, that is, the point is blocked by the object, so the point is rendered as a shadow area. On the contrary, if the depth value is less than the value in the shadow map, it means that the point is not blocked and should be displayed normally.
[0073] By rendering the scene for each cascade level separately and applying the above-mentioned frustum range limitation, a series of cascaded shadows with different levels of detail and coverage can be obtained. These shadows together constitute the shadow effect in the scene, which can significantly improve the quality and efficiency of shadow generation.
[0074] Optionally, see Fig. 9 , based on the frustum range, each cascade level is rendered from the light source perspective to generate cascade shadows, and also includes:
[0075] Step 33: Determine the cascade level to be tested based on the depth value of each pixel point within the coverage range of the cascade shadow.
[0076] Step 34: Perform a shadow test on the cascaded level to be tested to determine the degree of occlusion of each pixel in the cascaded level to be tested.
[0077] Step 35: Adjust the shadow value of the cascade shadow of the cascade level to be tested based on the degree of occlusion.
[0078] In the process of generating cascaded shadows, in order to further enhance the realism and detail of the shadows, the cascaded levels can be tested for shadows at the same time during the rendering process to obtain a more detailed shadow effect for the corresponding cascaded levels. This process involves analyzing the depth information of each pixel within the shadow coverage range, and determining the rendering intensity of the shadow, that is, the softness or hardness of the shadow, based on this.
[0079] In this process, since the subsequent shadow test requires certain computing resources, and in different simulation tasks, the areas with higher precision are usually some relevant areas in the scene, it is usually not necessary to perform all shadow mapping. Therefore, some cascade levels can be determined as the cascade levels to be tested for corresponding shadow testing. Among them, since the smaller the cascade level, the smaller the rendering range, the higher the clarity, and the more accurate the precision calculation, the cascade level to be tested usually selects the smallest cascade level, that is, the cascade level closest to the target object, for example Figure 3 The cascade level Near in the figure, subsequent shadow testing and shadow value adjustment on the minimum cascade level can usually meet the needs of common simulation tasks such as autonomous driving simulation, game scene simulation, and architectural design simulation.
[0080] After determining the cascade level to be tested, a shadow test can be performed on the level to be tested. The shadow test is to compare the depth value of the pixel point seen from the current viewpoint with the depth value of each pixel point from the light source within the coverage range of the cascade shadow to determine whether the corresponding point is obscured. The degree of obstruction can be determined based on the pixels around it, so that the shadow value of each pixel point can be adjusted based on the degree of obstruction, thereby increasing the accuracy and authenticity of the cascade level for shadow testing.
[0081] After determining the degree of occlusion of each pixel, the rendering of the cascaded shadows can be fine-tuned based on this information. Specifically, for pixels that are completely occluded, their shadow values can be set to the maximum value, usually black, to indicate that these areas are completely in shadow; for partially occluded pixels, the shadow value will be reduced according to the degree of occlusion to achieve a softening effect of the shadow. This processing method not only improves the realism of the shadow, but also makes the shadow blend more naturally with the surrounding environment.
[0082] By implementing the above steps, cascaded shadows with rich details and high realism can be generated. These shadows not only cover all objects within the viewing cone, but are also accurately rendered and adjusted according to the position, direction and intensity of the light source and the shape and position of the object, making the generation of cascaded shadows more accurate and realistic, which is conducive to improving the effectiveness and reliability of scene simulation.
[0083] See also Fig.10 , Fig.10 It is a structural schematic diagram of an embodiment of a cascade shadow generating device provided by the present application.
[0084] The cascade shadow generating device 40 includes: a division module 41, which is used to divide the target object into multiple cascade levels along a preset radius with the center of the circle as the center; a calculation module 42, which is used to calculate the cone range of each cascade level under the perspective of the light source; and a rendering module 43, which is used to render the scene of each cascade level from the perspective of the light source based on the cone range to generate a cascade shadow.
[0085] Optionally, the preset radius is not less than the distance from the viewpoint on the target object to the farthest point of the viewing cone corresponding to the viewpoint.
[0086] Optionally, dividing along a preset radius to form a plurality of cascade levels includes: dividing the preset radius based on a division method selected from linear division, logarithmic division and weighted mixed division to obtain a plurality of cascade levels.
[0087] Optionally, the calculation module 42 is also specifically used to: determine the enclosing rectangle of each cascade level, and use the enclosing rectangle as the corner point; calculate the minimum z value and cone width that surround all corner points from the perspective of the light source; determine the observation matrix and projection matrix of the cascade level from the perspective of the light source based on the minimum z value and the cone width; determine the cone range of each cascade level from the perspective of the light source based on the observation matrix and the projection matrix.
[0088] Optionally, the calculation module 42 is further specifically used to: determine the view cone position information under the perspective of the light source based on the observation matrix; determine the view cone shape information under the perspective of the light source based on the projection matrix; and determine the view cone range based on the view cone position information and the view cone shape information.
[0089] Optionally, the rendering module 43 is further specifically used to: determine the coverage range of cascade shadows corresponding to each cascade level based on the frustum range; and perform shadow mapping rendering on the scene within the cascade shadow generation range from the perspective of the light source to obtain corresponding cascade shadows.
[0090] Optionally, the rendering module 43 is also specifically used to: determine the cascade level to be tested based on the depth value of each pixel point within the coverage range of the cascade shadow; perform a shadow test on the cascade level to be tested to determine the degree of occlusion of each pixel point in the cascade level to be tested; and adjust the shadow value of the cascade shadow of the cascade level to be tested based on the degree of occlusion.
[0091] Since the embodiments of the device part correspond to the embodiments of the above-mentioned method, the introduction of the cascaded shadow generating device 40 provided in the embodiment of the present invention and the corresponding beneficial effects can refer to the above-mentioned cascaded shadow generating method embodiment, and this embodiment will not be repeated here.
[0092] See also Fig.11 , Fig.11 It is a structural diagram of an embodiment of the storage medium provided by the present application.
[0093] The storage medium 50 stores program data 51. When the program data 51 is executed by the processor, the following is achieved: Figures 2 to 9 The described method for generating cascaded shadows.
[0094] The program data 51 is stored in a storage medium 50, and includes a number of instructions for enabling a network device (such as a router, a personal computer, a server, or other network device) or a processor to execute all or part of the steps of the method described in each embodiment of the present application.
[0095] Optionally, the storage medium 50 may be a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, an optical disk, or other medium that can store the program data 51 .
[0096] See also Fig.12 , Fig.12 It is a structural schematic diagram of an embodiment of a computer device provided by the present application.
[0097] The computer device 60 includes a processor 62 and a memory 61 connected to each other. The memory 61 stores a computer program. When the processor 62 executes the computer program, the following is achieved: Figures 2 to 9 The described cascade shadow generation method. The memory 61 may include the storage medium 50, or may be other independently developed memory.
[0098] Different from the prior art, the present application discloses a cascade shadow generation method, device, storage medium and computer equipment. By dividing the cascade level along the radius with the center of the target object as the center of the circle, the cascade level can be bound to the target object, and the consistency of each cascade level in all directions can be maintained, so that when observing the simulation scene of each cascade level with the target object as the center, it also has consistency, so that the cones starting from different viewpoints can all fall within the range of the cascade level rendering, and the sharing of cascade shadows between different viewpoints can be achieved, which is very flexible and generalized. When the geometric position of the target object has not changed or the change is small, the present application does not need to re-divide the cascade level and regenerate the cascade shadow, nor does it need to perform additional adjustment calculations on the viewpoint, which reduces the consumption of corresponding computing resources, avoids the jitter of the shadow, and improves the real-time, high efficiency, accuracy and stability of the cascade shadow generation, which is conducive to improving the effectiveness and reliability of scene simulation.
[0099] Each embodiment in this specification is described in a progressive 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 cascaded shadow generation device embodiment, storage medium and computer device embodiment, since they are basically similar to the cascaded shadow generation method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the cascaded shadow generation method embodiment.
[0100] The present application can be used in many general or special computing system environments or configurations, such as personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc.
[0101] In the several embodiments provided in this application, it should be understood that the disclosed methods, devices, storage media, and computer equipment can be implemented in other ways. For example, the device implementation described above is only illustrative, for example, the division of the modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.
[0102] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0103] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0104] The above descriptions are merely embodiments of the present application and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A cascade shadow generation method, It is characterized in that The cascade shadow generation method comprises: Taking the center of the target object as the center of the circle, multiple cascade levels are formed along the preset radius; Calculating the frustum range of each cascade level under the perspective of the light source; Based on the viewing cone range, scene rendering is performed on each of the cascade levels from the perspective of the light source to generate cascade shadows.
2. The cascade shadow generation method according to claim 1, It is characterized in that The calculating of the frustum range of each cascade level under the perspective of the light source includes: Determine the outer bounding rectangle of each cascade level, and use the outer bounding rectangle as a corner point; Calculate the minimum z value and the width of the cone that surround all the corner points from the perspective of the light source, wherein the minimum z value is the minimum distance value from the light source to the outer rectangle, and the cone width is the width of the outer rectangle under the perspective of the light source; Determine the observation matrix and the projection matrix of the cascaded level under the perspective of the light source based on the minimum z value and the viewing cone width; The viewing frustum range of each of the cascade levels under the viewing angle of the light source is determined based on the observation matrix and the projection matrix.
3. The cascade shadow generation method according to claim 2, It is characterized in that The determining the viewing cone range of each cascade level under the viewing angle of the light source based on the observation matrix and the projection matrix includes: Determine the view cone position information under the viewing angle of the light source based on the observation matrix; Determine the cone shape information under the viewing angle of the light source based on the projection matrix; The range of the viewing cone is determined based on the viewing cone position information and the viewing cone shape information.
4. The cascade shadow generation method according to claim 1, It is characterized in that The performing scene rendering on each of the cascade levels from the perspective of the light source based on the frustum range to generate cascade shadows includes: Determine the cascade shadow coverage range corresponding to each of the cascade levels based on the viewing cone range; Shadow mapping rendering is performed on the scene within the cascade shadow generation range from the perspective of the light source to obtain the corresponding cascade shadow.
5. The cascade shadow generation method according to claim 4, It is characterized in that The method of performing scene rendering on each of the cascade levels from the perspective of the light source based on the frustum range to generate cascade shadows further includes: Determine the cascade level to be tested based on the depth value of each pixel point within the coverage range of the cascade shadow; Performing a shadow test on the cascaded level to be tested to determine the degree of occlusion of each pixel in the cascaded level to be tested; The shadow value of the cascade shadow of the cascade level to be tested is adjusted based on the degree of occlusion.
6. The cascade shadow generation method according to claim 1, It is characterized in that The preset radius is not less than the distance from the viewpoint on the target object to the farthest point of the viewing cone corresponding to the viewpoint.
7. The cascade shadow generation method according to claim 1, It is characterized in that The division along the preset radius to form multiple cascade levels includes: The preset radius is divided based on a division method selected from linear division, logarithmic division and weighted mixed division to obtain a plurality of cascade levels.
8. A cascade shadow generating device, It is characterized in that The cascade shadow generating device comprises: A division module, used to divide the target object into multiple cascade levels along a preset radius with the center of the circle as the center; A calculation module, used for calculating the frustum range of each cascade level under the perspective of the light source; A rendering module is used to perform scene rendering on each of the cascade levels from the perspective of the light source based on the range of the viewing cone to generate cascade shadows.
9. A storage medium having program data stored thereon, It is characterized in that When the program data is executed by a processor, the steps of the cascade shadow generation method according to any one of claims 1 to 7 are implemented.
10. A computer device, It is characterized in that The method comprises a processor and a memory connected to each other, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of the cascade shadow generation method according to any one of claims 1 to 7 are implemented.
