Detailed Description
The embodiment of the specification provides a particle-based firework special effect realization method, device and equipment.
In order to make those skilled in the art better understand the technical solutions in the present specification, the technical solutions in the embodiments of the present specification will be clearly and completely described below with reference to the drawings in the embodiments of the present specification, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be obtained by a person skilled in the art without making any inventive step based on the embodiments of the present disclosure, shall fall within the scope of protection of the present application.
The scheme of the specification utilizes the particle map containing the particle tailing, calculates the speed direction of each particle based on a particle system, and then correspondingly rotates the particle map to enable the reverse direction of the particle tailing to be consistent with the speed direction of the corresponding particle, so that the aim of realizing the special effect of the firework more efficiently and truly by using a small amount of particles is fulfilled. The particle system used herein is not particularly limited, and may be, for example, a Graphics Processing Unit (GPU) particle system based on a 3D engine.
It should be noted that the scheme in this specification can be used not only to implement a special effect of fireworks, but also to implement other phenomena that can be represented by trailing particles, such as flames, clouds, meteor, comet, etc. Some embodiments below mainly take the implementation of the firework specific effect as an example.
Fig. 1 is a schematic flow chart of a method for implementing a special effect of fireworks based on particles according to an embodiment of the present specification, and an execution main body includes the particle system and the device thereof. The device may be a server, or may be a user terminal such as a smartphone, a tablet, a smart watch, or the like.
The process in fig. 1 may include the following steps:
s102: and acquiring a particle map used for representing the particles, wherein the particle map comprises a particle tail.
In the embodiment of the specification, the particle tailing is represented by the particle map instead of a large number of particles, and therefore, the number of particles used for realizing the firework effect can be reduced. The particle map and the specific pattern of the particle tails included in the particle map are not limited, and may be designed according to actual needs, for example, fig. 2 shows an exemplary particle map. In fig. 2, the right side of the map represents the particle head, and the left side represents the tail formed by the particle during operation. Under the scene of realizing the firework special effect, the particles simulate firework particles, and the firework particles can form a tail similar to that in fig. 2 in actual operation.
In the embodiment of the present specification, the particle map may be a map on a two-dimensional plane, or may be a 3D map.
S104: calculating the elapsed time after each of said particle emissions.
In the present embodiment, the transmission in step S104 is simulated by a computer, not actual physical motion. Each particle is emitted to simulate the emission of fireworks, and the respective initial parameters of each particle during the emission can be configured according to the emission condition of the fireworks, so that the emission process of the fireworks can be simulated more truly. The initial parameters include, for example: the launching system comprises launching starting time, launching position, launching initial speed, launching acceleration, life cycle, size, color, appearance change mode and the like.
During the period from the particle emission to the particle disappearance, the particle is in a continuous operation state (from a visual point of view, the particle moves according to a certain track), and the operation time after the particle emission can be calculated according to the emission starting time and the current time of the particle.
S106: and calculating the position and the speed direction of each particle according to the running time.
In the embodiments of the present specification, more specifically, the position of the particle at any time may be calculated based on the parameters such as the elapsed time, the emission start time, the emission position, the emission initial velocity, and the emission acceleration, and the velocity direction of the particle at any time may be calculated based on the parameters such as the elapsed time, the emission initial velocity, and the emission acceleration.
S108: and calculating the direction to which the particle map corresponding to each particle needs to be rotated during rendering according to the speed direction, wherein the rotation is used for enabling the opposite direction of the trailing of the particle to be consistent with the speed direction of the corresponding particle.
In the embodiment of the specification, when the real firework particles operate, as the speed direction changes, the firework particle tailing changes the direction correspondingly. In order to simulate the changing state, the particle map can be correspondingly rotated according to the change of the speed direction of the particles during rendering, so that a more real firework special effect is presented.
In the embodiment of the present specification, the direction in which the particle is trailing can be regarded as being the same as possible as the direction of the velocity of the corresponding particle by rotation. In practical applications, the particle map is usually two-dimensional, and the velocity direction of the particle may be three-dimensional, in which case, if the map is only mapped on a single two-dimensional plane during rendering, the opposite direction of the particle tail can be considered to be consistent with the component direction of the velocity direction of the corresponding particle on the two-dimensional plane by rotating the particle map on the two-dimensional plane as much as possible.
S110: and rendering to obtain an image frame after each particle is emitted according to the position, the direction to which the particle needs to be rotated and the particle mapping.
In the embodiment of the present specification, the continuous image frames constitute the firework special effect image. Besides the elements required for rendering in step S110, there may be other factors such as particle size, color, stretching degree and the like to increase the reality of the special effect, and the other factors may also change during the particle operation, so that the size, color and stretching degree of the particle map may be adjusted accordingly during rendering.
In the present specification embodiment, steps S102 to S108 may also belong to steps performed in the rendering process themselves.
Through the method of fig. 1, the visual tailing effect of the fireworks can be simulated by correspondingly rotating the particle map containing the particle tailing according to the current speed direction of the particles, so that the special effect of the fireworks can be realized by a small amount of particles, the calculated amount is small, the occupied storage space is small, the resources can be saved, and the performance can be improved.
Based on the method of fig. 1, the present specification also provides some specific embodiments of the method, and further embodiments, which are described below.
In this embodiment of the present disclosure, as can be seen from the foregoing description, the above calculation process further needs to use configured initial parameters, for example, for step S104, before calculating the elapsed time after each particle is emitted, the following steps may be further performed: and determining initial parameters of the particles, such as emission starting time, emission position, emission initial velocity, emission acceleration, life cycle and the like.
In this embodiment of the present specification, for step S104, the calculating the elapsed time after each particle is emitted may further perform: calculating the remaining time after each particle is emitted; and calculating parameters such as the size and the color of each particle according to the remaining time for rendering.
In this embodiment of the present specification, for step S108, calculating, according to the speed direction, a direction to which a particle map corresponding to each particle needs to be rotated when rendering, specifically may include: and calculating the direction of the velocity component of the velocity of each particle in the coordinate system of the corresponding particle map as the direction to which the particle map needs to rotate during rendering. More intuitively, the embodiment of the present specification further provides a schematic diagram for determining a direction to which the particle map needs to be rotated and an effect after the rotation in an actual application scenario, as shown in fig. 3a to 3 c. In this practical scenario, it is assumed that the velocity of the particle is in the x-y-z three-dimensional coordinate system and the particle map is in the x-y two-dimensional coordinate system.
Fig. 3a shows an exemplary velocity of a particle at a certain time instant, represented by a velocity vector. It can be seen that the velocity vector is perpendicularly projected onto the x-y plane, and the velocity component of the velocity in the x-y two-dimensional coordinate system can be obtained.
Further, fig. 3b shows the x-y plane, and it can be seen that the particle map contains a particle tail whose currently opposite direction is the x-axis direction, and the angle between this opposite direction and the direction of the velocity component is α. Then in rendering, the particle map can be rotated counterclockwise by α around the center of the coordinate system, so that the opposite direction of the trailing particle after rotation is the same as the direction of the velocity component, as shown in fig. 3 c. Exemplary mathematical equations are further provided to implement the rotation operations described above.
The assumed velocity vector is recorded as
The inverse direction of the particle tail before rotation is expressed as a unit vector
The angle between the velocity vector and the unit vector is alpha, the rotation matrix is expressed as
By vector rotation formula
From this calculation, x '= cos α, y' = sin α. Substituting the rotation matrix to obtain a rotation matrix represented by the velocity vector
When rendering, each particle map is multiplied by the rotation matrix, namely, the rotation operation can be realized.
In the embodiment of the present specification, the particle light emitting effect can also be simulated by using the transparency mask, which is also beneficial to reduce the number of particles required to be used. In this case, for step S102, acquiring a particle map representing a particle, the following steps may be further performed: and obtaining a transparency mask, and matching the transparency mask with the particle map during rendering to simulate the light emitting effect of the particles. The shape of the transparency mask can be adapted to the shape of the particle map, and the transparency of different parts of the transparency mask can be automatically adjusted according to a preset algorithm in the operation process of the particles so as to simulate the light-emitting variation effect more truly. An exemplary transparency mask is shown in fig. 4, a glowing effect is currently simulated by the transparency mask in which the particle heads are darkened, while the particle tails are still bright.
According to the above description, an embodiment of the present specification further provides a flowchart of a specific implementation of the method for implementing a special effect of a particle-based firework in an actual application scenario, as shown in fig. 5.
The flow in fig. 5 may include the following steps:
transmitting the particle map into a GPU particle system; configuring parameters such as the emission position (position), the initial emission speed (velocity), the acceleration emission (acceleration), the life cycle (life time), the size (size), the color (color) and the like of each particle; an incoming transmission start time (start _ time); triggering each frame image frame to be rendered according to a preset frame rate, and transmitting current _ time; calculating the running time (deltaTime = current _ time-start _ time) and the normalized remaining time (left _ time =1.0- (deltaTime/lifeTime)) of each particle during each frame rendering, calculating the current speed (v = velocity + acquisition _ deltaTime) and position (p = position + v _ deltaTime) of each particle according to the running time, calculating the current size (e.g., s = size _ lifeLeft) and color (e.g., c = color _ lifeTime) of each particle according to the remaining time, obtaining the direction vector of the component after normalizing the component of the current speed vector of the particle on an x-y plane, rotating the corresponding particle map to the direction of the direction vector, and rendering the image frame; until rendering is finished.
Fig. 6 is an exemplary firework special effect image frame rendered by the particle-based firework special effect implementation method provided in the embodiment of the present specification. In fig. 6, it can be seen that each particle map has been rotated into place, enabling a more realistic simulation of fireworks.
Based on the same idea, the embodiment of the present specification further provides an apparatus corresponding to the method of fig. 1, as shown in fig. 7.
Fig. 7 is a schematic structural diagram of a particle-based firework effect implementation apparatus corresponding to fig. 1 provided in an embodiment of the present specification, where a dashed box represents an optional module, and the apparatus includes:
an obtaining module 701, configured to obtain a particle map used for representing a particle, where the particle map includes a particle tail;
a first calculation module 702, which calculates the operation time of each particle after emission;
a second calculation module 703 for calculating the position and the velocity direction of each particle according to the running time;
a third calculating module 704, configured to calculate, according to the speed direction, a direction to which a particle map corresponding to each particle needs to be rotated when rendering is performed, where the rotation is used to make a reverse direction of trailing of the particle coincide with the speed direction of the corresponding particle;
and a rendering module 705, for rendering to obtain an image frame after each particle is emitted according to the position, the direction to be rotated and the particle map.
Optionally, the apparatus further comprises:
a determining module 706, configured to determine an emission start time, an emission position, an emission initial velocity, an emission acceleration, and a life cycle of each particle before the first calculating module 702 calculates the elapsed time after the emission of each particle.
Optionally, the first calculating module 702 calculates a running time of each particle after emission, and further includes:
the first calculation module 702 calculates the remaining time after each particle is emitted;
and calculating the size and the color of each particle according to the remaining time for the rendering.
Optionally, the third calculating module 704 calculates, according to the speed direction, a direction to which the particle map corresponding to each particle needs to be rotated when rendering the particle map, and specifically includes:
the third calculating module 704 calculates a direction of a velocity component of the velocity of each particle in the coordinate system of the corresponding particle map as a direction to which the particle map needs to be rotated during rendering.
Optionally, the obtaining module 701 obtains a particle map for representing a particle, further includes:
the obtaining module 701 obtains a transparency mask for simulating a light emitting effect of a particle in cooperation with the particle map during the rendering.
Based on the same idea, the embodiments of the present specification further provide a device and a non-volatile computer storage medium corresponding to the foregoing method.
The embodiment of the present specification provides a particle-based firework special effect implementation apparatus corresponding to fig. 1, including:
at least one processor; and (c) a second step of,
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores instructions executable by the at least one processor to cause the at least one processor to:
acquiring a particle map used for representing particles, wherein the particle map comprises a particle tail;
calculating the elapsed time after each particle has been emitted;
calculating the position and the speed direction of each particle according to the running time;
calculating the direction to which the particle map corresponding to each particle needs to be rotated when rendering according to the speed direction, wherein the rotation is used for enabling the opposite direction of the trailing of the particle to be consistent with the speed direction of the corresponding particle;
and rendering to obtain the image frame after each particle is emitted according to the position, the direction to which the particle needs to be rotated and the particle map.
A non-volatile computer storage medium corresponding to fig. 1 provided by the embodiments of the present description stores computer-executable instructions configured to:
acquiring a particle map used for representing particles, wherein the particle map comprises a particle tail;
calculating the running time of each particle after emission;
calculating the position and the speed direction of each particle according to the running time;
calculating the direction to which the particle map corresponding to each particle needs to be rotated when rendering according to the speed direction, wherein the rotation is used for enabling the opposite direction of the trailing of the particle to be consistent with the speed direction of the corresponding particle;
and rendering to obtain an image frame after each particle is emitted according to the position, the direction to which the particle needs to be rotated and the particle mapping.
The foregoing description has been directed to specific embodiments of this disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
All the embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the embodiments of the apparatus, the device, and the nonvolatile computer storage medium, since they are substantially similar to the embodiments of the method, the description is simple, and for the relevant points, reference may be made to the partial description of the embodiments of the method.
The apparatus, the device, the nonvolatile computer storage medium, and the method provided in the embodiments of the present specification correspond to each other, and therefore, the apparatus, the device, and the nonvolatile computer storage medium also have advantageous technical effects similar to those of the corresponding method.
In the 90's of the 20 th century, improvements to a technology could clearly distinguish between improvements in hardware (e.g., improvements to circuit structures such as diodes, transistors, switches, etc.) and improvements in software (improvements to process flow). However, as technology advances, many of today's process flow improvements have been seen as direct improvements in hardware circuit architecture. Designers almost always obtain a corresponding hardware circuit structure by programming an improved method flow into the hardware circuit. Thus, it cannot be said that an improvement in the process flow cannot be realized by hardware physical blocks. For example, a Programmable Logic Device (PLD), such as a Field Programmable Gate Array (FPGA), is an integrated circuit whose Logic functions are determined by programming the Device by a user. A digital system is "integrated" on a PLD by the designer's own programming without requiring the chip manufacturer to design and fabricate application-specific integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing an Integrated Circuit chip, such Programming is often implemented by "logic compiler" software, which is similar to a software compiler used in program development and writing, but the original code before compiling is also written by a specific Programming Language, which is called Hardware Description Language (HDL), and HDL is not only one but many, such as ABEL (Advanced Boolean Expression Language), AHDL (alternate Hardware Description Language), traffic, CUPL (core universal Programming Language), HDCal, jhddl (Java Hardware Description Language), lava, lola, HDL, PALASM, rhyd (Hardware Description Language), and vhigh-Language (Hardware Description Language), which is currently used in most popular applications. It will also be apparent to those skilled in the art that hardware circuitry for implementing the logical method flows can be readily obtained by a mere need to program the method flows with some of the hardware description languages described above and into an integrated circuit.
The controller may be implemented in any suitable manner, for example, the controller may take the form of, for example, a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro) processor, logic gates, switches, an Application Specific Integrated Circuit (ASIC), a programmable logic controller, and an embedded microcontroller, examples of which include, but are not limited to, the following microcontrollers: ARC 625D, atmel AT91SAM, microchip PIC18F26K20, and Silicone Labs C8051F320, the memory controller may also be implemented as part of the control logic for the memory. Those skilled in the art will also appreciate that, in addition to implementing the controller in purely computer readable program code means, the same functionality can be implemented by logically programming method steps such that the controller is in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, embedded microcontrollers and the like. Such a controller may thus be considered a hardware component, and the means included therein for performing the various functions may also be considered as a structure within the hardware component. Or even means for performing the functions may be conceived to be both a software module implementing the method and a structure within a hardware component.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. One typical implementation device is a computer. In particular, the computer may be, for example, a personal computer, a laptop computer, a cellular telephone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
For convenience of description, the above devices are described as being divided into various units by function, and are described separately. Of course, the functionality of the various elements may be implemented in the same one or more pieces of software and/or hardware in the practice of this description.
As will be appreciated by one skilled in the art, the present specification embodiments may be provided as a method, system, or computer program product. Accordingly, embodiments of the present description may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and so forth) having computer-usable program code embodied therein.
The description has been presented with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the description. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static Random Access Memory (SRAM), dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrases "comprising one of 8230; \8230;" 8230; "does not exclude the presence of additional like elements in a process, method, article, or apparatus that comprises that element.
As will be appreciated by one skilled in the art, embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, the description may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and so forth) having computer-usable program code embodied therein.
This description may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
All the embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, as for the system embodiment, since it is substantially similar to the method embodiment, the description is relatively simple, and reference may be made to the partial description of the method embodiment for relevant points.
The above description is only an example of the present specification, and is not intended to limit the present application. Various modifications and changes may occur to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.