Shadow rendering method and apparatus, computer device, and storage medium
By determining the shadow space distance of pixels in the virtual scene and performing linear transformation, the problem of high complexity of traditional shadow rendering methods is solved, the shadow rendering efficiency is improved, and a realistic soft shadow effect is achieved.
Patent Information
- Application Number
- PCT/CN2024/076534
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-03-23
- Filing Date
- 2024-02-07
- Publication Date
- 2024-09-26
AI Technical Summary
The traditional shadow rendering method has high computational complexity, resulting in low shadow rendering efficiency and difficulty in achieving the realistic effect of soft shadows.
By determining the shadow space distance of the pixel point under the light source from the observation perspective of the virtual scene, and linearly transforming the distance based on the linear transformation rendering parameters, the shadow attenuation factor is obtained, which is used to render the soft shadow effect.
The calculation complexity of shadow rendering is simplified, the efficiency of shadow rendering is improved, and the shadow effect can be flexibly controlled by adjusting the preset conditions to achieve a more realistic soft shadow presentation.
Smart Images

Figure CN2024076534_26092024_PF_FP
Abstract
Description
Shadow rendering method, device, computer equipment and storage medium
[0001] Related applications
[0002] This application claims priority to Chinese patent application number 2023102884260, filed on March 23, 2023, entitled “Shadow rendering method, device, computer device and storage medium,” the entire text of which is incorporated herein by reference. Technical Field
[0003] The present application relates to the technical field of shadow rendering, and in particular to a shadow rendering method, apparatus, computer equipment, and storage medium. Background Art
[0004] With the development of computer technology, shadow rendering technology has emerged. Shadow rendering technology is used to render shadows. Shadows include soft shadows and hard shadows. Hard shadows have obvious boundaries, while soft shadows gradually transition from shadows to no shadows. Therefore, soft shadows are more in line with real shadows.
[0005] In traditional technology, in order to achieve the effect of soft shadows, the distance between the projection area and the occluder can be calculated to achieve the soft shadow.
[0006] However, the traditional method of achieving soft shadows has high computational complexity, resulting in low shadow rendering efficiency.
[0007] Summary of the Invention
[0008] Based on this, it is necessary to provide a shadow rendering method, apparatus, computer equipment, computer-readable storage medium and computer program product that can improve the rendering effect of shadows in order to address the above technical problems.
[0009] In one aspect, the present application provides a shadow rendering method, performed by a computer device, the method comprising:
[0010] Determining, under an observation perspective of a virtual scene, a shadow space distance of a pixel point in screen space under a light source of the virtual scene, wherein the shadow space distance refers to a distance in shadow camera space between a world space position of the pixel point and a shadow camera located at a position of the light source;
[0011] performing a linear transformation on the shadow space distance of the pixel under the light source based on a linear transformation rendering parameter of the light source to obtain a shadow attenuation factor of the pixel; wherein the linear transformation rendering parameter is determined according to a preset condition set for the light source;
[0012] The shadow of the pixel point is rendered based on the shadow attenuation factor of the pixel point to obtain a shadow rendering result of the virtual scene under the observation perspective.
[0013] In another aspect, the present application further provides a shadow rendering device. The device includes: a distance determination module configured to determine, under a viewing angle of a virtual scene, a shadow space distance of a pixel point in screen space under a light source of the virtual scene, wherein the shadow space distance refers to the distance between the world space position of the pixel point and a shadow camera located at the light source position in the shadow camera space;
[0014] a factor determination module, configured to perform a linear transformation on the shadow space distance of the pixel under the light source based on a linear transformation rendering parameter of the light source to obtain a shadow attenuation factor of the pixel, wherein the linear transformation rendering parameter is determined according to preset conditions set for the light source;
[0015] A shadow rendering module is used to render the shadow of the pixel point based on the shadow attenuation factor of the pixel point to obtain a shadow rendering result of the virtual scene under the observation angle.
[0016] In another aspect, the present application further provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps in the above-mentioned shadow rendering method when executing the computer program.
[0017] In another aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, which implements the steps in the above-mentioned shadow rendering method when executed by a processor.
[0018] In another aspect, the present application further provides a computer program product, which includes a computer program that implements the steps in the above-mentioned shadow rendering method when executed by a processor.
[0019] The details of one or more embodiments of the present application are set forth in the accompanying drawings and the description below. Other features, objects, and advantages of the present application will become apparent from the description, drawings, and claims. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the conventional technology, the following briefly introduces the drawings required for use in the embodiments or the conventional technology descriptions. Obviously, the drawings described below are merely embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the disclosed drawings without any creative work.
[0021] FIG1 is a diagram illustrating an application environment of a shadow rendering method in some embodiments;
[0022] FIG2 is a schematic diagram of a flow chart of a shadow rendering method in some embodiments;
[0023] FIG3 is a comparison diagram of shadow rendering effects in some embodiments;
[0024] FIG4 is a schematic diagram showing the relationship between depth value and shadow space distance in some embodiments;
[0025] FIG5 is a schematic diagram showing the relationship between depth value and shadow space distance in some embodiments;
[0026] FIG6 is a schematic diagram showing the relationship between depth value and shadow space distance in some embodiments;
[0027] FIG7 is a schematic diagram of a flow chart of a shadow rendering method in some embodiments;
[0028] FIG8 is a comparison diagram of shadow rendering effects in some embodiments;
[0029] FIG9 is a block diagram of a shadow rendering apparatus in some embodiments;
[0030] FIG10 is a diagram illustrating the internal structure of a computer device in some embodiments;
[0031] FIG11 is a diagram illustrating the internal structure of a computer device in some embodiments. DETAILED DESCRIPTION
[0032] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0033] The shadow rendering method provided in the embodiments of the present application can be applied in the application environment shown in FIG1 . In this embodiment, terminal 102 communicates with server 104 via a network. A data storage system can store data that server 104 needs to process. The data storage system can be integrated with server 104 or placed in the cloud or on another server.
[0034] Specifically, the terminal 102 can obtain a virtual scene from the server 104. In order to render the picture observed from the observation angle of the virtual scene, if there is a shadow in the picture, the terminal 102 can determine the shadow space distance of the pixel point in the screen space under the light source of the virtual scene, and based on the linear transformation rendering parameters of the light source, perform a linear transformation on the shadow space distance of the pixel point under the light source to obtain the shadow attenuation factor of the pixel point, and render the shadow of the pixel point based on the shadow attenuation factor of the pixel point to obtain the shadow rendering result of the virtual scene from the observation angle. Among them, the shadow space distance refers to the distance between the world space position of the pixel point and the shadow camera located at the light source position in the shadow camera space. The linear transformation rendering parameters are determined based on the preset conditions set for the light source. The terminal 102 can display the shadow rendering result or send the shadow rendering result to the server 104.
[0035] Among them, the terminal 102 can be, but is not limited to, various desktop computers, laptops, smart phones, tablets, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, cloud security, host security and other network security services, CDN, as well as basic cloud computing services such as big data and artificial intelligence platforms. The terminal 102 and the server 104 can be directly or indirectly connected through wired or wireless communication, and this application does not impose any restrictions on this.
[0036] In some embodiments, as shown in FIG2 , a shadow rendering method is provided. The method may be executed by a terminal or a server, or may be executed jointly by the terminal and the server. The method is described by taking the application of the method to the terminal 102 in FIG1 as an example, and includes the following steps:
[0037] Step 202, under the observation angle of observing the virtual scene, determine the shadow space distance of the pixel point in the screen space under the light source of the virtual scene. The shadow space distance refers to the distance between the world space position of the pixel point and the shadow camera located at the light source position in the shadow camera space.
[0038] Among them, the virtual scene is a virtual scene displayed (or provided) when the application is running on the terminal. The virtual scene can be a simulation of the real world environment scene, a semi-simulation and semi-fictitious three-dimensional environment scene, or a purely fictitious three-dimensional environment scene. The virtual scene can be any of a two-dimensional virtual scene, a 2.5-dimensional virtual scene, and a three-dimensional virtual scene. The observation perspective can be any perspective for observing the virtual scene. Virtual scenes include, but are not limited to, scenes such as film and television special effects, games, mirror simulation, visual design, VR (Virtual Reality), industrial simulation, and digital cultural creation.
[0039] The shadow camera is located at the light source position in the virtual scene and observes the virtual scene from the light source's direction. That is, the shadow camera's orientation aligns with the light source's direction. In other words, the shadow camera is the camera used to observe the virtual scene from the light source's position, and its viewing direction aligns with the light source's direction. The shadow camera space is a three-dimensional coordinate system established with the shadow camera's position as the origin. The shadow camera space can also be understood as the light source's light space, which is a three-dimensional coordinate system established with the light source as the origin.
[0040] World space refers to the three-dimensional space in which the virtual scene resides. The size of world space can be customized. For example, world space is a three-dimensional space with a length of 100 meters, a width of 100 meters, and a height of 100 meters. World space position refers to the position within world space. Screen space refers to the two-dimensional space of the screen. The size of screen space is the size of the screen, measured in pixels.
[0041] The world space position of a pixel is the world space position of the pixel after projecting the target scene area onto the screen space. The target scene area refers to the scene area observed from the perspective of the virtual scene. A light source can be the light source in the virtual scene that illuminates the target scene area. A light source refers to an object that can emit light and is emitting light, such as the sun, electric lights, burning materials, etc. The light source in the virtual scene is a set of lighting data that can realistically simulate the lighting effects of real-world light sources.
[0042] Specifically, the terminal can determine the world space positions corresponding to each pixel in the screen space after the target scene area is projected into the screen space; the target scene area is the scene area observed from the perspective of observing the virtual scene. The color value of the pixel is determined by the color value at the world space position corresponding to the pixel. The world space position corresponding to the pixel can be, for example, the position on an object in the world space. In order to render the light source, for each pixel's world space position, the terminal can convert the world space position into the shadow camera space to obtain the position of the world space position in the shadow camera space, i.e., the shadow space position.
[0043] In some embodiments, for each pixel point, the terminal can determine the position of the shadow camera in the shadow camera space, obtain the shadow space position of the shadow camera, and calculate the distance from the shadow space position corresponding to the world space position to the shadow space position of the shadow camera in the observation direction of the shadow camera. The calculated distance is the shadow space distance of the pixel point under the light source.
[0044] Step 204 : Based on the linear transformation rendering parameters of the light source, a linear transformation is performed on the shadow space distance of the pixel under the light source to obtain a shadow attenuation factor of the pixel. The linear transformation rendering parameters are determined according to preset conditions set for the light source.
[0045] The preset conditions may include preset attenuation parameters, and the preset attenuation parameters include at least two of the attenuation start distance, attenuation length, or attenuation end distance. The attenuation start distance refers to the distance from the starting position of shadow attenuation to the shadow camera in the shadow camera space, and the distance from the starting position of shadow attenuation to the light source. It can be the distance between the starting position of shadow attenuation and the shadow space position of the shadow camera in the observation direction of the shadow camera. The shadow space position of the shadow camera refers to the position of the shadow camera in the shadow camera space. The observation direction of the shadow camera refers to the orientation of the shadow camera. The shadow space position of the shadow camera refers to the position of the shadow camera in the shadow camera space. The shadow camera space can be identified by a three-dimensional coordinate system, and the direction of a coordinate axis in the three-dimensional coordinate system is the orientation of the shadow camera. For example, the direction of the Z axis in the three-dimensional coordinate system is the orientation of the shadow camera, so that the observation direction of the shadow camera is the direction of the Z axis in the three-dimensional coordinate system.
[0046] The attenuation end distance is the distance from the end position of the shadow attenuation to the shadow camera in shadow camera space. The distance from the end position of the shadow attenuation to the shadow camera can be the distance between the end position of the shadow attenuation and the shadow space position of the shadow camera in the shadow camera's viewing direction. The attenuation length is the difference between the attenuation start distance and the attenuation end distance. The sum of the attenuation start distance and the attenuation length is the attenuation end distance.
[0047] The shadow attenuation factor affects the shadow intensity of the shadow rendered at the pixel point. The larger the shadow attenuation factor, the smaller the shadow intensity, and the less obvious the shadow at the pixel point. The smaller the shadow attenuation factor, the greater the shadow intensity, and the more obvious the shadow at the pixel point.
[0048] Specifically, the shadow attenuation factor can be the result of linearly changing the shadow space distance using a linear transformation rendering parameter. The conditions satisfied by the linear transformation rendering parameter include: when the shadow space distance is consistent with the attenuation start distance, the result of linearly transforming the shadow space distance using the linear transformation rendering parameter is a first preset value; when the shadow space distance is consistent with the attenuation end distance, the result of linearly transforming the shadow space distance using the linear transformation rendering parameter is a second preset value. The first preset value is less than the second preset value. The first preset value is, for example, a value near 0, such as 0 or 0.1, and the second preset value is, for example, a value near 1, such as 1 or 0.9. Thus, the result obtained by linearly transforming the depth-related value is greater than or equal to the first preset value and less than or equal to the second preset value. The linear transformation rendering parameter is a parameter that characterizes the linear relationship between the shadow space distance and the shadow attenuation factor when rendering shadows. Assuming that for a certain light source, the linear relationship between the shadow space distance Y and the shadow attenuation factor X is Y = aX + b, then a and b are the linear transformation rendering parameters of the light source.
[0049] In some embodiments, the shadow attenuation factor may be the result of indirectly linearly varying the shadow space distance using linear transformation rendering parameters. Specifically, the terminal may determine a depth-related value for the pixel based on the shadow space distance of the pixel under the light source. The depth-related value is linearly related to the shadow space distance and is correlated with a target depth value. The target depth value refers to the depth value of the world-space position in the shadow camera space. The depth value represents the distance from the camera; a larger depth value indicates a larger distance from the camera. The target depth value represents the distance between the world-space position in the shadow camera space and the shadow camera. The terminal may linearly transform the depth-related value of the pixel based on the linear transformation rendering parameters of the light source to obtain the shadow attenuation factor for the pixel. The linear transformation rendering parameters satisfy preset conditions, including: when the shadow space distance coincides with the attenuation start distance, the result of linearly transforming the depth-related value using the linear transformation rendering parameters is a first preset value; when the shadow space distance coincides with the attenuation end distance, the result of linearly transforming the depth-related value using the linear transformation rendering parameters is a second preset value.
[0050] In some embodiments, the terminal may perform a linear transformation on the depth-related value of the pixel point based on the linear transformation rendering parameter of the light source, and use the result of the linear transformation as the shadow attenuation factor of the pixel point. The linear transformation rendering parameter can be one or more, and multiple means at least two. For example, factor = posL.z * t1 + t2. Among them, factor represents the shadow attenuation factor, posL.z represents the depth-related value, t1 and t2 are two linear transformation rendering parameters, and t1 and t2 meet the preset conditions.
[0051] Step 206 : Render the shadow of the pixel point based on the shadow attenuation factor of the pixel point to obtain a shadow rendering result of the virtual scene under the observation angle.
[0052] Specifically, the terminal can determine the first shadow intensity of the pixel under the light source; the first shadow intensity is one of the first preset intensity or the second preset intensity; the first preset intensity indicates that the light from the light source to the world space position of the pixel is blocked, and the second preset intensity indicates that the light from the light source to the world space position of the pixel is not blocked. The first preset intensity is greater than the second preset intensity, and the first preset intensity is, for example, a value near 1, such as 1 or 0.9, and the second preset intensity is, for example, a value near 0, such as 0 or 0.1. The terminal can use the shadow attenuation factor to attenuate the first shadow intensity of the pixel to obtain the second shadow intensity of the pixel under the light source, render the shadow of the pixel based on the second shadow intensity, and obtain the shadow rendering result of the virtual scene under the observation angle. The second shadow intensity is negatively correlated with the shadow attenuation factor.
[0053] In some embodiments, the terminal determines the world space position of each pixel in the screen space after projecting the target scene area into the screen space. The target scene area refers to the scene area observed under the observation angle of observing the virtual scene. For each pixel, the terminal can use the method for determining the shadow attenuation factor provided by the present application to obtain the shadow attenuation factor of the pixel according to the world space position of the pixel. When the shadow attenuation factor of each pixel is obtained, the shadow of the pixel is rendered based on the shadow attenuation factor of the pixel to obtain a shadow rendering result of the virtual scene under the observation angle, which includes the shadow generated by the light source and presents a soft shadow effect. In the case of multiple light sources, each light source can be used in turn for rendering to obtain a shadow rendering result, so that the shadow rendering result includes the soft shadows generated by each light source.
[0054] In the above shadow rendering method, under the observation angle of the virtual scene, the shadow space distance of a pixel in screen space under the light source is determined. The shadow space distance refers to the distance between the world space position of the pixel and the shadow camera located at the light source in the shadow camera space. Based on the linear transformation rendering parameters of the light source, the shadow space distance of the pixel under the light source is linearly transformed to obtain a shadow attenuation factor of the pixel. The linear transformation rendering parameters are determined according to preset conditions set for the light source (such as preset attenuation parameters). The shadow of the pixel is rendered based on the shadow attenuation factor of the pixel to obtain a shadow rendering result of the virtual scene under the observation angle. Since the shadow attenuation factor is obtained by linearly transforming the shadow space distance, the shadow attenuation factor has a linear relationship with the shadow space distance. Therefore, shadow attenuation using the shadow attenuation factor can produce a soft shadow effect. Since the linear change is achieved using the linear transformation rendering parameters of the light source, and the linear transformation rendering parameters are determined according to the preset attenuation parameters of the light source, the preset attenuation parameters of the light source can be used to simply and efficiently control the shadow attenuation factor, with low computational complexity, thereby improving the rendering efficiency of soft shadows.
[0055] By adopting the shadow rendering method provided by the present application, soft shadows can be rendered, and by adjusting the preset conditions, the shadow effect can be conveniently and quickly controlled, and the computational complexity is low, which improves the efficiency of shadow rendering. Taking the preset conditions including the attenuation starting distance x1 and the attenuation length x2 as an example, as shown in Figure 3, (a) in Figure 3 is an effect diagram without shadow attenuation, that is, an effect diagram of hard shadows, and (b)-(d) in Figure 3 are effect diagrams of shadow attenuation under different values of x1 and x2. (b) decays earlier than (c) and has a larger attenuation distance, but the attenuation end distances of (b) and (c) are both 1.5, and (d) decays earlier than (c) and has a larger attenuation distance. It can be seen that by adopting the shadow attenuation rendering method provided by the present application, the shadow rendering effect can be flexibly adjusted, thereby making the rendered shadow more realistic.
[0056] In some embodiments, based on the linear transformation rendering parameters of the light source, the shadow space distance of the pixel point under the light source is linearly transformed to obtain the shadow attenuation factor of the pixel point, including: determining the depth-related value of the pixel point based on the shadow space distance of the pixel point under the light source; the depth-related value is linearly related to the shadow space distance, and the depth-related value is related to the pixel depth value, and the pixel depth value refers to the depth value of the world space position of the pixel point in the shadow camera space; based on the linear transformation rendering parameters of the light source, the depth-related value of the pixel point is linearly transformed to obtain the shadow attenuation factor of the pixel point.
[0057] Specifically, the terminal can determine the pixel depth value based on the shadow space distance of the pixel point under the light source. The depth value calculation method includes a forward depth calculation method and a reverse depth calculation method (Reversed-Z method). In the forward depth calculation method, the depth value is positively correlated with the distance, so that in the forward depth calculation method, the pixel depth value is positively correlated with the shadow space distance. In the reverse depth calculation method, the depth value is negatively correlated with the distance, so that in the reverse depth calculation method, the pixel depth value is negatively correlated with the shadow space distance. The depth value calculation method is related to the projection type of the shadow camera, and the projection type includes at least one of perspective projection or orthogonal projection.
[0058] In some embodiments, when the projection type of the shadow camera is perspective projection and the depth calculation method is a forward depth calculation method, the calculation formula of the depth value d is formula (1): Where d represents the depth value, x represents the shadow space distance, n represents the shadow space distance of the shadow camera's near plane, and the shadow space distance of the near plane represents the distance from the shadow camera to the near plane in the shadow camera space. f represents the shadow space distance of the shadow camera's far plane, and the shadow space distance of the far plane represents the distance from the shadow camera to the far plane in the shadow camera space. When x in formula (1) is taken as the shadow space distance of the pixel under the light source, d calculated in formula (1) is the pixel depth value.
[0059] In some embodiments, when the projection type of the shadow camera is orthogonal projection and the depth calculation method is a forward depth calculation method, the calculation formula of the depth value d is formula (2): When the value of x in formula (2) is the shadow space distance of the pixel under the light source, the d calculated in formula (2) is the pixel depth value.
[0060] In some embodiments, when the projection type of the shadow camera is perspective projection and the depth calculation method is the inverse depth calculation method, the calculation formula of the depth value d is formula (3): When the value of x in formula (3) is the shadow space distance of the pixel under the light source, the d calculated in formula (3) is the pixel depth value.
[0061] In some embodiments, when the projection type of the shadow camera is orthogonal projection and the depth calculation method is the inverse depth calculation method, the calculation formula of the depth value d is formula (4): When the value of x in formula (4) is the shadow space distance of the pixel under the light source, the d calculated in formula (4) is the pixel depth value.
[0062] It can be seen from formulas (1)-(4) that when the projection type is perspective projection, the depth value d has a nonlinear relationship with the shadow space distance x. As shown in Figure 4, a schematic diagram of how d in formula (3) changes with x is shown. Obviously, d has a nonlinear relationship with x. When the projection type is orthogonal projection, the depth value d has a linear relationship with the shadow space distance x. As shown in Figure 5, a schematic diagram of how d in formula (2) changes with x is shown. Obviously, d has a linear relationship with x. Therefore, when the projection type is orthogonal projection, the terminal can use the pixel depth value as the depth-related value of the pixel point. When the projection type is perspective projection, the terminal can use the depth value d1 that has not undergone perspective division as the depth-related value of the pixel point. When the depth calculation method is the forward depth calculation method, the calculation formula for the depth value that has not undergone perspective division is formula (5): When the depth calculation method is the reverse depth calculation method, the calculation formula of the depth value without perspective division is formula (6): The difference between d and d1 lies in whether they are divided by x. Dividing by x indicates that perspective division is performed, while not dividing by x indicates that perspective division is not performed. The depth value d1 without perspective division is linearly related to the shadow space distance x. Figure 6 shows a schematic diagram of how d1 in formula (5) changes with x. Clearly, d1 is linearly related to x.
[0063] In some embodiments, the terminal can transform the world space position of the pixel point in sequence through the view matrix, the projection matrix of the shadow camera, and the matrix that jumps from the NDC (normalized device coordinate space) to the screen space to obtain the transformed position. The transformed position can be represented by homogeneous coordinates (X, Y, Z, W), where W is used to scale the coordinates, w is the shadow space distance, Z represents the pixel depth value without perspective division, Z / W is the pixel depth value, and (X / W, Y / W) is the screen space position. The terminal can thus directly determine the shadow space distance, the pixel depth value without perspective division, and the pixel depth value based on the transformed position.
[0064] In this embodiment, a linear transformation is performed on the depth-related value of a pixel point based on the linear transformation rendering parameters of the light source to obtain the shadow attenuation factor of the pixel point. It can be seen that there is a linear relationship between the shadow attenuation factor and the shadow attenuation factor. Since the depth-related value is linearly related to the shadow space distance, the shadow attenuation factor is also linearly related to the shadow space distance. Therefore, a shadow attenuation factor that is linearly related to the shadow space distance can be obtained through a simple linear transformation, thereby improving the efficiency of determining the shadow attenuation factor and thus improving the efficiency of shadow rendering. In addition, the method for calculating the shadow attenuation factor provided in this application can be applied to perspective projection and orthogonal projection, thereby unifying the attenuation calculation methods of perspective projection and orthogonal projection, reducing the amount of calculation, and further improving rendering efficiency.
[0065] In some embodiments, the preset conditions include at least two of the attenuation start distance, the attenuation length or the attenuation end distance, the attenuation length is the difference between the attenuation start distance and the attenuation end distance, and the linear transformation rendering parameters meet the following constraints: when the shadow space distance is consistent with the attenuation start distance, the result of linearly transforming the depth-related value of the pixel point using the linear transformation rendering parameters is a first preset value; the attenuation start distance refers to the distance from the starting position of the shadow attenuation to the shadow camera in the shadow camera space; when the shadow space distance is consistent with the attenuation end distance, the result of linearly transforming the depth-related value of the pixel point using the linear transformation rendering parameters is a second preset value; the attenuation end distance refers to the distance from the ending position of the shadow attenuation to the shadow camera in the shadow camera space; the first preset value is less than the second preset value.
[0066] Among them, the first preset value is less than the second preset value. The first preset value is, for example, a value near 0, such as 0 or 0.1, and the second preset value is, for example, a value near 1, such as 1 or 0.9. The constraints include: 1. When the shadow space distance is consistent with the attenuation start distance, the result of linearly transforming the depth-related value of the pixel point using the linear transformation rendering parameter is the first preset value; 2. When the shadow space distance is consistent with the attenuation end distance, the result of linearly transforming the depth-related value of the pixel point using the linear transformation rendering parameter is the second preset value. For example, x1 represents the attenuation start distance, x2 represents the attenuation length, and x3 represents the attenuation end distance, x3=x1+x2. If the first preset value is 0 and the second preset value is 1, then the constraints are: when x=x1, fac=0, and when x=x3, fac=1.
[0067] Thus, the result obtained by linearly transforming the depth-related value is greater than or equal to the first preset value and less than or equal to the second preset value. When the linear transformation rendering parameters meet the constraints, the shadow can be made to decay from the attenuation start distance and disappear at the attenuation end distance, so that the shadow presents a soft shadow effect. The first transformation parameter and the second transformation parameter are determined according to preset conditions, which include at least two of the attenuation start distance, the attenuation length, or the attenuation end distance.
[0068] Specifically, the terminal can determine the linear transformation rendering parameters that meet the constraints, and use the linear transformation rendering parameters that meet the constraints to perform a linear transformation on the depth-related values of the pixel points to obtain the shadow attenuation factor of the pixel points, so that the shadow rendered using the shadow attenuation factor presents a soft shadow effect.
[0069] In some embodiments, the linear transformation rendering parameters include a first transformation parameter and a second transformation parameter. The terminal can calculate the first transformation parameter and the second transformation parameter that satisfy the constraint conditions according to the constraint conditions, and use the first transformation parameter and the second transformation parameter that satisfy the constraint conditions to perform a linear transformation on the depth-related value of the pixel point to obtain the shadow attenuation factor of the pixel point. For example, the terminal can use the formula fac=t1*D(x)+t2 to calculate the shadow attenuation factor. Wherein, fac represents the shadow attenuation factor, t1 is the first transformation parameter, t2 is the second transformation parameter, and D(x) represents the function for calculating the depth-related value. For example, in the case of orthogonal projection, D(x) is the calculation formula for the depth value, and in the case of perspective projection, D(x) is the calculation formula for the depth value without perspective division. Wherein, the first transformation parameter and the second transformation parameter satisfy the constraint conditions.
[0070] In some embodiments, the first preset value is 0, the second preset value is 1, In the case of , the first transformation parameter and the second transformation parameter that satisfy the constraint conditions are: exist In the case of , the first transformation parameter and the second transformation parameter that satisfy the constraint conditions are: exist In the case of , the first transformation parameter and the second transformation parameter that satisfy the constraint conditions are: exist In the case of , the first transformation parameter and the second transformation parameter that satisfy the constraint conditions are:
[0071] In this embodiment, since the result of the linear transformation is the first preset value when the shadow space distance is consistent with the attenuation starting distance, and the result of the linear transformation is the second preset value when the shadow space distance is consistent with the attenuation ending distance, the first preset value is smaller than the second preset value. Therefore, in the process of the shadow space distance changing from the attenuation starting distance to the attenuation ending distance, that is, in the process of the shadow space distance gradually increasing, the result of the linear transformation gradually increases from the first preset value to the second preset value, that is, the shadow attenuation factor gradually increases from the first preset value to the second preset value. In other words, the shadow attenuation factor increases with the increase of the shadow space distance, which is consistent with the real phenomenon of soft shadows.
[0072] In some embodiments, determining the depth-related value of a pixel point based on the shadow space distance of the pixel point under the light source includes: when the shadow camera is an orthogonal projection camera, determining the pixel depth value based on the shadow space distance of the pixel point under the light source; and determining the pixel depth value as the depth-related value of the pixel point.
[0073] Specifically, the shadow camera is an orthogonal projection camera, which means that the projection method of the shadow camera is orthogonal projection. In the case of orthogonal projection, since the pixel depth value is linearly related to the shadow space distance, the terminal can determine the pixel depth value as the depth-related value of the pixel point.
[0074] In this embodiment, the pixel depth value is determined as the depth-related value of the pixel point, so that the depth-related value is obtained conveniently and quickly.
[0075] In some embodiments, the method further includes: when the shadow camera is a perspective projection camera, determining a depth-related value of the pixel point based on the shadow space distance of the pixel point under the light source; wherein the pixel depth value is the ratio of the depth-related value of the pixel point to the shadow space position.
[0076] Specifically, since the pixel depth value is the ratio of the depth-related value of the pixel point to the shadow space position, the depth-related value of the pixel point refers to the pixel depth value without perspective division. Since the pixel depth value is nonlinear with the shadow space position when the projection type is perspective projection, the pixel depth value is linear with the shadow space position, and the pixel depth value without perspective division is linear with the shadow space position. Therefore, the depth-related value of the pixel point is linear with the shadow space position. For example, when the depth calculation method is the forward depth calculation method, the pixel depth value is The pixel depth value without perspective division is Obviously, the pixel depth value without perspective division is linearly related to x.
[0077] In this embodiment, since the pixel depth value is the ratio of the depth correlation value of the pixel point to the shadow space position, a depth correlation value having a linear relationship with the shadow space distance is obtained.
[0078] In some embodiments, performing a linear transformation on the depth-related value of the pixel point based on the linear transformation rendering parameters of the light source to obtain a shadow attenuation factor of the pixel point includes: performing a linear transformation on the depth-related value of the pixel point based on the linear transformation rendering parameters of the light source to obtain a linear transformation value; and determining the shadow attenuation factor of the pixel point based on the linear transformation value and an attenuation factor threshold.
[0079] The attenuation factor threshold includes at least one of a first attenuation factor threshold or a second attenuation factor threshold, and the first attenuation factor threshold is smaller than the second attenuation factor threshold. For example, the first attenuation factor threshold is a value close to 0, such as 0 or 0.1. The second attenuation factor threshold is a value close to 1, such as 1 or 0.9.
[0080] Specifically, the terminal can perform a linear transformation on the depth-related value of the pixel point based on the linear transformation rendering parameter of the light source to obtain a linear transformation value. When the linear transformation value is less than the first attenuation factor threshold, the terminal can use the first attenuation factor threshold as the shadow attenuation factor of the pixel point. When the linear transformation value is greater than the second attenuation factor threshold, the terminal can use the second attenuation factor threshold as the shadow attenuation factor of the pixel point. When the linear transformation value is greater than or equal to the first attenuation factor threshold and the linear transformation value is less than or equal to the second attenuation factor threshold, the terminal can use the linear transformation value as the shadow attenuation factor of the pixel point.
[0081] Taking the first attenuation factor threshold as 0 and the second attenuation factor threshold as 1 as an example, the shadow attenuation factor factor can be calculated by the formula factor = saturate (posL.z*t1+t2). Among them, when the calculation result of posL.z*t1+t2 is less than 0, the result of the saturate function is 0, so the shadow attenuation factor factor = 0, when the calculation result of posL.z*t1+t2 is greater than 1, the result of the saturate function is 1, so the shadow attenuation factor factor = 1, when the calculation result of posL.z*t1+t2 is greater than or equal to 0 and less than or equal to 1, the result of the saturate function is the calculation result of posL.z*t1+t2, so the shadow attenuation factor factor = posL.z*t1+t2. posL.z represents the depth-related value, and t1 and t2 are two linear transformation rendering parameters.
[0082] In this embodiment, the shadow attenuation factor of the pixel is determined based on the linear transformation value and the attenuation factor threshold, thereby limiting the value range of the shadow attenuation factor and making the shadow attenuation factor more reasonable.
[0083] In some embodiments, determining the shadow space distance of a pixel point in the screen space under the light source includes: converting the world space position of the pixel point to the shadow camera space to obtain the shadow space position corresponding to the world space position; determining the distance between the shadow space position corresponding to the world space position and the shadow space position of the shadow camera in the observation direction of the shadow camera to obtain the shadow space distance of the pixel point under the light source.
[0084] The observation direction of the shadow camera refers to the orientation of the shadow camera. The shadow space position of the shadow camera refers to the position of the shadow camera in the shadow camera space. The shadow camera space can be identified by a three-dimensional coordinate system, and the direction of a coordinate axis in the three-dimensional coordinate system is the orientation of the shadow camera. For example, the direction of the Z axis in the three-dimensional coordinate system is the orientation of the shadow camera, so the observation direction of the shadow camera is the direction of the Z axis in the three-dimensional coordinate system.
[0085] Specifically, for a pixel point in the screen space, the terminal can determine the coordinates of the shadow space position corresponding to the world space position in the observation direction of the shadow camera, such as the coordinates in the Z-axis direction in the three-dimensional coordinate system of the shadow camera space, and obtain the first coordinate. Similarly, the terminal can determine the coordinates of the shadow space position of the shadow camera in the observation direction of the shadow camera, and obtain the second coordinate. The difference between the first coordinate and the second coordinate is calculated, and the difference is the shadow space distance of the pixel point under the light source.
[0086] In this embodiment, since the shadow space distance is the distance between the shadow space position corresponding to the world space position and the shadow space position of the shadow camera in the observation direction of the shadow camera, and the observation direction is consistent with the illumination direction of the light source, the shadow space position reflects the distance from the light source. Since the shadow far away from the light source has a larger attenuation, the shadow attenuation factor is determined using the shadow space distance, which improves the rationality of the shadow attenuation factor.
[0087] In some embodiments, the shadow of the pixel is rendered based on the shadow attenuation factor of the pixel to obtain the shadow rendering result of the virtual scene under the observation perspective, including: determining a first shadow intensity of the pixel under the light source; the first shadow intensity is one of a first preset intensity or a second preset intensity; the first preset intensity indicates that the light from the light source to the world space position of the pixel is blocked, and the second preset intensity indicates that the light from the light source to the world space position of the pixel is not blocked; the first shadow intensity of the pixel is attenuated by the shadow attenuation factor to obtain the second shadow intensity of the pixel under the light source; the shadow of the pixel is rendered based on the second shadow intensity to obtain the shadow rendering result of the virtual scene under the observation perspective.
[0088] Among them, the shadow intensity is used to reflect the obviousness of the shadow. The greater the shadow intensity, the more obvious the shadow. The first shadow intensity is one of the first preset intensity and the second preset intensity. The first preset intensity indicates that the light from the light source to the world space position of the pixel point is blocked. The second preset intensity indicates that the light from the light source to the world space position of the pixel point is not blocked. The first preset intensity is greater than the second preset intensity. The first preset intensity is, for example, a value near 1, such as 1 or 0.9, and the second preset intensity is, for example, a value near 0, such as 0 or 0.1. The second shadow intensity is negatively correlated with the shadow attenuation factor, and the second shadow intensity is positively correlated with the first shadow intensity.
[0089] Specifically, the terminal can determine the intensity retention value based on the shadow attenuation factor. The intensity retention value is negatively correlated with the shadow attenuation factor. For example, the intensity retention value = 1 - shadow attenuation factor. The terminal can multiply the intensity retention value by the first shadow intensity and use the result as the second shadow intensity. For example, the second shadow intensity intensity2 = (1 - factor) * intensity1. Where intensity1 represents the first shadow intensity, intensity2 represents the second shadow intensity, and factor represents the shadow attenuation factor.
[0090] In this embodiment, the shadow attenuation factor is used to attenuate the first shadow intensity of the pixel point to obtain the second shadow intensity of the pixel point under the light source, and the shadow of the pixel point is rendered based on the second shadow intensity, so that the shadow rendering result can present a soft shadow effect, thereby improving the shadow rendering effect.
[0091] In some embodiments, determining the first shadow intensity of a pixel point under a light source includes: converting the world space position of the pixel point to the shadow camera space of a shadow camera to obtain a shadow space position corresponding to the world space position; converting the shadow space position corresponding to the world space position to the screen space to obtain a screen space position corresponding to the world space position; determining the first shadow intensity of the pixel point under the light source based on the pixel depth value and the minimum depth value at the screen space position; the pixel depth value refers to the depth value of the world space position of the pixel point in the shadow camera space.
[0092] Among them, the shadow space position corresponding to the world space position refers to the position obtained by converting the world space position from world space to shadow camera space. The screen space position represents the position of the pixel point in screen space. The minimum depth value at the screen space position refers to the minimum depth value at the screen space position in screen space after the scene area observed by the shadow camera is projected into the screen space. Multiple scene points in the scene area observed by the shadow camera can be projected to the same position in the screen space, so that the screen space position can correspond to multiple scene points, and the depth value of the unobstructed scene point in the shadow camera space among the multiple scene points is the minimum depth value at the screen space position. The scene point is a point on a virtual object in the virtual scene. The virtual object can be a living object or an inanimate object, such as an animal, a building, or furniture. The world space position of a pixel point can also be understood as a point on a virtual object in the virtual scene.
[0093] Specifically, in order to determine the minimum depth value of the screen space position, for each of the multiple scene points corresponding to the screen space, the terminal can determine the distance between the position of the scene point in the shadow camera space and the shadow space position of the shadow camera in the observation direction of the shadow camera, and use the determined distance as the shadow space distance of the scene point under the light source. According to the shadow space distance of the scene point under the light source, the depth value of the scene point in the shadow camera space is determined. After obtaining the depth values of each of the multiple scene points, the terminal can determine the minimum depth value from each depth value as the minimum depth value at the screen space position. The method of determining the depth value based on the shadow space distance can refer to the above-mentioned method of determining the pixel depth value based on the shadow space distance, which will not be repeated here.
[0094] In some embodiments, the terminal may compare the pixel depth value with the minimum depth value at the screen space position, and determine the first shadow intensity of the pixel under the light source according to the comparison result.
[0095] In this embodiment, since the relationship between depth values can reflect the occlusion relationship, the first shadow intensity is determined by comparing the depth values, so that the first shadow intensity accurately reflects the occlusion relationship, thereby improving the accuracy of the first shadow intensity.
[0096] In some embodiments, the step of obtaining the minimum depth value at the screen space position includes: determining a shadow map of the light source; the shadow map includes the minimum depth value at each screen space position in the screen space after the scene area observed by the shadow camera is projected into the screen space; and obtaining the minimum depth value at the screen space position corresponding to the world space position from the shadow map.
[0097] Specifically, a shadow map includes the minimum depth value at each screen-space position in screen space after projecting the scene area observed by the shadow camera into screen space. The shadow map can be pre-generated. When rendering shadows using a light source, the minimum depth value at each screen-space position can be obtained from the light source's shadow map.
[0098] In this embodiment, the minimum depth value at the screen space position can be quickly obtained through the shadow map, thereby improving rendering efficiency.
[0099] In some embodiments, determining the first shadow intensity of the pixel point under the light source based on the pixel depth value and the minimum depth value at the screen space position includes: when the pixel depth value is greater than the minimum depth value at the screen space position, determining the first shadow intensity of the pixel point under the light source to be a first preset intensity; when the pixel depth value is less than or equal to the minimum depth value at the screen space position, determining the first shadow intensity of the pixel point under the light source to be a second preset intensity.
[0100] The first preset intensity indicates that the light from the light source to the world space position of the pixel is blocked. The second preset intensity indicates that the light from the light source to the world space position of the pixel is not blocked. The first preset intensity is greater than the second preset intensity. The first preset intensity is, for example, a value near 1, such as 1 or 0.9, and the second preset intensity is, for example, a value near 0, such as 0 or 0.1. The second shadow intensity is negatively correlated with the shadow attenuation factor and positively correlated with the first shadow intensity.
[0101] Specifically, when the pixel depth value is greater than the minimum depth value at the screen space position, it indicates that the light from the light source to the world space position of the pixel point is blocked. Therefore, when the pixel depth value is greater than the minimum depth value at the screen space position, the terminal can determine that the first shadow intensity of the pixel point under the light source is the first preset intensity. When the pixel depth value is less than or equal to the minimum depth value at the screen space position, it indicates that the light from the light source to the world space position of the pixel point is not blocked. Therefore, when the pixel depth value is less than or equal to the minimum depth value at the screen space position, the terminal can determine that the first shadow intensity of the pixel point under the light source is the second preset intensity.
[0102] In this embodiment, the value of the first shadow intensity is accurately determined by utilizing the fact that the pixel depth value is greater than the minimum depth value at the screen space position.
[0103] In some embodiments, the shadow of the pixel is rendered based on the second shadow intensity to obtain the shadow rendering result of the virtual scene under the observation perspective, including: determining the first color value of the pixel; the first color value refers to the color value of the pixel in the absence of a shadow; determining the second color value of the pixel based on the second shadow intensity and the first color value; and using the second color value of the pixel to render to obtain the shadow rendering result of the virtual scene under the observation perspective.
[0104] Among them, the first color value of the pixel point refers to the color value of the pixel point in the absence of shadow, that is, the color value of the pixel point without considering occlusion, that is, the color value of the pixel point under the assumption that the light source can illuminate the world space position of the pixel point.
[0105] Specifically, the second color value is negatively correlated with the second shadow intensity. The first terminal can determine a color retention coefficient based on the second shadow intensity. The color retention coefficient is negatively correlated with the second shadow intensity, and the product of the color retention coefficient and the second color value is used as the second color value. The color retention coefficient is a value between 0 and 1. For example, the color retention coefficient = 1 - the second shadow intensity, and the second color value = the first color value × (1 - the second shadow intensity).
[0106] In some embodiments, the terminal determines the world space position of each pixel in the screen space after projecting the target scene area into the screen space. The target scene area refers to the scene area observed when observing the virtual scene under the observation angle. For each pixel, the terminal can use the method for determining the shadow attenuation factor provided by the present application to obtain the shadow attenuation factor of the pixel according to the world space position of the pixel. When the shadow attenuation factor of each pixel is obtained, the second color value of each pixel is determined, and the shadow rendering result of the virtual scene under the observation angle is obtained by rendering using the second color value of each pixel. The shadow rendering result includes the shadow generated by the light source and presents a soft shadow effect. In the case of multiple light sources, each light source can be used in turn for rendering to obtain the shadow rendering result, so that the shadow rendering result includes the soft shadows generated by each light source.
[0107] In this embodiment, the second color value of the pixel is determined based on the second shadow intensity and the first color value, and the shadow rendering result of the virtual scene under the observation perspective is rendered using the second color value of the pixel, so that the shadow in the shadow rendering result presents a soft shadow effect, thereby improving the shadow rendering effect.
[0108] In some embodiments, as shown in FIG7 , a shadow rendering method is provided. The method may be executed by a terminal or jointly by a terminal and a server. The method is described using the terminal as an example, including the following steps:
[0109] Step 702 : determining the world space positions corresponding to the pixels in the screen space after the target scene area is projected into the screen space. The target scene area is the scene area observed when observing the virtual scene from an observation perspective.
[0110] Step 704 : For each pixel point, determine the distance between the shadow space position corresponding to the world space position of the pixel point and the shadow space position of the shadow camera in the observation direction of the shadow camera to obtain the shadow space distance of the pixel point under the light source.
[0111] The shadow camera is located at the light source position and observes the virtual scene from the illumination direction of the light source, that is, the direction of the shadow camera is consistent with the illumination direction of the light source.
[0112] Step 706: Determine a depth-related value of the pixel based on the shadow space distance of the pixel under the light source.
[0113] The depth-related value is linearly related to the shadow space distance, and the depth-related value is related to the pixel depth value. The pixel depth value refers to the depth value of the world space position of the pixel in the shadow camera space.
[0114] Step 708 : Based on the linear transformation rendering parameters of the light source, perform a linear transformation on the depth-related value of the pixel to obtain a shadow attenuation factor of the pixel.
[0115] Among them, the linear transformation rendering parameters meet the following constraints: when the shadow space distance is consistent with the attenuation start distance, the result of linearly transforming the depth-related values of the pixel points using the linear transformation rendering parameters is a first preset value; the attenuation start distance refers to the distance from the starting position of the shadow attenuation to the shadow camera in the shadow camera space; when the shadow space distance is consistent with the attenuation end distance, the result of linearly transforming the depth-related values of the pixel points using the linear transformation rendering parameters is a second preset value; the attenuation end distance refers to the distance from the end position of the shadow attenuation to the shadow camera in the shadow camera space; the first preset value is less than the second preset value.
[0116] Step 710: Determine the first shadow intensity of the pixel under the light source.
[0117] Among them, the first shadow intensity is one of a first preset intensity or a second preset intensity; the first preset intensity indicates that the light from the light source to the world space position of the pixel point is blocked, and the second preset intensity indicates that the light from the light source to the world space position of the pixel point is not blocked.
[0118] Step 712: Use the shadow attenuation factor to attenuate the first shadow intensity of the pixel point to obtain a second shadow intensity of the pixel point under the light source.
[0119] Step 714 : Render the shadow of the pixel point based on the second shadow intensity to obtain a shadow rendering result of the virtual scene under the observation perspective.
[0120] In this embodiment, a linear transformation rendering parameter determined by the attenuation start distance, attenuation end distance, or attenuation length is used to linearly transform the shadow spatial distance of a pixel under the light source to obtain the shadow attenuation factor of the pixel. This method implements a method for controlling the shadow attenuation factor using parameters (attenuation start distance, attenuation end distance, or attenuation length). This method for controlling the shadow attenuation factor is simple and efficient, with low computational complexity, improving the rendering efficiency of soft shadows. Figure 8 shows the effects of both the absence and presence of shadow attenuation.
[0121] The shadow rendering method provided in this application can be applied to any scene that requires shadow rendering, including but not limited to scenes such as film and television special effects, games, mirror simulation, visual design, VR (Virtual Reality), industrial simulation, and digital cultural creation. The shadow rendering method provided in this application can improve the efficiency of shadow rendering in scenes such as film and television special effects, visual design, games, mirror simulation, VR, industrial simulation, and digital cultural creation.
[0122] For game scenes with shadows, the terminal can determine the world space position corresponding to each pixel in the screen space after projecting the observed game scene area onto the screen space. It can also determine the shadow space distance of the pixel in the screen space under the light source. Based on the linear transformation rendering parameters of the light source, it can perform a linear transformation on the shadow space distance of the pixel under the light source to obtain the shadow attenuation factor of the pixel. The shadow of the pixel is then rendered based on the shadow attenuation factor to obtain the shadow rendering result for the game scene. This improves rendering efficiency while rendering soft shadows.
[0123] For industrial simulation scenarios, to render the shadows cast by simulated objects under lighting, the terminal can determine the world space position corresponding to each pixel in the screen space after projecting the observed industrial simulation scene area onto the screen space. It then determines the shadow space distance of the pixel in the screen space under the light source. Based on the linear transformation rendering parameters of the light source, it performs a linear transformation on the shadow space distance of the pixel under the light source to obtain the shadow attenuation factor of the pixel. The shadow of the pixel is then rendered based on the shadow attenuation factor to obtain the shadow rendering result for the industrial simulation scene. This improves rendering efficiency while rendering soft shadows.
[0124] It should be understood that, although the various steps in the flowcharts involved in the various embodiments described above are displayed in sequence according to the instructions of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowcharts involved in the various embodiments described above can include multiple steps or multiple stages, and these steps or stages are not necessarily executed and completed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of steps or stages in other steps.
[0125] Based on the same inventive concept, embodiments of the present application also provide a shadow rendering device for implementing the aforementioned shadow rendering method. The solution provided by this device is similar to the solution described in the aforementioned method. Therefore, the specific limitations of one or more shadow rendering device embodiments provided below can be found in the above-described limitations of the shadow rendering method and will not be further elaborated here.
[0126] In some embodiments, as shown in FIG9 , a shadow rendering apparatus is provided, including: a distance determination module 902 , a factor determination module 904 , and a shadow rendering module 906 , wherein:
[0127] The distance determination module 902 is used to determine the shadow space distance of a pixel point in the screen space under the light source when observing the virtual scene from an observation perspective. The shadow space distance refers to the distance between the world space position of the pixel point and the shadow camera located at the light source position in the shadow camera space.
[0128] The factor determination module 904 is used to perform a linear transformation on the shadow space distance of the pixel under the light source based on the linear transformation rendering parameters of the light source to obtain the shadow attenuation factor of the pixel. The linear transformation rendering parameters are determined according to preset conditions set for the light source.
[0129] The shadow rendering module 906 is used to render the shadow of the pixel point based on the shadow attenuation factor of the pixel point to obtain the shadow rendering result of the virtual scene under the observation angle.
[0130] In some embodiments, the factor determination module 904 is also used to determine the depth-related value of the pixel point based on the shadow space distance of the pixel point under the light source; the depth-related value is linearly related to the shadow space distance, and the depth-related value is related to the pixel depth value, and the pixel depth value refers to the depth value of the world space position of the pixel point in the shadow camera space; the depth-related value of the pixel point is linearly transformed based on the linear transformation rendering parameters of the light source to obtain the shadow attenuation factor of the pixel point.
[0131] In some embodiments, the preset conditions include at least two of the attenuation start distance, the attenuation length or the attenuation end distance, the attenuation length is the difference between the attenuation start distance and the attenuation end distance, and the linear transformation rendering parameters meet the following constraints: when the shadow space distance is consistent with the attenuation start distance, the result of linearly transforming the depth-related value of the pixel point using the linear transformation rendering parameters is a first preset value; the attenuation start distance refers to the distance from the starting position of the shadow attenuation to the shadow camera in the shadow camera space; when the shadow space distance is consistent with the attenuation end distance, the result of linearly transforming the depth-related value of the pixel point using the linear transformation rendering parameters is a second preset value; the attenuation end distance refers to the distance from the ending position of the shadow attenuation to the shadow camera in the shadow camera space; the first preset value is less than the second preset value.
[0132] In some embodiments, the factor determination module 904 is further configured to determine a pixel depth value based on the shadow space distance of the pixel under the light source when the shadow camera is an orthographic projection camera; and determine the pixel depth value as a depth-related value of the pixel.
[0133] In some embodiments, the factor determination module 904 is further used to determine the depth-related value of the pixel point based on the shadow space distance of the pixel point under the light source when the shadow camera is a perspective projection camera; wherein the pixel depth value is the ratio of the depth-related value of the pixel point to the shadow space position.
[0134] In some embodiments, the factor determination module 904 is further used to perform a linear transformation on the depth-related value of the pixel point based on the linear transformation rendering parameters of the light source to obtain a linear transformation value; and determine the shadow attenuation factor of the pixel point based on the linear transformation value and the attenuation factor threshold.
[0135] In some embodiments, the distance determination module 902 is also used to convert the world space position of the pixel point into the shadow camera space to obtain the shadow space position corresponding to the world space position; determine the distance between the shadow space position corresponding to the world space position and the shadow space position of the shadow camera in the observation direction of the shadow camera to obtain the shadow space distance of the pixel point under the light source.
[0136] In some embodiments, the shadow rendering module 906 is also used to determine a first shadow intensity of a pixel point under a light source; the first shadow intensity is one of a first preset intensity or a second preset intensity; the first preset intensity indicates that the light from the light source to the world space position of the pixel point is blocked, and the second preset intensity indicates that the light from the light source to the world space position of the pixel point is not blocked; the first shadow intensity of the pixel point is attenuated using a shadow attenuation factor to obtain a second shadow intensity of the pixel point under the light source; the shadow of the pixel point is rendered based on the second shadow intensity to obtain a shadow rendering result of the virtual scene under the observation perspective.
[0137] In some embodiments, the shadow rendering module 906 is also used to convert the world space position of the pixel point to the shadow camera space of the shadow camera to obtain the shadow space position corresponding to the world space position; convert the shadow space position corresponding to the world space position to the screen space to obtain the screen space position corresponding to the world space position; determine the first shadow intensity of the pixel point under the light source based on the pixel depth value and the minimum depth value at the screen space position; the pixel depth value refers to the depth value of the world space position of the pixel point in the shadow camera space.
[0138] In some embodiments, the device also includes a depth value obtaining module, which is used to determine a shadow map of the light source; the shadow map includes the minimum depth value at each screen space position in the screen space after the scene area observed by the shadow camera is projected into the screen space; the minimum depth value at the screen space position corresponding to the world space position is obtained from the shadow map.
[0139] In some embodiments, the shadow rendering module 906 is further used to determine that the first shadow intensity of the pixel point under the light source is a first preset intensity when the pixel depth value is greater than the minimum depth value at the screen space position; and to determine that the first shadow intensity of the pixel point under the light source is a second preset intensity when the pixel depth value is less than or equal to the minimum depth value at the screen space position.
[0140] In some embodiments, the shadow rendering module 906 is also used to determine the first color value of the pixel point; the first color value refers to the color value of the pixel point in the absence of a shadow; the second color value of the pixel point is determined based on the second shadow intensity and the first color value; and the shadow rendering result of the virtual scene under the observation perspective is obtained by rendering using the second color value of the pixel point.
[0141] Each module in the shadow rendering device described above can be implemented in whole or in part through software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in the computer device in the form of software, so that the processor can call and execute the corresponding operations of each module.
[0142] In some embodiments, a computer device is provided, which may be a server, and its internal structure diagram may be as shown in Figure 10. The computer device includes a processor, memory, an input / output (I / O) interface, and a communication interface. The processor, memory, and I / O interface are connected via a system bus, and the communication interface is connected to the system bus via the I / O interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The database of the computer device is used to store data involved in a shadow rendering method. The I / O interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal via a network connection. When executed by the processor, the computer program implements a shadow rendering method.
[0143] In some embodiments, a computer device is provided, which may be a terminal. A diagram of its internal structure may be shown in Figure 11. The computer device includes a processor, memory, an input / output interface, a communication interface, a display unit, and an input device. The processor, memory, and input / output interface are connected via a system bus, and the communication interface, display unit, and input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and external devices. The communication interface of the computer device is used to communicate with external terminals via wired or wireless communication. The wireless communication may be achieved via Wi-Fi, a mobile cellular network, NFC (near-field communication), or other technologies. When executed by the processor, the computer program implements a shadow rendering method. The display unit of the computer device is used to form a visually visible image, and can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device casing, or an external keyboard, touchpad or mouse, etc.
[0144] Those skilled in the art will understand that the structures shown in Figures 10 and 11 are merely block diagrams of partial structures related to the solution of the present application, and do not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figures, or combine certain components, or have a different component arrangement.
[0145] In some embodiments, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned shadow rendering method when executing the computer program.
[0146] In some embodiments, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned shadow rendering method are implemented.
[0147] In some embodiments, a computer program product is provided, comprising a computer program, which implements the steps in the above shadow rendering method when executed by a processor.
[0148] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions.
[0149] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, database or other media used in the embodiments provided in this application may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory may include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in the various embodiments provided herein may include at least one of a relational database and a non-relational database. Non-relational databases may include, but are not limited to, distributed databases based on blockchains. The processor involved in the various embodiments provided herein may be, but are not limited to, a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic unit, a data processing logic unit based on quantum computing, and the like.
[0150] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0151] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art could make various modifications and improvements without departing from the spirit of the present application, all of which fall within the scope of protection of the present application. Therefore, the scope of protection of the present patent application shall be determined by the appended claims.
Claims
1. A shadow rendering method, performed by a computer device, the method comprising: Determine, under the observation angle of the virtual scene, a shadow space distance of a pixel point in the screen space under the light source of the virtual scene, wherein the shadow space distance refers to a distance between a world space position of the pixel point and a shadow camera located at the light source position in the shadow camera space; Based on the linear transformation rendering parameters of the light source, a linear transformation is performed on the shadow space distance of the pixel under the light source to obtain a shadow attenuation factor of the pixel, wherein the linear transformation rendering parameters are determined according to preset conditions set for the light source; Determine a first shadow intensity of the pixel under the light source, where the first shadow intensity is one of a first preset intensity and a second preset intensity, wherein the first preset intensity indicates that the light emitted from the light source to the world space position of the pixel is blocked, and the second preset intensity indicates that the light emitted from the light source to the world space position of the pixel is not blocked; Attenuating the first shadow intensity of the pixel point by using the shadow attenuation factor to obtain a second shadow intensity of the pixel point under the light source; and The shadow of the pixel point is rendered based on the second shadow intensity to obtain a shadow rendering result of the virtual scene under the observation perspective.
2. According to the method of claim 1, the step of performing a linear transformation on the shadow space distance of the pixel under the light source based on the linear transformation rendering parameter of the light source to obtain the shadow attenuation factor of the pixel comprises: Determine a depth-related value of the pixel based on the shadow space distance of the pixel under the light source, wherein the depth-related value is linearly related to the shadow space distance and is related to a pixel depth value, and the pixel depth value refers to a depth value of the world space position of the pixel under the shadow camera space; A linear transformation is performed on the depth-related value of the pixel point based on the linear transformation rendering parameter of the light source to obtain a shadow attenuation factor of the pixel point.
3. The method according to claim 2, wherein the preset condition comprises at least two of a decay start distance, a decay length, or a decay end distance, wherein the decay length is a difference between the decay start distance and the decay end distance, and the linear transformation rendering parameter satisfies the following constraints: In a case where the shadow space distance is consistent with the attenuation start distance, a result of linearly transforming the depth-related value of the pixel point using the linear transformation rendering parameter is a first preset value, and the attenuation start distance refers to the distance from the starting position of the shadow attenuation in the shadow camera space to the shadow camera; When the shadow space distance is consistent with the attenuation termination distance, the result of linearly transforming the depth-related value of the pixel point using the linear transformation rendering parameters is a second preset value, and the attenuation termination distance refers to the distance from the end position of the shadow attenuation in the shadow camera space to the shadow camera, and the first preset value is less than the second preset value.
4. The method according to claim 2 or 3, wherein determining the depth-related value of the pixel point based on the shadow space distance of the pixel point under the light source comprises: In the case where the shadow camera is an orthogonal projection camera, determining the pixel depth value based on the shadow space distance of the pixel point under the light source; The pixel depth value is determined as a depth-related value of the pixel point.
5. The method according to any one of claims 2 to 4, wherein when the shadow camera is a perspective projection camera, the pixel depth value is a ratio of a depth-related value of the pixel point to the shadow space position.
6. According to the method according to any one of claims 2 to 5, the linear transformation of the depth-related value of the pixel point based on the linear transformation rendering parameter of the light source to obtain the shadow attenuation factor of the pixel point comprises: Performing a linear transformation on the depth-related value of the pixel point based on a linear transformation rendering parameter of the light source to obtain a linear transformation value; A shadow attenuation factor of the pixel is determined based on the linear transformation value and an attenuation factor threshold.
7. The method according to any one of claims 1 to 6, wherein determining the shadow space distance of a pixel point in the screen space under the light source of the virtual scene comprises: Convert the world space position of the pixel point to the shadow camera space to obtain the shadow space position corresponding to the world space position; Determine the distance between the shadow space position corresponding to the world space position and the shadow space position of the shadow camera in the observation direction of the shadow camera to obtain the shadow space distance of the pixel point under the light source of the virtual scene.
8. The method according to any one of claims 1 to 7, wherein determining the first shadow intensity of the pixel under the light source comprises: Convert the world space position of the pixel point into the shadow camera space of the shadow camera to obtain the shadow space position corresponding to the world space position; Convert the shadow space position corresponding to the world space position to the screen space to obtain the screen space position corresponding to the world space position; Based on a pixel depth value and a minimum depth value at the screen space position, a first shadow intensity of the pixel point under the light source is determined, wherein the pixel depth value refers to a depth value of the world space position of the pixel point in the shadow camera space.
9. The method according to claim 8, wherein the step of obtaining the minimum depth value at the screen space position comprises: Determining a shadow map for the light source, the shadow map comprising a minimum depth value at each screen space position in screen space after projecting a scene area observed by a shadow camera into screen space; The minimum depth value at the screen space position corresponding to the world space position is obtained from the shadow map.
10. The method according to claim 8 or 9, wherein determining the first shadow intensity of the pixel under the light source based on the pixel depth value and the minimum depth value at the screen space position comprises: When the pixel depth value is greater than the minimum depth value at the screen space position, determining a first shadow intensity of the pixel point under the light source to be the first preset intensity; When the pixel depth value is less than or equal to the minimum depth value at the screen space position, the first shadow intensity of the pixel point under the light source is determined to be the second preset intensity.
11. According to the method according to any one of claims 1 to 10, rendering the shadow of the pixel point based on the second shadow intensity to obtain the shadow rendering result of the virtual scene under the observation angle comprises: Determine a first color value of the pixel, where the first color value refers to the color value of the pixel when there is no shadow; Determine a second color value of the pixel based on the second shadow intensity and the first color value; The shadow rendering result of the virtual scene under the observation angle is obtained by rendering using the second color value of the pixel point.
12. A shadow rendering device, the device comprising: A distance determination module is used to determine the shadow space distance of a pixel point in the screen space under the light source of the virtual scene under the observation angle of the virtual scene, wherein the shadow space distance refers to the distance between the world space position of the pixel point and the shadow camera located at the light source position in the shadow camera space; a factor determination module, configured to perform a linear transformation on the shadow space distance of the pixel under the light source based on a linear transformation rendering parameter of the light source to obtain a shadow attenuation factor of the pixel, wherein the linear transformation rendering parameter is determined according to a preset condition set for the light source; A shadow rendering module is used to render the shadow of the pixel point based on the shadow attenuation factor of the pixel point to obtain a shadow rendering result of the virtual scene under the observation angle.
13. A computer device comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method according to any one of claims 1 to 11 when executing the computer program.
14. A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the method according to any one of claims 1 to 11.
15. A computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Shadow rendering method, game file packaging method and corresponding devices
CN114119854A
Soft shadow generation method and device, equipment and storage medium
CN115546389A
Shadow rendering method and device, computer equipment and storage medium
CN116012520A
Shadow softening graphics processing unit and method
US20140176546A1
