A method, device, equipment and readable storage medium for generating light and shadow effect diagram
By calculating and drawing the relationship between the shadow image and the original image, the problems of low efficiency and high cost of drawing artificial light and shadow rendering are solved, and efficient and low-cost light and shadow rendering are achieved.
Patent Information
- Application Number
- CN202111145188.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-28
- Publication Date
- 2025-05-16
- Estimated Expiration
- 2041-09-28
AI Technical Summary
Manual light and shadow rendering is inefficient and costly, and different scenes need to be designed according to different lighting conditions. A large amount of content needs to be changed when switching scenes.
By obtaining the shape size parameters of the target object, the image parameters of the original image and the preset light source parameters, calculate the shadow parameters and create a shadow image, create an initial light and shadow effect based on the original image size and shadow image size, and draw the shadow image and the original image in the order of the shadow image first and the original image in the subsequent order to obtain the target light and shadow effect.
It improves the drawing efficiency of light and shadow renderings, reduces the drawing cost, and realizes the adaptive generation of light and shadow renderings based on the application scenario.
Smart Images

Figure CN113870380B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to a method, device, equipment and computer-readable storage medium for generating a light and shadow effect diagram. Background Art
[0002] Shadows are crucial for realistic scene rendering. They not only reflect the mutual occlusion between objects in space, but also the geometric information of the occluding objects and the receiving surface. Real-time shadow rendering significantly enhances the realism of scene rendering. For example, in photography, capturing excellent shadow images requires a strong ability to observe shadows and a strong imagination. Therefore, post-processing of graphics and images is crucial. This can enhance contrast and highlight effects. However, such features and tools are still relatively rare on the market, and improper handling can have a counterproductive effect.
[0003] Shadows in graphics can make scenes more realistic. Different shadow algorithms are required to achieve different shadow scenarios. Graphics will produce different types of shadow effects depending on the lighting and lighting methods. Currently, shadows are highly utilized in image processing and interior design. Manual calculations and rendering of light and shadow effects are expensive. Furthermore, different scenes must be designed based on different lighting conditions, and switching scenes requires numerous changes, resulting in low efficiency and high labor costs.
[0004] In summary, how to effectively solve the problems of manual calculation and drawing of light and shadow effect images, low image drawing efficiency, and high labor costs is an urgent problem that technicians in this field need to solve. Summary of the Invention
[0005] The purpose of the present invention is to provide a method for generating a light and shadow effect diagram, which improves the drawing efficiency of the light and shadow effect diagram and reduces the drawing cost; another purpose of the present invention is to provide a device, equipment and computer-readable storage medium for generating a light and shadow effect diagram.
[0006] In order to solve the above technical problems, the present invention provides the following technical solutions:
[0007] A method for generating a light and shadow effect diagram, comprising:
[0008] Obtaining a target object for which a light and shadow effect image is to be generated and an original image of the target object;
[0009] Respectively reading the shape and size parameters of the target object, the image parameters of the original image, and the preset light source parameters;
[0010] Calculating shadow parameters according to the shape and size parameters and the light source parameters, and creating a shadow image according to the shadow parameters;
[0011] Reading the original image size from the image parameters and reading the shadow image size from the shadow parameters;
[0012] Calculating the size of the light and shadow effect graph according to the size of the original image and the size of the shadow image, and creating an initial light and shadow effect graph according to the size of the light and shadow effect graph;
[0013] The shadow image and the original image are drawn on the initial light and shadow effect diagram to obtain a target light and shadow effect diagram; wherein the drawing of the shadow image takes precedence over the drawing of the original image.
[0014] In a specific embodiment of the present invention, calculating the shadow parameter according to the shape and size parameter and the light source parameter includes:
[0015] When the light source type is artificial light, reading the artificial light distance from the artificial light source to the target object and the artificial light direction of the artificial light source relative to the target object from the light source parameters;
[0016] Calculate a first shadow position and a first shadow size according to the artificial light distance, the artificial light direction, and the shape and size parameters;
[0017] Reading the artificial light color from the light source parameters, and calculating the shadow color according to the artificial light color;
[0018] Reading artificial light intensity from the light source parameters, and calculating shadow transparency according to the artificial light intensity;
[0019] The shadow parameters are constructed according to the first shadow position, the first shadow size, the shadow color, and the shadow transparency.
[0020] In a specific embodiment of the present invention, calculating the shadow parameter according to the shape and size parameter and the light source parameter includes:
[0021] When the light source type is sunlight, reading the sunlight season and sunlight time from the light source parameters;
[0022] matching shadow transparency, shadow offset, second shadow position, and second shadow size from a pre-generated configuration table according to the shape size parameters, the sunlight season, and the sunlight time;
[0023] The shadow parameters are constructed according to the shadow transparency, the shadow offset, the second shadow position, and the second shadow size.
[0024] In a specific embodiment of the present invention, after obtaining the target light and shadow effect diagram, the method further includes:
[0025] Determine whether to save the target light and shadow effect image;
[0026] If so, read the preset target storage location;
[0027] The target light and shadow effect image is saved to the target storage location.
[0028] A device for generating a light and shadow effect diagram, comprising:
[0029] An object and image acquisition module, used to acquire a target object for generating a light and shadow effect image and an original image of the target object;
[0030] A parameter reading module, used to read the shape and size parameters of the target object, the image parameters of the original image, and the preset light source parameters respectively;
[0031] a shadow parameter calculation module, configured to calculate shadow parameters according to the shape and size parameters and the light source parameters, and create a shadow image according to the shadow parameters;
[0032] An image size reading module, configured to read the original image size from the image parameters and read the shadow image size from the shadow parameters;
[0033] An initial effect diagram creation module is used to calculate the size of the light and shadow effect diagram according to the size of the original image and the size of the shadow image, and to create an initial light and shadow effect diagram according to the size of the light and shadow effect diagram;
[0034] An image drawing module is used to draw the shadow image and the original image on the initial light and shadow effect diagram to obtain a target light and shadow effect diagram; wherein the drawing of the shadow image takes precedence over the drawing of the original image.
[0035] In a specific embodiment of the present invention, the shadow parameter calculation module includes:
[0036] a distance and direction reading submodule, configured to read, from the light source parameters, the artificial light distance from the artificial light source to the target object and the artificial light direction of the artificial light source relative to the target object when the light source type is artificial light;
[0037] a position and size calculation submodule, configured to calculate a first shadow position and a first shadow size according to the artificial light distance, the artificial light direction, and the shape and size parameters;
[0038] a shadow color calculation submodule, configured to read the artificial light color from the light source parameters and calculate the shadow color according to the artificial light color;
[0039] a shadow transparency calculation submodule, configured to read the artificial light intensity from the light source parameters and calculate the shadow transparency according to the artificial light intensity;
[0040] The first parameter construction submodule is used to construct the shadow parameters according to the first shadow position, the first shadow size, the shadow color and the shadow transparency.
[0041] In a specific embodiment of the present invention, the shadow parameter calculation module includes:
[0042] The season and time reading submodule is used to read the sunlight season and sunlight time from the light source parameters when the light source type is sunlight;
[0043] a parameter matching submodule, for matching shadow transparency, shadow offset, second shadow position, and second shadow size from a pre-generated configuration table according to the shape and size parameters, the sunlight season, and the sunlight time;
[0044] The second parameter construction submodule is used to construct the shadow parameters according to the shadow transparency, the shadow offset, the second shadow position and the second shadow size.
[0045] In a specific embodiment of the present invention, it also includes:
[0046] A judgment module, configured to judge whether to save the target light and shadow effect diagram after obtaining the target light and shadow effect diagram;
[0047] A storage location reading module, configured to read a preset target storage location when determining to perform a saving operation on the target light and shadow effect image;
[0048] The image saving module is used to save the target light and shadow effect image to the target storage location.
[0049] A device for generating a light and shadow effect diagram, comprising:
[0050] Memory for storing computer programs;
[0051] A processor is used to implement the steps of the method for generating the light and shadow effect diagram as described above when executing the computer program.
[0052] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the method for generating a light and shadow effect diagram as described above.
[0053] The method for generating a light and shadow effect diagram provided by the present invention obtains a target object for generating a light and shadow effect diagram and an original image of the target object; reads shape and size parameters of the target object, image parameters of the original image, and preset light source parameters respectively; calculates shadow parameters according to the shape and size parameters and the light source parameters, and creates a shadow image according to the shadow parameters; reads the original image size from the image parameters, and reads the shadow image size from the shadow parameters; calculates the light and shadow effect diagram size according to the original image size and the shadow image size, and creates an initial light and shadow effect diagram according to the light and shadow effect diagram size; draws the shadow image and the original image on the initial light and shadow effect diagram to obtain a target light and shadow effect diagram; wherein, drawing the shadow image takes precedence over drawing the original image.
[0054] As can be seen from the above technical solution, by presetting light source parameters, calculating shadow parameters based on the shape and size parameters of the target object for which the light and shadow effect diagram is to be generated, the image parameters of the original image corresponding to the target object, and the light source parameters, creating a shadow image based on the shadow parameters, creating an initial light and shadow effect diagram based on the sizes of the original image and the shadow image, and then drawing the shadow image and the original image onto the initial light and shadow effect diagram in the order of the shadow image first and the original image second, to obtain the target light and shadow effect diagram. This achieves adaptive generation of light and shadow effect diagrams based on the application scenario, significantly improving the efficiency of drawing light and shadow effect diagrams and reducing the drawing cost.
[0055] Correspondingly, the present invention also provides a light and shadow effect diagram generation device, equipment and computer-readable storage medium corresponding to the above-mentioned light and shadow effect diagram generation method, which has the above-mentioned technical effects and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0057] Figure 1 This is a flowchart of an implementation of a method for generating a light and shadow effect diagram in an embodiment of the present invention;
[0058] Figure 2 is another implementation flow chart of the method for generating a light and shadow effect diagram in an embodiment of the present invention;
[0059] Figure 3 is another implementation flow chart of the method for generating a light and shadow effect diagram in an embodiment of the present invention;
[0060] Figure 4 A schematic diagram of a light source type selection interface in an embodiment of the present invention;
[0061] Figure 5 This is a schematic diagram of an artificial light parameter setting interface according to an embodiment of the present invention;
[0062] Figure 6 This is a schematic diagram of an artificial light color setting interface in an embodiment of the present invention;
[0063] Figure 7 This is a schematic diagram of a sunlight parameter setting interface in an embodiment of the present invention;
[0064] Figure 8 This is a structural block diagram of a device for generating a light and shadow effect diagram according to an embodiment of the present invention;
[0065] Figure 9 This is a structural block diagram of a device for generating a light and shadow effect diagram in an embodiment of the present invention;
[0066] Figure 10 A schematic diagram of the specific structure of a light and shadow effect diagram generation device provided in this embodiment. DETAILED DESCRIPTION
[0067] In order to enable those skilled in the art to better understand the present invention, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments. Obviously, the embodiments described are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0068] See also Figure 1 , Figure 1 This is a flowchart of an implementation of a method for generating a light and shadow effect diagram in an embodiment of the present invention. The method may include the following steps:
[0069] S101: Acquire a target object for which a light and shadow effect image is to be generated and an original image of the target object.
[0070] When a light and shadow effect diagram is required for a target object, the target object and an original image of the target object are obtained. The obtained original image is an editable image. For example, an image processing interface can be used to create an editable image that is identical to the original non-editable image based on the shape and size of the target object.
[0071] S102: Reading the shape and size parameters of the target object, the image parameters of the original image, and the preset light source parameters respectively.
[0072] Preset the light source parameters corresponding to the light and shadow effect image to be generated, such as the light source type. For artificial light, the light source parameters may include the color of the artificial light and the distance from the artificial light source to the target object. After obtaining the target object for the light and shadow effect image to be generated and the original image of the target object, read the shape and size parameters of the target object, the image parameters of the original image, and the preset light source parameters.
[0073] S103: Calculate shadow parameters according to the shape and size parameters and the light source parameters, and create a shadow image according to the shadow parameters.
[0074] After reading the target object's shape and size parameters and the preset light source parameters, shadow parameters are calculated based on these parameters, and a shadow image is created based on the shadow parameters. For example, when the light source is artificial light, the shadow size is determined based on the shape and size parameters and the distance from the artificial light source to the target object, the shadow color is determined based on the color of the artificial light, and the shadow transparency is determined based on the intensity of the artificial light. When the light source is sunlight, a configuration table can be pre-set and the corresponding shadow parameters can be directly read from the configuration table based on the light source parameters.
[0075] S104: Read the original image size from the image parameters, and read the shadow image size from the shadow parameters.
[0076] The image parameters contain the original image size parameter information, and the shadow parameters contain the shadow image size parameter information. After creating the shadow image according to the shadow parameters, the original image size is read from the image parameters, and the shadow image size is read from the shadow parameters.
[0077] S105: Calculating the size of the light and shadow effect graph according to the size of the original image and the size of the shadow image, and creating an initial light and shadow effect graph according to the size of the light and shadow effect graph.
[0078] After reading the original image size and shadow image size, the size of the light and shadow effect map is calculated based on the original image size and shadow image size, and an initial light and shadow effect map is created based on the light and shadow effect map size. The initial light and shadow effect map is used as a container for subsequent shadow image and original image drawing.
[0079] It should be noted that shadows generally have offsets, so the size of the calculated light and shadow effect image is usually larger than the original image size and the shadow image size.
[0080] S106: Draw the shadow image and the original image on the initial light and shadow effect graph to obtain the target light and shadow effect graph.
[0081] Among them, the drawing of the shadow image takes precedence over the drawing of the original image.
[0082] After creating the initial light and shadow effect diagram, the shadow image and the original image are drawn onto the initial light and shadow effect diagram in the order of shadow image first and original image second, resulting in the target light and shadow effect diagram. By presetting the shadow image drawing to take precedence over the original image drawing, the original image is prevented from being obscured by the shadow image, improving the realism of the generated target light and shadow effect diagram. By presetting the light source parameters, the light and shadow effect diagram of the target object can be quickly generated, providing users with a better light and shadow experience.
[0083] As can be seen from the above technical solution, by presetting light source parameters, calculating shadow parameters based on the shape and size parameters of the target object for which the light and shadow effect diagram is to be generated, the image parameters of the original image corresponding to the target object, and the light source parameters, creating a shadow image based on the shadow parameters, creating an initial light and shadow effect diagram based on the sizes of the original image and the shadow image, and then drawing the shadow image and the original image onto the initial light and shadow effect diagram in the order of the shadow image first and the original image second, to obtain the target light and shadow effect diagram. This achieves adaptive generation of light and shadow effect diagrams based on the application scenario, significantly improving the efficiency of drawing light and shadow effect diagrams and reducing the drawing cost.
[0084] It should be noted that, based on the above embodiment, the embodiment of the present invention also provides corresponding improved solutions. In subsequent embodiments, the same steps or corresponding steps as those in the above embodiment can be referenced to each other, and the corresponding beneficial effects can also be referenced to each other, and will not be described in detail in the following improved embodiments.
[0085] See also Figure 2 , Figure 2 FIG. 5 is another implementation flow chart of a method for generating a light and shadow effect diagram in an embodiment of the present invention. The method may include the following steps:
[0086] S201: Acquire a target object for which a light and shadow effect image is to be generated and an original image of the target object.
[0087] S202: Reading the shape and size parameters of the target object, the image parameters of the original image, and the preset light source parameters respectively.
[0088] S203: When the light source type is artificial light, read the artificial light distance from the artificial light source to the target object and the artificial light direction of the artificial light source relative to the target object from the light source parameters.
[0089] See also Figure 4 and Figure 5 , Figure 4 This is a schematic diagram of a light source type selection interface in an embodiment of the present invention. Figure 5This is a schematic diagram of an artificial light parameter setting interface according to an embodiment of the present invention. Users can pre-select a light source type through the light source type selection interface. The diagram shows two light source types: artificial light and sunlight. The dots before the corresponding text indicate that only one of these two types of light can be selected. A white dot indicates an unselected light source, while a black dot indicates a selected light source, representing the currently set lighting effect.
[0090] When the light source type is artificial light, you can click Figure 4 Click the "Artificial Light Settings" button to set the artificial light source parameters. After clicking it, the interface will look like this: Figure 5 As shown in the figure, there are nine light direction options: upper left, upper, upper right, left, center, right, lower left, lower, and lower right. The dot before the corresponding text indicates that only one of the nine light directions can be selected. A white dot indicates that it is unselected, while a black dot indicates that it is the currently selected light direction. The figure allows you to set the distance of the artificial light source from the target object. You can choose the commonly used units: centimeters, points, or pixels. If you do not enter a value, centimeters will be used by default.
[0091] When the light source type is artificial light, the light source parameters include the artificial light distance from the artificial light source to the target object and the artificial light direction of the artificial light source relative to the target object. The artificial light distance from the artificial light source to the target object and the artificial light direction of the artificial light source relative to the target object are read from the light source parameters.
[0092] Artificial light is light produced by artificially designed and manufactured instruments and equipment, such as fluorescent light and laser.
[0093] S204: Calculating a first shadow position and a first shadow size according to the artificial light distance, the artificial light direction, and the shape and size parameters.
[0094] After reading the artificial light distance from the artificial light source to the target object and the artificial light direction of the artificial light source relative to the target object from the light source parameters, the first shadow position and the first shadow size are calculated based on the artificial light distance, artificial light direction, and shape and size parameters. For example: let the artificial light distance from the artificial light source to the target object be L1, calculate the distance L2 from the target object to the shadow based on the artificial light direction, and calculate the first shadow position based on the distance from the target object to the shadow, the artificial light distance, and the artificial light direction. Let the original shape and size of the target object be S1, then the first shadow size can be calculated using the following formula:
[0095] S2=S1*(L1+L2) 2 / L1 2 ;
[0096] Wherein, S2 is the calculated first shadow size.
[0097] The first shadow position is calculated using the following formula:
[0098] X = (WW*(L1+L2) / L1) / 2;
[0099] Y=(HH*(L1+L2) / L1) / 2;
[0100] Where W is the width of the original image, H is the height of the original image, X is the offset value of the shadow position in the X direction of the original image, and Y is the offset value of the shadow position in the Y direction of the original image.
[0101] S205: Read the artificial light color from the light source parameters, and calculate the shadow color according to the artificial light color.
[0102] like Figure 5 As shown, the artificial light color can also be set in the artificial light parameter setting interface. There is a color setting button next to the color, which can enter the color setting interface to set a specific color value so that the artificial light color is included in the light source parameters.
[0103] See also Figure 6 , Figure 6 This is a schematic diagram of an artificial light color setting interface in an embodiment of the present invention. Figure 6 It can be seen that there are 4 color parameters, namely transparency (A), red (R), green (G), and blue (B), and the value range is between 0 and 255. Figure 6 The selected color in the image displays the specific color information and effects when the user adjusts the parameters. The artificial light color is read from the light source parameters, and the shadow color is calculated based on the artificial light color. For example, if the artificial light color is A and the target object color is B, the shadow color can be calculated as C using the color processing interface. This allows the shadow color to be adjusted by setting the artificial light color.
[0104] S206: Read the artificial light intensity from the light source parameters, and calculate the shadow transparency according to the artificial light intensity.
[0105] like Figure 5 As shown, the artificial light intensity can also be set in the artificial light parameter setting interface. The intensity range filled in is 0%-100%, so that the artificial light intensity is included in the light source parameters. The artificial light intensity is read from the light source parameters and the shadow transparency is calculated based on the artificial light intensity. For example, if the artificial light intensity is 60%, the shadow transparency adjustment value is 60%. If the transparency of a pixel in the image is A, the shadow transparency of that pixel can be calculated using the following formula:
[0106] B = A*(1-60*0.01);
[0107] Among them, B is the shadow transparency.
[0108] S207: constructing shadow parameters according to the first shadow position, the first shadow size, the shadow color, and the shadow transparency, and creating a shadow image according to the shadow parameters.
[0109] After calculating the first shadow position, size, color, and transparency, shadow parameters are constructed based on the first shadow position, size, color, and transparency, and a shadow image is created based on the shadow parameters. The user sets the artificial light source parameters based on their personal preferences, and a shadow image of the target object is obtained under the artificial light of the corresponding light source parameters.
[0110] S208: Read the original image size from the image parameters, and read the shadow image size from the shadow parameters.
[0111] S209: Calculating the size of the light and shadow effect graph according to the size of the original image and the size of the shadow image, and creating an initial light and shadow effect graph according to the size of the light and shadow effect graph.
[0112] S210: Draw the shadow image and the original image on the initial light and shadow effect graph to obtain a target light and shadow effect graph.
[0113] Among them, the drawing of the shadow image takes precedence over the drawing of the original image.
[0114] S211: Determine whether to save the target light and shadow effect image. If so, execute step S212; if not, do nothing.
[0115] like Figure 4 As shown, in the light source type selection interface, you can also pre-set whether to save the target light and shadow effect diagram generated subsequently. The white selection box in the figure indicates whether to save to a specified location or draw directly. If there is a check in the white box, it means it needs to be saved to a specified location, which can be confirmed by browsing the local directory. If there is no check in the white box, it means drawing directly.
[0116] After the target light and shadow effect diagram is generated, it is determined whether to save the target light and shadow effect diagram. If so, step S212 is executed. If not, it means that the subsequently generated target light and shadow effect diagram does not need to be saved and is not processed.
[0117] S212: Read the preset target storage location.
[0118] When it is determined to save the target light and shadow effect image, a preset target storage location is read.
[0119] S213: Save the target light and shadow effect image to the target storage location.
[0120] After reading the preset target storage location, the target light and shadow effect map is saved to the target storage location, so that the target light and shadow effect map can be directly retrieved as needed later.
[0121] See also Figure 3 , Figure 3 FIG. 5 is another implementation flow chart of a method for generating a light and shadow effect diagram in an embodiment of the present invention. The method may include the following steps:
[0122] S301: Acquire a target object for which a light and shadow effect image is to be generated and an original image of the target object.
[0123] S302: Reading the shape and size parameters of the target object, the image parameters of the original image, and the preset light source parameters respectively.
[0124] S303: When the light source type is sunlight, read the sunlight season and sunlight time from the light source parameters.
[0125] like Figure 4 As shown, when the light source type selected by the user through the light source type selection interface is sunlight, the user can further set the light source through the sunlight parameter setting interface.
[0126] See also Figure 7 , Figure 7 Schematic diagram of a sunlight parameter setting interface in an embodiment of the present invention. Figure 7 A white box in the middle indicates whether or not to automatically acquire sunlight data. If the box is checked, it automatically acquires sunlight data. In this case, the dots before the text below do not need to be selected. If the box is unchecked, it indicates that the user can customize the season and time node. In this case, the dots before the text below can be set. Users can select the season and time node according to their needs through the sunlight parameter setting interface.
[0127] Figure 7 There are four seasons to choose from, namely Spring, Summer, Autumn, and Winter. The dot before the corresponding text indicates that only one of the four seasons can be selected. Furthermore, the color of the dot can be used to indicate the current selection status of the four seasons. Gray indicates that the selection operation cannot be performed, white indicates that it is not selected, and black indicates that the season is selected.
[0128] Figure 7There are 10 time nodes to choose from, namely 5:00-7:00, 7:00-10:00, 10:00-14:00, 14:00-17:00, 17:00-19:00, 19:00-21:00, 21:00-24:00, 0:00-2:00, 2:00-4:00, and 4:00-5:00. The dot before the corresponding text indicates that only one of the 10 time nodes can be selected. The color of the dot can also indicate the current selection status of each time node. Gray indicates that the selection operation cannot be performed, white indicates that it is not selected, and black indicates that the time node is selected.
[0129] When the light source type is sunlight, the light source parameters include the sunlight season and sunlight time, and the sunlight season and sunlight time are read from the light source parameters.
[0130] S304: Matching shadow transparency, shadow offset, second shadow position, and second shadow size from a pre-generated configuration table according to shape and size parameters, sunlight season, and sunlight time.
[0131] A configuration table is pre-set to store the corresponding relationships between the sunlight season, sunlight time, shadow transparency, shadow offset, second shadow position, and second shadow size. The second shadow size is calculated based on the shape and size parameters of the target object in combination with the sunlight season and sunlight time. After the sunlight season and sunlight time are read from the light source parameters, the shadow transparency, shadow offset, second shadow position, and second shadow size are matched from the pre-generated configuration table based on the shape and size parameters, sunlight season, and sunlight time.
[0132] S305: Construct shadow parameters according to the shadow transparency, the shadow offset, the second shadow position, and the second shadow size, and create a shadow image according to the shadow parameters.
[0133] After matching the shadow transparency, shadow offset, second shadow position and second shadow size, shadow parameters are constructed according to the shadow transparency, shadow offset, second shadow position and second shadow size, and a shadow image is created according to the shadow parameters, thereby obtaining a shadow image of the target object under sunlight in the corresponding season and time node.
[0134] S306: Read the original image size from the image parameters, and read the shadow image size from the shadow parameters.
[0135] S307: Calculate the size of the light and shadow effect graph according to the size of the original image and the size of the shadow image, and create an initial light and shadow effect graph according to the size of the light and shadow effect graph.
[0136] S308: Draw the shadow image and the original image on the initial light and shadow effect graph to obtain the target light and shadow effect graph.
[0137] Among them, the drawing of the shadow image takes precedence over the drawing of the original image.
[0138] The present invention can quickly generate a rendering with light and shadow effects based on a given season and time node of sunlight.
[0139] S309: Determine whether to save the target light and shadow effect image. If so, execute step S310; if not, do nothing.
[0140] S310: Reading a preset target storage location.
[0141] S311: Save the target light and shadow effect image to the target storage location.
[0142] Corresponding to the above method embodiment, the present invention further provides a device for generating a light and shadow effect diagram. The device for generating a light and shadow effect diagram described below and the method for generating a light and shadow effect diagram described above can refer to each other.
[0143] See also Figure 8 , Figure 8 This is a structural block diagram of a device for generating a light and shadow effect diagram in an embodiment of the present invention. The device may include:
[0144] The object and image acquisition module 81 is used to acquire the target object for generating the light and shadow effect image and the original image of the target object;
[0145] The parameter reading module 82 is used to read the shape and size parameters of the target object, the image parameters of the original image, and the preset light source parameters;
[0146] A shadow parameter calculation module 83 is used to calculate shadow parameters according to shape and size parameters and light source parameters, and create a shadow image according to the shadow parameters;
[0147] An image size reading module 84 is used to read the original image size from the image parameters and read the shadow image size from the shadow parameters;
[0148] An initial effect diagram creation module 85 is used to calculate the size of the light and shadow effect diagram according to the size of the original image and the size of the shadow image, and to create an initial light and shadow effect diagram according to the size of the light and shadow effect diagram;
[0149] The image drawing module 86 is used to draw the shadow image and the original image on the initial light and shadow effect diagram to obtain the target light and shadow effect diagram; wherein, the drawing of the shadow image takes precedence over the drawing of the original image.
[0150] As can be seen from the above technical solution, by presetting light source parameters, calculating shadow parameters based on the shape and size parameters of the target object for which the light and shadow effect diagram is to be generated, the image parameters of the original image corresponding to the target object, and the light source parameters, creating a shadow image based on the shadow parameters, creating an initial light and shadow effect diagram based on the sizes of the original image and the shadow image, and then drawing the shadow image and the original image onto the initial light and shadow effect diagram in the order of the shadow image first and the original image second, to obtain the target light and shadow effect diagram. This achieves adaptive generation of light and shadow effect diagrams based on the application scenario, significantly improving the efficiency of drawing light and shadow effect diagrams and reducing the drawing cost.
[0151] In a specific embodiment of the present invention, the shadow parameter calculation module 83 includes:
[0152] The distance and direction reading submodule is used to read the artificial light distance from the artificial light source to the target object and the artificial light direction of the artificial light source relative to the target object from the light source parameters when the light source type is artificial light;
[0153] a position and size calculation submodule, configured to calculate the first shadow position and the first shadow size according to the artificial light distance, the artificial light direction, and the shape and size parameters;
[0154] The shadow color calculation submodule is used to read the artificial light color from the light source parameters and calculate the shadow color based on the artificial light color;
[0155] The shadow transparency calculation submodule is used to read the artificial light intensity from the light source parameters and calculate the shadow transparency according to the artificial light intensity;
[0156] The first parameter construction submodule is used to construct shadow parameters according to the first shadow position, the first shadow size, the shadow color and the shadow transparency.
[0157] In a specific embodiment of the present invention, the shadow parameter calculation module 83 includes:
[0158] The season and time reading submodule is used to read the sunlight season and sunlight time from the light source parameters when the light source type is sunlight;
[0159] a parameter matching submodule for matching shadow transparency, shadow offset, second shadow position, and second shadow size from a pre-generated configuration table according to shape size parameters, sunlight season, and sunlight time;
[0160] The second parameter construction submodule is used to construct shadow parameters according to shadow transparency, shadow offset, second shadow position and second shadow size.
[0161] In a specific embodiment of the present invention, the device may further include:
[0162] A judgment module is used to judge whether to save the target light and shadow effect diagram after obtaining the target light and shadow effect diagram;
[0163] A storage location reading module is used to read a preset target storage location when it is determined to save the target light and shadow effect image;
[0164] The image saving module is used to save the target light and shadow effect image to the target storage location.
[0165] Corresponding to the above method embodiment, see Figure 9 , Figure 9 This is a schematic diagram of a device for generating a light and shadow effect diagram provided by the present invention, which may include:
[0166] Memory 332, for storing computer programs;
[0167] The processor 322 is configured to implement the steps of the method for generating the light and shadow effect diagram of the above method embodiment when executing a computer program.
[0168] For details, please refer to Figure 10 , Figure 10 A schematic diagram of the specific structure of a device for generating a light and shadow effect diagram provided in this embodiment, the device for generating the light and shadow effect diagram may have relatively large differences due to different configurations or performances, and may include a processor (central processing units, CPU) 322 (for example, one or more processors) and a memory 332, and the memory 332 stores one or more computer applications 342 or data 344. Among them, the memory 332 can be a temporary storage or a permanent storage. The program stored in the memory 332 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the data processing device. Furthermore, the processor 322 can be configured to communicate with the memory 332 to execute a series of instruction operations in the memory 332 on the device 301 for generating the light and shadow effect diagram.
[0169] The light and shadow effect image generating device 301 may further include one or more power supplies 326 , one or more wired or wireless network interfaces 350 , one or more input and output interfaces 358 , and / or one or more operating systems 341 .
[0170] The steps in the method for generating a light and shadow effect diagram described above can be implemented by the structure of a device for generating a light and shadow effect diagram.
[0171] Corresponding to the above method embodiment, the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the following steps can be implemented:
[0172] Obtain a target object for generating a light and shadow effect diagram and an original image of the target object; read the shape and size parameters of the target object, the image parameters of the original image, and the preset light source parameters respectively; calculate the shadow parameters according to the shape and size parameters and the light source parameters, and create a shadow image according to the shadow parameters; read the original image size from the image parameters, and read the shadow image size from the shadow parameters; calculate the light and shadow effect diagram size according to the original image size and the shadow image size, and create an initial light and shadow effect diagram according to the light and shadow effect diagram size; draw the shadow image and the original image on the initial light and shadow effect diagram to obtain the target light and shadow effect diagram; wherein, drawing the shadow image takes precedence over drawing the original image.
[0173] The computer-readable storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc., which can store program codes.
[0174] For an introduction to the computer-readable storage medium provided by the present invention, please refer to the above method embodiment, and the present invention will not elaborate on it here.
[0175] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from the other embodiments. References to the same or similar parts between the various embodiments are sufficient. The devices, apparatuses, and computer-readable storage media disclosed in the embodiments are described briefly because they correspond to the methods disclosed in the embodiments. For relevant details, refer to the description of the methods.
[0176] This document uses specific examples to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only intended to help understand the technical solutions and core concepts of the present invention. It should be noted that those skilled in the art can make various improvements and modifications to the present invention without departing from the principles of the present invention, and such improvements and modifications also fall within the scope of protection of the claims of the present invention.
Claims
1. A method for generating a light and shadow effect diagram, characterized in that: include: Acquire a target object for which a light and shadow effect diagram is to be generated and an original image of the target object; wherein the original image is an editable image that is the same as the original non-editable image and is created according to the shape and size of the target object through an image processing interface; Respectively reading the shape and size parameters of the target object, the image parameters of the original image, and the preset light source parameters; Calculating shadow parameters according to the shape size parameters and the light source parameters, and creating a shadow image according to the shadow parameters; Reading the original image size from the image parameters, and reading the shadow image size from the shadow parameters; Calculating the size of the light and shadow effect graph according to the size of the original image and the size of the shadow image, and creating an initial light and shadow effect graph according to the size of the light and shadow effect graph; wherein the initial light and shadow effect graph is used as a container for drawing the shadow image and the original image, and the size of the initial light and shadow effect graph is larger than the size of the original image and the size of the shadow image; Drawing the shadow image and the original image on the initial light and shadow effect diagram to obtain a target light and shadow effect diagram; wherein the drawing of the shadow image takes precedence over the drawing of the original image; Determine whether to save the target light and shadow effect image; If so, read the preset target storage location; Saving the target light and shadow effect image to the target storage location; Calculating shadow parameters according to the shape size parameters and the light source parameters includes: When the light source type is artificial light, reading the artificial light distance from the artificial light source to the target object and the artificial light direction of the artificial light source relative to the target object from the light source parameters; Calculate a first shadow position and a first shadow size according to the artificial light distance, the artificial light direction and the shape and size parameters; Reading the artificial light color from the light source parameters, and calculating the shadow color according to the artificial light color; Reading artificial light intensity from the light source parameters, and calculating shadow transparency according to the artificial light intensity; Constructing the shadow parameters according to the first shadow position, the first shadow size, the shadow color and the shadow transparency; The first shadow size is calculated by the formula: ; S1 is the original shape and size of the target object, L1 is the artificial light distance from the artificial light source to the target object, and L2 is the distance from the target object to the shadow calculated according to the direction of the artificial light; the first shadow position is calculated by the formula: ; ; W is the width of the original image, H is the height of the original image, X is the offset value of the shadow position in the X direction of the original image, and Y is the offset value of the shadow position in the Y direction of the original image.
2. The method for generating a light and shadow effect diagram according to claim 1, characterized in that: Calculating shadow parameters according to the shape size parameters and the light source parameters includes: When the light source type is sunlight, reading the sunlight season and sunlight time from the light source parameters; matching a shadow transparency, a shadow offset, a second shadow position, and a second shadow size from a pre-generated configuration table according to the shape size parameters, the sunlight season, and the sunlight time; The shadow parameters are constructed according to the shadow transparency, the shadow offset, the second shadow position and the second shadow size.
3. A device for generating a light and shadow effect diagram, characterized in that: include: An object and image acquisition module, used to acquire a target object for which a light and shadow effect diagram is to be generated and an original image of the target object; wherein the original image is an editable image that is the same as the original non-editable image and is created according to the shape and size of the target object through an image processing interface; A parameter reading module, used to read the shape and size parameters of the target object, the image parameters of the original image and the preset light source parameters respectively; A shadow parameter calculation module, used to calculate shadow parameters according to the shape size parameters and the light source parameters, and create a shadow image according to the shadow parameters; An image size reading module, used for reading the original image size from the image parameters, and reading the shadow image size from the shadow parameters; An initial effect picture creation module is used to calculate the size of the light and shadow effect picture according to the size of the original image and the size of the shadow image, and to create an initial light and shadow effect picture according to the size of the light and shadow effect picture; wherein the initial light and shadow effect picture is used as a container for drawing the shadow image and the original image, and the size of the initial light and shadow effect picture is larger than the size of the original image and the size of the shadow image; An image drawing module, used for drawing the shadow image and the original image on the initial light and shadow effect diagram to obtain a target light and shadow effect diagram; wherein the drawing of the shadow image takes precedence over the drawing of the original image; A judgment module, used for judging whether to save the target light and shadow effect diagram after obtaining the target light and shadow effect diagram; A storage location reading module, used for reading a preset target storage location when determining to perform a saving operation on the target light and shadow effect graph; An image saving module, used for saving the target light and shadow effect image to the target storage location; The shadow parameter calculation module includes: A distance and direction reading submodule, for reading, when the light source type is artificial light, the artificial light distance from the artificial light source to the target object and the artificial light direction of the artificial light source relative to the target object from the light source parameters; A position and size calculation submodule, used to calculate the first shadow position and the first shadow size according to the artificial light distance, the artificial light direction and the shape and size parameters; A shadow color calculation submodule, used to read the artificial light color from the light source parameters, and calculate the shadow color according to the artificial light color; A shadow transparency calculation submodule, used for reading the artificial light intensity from the light source parameters, and calculating the shadow transparency according to the artificial light intensity; A first parameter construction submodule, used for constructing the shadow parameters according to the first shadow position, the first shadow size, the shadow color and the shadow transparency; The first shadow size is calculated by the formula: ; S1 is the original shape and size of the target object, L1 is the artificial light distance from the artificial light source to the target object, and L2 is the distance from the target object to the shadow calculated according to the direction of the artificial light; the first shadow position is calculated by the formula: ; ; W is the width of the original image, H is the height of the original image, X is the offset value of the shadow position in the X direction of the original image, and Y is the offset value of the shadow position in the Y direction of the original image.
4. The device for generating a light and shadow effect diagram according to claim 3, characterized in that: The shadow parameter calculation module includes: A season and time reading submodule, used for reading the sunlight season and sunlight time from the light source parameters when the light source type is sunlight; a parameter matching submodule, for matching shadow transparency, shadow offset, second shadow position and second shadow size from a pre-generated configuration table according to the shape size parameter, the sunlight season and the sunlight time; The second parameter construction submodule is used to construct the shadow parameters according to the shadow transparency, the shadow offset, the second shadow position and the second shadow size.
5. A device for generating a light and shadow effect diagram, characterized in that: include: Memory for storing computer programs; A processor, used to implement the steps of the method for generating a light and shadow effect diagram as described in any one of claims 1 to 2 when executing the computer program.
6. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method for generating a light and shadow effect diagram as described in any one of claims 1 to 2 are implemented.
Citation Information
Patent Citations
Virtual object display method and device, equipment and storage medium
CN111862295A
Shadow rendering method, device and electronic equipment
CN113240787A