A method and device for adding flame special effects to a picture
By projecting the three-dimensional model to a two-dimensional plane and setting a flame source on the target special effect plane, using a preset flame simulation algorithm to generate a flame special effect layer, and superimpose it with the three-dimensional model, it solves the problem of high hardware resource consumption when adding flame special effects on the three-dimensional model, and achieves efficient and instant flame special effect addition.
Patent Information
- Application Number
- CN202111183954.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-11
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2041-10-11
AI Technical Summary
When adding flame special effects to three-dimensional models, it is difficult for the prior art to accurately express the visual effects of the object surface while reducing the consumption of hardware resources, resulting in low processing performance and large video memory consumption.
By projecting the three-dimensional model to a two-dimensional plane and setting a flame source on the target special effect plane, using the preset flame simulation algorithm to generate a flame special effect layer, and finally superimpose and render the flame special effect layer with the three-dimensional model to achieve the addition of flame special effect.
This method effectively reduces the calculation amount and memory consumption required for adding flame special effects to the three-dimensional model, improves the immediacy and authenticity of flame special effects, and can accurately express the flame visual effect on the surface of the object while reducing the consumption of hardware resources.
Smart Images

Figure CN114004920B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of image processing, and in particular to a method and device for adding flame special effects to a picture. Background Art
[0002] In the field of image processing, the effect of an object on fire can be simulated by superimposing a flame image on the object image. In some application scenarios, it is necessary to add flame effects to 3D models. However, 3D models are more complex than 2D images, and adding flame effects requires higher processing power and longer processing time, which is not conducive to timely adding special effects.
[0003] How to reduce the consumption of hardware resources while accurately expressing the visual effects of the object surface is the technical problem to be solved by this application. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a method and device for adding flame special effects to a picture, so as to solve the problem of how to reduce the consumption of hardware resources while accurately expressing the visual effects of the surface of an object.
[0005] In a first aspect, a method for adding a flame special effect to a picture is provided, comprising:
[0006] Obtain the three-dimensional model to which the flame special effect is to be added;
[0007] Disposing at least one flame source on at least a portion of the surface of the three-dimensional model, wherein the at least one flame source is used to generate a flame special effect;
[0008] Projecting a three-dimensional model including at least one flame source onto a target special effect plane, wherein the projected target special effect plane includes at least one model layer, wherein the model layer includes a two-dimensional model image obtained by projecting the three-dimensional model and at least one flame source distributed on the two-dimensional model image, and the at least one model layer represents an occlusion relationship of at least one surface of the three-dimensional model;
[0009] Generate a flame special effect layer based on a preset flame simulation algorithm and at least one flame source in the target special effect plane, wherein the flame special effect layer includes at least one flame image, and the preset flame simulation algorithm is used to generate the flame image according to the position of the at least one flame source;
[0010] The flame special effect layer is overlaid and rendered with the three-dimensional model to obtain a picture with the flame special effect added.
[0011] In a second aspect, a device for adding a flame special effect to a picture is provided, comprising:
[0012] An acquisition module is used to acquire a three-dimensional model to which a flame effect is to be added;
[0013] A setting module, for setting at least one flame source on at least a portion of the surface of the three-dimensional model, wherein the at least one flame source is used to generate a flame special effect;
[0014] A projection module projects a three-dimensional model including at least one flame source onto a target special effect plane, wherein the projected target special effect plane includes at least one model layer, wherein the model layer includes a two-dimensional model image obtained by projecting the three-dimensional model and at least one flame source distributed on the two-dimensional model image, and wherein the at least one model layer represents an occlusion relationship of at least one surface of the three-dimensional model;
[0015] A generating module, generating a flame special effect layer based on a preset flame simulation algorithm and at least one flame source in the target special effect plane, wherein the flame special effect layer includes at least one flame image, and the preset flame simulation algorithm is used to generate the flame image according to the position of the at least one flame source;
[0016] The rendering module performs superimposed rendering on the flame special effect layer and the three-dimensional model to obtain a picture with the flame special effect added.
[0017] According to a third aspect, an electronic device is provided. The electronic device comprises a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the steps of the method according to the first aspect are implemented.
[0018] According to a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method according to the first aspect are implemented.
[0019] In an embodiment of the present application, a three-dimensional model to be added with flame special effects is obtained; at least one flame source is set on at least part of the surface of the three-dimensional model, and the at least one flame source is used to generate flame special effects; the three-dimensional model including at least one flame source is projected onto a target special effects plane, and the projected target special effects plane includes at least one model layer, and the model layer includes a two-dimensional model image obtained by projecting the three-dimensional model and at least one flame source distributed on the two-dimensional model image, and the at least one model layer represents the occlusion relationship of at least one surface of the three-dimensional model; a flame special effects layer is generated based on a preset flame simulation algorithm and at least one flame source in the target special effects plane, and the flame special effects layer includes at least one flame image, and the preset flame simulation algorithm is used to generate a flame image according to the position of the at least one flame source; the flame special effects layer is superimposed and rendered with the three-dimensional model to obtain a picture after adding flame special effects. In the solution of the embodiment of the present invention, the three-dimensional model is projected onto a two-dimensional image for flame special effects processing, and data dimensionality reduction is achieved, which can effectively reduce the consumed hardware resources and reduce the consumption of video memory while accurately representing the visual effects of the object surface. Reducing the processing performance required for adding flame special effects can shorten the special effects processing time, which is conducive to the realization of real-time special effects addition. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0021] Figure 1 This is one of the flow charts of a method for adding flame special effects to a picture according to an embodiment of the present invention;
[0022] Figure 2 This is a second flow chart of a method for adding flame special effects to a picture according to an embodiment of the present invention;
[0023] Figure 3 This is a third flow chart of a method for adding flame special effects to a picture according to an embodiment of the present invention;
[0024] Figure 4 This is a fourth flow chart of a method for adding flame special effects to a picture according to an embodiment of the present invention;
[0025] Figure 5 This is a fifth flow chart of a method for adding flame special effects to a picture according to an embodiment of the present invention;
[0026] Figure 6 This is a sixth flow chart of a method for adding flame special effects to a picture according to an embodiment of the present invention;
[0027] Figure 7 This is a seventh flow chart of a method for adding flame special effects to a picture according to an embodiment of the present invention;
[0028] Figure 8 The present invention is a schematic structural diagram of a device for adding flame special effects to a picture according to an embodiment of the present invention. DETAILED DESCRIPTION
[0029] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. The figure numbers in this application are only used to distinguish the various steps in the scheme, and are not used to limit the execution order of the various steps. The specific execution order is subject to the description in the specification.
[0030] In the field of image processing, it is often necessary to add special effects to pictures and videos to enhance the visual effect of the picture. Flame effect is a commonly used type of special effect in visual effects. After adding flame effect to the object in the image, the object can be made to look like it is on fire.
[0031] In practical applications, there are application scenarios for adding flame effects to three-dimensional models. Among them, the three-dimensional model is a computer data composed of basic graphic elements (points, lines, and surfaces) that restores the visual performance of three-dimensional objects in the real world, which can be specifically constructed and generated in the software. If you want to add flame effects to the surface of the three-dimensional model, you can generate some two-dimensional slices of sequence frames of flames near the surface of the model, and let these two-dimensional slices always face the viewing angle, which can be the angle of the viewer, that is, the two-dimensional slices always face the viewer. In this way, although it is possible to add flame effects, for three-dimensional models with complex surface structures, the visual realism of the flame two-dimensional slice is poor, and "goofs" often occur.
[0032] Specifically, if the 2D slices of the flame sequence frames are too sparse and the area is too large, the model will be interlaced and the flame will have an obvious flaky feel. If the 2D slices of the flame sequence frames are too dense and the area is too small, the flame will be too small and look unrealistic. The details of the original model are basically unclear and can only be used for some stylized expressions. In addition, if an accurate simulation method is used to calculate the flame effect, it is difficult to apply it to real-time rendering due to the large amount of calculation required. Moreover, the amount of data in a 3D image is larger than that in a 2D image. If the processing accuracy is to be guaranteed during the processing, more video memory space is required. Compared with 2D images, the video memory space occupied during the 3D image processing process increases exponentially, which is difficult for most graphics card hardware to accept.
[0033] In order to solve the problems existing in the prior art, the embodiment of the present application provides a method for adding flame special effects to a picture, such as Figure 1 As shown, the following steps are included:
[0034] S11: Obtain a three-dimensional model to which a flame special effect is to be added.
[0035] In practical applications, a suitable 3D model application can be selected according to actual needs to perform this step. In this embodiment, it is performed in ComputeShader (CS). ComputeShader is a programmable computing unit in a graphics card. Shader can refer to a program running in a graphics card, or a graphics card computing unit that runs the above program.
[0036] In this step, load the 3D model to which you want to add the flame effect in CS. In addition, you can also input the parameters or components required for the model's lighting calculation, such as color, normal, PBR (Physicallly-Based Rendering) map, etc. The loaded 3D model specifically includes basic graphic elements such as the model's vertices and triangles.
[0037] S12: Disposing at least one flame source on at least a portion of the surface of the three-dimensional model, wherein the at least one flame source is used to generate a flame special effect.
[0038] The three-dimensional model often includes multiple surfaces, and the surface mentioned here can be a plane or a curved surface. The flame source set in this step is used to generate flame effects to simulate the visual effect of the surface of the three-dimensional model being on fire.
[0039] Optionally, the flame source set in this step can use the vertices and triangular faces of the three-dimensional model as reference positions, and evenly set the flame source based on at least part of the surface of the three-dimensional model, and set a suitable number of flame source points according to actual needs.
[0040] For example, the at least one flame source can be arranged based on a preset interval and a preset dot matrix position. The flame source in this step can be used as an input of the flame simulation algorithm in the subsequent step, and is the calculation starting point required for simulating flame special effects. When setting the flame point, the position corresponding to the flame burning in the real world can be simulated for setting.
[0041] S13: Projecting a three-dimensional model including at least one flame source onto a target special effects plane, wherein the projected target special effects plane includes at least one model layer, wherein the model layer includes a two-dimensional model image obtained by projecting the three-dimensional model and at least one flame source distributed on the two-dimensional model image, and the at least one model layer represents an occlusion relationship of at least one surface of the three-dimensional model.
[0042] The target special effect plane can be understood as a plane facing the audience's perspective. Projecting the 3D model onto the target special effect plane can flatten the 3D model seen by the audience, that is, present the appearance of the 3D model seen by the audience in a 2D form. After projection, the target special effect plane includes a 3D model image presented in a 2D form, and at least one flame source distributed on the 3D model image.
[0043] Among them, one or more model layers can be set according to the viewing angle of the audience, so as to project the three-dimensional model onto the model layer, thereby displaying the two-dimensional model image of the three-dimensional model seen by the audience on the model layer.
[0044] Specifically, the step of projecting the three-dimensional model and the flame source onto the target special effect plane may include coordinate transformation, rasterization, light and shadow shading, etc. These steps may be based on the three-dimensional model, color, discovery, PBR map, etc. input in the above step S11, and use CS to complete the projection step.
[0045] The above-mentioned rasterization refers to the process of projecting points on a model in real space to discrete pixel points on a two-dimensional plane, which is generally implemented through display device hardware. In this embodiment, this process is implemented in software.
[0046] In the solution provided in this embodiment, the step of performing projection can restore the basic process of the universal rendering pipeline. The universal rendering pipeline process refers to the process of rendering the model to the screen, executing a series of fixed-function shaders. In modern graphics, this process may include coordinate transformation, rasterization, and light and shadow shading. With the development of technology, there are certain variations. In this embodiment, the above process is implemented in ComputeShader.
[0047] Optionally, if the scene contains multiple objects, a spatial transformation can be performed based on the three-dimensional coordinates of the multiple objects to determine the depth of the pixel corresponding to each object. The depth of each pixel can be represented by a depth image to handle the occlusion relationship or other color mixing between multiple objects to achieve better visual effects.
[0048] Optionally, multiple layers can be set in the target special effect plane, and these layers are used to show the front and back occlusion relationship between different planes of the 3D model. After the flame image is generated, the occlusion effect of the flame and the object can be achieved through overlay rendering to improve the authenticity of the visual effect. It is especially suitable for models containing transparent materials, and can more realistically show the appearance of transparent objects.
[0049] S14: Generate a flame special effect layer based on a preset flame simulation algorithm and at least one flame source in the target special effect plane, the flame special effect layer including at least one flame image, and the preset flame simulation algorithm is used to generate the flame image according to the position of the at least one flame source.
[0050] The preset flame simulation algorithm used in this embodiment can be a simulation algorithm for simulating and generating a two-dimensional flame image. The flame simulation algorithm can take into account the existence of objects in the space and respond so that the flame can bypass the object, drift with the wind, etc. For example, the preset flame simulation algorithm can generate a flame image based on the position of the flame point according to preset parameters or the parameters input in step S11. The parameters used here may include buoyancy parameters, wind speed parameters, gravity parameters, flame color parameters, etc., which are not limited in the embodiments of the present application.
[0051] The number of flame special effect layers can be one or more, and the flame special effect layers can be generated based on the occlusion relationship of the model layer in the target special effect plane. For example, when the number of flame special effect layers is multiple, the flame special effect layer generated by the flame source in front of the three-dimensional object close to the audience is located on the model layer, and the flame special effect layer generated by the flame source behind the three-dimensional object far from the audience is located under the model layer. In this way, after the subsequent overlay rendering step, the stacked occlusion effect of the front flame occluding the object and the object occluding the rear flame can be achieved, which is conducive to improving the authenticity of the visual effect.
[0052] Optionally, the occlusion relationship of multiple surfaces of a three-dimensional model can also be displayed through a model layer. For example, a distance parameter is set on each pixel of the model layer, and the distance parameter is used to characterize the relative distance between the three-dimensional model plane displayed by the pixel point and the viewer. For example, the distance parameter of the pixel point corresponding to the three-dimensional model plane close to the viewer is smaller, and the distance parameter of the pixel point corresponding to the three-dimensional model plane far away from the viewer and occluded by other planes is larger. In this way, the occlusion relationship of at least one surface of the three-dimensional model can be represented through a model layer.
[0053] Through this step, a flame special effect layer can be generated based on at least one flame source, wherein each pixel point of the flame special effect layer can have transparency, which is used for subsequent overlay rendering with the three-dimensional model.
[0054] S15: Overlaying and rendering the flame special effect layer and the three-dimensional model to obtain a picture after adding the flame special effect.
[0055] The three-dimensional model in the target special effect plane can be rendered in advance using a universal rendering pipeline, so that the occlusion, shadow and other information of the three-dimensional model itself can be used in the rendering step in this step, so that the screen after adding the flame special effect can show the occlusion, shadow and other effects. In the step of performing superimposed rendering, the flame image and the three-dimensional model in the above step are superimposed and rendered, so that the image rendering of the three-dimensional model and the flame special effect are fused, so that the screen after adding the flame special effect can show a realistic visual effect of the three-dimensional model on fire.
[0056] Through the scheme provided by the embodiment of the present application, the three-dimensional model is projected onto a two-dimensional plane to add flame special effects, which can effectively reduce the amount of calculation required for adding special effects to the three-dimensional model and the consumption of video memory, improve the immediacy of adding flame special effects, and can effectively reduce the consumed hardware resources while accurately showing the flame visual effect on the surface of the object. Moreover, this scheme generates flame images in layers on the target special effect plane, and then superimposes and renders the flame images and the three-dimensional model, which can effectively reduce the resources consumed by image processing, and projects the three-dimensional image onto a two-dimensional plane for processing, thereby realizing data dimensionality reduction. In addition, since this scheme has the advantages of low calculation amount and realistic effect, it can be conducive to the immediate addition of flame images, and can be widely used in application scenarios of human-computer interaction.
[0057] The solution provided in the embodiment of the present application generates flame effects based on a flame source, and the flame source may specifically refer to information required for generating flame effects. For example, the flame source specifically includes information characterizing the location of the flame source, temperature information characterizing the location of the flame source and its vicinity, density information characterizing the transparency of the flame source, etc. The information contained in the flame source can be used to generate a flame image corresponding to the flame source to simulate the visual effect of a real flame.
[0058] In practical applications, a dynamic image or video containing multiple time-sequence frames can be generated based on the solution provided by this embodiment to show the effect of flame dynamic jumping and flame spreading and burning. Among them, a flame special effect can be added to the first frame of the picture first, and then a second frame of the picture based on the time sequence adjacent is generated based on the first frame of the picture after the flame special effect is added. Among them, the first frame of the picture can specifically include information such as the temperature and density of each pixel. In the process of adding the flame special effect to the second frame of the picture, a flame special effect image of the second frame of the picture is generated based on information such as the temperature and density of each pixel in the first frame of the picture.
[0059] In the case where no new flame source is added and no combustion-supporting factors are added, the flame will tend to decay, that is, the ignition area will shrink, the flame will become smaller, etc., and the flame will eventually go out. The above flame decay effect can be generated based on a flame simulation algorithm.
[0060] If the flame needs to continue to burn and spread, it can be achieved by adding a new flame source. For example, in the step of adding a flame special effect to the second frame, a new flame source is added based on the first frame to compensate for the attenuation of the flame in the first frame so that the flame continues to burn. In addition, the flame can be spread by adding a new flame source. Based on the first frame and the newly added flame source in the second frame, the steps provided in the embodiment of the present application can be repeated to complete the addition of the flame special effect to the second frame. By repeating the above steps, a multi-frame continuous flame picture based on a time sequence can be generated, thereby generating a dynamic image of the flame.
[0061] The newly added flame sources in the second frame may be manually added or automatically generated based on algorithmic rules. Specifically, the number and position of the newly added flame sources may be determined based on factors such as the material of the burning object, the surrounding temperature, wind direction, humidity, etc. In addition, the addition of new flame sources may be stopped under external force or other conditions.
[0062] Taking the second frame as an example, the newly added flame source and the temperature, density and other information contained in the first frame can be superimposed and mixed. In the process of adding flame + special effects to the second frame, the flame image can be generated based on the mixed information.
[0063] Based on the solution provided in the above embodiment, optionally, Figure 2 As shown, before the above step S12, it also includes:
[0064] S21: Acquire a special effect layer that matches at least one surface of the three-dimensional model, where the special effect layer includes an area where a flame source is to be set.
[0065] The special effect layer obtained in this step can also be called a Mask, which can be a map. Each pixel in the map is set with 0 or 1 to distinguish which areas are the areas where the flame source is set. For example, the pixel with a value of 1 can be set with a flame source, and the pixel with a value of 0 is not set with a flame source. Subsequently, based on the special effect layer, the flame source can be evenly set in the area with a value of 1.
[0066] Alternatively, each pixel in the Mask map can also be a continuous value between 0 and 1, and the value set on the pixel is used to represent the probability of generating a flame source at the pixel. Subsequently, the flame source is set based on the probability corresponding to each pixel on the special effect layer.
[0067] The texture in this step has the same UV (texture coordinate) distribution as other textures of the 3D model. The texture coordinates mentioned here usually have two coordinate axes, U and V, so they are also called UV coordinates. U represents the distribution on the horizontal coordinate, and V represents the distribution on the vertical coordinate. It defines the position information of each point on the image. These points are interconnected with the 3D model to determine the position of the surface texture map.
[0068] S22: determining a special effect area on the surface of the three-dimensional model where a flame source is to be set according to the special effect layer.
[0069] Since the texture in the above steps has a corresponding relationship with the surface of the 3D model, the vertices and UV of the triangular surface of the 3D model have corresponding parameter values in the texture. According to the parameter values in the texture, it can be determined which areas are to be set as the special effects area of the flame source.
[0070] Wherein, the above step S12 includes:
[0071] S23: Setting at least one flame source in the special effect area of the three-dimensional model.
[0072] In this step, the flame source can be uniformly generated in the special effect area of the above step, or the probability of setting the flame source for each pixel in the special effect area can be determined based on the various parameter values in the map corresponding to the special effect area, so as to set the flame source in the special effect area of the three-dimensional model according to the preset density.
[0073] Through the solution provided in the embodiment of the present application, it is possible to effectively set which areas can add flame sources of flame special effects. In practical applications, it is helpful to simulate the effect of real burning flames. For example, metal objects often cannot be ignited. Through the solution provided in this embodiment, the location of the metal object can be "covered" by the special effect layer to avoid generating a flame source at the location of the metal object, making the image after adding special effects more realistic.
[0074] Based on the solution provided in the above embodiment, optionally, the target special effect plane also includes a depth image, which represents the depth of each pixel of the two-dimensional model image before projection, such as Figure 3 shown.
[0075] In practical applications, the object to which the flame special effect is added usually does not exist alone, but is set in a scene. The object may be blocked by foreground objects or may block background objects.
[0076] In this embodiment, the target special effect plane includes a depth image, and the pixels contained in the depth image represent the depth of each pixel before projection. For example, the color value, brightness value or other parameter value of each pixel can be used to represent the distance between the pixel and the audience before projection. For example, the larger the parameter value, the farther the pixel is from the audience before projection, and the smaller the parameter value, the closer it is.
[0077] Among them, S15 includes:
[0078] S31: According to the depth of each pixel of the two-dimensional model image represented by the depth image before projection, the flame special effect layer is superimposed and rendered with the three-dimensional model to obtain a picture with the flame special effect added.
[0079] In the step of performing overlay rendering, not only the generated flame image is rendered and fused with the 3D model, but also the rendering can be performed based on the depth of each pixel before projection represented by the depth image, with reference to the occlusion relationship. Specifically, by comparing the depth, it is decided whether to render the current pixel, cover the current pixel, etc., to improve the authenticity of the special effect picture.
[0080] In addition, if the 3D model is semi-transparent, in this embodiment, the depth value in the depth image can be used as a basis to determine the occlusion relationship between the flame and the 3D model, so as to realize the superimposed rendering of the flame special effect layer and the semi-transparent 3D model. Specifically, the flame in the part with a small depth value (closer to the audience) will flow more to the area with a large depth value, so as to realize the ignition effect without penetration between the flame and the burning model.
[0081] Based on the solution provided in the above embodiment, optionally, Figure 4 As shown, the above step S14 includes:
[0082] S41: inputting at least one flame source into a preset flame simulation algorithm to obtain an output result of the preset flame simulation algorithm.
[0083] In the embodiment of the present application, the at least one flame source can be displayed by setting the temperature value and density value on the pixel. For example, the temperature value and density value of the pixel where the flame source is located are preset. The model layer containing the temperature value and density value is input into the preset flame simulation algorithm. The flame simulation algorithm processes each pixel in the model layer based on the preset rules. Specifically, the temperature value and density value of the pixel at the center of the output are determined according to the temperature value and density value of the adjacent upper, lower, left, and right pixels. For example, the original pixel temperature is T, and the upper, lower, left, and right pixels are T1, T2, T3, and T4. The final output temperature value can be T0+A*(T1+T2+T3+T4-4*T0), where A is an adjustable coefficient. Similarly, the density value of the pixel can also be determined based on the above rules. Optionally, the temperature value and density value of each pixel obtained by the above steps can be further processed according to energy attenuation or other rules.
[0084] In practical applications, adjacent pixels influence each other during the above processing, and the greater the difference in the values of adjacent pixels, the greater the degree of influence. Based on the solution provided in this embodiment, pixels with higher values (temperature values or density values) will "flow" toward adjacent pixels with lower values, and the speed of "flow" is positively correlated with the difference.
[0085] S42: Determine the attribute value of each pixel in the flame special effect layer according to the output result, wherein the attribute value includes color value and transparency.
[0086] Specifically, the color value of each pixel can be determined according to the temperature value in the above example, and the transparency can be determined according to the density value in the above example. In addition, the color value can also be determined according to the material or other parameters of the three-dimensional object.
[0087] Based on the solution provided in the above embodiment, optionally, Figure 5 As shown, the attribute value also includes a temperature value and a density value. The above step S42 includes:
[0088] S51: Determine the temperature value and density value of the target pixel point in the flame special effect layer according to the output result.
[0089] S52: determining a color value of the target pixel point according to a temperature value of the position where the target pixel point is located, and determining a transparency of the target pixel point according to a density value of the position where the target pixel point is located.
[0090] Through the solution provided by the embodiment of the present application, the color value and transparency of each pixel are determined by a preset flame simulation algorithm, so that the generated flame image is more realistic. The color value and transparency of the pixel can be used for superimposed rendering with the three-dimensional model in the subsequent steps, making the picture after adding the flame special effect more realistic.
[0091] Based on the solution provided in the above embodiment, Figure 6 As shown, the above step S41 includes:
[0092] S61: Inputting the input layer including the at least one flame source into the preset flame simulation algorithm to obtain an output layer output by the preset flame simulation algorithm after at least one iterative processing, wherein the input layer includes the attribute value of each pixel point, and the attribute value of the target pixel point in the output layer is determined according to the attribute value of the pixel point in the input layer corresponding to the target pixel point in the input layer.
[0093] In this step, the preset flame simulation algorithm can perform multiple iterative processes on the input layer. For example, an input layer including at least one flame source is input into the preset flame simulation algorithm to obtain a first output layer after the first processing. Then, the first output layer is input into the preset flame simulation algorithm to obtain a second output layer after one iterative process.
[0094] Without considering environmental factors, the target pixel in the output layer can be located at the same position as the corresponding pixel in the input layer. However, when there is wind or other factors in the environment, the target pixel in the output layer can be located at a different position than the corresponding pixel in the input layer. For example, each pixel in the input layer moves as a whole with the wind, and then the attribute value of each pixel in the output layer is obtained based on the preset flame simulation algorithm.
[0095] In the above iterative processing, for a certain target pixel point, the transparency difference O1, O2, O3, O4 between the pixel point and the four adjacent upper, lower, left and right pixel points in the model layer is first determined in the input layer, so that the formula of the original temperature value can be changed to T0+A*((T1-T0)*abs(1-O1)+(T2-T0)*abs(1–O2)+(T3-T0)*abs(1–O3)+(T4-T0)*abs(1–O4)-4*T0), where abs is an absolute value and the transparency value can be 0 or 1, 1 means that there is a pixel value obtained by rendering the three-dimensional model at the current pixel position, and 0 means that there is no pixel value. The temperature value of the target pixel point in the output layer is calculated. In this way, the flame at the position with low transparency will not flow to the position with high transparency (so that the flame will not continue to flow when it hits the model surface), while the flames can flow between the positions with high transparency, and the positions with high transparency can flow flames to the positions with low transparency.
[0096] Optionally, the rate at which the target pixel circulates the flame to the surroundings can also be determined based on the depth value in the model layer. For example, without considering environmental factors, the rate at which the target pixel circulates the flame in all directions within the plane can be the same. However, if the flame is to circulate to another plane, the rate at which the flame circulates will often change. The rate at which the flame circulates can be specifically determined based on the depth value in the model layer. Generating flame special effects based on the above depth value can make the generated flame special effects closer to the real flame burning visual effect.
[0097] In addition, the output result can be further processed based on energy conservation. In some cases, in addition to determining the attribute value of the target pixel based on the four adjacent upper, lower, left, and right pixels, the attribute value of the target pixel can also be determined based on more pixels within a certain distance from the target pixel.
[0098] S62: Determine the output layer after at least one iterative process as the output result of the preset flame simulation algorithm.
[0099] In practical applications, the above iterative processing can be repeated dozens of times to obtain an output layer that has been iteratively processed dozens of times, so that the output layer can more realistically reflect the visual effect of the flame.
[0100] Optionally, when a scene contains multiple objects, the objects, foreground, and background in the scene that do not need to add flame effects can be rendered to the screen first. After the rendering process is completed, the objects that need to add flame effects are rendered. In the process of rendering the objects that need to add flame effects, data dimension reduction is achieved by projecting them to the target special effects plane, thereby reducing the hardware consumption required in the process of adding flame effects. The target special effects plane with flame effects is then mixed and rendered with the image that has been rendered to the screen before. Among them, the coordinates of the pixel point in the screen space where a certain pixel point of the target special effects plane is located can be obtained through spatial coordinate transformation, and then the depth of the pixel point can be determined, which is used to handle the occlusion relationship between other objects or perform transparent color mixing to optimize the visual effect.
[0101] Based on the solution provided in the above embodiment, optionally, Figure 7 As shown, after step S15, the following further includes:
[0102] S71: Determine the first frame corresponding to the image after adding the flame special effect.
[0103] The solution provided by the embodiment of the present application can not only realize adding flame special effects to images, but also be applied to videos containing multiple frames. Further, it can also be applied to adding real-time flame special effects to human-computer interactive screens. In this step, the screen after adding the flame special effects can be determined as the first frame of the screen, and the first frame can correspond to a timestamp to characterize the temporal position of the first frame of the screen in the video.
[0104] S72: Generate a second frame adjacent to the first frame based on the first frame, wherein the second frame includes a flame effect associated with the first frame, and the flame effect in the second frame is generated based on the temperature value and / or density value of each pixel point in the first frame.
[0105] In this step, the solution provided by any of the above embodiments can be applied to obtain the second frame based on the first frame. Specifically, the second frame can be generated based on the attribute values of each pixel of the first frame through a preset flame simulation algorithm, so that the second frame is associated with the first frame, thereby generating a dynamic flame effect, and generating a flame effect video or dynamic image. The above first frame and second frame can refer to sequence frames, specifically, recording the dynamic visual performance as a series of pictures sorted by time, and displaying these pictures in time sequence, which can achieve more complex visual effects at a lower cost.
[0106] In practical applications, a new flame source can be added based on the first frame according to the size of the fire and the direction of the fire spreading, that is, the second frame is generated based on the first frame and the newly added flame source, so that the fire in the second frame is larger than that in the first frame, or the flame continues to burn. In addition, if the fire needs to gradually decrease, no new flame source needs to be added, and the flame generated frame by frame based on the flame simulation algorithm will gradually decrease.
[0107] The time difference between the first frame and the second frame can be preset according to the requirements. In a windy environment, the flame often spreads with the wind direction, and the above time difference can be associated with the wind speed. In addition, more environment and model related parameters can be set to improve the accuracy of the simulation results.
[0108] The specific steps of generating the flame special effects in the second frame in this step can be the same as the specific steps of generating the flame special effects in the first frame. Specifically, the steps of generating the flame special effects in the second frame can include: projecting the three-dimensional model to the target special effects plane, the projected target special effects plane includes at least one model layer, the model layer includes a two-dimensional model image obtained by projecting the three-dimensional model, and the at least one model layer represents the occlusion relationship of at least one surface of the three-dimensional model; generating a flame special effects layer based on the preset flame simulation algorithm and the temperature value and density value of each pixel point in the first frame, the flame special effects layer includes at least one flame image, and the preset flame simulation algorithm is used to generate the flame image according to the temperature value and density value of each pixel point in the first frame; superimposing and rendering the flame special effects layer with the three-dimensional model to obtain the picture after adding the flame special effects. Optionally, in the step of generating the flame image of the second frame, the preset flame simulation algorithm can also generate the flame image of the second frame according to the temperature value, density value of each pixel point in the first frame and the newly added flame source.
[0109] Among them, the three-dimensional model can be processed in the process of generating the second frame of the picture according to the temperature value of each pixel point in the picture of the first frame. For example, based on the position of the flame point, the volume of the three-dimensional model is consumed to achieve the visual effect of flame burning and consuming materials. Specifically, in the process of performing light and shadow calculation of the three-dimensional model, the flame calculation result of the first frame can be input for correction, and the result can be stored in the second frame. Through the solution provided by the embodiment of the present application, it is not only possible to add flame special effects to the three-dimensional model picture and generate dynamic images or videos. It is also possible to achieve the visual effect of flame consuming the material of the three-dimensional object, making the flame burning effect more realistic.
[0110] The solution provided in the embodiment of the present application is implemented using a flame simulation algorithm on a two-dimensional plane. Compared with the flame simulation algorithm in a three-dimensional space, the solution provided in the embodiment of the present application has lower computational complexity, is more in line with the design structure of modern graphics cards, and has no obvious difference in static visual effects.
[0111] In order to solve the problems existing in the prior art, the embodiment of the present application further provides a device 80 for adding flame special effects to a picture, such as Figure 8 As shown, including:
[0112] An acquisition module 81 acquires a three-dimensional model to which a flame special effect is to be added;
[0113] A setting module 82 is used to set at least one flame source on at least a part of the surface of the three-dimensional model, and the at least one flame source is used to generate a flame special effect;
[0114] A projection module 83 projects the three-dimensional model including at least one flame source onto a target special effect plane, wherein the projected target special effect plane includes at least one model layer, the model layer includes a two-dimensional model image obtained by projecting the three-dimensional model and at least one flame source distributed on the two-dimensional model image, and the at least one model layer represents an occlusion relationship of at least one surface of the three-dimensional model;
[0115] A generating module 84 generates a flame special effect layer based on a preset flame simulation algorithm and at least one flame source in a target special effect plane, wherein the flame special effect layer includes at least one flame image, and the preset flame simulation algorithm is used to generate the flame image according to the position of the at least one flame source;
[0116] The rendering module 85 performs superimposed rendering on the flame special effect layer and the three-dimensional model to obtain a picture with the flame special effect added.
[0117] Through the device provided by the embodiment of the present application, a three-dimensional model to be added with flame special effects is obtained; at least one flame source is set on at least part of the surface of the three-dimensional model, and the at least one flame source is used to generate flame special effects; the three-dimensional model including at least one flame source is projected onto a target special effects plane, and the projected target special effects plane includes at least one model layer, and the model layer includes a two-dimensional model image obtained by projecting the three-dimensional model and at least one flame source distributed on the two-dimensional model image, and the at least one model layer represents the occlusion relationship of at least one surface of the three-dimensional model; based on a preset flame simulation algorithm and at least one flame source in the target special effects plane, a flame special effects layer is generated, and the flame special effects layer includes at least one flame image, and the preset flame simulation algorithm is used to generate the flame image according to the position of at least one flame source; the flame special effects layer is superimposed and rendered with the three-dimensional model to obtain a picture after adding flame special effects. The solution of the embodiment of the present invention, projecting the three-dimensional model onto a two-dimensional plane to add flame special effects can effectively reduce the amount of calculation required for adding special effects to the three-dimensional model and the consumption of video memory, improve the immediacy of adding flame special effects, and can effectively reduce the consumption of hardware resources while accurately expressing the flame visual effect on the surface of the object. Moreover, the scheme generates flame images in layers on the target special effects plane, and then overlays and renders the flame images with other images on the target special effects plane, which can effectively reduce the resources consumed by image processing, project the three-dimensional image onto a two-dimensional plane for processing, and achieve data dimensionality reduction. In addition, since the scheme has the advantages of low computational complexity and realistic effects, it is conducive to adding flame images in real time and can be widely used in human-computer interaction application scenarios.
[0118] Preferably, an embodiment of the present invention further provides an electronic device, including a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the various processes of the above-mentioned method embodiment for adding flame special effects to a picture are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.
[0119] The embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, each process of the above-mentioned method for adding flame special effects to a picture is implemented, and the same technical effect can be achieved. To avoid repetition, it is not repeated here. The computer-readable storage medium is, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0120] It should be noted that, in this article, the terms "include", "comprises" or any other variations 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.
[0121] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods of various embodiments of the present invention.
[0122] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation modes, which are merely illustrative rather than restrictive. Under the guidance of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the present invention and the claims, all of which are within the protection of the present invention.
Claims
1. A method for adding flame special effects to a picture, characterized in that: include: Obtain the three-dimensional model to which the flame special effect is to be added; Disposing at least one flame source on at least a portion of the surface of the three-dimensional model, wherein the at least one flame source is used to generate a flame special effect; Projecting a three-dimensional model including at least one flame source onto a target special effect plane, wherein the projected target special effect plane includes at least one model layer, wherein the model layer includes a two-dimensional model image obtained by projecting the three-dimensional model and at least one flame source distributed on the two-dimensional model image, and the at least one model layer represents an occlusion relationship of at least one surface of the three-dimensional model; Generate a flame special effect layer based on a preset flame simulation algorithm and at least one flame source in the target special effect plane, wherein the flame special effect layer includes at least one flame image, and the preset flame simulation algorithm is used to generate the flame image according to the position of the at least one flame source; The flame special effect layer is overlaid and rendered with the three-dimensional model to obtain a picture with the flame special effect added.
2. The method according to claim 1, characterized in that Before at least one flame source is arranged on at least a portion of the surface of the three-dimensional model, the method further comprises: Acquire a special effect layer matching at least one surface of the three-dimensional model, wherein the special effect layer includes an area where a flame source is to be set; Determining a special effect area on the surface of the three-dimensional model where a flame source is to be set according to the special effect layer; Wherein, at least one flame source is arranged on at least a portion of the surface of the three-dimensional model, comprising: At least one flame source is arranged in the special effect area of the three-dimensional model.
3. The method according to claim 1, characterized in that The target special effect plane also includes a depth image, wherein the depth image represents the depth of each pixel of the two-dimensional model image before projection; The flame special effect layer is overlaid and rendered with the three-dimensional model to obtain a picture with the flame special effect added, including: According to the depth of each pixel of the two-dimensional model image represented by the depth image before projection, the flame special effect layer is superimposed and rendered with the three-dimensional model to obtain a picture with the flame special effect added.
4. The method according to claim 3, characterized in that Generating a flame special effect layer based on a preset flame simulation algorithm and at least one flame source in the target special effect plane includes: Inputting the at least one flame source into the preset flame simulation algorithm to obtain an output result of the preset flame simulation algorithm; The attribute value of each pixel in the flame special effect layer is determined according to the output result, and the attribute value includes color value and transparency.
5. The method according to claim 4, characterized in that The attribute values also include temperature value and density value; Wherein, determining the attribute value of each pixel in the flame special effect layer according to the output result includes: Determine the temperature value and density value of the target pixel point in the flame special effect layer according to the output result; The color value of the target pixel is determined according to the temperature value of the position where the target pixel is located, and the transparency of the target pixel is determined according to the density value of the position where the target pixel is located.
6. The method according to claim 4, characterized in that Inputting the at least one flame source into the preset flame simulation algorithm to obtain an output result of the preset flame simulation algorithm comprises: Inputting an input layer including the at least one flame source into the preset flame simulation algorithm to obtain an output layer output by the preset flame simulation algorithm after at least one iteration, wherein the input layer includes attribute values of each pixel point, and the attribute value of a target pixel point in the output layer is determined according to the attribute values of adjacent pixel points of a pixel point corresponding to the target pixel point in the input layer in the input layer; The output layer that has been iteratively processed for at least one time is determined as the output result of the preset flame simulation algorithm.
7. The method according to claim 5 or 6, characterized in that After the flame special effect layer is overlaid and rendered with the three-dimensional model to obtain a picture with the flame special effect added, the method further includes: Determine the first frame corresponding to the image after adding the flame special effect; A second frame adjacent to the first frame is generated based on the first frame, the second frame includes a flame effect associated with the first frame, and the flame effect in the second frame is generated based on the temperature value and / or density value of each pixel point in the first frame.
8. A device for adding flame special effects to a picture, characterized in that: include: An acquisition module is used to acquire a three-dimensional model to which a flame effect is to be added; A setting module, for setting at least one flame source on at least a portion of the surface of the three-dimensional model, wherein the at least one flame source is used to generate a flame special effect; A projection module projects a three-dimensional model including at least one flame source onto a target special effect plane, wherein the projected target special effect plane includes at least one model layer, wherein the model layer includes a two-dimensional model image obtained by projecting the three-dimensional model and at least one flame source distributed on the two-dimensional model image, and wherein the at least one model layer represents an occlusion relationship of at least one surface of the three-dimensional model; A generating module, generating a flame special effect layer based on a preset flame simulation algorithm and at least one flame source in the target special effect plane, wherein the flame special effect layer includes at least one flame image, and the preset flame simulation algorithm is used to generate the flame image according to the position of the at least one flame source; The rendering module performs superimposed rendering on the flame special effect layer and the three-dimensional model to obtain a picture with the flame special effect added.
9. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the method according to any one of claims 1 to 7 when executed by the processor.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
3D scene special effect processing method and storage equipment
CN107369200A
Virtual object control method and device, terminal and storage medium
CN110478895A