Object falling special effects simulation method, device and storage medium
The special effects of falling objects are simulated through particle clustering attributes and special effects rendering algorithms, which solves the problem of insufficient customization of filter effects and improves the customization and visual effects of image display.
Patent Information
- Application Number
- CN202311005139.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-09
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2043-08-09
AI Technical Summary
Existing filter effects are not sufficiently customized in image display, making it difficult to balance high-quality effects and real-time performance. Moreover, the filters on the market are generally designed and cannot fully meet specific needs, resulting in poor display effects of falling objects.
Using the object falling special effect simulation method, through the center calculation of particle clustering attributes, matrix field size calculation and distance measurement, combined with the special effects rendering algorithm, a target image with a falling object special effect is generated to simulate the shape of different objects under the action of gravity and wind. Random falling effect.
It improves the customization ability of image display, enhances the display effect of falling objects of different image shapes and sizes, improves the overall visual effect of the video, and solves the problem of insufficient customization of filter effects.
Smart Images

Figure CN116993877B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of display special effects, and in particular to a method, device and storage medium for simulating special effects of falling objects. Background Art
[0002] Filters are indeed very common applications in the field of graphics processing, and they play an important role in the field of special effects. Filters can change the appearance, color, contrast and other properties of an image or video, thus providing users with a unique visual experience.
[0003] However, in the existing market, there are generally problems such as low development of filter effects and limited customization capabilities. This is mainly due to the following reasons:
[0004] 1. Algorithm complexity and performance requirements. Filters usually require complex calculations and processing of images. In practical applications, filter algorithms not only need to have good effects, but also need to consider the consumption of computing resources and real-time requirements. For some complex filter effects, it is difficult to take into account both high-quality effects and real-time performance.
[0005] 2. Universality and applicability. Filters on the market are usually designed to meet a wide range of user needs, so their design goals are universality and applicability, in order to cover more application scenarios. This results in the effect of the filter not fully meeting certain specific needs, thus limiting its customization capabilities.
[0006] 3. Development resources and time costs. The development of filter effects requires a lot of time and effort. For some filter effects that are more complex or unique, more research and development work may be required. This makes customized filter effects more difficult and expensive.
[0007] Therefore, in order to solve the technical problems that the current filter effects are insufficiently customized for different image displays and the display effects of falling objects of different image shapes and sizes are poor, a new technology is needed to solve the current problems. Summary of the invention
[0008] The main purpose of the present invention is to solve the technical problems that the current filter effect is not sufficiently customized for different image displays and the display effect of falling objects of different image shapes and sizes is not good.
[0009] A first aspect of the present invention provides a method for simulating special effects of falling objects, comprising the steps of:
[0010] Receiving a target image to be simulated with special effects;
[0011] According to the preset center analysis algorithm, the preset particle clustering attributes are processed by center calculation to obtain the particle center point coordinates;
[0012] According to a preset size calculation formula, a matrix field size calculation is performed on the particle clustering attribute to obtain a particle rectangular field size value;
[0013] Measuring the distance between the display interface of the target image and the particle rectangular field size value to obtain a display distance value;
[0014] Determining whether the displayed distance value is less than zero;
[0015] If the display distance value is less than zero, modifying and rendering the particle clustering attribute according to a preset special effect rendering algorithm to obtain a special effect rendering pixel set;
[0016] According to the special effect drawing pixel set, filter drawing processing is performed on the target image to obtain a target image with a special effect simulation of falling objects.
[0017] Optionally, in a first implementation of the first aspect of the present invention, the particle clustering attributes include: clustering attributes, particle index table, and the particle generation processing is performed on the preset particle cluster according to the preset center analysis algorithm to obtain the particle center point includes:
[0018] Based on the particle index table, the clustering attribute is substituted into a preset speed calculation formula to obtain a target particle speed;
[0019] Substitute the target particle velocity and the clustering attribute into a preset center measurement formula to obtain the particle center point coordinates.
[0020] Optionally, in a second implementation of the first aspect of the present invention, the speed calculation formula includes:
[0021]
[0022] Wherein, V is the target particle velocity, a, b, c, d are constants, j is an index value of the target particle in the particle index table, and FUbo.upartilceCount is the total number of particles with clustering attributes.
[0023] Optionally, in a third implementation of the first aspect of the present invention, the center measurement formula includes:
[0024] Center=Vec2((uv-e)*FUbo.uparticleSpeed+rand(j)+f*cos(FUbo.uCompletion+sin(j)), mod(sin(j)+V*(FUbo.uCompletion*g*(h+FUbo.uparticleSpeed))),
[0025] Among them, Center is the coordinate of the particle center point, Vec2() is a two-dimensional vector constructor, uv is the coordinate of the current pixel point, e, f, g, h, z are constants, j is an index value of the target particle in the particle index table, FUbo.uparticleSpeed is the particle change speed of the clustering attribute, FUbo.uCompletion is the change period of the clustering attribute, V is the target particle speed, rand() is a random function, and mod() is a modulo function.
[0026] Optionally, in a fourth implementation of the first aspect of the present invention, the distance between the display interface of the target image and the particle rectangular field size value is measured to obtain a display distance value, comprising:
[0027] According to a preset vector field calculation formula, the distance between the display interface of the target image and the particle rectangular field size value is measured to obtain a display distance value, wherein the vector field calculation formula includes:
[0028] Result=rectSDF(aspect-Center,Vec2(rectSize,0)),
[0029] Among them, Result is the display distance value, rectSDF() is the vector field calculation function, aspect is the aspect ratio of the display interface, Center is the rectangular field size value, Vec2() is the two-dimensional vector constructor, and rectSize is the particle radius value.
[0030] Optionally, in a fifth implementation of the first aspect of the present invention, the modifying and drawing processing of the particle clustering attributes according to a preset special effect drawing algorithm to obtain a special effect drawing pixel set includes:
[0031] constructing a blank pixel framework based on the particle radius value of the particle clustering attribute;
[0032] Based on a preset flipping algorithm, the particle clustering attribute is flipped and modified to obtain a clustering modified attribute;
[0033] Based on the cluster modification attribute, the pixel values of the blank pixel frame are modified to obtain a special effect drawing pixel set.
[0034] Optionally, in a sixth implementation of the first aspect of the present invention, the step of modifying and rendering the particle clustering attributes according to a preset special effect rendering algorithm to obtain a special effect rendering pixel set further comprises:
[0035] constructing a blank pixel framework based on the particle radius value of the particle clustering attribute;
[0036] Based on a preset rotation algorithm, performing rotation modification processing on the particle clustering attribute to obtain a clustering modification attribute;
[0037] Based on the cluster modification attribute, the pixel values of the blank pixel frame are modified to obtain a special effect drawing pixel set.
[0038] Optionally, in a seventh implementation manner of the first aspect of the present invention, performing filter drawing processing on the target image according to the special effect drawing pixel set to obtain a target image with a special effect simulation of falling objects includes:
[0039] Analyzing the overlapping range between the special effect drawing pixel set and the target image to obtain an overlapping drawing pixel set;
[0040] The overlapping drawing pixel set is assigned to the alpha channel of the target image to generate a target image with a special effect simulation of falling objects.
[0041] A second aspect of the present invention provides a device for simulating falling object special effects, comprising: a memory and at least one processor, wherein instructions are stored in the memory, and the memory and the at least one processor are interconnected via lines; the at least one processor calls the instructions in the memory so that the device for simulating falling object special effects executes the above-mentioned method for simulating falling object special effects.
[0042] A third aspect of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the above-mentioned method for simulating special effects of falling objects.
[0043] In an embodiment of the present invention, by modifying the configuration element type, gravity size, wind speed direction, number of filter elements and other related parameters of particle data and particle clustering properties, the effect of random falling of objects of different shapes under the combined action of gravity and wind can be simulated, which can greatly improve the overall visual effect of the original video and solve the technical problems of insufficient customization of current filter effects for different image displays and poor display effect of falling effects of objects of different image shapes and sizes. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 It is a schematic diagram of a first embodiment of a method for simulating special effects of falling objects in an embodiment of the present invention;
[0045] Figure 2 This is an embodiment of step 102 of the method for simulating special effects of falling objects in an embodiment of the present invention;
[0046] Figure 3 This is the first embodiment of step 106 of the method for simulating special effects of falling objects in an embodiment of the present invention;
[0047] Figure 4 This is a second embodiment of step 106 of the method for simulating special effects of falling objects in an embodiment of the present invention;
[0048] Figure 5 This is an embodiment of step 107 of the method for simulating special effects of falling objects in an embodiment of the present invention;
[0049] Figure 6 It is a schematic diagram of an embodiment of a device for simulating special effects of falling objects in an embodiment of the present invention. DETAILED DESCRIPTION
[0050] The embodiments of the present invention provide a method, a device and a storage medium for simulating special effects of falling objects.
[0051] The embodiments disclosed in the present invention will be described in more detail below with reference to the accompanying drawings. Although certain embodiments disclosed in the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present invention. It should be understood that the drawings and embodiments disclosed in the present invention are only for exemplary purposes and are not intended to limit the scope of protection disclosed in the present invention.
[0052] In the description of the embodiments disclosed in the present invention, the term "including" and similar terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "based at least in part on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The terms "first", "second", etc. may refer to different or the same objects. Other explicit and implicit definitions may also be included below.
[0053] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 An embodiment of the method for simulating special effects of falling objects in an embodiment of the present invention includes:
[0054] 101. Receive a target image to be simulated with special effects;
[0055] In this embodiment, a target image to be simulated with special effects is received. The target image may be an image of video data split into video frames. Therefore, the present invention may also perform special effects simulation on video data. The pre-processing in this step is to split the video data into individual video frame images.
[0056] 102. According to a preset center analysis algorithm, a center calculation process is performed on the preset particle clustering attributes to obtain the coordinates of the particle center point;
[0057] In this embodiment, based on the particle system theory, a certain number of particle units (the number can be controlled by the user) are generated within the current frame time point range, and the center positions of these particles are randomly determined to simulate the natural random presentation of objects in a real physical environment. On this basis, the particles are objectified, that is, an object of random size (such as petals, snowflakes, meteor showers, etc.) is presented at the current particle position. Finally, after the particles are objectified, the objects are randomly transformed (rotated, scaled, twisted, etc.) to form pictures with different visual angles, and finally present a random falling picture in a real 3D physical environment. Therefore, the user only needs to set various properties of particle clustering, and transmit the particle clustering property data into the simulation system. The preset center analysis algorithm first generates the particle center point coordinates based on the particle clustering properties.
[0058] Further, you can refer to Figure 2 , Figure 2 This is an embodiment of step 102 of the method for simulating special effects of falling objects in an embodiment of the present invention. The particle clustering attributes include: clustering attributes, particle index table. In step 102, the following can be performed:
[0059] 1021. Based on the particle index table, substitute the clustering attribute into a preset speed calculation formula to obtain a target particle speed;
[0060] 1022. Substitute the target particle velocity and the clustering attribute into a preset center measurement formula to obtain the particle center point coordinates.
[0061] In steps 1021-1022, different particles in the particle index table have different corresponding index values. In order to find the center coordinates of a clustered particle, it is necessary to traverse the particle index values in the particle index table, substitute them into the speed calculation formula in turn, calculate the target particle speed, and then analyze the center point coordinate data based on the target particle speed and clustering attributes.
[0062] Specifically, the speed calculation formula includes:
[0063]
[0064] Wherein, V is the target particle velocity, a, b, c, d are constants, j is an index value of the target particle in the particle index table, and FUbo.upartilceCount is the total number of particles with clustering attributes.
[0065] Programming data using floating point numbers can be done as follows:
[0066] float speed=0.3f+rand(cos(j))*(0.7f+0.5f*cos(j / (float(fUbo.uParticleCount)*0.25f))).
[0067] Specifically, the center calculation formula includes:
[0068] Center=Vec2((uv-e)*FUbo.uparticleSpeed+rand(j)+f*cos(FUbo.uCompletion+sin(j)), mod(sin(j)+V*(FUbo.uCompletion*g*(h+FUbo.uparticleSpeed)), z)),
[0069] Among them, Center is the coordinate of the particle center point, Vec2() is a two-dimensional vector constructor, uv is the coordinate of the current pixel point, e, f, g, h, z are constants, j is an index value of the target particle in the particle index table, FUbo.uparticleSpeed is the particle change speed of the clustering attribute, FUbo.uCompletion is the change period of the clustering attribute, V is the target particle speed, rand() is a random function, and mod() is a modulo function.
[0070] The programming data using floating point numbers can be used as follows: vec2center = vec2(-(0.25f-uv.y)*fUbo.uParticleSpeed+rand(j)+0.1f*cos(fUbo.uCompletion+sin(j)),mod(sin(j)
[0071] +speed*(fUbo.uCompletion*1.5f*(0.1f+fUbo.uParticleSpeed)), 1.0f)).
[0072] 103. According to a preset size calculation formula, a matrix field size calculation is performed on the particle clustering attribute to obtain a particle rectangular field size value;
[0073] 104. Calculate the distance between the display interface of the target image and the particle rectangular field size value to obtain a display distance value;
[0074] In steps 103-104, rectSize=0.001+speed*0.012*2 is used to calculate the size rectSize of the particle clustering attribute through the target particle speed Speed, and then the size calculation formula is used to calculate the particle rectangular field and the particle rectangular field size value through the size rectSize.
[0075] The relationship of the current coordinate to the rectangle (inside the rectangle, on the border, or outside the rectangle).
[0076] Specifically, the following steps may be performed at 104:
[0077] 1041. According to a preset vector field calculation formula, a distance is measured between the display interface of the target image and the particle rectangular field size value to obtain a display distance value, wherein the vector field calculation formula includes:
[0078] Result=rectSDF(aspect-Center,Vec2(rectSize,0)),
[0079] Among them, Result is the display distance value, rectSDF() is the vector field calculation function, aspect is the aspect ratio of the display interface, Center is the rectangular field size value, Vec2() is the two-dimensional vector constructor, and rectSize is the particle radius value.
[0080] Programming data using floating point numbers can be done as follows:
[0081] float rectSize=0.001+speed*0.012*2.0f;
[0082] vec2 currentCoord = uv;
[0083] / / Use the y-axis as the normalization standard
[0084] currentCoord*=aspect;
[0085] center*=aspect;
[0086] float sdfResult=rectSDF(currentCoord-center,vec2(rectSize),0.0f);
[0087] rectSize=0.001+speed*0.012*2.0f is the line of code that calculates the size of the rectangle. It uses a variable speed and some numerical operations to finally get a floating-point size value. vec2currentCoord=uv; assigns the input two-dimensional coordinate uv to the variable currentCoord, indicating the current coordinate position. currentCoord*=aspect; and center*=aspect; are because the texture coordinates and the center coordinates of the rectangle are relative to the aspect ratio of the screen, these two lines of code multiply the coordinates by aspect (i.e. the aspect ratio of the screen) for normalization.
[0088] floatsdfResult = rectSDF(currentCoord-center, vec2(rectSize), 0.0f); This line of code calls a function called rectSDF, calculates the distance between the current coordinate and the center of the rectangle, and stores the distance in the variable sdfResult. The function's parameters include the current coordinate minus the coordinate of the center of the rectangle, the size of the rectangle (vector vec2(rectSize)), and a floating-point constant 0.0f. The function calculates a standardized value based on the distance to indicate the relationship between the current coordinate and the rectangle (inside the rectangle, on the boundary, or outside the rectangle).
[0089] 105. Determine whether the displayed distance value is less than zero;
[0090] In this embodiment, it is analyzed whether the value of rectSDF in the above text is less than zero.
[0091] 106. If the display distance value is less than zero, modify and draw the particle clustering attribute according to a preset special effect drawing algorithm to obtain a special effect drawing pixel set;
[0092] In this embodiment, if rectSDF is less than zero, it means that the particle position is on the display interface. Through the set special effect drawing algorithm, the particle clustering attributes are modified and drawn to draw the pixel set.
[0093] For further reference, Figure 3 , Figure 3 This is the first embodiment of step 106 of the method for simulating special effects of falling objects in an embodiment of the present invention. Step 106 may perform the following operations:
[0094] 1061. Construct a blank pixel framework based on the particle radius value of the particle clustering attribute;
[0095] 1062. Based on a preset flip algorithm, flip and modify the particle clustering attribute to obtain a clustering modification attribute;
[0096] 1063. Based on the cluster modification attribute, modify the pixel value of the blank pixel frame to obtain a special effect drawing pixel set.
[0097] In steps 1061-1063, the parameters of the 3D transformation are configured through some random factor parameters, and then converted into a 2D transformation:
[0098] vec2tempCoord=currentCoord-center;
[0099] / Remap to the rectangular coordinate system corresponding to the current sdf. The following transformation operations are performed in this coordinate system.
[0100] vec2 scaleSize=vec2(rectSize*2.0f);
[0101] tempCoord=tempCoord / scaleSize;
[0102] This part of the code remaps the coordinate tempCoord to the rectangular coordinate system corresponding to the current SDF (SignedDistanceField) for subsequent transformation operations.
[0103] First, a scaling factor scaleSize is calculated by vec2scaleSize = vec2(rectSize * 2.0f);, which is twice the rectangle size rectSize. This is done to keep the unit length of the distance field function consistent in the rectangular coordinate system.
[0104] Then, by tempCoord = tempCoord / scaleSize;, the coordinate tempCoord is divided by scaleSize to implement the scaling operation of the coordinates. This operation will limit the range of the original coordinate tempCoord to the interval [-1,1], that is, normalize it to the unit range of the rectangular coordinate system corresponding to the current SDF. Through this scaling operation, subsequent geometric operations such as rotation and translation can be performed more conveniently in the rectangular coordinate system.
[0105] After obtaining the blank pixel frame, the particle clustering properties are modified. The specific implementation code can be as follows:
[0106] / / 2) Particle flip principle: angle calculation (the symmetry axis is first rotated to the positive Y axis position, and then flipped and remapped)
[0107] / / Symmetric angle: the angle with the positive Y axis clockwise
[0108] float symmetryTheta=-PI*(45.0f / 180.0f);
[0109] mat2symmetryMat=mat2(cos(symmetryTheta),sin(symmetryTheta),-sin(symmetryTheta),cos(symmetryTheta));
[0110] tempCoord=symmetryMat*tempCoord;
[0111] / / Flip 180° back and forth
[0112] floatflipTheta=PI*fUbo.uCompletion*speed;
[0113] / / Map out the original texture address. The remapping here requires the use of trigonometric thinking. After rotation, from the perspective of the geometric relationship diagram, it is equivalent to the text element being stretched.
[0114] tempCoord.x=tempCoord.x / cos(flipTheta).
[0115] For further reference, Figure 4 , Figure 4 This is a second embodiment of step 106 of the method for simulating special effects of falling objects in an embodiment of the present invention. Step 106 may perform the following operations:
[0116] 1064. Construct a blank pixel framework based on the particle radius value of the particle clustering attribute;
[0117] 1065. Based on a preset rotation algorithm, rotation modification processing is performed on the particle clustering attribute to obtain a clustering modification attribute;
[0118] 1066. Based on the cluster modification attribute, modify the pixel value of the blank pixel frame to obtain a special effect drawing pixel set.
[0119] In steps 1064-1066, the parameters of the 3D transformation are configured through some random factor parameters, and then converted into a 2D transformation:
[0120] vec2 tempCoord=currentCoord-center;
[0121] / Remap to the rectangular coordinate system corresponding to the current sdf. The following transformation operations are performed in this coordinate system.
[0122] vec2 scaleSize=vec2(rectSize*2.0f);
[0123] tempCoord=tempCoord / scaleSize;
[0124] This part of the code remaps the coordinate tempCoord to the rectangular coordinate system corresponding to the current SDF (SignedDistanceField) for subsequent transformation operations.
[0125] First, a scaling factor scaleSize is calculated by vec2scaleSize = vec2(rectSize * 2.0f);, which is twice the rectangle size rectSize. This is done to keep the unit length of the distance field function consistent in the rectangular coordinate system.
[0126] Then, by tempCoord = tempCoord / scaleSize;, the coordinate tempCoord is divided by scaleSize to implement the scaling operation of the coordinates. This operation will limit the range of the original coordinate tempCoord to the interval [-1,1], that is, normalize it to the unit range of the rectangular coordinate system corresponding to the current SDF. Through this scaling operation, subsequent geometric operations such as rotation and translation can be performed more conveniently in the rectangular coordinate system.
[0127] After obtaining the blank pixel frame, the particle clustering properties are modified. The specific implementation code can be as follows:
[0128] / / 3)Particle rotation
[0129] float angle=MAX_RORATE_ANGLE*speed*fUbo.uCompletion*1.0f;
[0130] mat2 mat=mat2(cos(angle),sin(angle),-sin(angle),cos(angle));
[0131] tempCoord = mat*tempCoord;
[0132] / / The center point moves to the origin (0.0f, 0.0f)
[0133] tempCoord += vec2(0.5f);
[0134] float angle=MAX_RORATE_ANGLE*speed*fUbo.uCompletion*1.0f is the calculated rotation angle angle. MAX_RORATE_ANGLE is a constant used to control the maximum rotation angle. By multiplying speed, fUbo.uCompletion and 1.0f, the speed and completion of the rotation can be controlled according to external parameters.
[0135] mat2 mat=mat2(cos(angle),sin(angle),-sin(angle),cos(angle)); creates a 2x2 matrix mat, in which cos(angle) and sin(angle) are used to represent the element values of the rotation matrix.
[0136] tempCoord=mat*tempCoord is to multiply the matrix mat by the coordinate tempCoord, thereby realizing the rotation operation of the coordinate.
[0137] tempCoord+=vec2(0.5f) translates tempCoord to move the center point to the origin (0.5f, 0.5f). This step may be to handle the transformation of the texture coordinate system from the upper left corner to the center. This code uses basic mathematical operations and spatial geometric mapping to rotate, scale, and translate the current pixel coordinates to achieve some specific visual effects.
[0138] 107. Perform filter drawing processing on the target image according to the special effect drawing pixel set to obtain a target image with a special effect simulation of falling objects.
[0139] In this embodiment, the pixel color is processed and selected according to the range and coordinate position of the particles, and the mixing effect of the particles and background pixels is achieved through a mixing operation, and finally a filter effect is generated to obtain a target image with a special effect simulation of falling objects.
[0140] For further reference, Figure 5 , Figure 5 This is an embodiment of step 107 of the method for simulating special effects of falling objects in an embodiment of the present invention. Step 107 may perform the following operations:
[0141] 1071. Analyze the overlapping range between the special effect drawing pixel set and the target image to obtain an overlapping drawing pixel set;
[0142] 1072. Assign the overlapping drawing pixel set to the alpha channel of the target image to generate a target image with a special effect simulation of falling objects.
[0143] In steps 1071-1702, the following code can be used to implement it:
[0144] vec4imgColor = vec4(0.0f);
[0145] / / Texture location constraints, if it exceeds the texture boundary, it will be transparent
[0146] if(tempCoord.x<0.0f||tempCoord.x>1.0f||tempCoord.y<0.0f||tempCoord.y>1.0f){
[0147] / / Out of range site selection
[0148] imgColor = vec4(0.0f);
[0149] }else{
[0150] / / Select a location within the normal range
[0151] imgColor=texture(uTexture1,tempCoord);
[0152] if(imgColor.a<=0.0f){
[0153] imgColor = vec4(0.0f);
[0154] }
[0155] }
[0156] / / One pixel satisfies two particle ranges at the same time and performs special coverage processing
[0157] if(sdfResult<=0.0f){
[0158] imgColor = fragColor;
[0159] }else{
[0160] / / Mix with the previous base color
[0161] imgColor=mix(fragColor,imgColor,imgColor.a);
[0162] }
[0163] fragColor = imgColor;
[0164] vec4bgColor=texture(uTexture2,vTexPosition1);
[0165] fragColor=mix(bgColor,fragColor,fragColor.a);
[0166] glFragColor = fragColor;
[0167] This code mainly realizes the mixing effect of particles and background pixels, and forms the final filter effect. vec4imgColor = vec4(0.0f); creates a color variable imgColor with an initial value of zero to store the final pixel color.
[0168] if(tempCoord.x<0.0f||tempCoord.x>1.0f||tempCoord.y<0.0f||tempCoord.y>1.0f) checks whether the coordinate tempCoord exceeds the texture boundary (0-1 range). If so, set imgColor to fully transparent black (vec4(0.0f)).
[0169] Else if the coordinates are within the texture range, do the following:
[0170] a.imgColor=texture(uTexture1,tempCoord) obtains the pixel color with coordinates tempCoord from texture uTexture1.
[0171] b.if(imgColor.a<=0.0f) checks whether the alpha component of the obtained pixel color is less than or equal to 0.0. If so, imgColor is set to fully transparent black (vec4(0.0f)).
[0172] if(sdfResult<=0.0f) is to check whether a certain condition (which may be related to the range of other particles) is met. If it is met, the following operations are performed:
[0173] a.imgColor = fragColor; assigns the current fragment color fragColor to imgColor.
[0174] Else: If the previous condition is not met, do the following:
[0175] a.imgColor = mix(fragColor, imgColor, imgColor.a) is to use the mix function to mix fragColor and imgColor, and the mixing ratio is the alpha component of imgColor. The purpose here is to mix two colors while maintaining partial transparency.
[0176] fragColor = mix(bgColor, fragColor, fragColor.a) is to use the mix function again to mix bgColor (background color) and fragColor, and the mixing ratio is the alpha component of fragColor. The purpose here is to finally mix the mixed result with the background color.
[0177] glFragColor=fragColor assigns the final mixed color to glFragColor as the final output color.
[0178] In an embodiment of the present invention, by modifying the configuration element type, gravity size, wind speed direction, number of filter elements and other related parameters of particle data and particle clustering properties, the effect of random falling of objects of different shapes under the combined action of gravity and wind can be simulated, which can greatly improve the overall visual effect of the original video and solve the technical problems of insufficient customization of current filter effects for different image displays and poor display effect of falling effects of objects of different image shapes and sizes.
[0179] Figure 6 1 is a schematic diagram of the structure of an object falling special effect simulation device provided by an embodiment of the present invention. The object falling special effect simulation device 600 may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 610 (for example, one or more processors) and a memory 620, and one or more storage media 630 (for example, one or more mass storage devices) storing application programs 633 or data 632. Among them, the memory 620 and the storage medium 630 can be short-term storage or permanent storage. The program stored in the storage medium 630 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the object falling special effect simulation device 600. Furthermore, the processor 610 can be configured to communicate with the storage medium 630 to execute a series of instruction operations in the storage medium 630 on the object falling special effect simulation device 600.
[0180] The object falling special effect simulation device 600 may also include one or more power supplies 640, one or more wired or wireless network interfaces 650, one or more input and output interfaces 660, and / or one or more operating systems 631, such as Windows Serve, Mac OS X, Unix, Linux, Free BSD, etc. Those skilled in the art will appreciate that Figure 6 The structure of the device for simulating falling object special effects shown does not constitute a limitation on the device for simulating falling object special effects, and may include more or less components than shown in the figure, or a combination of certain components, or a different arrangement of components.
[0181] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the steps of the method for simulating special effects of falling objects.
[0182] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0183] In addition, although each operation is described in a specific order, this should be understood as requiring such operation to be performed in the specific order shown or in a sequential order, or requiring that all illustrated operations should be performed to obtain desired results. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single implementation in combination. On the contrary, the various features described in the context of a single implementation can also be implemented in multiple implementations individually or in any suitable sub-combination mode.
[0184] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
Claims
1. A method for simulating special effects of falling objects, characterized in that: Includes steps: Receiving a target image to be simulated with special effects; According to the preset center analysis algorithm, the preset particle clustering attributes are processed by center calculation to obtain the particle center point coordinates; According to a preset size calculation formula, a rectangular field size calculation is performed on the particle clustering attribute to obtain a particle rectangular field size value; Measuring the distance between the display interface of the target image and the particle rectangular field size value to obtain a display distance value; Determining whether the displayed distance value is less than zero; If the display distance value is less than zero, modifying and rendering the particle clustering attribute according to a preset special effect rendering algorithm to obtain a special effect rendering pixel set; According to the special effect drawing pixel set, filter drawing processing is performed on the target image to obtain a target image with a special effect simulation of falling objects; The particle clustering attributes include: clustering attributes, particle index table, and the particle generation process is performed on the preset particle clustering according to the preset center analysis algorithm to obtain the particle center point, including: Based on the particle index table, the clustering attribute is substituted into a preset speed calculation formula to obtain a target particle speed; Substituting the target particle velocity and the clustering attribute into a preset center measurement formula to obtain the particle center point coordinates; Wherein, the speed calculation formula includes: Wherein, V is the target particle velocity, a, b, c, d are constants, j is an index value of the target particle in the particle index table, and FUbo.upartilceCount is the total number of particles with clustering attributes; The center calculation formula includes: , Among them, Center is the coordinate of the particle center point, Vec2() is a two-dimensional vector constructor, uv is the coordinate of the current pixel point, e, f, g, h, z are constants, j is an index value of the target particle in the particle index table, FUbo.uparticleSpeed is the particle change speed of the clustering attribute, FUbo.uCompletion is the change period of the clustering attribute, V is the target particle speed, rand() is a random function, and mod() is a modulo function; The step of measuring the distance between the display interface of the target image and the particle rectangular field size value to obtain the display distance value comprises: According to a preset vector field calculation formula, the distance between the display interface of the target image and the particle rectangular field size value is measured to obtain a display distance value, wherein the vector field calculation formula includes: Result=rectSDF(aspect-Center,Vec2(rectSize,0)), Among them, Result is the display distance value, rectSDF() is the vector field calculation function, aspect is the aspect ratio of the display interface, Center is the coordinate of the particle center point, Vec2() is the two-dimensional vector constructor, and rectSize is the particle size radius value; Among them, rectSize=0.001+V*0.012*2.0f, V is the target particle speed, and 2.0f is a floating point constant.
2. The method for simulating falling object special effects according to claim 1, characterized in that: The modifying and drawing processing of the particle clustering attributes according to the preset special effect drawing algorithm to obtain the special effect drawing pixel set includes: Constructing a blank pixel framework based on the particle size radius value of the particle clustering attribute; Based on a preset flipping algorithm, the particle clustering attribute is flipped and modified to obtain a clustering modified attribute; Based on the cluster modification attribute, the pixel values of the blank pixel frame are modified to obtain a special effect drawing pixel set.
3. The method for simulating falling object special effects according to claim 1, characterized in that: The step of modifying and rendering the particle clustering attributes according to a preset special effect rendering algorithm to obtain a special effect rendering pixel set further comprises: Constructing a blank pixel framework based on the particle size radius value of the particle clustering attribute; Based on a preset rotation algorithm, performing rotation modification processing on the particle clustering attribute to obtain a clustering modification attribute; Based on the cluster modification attribute, the pixel values of the blank pixel frame are modified to obtain a special effect drawing pixel set.
4. The method for simulating falling object special effects according to claim 1, characterized in that: The step of performing filter drawing processing on the target image according to the special effect drawing pixel set to obtain the target image with the object falling special effect simulation comprises: Analyzing the overlapping range between the special effect drawing pixel set and the target image to obtain an overlapping drawing pixel set; The overlapping drawing pixel set is assigned to the alpha channel of the target image to generate a target image with a special effect simulation of falling objects.
5. A device for simulating falling object special effects, characterized in that: The object falling special effect simulation device comprises: a memory and at least one processor, the memory stores instructions, and the memory and the at least one processor are interconnected via a line; The at least one processor calls the instructions in the memory to enable the falling object special effect simulation device to execute the falling object special effect simulation method according to any one of claims 1 to 4.
6. 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 for simulating falling object special effects as described in any one of claims 1 to 4 is implemented.
