Disclosure of Invention
The invention mainly aims to provide a method, a device, equipment and a storage medium for generating a water ripple image, and aims to solve the technical problems that when a simulated water ripple visual effect is realized by using Unity3D, the consumption of computer performance is overlarge, and the visual effect is poor because a water ripple distortion effect cannot act on objects except a background picture.
In order to achieve the above object, the present invention provides a method for generating a water ripple image, the method comprising the steps of:
acquiring texture coordinates of each pixel point in a previous frame of water ripple image of a target water ripple image to be generated through a preset C # script program;
calculating the texture coordinate and the corresponding color value of each pixel point in the target water ripple image according to the texture coordinate of each pixel point in the previous frame of water ripple image;
creating a shader, storing texture coordinates and corresponding color values of each pixel point in the target water ripple image into the shader, and storing the preset length-width ratio of the water wave resolution and the texture coordinates of a water wave generation center point into the shader;
creating a material ball in the shader, and transmitting texture coordinates and corresponding color values of each pixel point in the target water ripple image stored in the shader, the length-width ratio of the water wave resolution and the texture coordinates of the water wave generation center point into the material ball;
and calling a vertex function of the shader, calculating the position coordinates of the target water ripple image in a screen according to the vertex function, and generating the target water ripple image according to the position coordinates and the material ball.
Optionally, the step of calculating the texture coordinate and the corresponding color value of each pixel point in the target water ripple image according to the texture coordinate of each pixel point in the previous frame of water ripple image includes:
performing coordinate transformation on the texture coordinate of each pixel point in the previous frame of water ripple image to obtain the texture coordinate of each pixel point in the target water ripple image;
calculating the horizontal offset and the vertical offset corresponding to the texture coordinate of each pixel point in the target water ripple image according to the texture coordinate of each pixel point in the target water ripple image;
and calculating the color value of each pixel point in the target water ripple image according to the horizontal offset and the vertical offset.
Optionally, the step of performing coordinate transformation on the texture coordinate of each pixel point in the previous frame of water ripple image to obtain the texture coordinate of each pixel point in the target water ripple image includes:
when calculating the texture coordinate of any target pixel point in the target water ripple image, acquiring the texture coordinate of the target pixel point in the previous frame of water ripple image and the texture coordinate of 8 pixel points around the target pixel point in the previous frame of water ripple image;
and substituting texture coordinates of the target pixel points in the previous frame of the water ripple image and texture coordinates of 8 pixel points around the target pixel points in the previous frame of the water ripple image into a preset coordinate transformation formula for calculation to obtain the texture coordinates of the target pixel points in the target water ripple image.
Optionally, the coordinate transformation formula is:
waveB[w,h]'=(waveA[w,h-1]+waveA[w,h+1]+waveA[w-1,h-1]+waveA[w-1,h]+waveA[w-1,h+1]+waveA[w+1,h-1]+waveA[w+1,h]+waveA[w+1,h+1])/4-waveB[w,h];
wherein, waveB [ w, h ]' represents the texture coordinate of the target pixel point in the target water ripple image, waveA [ w, h-1], waveA [ w, h +1], waveA [ w-1, h-1], waveA [ w-1, h +1], waveA [ w +1, h-1], waveA [ w +1, h ] respectively represent the texture coordinate of 8 pixel points around the target pixel point in the previous frame of water ripple image, and waveB [ w, h ] represents the texture coordinate of the target pixel point in the previous frame of water ripple image.
Optionally, the step of calculating, according to the texture coordinate of each pixel point in the target water ripple image, a horizontal offset and a vertical offset corresponding to the texture coordinate of each pixel point in the target water ripple image includes:
when calculating the horizontal offset and the vertical offset corresponding to the target pixel point, acquiring texture coordinates of left and right pixel points adjacent to the target pixel point in the horizontal direction and texture coordinates of upper and lower pixel points adjacent to the target pixel point in the vertical direction;
calculating the texture coordinate difference value of the left pixel point and the right pixel point in the horizontal direction and the texture coordinate difference value of the upper pixel point and the lower pixel point in the vertical direction;
and taking the texture coordinate difference value of the left pixel point and the right pixel point in the horizontal direction as the horizontal offset corresponding to the target pixel point, and taking the texture coordinate difference value of the upper pixel point and the lower pixel point in the vertical direction as the vertical offset corresponding to the target pixel point.
Optionally, the color values include color values of three primary colors of R, G, and B, where R is calculated according to the horizontal offset, G is calculated according to the vertical offset, a value range of R and G is between 0 and 1, and B is a preset value between 0 and 1.
Optionally, the method further comprises:
according to a preset ripple attenuation algorithm, carrying out attenuation processing on texture coordinates of the target pixel points in the target water ripple image;
and taking the texture coordinate after the attenuation processing as the texture coordinate of the target pixel point in the next frame of the water ripple image of the target water ripple image.
Optionally, the ripple attenuation algorithm is:
the term "waveB [ w, h ]" — waveB [ w, h ] '-waveB [ w, h ]' atten, wherein waveB [ w, h ] "represents texture coordinates after attenuation processing, and atten represents a preset attenuation coefficient.
Optionally, the method further comprises:
determining a ripple central area according to a preset radius by taking the water wave generation central point as a circle center;
calculating a new ripple in the ripple center region according to the shader's fragment function;
and mixing the ripples in the target water ripple image with the new ripples according to preset mixing weights, wherein in the ripple central region, the mixing weights of the ripples in the target water ripple image increase along with the increase of the distance from the water wave generation central point, and the mixing weights of the new ripples decrease along with the increase of the distance from the water wave generation central point.
Further, to achieve the above object, the present invention provides a water ripple image generation apparatus including:
the acquisition module is used for acquiring texture coordinates of each pixel point in a previous frame of water ripple image of a target water ripple image to be generated through a preset C # script program;
the script execution module is used for calculating the texture coordinate and the corresponding color value of each pixel point in the target water ripple image according to the texture coordinate of each pixel point in the previous frame of water ripple image;
the shader creating module is used for creating a shader, storing the texture coordinate and the corresponding color value of each pixel point in the target water ripple image into the shader, and storing the length-width ratio of the preset water wave resolution and the texture coordinate of the water wave generation center point into the shader;
a texture sphere creating module, configured to create a texture sphere in the shader, and transmit texture coordinates and corresponding color values of each pixel point in the target water ripple image stored in the shader, a length-width ratio of the water wave resolution, and texture coordinates of the water wave generation center point into the texture sphere;
and the generating module is used for calling a vertex function of the shader, calculating the position coordinates of the target water ripple image in the screen according to the vertex function, and generating the target water ripple image according to the position coordinates and the material ball.
Further, to achieve the above object, the present invention also provides a generation apparatus of a water ripple image, the apparatus including: the image generating method comprises a memory, a processor and a water ripple image generating program stored on the memory and capable of running on the processor, wherein the water ripple image generating program realizes the steps of the water ripple image generating method when executed by the processor.
Further, to achieve the above object, the present invention provides a storage medium having stored thereon a water ripple image generation program that realizes the steps of the water ripple image generation method as described above when executed by a processor.
The method comprises the steps of obtaining texture coordinates of each pixel point in a previous frame of water ripple image of a target water ripple image to be generated through a preset C # script program; calculating the texture coordinate and the corresponding color value of each pixel point in the target water ripple image according to the texture coordinate of each pixel point in the previous frame of water ripple image; creating a shader, storing texture coordinates and corresponding color values of each pixel point in the target water ripple image into the shader, and storing the preset length-width ratio of the water wave resolution and the texture coordinates of a water wave generation center point into the shader; creating a material ball in the shader, and transmitting texture coordinates and corresponding color values of each pixel point in the target water ripple image stored in the shader, the length-width ratio of the water wave resolution and the texture coordinates of the water wave generation center point into the material ball; and calling a vertex function of the shader, calculating the position coordinates of the target water ripple image in a screen according to the vertex function, and generating the target water ripple image according to the position coordinates and the material ball. In this way, the distortion effect of the water ripples can be applied to other layers or game objects, so that the visual effect is enhanced; in addition, through the multithread calculation mode, the calculation resources can be reasonably utilized, and the calculation efficiency is improved. Therefore, the invention solves the technical problems that when the Unity3D is used for realizing the simulated water ripple visual effect, the performance consumption of a computer is overlarge, and the visual effect is poor because the water ripple distortion effect cannot act on objects except the background picture.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
As shown in fig. 1, fig. 1 is a schematic device structure diagram of a hardware operating environment according to an embodiment of the present invention.
The generation device of the water ripple image in the embodiment of the invention can be a PC, a computer or a server.
As shown in fig. 1, the apparatus may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, a communication bus 1002. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory (e.g., a magnetic disk memory). The memory 1005 may alternatively be a storage device separate from the processor 1001.
Those skilled in the art will appreciate that the configuration of the apparatus shown in fig. 1 is not intended to be limiting of the apparatus and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
As shown in fig. 1, a memory 1005, which is a kind of computer storage medium, may include therein an operating system, a network communication module, a user interface module, and a generation program of a water ripple image.
In the terminal shown in fig. 1, the network interface 1004 is mainly used for connecting to a backend server and performing data communication with the backend server; the user interface 1003 is mainly used for connecting a client (user side) and performing data communication with the client; and the processor 1001 may be configured to call a generation program of the moire image stored in the memory 1005 and perform operations in various embodiments of the generation method of the moire image described below.
Based on the hardware structure, various embodiments of the method for generating the water ripple image are provided.
Referring to fig. 2, fig. 2 is a schematic flow chart of a first embodiment of a method for generating a water ripple image according to the present invention, where the method includes:
step S10, acquiring texture coordinates of each pixel point in the previous frame of water ripple image of the target water ripple image to be generated through a preset C # script program;
the generation method of the water ripple image in the embodiment is applied to a scene in which the Unity3D tool is used to realize simulation of the water ripple effect, and may be specifically realized by a generation device of the water ripple image, and the embodiment takes the generation device of the water ripple image as an example for explanation. By observing water waves in nature, we find that the water waves have the characteristics of diffusion, attenuation and refraction, and according to the characteristics, the real water waves can be simulated by applying mathematical and geometric knowledge. In this embodiment, based on the Unity 2D scene, the position where the mouse stays on the screen is set as the water wave generation central point, and the user can also flexibly set the water wave generation central point according to the needs of the user.
In order to ensure the normal implementation of the present invention, the server needs to create a C # script program in advance, where the C # script program is an object-oriented high-level programming language published by microsoft and operated on NET Framework.
Specifically, two int type (integer) variables waveWidth and waveHeight can be defined in the C # script program as the length and width of the water wave resolution, respectively, where waveWidth/waveHeight can be the aspect ratio of the water ripple image display window resolution; defining two-dimensional texture coordinate arrays waveA and waveB of two float types (floating point types), wherein the waveA is used for storing the texture coordinate of each pixel point in the previous frame of water ripple image, the waveB is used for storing the texture coordinate of each pixel point in the target water ripple image, and the array lengths of the waveA and the waveB can be set as waveWidth x waveHeight for storing the texture coordinates of all the pixel points in the image; in addition, defining an array of Color types (Color types) for storing the Color value of each pixel point in the target water ripple image; a variable tex _ uv of Texture2D type (two-dimensional picture type) is defined for storing the water-ripple Texture data of the target water-ripple image.
And at the time interval of displaying each frame of water ripple image, the server executes the C # script program, and can acquire the texture coordinate of each pixel point in the last frame of water ripple image of the pre-stored current target water ripple image to be generated, wherein the texture coordinate is a UV coordinate, U represents the horizontal direction, and U represents the vertical direction, and the position of each pixel point in the image can be positioned through the UV coordinate.
Step S20, calculating texture coordinates and corresponding color values of each pixel point in the target water ripple image according to the texture coordinates of each pixel point in the previous frame of water ripple image;
in this step, the server continues to execute the C # script program to calculate the texture coordinate and the corresponding color value of each pixel point in the target ripple image according to the texture coordinate of each pixel point in the obtained previous frame ripple image.
Specifically, the step S20 may further include: performing coordinate transformation on the texture coordinate of each pixel point in the previous frame of water ripple image to obtain the texture coordinate of each pixel point in the target water ripple image; calculating the horizontal offset and the vertical offset corresponding to the texture coordinate of each pixel point in the target water ripple image according to the texture coordinate of each pixel point in the target water ripple image; and calculating the color value of each pixel point in the target water ripple image according to the horizontal offset and the vertical offset.
In this embodiment, the server may perform coordinate transformation on the texture coordinate of each pixel point in the previous frame of water ripple image to obtain the texture coordinate of each pixel point in the target water ripple image, where the texture coordinate is stored in the array waveB, and then, according to the texture coordinate of each pixel point in the target water ripple image, calculate the horizontal offset and the vertical offset corresponding to the texture coordinate of each pixel point in the target water ripple image, and then, according to the horizontal offset and the vertical offset, calculate the Color value of each pixel point in the target water ripple image, where the Color value is stored in the array Color.
The step of transforming the texture coordinate of each pixel point in the previous frame of the water ripple image to obtain the texture coordinate of each pixel point in the target water ripple image may further include: when calculating the texture coordinate of any target pixel point in the target water ripple image, acquiring the texture coordinate of the target pixel point in the previous frame of water ripple image and the texture coordinate of 8 pixel points around the target pixel point in the previous frame of water ripple image; and substituting the texture coordinate of the target pixel point in the previous frame of the water ripple image and the texture coordinate of 8 pixel points around the target pixel point in the previous frame of the water ripple image into a preset coordinate transformation formula for calculation to obtain the texture coordinate of the target pixel point in the target water ripple image.
The coordinate transformation formula may be:
waveB[w,h]'=(waveA[w,h-1]+waveA[w,h+1]+waveA[w-1,h-1]+waveA[w-1,h]+waveA[w-1,h+1]+waveA[w+1,h-1]+waveA[w+1,h]+waveA[w+1,h+1])/4-waveB[w,h];
wherein, waveB [ w, h ]' represents the texture coordinate of the target pixel point in the target water ripple image, waveA [ w, h-1], waveA [ w, h +1], waveA [ w-1, h-1], waveA [ w-1, h +1], waveA [ w +1, h-1], waveA [ w +1, h ] respectively represent the texture coordinate of 8 pixel points around the target pixel point in the previous frame of water ripple image, and waveB [ w, h ] represents the texture coordinate of the target pixel point in the previous frame of water ripple image.
Further, the step of calculating the horizontal offset and the vertical offset corresponding to the texture coordinate of each pixel point in the target water ripple image according to the texture coordinate of each pixel point in the target water ripple image includes: when calculating the horizontal offset and the vertical offset corresponding to the target pixel point, acquiring texture coordinates of left and right pixel points adjacent to the target pixel point in the horizontal direction and texture coordinates of upper and lower pixel points adjacent to the target pixel point in the vertical direction; calculating the texture coordinate difference value of the left pixel point and the right pixel point in the horizontal direction and the texture coordinate difference value of the upper pixel point and the lower pixel point in the vertical direction; and taking the texture coordinate difference value of the left pixel point and the right pixel point in the horizontal direction as the horizontal offset corresponding to the target pixel point, and taking the texture coordinate difference value of the upper pixel point and the lower pixel point in the vertical direction as the vertical offset corresponding to the target pixel point.
In this embodiment, it is assumed that the horizontal offset corresponding to the target pixel point is offset _ u and the vertical offset is offset _ v, and then the offset _ u is equal to the difference between the texture coordinates of the left and right pixel points of the target pixel point in the horizontal direction, and the offset _ v is equal to the difference between the texture coordinates of the upper and lower pixel points of the target pixel point in the vertical direction. And then, calculating the color value of the target pixel point according to the offset _ u and the offset _ v.
Further, the color values comprise color values of three primary colors of R, G and B, wherein R is obtained through calculation according to horizontal offset, G is obtained through calculation according to vertical offset, the value range of R and G is between 0 and 1, and B is a preset value between 0 and 1.
And after calculating the texture coordinate and the corresponding color value of each pixel point in the target water ripple image, the server assigns the texture coordinate and the corresponding color value of each pixel point in the target water ripple image to tex _ uv, so as to obtain the water ripple texture of the target water ripple image.
Further, in this embodiment, the method for generating a water ripple image may further include: according to a preset ripple attenuation algorithm, carrying out attenuation processing on texture coordinates of the target pixel points in the target water ripple image; and taking the texture coordinate after the attenuation processing as the texture coordinate of the target pixel point in the next frame of the water ripple image of the target water ripple image.
In this embodiment, in order to present an effect that the ripple gradually attenuates over time, the texture coordinate of the target pixel point in the target water ripple image, that is, the waveB [ w, h ]' may be attenuated according to a preset ripple attenuation algorithm, and then the texture coordinate after the attenuation processing is used as the texture coordinate of the target pixel point in the next frame of water ripple image of the target water ripple image.
The ripple attenuation algorithm may be: the term "waveB [ w, h ]" — waveB [ w, h ] '-waveB [ w, h ]' atten, wherein waveB [ w, h ] "represents texture coordinates after attenuation processing, and atten represents a preset attenuation coefficient.
With the above algorithm, the ripple will slowly decay every frame until it is 0. Where the attenuation coefficient atten is a float type variable, which can be flexibly set, for example, atten can be set larger when fast attenuation of the ripple is desired, and atten can be set smaller when slow attenuation of the ripple is desired.
It should be noted that, in order to enable the ripple to be diffused, the waveform calculated in the current frame and the waveform of the last two frames may be replaced, and the above calculation is repeated cyclically, and the ripple is diffused continuously.
Step S30, creating a shader, storing the texture coordinate and the corresponding color value of each pixel point in the target water ripple image into the shader, and storing the length-width ratio of the preset water wave resolution and the texture coordinate of the water wave generation center point into the shader;
the server creates a Shader after calculating the water ripple texture of the target water ripple image, then stores texture coordinates and corresponding color values of each pixel point in the target water ripple image into the Shader, and stores the preset length-width ratio of the water wave resolution and the texture coordinates of the water wave generation center point into the Shader for subsequent calling.
Specifically, a shader named WaterWaveCameraShader may be created, where a sampler2D type variable is defined to store the calculated tex _ uv, two float type variables _ WaveCenter _ x and _ WaveCenter _ y are defined, x and y of uv coordinates of a center point of a ripple generation are stored, a float type variable _ Scale _ xy is defined, and a ratio waveWidth/waveHeight of water wave resolution is stored.
Step S40, creating a material ball in the shader, and transmitting the texture coordinate of each pixel point in the target water ripple image stored in the shader, the corresponding color value, the length-width ratio of the water wave resolution and the texture coordinate of the water wave generation center point into the material ball;
in the step, a server firstly creates a material ball in a shader, and because the water ripple of the invention is based on a Camera (Camera), a WaterWaveCamera script needs to be bound on the Camera, and a post-processing function is written in the WaterWaveCamera script, wherein the function is to perform post special effect processing on an image shot by the Camera on the basis of the image; and then, transmitting texture coordinates and corresponding color values of each pixel point in the target water ripple image stored in the shader, the length-width ratio of the water wave resolution and the texture coordinates of the water wave generation central point into the material ball.
And step S50, calling a vertex function of the shader, calculating the position coordinates of the target water ripple image in the screen according to the vertex function, and generating the target water ripple image according to the position coordinates and the material ball.
In the step, a server calculates the position coordinates of a target water ripple image in a screen by calling a vertex function of a shader, wherein the vertex function is used for completing the conversion of the vertex coordinates of textures from a model space to a clipping space; and then, generating a target water ripple image according to the calculated position coordinates and the material ball. The specific manner of calculating the position coordinates of the target water ripple image in the screen and generating the target water ripple image according to the position coordinates and the material ball may refer to the prior art, and details are not repeated herein.
In the embodiment, through the mode, the distortion effect of the water ripples can be applied to other layers or game objects, so that the visual effect is enhanced; in addition, the texture coordinates and the corresponding color values of each pixel point in the target water ripple image are calculated by independently creating a C # script program, so that the calculation of the water ripple texture is realized, and compared with the existing mode of calculating the water ripple texture by calling the API of Unity3D, the performance consumption of the computer is greatly reduced. Therefore, the embodiment solves the technical problems that when the Unity3D is used for realizing the simulated water ripple visual effect, the performance consumption of the computer is too high, and the visual effect is poor because the water ripple distortion effect cannot act on objects except the background picture.
Further, based on the first embodiment of the method for generating a water ripple image of the present invention, a second embodiment of the method for generating a water ripple image of the present invention is proposed.
In this embodiment, the method for generating a water ripple image may further include: determining a ripple central area according to a preset radius by taking the water wave generation central point as a circle center; calculating a new ripple in a ripple center area according to the fragment function of the shader; and mixing the ripple in the target water ripple image with new ripple according to a preset mixing weight, wherein in the ripple central region, the mixing weight of the ripple in the target water ripple image increases along with the increase of the distance from the water wave generation central point, and the mixing weight of the new ripple decreases along with the increase of the distance from the water wave generation central point.
In this embodiment, to further enhance the visual effect of the image, the water wave texture in the generated target water wave image may be optimized. Specifically, a flow type variable _ Waveuv may be defined to store uv of the water ripple texture acquired by _ WaveTex, where the value intervals of _ waveuv.x and _ waveuv.y are (0-1), and since the uv offset of the ripple is positive or negative, it is necessary to map this _ waveuv.x and _ waveuv.y between (-1), and if the ripple effect is too strong, the value may be multiplied by a number less than 1 to weaken the _ Waveuv offset effect. And superposing the uv value output by the vertex function and the _ Waveuv, and applying the superposed uv value to the main texture _ MainTex to obtain the water ripple effect. However, the central ripple area of the water ripple effect at this time appears to be composed of many water waves of dense and dense hemp, the visual sense is extremely poor, the effect is shown in fig. 4, and fig. 4 is a schematic diagram of the display effect of the target water ripple image in the embodiment of the present invention.
In order to weaken the sense of violation of the central region, a new ripple may be recalculated in the ripple central region by using a sine function and a time function in the sharer's patch element function, as shown in fig. 5, fig. 5 is a schematic diagram illustrating the display effect of the water wave generation central point in the embodiment of the present invention, which may use the water wave generation central point as a center, and define a float type variable _ R as a radius of the ripple central region to be processed, thereby determining a ripple central region, then call the sharer's patch element function to calculate a new ripple in the ripple central region, and then mix the ripple in the target water ripple image with the new ripple according to a preset mixing weight, where the mixing rule may be: in the ripple center region, the mixing weight of the ripple in the target water ripple image increases with the increase of the distance from the water wave generation center point, and the mixing weight of the new ripple decreases with the increase of the distance from the water wave generation center point, so that seamless connection of the two waves can be realized, and the final effect is shown in fig. 6, where fig. 6 is a schematic diagram of the display effect of the embodiment of the present invention after mixing the target water ripple image and the new ripple generated in the ripple center region, the visual effect of the ripple in fig. 6 has been significantly improved, and the fish in the scene also has a distortion effect.
The embodiment further enhances the visual effect of the image by calculating a new ripple in the central area of the ripple and mixing the ripple in the target water ripple image with the new ripple.
The invention also provides a device for generating the water ripple image. Referring to fig. 3, fig. 3 is a block diagram of an embodiment of a device for generating a water ripple image according to the present invention. In this embodiment, the generation device of the water ripple image includes:
the acquiring module 10 is configured to acquire, through a preset C # script program, texture coordinates of each pixel point in a previous frame of water ripple image of a target water ripple image to be generated;
the script execution module 20 is configured to calculate a texture coordinate and a corresponding color value of each pixel point in the target water ripple image according to the texture coordinate of each pixel point in the previous frame of water ripple image;
a shader creating module 30, configured to create a shader, store the texture coordinate and the corresponding color value of each pixel point in the target water ripple image into the shader, and store the length-width ratio of the preset water wave resolution and the texture coordinate of the water wave generation center point into the shader;
a texture sphere creating module 40, configured to create a texture sphere in the shader, and transmit the texture coordinate and the corresponding color value of each pixel point in the target water ripple image stored in the shader, the length-width ratio of the water wave resolution, and the texture coordinate of the water wave generation center point into the texture sphere;
and the generating module 50 is configured to call a vertex function of the shader, calculate a position coordinate of the target water ripple image in the screen according to the vertex function, and generate the target water ripple image according to the position coordinate and the material ball.
Further, the script execution module 20 is further configured to:
performing coordinate transformation on the texture coordinate of each pixel point in the previous frame of water ripple image to obtain the texture coordinate of each pixel point in the target water ripple image;
calculating the horizontal offset and the vertical offset corresponding to the texture coordinate of each pixel point in the target water ripple image according to the texture coordinate of each pixel point in the target water ripple image;
and calculating the color value of each pixel point in the target water ripple image according to the horizontal offset and the vertical offset.
Further, the script execution module 20 is further configured to:
when calculating the texture coordinate of any target pixel point in the target water ripple image, acquiring the texture coordinate of the target pixel point in the previous frame of water ripple image and the texture coordinate of 8 pixel points around the target pixel point in the previous frame of water ripple image;
and substituting texture coordinates of the target pixel points in the previous frame of the water ripple image and texture coordinates of 8 pixel points around the target pixel points in the previous frame of the water ripple image into a preset coordinate transformation formula for calculation to obtain the texture coordinates of the target pixel points in the target water ripple image.
Further, the coordinate transformation formula is as follows:
waveB[w,h]'=(waveA[w,h-1]+waveA[w,h+1]+waveA[w-1,h-1]+waveA[w-1,h]+waveA[w-1,h+1]+waveA[w+1,h-1]+waveA[w+1,h]+waveA[w+1,h+1])/4-waveB[w,h];
wherein, waveB [ w, h ]' represents the texture coordinate of the target pixel point in the target water ripple image, waveA [ w, h-1], waveA [ w, h +1], waveA [ w-1, h-1], waveA [ w-1, h +1], waveA [ w +1, h-1], waveA [ w +1, h ] respectively represent the texture coordinate of 8 pixel points around the target pixel point in the previous frame of water ripple image, and waveB [ w, h ] represents the texture coordinate of the target pixel point in the previous frame of water ripple image.
Further, the script execution module 20 is further configured to:
when calculating the horizontal offset and the vertical offset corresponding to the target pixel point, acquiring texture coordinates of left and right pixel points adjacent to the target pixel point in the horizontal direction and texture coordinates of upper and lower pixel points adjacent to the target pixel point in the vertical direction;
calculating the texture coordinate difference value of the left pixel point and the right pixel point in the horizontal direction and the texture coordinate difference value of the upper pixel point and the lower pixel point in the vertical direction;
and taking the texture coordinate difference value of the left pixel point and the right pixel point in the horizontal direction as the horizontal offset corresponding to the target pixel point, and taking the texture coordinate difference value of the upper pixel point and the lower pixel point in the vertical direction as the vertical offset corresponding to the target pixel point.
Further, the color values comprise color values of three primary colors of R, G and B, wherein R is obtained through calculation according to the horizontal offset, G is obtained through calculation according to the vertical offset, the value range of R and G is between 0 and 1, and B is a preset value between 0 and 1.
Further, the apparatus further comprises:
the attenuation module is used for carrying out attenuation processing on texture coordinates of the target pixel points in the target water ripple image according to a preset ripple attenuation algorithm;
taking the texture coordinate after the attenuation processing as a texture coordinate of the target pixel point in a next frame of water ripple image of the target water ripple image;
further, the ripple attenuation algorithm is as follows:
the term "waveB [ w, h ]" — waveB [ w, h ] '-waveB [ w, h ]' atten, wherein waveB [ w, h ] "represents texture coordinates after attenuation processing, and atten represents a preset attenuation coefficient.
Further, the apparatus further comprises:
the determining module is used for determining a ripple central area according to a preset radius by taking the water wave generation central point as a circle center;
the calculation module is used for calculating a new ripple in the ripple center area according to the fragment function of the shader;
and the ripple mixing module is used for mixing the ripples in the target water ripple image with the new ripples according to preset mixing weights, wherein in the ripple center area, the mixing weights of the ripples in the target water ripple image increase along with the increase of the distance from the water wave generation center point, and the mixing weights of the new ripples decrease along with the increase of the distance from the water wave generation center point.
The method and the beneficial effects of the implementation of each program module can refer to the embodiment of the method for generating the water ripple image, and are not described herein again.
The invention also provides a storage medium.
The storage medium of the present invention stores thereon a water ripple image generation program that realizes the steps of the water ripple image generation method described above when executed by a processor.
The method implemented when the program for generating a water ripple image run on the processor is executed may refer to each embodiment of the method for generating a water ripple image of the present invention, and is not described herein again.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.