Lightning Special Effect Drawing Method, Device, Computer Equipment and Readable Storage Medium

Through iterative processing and random selection of connection points, a complete lightning structure is formed, which solves the problems of poor lightning special effects and large time and space overhead in the existing technology, and achieves flexibility and real-time rendering effects.

CN114723856BActive Publication Date: 2025-06-24SHENZHEN WONDERSHARE SOFTWARE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210342569.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-31
Publication Date
2025-06-24
Estimated Expiration
2042-03-31

AI Technical Summary

Technical Problem

The prior art has poor effect when superimposing lightning special effects in video content. The traditional method has the problem of high customization but not flexible enough, or the time and space overhead is large, making it difficult to achieve real-time rendering.

Method used

By obtaining the starting point and end point of the lightning trunk structure, iterative processing is performed to determine the lightning inflection point, connecting to form the backbone structure, randomly selecting the connection point as the starting point of the branch, and determining the branch end point based on the branch direction and length, and continuing iterative processing to form a complete lightning structure.

Benefits of technology

It realizes the flexibility and real-time rendering of lightning structure, improves the presentation effect of lightning special effects in video, and solves the major problems of time and space overhead of traditional methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114723856B_ABST
    Figure CN114723856B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device, computer device and storage medium for drawing lightning special effects. The method includes obtaining the starting point and the ending point of the lightning trunk structure; performing iterative processing on the lightning trunk structure to determine the lightning inflection points on the lightning trunk structure; after the iterative processing ends, connecting all the connection points corresponding to the lightning trunk structure in sequence to obtain the lightning trunk structure, generating a lightning branch structure based on the lightning trunk structure, and finally forming a final complete lightning structure, and storing the coordinates and corresponding index values of all the connection points in the lightning trunk structure and each lightning branch structure into the connection point sequence corresponding to the lightning branch structure. From the perspective of the algorithm, this method ensures that the structure of the lightning can be changed in real time through parameters, solves the problems of large time and space overhead of the traditional lightning structure algorithm, and improves the presentation effect of the lightning special effects in the video.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the field of image processing, and in particular, to a method, device, computer device, and storage medium for lightning special effect drawing. Background Art

[0002] With the rapid rise of various short video platforms, there is an increasing demand for new creative ideas for video content by adding filters, special effects, etc. through various video editing software. Among them, the simulation of lightning special effects related to natural phenomena has a wide range of application prospects.

[0003] In traditional methods, superimposing lightning special effects on video content generally falls into two methods: based on texture maps and based on algorithms. Currently, lightning special effects based on texture maps are very common in various software. The implementation of such effects is generally that designers pre-make lightning texture maps, then fuse the texture maps with video frames, and finally display the lightning texture in the specified area. Here, the texture can be a single image or a flash animation. The advantage of this method is high customization, and designers can design corresponding texture maps according to requirements. However, the disadvantage of this method is that it is not flexible enough, and shape repetition is easily seen when used in batches. Another method is to use algorithm models to generate in real time. For example, the Poisson growth algorithm and the Laplace growth algorithm after alignment simplification. Although this type of method can solve the problem of shape repetition and adjust the shape of lightning through algorithm parameters, it has the disadvantages of large time overhead and space overhead, and it is difficult to apply in real-time rendering of high-definition, ultra-high definition, or even 2K videos. Summary of the Invention

[0004] Embodiments of the present invention provide a method, device, computer device, and readable storage medium for lightning special effect drawing, aiming to solve the problem of poor effects when superimposing lightning special effects on video content in the prior art.

[0005] In a first aspect, embodiments of the present invention provide a method for lightning special effect drawing, which includes:

[0006] Obtain the starting point and ending point of the lightning trunk structure;

[0007] Iterative processing of the lightning trunk structure: Based on the coordinates of the starting point, the coordinates of the ending point, and a preset offset parameter, perform iterative calculations of multi-level lightning inflection points, and determine whether the offset parameter is less than a preset minimum threshold in the iterative calculation of each level of lightning inflection points. If not, continue the iterative calculation; if so, end the iterative calculation; wherein, the offset parameter decreases according to the iterative level.

[0008] After the iterative process ends, connect all the connection points corresponding to the lightning backbone structure in sequence to obtain the lightning backbone structure, and store the coordinates and corresponding index values of all the connection points into the connection point sequence corresponding to the lightning backbone structure. The connection points include: a starting point, an ending point, and each lightning inflection point. The index value is the unique serial number corresponding to each connection point.

[0009] Randomly select several connection points from the connection point sequence corresponding to the lightning backbone structure as the starting points corresponding to each lightning branch structure based on the complexity parameter, and determine the ending points corresponding to each lightning branch structure based on the preset branch direction and branch length.

[0010] Continue to perform iterative processing on multi-level lightning inflection points for each lightning branch structure. After the iterative process ends, connect all the connection points corresponding to each lightning branch structure in sequence to obtain each lightning branch structure, form the final complete lightning structure, and store the coordinates and corresponding index values of all the connection points in each lightning branch structure into the connection point sequence corresponding to the lightning branch structure.

[0011] In a second aspect, an embodiment of the present invention provides a lightning special effect rendering device, which includes:

[0012] An acquisition module, configured to acquire the starting point and the ending point of the lightning backbone structure;

[0013] An iterative processing module, configured to perform iterative processing on the lightning backbone structure: perform iterative calculation of multi-level lightning inflection points based on the coordinates of the starting point, the coordinates of the ending point, and the preset offset parameter, and determine whether the offset parameter is less than the preset minimum threshold in the iterative calculation of each level of lightning inflection point. If not, continue the iterative calculation; if so, end the iterative calculation. Wherein, the offset parameter decreases according to the iterative level;

[0014] A first connection module, configured to, after the iterative process ends, connect all the connection points corresponding to the lightning backbone structure in sequence to obtain the lightning backbone structure, and store the coordinates and corresponding index values of all the connection points into the connection point sequence corresponding to the lightning backbone structure. The connection points include: a starting point, an ending point, and each lightning inflection point. The index value is the unique serial number corresponding to each connection point.

[0015] A selection module, configured to randomly select several connection points from the connection point sequence corresponding to the lightning backbone structure as the starting points corresponding to each lightning branch structure based on the complexity parameter, and determine the ending points corresponding to each lightning branch structure based on the preset branch direction and branch length.

[0016] A second connection module is configured to continue the iterative processing of multiple lightning inflection points for each lightning branch structure. After the iterative processing is completed, all connection points corresponding to each lightning branch structure are connected in sequence to obtain each lightning branch structure, forming a final complete lightning structure, and the coordinates and corresponding index values of all connection points in each lightning branch structure are stored in the connection point sequence corresponding to the lightning branch structure.

[0017] In a third aspect, an embodiment of the present invention further provides a computer device, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the lightning special effect drawing method described in the first aspect above is implemented.

[0018] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor is caused to execute the lightning special effect drawing method described in the first aspect above.

[0019] An embodiment of the present invention provides a lightning special effect drawing method, device, computer device, and storage medium. The method includes obtaining the starting point and ending point of a lightning trunk structure; performing iterative processing on the lightning trunk structure to determine the lightning inflection points on the lightning trunk structure; after the iterative processing is completed, connecting all connection points corresponding to the lightning trunk structure in sequence to obtain the lightning trunk structure, and storing the coordinates and corresponding index values of all connection points in the connection point sequence corresponding to the lightning trunk structure; randomly selecting a number of connection points from the connection point sequence corresponding to the lightning trunk structure as the starting points of each lightning branch structure based on a complexity parameter, and determining the ending points of each lightning branch structure based on a preset branch direction and branch length; continuing the iterative processing of multiple lightning inflection points for each lightning branch structure, and after the iterative processing is completed, connecting all connection points corresponding to each lightning branch structure in sequence to obtain each lightning branch structure, forming a final complete lightning structure, and storing the coordinates and corresponding index values of all connection points in each lightning branch structure in the connection point sequence corresponding to the lightning branch structure. From an algorithm perspective, this method ensures that the structure of the lightning can be changed in real time through parameters such as the starting point, ending point, and offset parameter, solves the problem of large time and space overhead of traditional lightning structure algorithms, and improves the presentation effect of lightning special effects in videos. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for the description of the embodiments will be briefly introduced below. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0021] Figure 1 Schematic flowchart of an embodiment of the lightning special effect drawing method provided by the present invention;

[0022] Figure 2 For Figure 1 Sub - flowchart schematic diagram of step S120 in an embodiment of

[0023] Figure 3 For Figure 1 Sub - flowchart schematic diagram of step S140 in an embodiment of

[0024] Figure 4 For Figure 1 Sub - flowchart schematic diagram of step S150 in an embodiment of

[0025] Figure 5 Schematic flowchart of another embodiment of the lightning special effect drawing method provided by the present invention;

[0026] Figure 6 Schematic block diagram of the lightning special effect drawing device provided by the present invention;

[0027] Figure 7 Schematic diagram of the iterative processing of the lightning trunk structure in the lightning special effect drawing method provided by the present invention;

[0028] Figure 8 Schematic diagram of the blur algorithm convolution kernel in the lightning special effect drawing method provided by the present invention. Detailed implementation manners

[0029] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0030] It should be understood that when used in this specification and the appended claims, the terms "comprises" and "comprising" indicate the presence of the described features, wholes, steps, operations, elements, and / or components, but do not preclude the presence or addition of one or more other features, wholes, steps, operations, elements, components, and / or their combinations.

[0031] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in this specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an", and "the" are intended to include the plural forms.

[0032] It should also be further understood that the term "and / or" used in the specification and appended claims of the present invention refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0033] Please refer to Figure 1 FIG. is a schematic flow chart of a lightning special effect drawing method provided for an embodiment of the present invention, and the method includes steps S110 to S150.

[0034] Step S110: Obtain the starting point and ending point of the lightning trunk structure;

[0035] Step S120: Iterative processing of the lightning trunk structure: Based on the coordinates of the starting point, the coordinates of the ending point, and a preset offset parameter, perform iterative calculations of multi-level lightning inflection points, and determine whether the offset parameter is less than a preset minimum threshold in the iterative calculation of each level of lightning inflection points. If not, continue the iterative calculation; if so, end the iterative calculation; wherein, the offset parameter decreases according to the iterative level;

[0036] In this embodiment, an image to which a lightning special effect is to be added is obtained, the starting point and ending point of the lightning trunk structure are determined on the image, iterative calculations of multi-level lightning inflection points are performed based on the coordinates of the starting point, the coordinates of the ending point, and a preset offset parameter, and it is determined whether the offset parameter is less than a preset minimum threshold in the iterative calculation of each level of lightning inflection points. If not, continue the iterative calculation; if so, end the iterative calculation. Among them, the offset parameter represents the maximum threshold of the midpoint offset, and according to the shape of the lightning, it is set that the offset parameter decreases according to the iterative level, for example, it is decreased to half of the original; the minimum threshold is determined according to the computing power of the user terminal and can be appropriately adjusted.

[0037] As Figure 2 shown, in one embodiment, step S120 includes:

[0038] Step S210: Based on the coordinates of the starting point and the coordinates of the ending point, perform midpoint calculation to obtain the first-level midpoint coordinates of the lightning trunk structure;

[0039] Step S220: Based on the first-level midpoint coordinates, the offset parameter, and a preset random seed function, perform inflection point calculation on the lightning inflection point to obtain the coordinates of the first-level lightning inflection point;

[0040] Step S230: Perform a decreasing process on the offset parameter to obtain an updated offset parameter, and determine whether the updated offset parameter is less than a preset minimum threshold. If so, end the iterative calculation; if not, based on the coordinates of the starting point and the coordinates of the first-level lightning inflection point, perform midpoint calculation to obtain one of the second-level midpoint coordinates, and based on the coordinates of the first-level lightning inflection point and the coordinates of the ending point, perform midpoint calculation to obtain the other second-level midpoint coordinates;

[0041] Step S240: Calculate the inflection points of the lightning inflection points based on the secondary midpoint coordinates, offset parameters, and preset random seed function to obtain the coordinates of the secondary lightning inflection points;

[0042] Step S250: Continue to perform a decrement process on the offset parameter to obtain an updated offset parameter, and determine whether the updated offset parameter is less than a preset minimum threshold, and so on, until the updated offset parameter is less than the preset minimum threshold.

[0043] In this embodiment, the midpoint calculation is performed based on the coordinates of the starting point and the coordinates of the ending point to obtain the first-level midpoint coordinates of the lightning trunk structure; the inflection point calculation of the lightning inflection point is performed based on the first-level midpoint coordinates, offset parameters, and preset random seed function to obtain the coordinates of the first-level lightning inflection point. The inflection point calculation is performed according to the following calculation formula:

[0044] mid_x = (x2 + x1) / 2 + ((rand() % 100) / 50.0 - 1.0) * displace;

[0045] mid_y = (y2 + y1) / 2 + ((rand() % 100) / 50.0 - 1.0) * displace;

[0046] Among them, (mid_x, mid_y) represents the coordinates of the first-level lightning inflection point, (x1, y1) represents the starting point coordinates, (x2, y2) represents the ending point coordinates, rand() represents the random seed function, and displace represents the offset parameter. The random seed function generates different coordinate parameters during each inflection point calculation, and then the offset parameter is decremented to obtain an updated offset parameter. Determine whether the updated offset parameter is less than the preset minimum threshold. If so, end the iterative calculation. If not, perform a midpoint calculation based on the coordinates of the starting point and the coordinates of the first-level lightning inflection point to obtain one of the secondary midpoint coordinates, and perform a midpoint calculation based on the coordinates of the first-level lightning inflection point and the coordinates of the ending point to obtain the other secondary midpoint coordinates; perform an inflection point calculation on the lightning inflection point based on the secondary midpoint coordinates, offset parameters, and preset random seed function to obtain the coordinates of the secondary lightning inflection point; continue to perform a decrement process on the offset parameter to obtain an updated offset parameter, and determine whether the updated offset parameter is less than the preset minimum threshold, and so on. Repeat the calculation of the lightning inflection point until the updated offset parameter is less than the preset minimum threshold.

[0047] For example Figure 7As shown, the midpoint is calculated based on the start and end coordinates of L1 to obtain the first-level midpoint coordinates. The lightning inflection points are calculated based on the first-level midpoint coordinates, the offset parameter, and the random seed function to obtain the coordinates of the first-level lightning inflection points. The offset parameter is decremented to obtain the updated offset parameter. If the updated offset parameter is less than the preset minimum threshold, the first-level lightning inflection points, the start point, and the end point are connected in sequence to obtain structure L2. If the updated offset parameter is not less than the preset minimum threshold, the midpoint is calculated based on the coordinates of the start point and the coordinates of the first-level lightning inflection points to obtain one of the second-level midpoint coordinates, and the midpoint is calculated based on the coordinates of the first-level lightning inflection points and the coordinates of the end point to obtain the other second-level midpoint coordinates. Finally, the lightning inflection points are calculated based on the second-level midpoint coordinates, the offset parameter, and the preset random seed function to obtain the coordinates of the second-level lightning inflection points. The offset parameter is decremented to obtain the updated offset parameter. If the updated offset parameter is less than the preset minimum threshold, the iterative calculation is ended, that is, structure L3 is obtained.

[0048] Step S130: After the iterative process ends, all the connection points corresponding to the lightning trunk structure are connected in sequence to obtain the lightning trunk structure, and the coordinates and corresponding index values of all the connection points are stored in the connection point sequence corresponding to the lightning trunk structure. The connection points include: the start point, the end point, and each lightning inflection point, and the index value is the unique serial number corresponding to each connection point.

[0049] In this embodiment, when the offset parameter is less than the minimum threshold during the iterative process, the iterative process ends, and all the connection points (the start point, the end point, and each lightning inflection point) of the lightning trunk structure are obtained. The connection points corresponding to the lightning trunk structure are sorted according to the distance from the start point, and the closer to the start point, the higher the ranking, to obtain the index value corresponding to each connection point. The index value is the unique serial number corresponding to each connection point. Finally, the coordinates and corresponding index values of all the connection points are stored in the connection point sequence corresponding to the lightning trunk structure. For example, the start point (mainStrPoint.x, mainStrPoint.y) is stored in the connection point sequence, and the serial number of the start point is 0, so the sequence corresponding to the start point is (mainStrPoint.x, mainStrPoint.y, 0).

[0050] Step S140: Based on the complexity parameter, several connection points are randomly selected from the connection point sequence corresponding to the lightning trunk structure as the start points of each lightning branch structure, and based on the preset branch direction and branch length, the end points corresponding to each lightning branch structure are determined.

[0051] In this embodiment, the starting point of the lightning branch structure must be located on the lightning main structure, and the direction parameter of the lightning branch structure must be generally in the same orientation as the lightning main structure. Therefore, the included angle between the branch and L3 is preferably within 0 to 90°. If it is too large, it will cause the branch to grow in the reverse direction and the desired lightning structure cannot be obtained. The length of the lightning branch structure is preferably defined to be between 20% and 50% of the length of the lightning main structure. If it is too short, the effect is not obvious, and if it is too long, the primary-secondary relationship between the lightning main structure and the lightning branch structure will not be obvious in the visualization result. Define the complexity parameter as the number of branches. The larger the value of the complexity parameter, the more branches there are, and the higher the rendering performance. Based on the complexity parameter, randomly select several connection points from the connection point sequence corresponding to the lightning main structure as the starting point of each lightning branch structure, and determine the end point of each lightning branch structure based on the preset branch direction and branch length.

[0052] As Figure 3 shown, in one embodiment, step S140 includes:

[0053] Step S310, generate a corresponding number of random numbers within the range of the complexity parameter according to the complexity parameter and a preset random function;

[0054] Step S320, find the index value corresponding to the random number from the connection point sequence corresponding to the lightning main structure to obtain the target index value;

[0055] Step S330, use the connection point corresponding to the target index value as the starting point of the lightning branch.

[0056] In this embodiment, the index values of all connection points in the connection point sequence corresponding to the lightning main structure are known. According to the complexity parameter and a preset random function, randomly generate a corresponding number of random numbers within the range of the complexity parameter, and the random numbers can be found among the index values. Find the index value corresponding to the random number from the connection point sequence corresponding to the lightning main structure to obtain the target index value; use the connection point corresponding to the target index as the starting point of the lightning branch.

[0057] For example, the complexity parameter is 3, and the index values in the connection point sequence corresponding to the lightning main structure are (1, 2, 3, 4, 5, 6). The coordinates of the connection point corresponding to each index value are omitted here. The randomly generated random numbers according to the complexity parameter are (2, 5, 6), then use the coordinates of the connection points corresponding to the index values 2, 5, and 6 as the starting points of the lightning branches.

[0058] Step S150: Continue to perform iterative processing on multiple lightning inflection points for each lightning branch structure. After the iterative processing is completed, connect all the connection points corresponding to each lightning branch structure in sequence to obtain each lightning branch structure, forming the final complete lightning structure, and store the coordinates and corresponding index values of all the connection points in each lightning branch structure into the connection point sequence corresponding to the lightning branch structure.

[0059] In this embodiment, after obtaining the lightning branch structure, continue to repeat the iterative processing of the lightning main structure, and continue to perform iterative processing on multiple lightning inflection points for each lightning branch structure to determine the lightning inflection points on the lightning branch structure; finally, connect all the connection points (the lightning inflection points, starting points, and ending points on the lightning branch structure) corresponding to each lightning branch structure in sequence to obtain each lightning branch structure, forming the final complete lightning structure, and store the coordinates and corresponding index values of all the connection points in each lightning branch structure into the connection point sequence corresponding to the lightning branch structure.

[0060] As Figure 4 shown, in one embodiment, step S150 includes:

[0061] Step S410: Connect all the connection points corresponding to each lightning branch structure in sequence to obtain each lightning branch structure;

[0062] Step S420: Continue to randomly select several connection points from the connection point sequence corresponding to the lightning branch structure as the starting points of the corresponding secondary lightning branch structures based on the complexity parameter, and determine the ending points of the corresponding secondary lightning branch structures based on the preset branch direction and branch length;

[0063] Step S430: Continue to perform iterative processing on multiple lightning inflection points for the secondary lightning branch structures to obtain the secondary lightning branch structures;

[0064] Step S440: Continue to randomly select several connection points from the connection point sequence corresponding to the secondary lightning branch structures as the starting points of the corresponding more secondary lightning branch structures based on the complexity parameter, and determine the ending points of the corresponding more secondary lightning branch structures based on the preset branch direction and branch length;

[0065] Step S450: Continue to perform iterative processing on multiple lightning inflection points for the more secondary lightning branch structures until the complexity parameter requirements are met.

[0066] In this embodiment, a multi-level lightning branch structure is defined. After obtaining each lightning branch structure, a secondary lightning branch structure is constructed in each lightning branch structure: Based on the complexity parameter, several connection points are randomly selected from the connection point sequence corresponding to the lightning branch structure as the starting points of the corresponding secondary lightning branch structures, and based on the preset branch direction and branch length, the end points of the corresponding secondary lightning branch structures are determined; Then, iterative processing of multi-level lightning inflection points is continued for the secondary lightning branch structures to obtain the lightning inflection points on the secondary lightning branch structures. Connecting the starting points, end points, and lightning inflection points of the secondary lightning branch structures, the secondary lightning branch structures are obtained. By analogy, if the requirements of the complexity parameter are not saturated, continue to construct more secondary lightning branch structures on the secondary lightning branch structures: Based on the complexity parameter, several connection points are randomly selected from the connection point sequence corresponding to the secondary lightning branch structures as the starting points of the corresponding more secondary lightning branch structures, and based on the preset branch direction and branch length, the end points of the corresponding more secondary lightning branch structures are determined. Then, iterative processing of multi-level lightning inflection points is continued for the more secondary lightning branch structures to obtain the lightning inflection points on the more secondary lightning branch structures. Connecting the starting points, end points, and lightning inflection points of the more secondary lightning branch structures, the more secondary lightning branch structures are obtained. Among them, the maximum number within each level of lightning branch structure is divided. If the complexity parameter is greater than the maximum number of the current level of lightning branch structure, a secondary lightning branch structure is generated on the current level of lightning branch structure.

[0067] For example, A. When the complexity parameter displace is between [0, 3], 3 connection points are selected from the connection point sequence corresponding to the lightning trunk structure as the starting points of the lightning branch structures to generate lightning branch structures; B. When the complexity parameter is between [4, 6], first execute A to generate 3 lightning branch structures from the lightning trunk structure, and then select displace - 3 connection points from the connection point sequences corresponding to the 3 lightning branch structures as the starting points of the secondary lightning branches to generate secondary lightning branch structures; C. When the complexity parameter displace is above 6, first execute A and B, and then select displace - 6 connection points from the connection point sequence corresponding to the secondary lightning branch structures generated in B as the starting points of the more secondary lightning branches to generate more secondary lightning branch structures.

[0068] As Figure 5 shown, in one embodiment, the lightning special effect drawing method further includes:

[0069] Step S510: Blur the complete lightning structure to obtain a blurred lightning structure;

[0070] Step S520: Mix the complete lightning structure and the blurred lightning structure to obtain the special effect layer of the lightning.

[0071] Step S530: Perform color dodge blending on the image where the complete lightning structure acts and the special effect layer to obtain the final lightning special effect.

[0072] In this embodiment, adding a glow effect to the complete lightning structure specifically includes: performing blurring processing on the complete lightning structure to obtain a blurred lightning structure; performing alpha blending on the complete lightning structure and the blurred lightning structure to obtain the special effect layer of the lightning; performing color dodge blending on the image where the complete lightning structure acts and the special effect layer to obtain the final lightning special effect with brighter pixel values. Among them, the calculation formula for color dodge blending is as follows:

[0073]

[0074] In the formula, A represents the base color of the image where the complete lightning structure acts, B represents the blending color of the special effect layer, and C represents the final lightning special effect. In addition, when performing rendering, calculate the outer bounding box of the special effect layer by using all the connection point data involved in the generation of the complete lightning structure and the blur radius parameter. When rendering in the GPU, the pixel points outside the bounding box do not participate in the calculation, which is of great help for performance improvement.

[0075] In one embodiment, step S520 includes:

[0076] Perform successive downsampling processing on the complete lightning structure through a preset first convolution kernel to obtain a downsampling result;

[0077] Perform successive upsampling processing on the downsampling result through a preset second convolution kernel until the upsampling result has the same resolution as the complete lightning structure to obtain the blurred lightning structure.

[0078] In this embodiment, a blurring algorithm is used for blurring processing. As Figure 8 shown, the blurring algorithm sets two different convolution kernels. Use Figure 8 the left convolution kernel to perform successive downsampling processing on the complete lightning structure to obtain a downsampling result; then use Figure 7 the right convolution kernel to perform successive upsampling processing on the downsampling result (the number of iterations of downsampling processing and upsampling processing is the same) until the upsampling result has the same resolution as the complete lightning structure to obtain the blurred lightning structure. This blurring processing method can achieve the same effect as the traditional blurring algorithm even with fewer iterations, and due to successive downsampling, the final blurring quality is guaranteed.

[0079] This method abandons the complex algorithms for generating lightning structures in the traditional way. By using the idea of continuously subdividing straight lines and combining with a set of custom generation rules, multiple parameter adjustments can be finally achieved, and the lightning structure can be freely controlled. Users can directly apply the special effects to videos. By only modifying a small number of parameters, ideal effects can be achieved. Combining with a more efficient blur algorithm and an outer bounding box calculation strategy, the frame rate of the lightning special effects can be maintained above 25fps in videos such as 1080p and 2k, solving the technical problems of large time and space overheads in the traditional lightning structure algorithms and being unable to be applied to videos in real time, enabling non-professionals to easily apply lightning special effects in videos. This application can be combined with a variety of AI algorithms, greatly enhancing the application of such effects in video editing.

[0080] An embodiment of the present invention also provides a lightning special effect drawing device, which is used to execute any embodiment of the foregoing lightning special effect drawing method. Specifically, please refer to Figure 6 , Figure 6 which is a schematic block diagram of the lightning special effect drawing device provided by the embodiment of the present invention. The lightning special effect drawing device 100 can be configured in a server.

[0081] As Figure 6 shown, the lightning special effect drawing device 100 includes an acquisition module 110, an iterative processing module 120, a first connection module 130, a selection module 140, and a second connection module 150.

[0082] The acquisition module 110 is used to acquire the starting point and the ending point of the lightning trunk structure;

[0083] The iterative processing module 120 is used to perform iterative processing on the lightning trunk structure: based on the coordinates of the starting point, the coordinates of the ending point, and a preset offset parameter, perform iterative calculations on the lightning inflection points at multiple levels, and determine whether the offset parameter is less than a preset minimum threshold in the iterative calculation of each level of lightning inflection points. If not, continue the iterative calculation; if so, end the iterative calculation; wherein, the offset parameter decreases according to the iterative levels;

[0084] The first connection module 130 is used to, after the iterative processing ends, connect all the connection points corresponding to the lightning trunk structure in sequence to obtain the lightning trunk structure, and store the coordinates and corresponding index values of all the connection points into the connection point sequence corresponding to the lightning trunk structure. The connection points include: the starting point, the ending point, and each lightning inflection point, and the index value is the unique serial number corresponding to each connection point;

[0085] The selection module 140 is used to randomly select several connection points from the connection point sequence corresponding to the lightning trunk structure as the starting points of each lightning branch structure based on a complexity parameter, and determine the ending points corresponding to each lightning branch structure based on a preset branch direction and branch length;

[0086] The second connection module 150 is configured to continue the iterative processing of multiple lightning inflection points for each lightning branch structure. After the iterative processing is completed, all the connection points corresponding to each lightning branch structure are connected in sequence to obtain each lightning branch structure, forming the final complete lightning structure, and storing the coordinates and corresponding index values of all the connection points in each lightning branch structure into the connection point sequence corresponding to the lightning branch structure.

[0087] In one embodiment, the iterative processing module 120 includes:

[0088] The midpoint calculation unit is configured to calculate the midpoint based on the coordinates of the starting point and the ending point to obtain the coordinates of the first-level midpoint of the lightning trunk structure.

[0089] The inflection point calculation unit is configured to calculate the lightning inflection point based on the first-level midpoint coordinates, the offset parameter, and the preset random seed function to obtain the coordinates of the first-level lightning inflection point.

[0090] The update unit is configured to perform a decreasing process on the offset parameter to obtain the updated offset parameter, and determine whether the updated offset parameter is less than the preset minimum threshold. If so, end the iterative calculation; otherwise, calculate the midpoint based on the coordinates of the starting point and the coordinates of the first-level lightning inflection point to obtain one of the second-level midpoint coordinates, and calculate the midpoint based on the coordinates of the first-level lightning inflection point and the coordinates of the ending point to obtain the other second-level midpoint coordinates.

[0091] The inflection point calculation unit is configured to calculate the lightning inflection point based on the second-level midpoint coordinates, the offset parameter, and the preset random seed function to obtain the coordinates of the second-level lightning inflection point.

[0092] The judgment unit is configured to continue to perform a decreasing process on the offset parameter to obtain the updated one, and determine whether the updated offset parameter is less than the preset minimum threshold, and so on, until the updated offset parameter is less than the preset minimum threshold.

[0093] In one embodiment, the selection module 140 includes:

[0094] The random generation unit is configured to generate a corresponding number of random numbers within the range of the complexity parameter according to the complexity parameter and the preset random function.

[0095] The search unit is configured to search for the index value corresponding to the random number from the connection point sequence corresponding to the lightning trunk structure to obtain the target index value.

[0096] The determination unit is configured to use the connection point corresponding to the target index value as the starting point of the lightning branch.

[0097] In one embodiment, the second connection module 150 includes:

[0098] A connection unit for connecting all connection points corresponding to each lightning branch structure in sequence to obtain each lightning branch structure;

[0099] A first selection unit for continuing to randomly select several connection points from the connection point sequence corresponding to the lightning branch structure based on the complexity parameter as the starting points of the corresponding secondary lightning branch structures, and determining the end points of the corresponding secondary lightning branch structures based on the preset branch direction and branch length;

[0100] A first iteration unit for continuing to perform iterative processing of multi-level lightning inflection points on the secondary lightning branch structures to obtain the secondary lightning branch structures;

[0101] A second selection unit for continuing to randomly select several connection points from the connection point sequence corresponding to the secondary lightning branch structure based on the complexity parameter as the starting points of the corresponding more secondary lightning branch structures, and determining the end points of the corresponding more secondary lightning branch structures based on the preset branch direction and branch length;

[0102] A second iteration unit for continuing to perform iterative processing of multi-level lightning inflection points on the more secondary lightning branch structures until the requirements of the complexity parameter are met.

[0103] An embodiment of the present invention further provides a computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. Wherein, when the processor executes the computer program, the lightning special effect drawing method described above is implemented.

[0104] In another embodiment of the present invention, a computer-readable storage medium is provided. The computer-readable storage medium can be a non-volatile computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor executes the lightning special effect drawing method described above.

[0105] Those skilled in the art can clearly understand that for the convenience and conciseness of description, the specific working processes of the devices, apparatuses, and units described above can refer to the corresponding processes in the foregoing method embodiments, and will not be elaborated herein. Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present invention.

[0106] In several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods, or units with the same function can be aggregated into one unit. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed couplings or direct couplings or communication connections to each other can be indirect couplings or communication connections through some interfaces, devices, or units, and can also be electrical, mechanical, or other forms of connection.

[0107] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they can be located in one place, or can be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiments of the present invention.

[0108] In addition, the functional units in each embodiment of the present invention can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above integrated units can be implemented in the form of hardware or in the form of software functional units.

[0109] When the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part 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 for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROMs), magnetic disks, or optical discs that can store program codes.

[0110] As described above, the above are only the specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present invention can easily think of various equivalent modifications or substitutions, and these modifications or substitutions should all be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention should be subject to the protection scope of the claims.

Claims

1. A method for drawing lightning special effects, characterized in that, Including: Obtain the starting point and ending point of the lightning trunk structure; Iterative processing of the lightning trunk structure: Based on the coordinates of the starting point, the coordinates of the ending point, and a preset offset parameter, perform iterative calculations for multi-level lightning inflection points, and determine whether the offset parameter in the iterative calculation of each level of lightning inflection points is less than a preset minimum threshold. If not, continue the iterative calculation; if so, end the iterative calculation; wherein, the offset parameter decreases according to the iterative level; After the iterative processing ends, connect all the connection points corresponding to the lightning trunk structure in sequence to obtain the lightning trunk structure, and store the coordinates of all the connection points and the corresponding index values into the connection point sequence corresponding to the lightning trunk structure. The connection points include: the starting point, the ending point, and each lightning inflection point, and the index value is the unique serial number corresponding to each connection point; Randomly select several connection points from the connection point sequence corresponding to the lightning trunk structure as the starting points corresponding to each lightning branch structure based on a complexity parameter, and determine the ending points corresponding to each lightning branch structure based on a preset branch direction and branch length; Continue to perform iterative processing of multi-level lightning inflection points for each lightning branch structure. After the iterative processing ends, connect all the connection points corresponding to each lightning branch structure in sequence to obtain each lightning branch structure, form a final complete lightning structure, and store the coordinates of all the connection points and the corresponding index values in each lightning branch structure into the connection point sequence corresponding to the lightning branch structure.

2. The lightning special effect drawing method according to claim 1, wherein The iterative processing of the lightning trunk structure includes: Perform a midpoint calculation based on the coordinates of the starting point and the coordinates of the ending point to obtain the first-level midpoint coordinates of the lightning trunk structure; Perform an inflection point calculation on the lightning inflection point based on the first-level midpoint coordinates, the offset parameter, and a preset random seed function to obtain the coordinates of the first-level lightning inflection point; Perform a decreasing process on the offset parameter to obtain an updated offset parameter, and determine whether the updated offset parameter is less than a preset minimum threshold. If so, end the iterative calculation; if not, perform a midpoint calculation based on the coordinates of the starting point and the coordinates of the first-level lightning inflection point to obtain one of the second-level midpoint coordinates, and perform a midpoint calculation based on the coordinates of the first-level lightning inflection point and the coordinates of the ending point to obtain the other second-level midpoint coordinates; Perform an inflection point calculation on the lightning inflection point based on the second-level midpoint coordinates, the offset parameter, and a preset random seed function to obtain the coordinates of the second-level lightning inflection point; Continue to perform a decreasing process on the offset parameter to obtain an updated offset parameter, and determine whether the updated offset parameter is less than a preset minimum threshold, and so on, until the updated offset parameter is less than a preset minimum threshold.

3. The lightning special effect drawing method according to claim 2, wherein The performing an inflection point calculation on the lightning inflection point based on the first-level midpoint coordinates, the offset parameter, and a preset random seed function to obtain the coordinates of the first-level lightning inflection point includes: Perform an inflection point calculation according to the following calculation formula: mid_x = (x2 + x1) / 2 + ((rand() % 100) / 50.0 - 1.0) * displace; mid_y = (y2 + y1) / 2 + ((rand() % 100) / 50.0 - 1.0) * displace; Among them, (mid_x, mid_y) represents the coordinates of the inflection point of the primary lightning, (x1, y1) represents the starting point coordinates, (x2, y2) represents the ending point coordinates, rand() represents the random seed function, and displace represents the offset parameter.

4. The lightning special effect drawing method according to claim 1, characterized in that Randomly selecting several connection points from the connection point sequence corresponding to the lightning trunk structure as the starting points corresponding to each lightning branch structure based on the complexity parameter, includes: Generating a corresponding number of random numbers within the range of the complexity parameter according to the complexity parameter and a preset random function; Searching for the index value corresponding to the random number from the connection point sequence corresponding to the lightning trunk structure to obtain the target index value; Taking the connection point corresponding to the target index value as the starting point of the lightning branch.

5. The lightning special effect drawing method according to claim 1, characterized in that Continuing to perform iterative processing of multi-level lightning inflection points on each lightning branch structure, after the iterative processing ends, connecting all the connection points corresponding to each lightning branch structure in sequence to obtain each lightning branch structure, forming the final complete lightning structure, includes: Connecting all the connection points corresponding to each lightning branch structure in sequence to obtain each lightning branch structure; Continuing to randomly select several connection points from the connection point sequence corresponding to the lightning branch structure as the starting points corresponding to the secondary lightning branch structures based on the complexity parameter, and determining the ending points corresponding to the secondary lightning branch structures based on the preset branch direction and branch length; Continuing to perform iterative processing of multi-level lightning inflection points on the secondary lightning branch structures to obtain the secondary lightning branch structures; Continuing to randomly select several connection points from the connection point sequence corresponding to the secondary lightning branch structures as the starting points corresponding to the more secondary lightning branch structures based on the complexity parameter, and determining the ending points corresponding to the more secondary lightning branch structures based on the preset branch direction and branch length; Continuing to perform iterative processing of multi-level lightning inflection points on the more secondary lightning branch structures until the complexity parameter requirements are met.

6. The lightning special effect drawing method according to claim 1, wherein Also includes: Performing blurring processing on the complete lightning structure to obtain a blurred lightning structure; Performing hybrid processing on the complete lightning structure and the blurred lightning structure to obtain the special effect layer of the lightning; Performing color filter fusion on the image base color affected by the complete lightning structure and the special effect layer to obtain the final lightning special effect.

7. The lightning special effect drawing method according to claim 6, characterized in that Performing blurring processing on the complete lightning structure to obtain a blurred lightning structure, includes: Performing step-by-step downsampling processing on the complete lightning structure through a preset first convolution kernel to obtain a downsampling result; Performing step-by-step upsampling processing on the downsampling result through a preset second convolution kernel until the resolution of the upsampling result is the same as that of the complete lightning structure to obtain the blurred lightning structure.

8. A lightning special effect drawing device, characterized in that, Includes: An acquisition module, used to acquire the starting point and ending point of the lightning trunk structure; Iterative processing module, for performing iterative processing on the lightning backbone structure: based on the coordinates of the starting point, the coordinates of the ending point and the preset offset parameter, perform iterative calculation of multi-level lightning inflection points, and judge whether the offset parameter is less than the preset minimum threshold in the iterative calculation of each level of lightning inflection points. If not, continue the iterative calculation; if so, end the iterative calculation; wherein, the offset parameter decreases according to the iterative level; First connection module, after the iterative processing ends, connect all the connection points corresponding to the lightning backbone structure in sequence to obtain the lightning backbone structure, and store the coordinates and corresponding index values of all the connection points into the connection point sequence corresponding to the lightning backbone structure. The connection points include: the starting point, the ending point and each lightning inflection point, and the index value is the unique serial number corresponding to each connection point; Selection module, for randomly selecting several connection points from the connection point sequence corresponding to the lightning backbone structure as the starting points of each lightning branch structure based on the complexity parameter, and determining the ending points corresponding to each lightning branch structure based on the preset branch direction and branch length; Second connection module, for continuing to perform iterative processing of multi-level lightning inflection points on each lightning branch structure. After the iterative processing ends, connect all the connection points corresponding to each lightning branch structure in sequence to obtain each lightning branch structure, form the final complete lightning structure, and store the coordinates and corresponding index values of all the connection points in each lightning branch structure into the connection point sequence corresponding to the lightning branch structure; 9. A computer device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the lightning special effect drawing method according to any one of claims 1 to 7.

10. 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 the processor, the processor is caused to execute the lightning special effect drawing method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Lightning particle rendering method and device

    CN110706149A

  • Game special effect drawing method and device

    CN111127599A