A shadow mapping method and device
By mapping the first depth reference plane to the maximum depth value and the second depth reference plane to the minimum depth value in a three-dimensional scene, the projection transformation matrix is optimized, and the shadow flashing problem caused by floating point accuracy is solved, and the shadow rendering is improved Accuracy and speed.
Patent Information
- Application Number
- CN202310449108.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-01-07
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2039-01-07
AI Technical Summary
In the prior art, shadow rendering methods in three-dimensional scenes cause shadow flashing due to floating point accuracy problems, affecting the visual effect and the observer's emotions and visual fatigue.
By determining the first depth reference plane and the second depth reference plane in the shadow rendering method, the first depth reference plane is mapped to the maximum depth value, the second depth reference plane is mapped to the minimum depth value, and the shadow is determined based on these reference planes Area, optimize the projection transformation matrix to reduce the floating point accuracy differences.
Effectively reduces shadow flashing, improves the accuracy and speed of shadow rendering, and enhances visual effects.
Smart Images

Figure CN116468845B_ABST
Abstract
Description
[0001] The present invention is an invention patent application with application number 201910013863.5, application date January 7, 2019, application name A shadow rendering method in three-dimensional visualization graphics, and application type is a divisional application of an invention patent. Technical Field
[0002] The invention relates to a shadow rendering method, and in particular to a shadow mapping method and device. Background Art
[0003] In real scenes, shadow is a common lighting phenomenon, usually referring to the dark area caused by the light propagating in a straight line and being blocked by opaque objects. In virtual scenes, shadows represented by objects generated by three-dimensional modeling are very important for visualizing the screen in general and detecting the relative relationship between objects. In real-time rendering, there are currently a variety of shadow rendering algorithms, which are mainly divided into three categories, namely global illumination algorithms, shadow mapping algorithms, and shadow volume algorithms. Among them, the global illumination algorithm represented by ray tracing has realistic effects, but the amount of calculation is huge and it is difficult to perform real-time rendering. The shadow mapping algorithm and the shadow volume algorithm can be regarded as approximate methods of the global illumination method. The shadow volume algorithm has a serious dependence on the geometric complexity of the objects in the scene and has strict restrictions on the shape of the objects in the scene, so its applicability is poor. The shadow mapping algorithm has almost no restrictions on the complexity of the scene, and the principle is simple and the rendering speed is fast, making the shadow mapping algorithm the most commonly used shadow rendering algorithm in the field of real-time rendering. Its basic principle is that all illuminated parts of the scene can be seen from the light source as the viewpoint, and the areas that the light source cannot see are shadow areas.
[0004] The traditional shadow mapping method is mainly divided into two steps:
[0005] Step 1: Draw the entire scene with the light source position as the viewpoint, and record the visible depth of each visible pixel in the scene. This visible depth information represents the distance between the object closest to the light source at a certain pixel and the light source. After storing this visible depth information, it forms a depth texture;
[0006] Step 2: Draw the scene from the perspective of the real viewpoint. For each drawn point, calculate its distance from the light source and compare the distance from the light source with the corresponding depth value in the depth map generated in the first step. If the distance from the light source is greater than the visible depth, or the actual depth from the light source is greater than the visible depth, it means that there are other objects between the point and the light source and the point is in the shadow. Otherwise, the point is not in the shadow.
[0007] In order to compare the depth, the depth of each point must be processed as a number between [0 and 1]. According to the shadow generation method of the three-dimensional scene in the prior art, a reference plane close to the light source is a reference plane with a depth of 0, and a reference plane far from the light source is a reference plane with a depth of 1, and then the depth is judged based on the two reference planes. Although this reference plane setting method conforms to people's cognitive habits, the problem caused is that the floating point precision is obviously inferior to that of the area close to 1 in the area close to 0. In order to make the light shine on every point in the three-dimensional scene as much as possible and better simulate the effect of sunlight shining on the earth in a parallel manner, the light will be set far away from the three-dimensional scene, so that the shadow of the three-dimensional view will flicker. This flickering will not only affect the visual effect, but also may affect the mood of the observer and cause visual fatigue of the observer. Summary of the invention
[0008] In view of the shortcomings of the prior art, the present invention provides a shadow rendering method in three-dimensional visualization graphics, the method comprising: determining a first depth reference plane and a second depth reference plane for an area to be rendered, mapping a depth value of the first depth reference plane that is relatively closer to a light source in the first depth reference plane and the second depth reference plane as a maximum depth reference, and mapping a depth value of the second depth reference plane that is relatively farther from the light source in the first depth reference plane and the second depth reference plane as a minimum depth reference.
[0009] According to a preferred embodiment, the method includes: defining an envelope box of all or part of a volume of a stereoscopic scene to be rendered, wherein a first virtual surface and a second virtual surface of the envelope box perpendicular to the optical axis serve as a first depth reference plane and a second depth reference plane, respectively, and mapping a depth value of a first depth reference plane that is relatively closer to a light source in the first and second depth reference planes as a maximum depth reference, and mapping a depth value of a second depth reference plane that is relatively farther from the light source in the first and second depth reference planes as a minimum depth reference.
[0010] According to a preferred embodiment, a shadow rendering method in a three-dimensional visualization graphic comprises: determining a currently visible object according to a current viewpoint position and direction; determining a beam envelope box of the currently visible object in a three-dimensional scene; determining a first depth reference plane and a second depth reference plane according to a proximity order of intersection of a section perpendicular to the optical axis of the envelope box with the illuminated object; determining a shadow formed by the illuminated object in the three-dimensional scene based on the first depth reference plane and the second depth reference plane, wherein the first depth reference plane is mapped to a maximum depth reference Z max , and the second depth reference plane is mapped to the minimum depth reference Z min , wherein the first depth reference plane is closer to the light source than the second depth reference plane.
[0011] According to a preferred embodiment, the maximum depth reference is 1 and the minimum depth reference is 0.
[0012] According to a preferred embodiment, for a parallel light source, the projection transformation is as follows: Let w = light column width, h = light column height, n = Z1, f = Z2, and the projection transformation matrix M is as follows:
[0013]
[0014] The resulting depth mapping function is: Among them, Z1≤z≤Z2.
[0015] According to a preferred embodiment, for a point light source, the projection transformation is as follows:
[0016] Let aspect = aspect ratio of light cone, fovY = light cone angle, n = Z1, f = Z2, and the optimized projection transformation matrix M is as follows:
[0017]
[0018] Considering only the depth component, the depth mapping function is: Among them, Z1≤z≤Z2.
[0019] According to a preferred embodiment, the method further comprises: when a straight-line distance from the first depth reference plane Z1 to the corresponding pixel is less than a corresponding depth value, determining that the corresponding pixel is in a shadow.
[0020] According to a preferred embodiment, a computing device is provided, wherein the computing device is configured to execute the method as described in one of the aforementioned preferred embodiments.
[0021] According to a preferred embodiment, a central processing unit is provided, wherein the central processing unit is configured to execute the method of the present invention.
[0022] According to a preferred embodiment, a graphics processor is provided, wherein the graphics processor is configured to execute the method as described in any of the aforementioned preferred embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 is a schematic diagram of a preferred embodiment of the present invention;
[0024] Figure 2 is a schematic diagram of shadow mapping in the prior art, wherein: Figure 2 a is a schematic diagram showing the principle that a spatial point is in the shadow. Figure 2 b is a schematic diagram showing a spatial point not within the shadow;
[0025] Figure 3 It is a schematic diagram of the prior art;
[0026] Figure 4 It is the distribution diagram of the floating point precision of the computer;
[0027] Figure 5 It is a schematic diagram of the density change trend of floating point numbers from 0 to 1 and the floating point positions mainly used in the existing technology;
[0028] Figure 6 It is a density variation trend of floating point numbers from 0 to 1 and a schematic diagram of the floating point positions mainly used in the present invention;
[0029] Figure 7 is a schematic diagram of a preferred embodiment of the present invention;
[0030] Figure 8 is a schematic diagram of a preferred embodiment using a parallel light source;
[0031] Fig. 9 It is a depth mapping curve using parallel light sources in the prior art;
[0032] Fig.10 It is a depth mapping curve of the present invention using parallel light sources;
[0033] Fig.11 is a schematic diagram of a preferred embodiment using a point light source;
[0034] Fig.12 It is a depth mapping curve using a point light source in the prior art;
[0035] Fig.13 is a depth mapping curve of the present invention using a point light source; and
[0036] Fig.14 It is a flow chart of a preferred embodiment of the present invention.
[0037] Reference numerals list
[0038] 100: Scene 200: Envelope Box 300: Light Source
[0039] 310: optical axis 400: real viewpoint Z1: first depth reference plane
[0040] Z2: Second depth reference plane Z min : Minimum depth reference Z max : Maximum depth reference
[0041] Z A : View distance Z B : Straight-line distance P1: First spatial point
[0042] P2: Second spatial point z: Depth data before mapping DETAILED DESCRIPTION
[0043] The following is combined with Figure 1 , 2 , 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 and 14 are described in detail.
[0044] Example 1
[0045] This embodiment discloses a shadow generation method, or a shadow mapping method, or a shadow rendering method, or a shadow rendering method in a game scene, or a shadow rendering method in a virtual scene, especially a shadow rendering method in a three-dimensional visualization graphic. Without causing conflicts or contradictions, the whole and / or part of the preferred implementation methods of other embodiments can be used as a supplement to this embodiment. The method of the present invention can be implemented by the system of the present invention and / or other replaceable components. For example, the method of the present invention is implemented by using various components in the system of the present invention.
[0046] According to a preferred embodiment, the method may include determining a first depth reference plane Z1 and a second depth reference plane Z2 for the area to be rendered. The method may include setting the depth value of the first depth reference plane Z1, which is relatively closer to the light source 300, as the maximum depth reference plane Z1. max The method may include setting the depth value of the second depth reference plane Z2 that is relatively farther from the light source 300 in the first and second depth reference planes Z2 as the minimum depth reference plane Z2. min Preferably, the method may include: according to the set maximum depth reference Z max , and the minimum depth reference Z min Rendering shadows. Preferably, the method may include: according to the set maximum depth reference Z max and the minimum depth reference Z min Determine whether the corresponding spatial point is in the shadow. Preferably, the method can be used for shadow rendering in a game scene, especially for shadow rendering in a three-dimensional game scene.
[0047] According to a preferred embodiment, the method may include: according to the maximum depth reference Z mapped or set max and the minimum depth reference Z mapped or set min Determine whether the corresponding pixel is in the shadow. Since the depth value of the first depth reference plane Z1, which is relatively closer to the light source 300, is set as the maximum depth reference plane Z max The depth value of the second depth reference plane Z2 which is relatively farther from the light source 300 among the first depth reference plane Z1 and the second depth reference plane Z2 is set as the minimum depth reference plane Z1.min , which leads to the difference between the present invention and the prior art. In the prior art, the farther the shading point is from the light source, the greater the depth value, and the closer it is to the light source, the smaller the depth value. In the present invention, the shading point that is actually farther from the light source has a smaller depth value, and the closer it is to the light source has a larger depth value. The straight-line distance from the light source to the spatial point to determine whether it is in the shadow is also different from the prior art. In the prior art, the farther the spatial point is from the light source, the greater the straight-line distance, and the closer it is to the light source, the smaller the straight-line distance. In the present invention, the farther the spatial point is from the light source, the smaller the straight-line distance, and the closer it is to the light source, the larger the straight-line distance. Therefore, the method may include: when the straight-line distance from the first depth reference plane Z1 to the corresponding pixel is less than the corresponding depth value, determining that the corresponding pixel is in the shadow. As mentioned in the background technology, in the prior art, when the straight-line distance from the first depth reference plane Z1 to the pixel is greater than the corresponding depth value, the pixel is determined to be in the shadow.
[0048] According to a preferred embodiment, the method may include: dividing the local scene corresponding to the display image in the envelope box into a plurality of independently rendered sub-boxes. The method may include: determining the minimum depth value in the corresponding sub-box and the maximum depth value in the image area. The method may include: determining the pixel with the maximum straight-line distance to the first depth reference plane Z1 among all pixels corresponding to the corresponding sub-box. The method may include: when the maximum straight-line distance of the pixel with the maximum straight-line distance to the first depth reference plane Z1 among all pixels corresponding to the corresponding sub-box is less than the minimum depth value in the corresponding sub-box, determining that all pixels corresponding to the corresponding sub-box are in the shadow. The method may include: in response to determining that all pixels corresponding to the corresponding sub-box are in the shadow, determining that each pixel is in the shadow without performing a depth value reading for each pixel in the corresponding sub-box. The present invention can achieve at least the following beneficial technical effects by adopting this method: first, after the envelope box is divided into several sub-boxes, the partition rendering effect is better; second, when the maximum straight-line distance of the pixel with the maximum straight-line distance to the first depth reference plane Z1 among all pixels corresponding to the corresponding sub-box is less than the minimum depth value in the corresponding sub-box, then all pixels in the sub-box must be in the shadow, and there is no need to continue to read the depth value of each pixel to determine whether it is in the shadow, which speeds up the shadow rendering. According to a preferred embodiment, the method may include: determining all sub-boxes in several sub-boxes that envelop a continuous object, determining the outline of the shadow of the continuous object, and filling the pixels corresponding to all the sub-boxes in the determined several sub-boxes that envelop the continuous object with the lighter color depth.
[0049] According to a preferred embodiment, the method may include: determining a first depth reference plane Z1 and a second depth reference plane Z2 for the area to be rendered, mapping the depth value of the first depth reference plane Z1 that is relatively closer to the light source 300 in the first and second depth reference planes Z2 to the maximum depth reference plane Z1; max The method may include mapping the depth value of the second depth reference plane Z2 that is relatively farther from the light source 300 in the first and second depth reference planes Z2 to the minimum depth reference plane Z min .
[0050] According to a preferred embodiment, the method may include: defining an envelope box 200 of the whole or part of the volume of the stereoscopic scene 100 to be rendered, wherein a first virtual surface and a second virtual surface of the envelope box 200 perpendicular to the optical axis 310 are used as a first depth reference plane Z1 and a second depth reference plane Z2, respectively. The method may include: mapping the depth value of the first depth reference plane Z1, which is relatively closer to the light source 300, of the first and second depth reference planes Z2 to a maximum depth reference Z1. max The method may include mapping the depth value of the second depth reference plane Z2 that is relatively farther from the light source 300 in the first and second depth reference planes Z2 to the minimum depth reference plane Z min The first virtual surface may be closer to the light source 300 than the second virtual surface. Preferably, the maximum depth reference Z max Can be 1, minimum depth reference Z min Can be 0.
[0051] According to a preferred embodiment, the method may include: determining a first depth reference plane Z1 and a second depth reference plane Z2 for the area to be rendered. The method may include: mapping the depth value of the first depth reference plane Z1 that is relatively closer to the light source 300 of the first and second depth reference planes Z2 to 1. The method may include: mapping the depth value of the second depth reference plane Z2 that is relatively farther away from the light source 300 of the first and second depth reference planes Z2 to 0. In the prior art, it is customary to map the depth value of the first depth reference plane Z1 that is closer to the light source 300 to 0, and to map the depth value of the second depth reference plane Z2 that is farther away from the light source 300 to 1. However, the problem is that the floating point precision of the area close to 1 is much worse than that of the area close to 0, so that the shadow of the view will flicker.
[0052] According to a preferred embodiment, the method may include: defining an envelope box 200 of the whole or part of the volume of the stereoscopic scene 100 to be rendered. The method may include: using a first virtual plane and a second virtual plane of the envelope box 200 perpendicular to the optical axis 310 as a first depth reference plane Z1 and a second depth reference plane Z2, respectively. The method may include: mapping the depth value of the first depth reference plane Z1 relatively closer to the light source 300 of the first and second depth reference planes Z2 to 1. The method may include: mapping the depth value of the second depth reference plane Z2 relatively farther from the light source 300 of the first and second depth reference planes Z2 to 0. The first virtual plane may be closer to the light source 300 than the second virtual plane. Preferably, the optical axis 310 may refer to the optical axis 310 of the light source 300, and more specifically, may refer to the center line of the light beam or light column emitted by the light source 300.
[0053] According to a preferred embodiment, the method may include: determining the currently visible object according to the current viewpoint position and direction. The method may include: determining the beam envelope box of the currently visible object in the three-dimensional scene 100. The method may include: determining the first depth reference plane Z1 and the second depth reference plane Z2 according to the proximity order of the intersection of the tangent plane of the envelope box 200 perpendicular to the optical axis 310 with the illuminated object. The method may include: determining the shadow formed by the illuminated object in the three-dimensional scene 100 based on the first depth reference plane Z1 and the second depth reference plane Z2. Preferably, the first depth reference plane Z1 can be mapped to the maximum depth reference plane Z1. max The second depth reference plane Z2 can be mapped to the minimum depth reference Z min Preferably, the first depth reference plane Z1 is closer to the light source 300 than the second depth reference plane Z2.
[0054] According to a preferred embodiment, the method may include:
[0055] S1: Determine an envelope box 200 formed by an illuminated object in a three-dimensional scene 100;
[0056] S2: determining a beam envelope formed when the light beam of the light source 300 passes through the envelope box 200, wherein the beam envelope forms the envelope box 200 in the three-dimensional scene 100;
[0057] S3: determining a first depth reference plane Z1 and a second depth reference plane Z2 according to a proximity order of intersection of a section of the envelope box 200 perpendicular to the optical axis 310 and the illuminated object;
[0058] S4: Determine the shadow of the illuminated object in the three-dimensional scene 100 based on the first depth reference plane Z1 and the second depth reference plane Z2, wherein the first depth reference plane Z1 is mapped to the maximum depth reference Z max, and the second depth reference plane Z2 is mapped to the minimum depth reference Z min , wherein the first depth reference plane Z1 is closer to the light source 300 than the second depth reference plane Z2. Preferably, the light beam of the light source 300 may be at least one of a rectangular column, a cylindrical shape and a conical shape. Preferably, the light beam envelope box may be an envelope box.
[0059] According to a preferred embodiment, see Figure 2 and Figure 3 , Figure 2 and Figure 3 It is the prior art in this field. Due to cognitive habits and industry habits, people in this field are accustomed to setting the depth reference from small to large in the order from the direction of the light source 300 to the direction away from the light source 300. Figure 2 Take the traditional shadow mapping method as an example. Figure 2 A good explanation of how shadow mapping works. Figure 2 a, the straight-line distance Z between the first spatial point P1 and the first depth reference plane Z1 in the scene 100 B The visual distance Z in the direction of the line connecting the light source 300 and the first spatial point P1 in the scene 100 A In comparison, if the straight line distance Z B Greater than the viewing distance Z A , then there is an object blocking the line between the light source 300 and the first spatial point P1, and the first spatial point P1 is in the shadow. Figure 2 b, the straight-line distance Z between the second spatial point P2 and the first depth reference plane Z1 in the scene 100 B The visual distance Z in the direction of the line connecting the light source 300 and the first spatial point P1 in the scene 100 A In comparison, if the straight line distance Z B Equal to the viewing distance Z A , then there is no object blocking the line between the light source 300 and the first spatial point P1, and the second spatial point P2 is not in the shadow. A is the distance between the first depth reference plane Z1 and the obstruction in the direction of the line connecting the light source 300 and the first spatial point P1, and is also the distance that the light can reach when it is emitted from the first depth reference plane Z1 to the first spatial point P1. However, as mentioned in the background technology, this setting will cause the rendered shadow to flicker. Therefore, the applicant has studied and found that the technical personnel in this field have not considered the trend of floating point precision change and the object of shadow rendering at the minimum depth reference Z1. min and the maximum depth reference Z max In the case of the relationship between the distribution law, the minimum depth reference Z min and the maximum depth reference Z maxAlthough it violates cognitive habits and industry practices, it has achieved unexpected technical effects that are not inspired by existing technologies. For ease of understanding, a more detailed explanation is given here. Figure 3 , Figure 3 In the prior art, the depth value of the first depth reference plane Z1 which is relatively closer to the light source 300 in the first depth reference plane Z1 and the second depth reference plane Z2 is mapped as the minimum depth reference plane Z1. min , the depth value of the second depth reference plane Z2 which is relatively farther from the light source 300 in the first depth reference plane Z1 and the second depth reference plane Z2 is mapped to the maximum depth reference Z max , which is contrary to the configuration of the present invention. Figure 4 , Figure 4 A floating point number precision distribution diagram is given. Taking a 32-bit floating point number as an example, that is, Figure 4 As shown by the upper line segment, close to 0, that is, 10 -12 The minimum discernible accuracy is about 10 -19 , and near 1, i.e. 10 0 The minimum discernible precision is 10 -7 If we plot the value of each floating point expression between 0 and 1 on the number line, we will get something like Figure 5 The density effect shown. That is, the closer to 0, the denser the points, and the farther away from 0, the sparser the points. It should be noted that in order to show more intuitively, only some points are shown to show the density change trend of floating point numbers from 0 to 1. In actual situations, there will be more points. This shows that the representation of floating point numbers in computers is discontinuous. Due to the discontinuity of floating point numbers, the viewing distance Z of large and small can be compared. A and the straight-line distance Z B After a series of transformations, it may be mapped to the same position in [0,1]. B >Z A It may become Z B =Z A , and the further away from 0, the greater the chance of error, because the farther away from 0, the sparser the points. In the shadow calculation process, a point on a three-dimensional object, such as Figure 2 The first spatial point P1 in the image is transformed into a specific straight line distance Z in [0,1] after a series of transformations. B Then, it is compared with the minimum depth of the corresponding position in the pre-rendered scene 100 depth map, or the viewing distance Z A For comparison, if Z B >Z A-m, it means that it is blocked and darkening is performed. Otherwise, it is not blocked and the illumination is calculated normally. Among them, m is a positive value, and a very small positive value to avoid a point being blocked by itself. At this time, if the three-dimensional object, light source 300 or camera in the scene 100 moves slightly, it will cause Z B >Z A -m and Z B =Z A -m jumps back and forth between these two situations, see Figure 5 As shown in the case where the two points with unclear differences in a sparse area may be the case mentioned here, causing the program to jump back and forth between dimming and normal lighting to form flickering. This flickering is more obvious at places far away from 0. If the end far away from the light source 300 is mapped to 0 and the end near the light source 300 is mapped to 1, this flickering can be visually reduced. Although flickering is inevitable, it will be much less than the existing technology. Because in most cases, three-dimensional objects are viewed far away from the light source 300, and near 0, the size of floating point numbers can be distinguished more accurately. And see Figure 6 , if the minimum and maximum depth reference Z max By swapping the positions, the corresponding points can be located closer to the 0 value, and the value can be more accurately represented, so that the size of the two values can be accurately compared, thereby improving the flickering problem. Figure 7 In order to simulate the shadows of the real environment more realistically, the envelope box 200 will generally not only enclose the area visible to the real viewpoint 400, but will also be slightly expanded to project the shadows of objects projected into the area visible to the real viewpoint 400 into the area visible to the real viewpoint 400, such as projecting the building on the right into the area visible to the real viewpoint 400. Figure 7 The small dotted box in the middle envelope box 200 may be the area visible to the real viewpoint 400, while the envelope box 200 encloses a relatively larger volume. In fact, most of the areas visible to the real viewpoint 400 are closer to the second depth reference plane Z2. Therefore, the second depth reference plane Z2 is set as the minimum depth reference Z2. min It can improve the flickering situation and achieve unexpected technical effects in the prior art. Figure 8There are two three-dimensional objects in the three-dimensional scene 100. In this figure, the black squares in the side view represent the sides of the two three-dimensional objects. In this figure, it can also be seen that the incident direction of the light in the scene 100 is to project parallel light from the upper right to the lower left. In order to determine the projection, an envelope box 200 is virtually set. The envelope surface of the envelope box 200 close to the incident direction of the light is represented as Z1, and the envelope surface of the envelope box 200 away from the incident direction of the light is represented as Z2, wherein these two envelope surfaces are orthogonal to the incident direction of the light and are tangent to the outermost vertices of the two three-dimensional objects respectively. The depth value is defined along the direction of light projection, that is, the straight-line distance Z B For objects in the three-dimensional scene 100, since their shapes are continuous, the Z B The value should be a continuous value. However, because the computer needs to express it in discrete data, there is an error. Figure 8 In the figure, the distance between the lower right corner of the object represented by the black square on the right and the light source 300 is greater than the distance between the upper right corner and the light source 300, so the Z of the lower right corner is B Therefore, for the black column on the right, since its lower right corner is farther away from the light source 300, the bottom area of the three-dimensional graphic is more likely to flicker, which causes trouble to the three-dimensional scene 100.
[0060] According to a preferred embodiment, see Figure 8 , for the projection of parallel light, the conventional projection transformation is as follows:
[0061] Let w = light column width, h = light column height, n = Z1, f = Z2, and the projection transformation matrix M before optimization is as follows:
[0062]
[0063] Considering only the component in the depth direction, that is, along the direction of ray projection, the depth mapping function can be obtained as:
[0064] Among them, Z1≤z≤Z2, let Z1=10, Z2=1000, we can get the following Fig. 9 In this case, it can be seen that at the far end 1000 meters, that is, close to the observed object in the scene 100, the depth value is mapped to 1, and at the near end it is mapped to 0. Before optimization, according to The value near the observed object in the scene 100 is close to 1, so the accuracy is insufficient, which will cause flickering. For example, assuming that the depth data before mapping corresponding to the corresponding pixel or the depth data before mapping of the corresponding pixel is z=900,
[0065] For the projection of parallel light, the projection transformation optimized by the present invention is as follows:
[0066] Let w = light column width, h = light column height, n = Z1, f = Z2, and the optimized projection transformation matrix M is as follows:
[0067]
[0068] The depth mapping function is: Among them, Z1≤z≤Z2, the corresponding depth mapping curve can be found in Fig.10 After optimization: It can be seen that at the far end 1000 meters, that is, close to the observed object in the scene 100, the depth value is mapped to 0, and the near end is mapped to 1. After optimization, because The floating point value of is close to zero near the observed object within 100 of the scene, so the accuracy is high and flicker is not easy to appear. For example, for the pixel z=900 assumed before optimization mentioned above, after optimization, its corresponding z=110
[0069] According to a preferred embodiment, see Fig.11 , for the projection method of the point light source 300, the conventional projection transformation is as follows:
[0070] Let aspect = aspect ratio of light cone, fovY = light cone angle, n = Z1, f = Z2, and the projection transformation matrix M before optimization is as follows:
[0071]
[0072] Considering only the depth component, the depth mapping function can be obtained as: Among them, Z1≤Z≤Z2,
[0073] Let Z1 = 10, Z2 = 1000, and assume the unit is meter, then we can get Fig.12 The depth mapping curve shown in the figure. Before optimization, the depth value at the far end of 1000 meters is mapped to 1, and the near end is mapped to 0. What's worse is that the high-precision values close to 0 will be used up quickly, leaving only low-precision values at the far end.
[0074] For the projection method of the point light source 300, the projection transformation optimized by the present invention is as follows:
[0075] Let aspect = aspect ratio of light cone, fovY = light cone angle, n = Z1, f = Z2, and the optimized projection transformation matrix M is as follows:
[0076]
[0077] Considering only the depth component, the depth mapping function can be obtained as: Where Z1≤z≤Z2. Let Z1=10, Z2=1000, and assume the unit is meter, then we can get Fig.13 The depth mapping curve is shown. Fig.13 It can be seen that at the far end of 1000 meters, the depth value is mapped to 0, while at the near end it is mapped to 1. That is, the far end can make more use of high-precision values to reduce flicker.
[0078] According to a preferred embodiment, the method may include: determining two first virtual planes and second virtual planes that are parallel to each other and perpendicular to the optical axis 310. The first virtual plane may be closer to the light source 300 than the second virtual plane. The method may include: mapping a first normal depth value of a first virtual plane used to determine the depth of an illuminated object in the three-dimensional scene 100 to 1. The method may include: mapping a second normal depth value of a second virtual plane used to determine the depth of an illuminated object in the three-dimensional scene 100 to 0.
[0079] According to a preferred embodiment, the method may include: after defining the envelope box 200 of the whole or part of the volume of the stereoscopic scene 100 to be rendered and determining the first depth reference plane Z1, determining the angle between the vector of the first depth reference plane Z1 and the horizontal plane set in the stereoscopic scene 100. The method may include: determining the color depth of the shadow according to the angle. The method may include: the greater the absolute value of the angle, the higher the color depth of the shadow or the lighter the color depth. Preferably, the greater the absolute value of the angle, the lighter the color depth of the shadow. The method may include: placing the stereoscopic scene 100 to be rendered at a corresponding position of a virtual earth. The method may include: setting a moving light source as a virtual sun in the stereoscopic scene 100 to be rendered. The method may include: controlling the motion trajectory of the virtual sun relative to the virtual earth according to the current time and the motion trajectory of the real sun relative to the earth in the real world. Preferably, controlling the motion trajectory of the virtual sun relative to the virtual earth according to the current time and the current time of the real world can be periodically controlled. For example, the period can be 1 second, 1 minute, 5 minutes, 10 minutes, 30 minutes or 1 hour. The size of the period can be set according to the performance of the current computing device. The present invention can achieve at least the following beneficial technical effects by adopting this method: allowing gamers to feel the time in the real world according to the changes in the color depth and position of the shadows, which can not only improve the authenticity of the shadow rendering, but also allow some gamers to indirectly feel the changes in time, preventing some gamers from being immersed in the game and unable to feel the passage of time, which is equivalent to playing a psychological suggestion role for them.
[0080] According to a preferred embodiment, the method may include: determining a dynamically moving game character in a game scene, drawing the outline of the shadow of the game character through a shadow map, and filling the pixels within the outline with the shadow. The present invention can at least achieve the following beneficial technical effects by adopting this method: faster rendering speed. Preferably, the method may include: when filling the pixels within the outline with the shadow, filling the pixels that are relatively closer to the outline of the shadow with a lighter color depth.
[0081] According to a preferred embodiment, the method may include: determining whether the corresponding shadow belongs to a static shadow or a dynamic shadow, for static shadows, rendering based on the shadow determined last time when the relative position of the light source and the object causing the shadow has not changed, and for dynamic shadows, determining the shadow by real-time rendering. The present invention can at least achieve the following beneficial technical effects by adopting this method: it can reduce the computational overhead and render faster. Preferably, the method may include: when rendering the shadow, applying a static depth texture to a stationary object and applying a dynamic depth texture to a moving object. According to a preferred embodiment, a computing device, the computing device may be configured to execute all or at least a part of the method of the present invention. Preferably, the computing device includes a memory, at least one central processing unit and / or at least one graphics processing unit. The memory may store one or more instructions. At least one central processing unit and / or at least one graphics processing unit may be configured to execute all or at least a part of the method of the present invention when executing one or more instructions. Preferably, the central processing unit is a CPU and the graphics processing unit is a GPU. For example, the computing device may be configured to: determine a first depth reference plane Z1 and a second depth reference plane Z2 for the area to be rendered, and set the depth value of the first depth reference plane Z1 that is relatively closer to the light source 300 in the first and second depth reference planes Z2 as the maximum depth reference plane Z1. max The depth value of the second depth reference plane Z2 which is relatively farther from the light source 300 in the first and second depth reference planes Z2 is set as the minimum depth reference plane Z min , according to the maximum depth reference Z set max , and the minimum depth reference Z min Rendering shadows. The computing device may be configured to: max and the minimum depth reference Z min Determine whether the corresponding spatial point is in the shadow. The computing device is configured to determine that the pixel is in the shadow when the straight-line distance from the first depth reference plane Z1 to the pixel is less than the corresponding depth value. For the sake of brevity, this is merely an example and is not exhaustive.
[0082] According to a preferred embodiment, a central processing unit is provided, and the central processing unit can be configured to execute all or at least a part of the method of the present invention. The central processing unit can be connected or coupled to a memory storing one or more instructions, and the central processing unit can be configured to execute all or at least a part of the method of the present invention when executing one or more instructions.
[0083] According to a preferred embodiment, a graphics processor is provided, and the graphics processor can be configured to execute all or at least a part of the method of the present invention. The graphics processor can be connected or coupled to a memory storing one or more instructions. The graphics processor can be configured to execute all or at least a part of the method of the present invention when executing one or more instructions.
[0084] It should be noted that the above specific embodiments are exemplary, and those skilled in the art can come up with various solutions inspired by the disclosure of the present invention, and these solutions also belong to the disclosure scope of the present invention and fall within the protection scope of the present invention. Those skilled in the art should understand that the present invention description and its drawings are illustrative and do not constitute a limitation of the claims. The protection scope of the present invention is defined by the claims and their equivalents.
Claims
1. A shadow mapping method, characterized in that: The method at least comprises: After defining an envelope box (200) of all or part of a volume of a stereoscopic scene (100) to be rendered and determining a first depth reference plane (Z1), determining an angle between a vector of the first depth reference plane (Z1) and a horizontal plane set in the stereoscopic scene (100), Determine the color depth of the shadow based on the angle; Determine the currently visible objects based on the current viewpoint position and direction; Determining a beam envelope box of a currently visible object in a stereoscopic scene (100); Determining a first depth reference plane (Z1) and a second depth reference plane (Z2) according to a proximity order in which a section of the envelope box (200) perpendicular to the optical axis (310) intersects with the irradiated object; The depth value of the first depth reference plane relatively closer to the light source is mapped as the maximum depth reference, and the depth value of the second depth reference plane relatively farther from the light source is mapped as the minimum depth reference.
2. The method according to claim 1, characterized in that The method further comprises: The larger the absolute value of the angle is, the higher the color depth of the shadow is or the lighter the color depth is.
3. The method according to claim 1, characterized in that The method further comprises: The moving light source is set as a virtual sun in the stereoscopic scene (100) to be rendered, The movement trajectory of the virtual sun relative to the virtual earth is controlled according to the current time in the real world and the movement trajectory of the real sun relative to the earth within the current time.
4. The method according to claim 3, characterized in that The method further comprises: The motion trajectory of the virtual sun relative to the virtual earth is controlled periodically according to the current time in the real world and the motion trajectory of the real sun relative to the earth within the current time.
5. The method according to claim 1, characterized in that The method further comprises: For a parallel light source, the projection transformation is as follows: Let w = light column width, h = light column height, n = Z1, f = Z2, and the projection transformation matrix M is as follows: The resulting depth mapping function is: Among them, Z1≤z≤Z2, z is the depth data before mapping.
6. The method according to claim 1, characterized in that The method further comprises: For a point light source, the projection transformation is as follows: Let aspect = aspect ratio of light cone, fovY = light cone angle, n = Z1, f = Z2, and the optimized projection transformation matrix M is as follows: Considering only the depth component, the depth mapping function is: Among them, Z1≤Z≤Z2, z is the depth data before mapping.
7. A shadow mapping device, characterized in that: comprising at least one central processing unit and / or at least one graphics processing unit; The central processing unit and / or at least one graphics processor is configured to: After defining an envelope box (200) of all or part of a volume of a stereoscopic scene (100) to be rendered and determining a first depth reference plane (Z1), determining an angle between a vector of the first depth reference plane (Z1) and a horizontal plane set in the stereoscopic scene (100), Determine the color depth of the shadow based on the angle; Determine the currently visible objects based on the current viewpoint position and direction; Determining a beam envelope box of a currently visible object in a stereoscopic scene (100); Determining a first depth reference plane (Z1) and a second depth reference plane (Z2) according to a proximity order in which a section of the envelope box (200) perpendicular to the optical axis (310) intersects with the irradiated object; The depth value of the first depth reference plane relatively closer to the light source is mapped as the maximum depth reference, and the depth value of the second depth reference plane relatively farther from the light source is mapped as the minimum depth reference.
8. The device according to claim 7, characterized in that The central processing unit and / or at least one graphics processor are further configured to: The larger the absolute value of the angle is, the higher the color depth of the shadow is or the lighter the color depth is.
