Lightning generation method, device, electronic device and computer-readable storage medium

By randomly generating the starting and ending points of lightning in an open world 3D game, and generating multiple offset points on its plane, combined with grid processing and rendering processing, the problem of single and repetitive lightning effects in the existing technology is solved. problem, achieving a more realistic and vivid lightning performance, improving user experience and reducing computational complexity.

CN112669423BActive Publication Date: 2024-10-11BEIJING PIXEL SOFTWARE TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202011524840.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-22
Publication Date
2024-10-11
Estimated Expiration
2040-12-22

AI Technical Summary

Technical Problem

When the existing technology expresses the lightning effect in an open world 3D game, a single texture or sequential frame playback method causes the effect to be too single and repetitive, lacking a sense of reality, and affecting the user experience.

Method used

Randomly generate lightning trigger signals in response to preset triggers, obtain the position and orientation of the virtual camera, determine the starting point and end point of lightning, and generate multiple offset points on its plane to generate target lightning, using a grid Optimize and render to eliminate gaps and achieve a more random and vivid lightning effect.

Benefits of technology

The generated lightning is more random and flexible, avoids duplication, improves user experience, reduces computational complexity in two-dimensional space, avoids device freezes, and presents lightning scenes that are more realistic and credible.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112669423B_ABST
    Figure CN112669423B_ABST
Patent Text Reader

Abstract

The embodiments of the present application propose a lightning generation method, device, electronic device and computer-readable storage medium, which relate to the field of image processing. The method obtains the position and orientation of the current virtual camera by randomly generating a lightning trigger signal in response to a preset trigger. The lightning trigger signal includes a distance parameter, a height parameter and an offset parameter. The starting point and the end point of the target lightning are determined according to the position of the virtual camera, the orientation of the virtual camera, the distance parameter and the height parameter. According to the starting point, the end point and the offset parameter, multiple offset points are determined on the plane where the starting point and the end point are located, and the target lightning is generated according to the starting point, the end point and the multiple offset points. Since the lightning trigger signal is randomly triggered, the generated target lightning is more random and flexible, and even if there are multiple lightning strikes, there will be no repeated phenomenon, thereby making the presented lightning scene more realistic and credible, and improving the user experience.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image processing, and in particular, to a lightning generation method, device, electronic device and computer-readable storage medium. Background Art

[0002] With the continuous development of hardware and the rising taste of gamers, the weather system has become a standard feature in open world 3D games. In the weather system, rainy days are a highlight. How to show the lightning on rainy days is crucial to the vividness of the weather system and the visual shock of players.

[0003] In the prior art, lightning is generally presented by means of a texture or sequence frame playback. Among them, the texture method is to draw a lightning texture in advance, and display it through a rectangular grid when lightning is needed. This single texture lightning has a poor performance effect. The sequence frame playback method can more vividly show the dynamic effect of lightning, but it is often played in a fixed process. Even if more time and effort are spent on making several sets of sequence frames, after a few lightning strikes, repetition will begin to occur, giving players an impression that it is not real enough. Summary of the invention

[0004] Based on this, it is necessary to provide a lightning generation method, device, electronic device and computer-readable storage medium to address the above technical problems, so as to make the generated lightning more realistic and improve the user experience.

[0005] In order to achieve the above purpose, the technical solution adopted in the embodiment of the present application is as follows:

[0006] In a first aspect, the present application provides a lightning generation method, the method comprising:

[0007] In response to a lightning trigger signal randomly generated by a preset trigger, the position and orientation of the current virtual camera are obtained; the lightning trigger signal includes a distance parameter, a height parameter and an offset parameter;

[0008] Determine the starting point and the ending point of the target lightning according to the position of the virtual camera, the orientation of the virtual camera, the distance parameter and the height parameter;

[0009] Determine a plurality of offset points on a plane where the starting point and the ending point are located according to the starting point, the ending point and the offset parameter;

[0010] A target lightning is generated according to the starting point, the ending point and the plurality of offset points.

[0011] In an optional implementation, the step of determining the starting point and the ending point of the target lightning according to the position of the virtual camera, the orientation of the virtual camera, the distance parameter and the height parameter comprises:

[0012] Calculate a target position in the orientation of the virtual camera that is the distance parameter away from the position of the virtual camera;

[0013] The target position is offset in a direction perpendicular to the direction of the virtual camera according to the height parameter to obtain a starting point and an ending point of the target lightning; wherein the distance between the starting point and the ending point is the height parameter, and the target position is located on a line segment formed by the starting point and the ending point.

[0014] In an optional implementation, the step of determining a plurality of offset points on the plane where the starting point and the ending point are located according to the starting point, the ending point and the offset parameter comprises:

[0015] Determine a first vector formed by the starting point and the ending point, and calculate a second vector perpendicular to the first vector;

[0016] Offsetting the midpoint of the line segment formed by the starting point and the ending point according to the offset parameter and the direction of the second vector to obtain at least one offset point;

[0017] In the vertex set formed by the starting point, the offset point and the end point, every two adjacent vertices are used as a new starting point and a new end point, respectively, and the steps of determining the first vector formed by the starting point and the end point and calculating the second vector perpendicular to the first vector are returned until the number of iterations reaches a preset value, thereby determining multiple offset points.

[0018] In an optional implementation, the offset parameter includes a first offset parameter, and the step of offsetting the midpoint of the line segment formed by the starting point and the ending point according to the offset parameter and the direction of the second vector to obtain at least one offset point includes:

[0019] The midpoint is offset along the direction of the second vector according to the first offset parameter to obtain a first offset point.

[0020] In an optional implementation, the offset parameters include a first offset parameter and a second offset parameter, and the step of offsetting the midpoint of the line segment formed by the starting point and the ending point according to the offset parameters and the direction of the second vector to obtain at least one offset point includes:

[0021] offsetting the midpoint along the direction of the second vector according to the first offset parameter to obtain a first offset point;

[0022] The first offset point is offset according to a vector formed by the starting point and the first offset point and the second offset parameter to obtain a second offset point.

[0023] In an optional implementation, the step of generating target lightning according to the starting point, the ending point and the plurality of offset points comprises:

[0024] Performing gridding processing according to the starting point, the ending point and the plurality of offset points to generate a lightning grid;

[0025] The lightning grid is rendered to obtain target lightning.

[0026] In an optional implementation, the lightning grid includes multiple rectangular grids, and the step of rendering the lightning grid to obtain the target lightning includes:

[0027] Transparency processing is performed on the multiple rectangular grids to eliminate the gap between two adjacent rectangular grids.

[0028] In a second aspect, the present application provides a lightning generating device, the device comprising:

[0029] A response module, used to respond to a lightning trigger signal randomly generated by a preset trigger, and obtain the position and orientation of the current virtual camera; the lightning trigger signal includes a distance parameter, a height parameter, and an offset parameter;

[0030] A determination module, used to determine the starting point and the ending point of the target lightning according to the position of the virtual camera, the orientation of the virtual camera, the distance parameter and the height parameter;

[0031] An offset processing module, used for determining a plurality of offset points on the plane where the starting point and the ending point are located according to the starting point, the ending point and the offset parameter;

[0032] The lightning generation module is used to generate target lightning according to the starting point, the ending point and the multiple offset points.

[0033] In a third aspect, the present application provides an electronic device, including a processor and a memory, wherein the memory stores a computer program, and when the processor executes the computer program, the method described in any one of the aforementioned implementations is implemented.

[0034] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method described in any one of the aforementioned implementations.

[0035] The lightning generation method, device, electronic device and computer-readable storage medium provided in the embodiments of the present application obtain the position and orientation of the current virtual camera by randomly generating a lightning trigger signal in response to a preset trigger, wherein the lightning trigger signal includes a distance parameter, a height parameter and an offset parameter, and the starting point and the ending point of the target lightning are determined according to the position of the virtual camera, the orientation of the virtual camera, the distance parameter and the height parameter, and multiple offset points are determined on the plane where the starting point and the ending point are located according to the starting point, the ending point and the offset parameter, and the target lightning is generated according to the starting point, the ending point and the multiple offset points. Since the lightning trigger signal is randomly triggered and generated, the generated target lightning is more random and flexible, and even if there are multiple lightning strikes, there will be no repeated phenomenon, thereby making the presented lightning scene more realistic and credible, and improving the user experience. In addition, the embodiments of the present application generate lightning in a two-dimensional space, which can effectively reduce the computational complexity of the electronic device and avoid causing the device to freeze when presenting lightning.

[0036] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0038] Figure 1 A block diagram of an electronic device provided by an embodiment of the present application is shown;

[0039] Figure 2 A schematic diagram of a flow chart of a lightning generation method provided in an embodiment of the present application is shown;

[0040] Figure 3 Another schematic diagram of a flow chart of a lightning generation method provided in an embodiment of the present application is shown;

[0041] Figure 4 A schematic diagram of determining the starting point and ending point of a target lightning is shown;

[0042] Figure 5 Another schematic diagram of a flow chart of a lightning generation method provided in an embodiment of the present application is shown;

[0043] Figure 6 A schematic diagram of determining a second vector is shown;

[0044] Figure 7 Schematic diagrams of Z-type fragments and H-type fragments are shown;

[0045] Figure 8 A schematic diagram of determining a first offset point is shown;

[0046] Fig. 9 A schematic diagram of determining a second offset point is shown;

[0047] Fig.10 A schematic diagram showing a lightning structure obtained by multiple iterative calculations by an electronic device;

[0048] Fig.11 Another schematic diagram of a flow chart of a lightning generation method provided in an embodiment of the present application is shown;

[0049] Fig.12 A comparison diagram of the lightning grid before and after rendering is shown;

[0050] Fig.13 A functional module diagram of a lightning generating device provided in an embodiment of the present application is shown.

[0051] Icons: 100 - electronic device; 600 - lightning generating device; 110 - memory; 120 - processor; 130 - communication module; 610 - response module; 620 - determination module; 630 - offset processing module; 640 - lightning generating module. DETAILED DESCRIPTION

[0052] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various different configurations.

[0053] Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application for which protection is sought, but merely represents selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.

[0054] It should be noted that relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprises" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0055] Please refer to Figure 1 , is a block diagram of an electronic device 100 provided in an embodiment of the present application. The electronic device 100 may be, but is not limited to, a mobile device such as a smart phone or a tablet computer. The electronic device 100 includes a memory 110, a processor 120, and a communication module 130. The memory 110, the processor 120, and the communication module 130 are electrically connected to each other directly or indirectly to achieve data transmission or interaction. For example, these components may be electrically connected to each other via one or more communication buses or signal lines.

[0056] The memory 110 is used to store programs or data. The memory 110 may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc.

[0057] The processor 120 is used to read / write data or programs stored in the memory 110 and execute corresponding functions. For example, when the processor 120 executes the computer program stored in the memory 110, the lightning generation method disclosed in the embodiment of the present application can be implemented.

[0058] The communication module 130 is used to establish a communication connection between the electronic device 100 and other communication terminals through a network, and to send and receive data through the network.

[0059] It should be understood that Figure 1The structure shown is only a schematic diagram of the structure of the electronic device 100. The electronic device 100 may also include Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown. Figure 1 Each component shown in the figure can be implemented by hardware, software or a combination thereof.

[0060] The embodiment of the present application further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by the processor 120, the lightning generation method disclosed in the embodiment of the present application can be implemented.

[0061] Please refer to Figure 2 , is a flow chart of a lightning generation method provided in an embodiment of the present application. It should be noted that the lightning generation method provided in an embodiment of the present application is not based on Figure 2 The specific order below is not limited. It should be understood that in other embodiments, the order of some steps in the lightning generation method provided in the embodiment of the present application can be interchanged according to actual needs, or some steps can be omitted or deleted. The lightning generation method can be applied in Figure 1 The electronic device 100 shown is particularly suitable for making complex weather systems, games with certain performance requirements, and simulation systems. Figure 2 The specific process shown is described in detail.

[0062] Step S201, responding to a lightning trigger signal randomly generated by a preset trigger, obtaining the position and orientation of the current virtual camera; the lightning trigger signal includes a distance parameter, a height parameter and an offset parameter.

[0063] In this embodiment, for weather conditions that require lightning, a trigger can be pre-set to control the generation of lightning. The trigger can be randomly triggered within a certain time interval, or triggered after a set condition is met. The trigger pre-sets information such as the distance range, height range, and offset range for generating lightning. When the trigger triggers lightning, it randomly generates distance parameters, height parameters, and offset parameters within the corresponding range, and carries the randomly generated distance parameters, height parameters, and offset parameters in the lightning trigger signal.

[0064] The electronic device 100 responds to the lightning trigger signal to obtain the position and orientation of the current virtual camera, wherein the virtual camera can be understood as an eye in the virtual world space, and the things seen by the virtual camera will eventually be displayed on the screen of the electronic device 100.

[0065] Step S202, determining the starting point and the ending point of the target lightning according to the position of the virtual camera, the orientation of the virtual camera, the distance parameter and the height parameter.

[0066] In this embodiment, the distance parameter can be understood as the distance between the target lightning (i.e., the lightning to be randomly generated) and the virtual camera, and the height parameter can be understood as the height of the target lightning (i.e., the distance between the starting point and the ending point of the target lightning). Therefore, the starting point and the ending point of the target lightning can be determined based on the acquired position, orientation, distance parameter, and height parameter of the virtual camera.

[0067] Step S203, determining a plurality of offset points on the plane where the starting point and the ending point are located according to the starting point, the ending point and the offset parameter.

[0068] In this embodiment, the offset parameters may include parameters such as an offset angle and an offset distance. The electronic device 100 performs an offset calculation on the plane where the starting point and the ending point are located based on the determined starting point, ending point and offset parameters, and can obtain multiple offset points. The multiple offset points are used to generate lightning branches, including the trunk and branches of lightning.

[0069] Step S204, generating a target lightning according to the starting point, the ending point and the plurality of offset points.

[0070] In this embodiment, after determining the starting point, the ending point and the multiple offset points, the starting point, the ending point and the multiple offset points can be connected in a certain order to obtain a corresponding lightning structure, and then the lightning structure can be processed to generate the target lightning, which is finally presented on the electronic device 100.

[0071] The lightning generation method provided in the embodiment of the present application obtains the position and orientation of the current virtual camera by randomly generating a lightning trigger signal in response to a preset trigger, wherein the lightning trigger signal includes a distance parameter, a height parameter, and an offset parameter, and determines the starting point and the ending point of the target lightning according to the position of the virtual camera, the orientation of the virtual camera, the distance parameter, and the height parameter, and determines a plurality of offset points on the plane where the starting point and the ending point are located according to the starting point, the ending point, and the offset parameter, and generates the target lightning according to the starting point, the ending point, and the plurality of offset points. Since the lightning trigger signal is randomly triggered and generated, the generated target lightning is more random and flexible, and even if there are multiple lightning strikes, there will be no repetitive phenomena, thereby making the presented lightning scene more realistic and credible, and improving the user experience. In addition, the embodiment of the present application generates lightning in a two-dimensional space, which can effectively reduce the computational complexity of the electronic device 100 and avoid causing the device to freeze when presenting lightning.

[0072] In one embodiment, please refer to Figure 3 , the electronic device 100 can determine the starting point and the ending point of the target lightning in the following manner, that is, the above-mentioned step S202 specifically includes:

[0073] Sub-step S2021, calculates the target position with a distance parameter from the position of the virtual camera in the direction of the virtual camera.

[0074] In this embodiment, after the electronic device 100 obtains the position of the current virtual camera, it calculates the target position according to the direction of the virtual camera and the distance parameter corresponding to the target lightning.

[0075] Sub-step S2022, according to the height parameter, the target position is offset in the direction perpendicular to the direction of the virtual camera to obtain the starting point and the ending point of the target lightning; wherein, the distance between the starting point and the ending point is the height parameter, and the target position is located on the line segment formed by the starting point and the ending point.

[0076] In this embodiment, the electronic device 100 can use the target position as a reference point, and then shift the target position upward and downward in the virtual world space to obtain the starting point and the ending point of the target lightning respectively. In one implementation, the target position can be the midpoint of the line segment formed by the starting point and the ending point; of course, the target position can also be any point on the line segment formed by the starting point and the ending point, and this application does not limit this.

[0077] Below, Figure 4 As an example, the process of determining the starting point and the end point is described in detail. Assuming that the current position of the virtual camera is point C, the coordinates of point D can be calculated according to the orientation of the virtual camera and the obtained distance parameter to obtain the target position. Taking the coordinates of point D as the center point, point D is offset upward and downward according to the height parameter, and the starting point (i.e., point A) and the end point (i.e., point B) of the target lightning can be obtained. It can be understood that the distance of line segment CD is the distance parameter, the distance of line segment AB is the height parameter, and point D is the midpoint of line segment AB.

[0078] In one embodiment, please refer to Figure 5 , the electronic device 100 may determine a plurality of offset points in the following manner, that is, the above-mentioned step S203 specifically includes:

[0079] Sub-step S2031, determining a first vector formed by the starting point and the ending point, and calculating a second vector perpendicular to the first vector.

[0080] In this embodiment, after obtaining the starting point A and the ending point B of the target lightning, the first vector formed by the starting point and the ending point can be determined. Since the generation of lightning needs to be offset in the horizontal direction, it is necessary to obtain the vertical The second vector of . Figure 6 As shown, assuming that the first vector The first vector After rotating 90° (clockwise or counterclockwise), you can get The second vector is R = (-y, x) or -R = (y, -x). It can be understood that the first vector The direction of is the direction of the main trunk of the lightning, and the direction of the second vector R or -R is the horizontal growth direction of the lightning.

[0081] Sub-step S2032, offsetting the midpoint of the line segment formed by the starting point and the ending point according to the offset parameter and the direction of the second vector to obtain at least one offset point.

[0082] In this embodiment, since the second vector includes two directions, namely, the left and right directions, during the offset calculation process, the midpoint of the line segment formed by the starting point and the ending point can be offset to the left (i.e., in the direction of -R) or to the right (i.e., in the direction of R). The specific offset to the left or to the right is determined randomly. In each offset, one or two offset points can be determined.

[0083] Sub-step S2033, in the vertex set consisting of the starting point, the offset point and the end point, take every two adjacent vertices as the new starting point and the new end point respectively, return to the step of determining the first vector formed by the starting point and the end point, and calculate the second vector perpendicular to the first vector, until the number of iterations reaches a preset value, thereby determining multiple offset points.

[0084] In this embodiment, the process of determining the multiple offset points is an iterative calculation process: that is, in the vertex set consisting of the starting point, the offset point, and the end point, each two adjacent vertices are respectively used as the new starting point and the new end point, and then the first vector formed by the new starting point and the new end point is determined, and the second vector perpendicular to the first vector is calculated, and then according to the offset parameter and the direction of the second vector, the midpoint of the line segment formed by the new starting point and the new end point is offset to obtain at least one offset point; sub-steps S2031 to S2033 are repeatedly executed, and multiple iterative calculations are performed until the number of iterations reaches a preset value, thereby determining multiple offset points. In this way, after multiple iterations, the target lightning generated in the end can be made more stretched, complex, and vivid, and the lightning scene seen by the user is also more realistic.

[0085] In this embodiment, the determination of the offset point can be implemented based on an algorithm of fractal geometry, so that two forms of lightning branches can be generated according to the starting point, the end point and multiple offset points, such as Figure 7The Z-type segment and H-type segment shown in the figure. The Z-type segment consists of a starting point, an end point and an offset point, and is mainly used to generate the main part of the lightning; the H-type segment consists of a starting point, an end point and two offset points, and is mainly used to generate the branch part of the lightning. The H-type segment has one more vertex than the Z-type segment, so it can be understood that the H-type segment is based on the Z-type segment with one more offset point.

[0086] In this embodiment, when the electronic device 100 offsets the midpoint of the line segment formed by the starting point and the ending point according to the offset parameter and the direction of the second vector, whether to generate an offset point in a Z-shaped segment or an offset point in an H-shaped segment can be randomly determined, but it is necessary to ensure that the ratio of the Z-shaped segment and the H-shaped segment in the final lightning structure meets the preset conditions, so that the shape of the target lightning finally obtained is closer to the shape of real lightning in nature. The determination of the offset points in the Z-shaped segment and the H-shaped segment is described below.

[0087] In one implementation, the offset parameter may include a first offset parameter, and the above sub-step S2032 may specifically include: offsetting the midpoint along the direction of the second vector according to the first offset parameter to obtain a first offset point.

[0088] The first offset parameter may include an offset distance, such as Figure 8 As shown, after the electronic device 100 determines the first vector formed by the starting point A and the ending point B of the target lightning and calculates the second vector perpendicular to the first vector, the midpoint D of the line segment formed by the starting point A and the ending point B of the target lightning is offset by the first offset parameter (i.e., the length of the line segment DE) along the direction of the second vector (assuming rightward), and the first offset point E can be obtained. After the first offset point E is connected to the starting point A and the ending point B respectively, the above-mentioned Z-shaped segment can be obtained.

[0089] In another embodiment, the offset parameter includes a first offset parameter and a second offset parameter. The above-mentioned sub-step S2032 may specifically include: offsetting the midpoint along the direction of the second vector according to the first offset parameter to obtain a first offset point, and offsetting the first offset point according to the vector formed by the starting point and the first offset point and the second offset parameter to obtain a second offset point.

[0090] In this embodiment, the first offset parameter may include an offset distance, and the second offset parameter may include an offset angle. Assume that the electronic device 100 performs a first iteration calculation to obtain Figure 8 The first offset point E shown in FIG. 1 needs to perform a second iteration calculation based on the vertex set consisting of the starting point A, the ending point B and the first offset point E of the target lightning, such as Fig. 9As shown, the specific process includes the following: first, two adjacent vertices A and E are respectively used as the new starting point and the new ending point, the first vector formed by the starting point A and the ending point E is determined, and after the second vector perpendicular to the first vector is calculated, the midpoint F of the line segment formed by the starting point A and the ending point E of the target lightning is offset along the direction of the second vector (assuming to the right) by the first offset parameter (i.e., the length of the line segment FG), so that the first offset point G can be obtained, and then the vector formed by the starting point A and the first offset point G is calculated. The length and direction of the vector The length and direction of the first offset point G and the second offset parameter can be used to offset the first offset point G, and the position of the second offset point H can be obtained. In an example, The length of the vector length, the vector The direction obtained by rotating the second offset parameter clockwise or counterclockwise is taken as the vector In practical applications, since the branches of real lightning in nature are generally shorter than the main trunk, in order to make the generated lightning more realistic, the vector The length of The length is reduced, for example

[0091] After determining the first offset point G and the second offset point H, the two adjacent vertices E and B are used as the new starting point and the new ending point respectively, and one or two offset points are determined according to any of the above-mentioned implementation methods for determining the offset points (the generation method of the Z-shaped segment or the H-shaped segment), thereby completing the second iterative calculation; then the third iterative calculation is entered until the number of iterations reaches a preset value (for example, 7 times, 8 times or 9 times). Fig.10 As shown, the lightning structures are obtained after the electronic device 100 performs 3 to 7 iterative calculations. The shape of the lightning becomes more stretched, complex and vivid as the number of iterations increases.

[0092] It should be noted that, in the actual iterative calculation process, the first offset parameter and the second offset parameter can be attenuated to different degrees as the number of iterations increases, that is, the first offset parameter and the second offset parameter involved in the calculation in each iterative calculation process can be the initial first offset parameter and the second offset parameter (that is, the offset parameter randomly generated by the trigger) multiplied by the corresponding attenuation coefficient, and the attenuation coefficient changes with the number of iterations, so that the generated target lightning is more realistic.

[0093] In one embodiment, please refer to Fig.11 , the electronic device 100 may generate target lightning in the following manner, that is, the above step S204 may include:

[0094] Sub-step S2041, performing gridding processing according to the starting point, the ending point and the plurality of offset points to generate a lightning grid.

[0095] In this embodiment, the electronic device 100 needs to render based on Mesh, so before rendering lightning, a corresponding mesh needs to be generated. A mesh is a structure used by graphics hardware to draw complex objects, and it contains at least a set of vertices and triangles connecting these vertices (the most basic 2D shape). After the electronic device 100 connects the starting point, the end point, and multiple offset points in a certain order, it can obtain the lightning structure corresponding to the target lightning, and then translate each line segment in the lightning structure to generate a rectangle between each two adjacent points, and determine multiple vertices in each rectangle, connect these vertices with triangles, and generate a lightning mesh corresponding to the target lightning, and finally the entire lightning mesh is filled with triangles.

[0096] Sub-step S2042, rendering the lightning grid to obtain target lightning.

[0097] In this embodiment, the lightning grid corresponding to the target lightning includes multiple rectangular grids. Considering that there may be a certain gap between each two adjacent rectangular grids, resulting in discontinuity between the rectangular grids, the target lightning presentation effect is ultimately poor. Based on this, the electronic device 100 performs rendering processing on the lightning grid, which can effectively eliminate the gaps between the lightning grids, making the presented lightning scene more realistic and credible. Specifically, the electronic device 100 can perform transparency processing on the multiple rectangular grids to eliminate the gaps between two adjacent rectangular grids. Fig.12 The following are schematic diagrams showing the comparison of lightning grid before and after rendering.

[0098] In practical applications, when the electronic device 100 displays the target lightning, the lightning grid can always be oriented toward the virtual camera, so as to achieve an effect similar to the lightning produced by the three-dimensional grid. It should be noted that the lightning generation scheme in the two-dimensional space provided by the embodiment of the present application, after actual measurement, the number of mesh faces generated when iterating and calculating 7 times (i.e., the number of triangles mentioned above) is about 1800, which is much lower than that of the complex three-dimensional grid rendering scheme, so it can effectively reduce the computational complexity of the electronic device 100, so that it can run smoothly at the electronic device 100 end, avoiding the device from freezing when presenting lightning; and when presenting lightning, it can achieve an effect almost consistent with the three-dimensional grid rendering.

[0099] In order to execute the corresponding steps in the above embodiments and various possible methods, a method for implementing a lightning generation device is provided below. Fig.13 , Fig.13This is a functional module diagram of the lightning generation device 600 provided in the embodiment of the present application. It should be noted that the basic principle and technical effects of the lightning generation device 600 provided in this embodiment are the same as those of the above embodiments. For the sake of brief description, for the parts not mentioned in this embodiment, reference can be made to the corresponding contents in the above embodiments. The lightning generation device 600 can be applied in Figure 1 The electronic device 100 shown includes a response module 610 , a determination module 620 , an offset processing module 630 and a lightning generation module 640 .

[0100] Optionally, the above modules can be stored in the form of software or firmware. Figure 1 The memory 110 shown in the figure may be fixed in the operating system (OS) of the electronic device 100 and may be Figure 1 Meanwhile, the data and program codes required for executing the above modules may be stored in the memory 110.

[0101] The response module 610 is used to respond to a lightning trigger signal randomly generated by a preset trigger to obtain the position and orientation of the current virtual camera; the lightning trigger signal includes a distance parameter, a height parameter and an offset parameter.

[0102] It can be understood that the response module 610 can execute the above step S201.

[0103] The determination module 620 is used to determine the starting point and the ending point of the target lightning according to the position of the virtual camera, the orientation of the virtual camera, the distance parameter and the height parameter.

[0104] It can be understood that the determination module 620 can execute the above step S202.

[0105] The offset processing module 630 is used to determine a plurality of offset points on the plane where the starting point and the ending point are located according to the starting point, the ending point and the offset parameter.

[0106] It can be understood that the offset processing module 630 can execute the above step S203.

[0107] The lightning generation module 640 is used to generate target lightning according to a start point, an end point and a plurality of offset points.

[0108] It can be understood that the lightning generation module 640 can execute the above step S204.

[0109] Optionally, the determination module 620 can be specifically used to calculate a target position with a distance parameter from the position of the virtual camera in the direction of the virtual camera; offset the target position in a direction perpendicular to the direction of the virtual camera according to a height parameter to obtain the starting point and ending point of the target lightning; wherein the distance between the starting point and the ending point is the height parameter, and the target position is located on the line segment formed by the starting point and the ending point.

[0110] It can be understood that the determination module 620 can execute the above sub-steps S2021 to S2022.

[0111] Optionally, the offset processing module 630 can be specifically used to determine a first vector formed by the starting point and the end point, and calculate a second vector perpendicular to the first vector; according to the offset parameter and the direction of the second vector, the midpoint of the line segment formed by the starting point and the end point is offset to obtain at least one offset point; in the vertex set formed by the starting point, the offset point and the end point, each two adjacent vertices are used as the new starting point and the new end point, respectively, and the step of determining the first vector formed by the starting point and the end point and calculating the second vector perpendicular to the first vector is returned until the number of iterations reaches a preset value, thereby determining multiple offset points.

[0112] In one implementation, the offset parameter includes a first offset parameter, and the offset processing module 630 is specifically configured to offset the midpoint along the direction of the second vector according to the first offset parameter to obtain a first offset point.

[0113] In another embodiment, the offset parameter includes a first offset parameter and a second offset parameter, and the offset processing module 630 is specifically used to offset the midpoint along the direction of the second vector according to the first offset parameter to obtain a first offset point; and offset the first offset point according to the vector formed by the starting point and the first offset point and the second offset parameter to obtain a second offset point.

[0114] It can be understood that the offset processing module 630 can execute the above sub-steps S2031 to S2033.

[0115] Optionally, the lightning generation module 640 may be specifically configured to perform gridding processing according to a start point, an end point, and a plurality of offset points to generate a lightning grid; and perform rendering processing on the lightning grid to obtain a target lightning.

[0116] The lightning grid includes multiple segments of rectangular grids, and the lightning generation module 640 is specifically used to perform transparency processing on the multiple segments of rectangular grids to eliminate the gap between two adjacent segments of rectangular grids.

[0117] It can be understood that the lightning generation module 640 can execute the above sub-steps S2041 to S2042.

[0118] The lightning generation device 600 provided in the embodiment of the present application obtains the position and orientation of the current virtual camera through the response module 610 in response to the lightning trigger signal randomly generated by the preset trigger; the lightning trigger signal includes a distance parameter, a height parameter and an offset parameter; the determination module 620 determines the starting point and the ending point of the target lightning according to the position of the virtual camera, the orientation of the virtual camera, the distance parameter and the height parameter; the offset processing module 630 determines a plurality of offset points on the plane where the starting point and the ending point are located according to the starting point, the ending point and the offset parameter; the lightning generation module 640 generates the target lightning according to the starting point, the ending point and the plurality of offset points. Since the lightning trigger signal is randomly triggered and generated, the generated target lightning is more random and flexible, and even if there are multiple lightning strikes, there will be no repeated phenomenon, thereby making the presented lightning scene more realistic and credible, and improving the user experience. In addition, the embodiment of the present application generates lightning in a two-dimensional space, which can effectively reduce the computational complexity of the electronic device 100 and avoid causing the device to freeze when presenting lightning.

[0119] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0120] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.

[0121] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, electronic device, or network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as 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.

[0122] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A lightning generation method, characterized in that: The method comprises: In response to a lightning trigger signal randomly generated by a preset trigger, the position and orientation of the current virtual camera are obtained; the lightning trigger signal includes a distance parameter, a height parameter and an offset parameter; Determine the starting point and the ending point of the target lightning according to the position of the virtual camera, the orientation of the virtual camera, the distance parameter and the height parameter; the step of determining the starting point and the ending point of the target lightning according to the position of the virtual camera, the orientation of the virtual camera, the distance parameter and the height parameter comprises: calculating the target position that is at the distance parameter from the position of the virtual camera in the orientation of the virtual camera; offsetting the target position in a direction perpendicular to the orientation of the virtual camera according to the height parameter to obtain the starting point and the ending point of the target lightning; wherein the distance between the starting point and the ending point is the height parameter, and the target position is located on the line segment formed by the starting point and the ending point; Determine a plurality of offset points on a plane where the starting point and the ending point are located according to the starting point, the ending point and the offset parameter; A target lightning is generated according to the starting point, the ending point and the plurality of offset points.

2. The method according to claim 1, characterized in that The step of determining a plurality of offset points on the plane where the starting point and the ending point are located according to the starting point, the ending point and the offset parameter comprises: Determine a first vector formed by the starting point and the ending point, and calculate a second vector perpendicular to the first vector; Offsetting the midpoint of the line segment formed by the starting point and the ending point according to the offset parameter and the direction of the second vector to obtain at least one offset point; In the vertex set formed by the starting point, the offset point and the end point, every two adjacent vertices are used as a new starting point and a new end point, respectively, and the steps of determining the first vector formed by the starting point and the end point and calculating the second vector perpendicular to the first vector are returned until the number of iterations reaches a preset value, thereby determining multiple offset points.

3. The method according to claim 2, characterized in that The offset parameter includes a first offset parameter, and the step of offsetting the midpoint of the line segment formed by the starting point and the ending point according to the offset parameter and the direction of the second vector to obtain at least one offset point includes: The midpoint is offset along the direction of the second vector according to the first offset parameter to obtain a first offset point.

4. The method according to claim 2, characterized in that: The offset parameters include a first offset parameter and a second offset parameter, and the step of offsetting the midpoint of the line segment formed by the starting point and the ending point according to the offset parameters and the direction of the second vector to obtain at least one offset point includes: offsetting the midpoint along the direction of the second vector according to the first offset parameter to obtain a first offset point; The first offset point is offset according to a vector formed by the starting point and the first offset point and the second offset parameter to obtain a second offset point.

5. The method according to claim 1, characterized in that The step of generating target lightning according to the starting point, the ending point and the plurality of offset points comprises: Performing gridding processing according to the starting point, the ending point and the plurality of offset points to generate a lightning grid; The lightning grid is rendered to obtain target lightning.

6. The method according to claim 5, characterized in that The lightning grid includes multiple rectangular grids, and the step of rendering the lightning grid to obtain target lightning includes: Transparency processing is performed on the multiple rectangular grids to eliminate the gap between two adjacent rectangular grids.

7. A lightning generating device, characterized in that: The device comprises: A response module, used to respond to a lightning trigger signal randomly generated by a preset trigger, and obtain the position and orientation of the current virtual camera; the lightning trigger signal includes a distance parameter, a height parameter, and an offset parameter; A determination module, used for determining the starting point and the ending point of the target lightning according to the position of the virtual camera, the orientation of the virtual camera, the distance parameter and the height parameter; the determination module is used for calculating the target position which is the distance parameter away from the position of the virtual camera in the orientation of the virtual camera; according to the height parameter, the target position is offset in a direction perpendicular to the orientation of the virtual camera to obtain the starting point and the ending point of the target lightning; wherein the distance between the starting point and the ending point is the height parameter, and the target position is located on the line segment formed by the starting point and the ending point; An offset processing module, used for determining a plurality of offset points on the plane where the starting point and the ending point are located according to the starting point, the ending point and the offset parameter; The lightning generation module is used to generate target lightning according to the starting point, the ending point and the multiple offset points.

8. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores a computer program, and when the processor executes the computer program, the method according to any one of claims 1 to 6 is implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.