A method and apparatus for shadow processing

By acquiring and merging multiple shadow maps, the shadow rendering process is optimized, solving the problems of high performance consumption and insufficient accuracy in existing technologies, and achieving efficient and accurate shadow rendering effects.

CN114863001BActive Publication Date: 2025-11-14NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210492245.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-07
Publication Date
2025-11-14
Estimated Expiration
2042-05-07

Smart Images

  • Figure CN114863001B_ABST
    Figure CN114863001B_ABST
Patent Text Reader

Abstract

This invention provides a method and apparatus for shadow processing. The method includes: acquiring multiple first shadow maps baked under the condition that the angle of the target 3D model relative to the lighting direction monotonically changes for a target 3D model; performing interpolation calculations on the multiple first shadow maps to obtain multiple second shadow maps; merging the multiple first shadow maps and the multiple second shadow maps to obtain a third shadow map; and rendering the target 3D model in combination with the third shadow map. This invention optimizes shadow rendering, avoids the performance overhead of rendering the entire scene at the light source location, and improves the accuracy of shadow rendering.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of rendering technology, and in particular to a method and apparatus for shadow processing. Background Technology

[0002] For 3D models, shadow rendering can make them look more realistic and allow the observer to understand the spatial relationship between objects. Specifically, shadow rendering can be performed by setting shadow maps in the engine and then binding shaders.

[0003] In existing technologies, rendering is usually performed from the perspective of the light source's position. Everything that can be seen will be illuminated by the light source, while what cannot be seen must be in shadow. The depth of the visible objects from the light source is recorded in a map. During actual rendering, each point in the scene is compared with this map to determine whether the current point can be illuminated by the light source, i.e., whether it is in shadow.

[0004] However, this method requires rendering the entire scene at the light source location, which consumes a lot of performance. Furthermore, because the entire scene is rendered, there will be accuracy issues with the shadow textures of some models, especially for facial models that require high precision, this drawback is more pronounced. Summary of the Invention

[0005] In view of the above problems, a method and apparatus for shadow processing are proposed to overcome or at least partially solve the above problems, comprising:

[0006] A method for shadow processing, the method comprising:

[0007] For the target 3D model, obtain multiple first shadow maps baked under the condition that the angle of the target 3D model relative to the lighting direction changes monotonically;

[0008] Multiple second shadow maps are obtained by interpolation calculation based on multiple first shadow maps;

[0009] Multiple first shadow maps and multiple second shadow maps are merged to obtain a third shadow map, and the target 3D model is rendered by combining the third shadow map.

[0010] Optionally, the target 3D model is rendered in conjunction with a third shadow map, including:

[0011] Determine the current angle of the target 3D model relative to the lighting direction;

[0012] For each pixel in the target 3D model, determine the target shadow value in the third shadow map, and determine the current shadow result associated with the current angle under the target shadow value;

[0013] Render the target 3D model based on the current shadow results.

[0014] Optionally, before determining the current shadow result associated with the current angle under the target shadow value, the method further includes:

[0015] For the third shadow map, based on the monotonic change of angle, the correlation between the angle of the target 3D model relative to the lighting direction and the shadow result under different shadow values ​​is determined.

[0016] Optionally, multiple first shadow maps and multiple second shadow maps are merged to obtain a third shadow map, including:

[0017] For the same pixels in multiple first shadow maps and multiple second shadow maps, the average of the recorded shadow values ​​is calculated to obtain the shadow value of the third shadow map.

[0018] Optionally, multiple second shadow maps are obtained by interpolation calculation based on multiple first shadow maps, including:

[0019] For each pixel contained in multiple first shadow maps, determine the distance information to its nearest boundary; where the boundary is the location where the shadow value of the pixel changes.

[0020] For two first shadow maps baked at adjacent angles, interpolation calculations are performed using distance information to obtain the second shadow map corresponding to the angle between adjacent angles.

[0021] Optionally, before performing interpolation calculations based on multiple first shadow maps to obtain multiple second shadow maps, the method further includes:

[0022] Adjust at least a portion of the first shadow maps from multiple first shadow maps.

[0023] Optionally, before adjusting at least some of the first shadow maps among multiple first shadow maps, the method further includes:

[0024] Binarize multiple first shadow maps.

[0025] An apparatus for shadow processing, the apparatus comprising:

[0026] The first shadow map acquisition module is used to acquire multiple first shadow maps for a target 3D model when the angle of the target 3D model relative to the lighting direction changes monotonically.

[0027] The second shadow map acquisition module is used to perform interpolation calculations based on multiple first shadow maps to obtain multiple second shadow maps;

[0028] The target 3D model rendering module is used to merge multiple first shadow maps and multiple second shadow maps to obtain a third shadow map, and then combine the third shadow map to render the target 3D model.

[0029] An electronic device includes a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements the shadow processing method described above.

[0030] A computer-readable storage medium on which a computer program is stored, wherein the computer program, when executed by a processor, implements the shadow processing method described above.

[0031] The embodiments of the present invention have the following advantages:

[0032] In this embodiment of the invention, multiple first shadow maps are baked for the target 3D model under the condition that the angle of the target 3D model relative to the lighting direction changes monotonically. Multiple second shadow maps are obtained by interpolation calculation based on the multiple first shadow maps. The multiple first shadow maps and the multiple second shadow maps are merged to obtain a third shadow map. The target 3D model is then rendered in combination with the third shadow map. This optimizes shadow rendering, avoids the performance consumption caused by rendering the entire scene at the light source position, and improves the accuracy of shadow rendering. Attached Figure Description

[0033] To more clearly illustrate the technical solution of the present invention, the accompanying drawings used in the description of the present invention will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0034] Figure 1 This is a flowchart illustrating the steps of a shadow processing method according to an embodiment of the present invention;

[0035] Figure 2a This is a shadow map provided in one embodiment of the present invention;

[0036] Figure 2b This is another shadow map provided in one embodiment of the present invention;

[0037] Figure 3 This is a flowchart of another shadow processing method provided in an embodiment of the present invention;

[0038] Figure 4 This is a structural block diagram of a shadow processing device provided in an embodiment of the present invention. Detailed Implementation

[0039] To make the above-mentioned objects, features, and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.

[0040] Reference Figure 1 The diagram illustrates a flowchart of a shadow processing method according to an embodiment of the present invention, which may specifically include the following steps:

[0041] Step 101: For the target 3D model, obtain multiple first shadow maps baked under the condition that the angle of the target 3D model relative to the lighting direction changes monotonically.

[0042] Among them, the target 3D model can be a model with high display accuracy requirements, and it can be a model of a part of a virtual object, such as the facial model of a virtual character in a game.

[0043] Before actual rendering, the target 3D model can be imported into the 3D software, and the UV settings of the target 3D model can be ensured to be correct. Then, a parallel light source can be set in the current scene for the target 3D model. The parallel light source can then simulate the lighting in application scenarios such as games. Under the parallel light source, the lighting direction of every point on the target 3D model is the same.

[0044] Based on this, the lighting direction can be adjusted by moving the light source, and the angle of the target 3D model relative to the lighting direction can be adjusted by adjusting the lighting direction (the angle of the target 3D model relative to the lighting direction can be the angle of the target 3D model's normal relative to the lighting direction). This allows for baking of the target 3D model at different angles, resulting in multiple first shadow maps. It should be noted that the operation of moving the light source to adjust the lighting direction can be done manually by the user or automatically by the program. Automating the lighting direction by the program simplifies the user operation.

[0045] To facilitate subsequent image shadow processing based on angle, it is necessary to ensure that the changes in shadows across multiple first shadow textures exhibit a certain regularity. Therefore, during the process of adjusting the lighting direction by moving the light source, it is possible to ensure that the angle of the target 3D model relative to the lighting direction changes monotonically. That is, the angle of the target 3D model relative to the lighting direction can only increase from small to large, or decrease from large to small. Correspondingly, for a point in the target 3D model, the change in shadow in the sequentially acquired multiple first shadow textures can only be from being in shadow to not being in shadow, or from not being in shadow to being in shadow.

[0046] When the target 3D model has a symmetrical structure, the first shadow map of only one symmetrical side of the target 3D model can be obtained. For example, when the target 3D model is a facial model, in the process of adjusting the lighting direction by moving the light source, the light source can be adjusted from directly behind the facial model to directly in front, or the light source can be adjusted from directly in front of the facial model to directly behind, to obtain the first shadow map corresponding to 180 degrees.

[0047] For the other side of the symmetry, after obtaining the third shadow map based on the first shadow map of one side that has already been collected, the third shadow map of the other side can be obtained by mirroring.

[0048] Step 102: Perform interpolation calculations based on multiple first shadow maps to obtain multiple second shadow maps.

[0049] To reduce resource consumption, we can select the angles with more obvious shadow changes for baking to obtain multiple first shadow maps. For shadow maps at other angles, we can interpolate multiple first shadow maps to obtain multiple second shadow maps.

[0050] In one embodiment of the present invention, step 102 may include:

[0051] Sub-step 11: For each pixel contained in multiple first shadow maps, determine the distance information to its nearest boundary; where the boundary is the position where the shadow value of the pixel changes.

[0052] For the first shadow map, a preset algorithm can be used to generate the corresponding SDF (Singed Distance Function / Field) image. The SDF image is used to record the distance between a point and the boundary of an object. In the embodiment of this invention, the SDF image can be used to record the distance between each pixel and its nearest boundary.

[0053] As an example, the preset algorithm can be a raster scanning algorithm, such as 8SSEDT (8-point Singed Sequential Euclidean Distance Transform).

[0054] Sub-step 12: For two first shadow maps baked at adjacent angles, interpolation calculation is performed by combining distance information to obtain the second shadow map corresponding to the angle between adjacent angles.

[0055] Since the first shadow map is baked at an angle where the shadow change is more obvious, if we want to obtain shadow maps at other angles, we can first determine two adjacent angles from the multiple angles where the first shadow map has been baked. For the same pixel, the distance information between the two first shadow maps corresponding to the two adjacent angles is different. Then, for the angle between the two adjacent angles, we can interpolate the distance information corresponding to the two adjacent angles to obtain the distance information corresponding to the angle between the two adjacent angles. Then, based on the distance information, we can obtain the second shadow map corresponding to the angle between the two adjacent angles, thus achieving the effect of smooth shadow transition.

[0056] For example, in the first shadow map corresponding to 30 degrees, a certain pixel is located at the boundary. In the first shadow map corresponding to 45 degrees, the distance between this pixel and the boundary is 15. Therefore, for angles between 30 and 45 degrees (with 1 degree as the smallest shadow map unit, i.e., 1 degree corresponds to one shadow map), using linear interpolation, we can obtain that in the second shadow map corresponding to 31 degrees, the distance between this pixel and the boundary should be 1; in the second shadow map corresponding to 32 degrees, the distance should be 2, and so on. It can be seen that in the shadow maps corresponding to angles between 30 and 45 degrees, the boundary of each image shifts slightly towards the boundary of the shadow map corresponding to 45 degrees, thus achieving a smooth transition between the two angles.

[0057] In one embodiment of the present invention, before step 102, the following may be included:

[0058] Adjust at least a portion of the first shadow maps from multiple first shadow maps.

[0059] Since the first shadow map obtained through light source baking is too realistic, when the target virtual model to be rendered needs to achieve a non-realistic style, such as a cartoon style, the shadow map can be imported into image editing software. Adjustments can be made to certain areas of the shadow map to better suit the desired style. For example, the area corresponding to the nose in a facial model can be adjusted to visually achieve a smaller nose effect, making the character appear cuter. After adjustment, this adjusted shadow map can be used as the first shadow map in step 102 for interpolation calculations.

[0060] By processing and adjusting the shadow map, the problem of poor effect of the original shadow rendering solution in cartoon rendering is solved. It has a high degree of customizability and can adapt to different styles of cartoon rendering. Users can display any effect they want to express according to their needs.

[0061] In one embodiment of the present invention, before adjusting at least a portion of the first shadow maps among a plurality of first shadow maps, the method may further include:

[0062] Binarize multiple first shadow maps.

[0063] For certain rendering styles, such as cartoon rendering, the shadows lack a penumbra, meaning pixels are either in or out of shadow without a transition. In such cases, a threshold can be set. The shadow value in the first shadow map is compared to this threshold; if it's greater than or equal to the threshold, it's set to 1; otherwise, it's set to 0, thus achieving binarization. Figure 2a This is an unbinded shadow map, which contains gray areas in addition to black and white, such as... Figure 2b The resulting shadow map is binarized and contains only black and white regions. After obtaining the binarized first shadow map, adjustments can be made to at least a portion of the first shadow maps from multiple images, as described above.

[0064] Step 103: Merge multiple first shadow maps and multiple second shadow maps to obtain a third shadow map, and combine the third shadow map to render the target 3D model.

[0065] After obtaining multiple first shadow maps and multiple second shadow maps, shadow maps corresponding to all angles are obtained. Then, all shadow maps can be merged to obtain a third shadow map. This third shadow map can then be imported into the engine. In actual rendering, this third shadow map can be passed to the shader for calculation to perform shadow rendering. Since it is a pre-processed map, the overhead of rendering the scene at the light source position during traditional shadow mapping is eliminated.

[0066] Moreover, by rendering the target 3D model, the accuracy requirements of models such as faces are ensured, avoiding problems such as jagged edges during actual use.

[0067] In one embodiment of the present invention, merging multiple first shadow maps and multiple second shadow maps to obtain a third shadow map may include:

[0068] Sub-step 21: For the same pixels in multiple first shadow maps and multiple second shadow maps, calculate the average of the recorded shadow values ​​to obtain the shadow value of the third shadow map.

[0069] For each shadow map, there are pixels in the same part of the model, and the shadow value corresponding to each pixel is recorded. Then, the average shadow value corresponding to the pixels in the same part can be calculated, and the obtained shadow value can be used as the shadow value corresponding to the pixels in the same part in the third shadow map.

[0070] In one embodiment of the present invention, rendering the target 3D model in conjunction with a third shadow map may include:

[0071] Sub-step 31: For the third shadow map, based on the monotonic change of angle, determine the correlation between the angle of the target 3D model relative to the lighting direction and the shadow result under different shadow values.

[0072] Since the angle of the target 3D model relative to the lighting direction is monotonically changing when baking multiple first shadow maps, and the second shadow map is obtained by interpolation calculation of the first shadow map, the angle of the target 3D model relative to the lighting direction is monotonically changing for all shadow maps. Accordingly, for multiple shadow maps collected under monotonically changing angles, the corresponding shadow change can only be from being in shadow to not being in shadow, or from not being in shadow to being in shadow.

[0073] Assuming all shadow maps are arranged according to a monotonically changing angle, for pixels in the same location, their shadow value in the sequentially arranged shadow maps should change monotonically, that is, from being in shadow to not being in shadow, or from not being in shadow to being in shadow.

[0074] In the case of binarization, the changes in shadow values ​​in the sequentially arranged shadow maps can be categorized into two cases (assuming there are M shadow maps, where M and N are both positive integers greater than 1, and N is less than M):

[0075] 1. The shaded values ​​of the first N images are all 0, and the shaded values ​​of the last MN images are all 1;

[0076] 2. The shaded values ​​of the first N images are all 1, and the shaded values ​​of the last MN images are all 0.

[0077] Furthermore, since the shadow value of the third shadow map is the average of the shadow values ​​in the shadow maps corresponding to all angles, it can reflect the shadow results (whether or not it is in shadow) at all angles. In other words, the shadow value of the third shadow map can record the relationship between angle and shadow result.

[0078] For example, a shadow value of 0.5 with a total of 180 degrees means that 90 degrees are in shadow and 90 degrees are not. Similarly, a shadow value of 1 / 180 with a total of 180 degrees means that 1 degree is in shadow and 179 degrees are not.

[0079] Sub-step 32: Determine the current angle of the target 3D model relative to the lighting direction.

[0080] In actual rendering, on the one hand, the world coordinates of the light source can be obtained, and the difference between them and the world coordinates of the target 3D model can be calculated and normalized to obtain the lighting direction. On the other hand, the world space normal of the target 3D model can be obtained using its position and then normalized.

[0081] After obtaining the lighting direction and normal, multiply the two by a dot product and then change the value range to [0, 1] to obtain the cosine value of the lighting direction and the normal of the target 3D model. This cosine value can be used to characterize the current angle of the target 3D model relative to the lighting direction. It can be further converted into an angle, or the cosine value can be used directly without conversion.

[0082] Sub-step 33: For a pixel in the target 3D model, determine the target shadow value in the third shadow map, and determine the current shadow result associated with the current angle under the target shadow value.

[0083] For a pixel in the target 3D model, the target shadow value corresponding to it can be determined in the third shadow map. Since the shadow value in the third shadow map can record the relationship between the angle and the shadow result, the current shadow result associated with the current angle can be determined.

[0084] Sub-step 34: Render the target 3D model based on the current shadow results.

[0085] After obtaining the current shadow result, the current shadow result can be used to render shadows on the corresponding pixels in the target 3D model.

[0086] In this embodiment of the invention, multiple first shadow maps are baked for the target 3D model under the condition that the angle of the target 3D model relative to the lighting direction changes monotonically. Multiple second shadow maps are obtained by interpolation calculation based on the multiple first shadow maps. The multiple first shadow maps and the multiple second shadow maps are merged to obtain a third shadow map. The target 3D model is then rendered in combination with the third shadow map. This optimizes shadow rendering, avoids the performance consumption caused by rendering the entire scene at the light source position, and improves the accuracy of shadow rendering.

[0087] Reference Figure 3 The diagram illustrates a flowchart of another shadow processing method provided by an embodiment of the present invention, which may specifically include the following steps:

[0088] Step 301: For the target 3D model, obtain multiple first shadow maps baked under the condition that the angle of the target 3D model relative to the lighting direction changes monotonically.

[0089] Step 302: Binarize multiple first shadow maps.

[0090] Step 303: Adjust at least some of the first shadow maps in the multiple first shadow maps.

[0091] Step 304: Perform interpolation calculations based on multiple first shadow maps to obtain multiple second shadow maps.

[0092] In one embodiment of the present invention, interpolation calculation based on multiple first shadow maps to obtain multiple second shadow maps may include:

[0093] For each pixel contained in multiple first shadow maps, the distance information to its nearest boundary is determined; for two first shadow maps baked at adjacent angles, interpolation calculation is performed by combining the distance information to obtain the second shadow map corresponding to the angle between adjacent angles.

[0094] The boundary represents the location where the shadow value of a pixel changes.

[0095] Step 305: Merge multiple first shadow maps and multiple second shadow maps to obtain a third shadow map, and combine the third shadow map to render the target 3D model.

[0096] In one embodiment of the present invention, merging multiple first shadow maps and multiple second shadow maps to obtain a third shadow map may include:

[0097] For the same pixels in multiple first shadow maps and multiple second shadow maps, the average of the recorded shadow values ​​is calculated to obtain the shadow value of the third shadow map.

[0098] In one embodiment of the present invention, rendering the target 3D model in conjunction with a third shadow map may include:

[0099] Determine the current angle of the target 3D model relative to the lighting direction; for each pixel in the target 3D model, determine the target shadow value in the third shadow map, and determine the current shadow result associated with the current angle under the target shadow value; combine the current shadow result to render the target 3D model.

[0100] In one embodiment of the present invention, before determining the current shadow result associated with the current angle under the target shadow value, the method may further include:

[0101] For the third shadow map, based on the monotonic change of angle, the correlation between the angle of the target 3D model relative to the lighting direction and the shadow result under different shadow values ​​is determined.

[0102] It should be noted that, for the sake of simplicity, the method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of the present invention are not limited to the described order of actions, because according to the embodiments of the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions involved are not necessarily essential to the embodiments of the present invention.

[0103] Reference Figure 4 The diagram shows a schematic representation of a shadow processing apparatus according to an embodiment of the present invention, which may specifically include the following modules:

[0104] The first shadow map acquisition module 401 can be used to acquire multiple first shadow maps baked for a target 3D model when the angle of the target 3D model relative to the lighting direction changes monotonically.

[0105] The second shadow map acquisition module 402 can be used to perform interpolation calculations based on multiple first shadow maps to obtain multiple second shadow maps.

[0106] The target 3D model rendering module 403 can be used to merge multiple first shadow maps and multiple second shadow maps to obtain a third shadow map, and then combine the third shadow map to render the target 3D model.

[0107] In one embodiment of the present invention, the target 3D model rendering module 403 may include:

[0108] The current angle determination submodule can be used to determine the current angle of the target 3D model relative to the lighting direction.

[0109] The Current Shadow Result Determination submodule can be used to determine the target shadow value in the third shadow map for pixels in the target 3D model, and determine the current shadow result associated with the current angle under the target shadow value.

[0110] The rendering submodule that combines the current shadow results can be used to render the target 3D model by combining the current shadow results.

[0111] In one embodiment of the present invention, it may further include:

[0112] The correlation determination module can be used to determine the correlation between the angle of the target 3D model relative to the lighting direction and the shadow result under different shadow values, based on the monotonic change of the angle, for the third shadow map.

[0113] In one embodiment of the present invention, the target 3D model rendering module 403 may include:

[0114] The third shadow map acquisition submodule is used to calculate the average of the recorded shadow values ​​for the same pixels in multiple first shadow maps and multiple second shadow maps, and obtain the shadow value of the third shadow map.

[0115] In one embodiment of the present invention, the second shadow mapping module 402 may include:

[0116] The distance information determination submodule can be used to determine the distance information of the nearest boundary to the pixels contained in multiple first shadow maps; where the boundary is the position where the shadow value of the pixel changes.

[0117] The interpolation calculation submodule can be used to perform interpolation calculations on two first shadow maps baked at adjacent angles, combining distance information, to obtain a second shadow map corresponding to the angle between adjacent angles.

[0118] In one embodiment of the present invention, it may further include:

[0119] The first shadow map adjustment module can be used to adjust at least some of the first shadow maps from multiple first shadow maps.

[0120] In one embodiment of the present invention, it may further include:

[0121] The first shadow map binarization module can be used to binarize multiple first shadow maps.

[0122] In this embodiment of the invention, multiple first shadow maps are baked for the target 3D model under the condition that the angle of the target 3D model relative to the lighting direction changes monotonically. Multiple second shadow maps are obtained by interpolation calculation based on the multiple first shadow maps. The multiple first shadow maps and the multiple second shadow maps are merged to obtain a third shadow map. The target 3D model is then rendered in combination with the third shadow map. This optimizes shadow rendering, avoids the performance consumption caused by rendering the entire scene at the light source position, and improves the accuracy of shadow rendering.

[0123] An embodiment of the present invention also provides an electronic device, which may include a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements the above-described shadow processing method.

[0124] An embodiment of the present invention also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the above-described shading method is implemented.

[0125] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.

[0126] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.

[0127] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, apparatus, or computer program products. Therefore, embodiments of the present invention can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of the present invention can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0128] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0129] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0130] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0131] Although preferred embodiments of the present invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present invention.

[0132] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.

[0133] The above provides a detailed description of the shadow processing method and apparatus. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, those skilled in the art will recognize that there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A method for shadow processing, characterized in that, The method includes: For the target 3D model, obtain multiple first shadow maps baked under the condition that the angle of the target 3D model relative to the lighting direction changes monotonically; Multiple second shadow maps are obtained by interpolation calculation based on the multiple first shadow maps; The multiple first shadow maps and the multiple second shadow maps are merged to obtain a third shadow map, and the target 3D model is rendered by combining the third shadow map. The rendering of the target 3D model in conjunction with the third shadow map includes: Determine the current angle of the target 3D model relative to the lighting direction; For each pixel in the target 3D model, the target shadow value in the third shadow map is determined, and the current shadow result associated with the current angle under the target shadow value is determined. Based on the current shadow results, the target 3D model is rendered; The step of merging the multiple first shadow maps and the multiple second shadow maps to obtain a third shadow map includes: For the same pixels in the multiple first shadow maps and the multiple second shadow maps, the average of the recorded shadow values ​​is calculated to obtain the shadow value of the third shadow map.

2. The method according to claim 1, characterized in that, Before determining the current shadow result associated with the current angle under the target shadow value, the method further includes: For the third shadow map, based on the monotonic change of the angle, the correlation between the angle of the target 3D model relative to the lighting direction and the shadow result under different shadow values ​​is determined.

3. The method according to any one of claims 1-2, characterized in that, The step of interpolating and calculating multiple second shadow maps based on the multiple first shadow maps includes: For each pixel contained in the plurality of first shadow maps, the distance information to its nearest boundary is determined; wherein, the boundary is the position where the shadow value of the pixel changes; For two first shadow maps baked at adjacent angles, interpolation calculations are performed using the distance information to obtain a second shadow map corresponding to the angle between the adjacent angles.

4. The method according to claim 1, characterized in that, Before performing interpolation calculations based on the multiple first shadow maps to obtain multiple second shadow maps, the method further includes: At least some of the first shadow maps in the plurality of first shadow maps are adjusted.

5. The method according to claim 4, characterized in that, Before adjusting at least a portion of the first shadow maps in the plurality of first shadow maps, the method further includes: The multiple first shadow maps are binarized.

6. A device for shadow processing, characterized in that, The device includes: The first shadow map acquisition module is used to acquire multiple first shadow maps baked for a target 3D model when the angle of the target 3D model relative to the lighting direction changes monotonically. The second shadow map obtaining module is used to perform interpolation calculations based on the multiple first shadow maps to obtain multiple second shadow maps; The target 3D model rendering module is used to merge the multiple first shadow maps and the multiple second shadow maps to obtain a third shadow map, and to render the target 3D model in combination with the third shadow map; The target 3D model rendering module includes: The current angle determination submodule can be used to determine the current angle of the target 3D model relative to the lighting direction; The current shadow result determination submodule can be used to determine the target shadow value in the third shadow map for pixels in the target 3D model, and determine the current shadow result associated with the current angle under the target shadow value; The rendering submodule that combines the current shadow results can be used to render the target 3D model by combining the current shadow results; The target 3D model rendering module includes: The third shadow map acquisition submodule is used to calculate the average of the recorded shadow values ​​for the same pixels in multiple first shadow maps and multiple second shadow maps, and obtain the shadow value of the third shadow map.

7. An electronic device, characterized in that, It includes a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements the shadow processing method as described in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, which, when executed by a processor, implements the shadow processing method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Method for displaying real-time shadow in virtual reality

    CN106355631A

  • Virtual model rendering method and device

    CN114067043A