Shadow map generation method and device, computer device, and storage medium
By generating a lighting model for a 3D model of a 2D object and correcting the original shadow map, the problem of low shadow map rendering efficiency in existing technologies is solved, and efficient generation of shadow effects with flexible adjustment is achieved.
Patent Information
- Application Number
- CN202210158352.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-21
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2042-02-21
AI Technical Summary
Existing technologies require drawing a large number of shadow maps to cope with changes in lighting direction and motion when adding shadow effects to two-dimensional objects, resulting in low efficiency.
By obtaining the 3D model and lighting direction of the 2D object, the lighting model is determined, and the original shadow map is corrected using the lighting model to generate a flexibly adjustable shadow map.
It enables flexible adjustment of shadow effects when the lighting direction and motion change, improving the efficiency of shadow map generation.
Smart Images

Figure CN114529656B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more specifically, to a method, apparatus, computer device, and storage medium for generating shadow maps. Background Technology
[0002] When rendering two-dimensional objects such as cartoon characters, shadow effects are added to enhance the realism of the rendered image. Since two-dimensional objects do not actually exist, shadow areas are usually determined manually and shadow maps are created accordingly. These shadow maps are then used to add shadow effects to the two-dimensional objects. This method results in relatively fixed shadow effects during rendering. If it is necessary to generate continuously changing visuals using two-dimensional objects, a large number of shadow maps need to be drawn, which is inefficient. Summary of the Invention
[0003] This disclosure provides at least one method, apparatus, computer device, and storage medium for generating shadow maps.
[0004] In a first aspect, embodiments of this disclosure provide a method for generating a shadow map, comprising: acquiring a three-dimensional model of a target object and an original shadow map corresponding to the three-dimensional model; determining a lighting model corresponding to the three-dimensional model based on the three-dimensional model and the lighting direction corresponding to the three-dimensional model; the lighting model being used to characterize the shadow intensity information corresponding to multiple vertices of the three-dimensional model; and using the lighting model to perform lighting direction correction processing on the original shadow map to obtain a first target shadow map of the three-dimensional model.
[0005] In this way, since the obtained lighting model can reflect the shadow intensity information of multiple vertices of the 3D model under the current lighting direction, the original shadow map determined for the 3D model is corrected in the lighting direction using the lighting model. The resulting first target shadow map can be flexibly adjusted according to the lighting direction compared to the original shadow map. Therefore, after rendering the 3D model, the obtained first target shadow map can enable the 2D object to express the shadow effect under the current lighting direction. Thus, when generating continuous action scenes using 2D objects, the shadow effect can be flexibly adjusted, resulting in higher efficiency.
[0006] In one optional implementation, determining the lighting model corresponding to the three-dimensional model based on the three-dimensional model and the lighting direction corresponding to the three-dimensional model includes: determining the normal directions corresponding to multiple vertices in the three-dimensional model; performing a dot product operation on the normal direction corresponding to each vertex and the lighting direction for each vertex to obtain the shadow intensity information corresponding to each vertex; and obtaining the lighting model based on the shadow intensity information corresponding to the multiple vertices.
[0007] In this way, the lighting model determined by the direction of illumination and the normal direction corresponding to each vertex in the 3D model can more accurately reflect the shadow tendency that each vertex in the 3D model should exhibit under the target light source. That is, the obtained lighting model can reflect the lighting effect of the target light source on the 3D model and is more suitable for correcting the original shadow map corresponding to the 3D model under the direction of illumination of the target light source.
[0008] In one optional implementation, the method further includes: determining the position information of the target light source in the model coordinate system corresponding to the three-dimensional model; and determining the illumination direction corresponding to the three-dimensional model based on the position information of the light source.
[0009] In this way, by using a three-dimensional model, it is relatively easy to establish a model coordinate system. Furthermore, the model coordinate system can also be used to determine the position information of the target light source in the same coordinate system, thereby determining the relative positional relationship between the target light source and the three-dimensional model, so as to further determine the illumination direction corresponding to the three-dimensional model more accurately.
[0010] In one optional implementation, the original shadow map includes: original shadow intensity information corresponding to each vertex in the 3D model; the step of correcting the lighting direction of the original shadow map using the lighting model to obtain the first target shadow map of the 3D model includes: using the shadow intensity information corresponding to multiple vertices included in the lighting model to remap the original shadow intensity information corresponding to each vertex in the 3D model to obtain the first target shadow map of the 3D model.
[0011] In this way, the shadow intensity information corresponding to multiple vertices under the lighting model that reflects the direction of illumination can be used. After remapping calculation, the original shadow intensity information under the original shadow map also has the influence under the direction of illumination, so as to obtain the first target shadow map that can reflect the target object model affected by the direction of illumination.
[0012] In one optional implementation, the method further includes: in response to receiving a shadow range adjustment instruction, performing shadow range adjustment processing on the first target shadow map.
[0013] In one optional implementation, the shadow range adjustment instruction carries a target shadow partition grayscale threshold; the step of performing shadow range adjustment processing on the first target shadow map in response to receiving the shadow range adjustment instruction includes: in response to receiving the shadow range adjustment instruction, performing partition processing on the first target shadow map based on the target shadow partition grayscale threshold carried in the shadow range adjustment instruction to obtain a first partition and a second partition; and performing a first correction processing on the shadow depth of the first partition and the second partition respectively to obtain a second target shadow map.
[0014] In this way, the shadow area of the shadow map can be adjusted more flexibly by adjusting the grayscale threshold of the target shadow partition.
[0015] In an optional implementation, the method further includes: receiving a first value range adjustment instruction corresponding to the grayscale threshold of the target shadow partition; determining a first target value range of the grayscale threshold of the target shadow partition based on the first value range adjustment instruction; wherein the grayscale threshold of the target shadow partition carried in the shadow range adjustment instruction is located within the first target value range.
[0016] In an optional implementation, the method further includes: obtaining a shadow color adjustment instruction; the shadow color adjustment instruction carrying a color grayscale threshold; and using the color grayscale threshold to perform a second correction process on the shadow color of the first target shadow map to obtain a third target shadow map.
[0017] In an optional implementation, the method further includes: receiving a second value range adjustment instruction corresponding to the color grayscale threshold; determining a second target value range of the color grayscale threshold based on the second value range adjustment instruction; and the color grayscale threshold carried in the shadow color adjustment instruction being located within the second target value range.
[0018] This also allows for targeted adjustments to the shadow colors that can be displayed in shadow areas.
[0019] Secondly, embodiments of this disclosure also provide a shadow map generation apparatus, comprising: an acquisition module for acquiring a three-dimensional model of a target object and an original shadow map corresponding to the three-dimensional model; a first determination module for determining a lighting model corresponding to the three-dimensional model based on the three-dimensional model and a lighting direction corresponding to the three-dimensional model; the lighting model being used to characterize the shadow intensity information corresponding to multiple vertices of the three-dimensional model; and a first processing module for using the lighting model to perform lighting direction correction processing on the original shadow map to obtain a first target shadow map of the three-dimensional model.
[0020] In one optional implementation, when the first determining module determines the lighting model corresponding to the three-dimensional model based on the three-dimensional model and the lighting direction corresponding to the three-dimensional model, it is configured to: determine the normal directions corresponding to multiple vertices in the three-dimensional model; for each of the multiple vertices, perform a dot product operation on the normal direction corresponding to each vertex and the lighting direction to obtain the shadow intensity information corresponding to each vertex; and obtain the lighting model based on the shadow intensity information corresponding to the multiple vertices.
[0021] In one optional embodiment, the generating device further includes a second determining module, configured to: determine the position information of the target light source in the model coordinate system corresponding to the three-dimensional model; and determine the illumination direction corresponding to the three-dimensional model based on the light source position information.
[0022] In one optional implementation, the original shadow map includes: original shadow intensity information corresponding to each vertex in the 3D model; when the first processing module performs illumination direction correction processing on the original shadow map using the lighting model to obtain the first target shadow map of the 3D model, it is used to: use the shadow intensity information corresponding to the multiple vertices included in the lighting model to perform remapping processing on the original shadow intensity information corresponding to each vertex in the 3D model to obtain the first target shadow map of the 3D model.
[0023] In one optional embodiment, the generating apparatus further includes a second processing module, configured to: in response to receiving a shadow range adjustment instruction, perform shadow range adjustment processing on the first target shadow map.
[0024] In one optional implementation, the shadow range adjustment instruction carries a target shadow partition grayscale threshold; when the second processing module performs shadow range adjustment processing on the first target shadow map in response to receiving the shadow range adjustment instruction, it is configured to: in response to receiving the shadow range adjustment instruction, perform partition processing on the first target shadow map based on the target shadow partition grayscale threshold carried in the shadow range adjustment instruction to obtain a first partition and a second partition; and perform a first correction processing on the shadow depth of the first partition and the second partition respectively to obtain a second target shadow map.
[0025] In an optional implementation, the second processing module is further configured to: receive a first value range adjustment instruction corresponding to the grayscale threshold of the target shadow partition; determine a first target value range of the grayscale threshold of the target shadow partition based on the first value range adjustment instruction; wherein the grayscale threshold of the target shadow partition carried in the shadow range adjustment instruction is located within the first target value range.
[0026] In an optional embodiment, the generating device further includes a third processing module, configured to: obtain a shadow color adjustment instruction; the shadow color adjustment instruction carries a color grayscale threshold; and use the color grayscale threshold to perform a second correction processing on the shadow color of the first target shadow map to obtain a third target shadow map.
[0027] In an optional implementation, the third processing module is further configured to: receive a second value range adjustment instruction corresponding to the color grayscale threshold; determine a second target value range of the color grayscale threshold based on the second value range adjustment instruction; and the color grayscale threshold carried in the shadow color adjustment instruction is located within the second target value range.
[0028] Thirdly, an optional implementation of this disclosure also provides a computer device, a processor, and a memory, wherein the memory stores machine-readable instructions executable by the processor, and the processor is configured to execute the machine-readable instructions stored in the memory. When the machine-readable instructions are executed by the processor, the steps of the first aspect above, or any possible implementation of the first aspect, are performed.
[0029] Fourthly, an optional implementation of this disclosure also provides a computer-readable storage medium storing a computer program that, when run, performs the steps of the first aspect or any possible implementation of the first aspect.
[0030] For a description of the effects of the above-mentioned shadow map generation apparatus, computer equipment, and computer-readable storage medium, please refer to the description of the shadow map generation method above, which will not be repeated here.
[0031] To make the above-mentioned objects, features and advantages of this disclosure more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0032] To more clearly illustrate the technical solutions of the embodiments of this disclosure, the accompanying drawings used in the embodiments will be briefly described below. These drawings are incorporated in and constitute a part of this specification. They illustrate embodiments conforming to this disclosure and, together with the specification, serve to explain the technical solutions of this disclosure. It should be understood that the following drawings only show some embodiments of this disclosure and should not be considered as limiting the scope. Those skilled in the art can obtain other related drawings based on these drawings without creative effort.
[0033] Figure 1 A flowchart illustrating a method for generating a shadow map according to an embodiment of this disclosure is shown;
[0034] Figure 2 A schematic diagram of a three-dimensional model of a target object provided in an embodiment of this disclosure is shown;
[0035] Figure 3 A schematic diagram of an original shadow map provided in an embodiment of this disclosure is shown;
[0036] Figure 4 A schematic diagram illustrating a method for determining illumination direction provided by an embodiment of this disclosure is shown;
[0037] Figure 5 A schematic diagram of a sphere that can reflect shadow intensity information provided by an embodiment of this disclosure is shown;
[0038] Figure 6 A schematic diagram of a display interface for adjusting shadow effects provided in an embodiment of this disclosure is shown;
[0039] Figure 7 This illustration shows a schematic diagram of a rendered image obtained after shadow rendering of a target object, as provided in an embodiment of the present disclosure.
[0040] Figure 8 A schematic diagram of a shadow map generation apparatus provided in an embodiment of the present disclosure is shown;
[0041] Figure 9 A schematic diagram of a computer device provided in an embodiment of this disclosure is shown. Detailed Implementation
[0042] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, and not all of them. The components of the embodiments of this disclosure described and shown herein can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this disclosure is not intended to limit the scope of the claimed disclosure, but merely represents selected embodiments of this disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure.
[0043] Research has found that to improve the realism of rendered 2D objects, shadow effects are typically added during the rendering process. Currently, when adding shadow effects to 2D objects, a shadow map is usually defined for the object, and then the shadow is rendered using this map. Here, the shadow map is usually a manually drawn grayscale image. After manually determining the area to be shadowed, different grayscale values are used to reflect the area where the desired shadow is to appear on the 2D object. In this type of shadow map, the area to be rendered on the 2D object is relatively fixed. However, when generating continuously changing scenes using 2D objects, the size and intensity of these shadow areas may need to be adjusted as the direction of light illuminating the object changes or as the object moves, to ensure the shadows are realistic. Currently, the method of drawing shadow maps separately for each frame is used to handle situations where the shadow needs to be adjusted when the direction of light or the object's movement changes. This method is inefficient.
[0044] Based on the above research, this disclosure provides a method for generating shadow maps. When determining shadow maps for a two-dimensional object, the three-dimensional model of the two-dimensional object is first obtained. Then, the lighting direction illuminating the three-dimensional model is used to determine the lighting model corresponding to the three-dimensional model. Since the obtained lighting model can reflect the shadow intensity information corresponding to multiple vertices of the three-dimensional model under the current lighting direction, the original shadow map determined for the three-dimensional model is corrected in the lighting direction using the lighting model. The resulting first target shadow map can be flexibly adjusted according to the lighting direction compared to the original shadow map. Therefore, after rendering the three-dimensional model, the obtained first target shadow map can enable the two-dimensional object to express the shadow effect under the current lighting direction. Thus, when generating continuous action scenes using two-dimensional objects, the shadow effect can be flexibly adjusted, resulting in higher efficiency.
[0045] The shortcomings of the above solutions are the result of the inventor's practical experience and careful research. Therefore, the discovery process of the above problems and the solutions proposed in this disclosure below should be considered as the inventor's contribution to this disclosure.
[0046] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0047] To facilitate understanding of this embodiment, a method for generating a shadow map disclosed in this disclosure will first be described in detail. The execution entity of the shadow map generation method provided in this disclosure is generally a computer device with certain computing capabilities. This computer device may include, for example, a terminal device, a server, or other processing devices. The terminal device may be a user equipment (UE), mobile device, user terminal, terminal, cellular phone, cordless phone, personal digital assistant (PDA), handheld device, computing device, in-vehicle device, wearable device, etc. In some possible implementations, the shadow map generation method can be implemented by a processor calling computer-readable instructions stored in memory.
[0048] The following describes the shadow texture generation method provided in this disclosure. This disclosure provides a shadow texture generation method that can be used to determine the shadow texture of a two-dimensional object, and specifically applied to the shadow rendering of the two-dimensional object. The two-dimensional object described here can specifically include cartoon characters, game characters, virtual pets, etc. Therefore, the generation method provided in this disclosure can be specifically applied to different application fields such as game screen production or generation, animation and film production. After determining the shadow texture using the generation method provided in this disclosure, the determined shadow texture can be further used to render the two-dimensional object, so that the shadow effect displayed through rendering makes the two-dimensional object more realistic and believable.
[0049] See Figure 1 The diagram shows a flowchart of a shadow map generation method provided in this embodiment of the present disclosure. The method includes steps S101 to S103, wherein:
[0050] S101: Obtain the 3D model of the target object and the original shadow map corresponding to the 3D model;
[0051] S102: Based on the three-dimensional model and the lighting direction corresponding to the three-dimensional model, determine the lighting model corresponding to the three-dimensional model; the lighting model is used to characterize the shadow intensity information corresponding to multiple vertices of the three-dimensional model respectively;
[0052] S103: The original shadow map is corrected for lighting direction using the lighting model to obtain the first target shadow map of the three-dimensional model.
[0053] This embodiment utilizes a 3D model and its corresponding lighting direction to determine a lighting model for the 3D model, thereby correcting the original shadow map of the 3D model to obtain a first target shadow map. Compared to the original shadow map, this first target shadow map can be flexibly adjusted according to the lighting direction. Therefore, after rendering the 3D model, the obtained first target shadow map allows the 2D object to express the shadow effect under the current lighting direction. This enables flexible adjustment of the shadow effect when generating continuous motion scenes using 2D objects, resulting in higher efficiency.
[0054] The above S101 to S103 are explained in detail below.
[0055] Regarding S101 above, the three-dimensional model of the target object will first be explained. The target object may specifically include a two-dimensional object. Since a two-dimensional object is a virtual object and does not actually exist, its physical characteristics such as height and weight can be determined by constructing a three-dimensional model corresponding to the two-dimensional object. The determined three-dimensional model can then be used to simulate the desired appearance of the two-dimensional object in the real world. For example, see... Figure 2 The diagram shown is a schematic representation of a three-dimensional model of a target object provided in an embodiment of this disclosure. The three-dimensional model shown here is an artificially constructed virtual model. Specifically, the three-dimensional model can be further refined to represent facial features and clothing characteristics. Figure 2 The image is not shown. Furthermore, different 3D models can be determined for different 2D objects.
[0056] A 3D model typically consists of multiple vertices located on the surface of the 3D model, and meshes formed by the interconnections between the vertices.
[0057] After determining the target object model, the original shadow map corresponding to the 3D model can be obtained. The original shadow map specifically includes a grayscale image, composed of pixels at different grayscale values, which reflects the original shadow intensity information corresponding to each vertex in the 3D model. For example, see... Figure 3The diagram shown is a schematic of an original shadow map provided in an embodiment of this disclosure. In one possible case, when actually determining the shadow map for the target object model, a light map is first determined for the 3D model. The light map is composed of grayscale images in different channels, and the grayscale image in the shadow channel of the light map can also be used as the grayscale image of the original shadow map.
[0058] Regarding S102 above, using the three-dimensional model determined in S101 and the corresponding lighting direction, the lighting model corresponding to the three-dimensional model under illumination can be determined. Here, the obtained lighting model is used to characterize the shadow intensity information corresponding to multiple vertices of the three-dimensional model.
[0059] First, the specific method for determining the lighting model is explained. In a specific implementation, the lighting model can be determined as follows: determine the normal directions corresponding to multiple vertices in the 3D model; for each vertex, perform a dot product operation on the normal direction and the lighting direction corresponding to each vertex to obtain the shadow intensity information corresponding to each vertex; based on the shadow intensity information corresponding to the multiple vertices, the lighting model is obtained.
[0060] For multiple vertices in the 3D model and the normal directions corresponding to these vertices, see [link to documentation]. Figure 2 As shown, some vertices in the illustrated 3D model are labeled, along with the corresponding normal directions at each vertex. Since the 3D model is fixed, multiple vertices can be determined on the outer contour of the 3D model, and the normal directions for each vertex can be determined based on their respective positions on the 3D model. The specific method for determining the normal directions will not be elaborated upon here.
[0061] Regarding the direction of illumination, another embodiment of this disclosure also provides a specific method for determining the direction of illumination. Specifically, the position information of the target light source in the model coordinate system corresponding to the three-dimensional model can be determined, and then the illumination direction corresponding to the three-dimensional model can be determined based on the position information of the light source.
[0062] The target light source can include a virtual light source. When determining the illumination direction of the target light source, the relative positional relationship between the target light source and the 3D model is involved because the illumination direction specifically affects the 3D model. Therefore, to more accurately determine the illumination direction, a corresponding model coordinate system can be established based on the 3D model, and the light source position information of the target light source can be determined within this model coordinate system. In this way, for the target light source and the 3D model within the same model coordinate system, the relative positional relationship between the target light source and the 3D model can be accurately determined, thereby enabling the determination of the illumination direction corresponding to the 3D model.
[0063] For example, see Figure 4 The diagram shown is a schematic representation of determining the direction of illumination according to an embodiment of this disclosure. When establishing a model coordinate system using a 3D model, the central axis of the 3D model can be used as the z-axis to establish a coordinate system as shown below. Figure 4 The model coordinate system is shown in the diagram. The position information of the target light source 41 can also be represented by coordinate values in the model coordinate system, such as (x1, y1, z1). Based on the determined light source position information, it can be known that the target light source illuminates the upper left side of the 3D model, and the determined illumination direction is... Figure 4 The corresponding annotations were also made in the text.
[0064] Given a defined lighting direction, for each of the multiple vertices, a dot product operation can be performed using the normal direction and the lighting direction to obtain the shadow intensity information for each vertex. By determining the shadow intensity information for each of the multiple vertices, a lighting model can be obtained. Specifically, the shadow intensity information reflected in the lighting model indicates whether each vertex appears in a shadow area after rendering, and if so, whether the shadow color is darker or lighter.
[0065] The principles behind determining the lighting model are explained below. (See below) Figure 5 The diagram shown is a schematic representation of a sphere that can reflect shadow intensity information according to an embodiment of this disclosure. A simple sphere 51 is used in place of a three-dimensional model for illustration. Figure 5 The diagram also shows the target light source 52. For the sphere 51, multiple vertices on the surface can be determined, and the normal vector corresponding to each vertex can be identified. In the diagram, three special vertices a1, a2, and a3 are labeled, and their corresponding normal vectors are represented as N1, N2, and N3, respectively. For the target light source 52, the corresponding illumination direction is represented as L.
[0066] Thus, according to Figure 5The diagram showing the shadow effect of the sphere reveals that the normal vector N1 corresponding to vertex a1 is in the opposite direction to L, resulting in no shadow at vertex a1. The normal vector N2 corresponding to vertex a2 is perpendicular to L, resulting in a gray shadow at vertex a1. For vertices where the angle between their corresponding normal vector and L is greater than 90 degrees and less than 180 degrees, different shades of gray are observed, with a darker gray shadow appearing as the angle increases. The normal vector N3 corresponding to vertex a3 is in the same direction as L, resulting in a black shadow at vertex a3. Furthermore, all vertices where the angle between their corresponding normal vector and L is less than 90 degrees are also black. Based on this deduction, given the lighting direction L and the normal vector Na corresponding to each vertex a, it is possible to determine whether each vertex a is in a shadow region and, if so, the appropriate shadow color.
[0067] Therefore, regarding S103 above, for the original shadow map, a lighting model can be used to correct it under the lighting direction to obtain the first target shadow map of the 3D model. In a specific implementation, the following method can be adopted: using the shadow degree information corresponding to multiple vertices included in the lighting model, the original shadow degree information corresponding to each vertex in the 3D model is remapped to obtain the first target shadow map of the 3D model.
[0068] The remapping process specifically involves remapping the original shadow intensity information across the grayscale range, which can be achieved using linear interpolation. This allows the use of shadow intensity information corresponding to multiple vertices under a lighting model that reflects the direction of illumination. Through remapping, the original shadow intensity information in the original shadow map also retains the influence of the lighting direction, resulting in a first target shadow map that reflects the effect of the lighting direction on the target object model.
[0069] In another embodiment of this disclosure, the shadow range of the first target shadow map can also be partitioned to achieve dual-sided shadow adjustment, which is used to present a layered shadow that can reflect the occlusion relationship after the three-dimensional model is rendered and displayed.
[0070] In practical implementation, for example, in response to receiving a shadow range adjustment command, the shadow range of the first target shadow map can be adjusted. This shadow range adjustment command carries a target shadow partition grayscale threshold. Here, the target shadow partition grayscale threshold is a grayscale value that can be used to control the shadow tendency of the corresponding area of each pixel in the first target shadow map on the 3D model. In one possible scenario, if the target shadow partition grayscale threshold is determined to be 128, it can be determined that pixels in the first target shadow map with a grayscale value less than 128 will be less likely to produce shadows in the corresponding area of the 3D model, while pixels in the first target shadow map with a grayscale value greater than 128 will be more likely to produce shadows in the corresponding area of the 3D model.
[0071] Here, the shadow range adjustment command may include, for example, a target shadow zone grayscale threshold, meaning the target shadow zone grayscale threshold is adjustable. Specifically, the shadow range adjustment command can be determined in response to receiving an input command to the input box corresponding to the target shadow zone grayscale threshold or an operation command to the adjustment knob. See also Figure 6 The diagram shows a display interface for adjusting shadow effects according to an embodiment of this disclosure. A table labeled "Target Shadow Zone Grayscale Threshold" includes adjustment buttons. By sliding the buttons left and right, the grayscale threshold value of the target shadow zone can be changed. Sliding the adjustment buttons generates a shadow range adjustment command. Furthermore, after a sliding operation, the currently set target shadow zone grayscale threshold value is displayed in a table next to it, for example, "128" as shown.
[0072] When partitioning the first target shadow map using the target shadow partition grayscale threshold, pixels in the first target shadow map with grayscale values greater than or equal to the target shadow partition grayscale threshold can be assigned to the first partition, and pixels with grayscale values less than the target shadow partition grayscale threshold can be assigned to the second partition. Using the shadow tendencies that different regions should exhibit as described above, a first correction process for shadow depth can be performed on the first and second partitions respectively, resulting in a second target shadow map under the target shadow partition grayscale threshold.
[0073] In addition, since the grayscale threshold of the target shadow partition can be adjusted, the second target shadow map can be flexibly adjusted by adjusting the grayscale threshold of the target shadow partition within a certain range, provided that the second target shadow map is determined.
[0074] Specifically, the range of grayscale threshold values for the target shadow partition can be limited in the following manner: receiving a first value range adjustment instruction corresponding to the grayscale threshold value of the target shadow partition; determining a first target value range for the grayscale threshold value of the target shadow partition based on the first value range adjustment instruction; the grayscale threshold value of the target shadow partition carried in the shadow range adjustment instruction is located within the first target value range.
[0075] For example, see Figure 6 As shown, the table labeled "Value Range" also includes an adjustment knob. Sliding this knob determines an adjustment command for the first value range corresponding to the grayscale threshold of the target shadow region. Here, the determined first value range is also the selectable range of the target shadow region grayscale threshold described above during adjustment. For example, for... Figure 6 The “Area Range” shown in the table indicates that the current first target value range is 150, which means that the maximum grayscale threshold of the target shadow partition can be selected to be 150. In other words, when the adjustment knob in the “Target Shadow Partition Grayscale Threshold” table is slid to the maximum, the grayscale threshold that can be selected is 150.
[0076] In another embodiment of this disclosure, the shadow color displayed by the 3D model can also be adjusted. In a specific implementation, for example, the following method can be used: obtaining a shadow color adjustment instruction; the shadow color adjustment instruction carrying a color grayscale threshold; using the color grayscale threshold, performing a second correction process on the shadow color of the first target shadow map to obtain a third target shadow map.
[0077] Among them, see Figure 6 As shown, the table labeled "Shadow Color" contains a color picker button for the shadow color and a color chart for the currently selected shadow color. In response to the color picker operation, a shadow color adjustment command is generated, which carries the confirmed grayscale threshold for the color selected in the current color picker operation, for example... Figure 6 The "Shadow Color" table displays the shadow colors. Using a defined color grayscale threshold, a second correction process can be applied to the defined shadow color. For example, if the selected color grayscale threshold is high, the corresponding reaction will be to adjust the first target shadow map to display a lighter shadow; if the selected color grayscale threshold is low, the corresponding reaction will be to adjust the first target shadow map to display a darker shadow.
[0078] In addition, similar to the target shadow partition grayscale threshold described above, the selection range of shadow colors can also be limited by determining the shadow color adjustment range. In specific implementation, a second value range adjustment instruction corresponding to the color grayscale threshold can be received; based on the second value range adjustment instruction, a second target value range of the color grayscale threshold is determined; the color grayscale threshold carried in the shadow color adjustment instruction is located within the second target value range.
[0079] See Figure 6 As shown, in the table labeled "Shadow Color Adjustment Range," there is a color picker button for adjusting the shadow color adjustment range. Responding to the selection of the shadow color adjustment range using this color picker button, a second value range adjustment instruction corresponding to the color grayscale threshold can be determined, thereby determining the second target value range of the shadow color. For example, Figure 6 The color chart showing the range of shadow color adjustments indicates the deepest possible shadow color that can be selected.
[0080] The above describes two adjustment ranges for the target shadow partition grayscale threshold and shadow color setting. In scenarios where multiple people work together, by limiting the value range of the first target and the value range of the second target, the degree of adjustment that can be made when multiple people adjust the shadow depth and / or shadow color of the target shadow map can be limited to a certain range. This can reduce the situation where the shadow is too dark or too deep due to differences in personal style or preference.
[0081] The shadow map generation method provided in this disclosure provides a shadow map that, compared to a shadow map determined by manual drawing, allows for flexible adjustment of shadow depth and color, and can be corrected according to the direction of illumination. Therefore, when rendering a target object using the obtained shadow map, the shadow effect is more controllable. For example, see... Figure 7 The diagram shown is a schematic representation of a rendered image obtained after shadow rendering of a target object according to an embodiment of this disclosure. Figure 7 Image (a) shows the rendered image of the target object after the shadow map, which was determined directly by manual drawing, is rendered. Compared to Figure 7 The rendered image shown in (b) is not natural in its shadow representation, as it is obtained by the shadow mapping generation method provided in this embodiment. Figure 7 The rendered image shown in (b) is more in line with the lighting logic in reality in terms of shadow representation, and therefore more natural and able to enhance the realism of the target object.
[0082] Those skilled in the art will understand that, in the above-described method of the specific implementation, the order in which each step is written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.
[0083] Based on the same inventive concept, this disclosure also provides a shadow map generation apparatus corresponding to the shadow map generation method. Since the principle of the apparatus in this disclosure for solving the problem is similar to the shadow map generation method described above in this disclosure, the implementation of the apparatus can refer to the implementation of the method, and the repeated parts will not be described again.
[0084] Reference Figure 8 The diagram shown is a schematic of a shadow map generation apparatus provided in an embodiment of this disclosure. The apparatus includes: an acquisition module 81, a first determination module 82, and a first processing module 83; wherein,
[0085] The acquisition module 81 is used to acquire the three-dimensional model of the target object and the original shadow map corresponding to the three-dimensional model;
[0086] The first determining module 82 is used to determine a lighting model corresponding to the three-dimensional model based on the three-dimensional model and the lighting direction corresponding to the three-dimensional model; the lighting model is used to characterize the shadow intensity information corresponding to multiple vertices of the three-dimensional model respectively;
[0087] The first processing module 83 is used to perform lighting direction correction processing on the original shadow map using the lighting model to obtain the first target shadow map of the three-dimensional model.
[0088] In one optional implementation, when the first determining module 82 determines the lighting model corresponding to the three-dimensional model based on the three-dimensional model and the lighting direction corresponding to the three-dimensional model, it is configured to: determine the normal directions corresponding to multiple vertices in the three-dimensional model; perform a dot product operation on the normal direction corresponding to each vertex and the lighting direction for each vertex to obtain the shadow intensity information corresponding to each vertex; and obtain the lighting model based on the shadow intensity information corresponding to the multiple vertices.
[0089] In one optional embodiment, the generating device further includes a second determining module 84, configured to: determine the position information of the target light source in the model coordinate system corresponding to the three-dimensional model; and determine the illumination direction corresponding to the three-dimensional model based on the light source position information.
[0090] In one optional implementation, the original shadow map includes: original shadow intensity information corresponding to each vertex in the 3D model; when the first processing module 83 performs illumination direction correction processing on the original shadow map using the lighting model to obtain the first target shadow map of the 3D model, it is used to: use the shadow intensity information corresponding to the multiple vertices included in the lighting model to perform remapping processing on the original shadow intensity information corresponding to each vertex in the 3D model to obtain the first target shadow map of the 3D model.
[0091] In one optional embodiment, the generating apparatus further includes a second processing module 85, configured to: in response to receiving a shadow range adjustment instruction, perform shadow range adjustment processing on the first target shadow map.
[0092] In one optional implementation, the shadow range adjustment instruction carries a target shadow partition grayscale threshold; when the second processing module 85 performs shadow range adjustment processing on the first target shadow map in response to receiving the shadow range adjustment instruction, it is configured to: in response to receiving the shadow range adjustment instruction, perform partition processing on the first target shadow map based on the target shadow partition grayscale threshold carried in the shadow range adjustment instruction to obtain a first partition and a second partition; and perform a first correction processing on the shadow depth of the first partition and the second partition respectively to obtain a second target shadow map.
[0093] In an optional implementation, the second processing module 85 is further configured to: receive a first value range adjustment instruction corresponding to the grayscale threshold of the target shadow partition; determine a first target value range of the grayscale threshold of the target shadow partition based on the first value range adjustment instruction; wherein the grayscale threshold of the target shadow partition carried in the shadow range adjustment instruction is located within the first target value range.
[0094] In an optional embodiment, the generating device further includes a third processing module 86, configured to: obtain a shadow color adjustment instruction; the shadow color adjustment instruction carries a color grayscale threshold; and use the color grayscale threshold to perform a second correction processing on the shadow color of the first target shadow map to obtain a third target shadow map.
[0095] In an optional implementation, the third processing module 86 is further configured to: receive a second value range adjustment instruction corresponding to the color grayscale threshold; determine a second target value range of the color grayscale threshold based on the second value range adjustment instruction; and the color grayscale threshold carried in the shadow color adjustment instruction is located within the second target value range.
[0096] The processing flow of each module in the device and the interaction flow between each module can be referred to the relevant descriptions in the above method embodiments, and will not be detailed here.
[0097] This disclosure also provides a computer device, such as... Figure 9 The diagram shown is a schematic representation of a computer device structure provided in an embodiment of this disclosure, including:
[0098] Processor 10 and memory 20; the memory 20 stores machine-readable instructions executable by processor 10, and processor 10 executes the machine-readable instructions stored in memory 20. When the machine-readable instructions are executed by processor 10, processor 10 performs the following steps:
[0099] Obtain a 3D model of the target object and an original shadow map corresponding to the 3D model; based on the 3D model and the lighting direction corresponding to the 3D model, determine a lighting model corresponding to the 3D model; the lighting model is used to characterize the shadow intensity information corresponding to multiple vertices of the 3D model; use the lighting model to correct the lighting direction of the original shadow map to obtain the first target shadow map of the 3D model.
[0100] The aforementioned memory 20 includes a main memory 210 and an external memory 220; the main memory 210, also known as internal memory, is used to temporarily store the computational data in the processor 10, as well as the data exchanged with external memory 220 such as a hard disk. The processor 10 exchanges data with the external memory 220 through the main memory 210.
[0101] The specific execution process of the above instructions can be referred to the steps of the shadow map generation method described in the embodiments of this disclosure, and will not be repeated here.
[0102] This disclosure also provides a computer-readable storage medium storing a computer program that, when executed by a processor, performs the steps of the shadow mapping generation method described in the above method embodiments. The storage medium can be a volatile or non-volatile computer-readable storage medium.
[0103] This disclosure also provides a computer program product carrying program code. The program code includes instructions that can be used to execute the steps of the shadow map generation method described in the above method embodiments. For details, please refer to the above method embodiments, which will not be repeated here.
[0104] The aforementioned computer program product can be implemented through hardware, software, or a combination thereof. In one optional embodiment, the computer program product is specifically embodied in a computer storage medium; in another optional embodiment, the computer program product is specifically embodied in a software product, such as a software development kit (SDK), etc.
[0105] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems and devices described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. In the several embodiments provided in this disclosure, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection may be through some communication interfaces; the indirect coupling or communication connection of devices or units may be electrical, mechanical, or other forms.
[0106] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0107] In addition, the functional units in the various embodiments of this disclosure can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0108] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this disclosure, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this disclosure. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0109] Finally, it should be noted that the above-described embodiments are merely specific implementations of this disclosure, used to illustrate the technical solutions of this disclosure, and not to limit it. The protection scope of this disclosure is not limited thereto. Although this disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the scope of the technology disclosed in this disclosure. Such modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this disclosure, and should all be covered within the protection scope of this disclosure. Therefore, the protection scope of this disclosure should be determined by the protection scope of the claims.
Claims
1. A method for generating a shadow map, characterized in that, include: Obtain the 3D model of the target object and the original shadow map corresponding to the 3D model; Based on the three-dimensional model and the lighting direction corresponding to the three-dimensional model, a lighting model corresponding to the three-dimensional model is determined; the lighting model is used to characterize the shadow intensity information corresponding to multiple vertices of the three-dimensional model. The lighting model is used to correct the lighting direction of the original shadow map to obtain the first target shadow map of the three-dimensional model; The original shadow map includes: the original shadow intensity information corresponding to each vertex in the 3D model; The step of correcting the lighting direction of the original shadow map using the lighting model to obtain the first target shadow map of the 3D model includes: Using the shadow intensity information corresponding to multiple vertices included in the lighting model, the original shadow intensity information corresponding to each vertex in the three-dimensional model is remapped to obtain the first target shadow map of the three-dimensional model; The method further includes: In response to receiving a shadow range adjustment command, the shadow range of the first target shadow map is adjusted. The shadow range adjustment instruction carries the grayscale threshold of the target shadow partition; The step of adjusting the shadow range of the first target shadow map in response to receiving a shadow range adjustment command includes: In response to receiving a shadow range adjustment instruction, the first target shadow map is partitioned based on the target shadow partition grayscale threshold carried in the shadow range adjustment instruction to obtain a first partition and a second partition; The first shadow depth correction process is performed on the first partition and the second partition respectively to obtain the second target shadow map.
2. The generation method according to claim 1, characterized in that, The step of determining the lighting model corresponding to the three-dimensional model based on the three-dimensional model and the lighting direction corresponding to the three-dimensional model includes: Determine the normal directions corresponding to multiple vertices in the 3D model; For each of the multiple vertices, a dot product operation is performed on the normal direction and the lighting direction corresponding to each vertex to obtain the shadow intensity information corresponding to each vertex; The lighting model is obtained based on the shadow intensity information corresponding to each of the multiple vertices.
3. The generation method according to claim 1 or 2, characterized in that, The method further includes: determining the position information of the target light source in the model coordinate system corresponding to the three-dimensional model; Based on the light source position information, the illumination direction corresponding to the three-dimensional model is determined.
4. The generation method according to claim 1, characterized in that, The method further includes: Receive a command to adjust the first value range corresponding to the grayscale threshold of the target shadow partition; Based on the first value range adjustment instruction, a first target value range for the grayscale threshold of the target shadow partition is determined; The grayscale threshold of the target shadow partition carried in the shadow range adjustment instruction is within the range of the first target value.
5. The generation method according to any one of claims 1, 2, and 4, characterized in that, Also includes: Obtain a shadow color adjustment instruction; the shadow color adjustment instruction carries a color grayscale threshold. Using the color grayscale threshold, a second correction process for the shadow color of the first target shadow map is performed to obtain the third target shadow map.
6. The generation method according to claim 5, characterized in that, The method further includes: Receive an instruction to adjust the second value range corresponding to the color grayscale threshold; Based on the second value range adjustment instruction, the second target value range of the color grayscale threshold is determined; The grayscale threshold carried in the shadow color adjustment instruction is within the range of the second target value.
7. A shadow map generation apparatus for performing the generation method of claim 1, characterized in that, include: The acquisition module is used to acquire the three-dimensional model of the target object and the original shadow map corresponding to the three-dimensional model; The first determining module is used to determine the lighting model corresponding to the three-dimensional model based on the three-dimensional model and the lighting direction corresponding to the three-dimensional model; The lighting model is used to characterize the shadow intensity information corresponding to multiple vertices of the three-dimensional model; The first processing module is used to correct the lighting direction of the original shadow map using the lighting model to obtain the first target shadow map of the three-dimensional model. The original shadow map includes: the original shadow intensity information corresponding to each vertex in the 3D model; The step of correcting the lighting direction of the original shadow map using the lighting model to obtain the first target shadow map of the 3D model includes: Using the shadow intensity information corresponding to multiple vertices included in the lighting model, the original shadow intensity information corresponding to each vertex in the three-dimensional model is remapped to obtain the first target shadow map of the three-dimensional model.
8. A computer device, characterized in that, include: A processor and a memory, the memory storing machine-readable instructions executable by the processor, the processor executing the machine-readable instructions stored in the memory, wherein when the machine-readable instructions are executed by the processor, the processor performs the steps of the shadow map generation method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, which, when executed by a computer device, performs the steps of the shadow mapping generation method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Map generation method and device, computer equipment and storage medium
CN114519760A
Rendering method and device, computer equipment and storage medium
CN114549719A
System and method suitable for setting up real time shadow of transparent target
CN1369849A