A shadow rendering method, apparatus, device, and storage medium
By obtaining the opaque and transparent parts of the object to be rendered, generating corresponding shadow maps, and determining the target shadow brightness in combination with the depth of the lighting space, the problem of shadow brightness in the existing technology cannot be adjusted, and a personalized shadow rendering effect is achieved.
Patent Information
- Application Number
- CN202111506749.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-10
- Publication Date
- 2025-07-29
- Estimated Expiration
- 2041-12-10
AI Technical Summary
Existing shadow rendering methods cannot adjust shadow brightness according to object properties and cannot meet users' growing personalized needs.
By obtaining the opaque and transparent parts of the object to be rendered, rendering and generating opaque shadow maps and transparent shadow maps respectively, combining the depth of the lighting space to determine the target shadow brightness of each position point, and achieving different shadow rendering of different attribute parts.
It realizes different shadow rendering for different attribute parts of the rendered object, meets users' personalized needs and improves the realism and perspective effect of shadow rendering.
Smart Images

Figure CN114241117B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of graphics rendering technology, and in particular to a shadow rendering method, apparatus, device, and storage medium. Background Art
[0002] With the rapid development of 3D games, the implementation of lighting and shadows has become increasingly complex. By rendering shadows on 3D models, adding shadow effects to them can greatly enhance the realism of the game screen.
[0003] Currently, existing shadow rendering methods primarily include shadow mapping algorithms. In these algorithms, the spatial depth of each point in the rendered scene is used to determine whether each point is in shadow, thereby determining whether to add a shadow to that point. However, existing techniques set the same shadow brightness for all points in the shadow. This makes it impossible to adjust shadow brightness based on the corresponding object properties, failing to meet users' growing personalized needs. Summary of the invention
[0004] Embodiments of the present invention provide a shadow rendering method, apparatus, device, and storage medium, which can configure different shadow brightnesses for parts of a model to be rendered with different attributes, thereby meeting the growing personalized needs of users.
[0005] In a first aspect, an embodiment of the present invention provides a shadow rendering method, comprising:
[0006] Obtaining an object to be rendered, and obtaining an opaque part and a transparent part of the object to be rendered;
[0007] Rendering the opaque part and the transparent part of the object to be rendered respectively by using a preset light source to obtain an opaque shadow map and a transparent shadow map;
[0008] The light space depth of each position point of the object to be rendered is obtained, and the target shadow brightness of each position point of the object to be rendered is determined according to the light space depth, the opaque shadow map and the transparent shadow map of each position point of the object to be rendered.
[0009] In a second aspect, an embodiment of the present invention further provides a shadow rendering device, comprising:
[0010] The module for obtaining an object to be rendered is used to obtain an object to be rendered and obtain an opaque part and a transparent part of the object to be rendered;
[0011] A shadow map acquisition module is used to render the opaque part and the transparent part of the object to be rendered respectively through a preset light source to obtain an opaque shadow map and a transparent shadow map;
[0012] A target shadow brightness determination module, configured to obtain the light space depth of each position point of the object to be rendered, and determine the target shadow brightness of each position point of the object to be rendered according to the light space depth of each position point of the object to be rendered, the opaque shadow map, and the transparent shadow map.
[0013] In a third aspect, an embodiment of the present invention further provides an electronic device, which includes:
[0014] One or more processors;
[0015] A memory, configured to store one or more computer programs;
[0016] When the one or more computer programs are executed by the one or more processors, such that the one or more processors execute the computer programs, the shadow rendering method provided in any embodiment of the present invention is implemented.
[0017] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the shadow rendering method provided in any embodiment of the present invention is implemented.
[0018] The technical solution provided by the embodiment of the present invention includes: obtaining the object to be rendered, and obtaining the opaque part and the transparent part of the object to be rendered; then, respectively rendering the opaque part and the transparent part of the object to be rendered by a preset light source to obtain an opaque shadow map and a transparent shadow map; further, obtaining the light space depth of each position point of the object to be rendered, and determining the target shadow brightness of each position point of the object to be rendered according to the light space depth of each position point of the object to be rendered, the opaque shadow map, and the transparent shadow map; by dividing the object to be rendered according to the object attributes, and then configuring different shadow brightnesses for each position point of the object to be rendered based on the shadow maps of different attribute parts, the differential shadow rendering of different attribute parts of the object to be rendered can be realized, and the growing personalized needs of users can be satisfied. Description of the Drawings
[0019] Figure 1 is a flowchart of a shadow rendering method in an embodiment of the present invention;
[0020] Figure 2A is a flowchart of a shadow rendering method in another embodiment of the present invention;
[0021] Figure 2B is a schematic diagram of the effect of a shadow rendering method obtained by using the prior art;
[0022] Figure 2CIt is a schematic diagram of the effect of a shadow rendering method obtained by adopting the technical solution of the embodiment of the present invention;
[0023] Figure 2D It is a flowchart of a shadow rendering method in another embodiment of the present invention;
[0024] Figure 3 It is a schematic structural diagram of a shadow rendering device in another embodiment of the present invention;
[0025] Figure 4 It is a schematic structural diagram of an electronic device in another embodiment of the present invention. Detailed implementation manners
[0026] The embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although some embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. On the contrary, these embodiments are provided to more thoroughly and completely understand the present invention. It should be understood that the drawings and embodiments of the present invention are only for exemplary purposes and are not used to limit the protection scope of the present invention.
[0027] Figure 1 It is a flowchart of a shadow rendering method provided by an embodiment of the present invention. The embodiment of the present invention is applicable to the case of using shadow maps of different attribute parts of an object to be rendered to configure corresponding shadow brightnesses for different attribute parts of the object to be rendered; this method can be executed by a shadow rendering device, which can be composed of hardware and / or software and is generally integrated in an electronic device. Typically, it can be integrated in a computer device or a server. As Figure 1 shown, the method specifically includes the following steps:
[0028] S110. Obtain the object to be rendered, and obtain the opaque part and the transparent part of the object to be rendered.
[0029] Among them, the object to be rendered can be a 3D model established by a three-dimensional (3D) modeling tool (such as Maya, Houdini, etc.); for example, the object to be rendered can be a 3D character model. It can be understood that the object to be rendered can include many parts with different attributes; taking the transparent attribute as an example, the object to be rendered can include an opaque part and a transparent part.
[0030] In this embodiment, after completing the modeling of the object to be rendered, the object to be rendered can be divided according to the transparency attribute to obtain the opaque part and the transparent part of the object to be rendered. For example, when the object to be rendered is a 3D character model, the human body and opaque clothing can be regarded as the opaque part, and the transparent clothing (such as a tulle skirt) can be regarded as the transparent part. It should be noted that the transparent part includes a completely transparent part and a semi-transparent part. Specifically, when modeling the object to be rendered, the transparency attributes of each part can be marked, and then, according to the transparency attribute marks of each part of the object to be rendered, the opaque part and the transparent part of the object to be rendered can be obtained.
[0031] Optionally, the attributes of each part can also be determined according to the material of each part of the object to be rendered. Among them, when the object to be rendered is a 3D character model, the human body part of the 3D character model can be directly determined as the opaque part, and according to the material of each part of the clothing, it can be determined whether each part of the clothing has a transparent attribute or an opaque attribute; for example, if it is determined that a certain part of the clothing is made of tulle, it can be determined that this part is the transparent part.
[0032] S120. Render the opaque part and the transparent part of the object to be rendered respectively through a preset light source, and obtain an opaque shadow map and a transparent shadow map.
[0033] Among them, the preset light source is a light source pre-set in the rendering scene and is located above the object to be rendered; the preset light source can be a point light source or a parallel light source, and this embodiment does not make a specific limitation on this. It can be understood that light travels in a straight line in space. When there are other objects blocking between a certain point in space and the light source, this point cannot be illuminated by the light source, and then this point is in the shadow of the blocking object.
[0034] In this embodiment, after dividing the object to be rendered into an opaque part and a semi-transparent part, an opaque shadow map and a transparent shadow map can be calculated respectively through the shadow map algorithm (Shadow Map).
[0035] In an alternative implementation manner of this embodiment, rendering the opaque part and the transparent part of the object to be rendered respectively through a preset light source to obtain an opaque shadow map and a transparent shadow map may include: rendering the opaque part of the object to be rendered through the preset light source to obtain the first minimum light space depth of each position point of the object to be rendered, and generating an opaque shadow map according to the first minimum light space depth of each position point of the object to be rendered; rendering the transparent part of the object to be rendered through the preset light source to obtain the second minimum light space depth of each position point of the object to be rendered, and generating a transparent shadow map according to the second minimum light space depth of each position point of the object to be rendered.
[0036] Among them, the light space depth refers to the straight-line distance between a certain position point and the preset light source; the minimum light space depth refers to the minimum distance between the rendering object and the preset light source on the line connecting a certain position point on the object to be rendered and the preset light source. It should be noted that when a certain position point on the object to be rendered is blocked, that is, when it cannot be irradiated by the preset light source; at this time, the light space depth corresponding to this position point is not the distance of its connection line with the preset light source, but the distance between the position point on the object to be rendered where the light first arrives and the preset light source on the connection line between this position point and the preset light source, that is, the minimum distance.
[0037] Specifically, the preset light source is used to irradiate the opaque part and the transparent part of the object to be rendered in the rendering scene respectively, so as to obtain the minimum light space depth between each position point on the object to be rendered and the preset light source in the two cases, that is, the first minimum light space depth and the second minimum light space depth. Further, the first minimum light space depth and the second minimum light space depth of each obtained position point are stored respectively to obtain an opaque shadow map and a transparent shadow map, that is, an opaque depth texture map and a transparent depth texture map. Among them, the data format stored in the shadow map is a 32-bit floating-point numerical value.
[0038] S130. Obtain the light space depth of each position point of the object to be rendered, and determine the target shadow brightness of each position point of the object to be rendered according to the light space depth of each position point of the object to be rendered, the opaque shadow map and the transparent shadow map.
[0039] In this embodiment, after obtaining the opaque shadow map and the transparent shadow map, the space depth of each position point of the object to be rendered from the screen perspective can be obtained and converted into the space depth from the perspective of the preset light source to obtain the light space depth of each position point. It should be noted that the current light space depth of each position point is the actual distance between each position point and the preset light source.
[0040] Further, the light space depth of each position point of the object to be rendered can be compared with the first minimum light space depth of the corresponding position point in the opaque shadow map. If the light space depth is less than or equal to the corresponding first minimum light space depth, it means that this position point is not blocked, that is, this position point is not in the shadow; and if the light space depth is greater than the corresponding first minimum light space depth, it means that this position point is blocked, that is, this position point is in the shadow.
[0041] In this embodiment, different shadow brightnesses can be set for each position point in the shadow and not in the shadow. Thus, the first shadow brightness of each position point can be obtained; for example, for the position points in the shadow, set their shadow brightness to 0; for the position points not in the shadow, set their shadow brightness to 1.
[0042] Similarly, the light space depth of each position point of the object to be rendered is compared with the second smallest light space depth of the corresponding position point in the transparent shadow map, and it is determined again whether each position point is in the shadow, and the corresponding second shadow brightness is configured for each position point. Thus, for each position point of the model to be rendered, two corresponding sets of shadow brightness can be obtained, namely the first shadow brightness and the second shadow brightness. Further, the weights corresponding to the first shadow brightness and the second shadow brightness can be set respectively, and the weighted first shadow brightness and the second shadow brightness are multiplied to determine the final target shadow brightness corresponding to each position point.
[0043] In this embodiment, by dividing the object to be rendered into an opaque part and a transparent part, and respectively obtaining the corresponding opaque shadow map and transparent shadow map, for each position point of the object to be rendered, the shadow brightness corresponding to the opaque attribute and the shadow brightness corresponding to the transparent attribute can be obtained respectively. Furthermore, by adjusting the weights of the shadow brightness corresponding to different attributes, shadows with different brightness can be added to the parts of the object to be rendered with different attributes, meeting the personalized needs of users.
[0044] In an optional implementation manner of this embodiment, obtaining the light space depth of each position point of the object to be rendered may include: obtaining the initial space depth of each position point of the object to be rendered in the screen view coordinate system, and obtaining the space transformation matrix between the screen view coordinate system and the preset light source view coordinate system; according to the initial space depth of each position point of the object to be rendered in the screen view coordinate system and the space transformation matrix, obtaining the light space depth of each position point of the object to be rendered.
[0045] Among them, the screen view coordinate system is a rectangular coordinate system established with the computer screen as the (x, y) plane and the perpendicular line of the computer screen as the z-axis direction. The origin of the screen view coordinate system can be any point on the computer screen. The preset light source view coordinate system is a rectangular coordinate system established with the preset light source as the coordinate origin and the line connecting the preset light source and the vertex of the object to be rendered as the z-axis. The screen view coordinate system and the preset light source view coordinate system can be converted through the space transformation matrix.
[0046] It can be understood that both the opaque shadow map and the transparent shadow map store the depth of each position point in the light space. Therefore, for each position point on the object to be rendered, it is necessary to obtain its position coordinates in the light space, and then obtain the actual light space depth of each position point. Specifically, the initial position coordinates and the initial space depth of each position point on the object to be rendered in the screen view coordinate system can be obtained first, and then the position coordinates of each position point in the preset light source view coordinate system can be obtained by multiplying the initial position coordinates with the space transformation matrix. Furthermore, in combination with the position coordinates of the preset light source, the light space depth of each position point can be obtained.
[0047] In another optional implementation manner of this embodiment, obtaining the space transformation matrix between the screen view coordinate system and the preset light source view coordinate system may include: respectively determining the first space transformation matrix between the screen view coordinate system and the world coordinate system, and the second space transformation matrix between the preset light source view coordinate system and the world coordinate system; determining the space transformation matrix between the screen view coordinate system and the preset light source view coordinate system according to the first space transformation matrix and the second space transformation matrix. Among them, the world coordinate system is a standard rectangular coordinate system established in advance in the rendering scene.
[0048] In this embodiment, when calculating the space transformation matrix between the screen view coordinate system and the preset light source view coordinate system, the first space transformation matrix A between the screen view coordinate system and the world coordinate system, and the second space transformation matrix B between the preset light source view coordinate system and the world coordinate system can be calculated first. Then, the space transformation matrix between the world coordinate system and the preset light source view coordinate system is B -1 ; Thus, the space transformation matrix between the screen view coordinate system and the preset light source view coordinate system can be calculated as A·B -1 .
[0049] The technical solution provided by the embodiments of the present invention obtains the object to be rendered and obtains the opaque part and the transparent part of the object to be rendered; then, the opaque part and the transparent part of the object to be rendered are respectively rendered by a preset light source to obtain an opaque shadow map and a transparent shadow map; further, the light space depth of each position point on the object to be rendered is obtained, and the target shadow brightness of each position point on the object to be rendered is determined according to the light space depth, the opaque shadow map, and the transparent shadow map of each position point on the object to be rendered; by dividing the object to be rendered according to the object attributes, and then configuring different shadow brightnesses for each position point on the object to be rendered based on the shadow maps of different attribute parts, differential shadow rendering of different attribute parts of the object to be rendered can be realized, which can meet the growing personalized needs of users.
[0050] Figure 2AThe flowchart of the shadow rendering method provided by another embodiment of the present invention. This embodiment is based on the above technical solution. In this embodiment, the first shadow brightness and the second shadow brightness of each position point of the object to be rendered are calculated according to the opaque shadow map and the transparent shadow map respectively, and the target shadow brightness of each position point is determined according to the first shadow brightness and the second shadow brightness of each position point; as Figure 2A shown, the method includes:
[0051] S210. Obtain the object to be rendered, and obtain the opaque part and the transparent part of the object to be rendered.
[0052] S220. Render the opaque part of the object to be rendered through a preset light source, obtain the first minimum light space depth of each position point of the object to be rendered, and generate an opaque shadow map according to the first minimum light space depth of each position point of the object to be rendered.
[0053] S230. Render the transparent part of the object to be rendered through a preset light source, obtain the second minimum light space depth of each position point of the object to be rendered, and generate a transparent shadow map according to the second minimum light space depth of each position point of the object to be rendered.
[0054] S240. Obtain the light space depth of each position point of the object to be rendered.
[0055] S250. Determine the first shadow brightness of each position point of the object to be rendered according to the light space depth of each position point of the object to be rendered and the opaque shadow map; and determine the second shadow brightness of each position point of the object to be rendered according to the light space depth of each position point of the object to be rendered and the transparent shadow map.
[0056] In this embodiment, it is possible to respectively determine whether the light space depth of each position point of the object to be rendered is less than the first minimum light space depth of the corresponding position point in the opaque shadow map; if so, it is determined that the position point is not in the shadow, and the first shadow brightness of the position point is set to a preset first shadow brightness parameter; otherwise, it is determined that the position point is in the shadow, and the first shadow brightness of the position point is set to a preset second shadow brightness parameter, and the first shadow brightness of each position point of the object to be rendered with the configuration completed is obtained;
[0057] Further, determine whether the light space depth of each position point of the object to be rendered is less than the second minimum light space depth of the corresponding position point in the transparent shadow map; if so, determine that the position point is not in the shadow, and set the second shadow brightness of the position point to a preset first shadow brightness parameter; otherwise, determine that the position point is in the shadow, set the second shadow brightness of the position point to a preset second shadow brightness parameter, and obtain the second shadow brightness of each position point of the configured object to be rendered.
[0058] Among them, the preset first shadow brightness parameter is the shadow brightness parameter value corresponding to the position point not in the shadow set in advance; correspondingly, the preset second shadow brightness parameter is the shadow brightness parameter value corresponding to the position point in the shadow set in advance. For example, the preset first shadow brightness parameter can be 1, and the preset second shadow brightness parameter can be 0.
[0059] In this embodiment, the light space depth of each position point of the object to be rendered can be compared with the first minimum light space depth of the corresponding position point in the opaque shadow map and the second minimum light space depth of the corresponding position point in the transparent shadow map respectively, so as to determine whether each position point is in the shadow, and further determine the first shadow brightness and the second shadow brightness corresponding to each position point.
[0060] S260. Determine the target shadow brightness of each position point of the object to be rendered according to the first shadow brightness and the second shadow brightness of each position point of the object to be rendered.
[0061] In an optional implementation manner of this embodiment, determining the target shadow brightness of each position point of the object to be rendered according to the first shadow brightness and the second shadow brightness of each position point of the object to be rendered may include: calculating the target shadow brightness L of each position point according to the formula: L = L0×(1.0 - (1.0 - T0)×M); where L0 represents the first shadow brightness of the position point, T0 represents the second shadow brightness of the position point, and M represents a preset transparency brightness parameter, and the value range of M is from 0 to 1.
[0062] Optionally, the value ranges of the first shadow brightness, the second shadow brightness, and the target shadow brightness are all [0, 1]; when the shadow brightness is 0, it means that the position point is in the shadow, and when the shadow brightness is 1, it means that the position point is not in the shadow.
[0063] In this embodiment, calculating the target shadow brightness based on the above formula can adjust the shadow brightness of the transparent part of the object to be rendered by setting the corresponding transparency brightness parameter; among them, the shadow brightness of the transparent part can be made consistent with the shadow brightness of other parts, or a larger shadow brightness can be configured for the transparent part, which can achieve a certain perspective effect while ensuring the realism of the object to be rendered.
[0064] To more clearly and intuitively illustrate the technical effects of the embodiments of the present invention, the rendering effect diagrams before and after using the solutions of the embodiments of the present invention will be compared and described. Among them, Figure 2B is a schematic diagram of the effect of a shadow rendering method obtained by using the prior art; Figure 2C is a schematic diagram of the effect of a shadow rendering method obtained by using the technical solution of the embodiment of the present invention.
[0065] Among them, taking the object to be rendered as Figure 2B the 3D character model shown, the legs of the current 3D character model are blocked by a transparent skirt. In the prior art, when performing shadow rendering for this 3D character model, it cannot recognize the attributes of each part of the 3D character model, so it can only add shadows with a unified brightness to each part. In Figure 2B it can be observed that the legs blocked by the transparent skirt are darker; and when the user needs to achieve a certain perspective effect, the prior art cannot meet the requirement.
[0066] To solve the above problems, in this embodiment, by obtaining the first shadow brightness corresponding to the opaque attribute and the second shadow brightness corresponding to the transparent attribute at each position point, and then by adjusting the transparent brightness parameter, the shadow brightness of the transparent part can be increased. As Figure 2C shown, even after shadow rendering, the legs behind the transparent skirt can still be clearly observed, making the legs look less dark and achieving a certain perspective effect.
[0067] The technical solution provided by the embodiment of the present invention, after obtaining the light space depth of each position point of the object to be rendered, determines the first shadow brightness of each position point of the object to be rendered according to the light space depth and the opaque shadow map of each position point of the object to be rendered; and determines the second shadow brightness of each position point of the object to be rendered according to the light space depth and the transparent shadow map of each position point of the object to be rendered, and then determines the target shadow brightness of each position point of the object to be rendered according to the first shadow brightness and the second shadow brightness of each position point of the object to be rendered; by separately obtaining the first shadow brightness and the second shadow brightness of each position point of the object to be rendered, the adjustment of the shadow brightness of the transparent part of the object to be rendered can be achieved by adjusting the weight parameters of the first shadow brightness and the second shadow brightness, a certain degree of perspective effect of the transparent part can be achieved, and the personalized needs of users can be satisfied.
[0068] In a specific implementation manner of this embodiment, as Figure 2DAs shown, first, the opaque part of the object to be rendered is rendered, and the first minimum light space depth of each position point of the object to be rendered is obtained and stored in the opaque shadow map; then, the transparent part of the object to be rendered is rendered, and the second minimum light space depth of each position point of the object to be rendered is obtained and stored in the transparent shadow map. Furthermore, the light space depth of each position point of the object to be rendered is obtained, and based on the light space depth of each position point of the object to be rendered and the opaque shadow map, the opaque shadow brightness L0 is calculated. Based on the light space depth of each position point of the object to be rendered and the transparent shadow map, the transparent shadow brightness T0 is calculated. Finally, according to the formula L0 * (1.0 - (1.0 - T0) * transparent brightness parameter), the target transparent brightness of each position point is calculated.
[0069] Figure 3 The following is a schematic structural diagram of a shadow rendering device provided by another embodiment of the present invention. As Figure 3 shown, the device includes: an object to be rendered acquisition module 310, a shadow map acquisition module 320, and a target shadow brightness determination module 330. Among them,
[0070] The object to be rendered acquisition module 310 is configured to acquire the object to be rendered and acquire the opaque part and the transparent part of the object to be rendered;
[0071] The shadow map acquisition module 320 is configured to render the opaque part and the transparent part of the object to be rendered respectively through a preset light source, and acquire an opaque shadow map and a transparent shadow map;
[0072] The target shadow brightness determination module 330 is configured to acquire the light space depth of each position point of the object to be rendered, and based on the light space depth of each position point of the object to be rendered, the opaque shadow map, and the transparent shadow map, determine the target shadow brightness of each position point of the object to be rendered.
[0073] The technical solution provided by the embodiment of the present invention acquires the object to be rendered and acquires the opaque part and the transparent part of the object to be rendered; then, the opaque part and the transparent part of the object to be rendered are respectively rendered through a preset light source to acquire an opaque shadow map and a transparent shadow map; further, the light space depth of each position point of the object to be rendered is acquired, and based on the light space depth of each position point of the object to be rendered, the opaque shadow map, and the transparent shadow map, the target shadow brightness of each position point of the object to be rendered is determined; by dividing the object to be rendered according to the object attributes, and then based on the shadow maps of different attribute parts, different shadow brightnesses are configured for each position point of the object to be rendered, which can realize the differential shadow rendering of different attribute parts of the object to be rendered and meet the growing personalized needs of users.
[0074] Optionally, based on the above technical solution, the shadow map acquisition module 320 includes:
[0075] An opaque shadow map generation unit, configured to render the opaque part of the object to be rendered through a preset light source, obtain the first minimum light space depth of each position point of the object to be rendered, and generate an opaque shadow map according to the first minimum light space depth of each position point of the object to be rendered;
[0076] A transparent shadow map generation unit, configured to render the transparent part of the object to be rendered through a preset light source, obtain the second minimum light space depth of each position point of the object to be rendered, and generate a transparent shadow map according to the second minimum light space depth of each position point of the object to be rendered.
[0077] Optionally, based on the above technical solution, the target shadow brightness determination module 330 includes:
[0078] A shadow brightness determination unit, configured to determine the first shadow brightness of each position point of the object to be rendered according to the light space depth of each position point of the object to be rendered and the opaque shadow map; and determine the second shadow brightness of each position point of the object to be rendered according to the light space depth of each position point of the object to be rendered and the transparent shadow map;
[0079] A target shadow brightness determination unit, configured to determine the target shadow brightness of each position point of the object to be rendered according to the first shadow brightness and the second shadow brightness of each position point of the object to be rendered.
[0080] Optionally, based on the above technical solution, the target shadow brightness determination unit is specifically configured to calculate the target shadow brightness L of each position point according to the formula: L = L0 × (1.0 - (1.0 - T0) × M); where L0 represents the first shadow brightness of the position point, T0 represents the second shadow brightness of the position point, and M represents a preset transparency brightness parameter, and the value range of M is from 0 to 1.
[0081] Optionally, based on the above technical solution, the shadow brightness determination unit includes:
[0082] A first shadow brightness acquisition subunit, configured to respectively determine whether the light space depth of each position point of the object to be rendered is less than the first minimum light space depth of the corresponding position point in the opaque shadow map; if so, determine that the position point is not in the shadow, and set the first shadow brightness of the position point to a preset first shadow brightness parameter; otherwise, determine that the position point is in the shadow, and set the first shadow brightness of the position point to a preset second shadow brightness parameter, and obtain the first shadow brightness of each position point of the object to be rendered with the configuration completed;
[0083] A second shadow brightness acquisition subunit, configured to respectively determine whether the light space depth of each position point of the object to be rendered is less than the second minimum light space depth of the corresponding position point in the transparent shadow map; if so, determine that the position point is not in the shadow, and set the second shadow brightness of the position point to a preset first shadow brightness parameter; otherwise, determine that the position point is in the shadow, set the second shadow brightness of the position point to a preset second shadow brightness parameter, and obtain the second shadow brightness of each position point of the object to be rendered with the configuration completed.
[0084] Optionally, on the basis of the above technical solution, the target shadow brightness determination module 330 includes:
[0085] A space transformation matrix acquisition unit, configured to acquire the initial space depth of each position point of the object to be rendered in the screen view coordinate system, and acquire the space transformation matrix between the screen view coordinate system and the preset light source view coordinate system;
[0086] A light space depth acquisition unit, configured to acquire the light space depth of each position point of the object to be rendered according to the initial space depth of each position point of the object to be rendered in the screen view coordinate system and the space transformation matrix.
[0087] Optionally, on the basis of the above technical solution, the space transformation matrix acquisition unit includes:
[0088] A first space transformation matrix determination subunit, configured to respectively determine the first space transformation matrix between the screen view coordinate system and the world coordinate system, and the second space transformation matrix between the preset light source view coordinate system and the world coordinate system;
[0089] A space transformation matrix determination subunit, configured to determine the space transformation matrix between the screen view coordinate system and the preset light source view coordinate system according to the first space transformation matrix and the second space transformation matrix.
[0090] The above device can execute the shadow rendering method provided by the foregoing embodiments of the present invention, and has corresponding function modules and beneficial effects for executing the above method. For technical details not described in detail in the embodiments of the present invention, reference can be made to the shadow rendering method provided by the foregoing embodiments of the present invention.
[0091] Figure 4 A schematic structural diagram of an electronic device provided by another embodiment of the present invention is shown in Figure 4 As shown, the electronic device includes a processor 410, a memory 420, an input device 430, and an output device 440; the number of processors 410 in the electronic device can be one or more. Figure 4Take a processor 410 as an example; the processor 410, memory 420, input device 430, and output device 440 in the electronic device can be connected through a bus or other means. Figure 4 Take the connection through the bus as an example. The memory 420, as a computer-readable storage medium, can be used to store software programs, computer-executable programs, and modules, such as the program instructions / modules corresponding to a shadow rendering method in any embodiment of the present invention (for example, the object to be rendered acquisition module 310, shadow map acquisition module 320, and target shadow brightness determination module 330 in a shadow rendering device). The processor 410 executes various functional applications and data processing of the electronic device by running the software programs, instructions, and modules stored in the memory 420, that is, to implement the above-mentioned shadow rendering method. That is, when the program is executed by the processor, it realizes:
[0092] Acquire the object to be rendered, and acquire the opaque part and the transparent part of the object to be rendered;
[0093] Render the opaque part and the transparent part of the object to be rendered respectively through a preset light source, and acquire an opaque shadow map and a transparent shadow map;
[0094] Acquire the light space depth of each position point of the object to be rendered, and determine the target shadow brightness of each position point of the object to be rendered according to the light space depth, opaque shadow map, and transparent shadow map of each position point of the object to be rendered.
[0095] The memory 420 may mainly include a program storage area and a data storage area. Among them, the program storage area can store an operating system and application programs required for at least one function; the data storage area can store data created according to the use of the terminal, etc. In addition, the memory 420 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices. In some instances, the memory 420 may further include a memory remotely set relative to the processor 410, and these remote memories can be connected to the electronic device through a network. Examples of the above network include but are not limited to the Internet, enterprise intranet, local area network, mobile communication network, and their combinations. The input device 430 can be used to receive input digital or character information, and generate key signal inputs related to the user settings and function controls of the electronic device, and may include a keyboard, a mouse, etc. The output device 440 may include a display device such as a display screen.
[0096] Optionally, the electronic device may be a server, which may be an independent server or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, Content Delivery Network (CDN), and big data and artificial intelligence platforms.
[0097] The embodiments of the present invention further provide a computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, it implements the method described in any embodiment of the present invention. Of course, the computer-readable storage medium provided by the embodiments of the present invention can perform the related operations in a shadow rendering method provided by any embodiment of the present invention. That is, when the program is executed by a processor, it implements:
[0098] Obtain the object to be rendered, and obtain the opaque part and the transparent part of the object to be rendered;
[0099] Render the opaque part and the transparent part of the object to be rendered respectively through a preset light source to obtain an opaque shadow map and a transparent shadow map;
[0100] Obtain the light space depth of each position point of the object to be rendered, and determine the target shadow brightness of each position point of the object to be rendered according to the light space depth, the opaque shadow map, and the transparent shadow map of each position point of the object to be rendered.
[0101] From the above description of the embodiments, those skilled in the art can clearly understand that the present invention can be implemented by means of software and necessary general-purpose hardware. Of course, it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as a floppy disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a FLASH memory, a hard disk, or an optical disc of a computer, and includes several instructions for causing an electronic device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in various embodiments of the present invention.
[0102] It should be noted that in the embodiments of the above shadow rendering device, the included units and modules are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be realized; in addition, the specific names of the functional units are only for the convenience of mutual distinction and do not limit the protection scope of the present invention.
[0103] Note that the above are only the preferred embodiments of the present invention and the technical principles applied. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein. Various obvious changes, re-adjustments, and substitutions can be made by those skilled in the art without departing from the protection scope of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments. Without departing from the concept of the present invention, more other equivalent embodiments can be included, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A shadow rendering method, characterized in that, Including: Obtain the object to be rendered, and obtain the opaque part and the transparent part of the object to be rendered; Render the opaque part of the object to be rendered through a preset light source, obtain the first minimum light space depth of each position point of the object to be rendered, and generate an opaque shadow map according to the first minimum light space depth of each position point of the object to be rendered; Render the transparent part of the object to be rendered through a preset light source, obtain the second minimum light space depth of each position point of the object to be rendered, and generate a transparent shadow map according to the second minimum light space depth of each position point of the object to be rendered; Obtain the light space depth of each position point of the object to be rendered, and determine the first shadow brightness of each position point of the object to be rendered according to the light space depth of each position point of the object to be rendered and the opaque shadow map; And determine the second shadow brightness of each position point of the object to be rendered according to the light space depth of each position point of the object to be rendered and the transparent shadow map; According to the formula: L = L0 × (1.0 - (1.0 - T0) × M), calculate the target shadow brightness L of each position point; where, L0 represents the first shadow brightness of the position point, T0 represents the second shadow brightness of the position point, and M represents a preset transparent brightness parameter, and the value range of M is from 0 to 1.
2. The method according to claim 1, characterized in that Determine the first shadow brightness of each position point of the object to be rendered according to the light space depth of each position point of the object to be rendered and the opaque shadow map; And determine the second shadow brightness of each position point of the object to be rendered according to the light space depth of each position point of the object to be rendered and the transparent shadow map, including: Respectively judge whether the light space depth of each position point of the object to be rendered is less than the first minimum light space depth of the corresponding position point in the opaque shadow map; if so, determine that the position point is not in the shadow, and set the first shadow brightness of the position point to a preset first shadow brightness parameter; otherwise, determine that the position point is in the shadow, and set the first shadow brightness of the position point to a preset second shadow brightness parameter, and obtain the first shadow brightness of each position point of the object to be rendered with the configuration completed; Respectively judge whether the light space depth of each position point of the object to be rendered is less than the second minimum light space depth of the corresponding position point in the transparent shadow map; if so, determine that the position point is not in the shadow, and set the second shadow brightness of the position point to a preset first shadow brightness parameter; otherwise, determine that the position point is in the shadow, and set the second shadow brightness of the position point to a preset second shadow brightness parameter, and obtain the second shadow brightness of each position point of the object to be rendered with the configuration completed.
3. The method according to claim 1, wherein Obtain the light space depth of each position point of the object to be rendered, including: Obtain the initial space depth of each position point of the object to be rendered in the screen view coordinate system, and obtain the space transformation matrix between the screen view coordinate system and the preset light source view coordinate system; Obtain the light space depth of each position point of the object to be rendered according to the initial space depth of each position point of the object to be rendered in the screen view coordinate system and the space transformation matrix.
4. The method according to claim 3, wherein Obtaining the spatial transformation matrix between the screen view coordinate system and the preset light source view coordinate system includes: Respectively determining a first spatial transformation matrix between the screen view coordinate system and the world coordinate system, and a second spatial transformation matrix between the preset light source view coordinate system and the world coordinate system; Determining the spatial transformation matrix between the screen view coordinate system and the preset light source view coordinate system according to the first spatial transformation matrix and the second spatial transformation matrix.
5. A shadow rendering device, characterized in that, Including: A to-be-rendered object acquisition module, configured to acquire a to-be-rendered object, and acquire the opaque part and the transparent part of the to-be-rendered object; A shadow map acquisition module, configured to render the opaque part of the to-be-rendered object through a preset light source, obtain the first minimum light space depth of each position point of the to-be-rendered object, and generate an opaque shadow map according to the first minimum light space depth of each position point of the to-be-rendered object; Rendering the transparent part of the to-be-rendered object through a preset light source, obtaining the second minimum light space depth of each position point of the to-be-rendered object, and generating a transparent shadow map according to the second minimum light space depth of each position point of the to-be-rendered object; A target shadow brightness determination module, configured to acquire the light space depth of each position point of the to-be-rendered object, and determine the first shadow brightness of each position point of the to-be-rendered object according to the light space depth of each position point of the to-be-rendered object and the opaque shadow map; And determining the second shadow brightness of each position point of the to-be-rendered object according to the light space depth of each position point of the to-be-rendered object and the transparent shadow map; Calculating the target shadow brightness L of each position point according to the formula: L = L0 × (1.0 - (1.0 - T0) × M); where L0 represents the first shadow brightness of the position point, T0 represents the second shadow brightness of the position point, and M represents a preset transparency brightness parameter, and the value range of M is from 0 to 1.
6. An electronic device, characterized in that, Including: One or more processors; A memory, configured to store one or more computer programs; When the one or more computer programs are executed by the one or more processors, enabling the one or more processors to execute the computer programs to implement the shadow rendering method according to any one of claims 1-4.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, implementing the shadow rendering method according to any one of claims 1-4.
Citation Information
Patent Citations
Soft shadow casting circuit
JP2001101445A