Method and device for improving real-time rendering parallel light shadow mapping effect
By processing scene data in real -time rendering, establishing parallel light space, and calculating the minimum surround rectangular information, the details of details in the effect of parallel light shadow stickers and the lack of shadowing are solved, and a more efficient and accurate shadow rendering effect is achieved.
Patent Information
- Application Number
- CN202310940302.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-27
- Publication Date
- 2025-01-28
AI Technical Summary
In the prior art, in real-time rendering, parallel light shadow map effects have problems of loss of details and missing shadows, especially in complex scenes and high details requirements.
By processing scene data, ensure that the object has a legal axis to enclose the enclosure box value, establish a parallel light space, and convert the axis of the object to the coordinates of the enclosure box to the parallel light space. Construct the view matrix and orthogonal projection matrix.
It improves the spatial utilization rate of shadow stickers, enhances the accuracy of shadows, meets the requirements of real -time rendering, ensures that the shadows of the edge of the object and small objects are clearly distinguished, and provide a more real and accurate shadow effect.
Smart Images

Figure CN119379893A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of modeling and rendering, and in particular relates to a method and a device for improving the real-time rendering of parallel light shadow mapping effects. Background Art
[0002] In real-time rendering, the algorithms for the shadow effects of parallel light are basically shadow map algorithms and their variants. The principle of shadow map is to render a depth map of the scene from the space where the parallel light is located, and then when rendering each pixel of the object, the current pixel is converted to the parallel light space, and the depth value of the current pixel is compared with the depth value of the corresponding pixel on the depth map. If the current pixel depth is greater, it means that the current pixel is not illuminated by the light source, which is a shadow.
[0003] Although the shadow map algorithm is simple, there are many uncertain details. The most important issue is how to determine the camera coordinates, the camera's upward direction and the coordinates of the scene in the view matrix of the parallel light space, and the width and height values in the orthogonal projection matrix. Generally speaking, determining these values requires developers to be very familiar with the rendering scene, know the size of the scene, and write some empirical values based on this. When the scene is relatively fixed, this solution can achieve good results.
[0004] As 3D scene types become more and more complex, the drawbacks of this empirical value method become increasingly apparent. For example, in order to ensure universality, the default value is usually set to a larger value, but in some scenes, the size of the objects in the scene is relatively small. In such scenes, users tend to pay more attention to details, and the larger default value causes the details to be lost. In some more serious cases, even if a larger default value is set, some scenes may have larger objects, which will cause the generated depth map to fail to cover the entire scene. Therefore, shadows will be missing in places beyond the default value range, resulting in a visual fault phenomenon, which greatly affects the user's viewing experience.
[0005] In the prior art, a method of calculating the scene bounding box can be used to solve this problem. This method dynamically calculates the total bounding box of all objects in the scene, and then constructs a view matrix and an orthogonal projection matrix based on the bounding box information. This method is sufficient for general scenarios, but the depth map generated by this method is usually not highly utilized, and may even be less than 10% at special angles. Therefore, for scenes with finer object modeling, if the user's need is to see the details of the object clearly, this method is still not ideal. Summary of the invention
[0006] In order to overcome the defects of the above-mentioned prior art, the present invention proposes a method for improving the real-time rendering of parallel light shadow mapping effect, the method comprising:
[0007] Process the scene data to ensure that the objects that need to be shadowed have valid axis-aligned bounding box values;
[0008] Establishing a parallel light space, and transforming the axis-aligned bounding box coordinates of the object into the parallel light space;
[0009] Calculating information of a minimum enclosing rectangle of the object in the parallel light space; the information of the minimum enclosing rectangle includes a width, a height, a center coordinate, and a rotation angle of the minimum enclosing rectangle;
[0010] After converting the center coordinates of the minimum enclosing rectangle into three-dimensional coordinates in the world space, a view matrix and an orthogonal projection matrix are constructed.
[0011] Specifically, the “establishing parallel light space” includes:
[0012] Merging the axis-aligned bounding boxes of the objects into an overall axis-aligned bounding box;
[0013] The parallel light space is obtained by aligning the center of the scene axis bounding box and half of the longest diagonal length, combined with the parallel light direction.
[0014] Preferably, the axis-aligned bounding box of the object is transformed into the parallel light space by orthogonal projection transformation.
[0015] Specifically, the “converting the axis-aligned bounding box coordinates of the object into the parallel light space” includes:
[0016] Obtaining vertex coordinates of the axis-aligned bounding box of the object;
[0017] The coordinates of each vertex are converted from the world space coordinate system to the parallel light space coordinate system.
[0018] Furthermore, the “calculating information of the minimum enclosing rectangle of the object in the parallel light space” includes:
[0019] Acquire the vertex coordinates from the parallel light space coordinate system, and use the vertex coordinates as a point set;
[0020] Solving the convex hull of the point set;
[0021] The rotating caliper algorithm is used to solve the information of the minimum enclosing rectangle of the convex hull; the information of the minimum enclosing rectangle of the convex hull is the information of the minimum enclosing rectangle of the object in the parallel light space.
[0022] Preferably, the “converting the center of the minimum enclosing rectangle into a three-dimensional coordinate in world space” comprises:
[0023] The third dimension coordinate of the center point of the axis-aligned bounding box of the entire scene is used as the third dimension coordinate of the center to be determined, so as to convert the center coordinate of the minimum enclosing rectangle into a three-dimensional coordinate of the world space.
[0024] Specifically, the view matrix is constructed based on the coordinates, orientation, and upward direction of the observer observing the object, and the orthogonal projection matrix is constructed based on the width and height of the minimum enclosing rectangle.
[0025] The present invention also proposes a device for improving the real-time rendering of parallel light shadow mapping effect, the device comprising:
[0026] The processing module is used to process the scene data to ensure that the objects that need to draw shadows have legal axis-aligned bounding box values;
[0027] A conversion module, used for establishing a parallel light space, and converting the axis-aligned bounding box coordinates of the object into the parallel light space;
[0028] A calculation module, used for calculating information of a minimum enclosing rectangle of the object in the parallel light space; the information of the minimum enclosing rectangle includes a width, a height, a center coordinate and a rotation angle of the minimum enclosing rectangle;
[0029] The construction module is used to convert the center coordinates of the minimum enclosing rectangle into three-dimensional coordinates in the world space, and then construct a view matrix and an orthogonal projection matrix.
[0030] Specifically, the conversion module includes:
[0031] a merging unit, configured to merge the axis-aligned bounding boxes of the objects into an overall axis-aligned bounding box;
[0032] A construction unit, used to obtain the parallel light space by aligning the center of the bounding box and half of the longest diagonal length through the scene axis and combining the parallel light direction;
[0033] A first acquisition unit, configured to acquire vertex coordinates of the axis-aligned bounding box of the object;
[0034] The conversion unit is used to convert the coordinates of each vertex from the world space coordinate system to the parallel light space coordinate system.
[0035] Furthermore, the calculation module includes:
[0036] A second acquisition unit, configured to acquire the vertex coordinates from the parallel light space coordinate system and use the vertex coordinates as a point set;
[0037] A first solving unit, used for solving the convex hull of the point set;
[0038] The second solving unit is used to solve the minimum enclosing rectangle information of the convex hull by using the rotating caliper algorithm; the minimum enclosing rectangle information of the convex hull is the minimum enclosing rectangle information of the object in the parallel light space.
[0039] The present invention has at least the following beneficial effects:
[0040] The solution proposed in the present invention determines the shadow map boundary by combining the bounding box of each object in the scene with the direction of parallel light, thereby improving the space utilization of the shadow map and improving the precision of the shadow. The solution can meet the requirements of real-time rendering, increase the utilization of actual objects in the shadow map under the same storage conditions, and realize the calculation of high-quality depth maps while ensuring the strict requirements of real-time rendering calculations, and improve the effect of real-time rendering shadows.
[0041] Furthermore, the solution proposed in the present invention enables users to operate in a two-dimensional plane, reduces the demand for calculations, improves calculation efficiency, and is easy for users to understand intuitively. It also allows users to directly obtain the range of the calculated parallel light in the space where it is located.
[0042] Therefore, the present invention provides a method and device for improving the real-time rendering of parallel light shadow mapping effects. The scheme proposed in the present invention can more accurately calculate the position and projection of the object in the light source coordinate system, realize the calculation of high-quality depth map, and improve the real-time rendering shadow effect without affecting the rendering performance, so that the edges of objects and the shadows of small objects are clearly distinguishable, ensuring that the shadow effect is more realistic and accurate, and providing users with a more realistic viewing experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0044] Figure 1 A schematic diagram of the overall process of the method for improving the real-time rendering of parallel light shadow mapping effects provided in Example 1;
[0045] Figure 2(a) is a schematic diagram of the world space coordinate system;
[0046] FIG2( b ) is a schematic diagram of a parallel light space coordinate system;
[0047] Figure 3 A schematic diagram of the process of establishing parallel light space;
[0048] Figure 4A schematic diagram of the process of converting the axis-aligned bounding box coordinates of an object into parallel light space;
[0049] Figure 5 A flowchart for calculating the minimum enclosing rectangle of an object in a parallel light space;
[0050] Figure 6 A schematic diagram of the module structure of the device for improving the real-time rendering of parallel light shadow mapping effects provided in Example 2.
[0051] Reference numerals
[0052] 21-processing module; 22-conversion module; 23-calculation module; 24-construction module; 221-merging unit; 222-construction unit; 223-first acquisition unit; 224-conversion unit; 231-second acquisition unit; 232-first solution unit; 233-second solution unit. DETAILED DESCRIPTION
[0053] 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 without creative work are within the scope of protection of the present invention.
[0054] Hereinafter, various embodiments of the present invention will be described more fully. The present invention may have various embodiments, and adjustments and changes may be made therein. However, it should be understood that there is no intention to limit the various embodiments of the present invention to the specific embodiments disclosed herein, but the present invention should be understood to cover all adjustments, equivalents and / or alternatives falling within the spirit and scope of the various embodiments of the present invention.
[0055] Hereinafter, the term "include" or "may include" used in various embodiments of the present invention indicates the presence of disclosed functions, operations or elements, and does not limit the addition of one or more functions, operations or elements. In addition, as used in various embodiments of the present invention, the terms "include", "have" and their cognates are intended only to indicate specific features, numbers, steps, operations, elements, components or combinations of the foregoing items, and should not be understood as first excluding the presence of one or more other features, numbers, steps, operations, elements, components or combinations of the foregoing items or the possibility of adding one or more features, numbers, steps, operations, elements, components or combinations of the foregoing items.
[0056] In various embodiments of the present invention, the expression "or" or "at least one of A or / and B" includes any combination or all combinations of the words listed at the same time. For example, the expression "A or B" or "at least one of A or / and B" may include A, may include B, or may include both A and B.
[0057] The expressions (such as "first", "second", etc.) used in various embodiments of the present invention may modify the various constituent elements in various embodiments, but may not limit the corresponding constituent elements. For example, the above expressions do not limit the order and / or importance of the elements. The above expressions are only used for the purpose of distinguishing an element from other elements. For example, the first user device and the second user device indicate different user devices, although both are user devices. For example, without departing from the scope of various embodiments of the present invention, the first element may be referred to as the second element, and similarly, the second element may also be referred to as the first element.
[0058] It should be noted that in the present invention, unless otherwise clearly specified and defined, the terms such as "installation", "connection", "fixation" and the like should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium; it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0059] In the present invention, those skilled in the art need to understand that the terms indicating orientation or positional relationship herein are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention.
[0060] The terms used in various embodiments of the present invention are only used for the purpose of describing specific embodiments and are not intended to limit various embodiments of the present invention. As used herein, the singular form is intended to also include the plural form, unless the context clearly indicates otherwise. Unless otherwise limited, all terms used here (including technical terms and scientific terms) have the same meaning as the meaning generally understood by those of ordinary skill in the art to which the various embodiments of the present invention belong. The terms (such as the terms defined in the dictionary generally used) will be interpreted as having the same meaning as the contextual meaning in the relevant technical field and will not be interpreted as having an idealized meaning or an overly formal meaning, unless clearly defined in various embodiments of the present invention.
[0061] To render a depth map from the space where the parallel light is located, you need to create a view matrix and an orthogonal projection matrix. The information needed to create the view matrix includes the position of the camera, the camera's upward direction, and a coordinate of the scene it is looking at. To create the orthogonal projection matrix, you need to know the width, height, near plane, and far plane of the scene you are looking at.
[0062] After constructing the view matrix and orthogonal projection matrix, the subsequent rendering of each specific pixel is also converted to the parallel light space through matrix multiplication and perspective processing, and then the depth value is compared.
[0063] Example 1
[0064] This embodiment proposes a method for improving the effect of real-time rendering of parallel light shadow mapping. The method proposed in this embodiment can realize the calculation of high-quality depth map and improve the effect of real-time rendering shadow while ensuring the strict requirements of real-time rendering calculation. Figure 1 , the method comprising:
[0065] S100: Process scene data to ensure that objects that need to draw shadows have legal axis-aligned bounding box values.
[0066] The axis-aligned bounding box with illegal values has a great impact on the final result of this solution, and may often result in the generation of a depth map with a width or height of 0. Therefore, in this embodiment, these objects need to be eliminated through step S100 to ensure that the final calculated value is legal.
[0067] It should be noted that the axis-aligned bounding box (AABB) is a box commonly used in computer graphics to enclose an object. It consists of a minimum coordinate point and a maximum coordinate point, and the sides of the box are parallel to the coordinate axis.
[0068] Among them, a legal axis-aligned bounding box refers to a box that meets the conditions that each component of the minimum coordinate point is less than or equal to the corresponding component of the maximum coordinate point and the side of the box must be parallel to the coordinate axis; a box whose component of the minimum coordinate point is greater than the corresponding component of the maximum coordinate point or whose side is not parallel to the coordinate axis is an illegal axis-aligned bounding box.
[0069] S200: Establishing a parallel light space, and transforming the axis-aligned bounding box coordinates of the object into the parallel light space.
[0070] S300: Calculate information of the minimum enclosing rectangle of the object in the parallel light space.
[0071] It should be noted that the minimum enclosing rectangle refers to a rectangle that encloses an object within the range of the minimum enclosing rectangle. The minimum enclosing rectangle is a rectangle on a two-dimensional plane, which is usually not necessarily parallel to the coordinate axis, and its bottom side often has a certain angle with the horizontal coordinate axis.
[0072] The information of the minimum enclosing rectangle can be obtained through step S300, and the information of the minimum enclosing rectangle includes the width, height, center coordinates and rotation angle relative to the horizontal axis of the rectangle.
[0073] S400: After converting the center coordinates of the minimum enclosing rectangle into three-dimensional coordinates in the world space, a view matrix and an orthogonal projection matrix are constructed.
[0074] It should be noted that, please refer to Figure 2(a), the world space three-dimensional coordinates are a mathematical representation used to describe the position of an object in three-dimensional space. In the world space coordinate system, three values of x, y, and z are usually used to represent the position of a point; among them, the x-axis represents the horizontal direction, the y-axis represents the vertical direction, and the z-axis represents the front-back direction. The positive direction can be forward or backward. With given x, y, and z values, the position of a unique point in the world space can be determined.
[0075] In step S400, "converting the center coordinates of the minimum enclosing rectangle into three-dimensional coordinates in world space" is the reverse step of "converting the coordinates of the axis-aligned bounding box of the object into parallel light space" in step S200. After obtaining the center coordinates of the minimum enclosing rectangle through step S300, the axis formed by connecting the center coordinates and the camera coordinates is the axis where the camera is finally located. However, at this time, the center of the minimum enclosing rectangle is a point on a two-dimensional plane, which needs to be converted into three-dimensional coordinates in world space first. Converting the center of the minimum enclosing rectangle into three-dimensional coordinates in world space can be achieved by assigning an arbitrary legal value.
[0076] Preferably, the "converting the center of the minimum enclosing rectangle into three-dimensional coordinates in world space" described in step S400 is implemented using the third-dimensional coordinates of the center point of the axis-aligned bounding box of the entire scene as the third-dimensional coordinates of the center to be determined, thereby allowing the three-dimensional coordinates of the world space converted from the center of the minimum enclosing rectangle to remain within the scene, simplifying the calculation and avoiding additional boundary judgments for the center point to be determined, while improving calculation efficiency.
[0077] It should also be noted that the view matrix is used to define the position and viewing direction of the observer observing the object, and to transform the objects in the scene into the coordinate space of the observer. In a specific embodiment, the view matrix includes information such as the position, orientation, and upward direction of the camera. By calculating the view matrix, the object can be transformed from the world coordinate system to the camera coordinate system.
[0078] The orthogonal projection matrix is used to project a three-dimensional scene onto a two-dimensional screen. The orthogonal projection matrix defines a regular observation volume (visible area) and compresses the observed rectangular area into a cube with a unit of 1. By calculating the orthogonal projection matrix, the three-dimensional scene can be correctly presented on the screen.
[0079] In this embodiment, a view matrix is constructed based on the observer's information, and an orthogonal projection matrix is constructed based on the information of the minimum enclosing rectangle, wherein the observer's information includes the observer's coordinates, orientation, and upward direction, and the minimum enclosing rectangle's information includes the width and height of the minimum enclosing rectangle. The specific method of constructing the view matrix and the orthogonal projection matrix belongs to the prior art and will not be described in detail in this embodiment.
[0080] Normally, the parallel light space can be determined by solving equations in analytic geometry to find the intersection of the aligned bounding boxes of all objects in the scene and a plane representing the direction of the parallel light. However, this method has a high computational cost, especially for large and complex scenes, and cannot meet the requirements of real-time rendering.
[0081] To solve this problem, in the solution of this embodiment, according to the provided parallel light direction, a suitable position outside the axis-aligned bounding box of the scene is calculated through the axis-aligned bounding box of the entire scene, and a parallel light space is established at this position. The purpose of establishing the parallel light space is to optimize the positional relationship between the calculated object and the parallel light during real-time rendering.
[0082] Specifically, see Figure 3 The “establishing parallel light space” in step S200 includes:
[0083] S210: Merge the axis-aligned bounding boxes of the objects into an overall axis-aligned bounding box.
[0084] Specifically, step S210 is implemented by calculating an axis-aligned bounding box of the entire scene.
[0085] S220: Align the center of the bounding box with the scene axis, half of the longest diagonal length, and combine with the parallel light direction to obtain the parallel light space.
[0086] Please refer to Figure 2(b). It should be noted that the quantities required to construct the parallel light space are basically the same as the quantities required to construct the view matrix, including the coordinate origin of the parallel light space, the Z axis of the parallel light space and the Y axis of the parallel light. The coordinate origin of the parallel light space is similar to the position of the camera, the Z axis of the parallel light space is similar to the direction of the camera, and the Y axis of the parallel light is similar to the upward direction of the camera. Since the X axis of the parallel light space can be obtained mathematically through basic vector cross multiplication operations, it can be ignored here.
[0087] In this embodiment, the Z axis of the parallel light space is the known parallel light direction. The Y axis of the parallel light can be calculated by setting a default value to obtain the value of the X axis and then return to continue further verification. Since the direction of the parallel light is known, the position facing the scene can use the center of the scene bounding box. Therefore, when it is necessary to know the distance from the camera to the position looking at the scene, the scene axis can be aligned with half the diagonal length of the bounding box, and then the value P of the coordinate origin is calculated according to the vector calculation formula. The formula is:
[0088] P=o–s*D
[0089] Among them, the three-dimensional vector P is the value of the coordinate origin, the three-dimensional vector D is the direction of the parallel light, the three-dimensional vector o is the position toward the scene, and s is half the diagonal length of the scene axis-aligned bounding box.
[0090] That is, use the center and height of the cuboid to calculate a plane for the parallel light. The condition satisfied by the plane is that the cuboids are all on one side of the plane. This ensures that the scene objects are all on one side of the plane. The center of the cuboid is used to determine the center of the parallel light space. Therefore, the center of the cuboid needs to be moved by half the height of the cuboid (corrected to: deleted).
[0091] The parallel light space in this embodiment is represented by a vector, and the method of converting the axis-aligned bounding box of the object to the parallel light space is an orthogonal projection transformation. After the parallel light space is constructed, projection is used to reduce the dimension of the object so that the user can operate in a two-dimensional plane. This setting is conducive to reducing the amount of calculation, facilitating intuitive understanding, and can directly obtain the range in the space where the parallel light is located after calculation.
[0092] Specifically, see Figure 4 The “converting the axis-aligned bounding box coordinates of the object to the parallel light space” in step S200 includes:
[0093] S230: Obtain the vertex coordinates of the axis-aligned bounding box of the object.
[0094] It should be noted that these vertex coordinates can be expressed as point coordinates in the local coordinate system of the object.
[0095] S240: Convert each vertex coordinate from the world space coordinate system to the parallel light space coordinate system.
[0096] Further, see Figure 5 , step S300 includes:
[0097] S310: Acquire vertex coordinates from the parallel light space coordinate system, and use the vertex coordinates as a point set.
[0098] S320: Solve the convex hull of the point set.
[0099] It should be noted that the convex hull refers to the smallest convex polygon enclosing all points in the point set, which is the basis of the smallest enclosing rectangle. In this embodiment, any method available in the prior art can be used to solve the convex hull, such as the Graham scanning algorithm.
[0100] S330: Using the rotating caliper algorithm to obtain information about the minimum enclosing rectangle of the convex hull.
[0101] It should be noted that the rotating caliper algorithm is a method for solving the enclosing rectangle of a convex polygon. The rotating caliper algorithm first selects any edge on the convex hull as the initial edge, and then continuously rotates this edge while maintaining the properties of the convex hull to find the minimum enclosing rectangle that can enclose the convex hull.
[0102] By calculating the area of the rectangle during each rotation and recording the current minimum area and the corresponding rectangle boundary, after a series of rotations, the minimum enclosing rectangle finally obtained is the minimum enclosing rectangle of the parallel light space required by this solution.
[0103] Example 2
[0104] This embodiment proposes a device for improving the real-time rendering of parallel light shadow mapping effects, see Figure 6 , the device comprises:
[0105] A processing module 21 is used to process scene data to ensure that objects that need to be shadowed have legal axis-aligned bounding box values;
[0106] A conversion module 22, used for establishing a parallel light space and converting the axis-aligned bounding box coordinates of the object into the parallel light space;
[0107] A calculation module 23 is used to calculate the information of the minimum enclosing rectangle of the object in the parallel light space; the information of the minimum enclosing rectangle includes the width, height, center coordinates and rotation angle of the minimum enclosing rectangle;
[0108] The construction module 24 is used to convert the center coordinates of the minimum enclosing rectangle into three-dimensional coordinates in the world space, and then construct a view matrix and an orthogonal projection matrix.
[0109] In this embodiment, the conversion module 22 calculates a suitable position outside the scene axis-aligned bounding box according to the provided parallel light direction through the axis-aligned bounding box of the entire scene, and establishes a parallel light space at the position. The parallel light space is represented by a vector, and the axis-aligned bounding box of the object is converted to the parallel light space by orthogonal projection transformation. Specifically, the conversion module 22 includes:
[0110] A merging unit 221, used to merge the axis-aligned bounding boxes of the objects into an overall axis-aligned bounding box;
[0111] A construction unit 222 is used to align the center of the bounding box and half of the longest diagonal length through the scene axis, combined with the parallel light direction, to obtain the parallel light space;
[0112] A first acquisition unit 223 is used to acquire the vertex coordinates of the axis-aligned bounding box of the object;
[0113] The conversion unit 224 is used to convert the coordinates of each vertex from the world space coordinate system to the parallel light space coordinate system.
[0114] In this embodiment, the Z axis of the parallel light space is the known parallel light direction. The Y axis of the parallel light can be calculated by setting a default value to obtain the value of the X axis and then return to continue further verification. Since the direction of the parallel light is known, the position facing the scene can use the center of the scene bounding box. Therefore, when it is necessary to know the distance from the camera to the position looking at the scene, the scene axis can be aligned with half the diagonal length of the bounding box, and then the value P of the coordinate origin is calculated according to the vector calculation formula. The formula is:
[0115] P=o–s*D
[0116] Among them, the three-dimensional vector P is the value of the coordinate origin, the three-dimensional vector D is the direction of the parallel light, the three-dimensional vector o is the position toward the scene, and s is half the diagonal length of the scene axis-aligned bounding box.
[0117] Furthermore, the calculation module 23 includes:
[0118] A second acquisition unit 231 is used to acquire vertex coordinates from the parallel light space coordinate system and use the vertex coordinates as a point set;
[0119] A first solving unit 232, used for solving the convex hull of the point set;
[0120] The second solving unit 233 is used to solve the information of the minimum enclosing rectangle of the convex hull by using the rotating calibrant algorithm.
[0121] The information of the minimum enclosing rectangle of the convex hull solved by the second solving unit 233 is the information of the minimum enclosing rectangle of the object in the parallel light space.
[0122] In summary, the present invention provides a method and device for improving the real-time rendering of parallel light shadow mapping effects. The scheme proposed in the present invention can more accurately calculate the position and projection of the object in the light source coordinate system, realize the calculation of high-quality depth map, and improve the real-time rendering shadow effect without affecting the rendering performance. The edges of objects and the shadows of small objects are clearly distinguishable, ensuring that the shadow effect is more realistic and accurate, and providing users with a more realistic viewing experience.
[0123] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for improving the real-time rendering of parallel light shadow mapping effect, characterized in that: The method comprises: Process the scene data to ensure that the objects that need to be shadowed have valid axis-aligned bounding box values; Establishing a parallel light space, and transforming the axis-aligned bounding box coordinates of the object into the parallel light space; Calculating information of a minimum enclosing rectangle of the object in the parallel light space; the information of the minimum enclosing rectangle includes a width, a height, a center coordinate, and a rotation angle of the minimum enclosing rectangle; After converting the center coordinates of the minimum enclosing rectangle into three-dimensional coordinates in the world space, a view matrix and an orthogonal projection matrix are constructed.
2. The method for improving the real-time rendering of parallel light shadow mapping effect according to claim 1, characterized in that: The “establishing parallel light space” includes: Merging the axis-aligned bounding boxes of the objects into an overall axis-aligned bounding box; The parallel light space is obtained by aligning the center of the scene axis bounding box and half of the longest diagonal length, combined with the parallel light direction.
3. The method for improving the real-time rendering of parallel light shadow mapping effect according to claim 1, characterized in that: The axis-aligned bounding box of the object is transformed into the parallel light space by orthogonal projection transformation.
4. The method for improving the real-time rendering of parallel light shadow mapping effect according to any one of claims 1 to 3, characterized in that: The “converting the axis-aligned bounding box coordinates of the object into the parallel light space” comprises: Obtaining vertex coordinates of the axis-aligned bounding box of the object; The coordinates of each vertex are converted from the world space coordinate system to the parallel light space coordinate system.
5. The method for improving the real-time rendering of parallel light shadow mapping effect according to claim 4, characterized in that: The “information of calculating the minimum enclosing rectangle of the object in the parallel light space” includes: Acquire the vertex coordinates from the parallel light space coordinate system, and use the vertex coordinates as a point set; Solving the convex hull of the point set; The rotating caliper algorithm is used to solve the information of the minimum enclosing rectangle of the convex hull; the information of the minimum enclosing rectangle of the convex hull is the information of the minimum enclosing rectangle of the object in the parallel light space.
6. The method for improving the real-time rendering of parallel light shadow mapping effect according to claim 1, characterized in that: The "converting the center of the minimum enclosing rectangle into a three-dimensional coordinate in the world space" includes: The third dimension coordinate of the center point of the axis-aligned bounding box of the entire scene is used as the third dimension coordinate of the center to be determined, so as to convert the center coordinate of the minimum enclosing rectangle into a three-dimensional coordinate of the world space.
7. The method for improving the real-time rendering of parallel light shadow mapping effect according to claim 1 or 6, characterized in that: The view matrix is constructed based on the coordinates, orientation, and upward direction of an observer observing the object, and the orthogonal projection matrix is constructed based on the width and height of the minimum enclosing rectangle.
8. A device for improving the real-time rendering of parallel light shadow mapping effect, characterized in that: The device comprises: The processing module is used to process the scene data to ensure that the objects that need to draw shadows have legal axis-aligned bounding box values; A conversion module, used for establishing a parallel light space, and converting the axis-aligned bounding box coordinates of the object into the parallel light space; A calculation module, used for calculating information of a minimum enclosing rectangle of the object in the parallel light space; the information of the minimum enclosing rectangle includes a width, a height, a center coordinate and a rotation angle of the minimum enclosing rectangle; The construction module is used to convert the center coordinates of the minimum enclosing rectangle into three-dimensional coordinates in the world space, and then construct a view matrix and an orthogonal projection matrix.
9. The device for improving the real-time rendering of parallel light shadow mapping effect according to claim 8, characterized in that: The conversion module comprises: a merging unit, configured to merge the axis-aligned bounding boxes of the objects into an overall axis-aligned bounding box; A construction unit, used to obtain the parallel light space by aligning the center of the bounding box and half of the longest diagonal length through the scene axis and combining the parallel light direction; A first acquisition unit, configured to acquire vertex coordinates of the axis-aligned bounding box of the object; The conversion unit is used to convert the coordinates of each vertex from the world space coordinate system to the parallel light space coordinate system.
10. The device for improving the real-time rendering of parallel light shadow mapping effect according to claim 9, characterized in that: The calculation module comprises: A second acquisition unit, configured to acquire the vertex coordinates from the parallel light space coordinate system and use the vertex coordinates as a point set; A first solving unit, used for solving the convex hull of the point set; The second solving unit is used to solve the minimum enclosing rectangle information of the convex hull by using the rotating caliper algorithm; the minimum enclosing rectangle information of the convex hull is the minimum enclosing rectangle information of the object in the parallel light space.