Method for drawing soft shadow of directional light

Through the angle sampling on the parallel light and generate a beam with area, the parallel light shadow drawing in the existing technology is solved, and the dark changes of the light and the authenticity of the rendering results are realized.

CN119379892APending Publication Date: 2025-01-28LINGDI (ZHEJIANG) TECHNOLOGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310916087.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-07-25
Publication Date
2025-01-28

AI Technical Summary

Technical Problem

The existing parallel light shadow drawing method assumes that the light is completely parallel, resulting in unreal rendering effect and cannot effectively express the light and dark changes of shadows.

Method used

By performing a cone angle on parallel light to disturb the light direction, it is no longer completely parallel, which generates a beam with area. Use the conversion matrix to replace the sampling direction to the world space, and to cover the judgment and light calculation to achieve a soft shadow rendering.

Benefits of technology

This method can clearly express the light and dark changes of the shadow part, improve the authenticity of the shadow rendering, and make the rendering result closer to reality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119379892A_ABST
    Figure CN119379892A_ABST
Patent Text Reader

Abstract

The invention discloses a method for drawing a soft shadow of directional light. The method comprises the following steps: S1, establishing a space coordinate system in a forward direction by taking the direction of parallel light as a Z axis, and obtaining a conversion matrix; s2, an included angle range is set, and a new direction is sampled with the parallel light orientation as the center; s3, replacing the sampling direction to the world space through the conversion matrix and replacing the original parallel light orientation; and S4, judging whether shielding exists between the sampling direction and the irradiated point or not to complete soft shadow drawing. Cone angle sampling is carried out on each beam of parallel light to replace the original parallel light direction, the area is added for the parallel light, on the basis, whether the shielding object exists between the sampling direction and the irradiated object or not is judged, corresponding illumination calculation is carried out, and according to the mode, the soft shadow effect with light and dark changes can be obtained through rendering on the irradiated object. And the rendering result is closer to reality and is more realistic.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of soft shadow drawing, and in particular to a method for drawing soft shadow of directional light. Background Art

[0002] Ray tracing real rendering technology is widely used in related fields. Computers simulate the propagation of light in the real world. Different light sources will generate corresponding lighting effects and shadow ranges on different objects, thereby achieving rendering effects. In order to improve the realism of the rendering results, the light and dark changes of shadows are an important factor affecting the realism. Parallel light is a common light source that is often used to describe the light emitted from light sources such as sunlight from an infinite distance. Existing technologies usually describe parallel light by the direction D, assuming that all light rays are parallel to each other, thereby performing lighting calculations on objects in virtual scenes. In real life, light sources have areas, so even sunlight is generally not absolutely parallel. Therefore, when drawing parallel light, assuming that all light rays are absolutely parallel will cause unrealistic rendering effects. Therefore, it is necessary to study a new drawing method to solve this problem.

[0003] Chinese patent document CN104933754B discloses a "linear shadow map method for de-pixelated contour reconstruction". The method adopts (1) drawing the scene from the light source space, storing the depth values ​​of all pixel centers as the first shadow map, offsetting half the texel size in the x and y directions to obtain the second shadow map, and the first shadow map and the second shadow map constitute a linear shadow map; (2) drawing the scene from the view space, transforming the pixels to the light source space, and classifying the pixels into contour pixels and non-contour pixels; (3) using linear interpolation to calculate the depth value of the occluder for non-contour pixels, comparing the depth values ​​to obtain the shadow result, and for contour pixels, using the de-pixelated contour reconstruction method to reconstruct the shadow boundary. However, this method can only draw the effect of hard shadows, resulting in the rendered shadow effect not being realistic enough. Summary of the invention

[0004] The present invention mainly solves the technical problem that the original parallel light shadow drawing is unrealistic, and provides a soft shadow drawing method for directional light. The spatial coordinate system is established with the direction of the direction vector of the parallel light as the positive direction of the Z axis and a conversion matrix is ​​obtained. The direction of the parallel light is used as the central axis to perform sampling within a certain angle range, and the sampling result is substituted into the conversion matrix to replace it in the world space and replace the original parallel light direction. Finally, it is determined whether there is an obstruction between the sampling direction and the illuminated point and the corresponding illumination calculation is performed to complete the shadow rendering. This method can clearly show the light and dark changes of the shadow part, making the shadow rendering result more realistic.

[0005] The above technical problems of the present invention are mainly solved by the following technical solutions: The present invention comprises S1 establishes a spatial coordinate system with the direction of parallel light as the positive direction of the Z axis and obtains a transformation matrix; S2 sets the angle range and samples a new direction centered on the direction of the parallel light; S3 uses the conversion matrix to replace the sampling direction to the world space and replace the original parallel light direction; S4 determines whether there is any occlusion between the sampling direction and the illuminated point to complete the soft shadow drawing.

[0006] For the shadow rendering of objects illuminated by parallel light, most of the existing rendering technologies set all parallel lights as mutually parallel rays. Under this condition, all the rays do not interfere with each other and when they pass through the obstruction and shine on the object, there is a very obvious light-dark dividing line between the shadow area and the illuminated area generated. However, in current life, there are no parallel lights that are completely parallel to each other. Therefore, when parallel light passes through the obstruction and shines on the object, there is a certain light-dark change between the shadow area formed around the object and the illuminated area. There is a certain gap between the shadow effect diagram of parallel light drawn according to the original method and the reality, resulting in the generated shadow effect diagram not being realistic enough. The present invention disturbs each beam of parallel light to form a cone by cone angle sampling, and generates a light beam with an area for each beam of parallel light, so that the parallel light is closer to the actual situation, so that the subsequent parallel light passes through the obstruction and shines on the object to generate a soft shadow with light-dark changes, thereby improving the authenticity of the shadow rendering.

[0007] Preferably, in step S1, the parallel light direction D is determined and a local coordinate system is established with the unit vector of the parallel light direction D as the positive coordinate of the Z axis of the spatial coordinate system. Set vector D=(a,b,c) and set Z=D, then set X=(-c,0,a) and set the variable sign to +1 or -1 according to the positive or negative of c, that is, when c is greater than 0, sign=1, and when c<0, sign=-1; then set p=-1 / (sign+c), q=a*b*p. Calculate vector X = (1+sign*a*a*p, sign*q, -sign*a), Y = (q,sign+b*b*p, -b). Establishing a spatial coordinate system facilitates the calculation and substitution of subsequent transformation matrices.

[0008] Preferably, in step S1, let matrix N=(X, Y, Z), transpose N to obtain matrix M, let vector D=(a, b, c), then a and b are the first two components of direction D, and p and q are two temporary variables. By setting the matrix, the conversion matrix can be obtained for subsequent calculations.

[0009] Preferably, in step S2, in the local coordinate system, the cone angle range α is set with the parallel light direction D as the central axis, a direction is selected within the cone angle range, random numbers e1 and e2 uniformly distributed between 0 and 1 are randomly selected, and the azimuth angle phi=2*e1, e2 is used as an interpolation factor to interpolate between cos(α) and 1 to obtain cos(theta), theta is the angle value of the direction from the local coordinate axis Z axis, and finally the sampling direction L=(sin(theta)cos(phi), sin(theta)sin(phi), cos(theta)) in the cone angle is obtained. The calculation result is accurately optimized by the interpolation factor, so that the soft shadow effect generated subsequently is more realistic.

[0010] Preferably, in step S3, the direction L obtained after the cone angle sampling is converted into the world space through the conversion matrix M to obtain L', which is calculated as L'= M*L, and L' is used to replace the original parallel light direction D. After sampling, the sampling direction L can replace the original parallel light direction D through the conversion matrix, and multiple sampling directions L converge to fill each beam of parallel light into parallel light with an area, so as to achieve subsequent irradiation on the surface of the object to generate a shadow with light and dark changes.

[0011] Preferably, in step S4, an illuminated point is selected, and an offset point is obtained by offsetting the illuminated point in the L' direction by an infinite distance, and it is determined whether there is any occlusion between the offset point and the illuminated point. If there is no occlusion between the two points, illumination calculation is performed on the illuminated point. The illumination calculation method is to multiply the brightness of the light source reaching the illuminated point by the proportion of light reflected by the illuminated point to obtain the final brightness of the illuminated point. If there is occlusion between the two points, illumination calculation is not performed, and shadow rendering is performed on the illuminated point according to the calculation result.

[0012] Preferably, after the cone angle sampling, the parallel light forms an illumination area within the cone angle range α. The parallel light with the illumination area passes through the obstruction to generate a hard shadow area on the illuminated object, where no parallel light reaches the area; a soft shadow area, where some parallel light reaches the area and some parallel light cannot reach the area; and an illuminated area, where all parallel light can reach the area. The two sides of the hard shadow area are soft shadow areas, where there is a certain light-dark change, and the part of the soft shadow area that is not connected to the hard shadow area is provided with an illuminated area. The soft shadow area changes from light to dark from the end connected to the illuminated area to the end connected to the hard shadow area.

[0013] Preferably, after selecting a certain beam of parallel light in step S2, different angle sampling methods can be used to perturb the direction of the parallel light to draw soft shadows. In addition to the cone angle sampling method, a corresponding sampling method based on the direction of a certain beam of parallel light as the central axis can be used to change the direction of the parallel light within a small angle range to achieve the effect of soft shadows.

[0014] The beneficial effect of the present invention is that the present invention performs cone angle sampling on each beam of parallel light to replace the original parallel light direction, adds area to the parallel light, and on this basis determines whether there is an obstruction between the sampling direction and the illuminated object and performs corresponding lighting calculations. According to this method, a soft shadow effect with light and dark changes can be rendered on the illuminated object, making the rendering result closer to reality and more realistic. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] Figure 1 The present invention discloses a flow chart of parallel light soft shadow drawing.

[0016] Figure 2 This is a schematic diagram of the principle of a parallel light illuminating an object to form a shadow.

[0017] Figure 3 This is a schematic diagram of the principle of cone angle sampling of parallel light according to the present invention.

[0018] Figure 4 This is a principle diagram of the present invention in which parallel light performs cone angle sampling and then illuminates an object to form a shadow.

[0019] In the figure, A. illuminated area on the left, B. soft shadow area on the left, C. hard shadow area, D parallel light direction, E. soft shadow area on the right, F. illuminated area on the right, G occluder, H. parallel light, L. cone angle sampling direction. DETAILED DESCRIPTION

[0020] The technical solution of the present invention is further specifically described below through embodiments and in conjunction with the accompanying drawings.

[0021] Embodiment: A method for drawing soft shadows of directional light in this embodiment, such as Figure 1 As shown, S1 establishes a space coordinate system with the direction of parallel light as the positive direction of Z axis and obtains a transformation matrix; S2 sets the angle range and samples a new direction centered on the direction of the parallel light; S3 uses the conversion matrix to replace the sampling direction to the world space and replace the original parallel light direction; S4 determines whether there is any occlusion between the sampling direction and the illuminated point to complete the soft shadow drawing.

[0022] Realistic rendering technology based on ray tracing is widely used in fields such as film and television and games. Rendering technology simulates the propagation of light in the real world by means of computers, thereby producing a realistic picture effect. The simulation of light sources is a key link in rendering technology. Different light sources will produce different illumination ranges, light brightness, and shadows when shining on objects, and the light and dark changes of shadows are crucial to the improvement of realism. Parallel light is a common light source, which is often used to describe the light emitted from light sources such as sunlight from an infinite distance. Existing technologies usually describe parallel light by heading D, assuming that all light rays are parallel to each other, thereby performing illumination calculations on objects in virtual scenes. In real life, because light sources have areas, even sunlight is generally not absolutely parallel. Therefore, when drawing parallel light, assuming that all light rays are absolutely parallel will cause unrealistic rendering effects, which is also the reason why parallel light in the prior art will cause hard shadows. In this embodiment, the method of parallel light is disturbed, and the direction of parallel light is changed within a small range. The disturbed parallel light can generate a soft shadow effect when shining on an object, so that the rendering result is more in line with the actual situation. In step S1, the parallel light direction D is determined and the local coordinate system is established with the unit vector of the parallel light direction D as the positive coordinate of the Z axis of the spatial coordinate system. Set the vector D=(a,b,c) and set Z=D. Set X=(-c,0,a) and set the variable sign to +1 or -1 according to the positive or negative of c, that is, when c is greater than 0, sign=1, and when c<0, sign=-1; Set p=-1 / (sign+c), q=a*b*p. Calculate the vector X = (1+sign*a*a*p, sign*q, -sign*a), Y = (q,sign+b*b*p, -b), set the matrix N=(X,Y,Z), transpose N to obtain the matrix M, and calculate the Y coordinate by vector cross multiplication Y=cross(X,Z); finally, normalize X,Y,Z to obtain the coordinates X',Y',Z', and set the conversion matrix M = (X',Y',Z'). In step S2, in the local coordinate system, the cone angle range α is set with the parallel light direction D as the central axis, a direction is selected within the cone angle range, random numbers e1 and e2 uniformly distributed between 0 and 1 are randomly selected, and the azimuth angle phi=2*e1, e2 is used as an interpolation factor to interpolate between cos(α) and 1 to obtain cos(theta), theta is the angle value of the direction from the local coordinate axis Z axis, and finally the direction sampled in the cone angle L=(sin(theta)cos(phi), sin(theta)sin(phi), cos(theta)). In addition to the cone angle sampling method, after selecting a beam of parallel light, different angle sampling methods can be used to perturb the direction of the parallel light for soft shadow drawing. In step S3, the direction L obtained after the cone angle sampling is converted to the world space through the transformation matrix M to obtain L' and replace the original direction D of the parallel light.After the cone angle sampling, the parallel light forms an illumination area within the cone angle range α. The parallel light with the illumination area passes through the occluder and generates a hard shadow area on the illuminated object, where no parallel light reaches; a soft shadow area, where some parallel light reaches but some parallel light cannot reach; and an illuminated area, where all parallel light can reach. In step S4, the illuminated point is selected, and the offset point is obtained by offsetting the illuminated point in the L' direction by an infinite distance, and it is determined whether there is an occlusion between the offset point and the illuminated point. If there is no occlusion between the two points, the illumination calculation is performed on the illuminated point. If there is an occlusion between the two points, the illumination calculation is not performed, and the shadow rendering is performed on the illuminated point according to the calculation result.

[0023] like Figure 2 As shown, when rendering shadows based on parallel light, most of the time the parallel light rays H are set to be parallel to each other. However, in real life, parallel light sources have areas, and in reality, all parallel light rays are not parallel to each other. Therefore, the parallel light rays H that are parallel to each other pass through the obstruction G and illuminate the object only to generate a hard shadow area C and the left illuminated area A and the right illuminated area F on both sides. There is a very obvious light-dark dividing line between the hard shadow area C and the left illuminated area A and the right illuminated area F on both sides. The change process is very abrupt, which is quite different from the actual situation. Therefore, Figure 3 The embodiment shown in the figure disturbs the parallel light beams so that they produce an angle deviation within a certain range. The specific method is that when rendering, a beam of parallel light directed toward D is selected as the central axis, the cone angle variation range is set to α, and multiple cone angle sampling is performed to obtain the cone angle sampling direction L. In this way, each beam of parallel light H can have a certain angle variation and area, which is convenient for fitting the actual parallel light and subsequently generating a soft shadow effect. Figure 4 As shown in the figure, when each beam of parallel light is sampled at a cone angle and passes through the occluder G to illuminate the object, five areas are generated. The area where the parallel light H is completely blocked by the occluder G and cannot reach is the hard shadow area C. The left side of the hard shadow area C is the left soft shadow area B, and the right side of the hard shadow area C is the right soft shadow area E. Part of the parallel light H in the soft shadow area is not blocked by the occluder and reaches the area, while the other part of the parallel light H is blocked by the occluder G and cannot reach the area.

[0024] The left soft shadow area B is provided with a left illuminated area A on the left, and the right soft shadow area E forms a right illuminated area F on the right. Parallel light rays H can all reach the generated illuminated area. The soft shadow area is a transition zone between the hard shadow area and the illuminated area, and there is a certain light and dark change. The soft shadow drawing is generated in this way, and the shadow rendering is generated, so that the rendering obtained in this way is more realistic and close to the actual situation.

Claims

1. A method for drawing soft shadows of directional light, characterized in that: include S1 establishes a spatial coordinate system with the direction of parallel light as the positive direction of the Z axis and obtains a transformation matrix; S2 sets the angle range and samples a new direction centered on the direction of the parallel light; S3 uses the conversion matrix to replace the sampling direction to the world space and replace the original parallel light direction; S4 determines whether there is any occlusion between the sampling direction and the illuminated point to complete the soft shadow drawing.

2. A method for drawing soft shadows of directional light according to claim 1, characterized in that: In step S1, the parallel light direction D is determined and a local coordinate system is established with the unit vector of the parallel light direction D as the positive coordinate of the Z axis of the spatial coordinate system. Set vector D=(a,b,c) and set Z=D, then set X=(-c,0,a) and set the variable sign to +1 or -1 according to the positive or negative value of c, that is, sign=1 when c is greater than 0, and sign=-1 when c<0; then set p=-1 / (sign+c), q=a*b*p, and calculate vector X = (1+sign*a*a*p,sign*q, -sign*a), Y = (q,sign+b*b*p, -b).

3. A method for drawing soft shadows of directional light according to claim 1 or 2, characterized in that: In step S1, let matrix N=(X, Y, Z), transpose N to obtain matrix M, let vector D=(a, b, c), then a and b are the first two components of direction D, and p and q are two temporary variables.

4. The method for drawing soft shadows of directional light according to claim 2, characterized in that: In step S2, in the local coordinate system, the cone angle range α is set with the parallel light direction D as the central axis, a direction is selected within the cone angle range, and random numbers e1 and e2 uniformly distributed between 0 and 1 are randomly selected, and the azimuth angle phi=2*e1, and e2 is used as an interpolation factor to interpolate between cos(α) and 1 to obtain cos(theta), where theta is the angle between the direction and the local coordinate axis Z axis, and finally the sampling direction L=(sin(theta)cos(phi), sin(theta)sin(phi), cos(theta)) within the cone angle is obtained.

5. The method for drawing soft shadows of directional light according to claim 1, characterized in that: In step S3, the direction L obtained after cone angle sampling is converted into the world space through the transformation matrix M to obtain L', which is calculated as L'= M*L, and the original parallel light direction D is replaced by L'.

6. A method for drawing soft shadows of directional light according to claim 1 or 5, characterized in that: In the step S4, an illuminated point is selected, and an offset point is obtained by offsetting the illuminated point in the L' direction by an infinite distance, and it is determined whether there is any occlusion between the offset point and the illuminated point. If there is no occlusion between the two points, illumination calculation is performed on the illuminated point. If there is occlusion between the two points, illumination calculation is not performed, and shadow rendering is performed on the illuminated point according to the calculation result.

7. The method for drawing soft shadows of directional light according to claim 5, characterized in that: After the parallel light is sampled at the cone angle, the parallel light forms an illumination area within the cone angle range α. The parallel light with the illumination area passes through the obstruction and generates a hard shadow area on the illuminated object. No parallel light reaches the area. Soft shadow area, where some parallel light reaches but some parallel light cannot reach; Illuminates an area that all directional lights can reach.

8. A method for drawing soft shadows of directional light according to claim 5 or 7, characterized in that: After a certain beam of parallel light is selected in step S2, different angle sampling methods can be used to disturb the direction of the parallel light to perform soft shadow drawing.

Citation Information

Patent Citations

  • Linear Shading Map Method for Depixelated Contour Reconstruction

    CN104933754B