Shadow generation method, image rendering method, graphics processor and system
By determining the distance between the intersection point of the initial light and the shadow light and the light source in the graphics processor and calculating the shadow intensity, the problem of difficulty in obtaining a soft shadow effect in the existing technology is solved, and real-life effects can be obtained under limited resources. Shadow effect.
Patent Information
- Application Number
- CN202310316112.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-28
- Publication Date
- 2024-10-01
AI Technical Summary
It is difficult to obtain realistic soft shadow effects with existing technologies without using a large amount of hardware and software resources.
Match the shadow of the target pixel by determining the initial light and shadow light emitted from the target pixel in the three-dimensional scene of the image to be rendered, determining its intersection with the opaque object, and calculating the shadow intensity based on the distance between the intersection and the light source. strength.
It achieves a certain degree of soft shadow effect without introducing a ray tracing system, reducing the consumption of hardware and software resources.
Smart Images

Figure CN118736097A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of graphics processors, and in particular to a shadow generation method, an image rendering method, a graphics processor and a system. Background Art
[0002] Ray tracing is a new technology in the image rendering process of the graphics processing unit (GPU). It is used to make the rendered pictures produce more realistic light and shadow effects. The ray tracing system can complete the shadow calculation very well, but the entire ray tracing system requires a lot of hardware and software resources, and the implementation difficulty and complexity are very high. In the GPU rendering pipeline without ray tracing, the current shadow calculation is mainly to convert the perspective to the direction of the light source, calculate the depth of all objects, judge the shadow of the object according to the depth, and then convert the perspective back to the normal rendering perspective. However, this method of calculating the shadow of each pixel according to the depth, so the shadows obtained are all hard shadows. Even if the shadow edges are filtered, it is still difficult to obtain a real soft shadow effect. That is, it is currently difficult to obtain a real soft shadow effect without using a lot of hardware and software resources. Summary of the invention
[0003] The purpose of the present disclosure is to provide a shadow generation method, an image rendering method, a graphics processor and a system, which solve the technical problem in the prior art that it is difficult to obtain a real soft shadow effect without using a large amount of hardware and software resources.
[0004] According to one aspect of the present disclosure, there is provided a shadow generation method, comprising:
[0005] In a three-dimensional scene of an image to be rendered, an initial light ray emitted from a target pixel point of the image to be rendered is determined, and it is determined whether the initial light ray hits an opaque object, and if so, an intersection point between the initial light ray and the first opaque object hit by the initial light ray is determined as a first intersection point;
[0006] For a light source in a three-dimensional scene, determine whether a shadow ray starting from a first intersection point and pointing to the light source hits an opaque object; if so, determine the intersection point between the shadow ray and the first opaque spatial object hit by the shadow ray as the second intersection point, and calculate the distance between the first intersection point and the second intersection point to match the shadow intensity of the first intersection point under the light source according to the distance;
[0007] The shadow intensity of the target pixel is determined according to the shadow intensity of the first intersection point under the light source.
[0008] In some embodiments, in the above shadow-based generation method, the shadow intensity of the first intersection under the light source is negatively correlated with the distance between the first intersection and the second intersection.
[0009] In some embodiments, in the above shadow generation method, determining the shadow intensity of the target pixel point according to the shadow intensity of the first intersection point under the light source includes the following steps:
[0010] The shadow intensity of the first intersection point under each light source is superimposed to obtain the shadow intensity of the target pixel point.
[0011] In some embodiments, in the above shadow-based generation method, determining whether the initial light hits an opaque object, and if so, determining the intersection of the initial light and the first opaque object hit by the initial light as the first intersection, includes the following steps:
[0012] According to the ray equation of the initial ray, the initial ray is intersected with each opaque object in the three-dimensional scene to determine whether the initial ray hits the opaque object. If so, the intersection point and the three-dimensional coordinates of the first opaque object hit by the initial ray are determined, and the intersection point is taken as the first intersection point;
[0013] For a light source in a three-dimensional scene, determining whether a shadow ray starting from a first intersection point and pointing to the light source hits an opaque object; if so, determining the intersection point of the shadow ray and the first opaque spatial object hit by the shadow ray as a second intersection point, including the following steps:
[0014] For a light source in the three-dimensional scene, determining a light equation of a shadow light starting from the first intersection point and pointing to the light source according to the three-dimensional coordinates of the first intersection point and the three-dimensional coordinates of the light source;
[0015] According to the light equation of the shadow ray, the intersection calculation is performed between the shadow ray and each opaque object in the three-dimensional scene to determine whether the shadow ray hits the opaque object. If so, the intersection point and the three-dimensional coordinates of the shadow ray and the first opaque spatial object hit by the shadow ray are determined, and the intersection point is used as the second intersection point.
[0016] In some embodiments, in the above shadow-based generation method, for a light source in a three-dimensional scene, determining a light equation of a shadow light starting from the first intersection and pointing to the light source according to the three-dimensional coordinates of the first intersection and the three-dimensional coordinates of the light source includes the following steps:
[0017] For a light source in a three-dimensional scene, the light equation of the shadow light starting from the first intersection point and pointing to the light source is: X=X1+mt, Y=Y1+nt, Z=Z1+pt;
[0018] Where (X1, Y1, Z1) is the three-dimensional coordinate of the first intersection point, m, n and p are the direction vectors of the shadow light on the X-axis, Y-axis and Z-axis respectively, t is the light distance, and (X, Y, Z) is the three-dimensional coordinate of the point on the shadow light with a light distance of t;
[0019] According to the three-dimensional coordinates of the light source (X0, Y0, Z0), the light distance t between the first intersection point and the light source is:
[0020]
[0021] Substitute the three-dimensional coordinates of the light source (X0, Y0, Z0) and the light distance t between the first intersection point and the light source into the light equation of the shadow light, and obtain the direction vectors m, n and p of the shadow light on the X-axis, Y-axis and Z-axis respectively: m = (X0-X1) / t, n = (Y0-Y1) / t, p = (Z0-Z1) / t, thereby solving the light equation of the shadow light.
[0022] In some embodiments, in the above shadow-based generation method, the light equation of the shadow light is: X=X1+mt, Y=Y1+nt, Z=Z1+pt; wherein (X1, Y1, Z1) are the three-dimensional coordinates of the first intersection point, m, n and p are the direction vectors of the shadow light on the X axis, Y axis and Z axis respectively, t is the light distance, and (X, Y, Z) are the three-dimensional coordinates of the point on the shadow light with a light distance of t;
[0023] The distance D between the first intersection point and the second intersection point can be calculated using any of the following formulas:
[0024] D = |X2–X1| / m;
[0025] D = |Y2–Y1| / n;
[0026] D = |Z2–Z1| / p;
[0027] Among them, (X1, Y1, Z1) are the three-dimensional coordinates of the first intersection, and (X2, Y2, Z2) are the three-dimensional coordinates of the second intersection.
[0028] In some embodiments, in the above shadow-based generation method, determining the intersection point between the initial light ray and the first opaque object it hits and its three-dimensional coordinates includes the following steps:
[0029] In the process of calculating the intersection of the initial light ray and each opaque object in the three-dimensional scene, determining the intersection points and the three-dimensional coordinates of each intersecting opaque object of the initial light ray;
[0030] According to the three-dimensional coordinates of the target pixel point and the three-dimensional coordinates of the intersection points of the initial light ray and each of the intersecting opaque objects, determine the intersection point with the shortest distance from the target pixel point among the intersection points of the initial light ray and each of the intersecting opaque objects, as the intersection point of the initial light ray and the first opaque object hit by the initial light ray;
[0031] Determining the intersection point of the shadow ray with the first opaque space object it hits and its 3D coordinates includes the following steps:
[0032] In the process of calculating the intersection of the shadow ray and each opaque object in the three-dimensional scene, determining the intersection points and the three-dimensional coordinates of each intersecting opaque object of the shadow ray;
[0033] According to the three-dimensional coordinates of the first intersection point and the three-dimensional coordinates of the intersection points of the shadow ray and each intersecting opaque object, the intersection point with the shortest distance from the first intersection point among the intersection points of the shadow ray and each intersecting opaque object is determined as the intersection point of the shadow ray and the first opaque spatial object it hits.
[0034] In some embodiments, in the above shadow generation method, the distance D between the first intersection point and the second intersection point is calculated as follows:
[0035]
[0036] Among them, (X1, Y1, Z1) are the three-dimensional coordinates of the first intersection, and (X2, Y2, Z2) are the three-dimensional coordinates of the second intersection.
[0037] In some embodiments, the above shadow generation method further includes:
[0038] Perform denoising on the shadow intensity of the target pixel.
[0039] In some embodiments, in the above shadow-based generation method, the number of initial light rays emitted from a pixel point of the image to be rendered is less than or equal to a preset threshold.
[0040] In some embodiments, in the above shadow-based generation method, the light source is a point light source, a line light source or a surface light source.
[0041] In some embodiments, in the above shadow-based generation method, the number of shadow rays starting from a first intersection point and pointing to a light source is 1.
[0042] According to another aspect of the present disclosure, there is provided an image rendering method, comprising:
[0043] Obtaining the shadow intensity of each pixel in the image to be rendered by the shadow generation method of any of the above embodiments;
[0044] The color of each pixel in the image to be rendered is calculated through the rendering pipeline; the color of each pixel includes chromaticity and brightness;
[0045] According to the shadow intensity of each pixel, the brightness of each pixel is adjusted to obtain the final color of each pixel.
[0046] According to another aspect of the present disclosure, a graphics processor is provided, comprising:
[0047] A shadow generation module, configured to implement the shadow generation method of any of the above embodiments to obtain the shadow intensity of each pixel in the image to be rendered;
[0048] A rendering module is configured to calculate the color of each pixel of the image to be rendered through a rendering pipeline; the color of each pixel includes chromaticity and brightness;
[0049] The adjustment module is configured to adjust the brightness of each pixel according to the shadow intensity of each pixel to obtain the final color of each pixel.
[0050] According to another aspect of the present disclosure, a graphics processing system is provided, comprising a graphics processor according to any one of the above embodiments.
[0051] According to another aspect of the present disclosure, an electronic component is provided, comprising the graphics processing system of any one of the above embodiments.
[0052] According to another aspect of the present disclosure, an electronic device is provided, comprising the electronic component of any one of the above embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Figure 1 A schematic diagram of a flow chart of a shadow generation method provided by an embodiment of the present disclosure;
[0054] Figure 2 A schematic diagram of the intersection of a shadow ray and an object in a three-dimensional scene provided by an embodiment of the present disclosure;
[0055] Figure 3 A schematic diagram of the intersection of an initial light ray and an object in a three-dimensional scene provided by one embodiment of the present disclosure;
[0056] Figure 4 A schematic diagram of the intersection of a shadow ray corresponding to a line light source and an object in a three-dimensional scene provided by an embodiment of the present disclosure;
[0057] Figure 5 A flowchart of an image rendering method provided by an embodiment of the present disclosure;
[0058] Figure 6 Another schematic diagram of a flow chart of an image rendering method provided by an embodiment of the present disclosure;
[0059] Figure 7 A schematic diagram of the structure of a graphics processor provided by one embodiment of the present disclosure. DETAILED DESCRIPTION
[0060] Before introducing the embodiments of the present disclosure, it should be noted that:
[0061] Some embodiments of the present disclosure are described as processing flows. Although the various operation steps of the flow may be given sequential step numbers, the operation steps therein may be implemented in parallel, concurrently or simultaneously.
[0062] In the embodiments of the present disclosure, the terms "first", "second", etc. may be used to describe various features, but these features should not be limited by these terms. These terms are used only to distinguish one feature from another.
[0063] The term “and / or” may be used in embodiments of the present disclosure. “And / or” includes any and all combinations of one or more of the associated features listed.
[0064] It should be understood that when describing the connection or communication relationship between two components, unless it is explicitly stated that the two components are directly connected or directly communicating, the connection or communication between the two components can be understood as direct connection or communication, or as indirect connection or communication through an intermediate component.
[0065] In order to make the technical solutions and advantages of the embodiments of the present disclosure more clearly understood, the exemplary embodiments of the present disclosure are further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than an exhaustive list of all the embodiments. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.
[0066] The purpose of the present disclosure is to provide a shadow generation method, an image rendering method, a graphics processor and a system. The shadow generation method includes: in a three-dimensional scene of an image to be rendered, determining an initial light ray emitted from a target pixel point of the image to be rendered, and judging whether the initial light ray hits an opaque object, and if so, determining the intersection point of the initial light ray and the first opaque object hit by the initial light ray as a first intersection point; for a light source in the three-dimensional scene, judging whether a shadow light ray starting from the first intersection point and pointing to the light source hits an opaque object; if so, determining the intersection point of the shadow light ray and the first opaque spatial object hit by the initial light ray as a second intersection point, and calculating the distance between the first intersection point and the second intersection point to match the shadow intensity of the first intersection point under the light source according to the distance; and determining the shadow intensity of the target pixel point according to the shadow intensity of the first intersection point under the light source.
[0067] In this solution, a ray tracing system is not introduced. Instead, the distance between the intersection point (first intersection point) of the light emitted by the pixel and the scene and the light source obstruction is calculated to directly match the corresponding shadow intensity, so that a certain degree of soft shadow effect is finally obtained. In other words, a real soft shadow effect is obtained to a certain extent without using a large amount of hardware and software resources.
[0068] An embodiment of the present disclosure provides a shadow generation method, such as Figure 1 As shown, including:
[0069] Step S110: in the three-dimensional scene of the image to be rendered, determine the initial light emitted from the target pixel point of the image to be rendered, and judge whether the initial light hits an opaque object. If so, determine the intersection point of the initial light and the first opaque object hit by the initial light as the first intersection point;
[0070] Step S120: for a light source in the three-dimensional scene, determine whether a shadow ray starting from a first intersection point and pointing to the light source hits an opaque object; if so, determine the intersection point between the shadow ray and the first opaque spatial object hit by the shadow ray as the second intersection point, and calculate the distance between the first intersection point and the second intersection point to match the shadow intensity of the first intersection point under the light source according to the distance;
[0071] Step S130: determining the shadow intensity of the target pixel point according to the shadow intensity of the first intersection point under the light source.
[0072] It can be understood that the first opaque object hit by the initial light is the nearest unobstructed object that the human eye sees when looking at the target pixel (under the perspective corresponding to the initial light) or that the camera captures when shooting the target pixel (under the perspective corresponding to the initial light). The intersection point (first intersection point) between the initial light and the first opaque object hit by it can be understood as a point that the human eye sees when looking at the target pixel or that the camera captures when shooting the target pixel (also the intersection point of the initial light and the three-dimensional scene). Therefore, the shadow intensity of the target pixel can be obtained according to the shadow intensity of the intersection point (first intersection point) between the initial light and the first opaque object hit by it. Whether the first intersection point is in the shadow area of the light source depends on whether there is an obstruction between the first intersection point and the light source (i.e., whether the shadow light starting from the first intersection point and pointing to the light source hits the opaque object). When the first intersection point is in the shadow area of the light source, the shadow intensity of the first intersection point under the light source depends on the size of the obstruction distance (the distance between the first intersection point and the second intersection point). Different occlusion distances (the distance between the first intersection point and the second intersection point) can be matched to obtain different shadow intensities, thereby obtaining a certain degree of soft shadow effect.
[0073] In the above steps, the steps of light generation and shadow intensity matching are implemented by software, and the other steps are implemented by hardware.
[0074] The three-dimensional scene of the image to be rendered refers to a scene containing a three-dimensional model of the image to be rendered, such as a game scene, an animation scene, etc. The three-dimensional scene includes all geometric objects such as light sources, obstructions, and scene objects.
[0075] In some embodiments, the shadow intensity of the first intersection under the light source is negatively correlated with the distance between the first intersection and the second intersection.
[0076] That is to say, the matching rule of the shadow intensity of the first intersection under the light source is: the smaller the distance between the first intersection and the second intersection, the greater the shadow intensity of the first intersection under the corresponding light source; the greater the distance between the first intersection and the second intersection, the smaller the shadow intensity of the first intersection under the corresponding light source.
[0077] It can be understood that the distance between the first intersection and the second intersection indicates the degree of obstruction of the first intersection by the opaque object (obstruction). The smaller the distance, the greater the degree of obstruction of the first intersection by the opaque object (obstruction), and the greater the shadow intensity. The larger the distance, the smaller the degree of obstruction of the first intersection by the opaque object (obstruction), and the smaller the shadow intensity.
[0078] Among them, the specific correlation (such as correlation coefficient) between the shadow intensity of the first intersection under the light source and the distance between the first intersection and the second intersection can be specifically set as needed. The initial correlation between the shadow intensity and the occlusion distance (the distance between the first intersection and the second intersection) can be set by software, and the corresponding shadow intensity is matched according to the initial correlation in step S120. After the final rendering result of the image to be rendered is obtained by combining the shadow intensity through the rendering pipeline, the software can also continuously debug the correlation between the shadow intensity and the occlusion distance (the distance between the first intersection and the second intersection) according to the rendering result, so that the shadow effect in the final rendering result is constantly close to the real soft shadow effect.
[0079] In step S120, when the shadow light starting from the first intersection point and pointing to a light source does not hit the opaque object, it is determined that the first intersection point is not in the shadow area of the light source, that is, the shadow intensity under the light source is 0.
[0080] like Figure 2 As shown, points A, B, and C are the intersections of the initial light rays emitted by the three pixel points and the first opaque spatial object they hit, that is, points A, B, and C are the three first intersections corresponding to the three pixel points. Among them, the shadow light from point A to the light source does not hit the opaque object (that is, there is no obstruction between point A and the light source), and the shadow light from points B and C to the light source both hit the opaque object (that is, there is an obstruction between points B and C and the light source), so points B and C are shadows. Among them, since the distance from point C to the first opaque spatial object it hits is longer, the shadow of point C is lighter, and the distance from point B to the first opaque spatial object it hits is shorter, so the shadow of point B is darker.
[0081] In some embodiments, in step S110, it is determined whether the initial light hits an opaque object. If so, the intersection point between the initial light and the first opaque object hit by the initial light is determined as the first intersection point, including the following steps:
[0082] According to the ray equation of the initial ray, the initial ray is intersected with each opaque object in the three-dimensional scene to determine whether the initial ray hits the opaque object. If so, the intersection point and the three-dimensional coordinates of the first opaque object hit by the initial ray are determined, and the intersection point is taken as the first intersection point;
[0083] In step S120, for a light source in the three-dimensional scene, it is determined whether a shadow ray starting from the first intersection point and pointing to the light source hits an opaque object; if so, the intersection point of the shadow ray and the first opaque spatial object hit by the shadow ray is determined as the second intersection point, including the following steps:
[0084] For a light source in the three-dimensional scene, determining a light equation of a shadow light starting from the first intersection point and pointing to the light source according to the three-dimensional coordinates of the first intersection point and the three-dimensional coordinates of the light source;
[0085] According to the light equation of the shadow ray, the intersection calculation is performed between the shadow ray and each opaque object in the three-dimensional scene to determine whether the shadow ray hits the opaque object. If so, the intersection point and the three-dimensional coordinates of the shadow ray and the first opaque spatial object hit by the shadow ray are determined, and the intersection point is used as the second intersection point.
[0086] It is understood that if a ray intersects a geometric object, the ray is considered to hit the geometric object.
[0087] Among them, the light equation of the initial light emitted from the target pixel point of the image to be rendered is determined when the initial light is generated, and the spatial geometric equation of each opaque object in the three-dimensional scene is determined when the three-dimensional scene is constructed. Therefore, according to the light equation of the initial light and the spatial geometric equation of each opaque object, the initial light and each opaque object in the three-dimensional scene can be intersected and calculated to determine whether the initial light hits the opaque object. The initial light can also be intersected with the primitives (such as triangle primitives) that constitute the opaque object to determine whether the initial light hits the opaque object. Specifically, the intersection calculation can adopt Monte Carlo and other intersection algorithms. For example, in the intersection calculation process of the initial light and the triangle primitive, the intersection point of the light and the plane where the triangle primitive is located is usually calculated first, and then it is determined whether the intersection point is on the triangle primitive. If it is on the triangle primitive, it means that it is indeed intersected. Therefore, in the intersection calculation process, the intersection point and the three-dimensional coordinates of each intersecting opaque object of the initial light are also obtained at the same time.
[0088] Similarly, when judging whether a shadow ray starting from the first intersection point and pointing to a light source hits an opaque object, the ray equation of the shadow ray starting from the first intersection point and pointing to the light source is first determined, and then, based on the ray equation of the shadow ray, the shadow ray is intersected with each opaque object in the three-dimensional scene to judge whether the shadow ray hits the opaque object. During the intersection calculation process, the intersection points and three-dimensional coordinates of the shadow ray and each intersecting opaque object are also obtained.
[0089] In some embodiments, in the above scenario where the intersection calculation is used to determine whether the shadow ray intersects with the opaque object, for a light source in the three-dimensional scene, according to the three-dimensional coordinates of the first intersection point and the three-dimensional coordinates of the light source, determining the ray equation of the shadow ray starting from the first intersection point and pointing to the light source includes the following steps:
[0090] For a light source in a three-dimensional scene, the light equation of the shadow light starting from the first intersection point and pointing to the light source is: X=X1+mt, Y=Y1+nt, Z=Z1+pt;
[0091] Where (X1, Y1, Z1) is the three-dimensional coordinate of the first intersection point, m, n and p are the direction vectors of the shadow light on the X-axis, Y-axis and Z-axis respectively, t is the light distance, and (X, Y, Z) is the three-dimensional coordinate of the point on the shadow light with a light distance of t;
[0092] According to the three-dimensional coordinates of the light source (X0, Y0, Z0), the light distance t between the first intersection point and the light source is:
[0093]
[0094] Substitute the three-dimensional coordinates of the light source (X0, Y0, Z0) and the light distance t between the first intersection point and the light source into the light equation of the shadow light, and obtain the direction vectors m, n and p of the shadow light on the X-axis, Y-axis and Z-axis respectively: m = (X0-X1) / t, n = (Y0-Y1) / t, p = (Z0-Z1) / t, thereby solving the light equation of the shadow light.
[0095] Among them, the three-dimensional coordinates of each light source in the three-dimensional scene are determined when the three-dimensional scene is constructed.
[0096] The above-mentioned shadow ray solving process can be understood as follows: since the above-mentioned light source and the first intersection point are both on the shadow ray, the light distance between the two is first calculated through the three-dimensional coordinates of the light source and the first intersection point, and then the three-dimensional coordinates of the light source and the first intersection point, as well as the light distance between the two are substituted into the light equation of the shadow ray, that is, the direction vectors m, n and p of the shadow ray on the X-axis, Y-axis and Z-axis are solved, thereby solving the light equation of the shadow ray.
[0097] After the light equation of the shadow light is solved, in step S120, any of the following calculation formulas may be used to calculate the distance between the first intersection point and the second intersection point:
[0098] D = |X2–X1| / m;
[0099] D = |Y2–Y1| / n;
[0100] D = |Z2–Z1| / p;
[0101] Among them, (X1, Y1, Z1) are the three-dimensional coordinates of the first intersection point, and (X2, Y2, Z2) are the three-dimensional coordinates of the second intersection point.
[0102] In addition, the distance between the first intersection point and the second intersection point can be calculated directly according to the following calculation formula instead of the light equation of the shadow light:
[0103]
[0104] In some embodiments, in the above scenario where the intersection calculation is used to determine whether the initial light or the shadow light intersects with an opaque object, determining the intersection point between the initial light and the first opaque object hit by the initial light and its three-dimensional coordinates includes the following steps:
[0105] In the process of calculating the intersection of the initial light ray and each opaque object in the three-dimensional scene, determining the intersection points and the three-dimensional coordinates of each intersecting opaque object of the initial light ray;
[0106] According to the three-dimensional coordinates of the target pixel point and the three-dimensional coordinates of the intersection points of the initial light ray and each of the intersecting opaque objects, determine the intersection point with the shortest distance from the target pixel point among the intersection points of the initial light ray and each of the intersecting opaque objects, as the intersection point of the initial light ray and the first opaque object hit by the initial light ray;
[0107] Determining the intersection point of the shadow ray with the first opaque space object it hits and its 3D coordinates includes the following steps:
[0108] In the process of calculating the intersection of the shadow ray and each opaque object in the three-dimensional scene, determining the intersection points and the three-dimensional coordinates of each intersecting opaque object of the shadow ray;
[0109] According to the three-dimensional coordinates of the first intersection point and the three-dimensional coordinates of the intersection points of the shadow ray and each intersecting opaque object, the intersection point with the shortest distance from the first intersection point among the intersection points of the shadow ray and each intersecting opaque object is determined as the intersection point of the shadow ray and the first opaque spatial object it hits.
[0110] Among them, the intersection point with the smallest distance from the target pixel point among the intersection points of the initial light and each intersecting opaque object is determined, which can be understood as the first collision point between the initial light and the opaque object in the three-dimensional scene. This collision point is the first point seen by the human eye when looking at the target pixel point or captured by the camera when shooting the target pixel point (also the first intersection point of the initial light and the three-dimensional scene). The shadow intensity of this collision point can directly reflect the shadow intensity of the target pixel point, so the first collision point between the initial light and the opaque object in the three-dimensional scene is selected as the first intersection point to generate the shadow, such as Figure 3 shown.
[0111] In some embodiments, the distance D between the intersection point of the initial light and each intersecting opaque object and the target pixel point is i The calculation formula is: Among them, (X p ,Y p ,Z p ) is the three-dimensional coordinate of the target pixel, (X i ,Y i ,Z i ) are the three-dimensional coordinates of the intersection points of the initial light ray and each opaque object it intersects.
[0112] In addition, the intersection point with the smallest distance from the first intersection point among the intersection points of the shadow ray and each intersecting opaque object can be understood as the first collision point between the shadow ray and the opaque object in the three-dimensional scene. The distance between this collision point and the first intersection point can truly reflect the degree of occlusion of the first intersection point by the occluder (opaque object). The smaller the distance, the greater the degree of occlusion. Therefore, the first collision point between the shadow ray and the opaque object in the three-dimensional scene is selected as the second intersection point, and the distance between the second intersection point and the first intersection point is calculated to match the shadow intensity of the first intersection point.
[0113] In some embodiments, the distance D between the intersection points of the shadow ray and each of the opaque objects intersected and the first intersection point is j The calculation formula is: Among them, (X1, Y1, Z1) is the three-dimensional coordinates of the first intersection point, (X j ,Y j ,Z j ) are the three-dimensional coordinates of the intersection points of the shadow ray and each opaque object it intersects.
[0114] In the above shadow generation method, no matter how many initial rays are emitted from a pixel of the image to be rendered, a soft shadow effect can be obtained to a certain extent. However, the more initial rays are emitted from a pixel, the more computing resources are required. Therefore, in order to further avoid a large amount of computing resources, in some embodiments, the number of initial rays emitted from a pixel of the image to be rendered is less than or equal to a preset threshold. That is, the number of initial rays emitted from a pixel of the image to be rendered can be limited.
[0115] The more initial rays emitted from a pixel, the better the final shadow effect. Therefore, in some usage scenarios, the number of initial rays emitted from a pixel can be set by comprehensively considering the actual computing resource capabilities and the desired shadow effect.
[0116] In some embodiments, the preset threshold may be 1, that is, the number of initial light rays emitted from a pixel point of the image to be rendered is 1.
[0117] In a scenario where a pixel point (target pixel point) of the image to be rendered emits an initial ray of light, in order to make the initial ray emitted by a pixel point intersect with opaque objects as much as possible, the initial ray corresponding to the pixel point can be emitted toward areas where spatial objects are densely populated, so that each pixel point can obtain the corresponding shadow intensity as much as possible.
[0118] In some embodiments, the preset threshold may be greater than 1, that is, the number of initial light rays emitted from a pixel point of the image to be rendered may be greater than 1.
[0119] Among them, when multiple initial light rays emitted from a pixel point (target pixel point) of the image to be rendered hit the opaque object, different first intersection points are obtained. According to step S120, the shadow intensities of these first intersection points under a light source are obtained respectively. The shadow intensities of these first intersection points under the light source are superimposed to obtain the shadow intensity of the pixel point (target pixel point).
[0120] It should be noted that the direction of the initial light emitted from a pixel point (target pixel point) can be arbitrary (random), and can be selected according to the observation point or the position (viewing angle) of the camera, or it can be selected according to the observation point or the position (viewing angle) of the camera. For example, in a scenario where a pixel point (target pixel point) of the image to be rendered emits an initial light ray, the initial light rays corresponding to each pixel point in the image to be rendered can also be rays starting from a specified observation point and pointing to these pixel points respectively. If a pixel point (target pixel point) of the image to be rendered can emit two initial light rays, then two observation points can be specified, and so on.
[0121] In some embodiments, for a scene with multiple light sources in a three-dimensional scene, the shadow intensity of the first intersection under each light source can be obtained for each light source in the three-dimensional scene by the method in step S120.
[0122] Correspondingly, step S130 includes the following steps:
[0123] The shadow intensity of the first intersection point under each light source is superimposed to obtain the shadow intensity of the target pixel point.
[0124] The shadow intensities of the first intersection under each light source may be superimposed by directly adding them together, or by multiplying the shadow intensities of the first intersection under each light source by corresponding weights according to the contribution of each light source and then summing them up.
[0125] In a three-dimensional scene with multiple light sources, when multiple initial light rays emitted from a pixel point (target pixel point) of the image to be rendered hit an opaque object, different first intersection points are obtained. For different light sources, the shadow intensity of each first intersection point under each light source is obtained respectively according to step S120, and then for a first intersection point, the shadow intensities of the first intersection point under each light source are superimposed to obtain the total shadow intensity of the first intersection point under all light sources, and then the total shadow intensities of the first intersection points corresponding to the pixel point (target pixel point) are superimposed to obtain the shadow intensity of the pixel point (target pixel point).
[0126] In some embodiments, the shadow intensity of the target pixel obtained in the above step S130 may contain noise. In order to further optimize the soft shadow effect, the above method further includes: performing denoising processing on the shadow intensity of the target pixel.
[0127] A specific denoising processing method may be to perform denoising filtering through a filter kernel.
[0128] In some embodiments, the light source is a point light source, a line light source or a surface light source.
[0129] Among them, when the light source is a line light source or a surface light source, in the step of determining the light equation of the shadow light, the three-dimensional coordinates of the light source used refer to the three-dimensional coordinates of any point or specified point on the light source.
[0130] In some embodiments, when the light source is a line light source or a surface light source, there may be multiple shadow rays starting from a first intersection point and pointing to a light source (line light source or surface light source), that is, a first intersection point can emit shadow rays to different points of a light source (line light source or surface light source), and the multiple shadow rays obtained correspond to different second intersection points. The distances between these second intersection points and the first intersection point are calculated, and multiple shadow intensities are matched to obtain them. The multiple shadow intensities can be superimposed to finally obtain the shadow intensity of the first intersection.
[0131] In some embodiments, in order to further reduce computing resources and avoid wasting software resources and hardware resources, when the light source is a line light source or a surface light source, a shadow ray starting from a first intersection point and pointing to a light source (line light source or surface light source) is one, that is, a first intersection point sends a shadow ray to a light source (line light source or surface light source), and at most one second intersection point is obtained.
[0132] For example, Figure 4 , a schematic diagram of the intersection of the shadow light corresponding to the line light source and the objects in the three-dimensional scene is shown in FIG. Assume that the two ends of the line light source are point P and point Q. If the first intersection point is located in the ABCD plane, in a scene where a first intersection point sends a shadow light to the line light source, the emitted shadow light only needs to reach between PQ. Therefore, the directions of the shadow lights randomly emitted by each first intersection point on the ABCD plane may be different, and each shadow light may also hit an opaque object.
[0133] from Figure 4 It can be seen that on the ABCD plane, any shadow light emitted from the first intersection on the BC segment to the line light source will be blocked by the opaque object. Therefore, the BC segment is a very deep shadow. As mentioned above, the intensity of the shadow can be calculated based on the distance from the first intersection to the second intersection (the intersection of the occluder). Because the distances from the first intersection on all BC segments to the opaque object (occluder) are not much different, the shadow noise corresponding to the first intersection on the BC segment is not obvious, so the denoising filter can use a smaller and smoother filter kernel.
[0134] Send any shadow ray from the first intersection of AB and CD to the line light source. A shadow ray from the first intersection may reach the light source directly or be blocked by an opaque object. Therefore, the shadow intensity of the first intersection may be 0 (appearing as a bright spot) or non-0 (appearing as a shadow). For the first intersection of AB and CD, because bright spots or shadows are randomly generated, the rendering result looks like noise. After denoising filtering, a shadow of a certain intensity is finally generated. Because the bright spots and shadows are mixed together, the final result is a soft shadow.
[0135] The first intersection point is located on the left side of point A and on the right side of point D. Because the shadow light emitted to the linear light source will not be blocked by opaque objects, the rendering result is a bright spot.
[0136] Overall, the above shadow generation method realizes the transition and light-darkness change of shadows from dark to light and finally to bright areas under the line light source, which is closer to the real effect. The same is true for the surface light source, which will not be repeated here.
[0137] After the shadow intensity of each pixel on the image to be rendered is generated, the shadow intensity of each pixel may be written into a video memory, and in a subsequent rendering step, the shadow intensity of each pixel may be read out from the video memory as needed.
[0138] Based on the same inventive concept, Figure 5 As shown, the embodiment of the present disclosure also provides an image rendering method, including:
[0139] Step S210: obtaining the shadow intensity of each pixel in the image to be rendered by the shadow generation method of any of the above embodiments;
[0140] Step S220: Calculate the color of each pixel in the image to be rendered through the rendering pipeline; the color of each pixel includes chromaticity and brightness;
[0141] Step S230: adjusting the brightness of each pixel according to the shadow intensity of each pixel to obtain the final color of each pixel.
[0142] The rendering pipeline for calculating the color of each pixel in the image to be rendered includes the traditional vertex shading stage, the rasterization stage, and the fragment shading stage.
[0143] The shadow intensity of each pixel in the image to be rendered is obtained by the shadow generation method of any of the above embodiments and stored in the video memory. After the color of each pixel in the image to be rendered is calculated through the rendering pipeline, the shadow data (the shadow intensity of each pixel) is read from the video memory and superimposed on the color of each pixel to adjust the brightness of each pixel to obtain the final color of each pixel, which is then written back to the video memory.
[0144] Among them, in the process of superposition of the shadow intensity and color of each pixel point, the greater the shadow intensity of a pixel point, the lower the brightness of the pixel point, and the smaller the shadow intensity of a pixel point, the higher the brightness of the pixel point.
[0145] In some embodiments, Figure 6As shown, the overall process of the above-mentioned image rendering method is: the software generates an initial light (with a pixel as the starting point); the hardware calculates the intersection of the initial light and the first opaque object it hits as the first intersection, determines the light equation of the shadow light with the first intersection as the starting point and pointing to a light source, determines the intersection of the shadow light and the first opaque object it hits as the second intersection (shadow position point), calculates the distance between the first intersection and the second intersection, as the distance at which the shadow light is blocked by the opaque object; the hardware feeds back the distance to the software, and the software matches the shadow intensity of the first intersection according to the distance, obtains the shadow intensity of the pixel and writes it into the video memory; the hardware calculates the color of each pixel in the image to be rendered through the rendering pipeline, and reads the shadow data (the shadow intensity of each pixel) from the video memory, superimposes it on the color of each pixel to adjust the brightness of each pixel, obtains the final color of each pixel, and obtains the final rendering color and writes it back to the video memory.
[0146] The video memory mentioned above may be a frame buffer.
[0147] Based on the same inventive concept, the embodiment of the present disclosure also provides a graphics processor 300, such as Figure 7 As shown, including:
[0148] The shadow generation module 310 is configured to implement the shadow generation method of any of the above embodiments to obtain the shadow intensity of each pixel in the image to be rendered;
[0149] The rendering module 320 is configured to calculate the color of each pixel in the image to be rendered through the rendering pipeline; the color of each pixel includes chromaticity and brightness;
[0150] The adjustment module 330 is configured to adjust the brightness of each pixel according to the shadow intensity of each pixel to obtain the final color of each pixel.
[0151] The specific implementation process of each module of the above-mentioned graphics processor can refer to the shadow generation method of any of the above-mentioned embodiments or the image rendering method of any of the above-mentioned embodiments, which will not be repeated here.
[0152] Based on the same inventive concept, an embodiment of the present disclosure further provides a graphics processing system, comprising a graphics processor according to any of the above embodiments.
[0153] The graphics processing system may be a die (tube core), or a SOC (System on Chip) with multiple dies interconnected, or other organizational forms.
[0154] Based on the same inventive concept, an embodiment of the present disclosure further provides an electronic component, which includes the graphics processing system in any of the above embodiments.
[0155] In some usage scenarios, the product form of this electronic component is a graphics card or a CPU motherboard.
[0156] Based on the same inventive concept, the disclosed embodiment also provides an electronic device, which includes the above-mentioned electronic components. In some usage scenarios, the product form of the electronic device is a portable electronic device, such as a smart phone, a tablet computer, a VR device, etc.; in some usage scenarios, the product form of the electronic device is a personal computer, a game console, etc.
[0157] Although the preferred embodiments of the present disclosure have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present disclosure.
[0158] Obviously, those skilled in the art can make various changes and modifications to the present disclosure without departing from the spirit and scope of the present disclosure. Thus, if these modifications and variations of the present disclosure fall within the scope of the claims of the present disclosure and their equivalents, the present disclosure is also intended to include these modifications and variations.
Claims
1. A shadow generation method, comprising: In a three-dimensional scene of an image to be rendered, determining an initial light ray emitted from a target pixel point of the image to be rendered, and determining whether the initial light ray hits an opaque object, and if so, determining an intersection point between the initial light ray and the first opaque object hit by the initial light ray as a first intersection point; For a light source in the three-dimensional scene, determining whether a shadow ray starting from the first intersection point and pointing to the light source hits an opaque object; If yes, determine the intersection point of the shadow ray and the first opaque spatial object it hits as the second intersection point, and calculate the distance between the first intersection point and the second intersection point to match the shadow intensity of the first intersection point under the light source according to the distance; The shadow intensity of the target pixel point is determined according to the shadow intensity of the first intersection point under the light source. 2 . The method according to claim 1 , wherein the shadow intensity of the first intersection under the light source is negatively correlated with the distance between the first intersection and the second intersection.
3. The method according to claim 1, determining the shadow intensity of the target pixel point according to the shadow intensity of the first intersection point under the light source, comprising the following steps: The shadow intensity of the first intersection point under each light source is superimposed to obtain the shadow intensity of the target pixel point.
4. The method according to claim 1, determining whether the initial light hits an opaque object, and if so, determining the intersection of the initial light and the first opaque object hit by the initial light as the first intersection, comprising the following steps: According to the light equation of the initial light, the initial light is intersected with each opaque object in the three-dimensional scene to determine whether the initial light hits an opaque object, and if so, the intersection point and the three-dimensional coordinates of the first opaque object hit by the initial light are determined, and the intersection point is used as the first intersection point; For a light source in the three-dimensional scene, determining whether a shadow ray starting from the first intersection point and pointing to the light source hits an opaque object; If yes, then determining the intersection point of the shadow ray and the first opaque spatial object it hits as the second intersection point comprises the following steps: For a light source in the three-dimensional scene, determining a light equation of a shadow light starting from the first intersection point and pointing to the light source according to the three-dimensional coordinates of the first intersection point and the three-dimensional coordinates of the light source; According to the light equation of the shadow ray, the intersection calculation of the shadow ray and each opaque object in the three-dimensional scene is performed to determine whether the shadow ray hits an opaque object. If so, the intersection point of the shadow ray and the first opaque spatial object hit by the shadow ray and its three-dimensional coordinates are determined, and the intersection point is used as the second intersection point.
5. The method according to claim 4, for a light source in the three-dimensional scene, determining a light equation of a shadow light starting from the first intersection point and pointing to the light source according to the three-dimensional coordinates of the first intersection point and the three-dimensional coordinates of the light source, comprising the following steps: For a light source in the three-dimensional scene, the light equation of the shadow light starting from the first intersection and pointing to the light source is: X=X1+mt, Y=Y1+nt, Z=Z1+pt; Wherein, (X1, Y1, Z1) are the three-dimensional coordinates of the first intersection point, m, n and p are the direction vectors of the shadow light on the X-axis, Y-axis and Z-axis respectively, t is the light distance, and (X, Y, Z) are the three-dimensional coordinates of the point on the shadow light with a light distance of t; According to the three-dimensional coordinates (X0, Y0, Z0) of the light source, the light distance t between the first intersection point and the light source is obtained as: Substitute the three-dimensional coordinates (X0, Y0, Z0) of the light source and the light distance t between the first intersection point and the light source into the light equation of the shadow light, and obtain the direction vectors m, n and p of the shadow light on the X-axis, Y-axis and Z-axis respectively: m = (X0-X1) / t, n = (Y0-Y1) / t, p = (Z0-Z1) / t, thereby solving the light equation of the shadow light.
6. The method according to claim 4, wherein the light equation of the shadow light is: X=X1+mt, Y=Y1+nt, Z=Z1+pt; wherein, (X1, Y1, Z1) are the three-dimensional coordinates of the first intersection point, m, n and p are the direction vectors of the shadow light on the X-axis, Y-axis and Z-axis respectively, t is the light distance, and (X, Y, Z) are the three-dimensional coordinates of the point on the shadow light with the light distance t; The distance D between the first intersection point and the second intersection point is calculated using any one of the following formulas: D = |X2–X1| / m; D = |Y2–Y1| / n; D = |Z2–Z1| / p; Among them, (X2, Y2, Z2) are the three-dimensional coordinates of the second intersection point.
7. The method according to claim 4, determining the intersection point of the initial light ray with the first opaque object hit by the initial light ray and its three-dimensional coordinates, comprising the following steps: In the process of performing intersection calculation on the initial light and each opaque object in the three-dimensional scene, determining the intersection points and three-dimensional coordinates of each intersecting opaque object between the initial light and the intersecting opaque object; According to the three-dimensional coordinates of the target pixel point and the three-dimensional coordinates of the intersection points of the initial light ray and each of the intersecting opaque objects, determine the intersection point with the shortest distance from the target pixel point among the intersection points of the initial light ray and each of the intersecting opaque objects, as the intersection point of the initial light ray and the first opaque object hit by the initial light ray; Determining the intersection point of the shadow ray with the first opaque spatial object hit by the shadow ray and its three-dimensional coordinates, comprising the following steps: In the process of calculating the intersection of the shadow ray and each opaque object in the three-dimensional scene, determining the intersection points and the three-dimensional coordinates of each intersecting opaque object between the shadow ray and the opaque object; According to the three-dimensional coordinates of the first intersection point and the three-dimensional coordinates of the intersection points of the shadow ray and each intersecting opaque object, determine the intersection point with the shortest distance from the first intersection point among the intersection points of the shadow ray and each intersecting opaque object as the intersection point of the shadow ray and the first opaque spatial object it hits.
8. According to the method of claim 1, the distance D between the first intersection point and the second intersection point is calculated as follows: in, (X1, Y1, Z1) are the three-dimensional coordinates of the first intersection point, and (X2, Y2, Z2) are the three-dimensional coordinates of the second intersection point.
9. The method according to claim 1, further comprising: The shadow intensity of the target pixel is denoised.
10. According to the method of claim 1, the number of initial light rays emitted from a pixel point of the image to be rendered is less than or equal to a preset threshold. The method according to claim 1 , wherein the light source is a point light source, a line light source or a surface light source. 12 . The method according to claim 1 , wherein the number of shadow rays starting from the first intersection point and pointing to a light source is 1.
13. An image rendering method, comprising: Obtaining the shadow intensity of each pixel in the image to be rendered by the method described in any one of claims 1 to 12; Calculate the color of each pixel in the image to be rendered through a rendering pipeline; The color of each pixel includes chromaticity and brightness; According to the shadow intensity of each pixel, the brightness of each pixel is adjusted to obtain the final color of each pixel.
14. A graphics processor, comprising: A shadow generation module, configured to implement the method according to any one of claims 1 to 12 to obtain the shadow intensity of each pixel in the image to be rendered; A rendering module, configured to calculate the color of each pixel in the image to be rendered through a rendering pipeline; The color of each pixel includes chromaticity and brightness; The adjustment module is configured to adjust the brightness of each pixel according to the shadow intensity of each pixel to obtain the final color of each pixel.
15. A graphics processing system, comprising the graphics processor according to claim 14.
16. An electronic component, wherein: Includes the graphics processing system described in claim 15.
17. An electronic device, wherein: The electronic component comprising claim 16.
