Soft shadow drawing method for spotlight
Patent Information
- Application Number
- CN202310916086.1
- 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
The prior art cannot effectively draw the soft shadow effect of the spotlight, resulting in unreal shadow drawing.
Establish a spatial coordinate system with the centered light light, obtain the conversion matrix, set the consecutive light lamp to the geometric shape, random sampling to obtain sampling points, and replace the sampling point in the space coordinate by the conversion matrix to determine whether the sampling point and the illumination point are There is a soft drawing of the shadow of the spotlight.
The light and dark changes of the shadow are realized, the true level of shadow drawing is increased, and the authenticity of the consecration effect of the consecration of the concentration light in the light tracking rendering is enhanced.
Smart Images

Figure CN119379891A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of shadow drawing, and in particular to a method for drawing soft shadows of a spotlight. Background Art
[0002] Realistic rendering technology based on ray tracing is widely used in fields such as film, television and games. Rendering technology simulates the propagation of light in the real world through computer means, thereby producing realistic picture effects. The simulation of light sources is a key link in rendering technology. Different light sources will produce different lighting ranges, light brightness, and shadows when shining on objects. The light and dark changes of shadows are crucial to improving the sense of reality. Spotlights are a common light source. Existing technologies usually describe the position, direction and range of the light source to calculate the lighting of objects in the virtual scene. Since the lighting range parameters are not related to this patent, they are no longer marked here. In real life, all objects have areas. Therefore, the assumption that the spotlight is described as an infinitely small point will cause the rendering effect to be unrealistic, which is also the reason why the spotlight in the existing technology will cause hard shadows. How to draw a more realistic shadow effect is an urgent problem to be solved.
[0003] Chinese patent document CN104103092A discloses "a method for implementing real-time dynamic shadows based on spotlights". The method mainly includes: a. Traversing the list of visible objects in the scene, only rendering the visible or partially visible objects in the scene; b. When rendering the scene in the light space, obtaining the depth map of all pixels projected closest to the light source; c. When rendering the scene normally, comparing the depth value of the new position of the pixel obtained by converting the camera space to the light space. When the depth value of the new position of the pixel is greater than the depth map, the pixel is in the shadow; then mixing the shadow with the scene color and projecting it onto the screen. Further, the step b specifically includes: b1. When rendering the scene by placing the camera at the light source position, construct a light space; b2. In the light space, convert the world position in the light space into the cone projection space, and normalize it to obtain the depth map in the projection space; b3. When rendering the scene normally, convert the pixels U and V based on the screen space into world coordinates, and then convert them into the light space to obtain the depth value of the new position of the pixel in the space. However, this patent only includes the drawing of hard shadow parts, and cannot draw the brightness changes of the shadow parts, and thus cannot draw a more realistic shadow effect. Summary of the invention
[0004] The present invention mainly solves the technical problem that the original shadow drawing is unrealistic, and provides a soft shadow drawing method for spotlights. This patent takes the light source as the center and the illumination direction as the Z-axis direction to establish a spatial coordinate system. According to the established spatial coordinate system, a conversion matrix is obtained, and the spotlight is set to a geometric shape. Then, the sampling points in the spotlight area are obtained by a sampling method of the corresponding shape. The sampling points are converted to the spatial coordinate system through the conversion matrix and replace the original spotlight position. The illuminated point and the sampling point are connected to determine the area to which the illuminated point belongs. Through this solution, the light and dark changes of the shadow can be clearly drawn, and the authenticity of the shadow drawing can be improved.
[0005] The above technical problem of the present invention is mainly solved by the following technical solution: The present invention comprises S1 establishing a space coordinate with the spotlight as the center and obtaining a conversion matrix; S2 randomly samples and obtains the coordinates of the sampling points on the spotlight; S3 replaces the sampling point into the space coordinates through the transformation matrix instead of the original spotlight coordinates; S4 determines whether there is any occlusion between the sampling point and the illuminated point to complete the spotlight shadow drawing.
[0006] In the existing shadow drawing process, a spotlight is generally defined as a point, and light is emitted outward from the spotlight point. The light is affected by the obstruction to form a complete shadow area (i.e., a hard shadow area) and an illuminated area on the illuminated object. However, in actual situations, a spotlight generally has an area. After passing through the obstruction, the light will form an illuminated area and a shadow area with light and dark changes on the illuminated object. The brighter shadow area can be illuminated by part of the light emitted by the spotlight, and part of the light emitted by the spotlight is blocked by the obstruction. This part of the brighter shadow area is the soft shadow area. The shadow area between the illuminated object and the spotlight that is completely blocked by the obstruction is the hard shadow area, and the remaining area that is not completely blocked by the obstruction is the illuminated area. Therefore, in order to better fit the effect of shadows produced in real situations and make the shadows produced more realistic, this patent sets the spotlight point as a region with area and shape and obtains a transformation matrix, establishes the region in a spatial coordinate system and samples sampling points of corresponding shapes according to the shape of the spotlight, converts the sampling point coordinates to the world space through the transformation matrix to obtain the conversion point coordinates, and replaces the original spotlight position with the conversion point, determines whether there is an obstruction between the conversion point and the illuminated object, performs lighting calculations, and divides the illuminated object into areas to form shadow drawing.
[0007] Preferably, in step S1, the position L and the direction D of the spotlight are determined, and a spatial coordinate system is established with the unit vector of the spotlight direction D as the Z-axis direction, and vector D=(a,b,c) and Z=D are set, and then X=(-c,0,a), and the Y coordinate is calculated by vector cross multiplication Y=cross(X,Z); finally, X,Y,Z are normalized to obtain the coordinates X',Y',Z', and the transformation matrix M = (X',Y',Z'). Establishing a coordinate system with the spotlight as the origin of the spatial coordinate system and obtaining the transformation matrix by normalization can facilitate a clearer determination of the position of the spotlight and related sampling points, and facilitate subsequent calculations to distinguish shadow areas.
[0008] Preferably, in step S2, the spotlight is set to be disc-shaped, with a radius of R, and a sampling point P is randomly obtained from the disc, and two random numbers e1 and e2 uniformly distributed between 0 and 1 are taken, and the azimuth angle phi=2*e1, and the distance r between the sampling point and the center of the circle is equal to the square root of e2, then the coordinates of the sampling point p are (cos(phi)*r*R, sin(phi)*r*R, 0), and disc sampling is implemented. It is more convenient and accurate to determine the coordinates of the sampling points in the disc-shaped spotlight area by combining polar coordinates and disc sampling, and the disc-shaped spotlight area is more accurately divided by the sampling point coordinates, thereby improving the accuracy of the subsequent connection between the spotlight and the illuminated point, and thus improving the accuracy of the shadow area division.
[0009] Preferably, in step S3, the coordinates of the sampling point P are replaced into the spatial coordinate system through the conversion matrix M and the coordinates P' are obtained, and the original spotlight position L is replaced by P'. During the conversion, the matrix M and the three-dimensional point p are multiplied, that is, P'= M * P, and P' is used to replace the original spotlight position L. The coordinate position of the initial spotlight can be replaced into a more accurate representation in the spatial coordinate system through the conversion matrix, which is convenient for the subsequent calculation of the shadow area.
[0010] Preferably, in step S4, the area where the illuminated point is completely blocked forms a hard shadow area, the area where the illuminated point has a blocked area is a soft shadow area, and the area where the illuminated point is not blocked is an illuminated area. The area on the illuminated object that is not illuminated by any spotlight is a hard shadow area, the area where some spotlights are illuminated and some spotlights are blocked by obstructions and cannot reach is a soft shadow area, the area where all light can reach is an illuminated area, and there is an obvious brightness change process from the illuminated area to the soft shadow area to the hard shadow area.
[0011] Preferably, in step S4, any coordinate S of the illuminated point is selected, S and P' are connected into a line segment, and illumination calculation is performed after the line segment is connected, and the illuminated point S is divided into corresponding areas according to the illumination calculation. The illumination calculation method is to multiply the brightness of the light source reaching the illuminated point by the proportion of the light reflected by the illuminated point to obtain the final brightness of the illuminated point. Whether the spotlight sampling point and the illuminated point can be connected into a line segment is used as a judgment condition for whether illumination calculation can be performed. If the line segment cannot be connected, it means that the illuminated point is completely blocked by the obstruction and is in a hard shadow area, so illumination calculation cannot be performed.
[0012] Preferably, the left and right sides of the hard shadow area are soft shadow areas, and the side of the soft shadow area that is not connected to the hard shadow area is the illuminated area. The soft shadow area is a transition zone between the hard shadow area and the illuminated area. The soft shadow area tends to gradually darken as it approaches the hard shadow area, and the soft shadow area tends to gradually brighten as it approaches the illuminated area.
[0013] Preferably, in step S2, the spotlight can be set to other shapes, and the corresponding sampling points can be sampled in a manner adapted to the shape. This patent mentions setting the spotlight to a disc shape and obtaining sampling points in the spotlight area through disc sampling. The shape of the spotlight area does not need to be deliberately limited. The spotlight area is set to the required shape according to actual needs, and the sampling points in the spotlight area are also deliberately obtained through the sampling method corresponding to the shape to complete subsequent calculations.
[0014] The beneficial effects of the present invention are: defining a spotlight as a geometric shape and using a sampling method of the corresponding shape to obtain a sampling point on the spotlight in a spatial coordinate system, judging whether there is an occlusion between the two points based on the line segment connecting the sampling point and the illuminated point, and drawing soft shadows, hard shadows, and illuminated areas based on the occlusion results. Through the processing of the above technical point combination, the authenticity of the soft shadow rendering effect of the spotlight can be improved in ray tracing rendering. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 The present invention is a flowchart of a method for drawing soft shadows of a spotlight.
[0016] Figure 2 It is a principle diagram of a spotlight with an area generating a shadow according to the present invention.
[0017] Figure 3 This is a schematic diagram of the existing spotlight generating shadows.
[0018] In the figure, A. illuminated area on the left, B. soft shadow area on the left, C. hard shadow area, D spotlight direction, E. soft shadow area on the right, F. illuminated area on the right, G obstruction, H. spotlight light, L spotlight position. DETAILED DESCRIPTION
[0019] The technical solution of the present invention is further specifically described below through embodiments and in conjunction with the accompanying drawings.
[0020] Embodiment: A method for drawing soft shadows of a spotlight in this embodiment is as follows: Figure 1 As shown, S1 establishes the space coordinates with the spotlight as the center and obtains the transformation matrix; S2 randomly samples and obtains the coordinates of the sampling points on the spotlight; S3 replaces the sampling point into the space coordinates through the transformation matrix instead of the original spotlight coordinates; S4 determines whether there is any occlusion between the sampling point and the illuminated point to complete the spotlight shadow drawing.
[0021] In the conventional rendering process, the light source point is usually simplified to a point coordinate, and the shadow formed by the point light source on different objects is calculated and rendered. In the rendered picture, there are only two types of completely dark shadow areas and illuminated areas. However, in real life, all objects have areas. Therefore, when a light source such as a spotlight illuminates an object and forms a shadow area with light and dark changes around the illuminated object, the assumption that the spotlight is described as an infinitely small point will cause the rendering effect to be unrealistic. This is also the reason why the spotlight only generates hard shadows in the existing rendering technology. If the assumption of the point spotlight is changed, that is, the spotlight as a light source is not an infinitely small point, but an area with an area like the real world, then the spotlight can generate soft shadow areas and hard shadow areas. The combination of soft shadow areas, hard shadow areas and illuminated areas can render a more realistic spotlight shadow effect. The method of this patent can generate realistic soft shadows on the basis of the original hard shadows, thereby improving the texture of the rendered shadows. In step S1, the position L and the direction D of the spotlight are determined, and the spatial coordinate system is established with the unit vector of the spotlight direction D as the Z axis direction. Set the vector D=(a,b,c) and let Z=D, then set X=(-c,0,a), 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 transformation matrix M = (X',Y',Z'). In step S2, set the spotlight to be a disk with a disk radius of R, randomly obtain the sampling point P from the disk, take two random numbers e1 and e2 uniformly distributed between 0 and 1, set the azimuth phi=2*e1, and the distance r between the sampling point and the center of the circle is equal to the square root of e2, then the coordinates of the sampling point p are (cos(phi)*r*R,sin(phi)*r*R,0), realizing disk sampling. The spotlight can also be set to other shapes, and the corresponding sampling points can be sampled in a manner that is compatible with the shape. In step S3, the coordinates of the sampling point P are replaced in the spatial coordinate system through the conversion matrix M and the coordinates P' are obtained. The original spotlight position L is replaced by P'. During the conversion, the matrix M and the three-dimensional point p are multiplied, that is, P'= M * P, and the original spotlight position L is replaced by P'. In step S4, the area where the illuminated point is completely blocked forms a hard shadow area, the area where the illuminated point has a blocked area is a soft shadow area, and the area where the illuminated point is not blocked is an illuminated area. The left and right sides of the hard shadow area are soft shadow areas, and the side of the soft shadow area that is not connected to the hard shadow area is the illuminated area. Finally, the coordinates S of any illuminated point are selected, S and P' are connected into a line segment, and the illumination calculation is performed after the line segments are connected. According to the illumination calculation, the illuminated point S is divided into the corresponding area.
[0022] like Figure 2 and Figure 3 As shown, Figure 2In the figure, the spotlight position L is used as a point light source. During the transmission process along the spotlight direction D, part of the light is blocked by the obstruction G, forming a hard shadow area C on the illuminated object. The two sides of the hard shadow area C are the illuminated areas formed by the illumination of the spotlight position L on the illuminated object. The left side is the left illuminated area A and the right side is the right illuminated area F. The illuminated area is directly connected to the hard shadow area C, and there is an obvious light-dark dividing line between the left illuminated area A and the right illuminated area F and the hard shadow area C. However, this situation is too idealized, and there is an obvious transition interval between the bright area and the shadow area in real life. The shadow effect diagram rendered in this way is quite different from the display, and the rendering result is not realistic enough, and the presented picture effect is poor. If Figure 3 According to the method of the present invention, for example, the spotlight is assumed to be a disk, the position of the spotlight is L, the direction of the spotlight is D, and the area formed by the light H emitted by the spotlight that cannot reach the illuminated object after passing through the shield G is the hard shadow area C. The area formed by the light H emitted by the spotlight that can reach the illuminated object after passing through the shield G includes the left illuminated area A and the right illuminated area F. Since the spotlight itself has an area, there is an area between the hard shadow area C and the illuminated area. The lines connecting the points in this area and some of the sampling points on the spotlight will be blocked by the shield G, so the illumination calculation cannot be performed. The lines connecting the remaining points and some of the sampling points on the spotlight will not be blocked by the shield G, and normal illumination calculation can be performed. Therefore, this area is the transition area between the hard shadow area C and the illuminated area, that is, the soft shadow area. There is a left soft shadow area B between the left illuminated area A and the hard shadow area C, and there is a right soft shadow area E between the right illuminated area F and the hard shadow area C. Then on the illuminated object, the area will be divided into three segments, and these areas will have blurred light and dark boundaries, which will produce a soft shadow effect and improve the realism of the rendering.
Claims
1. A method for drawing soft shadows of a spotlight, characterized in that: Steps include S1 establishes the spatial coordinates with the spotlight as the center and obtains the transformation matrix; S2 randomly samples and obtains the coordinates of the sampling points on the spotlight; S3 replaces the sampling point into the space coordinates through the transformation matrix instead of the original spotlight coordinates; S4 determines whether there is any occlusion between the sampling point and the illuminated point to complete the spotlight shadow drawing.
2. A method for drawing soft shadows of a spotlight according to claim 1, characterized in that: In step S1, the position L of the spotlight and the direction D of the spotlight are determined, and a spatial coordinate system is established with the unit vector of the spotlight direction D as the Z-axis direction. Let vector D=(a,b,c) and let Z=D, then let X=(-c,0,a), and calculate the Y coordinate by vector cross multiplication Y=cross(X,Z); finally, X,Y,Z are normalized to obtain coordinates X',Y',Z', and let the transformation matrix M = (X',Y',Z').
3. A method for drawing soft shadows of a spotlight according to claim 1 or 2, characterized in that: In step S2, the spotlight is assumed to be in the shape of a disk with a disk radius of R, a sampling point P is randomly obtained from the disk, two random numbers e1 and e2 uniformly distributed between 0 and 1 are taken, and the azimuth angle phi=2*e1, and the distance r between the sampling point and the center of the circle is equal to the square root of e2, then the coordinates of the sampling point p are (cos(phi)*r*R, sin(phi)*r*R, 0), thereby realizing disk sampling.
4. The method for drawing soft shadows of a spotlight according to claim 2, characterized in that: In step S3, the coordinates of the sampling point P are replaced in the space coordinate system through the conversion matrix M to obtain the coordinates P', and the original spotlight position L is replaced by P'.
5. A method for drawing soft shadows of a spotlight according to claim 2 or 4, characterized in that: In step S4, the area where the illuminated point is completely blocked forms a hard shadow area, the area where the illuminated point is blocked forms a soft shadow area, and the area where the illuminated point is not blocked forms an illuminated area.
6. A method for drawing soft shadows of a spotlight according to claim 5, characterized in that: In the step S4, any coordinate S of the illuminated point is selected, S and P' are connected into a line segment, illumination calculation is performed after the line segments are connected, and the illuminated point S is divided into corresponding areas according to the illumination calculation.
7. A method for drawing soft shadows of a spotlight according to claim 5 or 6, characterized in that: The left and right sides of the hard shadow area are soft shadow areas, and the side of the soft shadow area that is not connected to the hard shadow area is a bright area.
8. The method for drawing soft shadows of a spotlight according to claim 1, characterized in that: In step S2, the spotlight may be set to other shapes, and corresponding sampling points may be sampled in a manner adapted to the shape.
Citation Information
Patent Citations
Real-time dynamic shadowing realization method based on projector lamp
CN104103092A