CN110917617B - Method, device, equipment and storage medium for generating water ripple image - Google Patents

Method, device, equipment and storage medium for generating water ripple image Download PDF

Info

Publication number
CN110917617B
CN110917617B CN201911120405.8A CN201911120405A CN110917617B CN 110917617 B CN110917617 B CN 110917617B CN 201911120405 A CN201911120405 A CN 201911120405A CN 110917617 B CN110917617 B CN 110917617B
Authority
CN
China
Prior art keywords
pixel point
target
image
texture coordinates
water
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201911120405.8A
Other languages
Chinese (zh)
Other versions
CN110917617A (en
Inventor
夏露辉
许秋子
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ruilishi Visual Creative Technology Shenzhen Co ltd
Original Assignee
Ruilishi Visual Creative Technology Shenzhen Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ruilishi Visual Creative Technology Shenzhen Co ltd filed Critical Ruilishi Visual Creative Technology Shenzhen Co ltd
Priority to CN201911120405.8A priority Critical patent/CN110917617B/en
Publication of CN110917617A publication Critical patent/CN110917617A/en
Application granted granted Critical
Publication of CN110917617B publication Critical patent/CN110917617B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • AHUMAN NECESSITIES
    • A63SPORTS; GAMES; AMUSEMENTS
    • A63FCARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
    • A63F13/00Video games, i.e. games using an electronically generated display having two or more dimensions
    • A63F13/50Controlling the output signals based on the game progress
    • A63F13/52Controlling the output signals based on the game progress involving aspects of the displayed game scene
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T15/003D [Three Dimensional] image rendering
    • G06T15/04Texture mapping
    • AHUMAN NECESSITIES
    • A63SPORTS; GAMES; AMUSEMENTS
    • A63FCARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
    • A63F2300/00Features of games using an electronically generated display having two or more dimensions, e.g. on a television screen, showing representations related to the game
    • A63F2300/30Features of games using an electronically generated display having two or more dimensions, e.g. on a television screen, showing representations related to the game characterized by output arrangements for receiving control signals generated by the game device
    • A63F2300/308Details of the user interface

Abstract

The invention discloses a method for generating a water ripple image, which comprises the following steps: calculating texture coordinates and corresponding color values of each pixel point in the target water ripple image through a preset C# script program; creating a shader, and storing texture coordinates and corresponding color values of each pixel point in the target water ripple image, a preset length-width ratio value of water wave resolution and texture coordinates of a water wave generation center point into the shader; creating a material ball, and transmitting the data stored in the shader into the material ball; and 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 balls. The invention also discloses a device and equipment for generating the moire image and a storage medium. The invention solves the technical problems that the computer performance is excessively consumed when the water ripple visual effect of the simulation is realized by utilizing the Unity3D, and the visual effect is poor because the water ripple distortion effect can not act on objects except the background picture.

Description

Method, device, equipment and storage medium for generating water ripple image
Technical Field
The present invention relates to the field of image processing technologies, and in particular, to a method, an apparatus, a device, and a storage medium for generating a moire image.
Background
Unity3D is a multi-platform comprehensive game development tool developed by Unity Technologies company, which can easily create types of interactive contents such as three-dimensional video games, building visualizations, real-time three-dimensional animations, 2D plane games, and the like, and is a fully integrated professional game engine, which is well known for its powerful cross-platform development characteristics, gorgeous 3D rendering effects, and freely rich man-machine interaction functions.
Currently, in the process of realizing the simulated water ripple visual effect by using Unity3D, the 2D planar water ripple effect realized by using Unity3D is based on a picture, which is generally used as a background, and the defect of this mode is that: only the picture has the twisting effect of the water wave, and other layers or game objects (such as swimming fish in the scene) do not have the twisting effect, so that the visual effect is poor; in addition, computing the water ripple texture of each frame of image in a dynamic scene requires invoking an application programming interface (Application Programming Interface, API) of Unity3D, resulting in excessive computer performance consumption.
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 computer performance is excessively consumed and a visual effect is poor because a water ripple distortion effect cannot act on objects except a background picture when the visual effect of simulated water ripple is realized by utilizing Unity 3D.
In order to achieve the above object, the present invention provides a method for generating a moire image, the method comprising 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 coordinates and the 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;
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 an aspect ratio value of a preset water wave resolution and 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 value 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 coordinate 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 coordinate and the material ball.
Optionally, the step of calculating the texture coordinate and the corresponding color value of each pixel point in the target moire image according to the texture coordinate of each pixel point in the last moire image includes:
carrying out coordinate transformation on the texture coordinates of each pixel point in the previous frame of the ripple image to obtain the texture coordinates of each pixel point in the target ripple image;
calculating a horizontal offset and a vertical offset corresponding to the texture coordinates of each pixel point in the target water ripple image according to the texture coordinates of each pixel point in the target water ripple image;
and calculating the color value of each pixel point in the target moire image according to the horizontal offset and the vertical offset.
Optionally, the step of transforming the texture coordinate of each pixel point in the previous frame of moire image to obtain the texture coordinate of each pixel point in the target moire image includes:
When calculating the texture coordinates of any target pixel point in the target moire image, acquiring the texture coordinates of the target pixel point in the previous frame moire image and the texture coordinates of 8 pixel points around the target pixel point in the previous frame moire image;
substituting texture coordinates of the target pixel point in the previous frame of water ripple image and texture coordinates of 8 pixel points around the target pixel point in the previous frame of water ripple image into a preset coordinate transformation formula for calculation to obtain texture coordinates of the target pixel point 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];
the method comprises the steps of determining a target pixel point, wherein the wave B [ w, h ]' represents texture coordinates of the target pixel point in the target water ripple image, wave A [ w, h-1], wave A [ w, h+1], wave A [ w-1, h-1], wave A [ w-1, h+1], wave A [ w+1, h-1], wave A [ w+1, h ], wave A [ w+1, h+1] respectively represents texture coordinates of 8 pixel points around the target pixel point in the previous frame of water ripple image, and wave B [ w, h ] represents texture coordinates of the target pixel point in the previous frame of water ripple image.
Optionally, the step of calculating the horizontal offset and the vertical offset corresponding to the texture coordinates of each pixel point in the target water ripple image according to the texture coordinates 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, obtaining texture coordinates of a left pixel point and a right pixel point which are adjacent to the target pixel point in the horizontal direction and texture coordinates of an upper pixel point and a lower pixel point which are adjacent to the target pixel point in the vertical direction;
calculating texture coordinate differences of the left pixel point and the right pixel point in the horizontal direction and texture coordinate differences 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 a 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 a 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, the range of values 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 treatment on texture coordinates of the target pixel point in the target ripple image;
and taking the texture coordinates after the attenuation processing as texture coordinates of the target pixel point in a water ripple image of the next frame of the target water ripple image.
Optionally, the ripple attenuation algorithm is:
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 corrugated 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 area according to the element function of the shader;
mixing the waves in the target water wave image with the new waves according to a preset mixing weight, wherein the mixing weight of the waves in the target water wave image increases with the distance from the water wave generation center point in the wave center area, and the mixing weight of the new waves decreases with the distance from the water wave generation center point.
In addition, in order to achieve the above object, the present invention also provides a device for generating a moire image, the device comprising:
the acquisition module is used for acquiring texture coordinates of each pixel point in a previous frame of water ripple image of the 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 system comprises a shader creation module, a storage module and a storage module, wherein the shader creation module is used for 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 an aspect ratio value of a preset water wave resolution and texture coordinates of a water wave generation center point into the shader;
the material ball creation module is used for 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 aspect ratio value of the water wave resolution and the texture coordinates of the water wave generation center point into the material ball;
And the generating module is used for calling the vertex function of the shader, calculating the position coordinate 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 coordinate and the material ball.
In addition, to achieve the above object, the present invention also provides a device for generating a moire image, the device comprising: the device comprises a memory, a processor and a water ripple image generation program which is stored in the memory and can run on the processor, wherein the water ripple image generation program realizes the steps of the water ripple image generation method when being executed by the processor.
In addition, in order to achieve the above object, the present invention also provides a storage medium having stored thereon a generation program of a moire image, which when executed by a processor, implements the steps of the above-described moire image generation method.
According to the method, texture coordinates of each pixel point in a previous frame of water ripple image of a target water ripple image to be generated are obtained through a preset C# script program; calculating the texture coordinates and the 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; 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 an aspect ratio value of a preset water wave resolution and 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 value 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 coordinate 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 coordinate and the material ball. In this way, the twisting effect of the water waves can be applied to other layers or game objects, thereby enhancing the visual effect; in addition, by the multithreading calculation mode, calculation resources can be reasonably utilized, and calculation efficiency is improved. Therefore, the invention solves the technical problems that the computer performance is excessively consumed when the water ripple visual effect of the simulation is realized by utilizing the Unity3D, and the visual effect is poor because the water ripple distortion effect can not act on objects except the background picture.
Drawings
FIG. 1 is a schematic diagram of a device architecture of a hardware operating environment according to an embodiment of the present invention;
FIG. 2 is a flow chart of a first embodiment of a method for generating a moire image according to the present invention;
FIG. 3 is a schematic block diagram illustrating an embodiment of a device for generating a moire image according to the present invention;
FIG. 4 is a schematic diagram showing the effect of displaying a target water ripple image according to an embodiment of the present invention;
FIG. 5 is a schematic diagram showing the effect of the water wave generating center point according to the embodiment of the present invention;
fig. 6 is a schematic diagram showing the effect of mixing a target water ripple image with new waves generated in the center area of the waves in the embodiment of the present invention.
The achievement of the objects, functional features and advantages of the present invention will be further described with reference to the accompanying drawings, in conjunction with the embodiments.
Detailed Description
It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
Referring to fig. 1, fig. 1 is a schematic device structure of a hardware running 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 the communication bus 1002 is used to enable connected communication between these components. The user interface 1003 may include a Display, an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may further 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 stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also optionally be a storage device separate from the processor 1001 described above.
It will be appreciated by those skilled in the art that the device structure shown in fig. 1 is not limiting of the device and may include more or fewer components than shown, or may combine certain components, or a different arrangement of components.
As shown in fig. 1, an operating system, a network communication module, a user interface module, and a generation program of a moire image may be included in a memory 1005 as one type of computer storage medium.
In the terminal shown in fig. 1, the network interface 1004 is mainly used for connecting to a background server and performing data communication with the background 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 used to call a generation program of the moire image stored in the memory 1005 and perform operations in various embodiments of the moire image generation method described below.
Based on the hardware structure, various embodiments of the method for generating the moire image are provided.
Referring to fig. 2, fig. 2 is a schematic flow chart of a first embodiment of a method for generating a moire image according to the present invention, the method includes:
step S10, 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;
The method for generating the moire image in the embodiment is applied to a scene of realizing the moire effect simulation by using the Unity3D tool, and can be specifically realized by a generating device of the moire image. By observing the water wave in the nature, we find that the water wave has the characteristics of diffusion, attenuation and refraction, and according to the characteristics, the real water wave can be simulated by using mathematics and geometric knowledge. According to the embodiment, based on the Unity 2D scene, the position where the mouse stays on the screen is set as the water wave generation center point, and a user can flexibly set the water wave generation center point according to own requirements.
In order to ensure the normal implementation of the present invention, the server needs to create a c# script program in advance, wherein c# is an object-oriented high-level programming language issued by microsoft corporation and running on top of NET Framework.
Specifically, two variables waveWidth, waveHeigh of the int type (integer) may be defined in the c# script program as the length and width of the water wave resolution, respectively, where the waveWidth/waveHeight may be the aspect ratio of the water wave image display window resolution; defining two-dimensional texture coordinate arrays waveA and waveB of two float types (floating point type), wherein waveA is used for storing texture coordinates of each pixel point in a previous frame of water ripple image, waveB is used for storing texture coordinates of each pixel point in a target water ripple image, and the array length of waveA and waveB can be set as waveWidth wave height for storing texture coordinates of all pixel points in the image; in addition, defining an array of Color types (Color types) for storing Color values of each pixel point in the target moire image; a variable tex_uv of a Texture2D type (two-dimensional picture type) is defined for storing the Texture data of the water Texture of the target water Texture image.
And executing the C# script program by the server at the time interval of displaying each frame of the water ripple image, and acquiring the pre-stored texture coordinates of each pixel point in the previous frame of the water ripple image of the current target water ripple image to be generated, wherein the texture coordinates are UV coordinates, U represents the horizontal direction, U represents the vertical direction, and the position of each pixel point in the image can be positioned through the UV coordinates.
Step S20, calculating the texture coordinates and the 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, so as to calculate the texture coordinates and the corresponding color values of each pixel point in the target moire image according to the texture coordinates of each pixel point in the last obtained moire image.
Specifically, the step S20 may further include: carrying out coordinate transformation on the texture coordinates of each pixel point in the previous frame of water ripple image to obtain the texture coordinates of each pixel point in the target water ripple image; according to the texture coordinates of each pixel point in the target water ripple image, calculating a horizontal offset and a vertical offset corresponding to the texture coordinates of each pixel point in the target water ripple image; and calculating the color value of each pixel point in the target moire 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 the moire image to obtain the texture coordinate of each pixel point in the target moire image, where the texture coordinate is stored in the array waveB, then calculate, according to the texture coordinate of each pixel point in the target moire image, a horizontal offset and a vertical offset corresponding to the texture coordinate of each pixel point in the target moire image, and calculate, according to the horizontal offset and the vertical offset, a Color value of each pixel point in the target moire 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 coordinates of any target pixel point in the target water ripple image, acquiring the texture coordinates of the target pixel point in the previous frame of water ripple image and the texture coordinates of 8 pixel points around the target pixel point in the previous frame of water ripple image; substituting texture coordinates of the target pixel point in the previous frame of the water ripple image and texture coordinates 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 coordinates of the target pixel point in the target water ripple image.
The above 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];
the waveB [ w, h ]' represents texture coordinates of the target pixel point in the target water ripple image, the waveA [ w, h-1], the waveA [ w, h+1], the waveA [ w-1, h-1], the waveA [ w-1, h+1], the waveA [ w+1, h-1], the waveA [ w+1, h ], the waveA [ w+1, h+1] respectively represents texture coordinates of 8 pixel points around the target pixel point in the previous frame of water ripple image, and the waveB [ w, h ] represents texture coordinates 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 coordinates of each pixel point in the target moire image according to the texture coordinates of each pixel point in the target moire image includes: when calculating a horizontal offset and a vertical offset corresponding to a target pixel, acquiring texture coordinates of left and right pixels adjacent to the target pixel in a horizontal direction and texture coordinates of upper and lower pixels adjacent to the target pixel in a vertical direction; calculating texture coordinate differences of the left pixel point and the right pixel point in the horizontal direction and texture coordinate differences of the upper pixel point and the lower pixel point in the vertical direction; the texture coordinate difference value of the left pixel point and the right pixel point in the horizontal direction is taken as the horizontal offset corresponding to the target pixel point, and the texture coordinate difference value of the upper pixel point and the lower pixel point in the vertical direction is taken as the vertical offset corresponding to the target pixel point.
In this embodiment, let the horizontal offset corresponding to the target pixel be offset_u and the vertical offset be offset_v, then the offset_u is equal to the texture coordinate difference between the left and right pixels of the target pixel in the horizontal direction, and the offset_v is equal to the texture coordinate difference between the upper and lower pixels of the target pixel 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 include color values of three primary colors R, G and B, wherein R is calculated according to a horizontal offset, G is calculated according to a vertical offset, the value range of R and G is between 0 and 1, and B is a preset value between 0 and 1.
After calculating the texture coordinates and the corresponding color values of each pixel point in the target water ripple image, the server assigns the texture coordinates and the corresponding color values of each pixel point in the target water ripple image to tex_uv, and then the water ripple texture of the target water ripple image is obtained.
Further, in this embodiment, the method for generating a moire image may further include: according to a preset ripple attenuation algorithm, carrying out attenuation treatment on texture coordinates of the target pixel point in the target ripple image; and taking the texture coordinates after the attenuation processing as texture coordinates of the target pixel point in a water ripple image of the next frame of the target water ripple image.
In this embodiment, in order to present an effect that the ripple is slowly attenuated over time, the attenuation processing may be performed on the texture coordinate of the target pixel point in the target water ripple image, that is, the waveB [ w, h ]' 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: 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.
Using the algorithm described above, the ripple will slowly decay at each frame until it is 0. Where the attenuation coefficient atten is a float type variable, it 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.
In order to enable the ripple to be diffused, the waveform calculated by the current frame and the waveform of the previous two frames may be replaced, and the calculation may be repeated in a cyclic manner, so that the ripple is diffused continuously.
Step S30, 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 an aspect ratio value of a preset water wave resolution and texture coordinates of a water wave generation center point into the shader;
After the server calculates the water ripple texture of the target water ripple image, a Shader is created, then texture coordinates and corresponding color values of each pixel point in the target water ripple image are stored in the Shader, and the aspect ratio value of the preset water wave resolution and the texture coordinates of the water wave generation center point are stored in the Shader for subsequent calling.
Specifically, a shader may be created first, named WaterWaterCamera loader, in which a variable of the type of sampler2D is defined, tex_uv calculated above is stored, variables of two float types, namely, waterCenter_x and WaterCenter_y, x and y, which store uv coordinates of a central point of the generation of the ripple, a variable of one float type, namely, scale_xy, is stored, and the ratio of water wave resolution, waveWidth/waveHeight, is stored.
Step S40, creating a material ball in the shader, and transmitting texture coordinates of each pixel point in the target water ripple image stored in the shader, corresponding color values, aspect ratio values of water wave resolution and texture coordinates of a water wave generation center point into the material ball;
in the step, firstly, a material ball is created in a shader by a server, and because the water ripple is based on a Camera (Camera), a WaterWaterCamera script is bound on the Camera, and a post-processing function is written in the WaterWaterCamera script, and the function is used for carrying out post-special effect processing on an image shot by the Camera; then, texture coordinates and corresponding color values of each pixel point in the target water ripple image stored in the shader, an aspect ratio value of the water wave resolution and texture coordinates of the water wave generation center point are transmitted into a material ball.
And 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 balls.
In the step, the server calculates the position coordinates of the target water ripple image in the screen by calling the vertex function of the shader, wherein the vertex function is used for completing the conversion of the vertex coordinates of the texture 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 balls. 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 balls may refer to the prior art, and will not be described herein.
In the embodiment, by the mode, the twisting effect of the water wave can be applied to other layers or game objects, so that the visual effect is enhanced; in addition, by independently creating a C# script program to calculate the texture coordinates and corresponding color values of each pixel point in the target water ripple image, the calculation of the water wave texture is realized, and compared with the existing mode of calculating the water wave texture by calling the API of the Unity3D, the computer performance consumption is greatly reduced. Therefore, the embodiment solves the technical problems that when the Unity3D is utilized to realize the simulated water ripple visual effect, the computer performance is excessively consumed, and the visual effect is poor because the water ripple distortion effect can not act on objects other than the background picture.
Further, based on the first embodiment of the method for generating a moire image according to the present invention, a second embodiment of the method for generating a moire image according to the present invention is provided.
In this embodiment, the method for generating a moire image may further include: determining a corrugated central area according to a preset radius by taking a water wave generation central point as a circle center; calculating a new ripple in the ripple center area according to the element function of the shader; mixing the waves in the target water wave image with new waves according to preset mixing weights, wherein the mixing weights of the waves in the target water wave image increase along with the increase of the distance from the water wave generation center point in the wave center area, and the mixing weights of the new waves decrease along with the increase of the distance from the water wave generation center 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 float type variable_Waveuv may be defined to store the values of_WaveTex, _Waveuv.x and_Waveuv.y for the water ripple texture (0-1), and since the uv offset of the ripple is positive and negative, it is necessary to map the_Waveuv.x and_Waveuv.y between (-1), if the ripple effect is too strong at this time, a number less than 1 may be multiplied to attenuate the_Waveuv offset effect. And superposing the uv value output by the vertex function and the_Waveuv, and applying the uv value and the_Waveuv to the main texture_MainTex to obtain the water ripple effect. However, the central area of the ripple effect in this case is formed by many water waves of mildly hemp, the visual sense is extremely bad, the effect is shown in fig. 4, and fig. 4 is a schematic diagram showing the effect of displaying the target water ripple image in the embodiment of the present invention.
In order to weaken the offence and sense of the central area, a new ripple may be calculated in the ripple central area again by using a sine function and a time function in the chip element function of the loader, as shown in fig. 5, fig. 5 is a schematic diagram of a display effect of a water wave generation central point in an embodiment of the present invention, a water wave generation central point may be used as a center, a float type variable_r may be defined as a radius of the ripple central area to be processed, thereby determining a ripple central area, then calling the chip element function of the loader to calculate a new ripple in the ripple central area, and then mixing 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 central area of the waves, the mixing weight of the waves in the target water wave image is increased along with the increase of the distance from the central point of the generation of the water waves, and the mixing weight of the new waves is reduced along with the increase of the distance from the central point of the generation of the water waves, so that the seamless connection of the two waves can be realized, the final effect is shown in fig. 6, fig. 6 is a schematic diagram showing the display effect after the target water wave image and the new waves generated in the central area of the waves are mixed, the visual effect of the waves in fig. 6 is obviously improved, and the fish in the scene has a twisting effect.
The embodiment further enhances the visual effect of the image by calculating a new ripple in the center 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 moire image. Referring to fig. 3, fig. 3 is a schematic block diagram of an embodiment of a device for generating a moire image according to the present invention. In this embodiment, the device for generating a moire image includes:
the obtaining module 10 is configured to obtain texture coordinates of each pixel point in a previous frame of the water ripple image of the target water ripple image to be generated through a preset c# script program;
the script execution module 20 is configured to calculate a texture coordinate and a corresponding color value of each pixel point in the target moire image according to the texture coordinate of each pixel point in the last moire image;
the shader creating module 30 is configured to create a shader, store texture coordinates and corresponding color values of each pixel point in the target water ripple image into the shader, and store an aspect ratio value of a preset water wave resolution and texture coordinates of a water wave generation center point into the shader;
A material ball creation module 40, configured to create a material ball in the shader, and transfer texture coordinates and corresponding color values of each pixel point in the target water ripple image stored in the shader, an aspect ratio value of the water wave resolution, and texture coordinates of the water wave generation center point into the material ball;
and the generating module 50 is used for calling the vertex function of the shader, calculating the position coordinate 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 coordinate and the material ball.
Further, the script execution module 20 is further configured to:
carrying out coordinate transformation on the texture coordinates of each pixel point in the previous frame of the ripple image to obtain the texture coordinates of each pixel point in the target ripple image;
calculating a horizontal offset and a vertical offset corresponding to the texture coordinates of each pixel point in the target water ripple image according to the texture coordinates of each pixel point in the target water ripple image;
and calculating the color value of each pixel point in the target moire image according to the horizontal offset and the vertical offset.
Further, the script execution module 20 is further configured to:
when calculating the texture coordinates of any target pixel point in the target moire image, acquiring the texture coordinates of the target pixel point in the previous frame moire image and the texture coordinates of 8 pixel points around the target pixel point in the previous frame moire image;
substituting texture coordinates of the target pixel point in the previous frame of water ripple image and texture coordinates of 8 pixel points around the target pixel point in the previous frame of water ripple image into a preset coordinate transformation formula for calculation to obtain texture coordinates of the target pixel point in the target water ripple image.
Further, 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];
the method comprises the steps of determining a target pixel point, wherein the wave B [ w, h ]' represents texture coordinates of the target pixel point in the target water ripple image, wave A [ w, h-1], wave A [ w, h+1], wave A [ w-1, h-1], wave A [ w-1, h+1], wave A [ w+1, h-1], wave A [ w+1, h ], wave A [ w+1, h+1] respectively represents texture coordinates of 8 pixel points around the target pixel point in the previous frame of water ripple image, and wave B [ w, h ] represents texture coordinates 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, obtaining texture coordinates of a left pixel point and a right pixel point which are adjacent to the target pixel point in the horizontal direction and texture coordinates of an upper pixel point and a lower pixel point which are adjacent to the target pixel point in the vertical direction;
calculating texture coordinate differences of the left pixel point and the right pixel point in the horizontal direction and texture coordinate differences 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 a 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 a 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 calculated according to the horizontal offset, G is calculated 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 point in the target water ripple image according to a preset ripple attenuation algorithm;
Taking the texture coordinates after the attenuation treatment as texture coordinates of the target pixel point in a water ripple image of the next frame of the target water ripple image;
further, the ripple attenuation algorithm is:
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 corrugated central area according to a preset radius by taking the water wave generation central point as a circle center;
a calculation module, configured to calculate a new ripple in the ripple center area according to the primitive function of the shader;
and the ripple mixing module is used for mixing the ripple in the target water ripple image with the new ripple according to a preset mixing weight, wherein in the ripple central area, the mixing weight of the ripple in the target water ripple image is increased along with the increase of the distance from the water wave generation central point, and the mixing weight of the new ripple is reduced along with the increase of the distance from the water wave generation central point.
The method for implementing each program module and the beneficial effects thereof can refer to the embodiment of the method for generating the moire image according to the present invention, and are not described herein.
The invention also provides a storage medium.
The storage medium of the present invention stores thereon a generation program of a moire image, which when executed by a processor, implements the steps of the moire image generation method as described above.
The method implemented when the generating program of the moire image running on the processor is executed may refer to each embodiment of the generating method of the moire image of the present invention, and will not be described herein.
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 one … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The foregoing embodiment numbers of the present invention are merely for the purpose of description, and do not represent the advantages or disadvantages of the embodiments.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (e.g. ROM/RAM, magnetic disk, optical disk) as described above, comprising instructions for causing a terminal device (which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to perform the method according to the embodiments of the present invention.
The foregoing description is only of the preferred embodiments of the present invention, and is not intended to limit the scope of the invention, but rather is intended to cover any equivalents of the structures or equivalent processes disclosed herein or in the alternative, which may be employed directly or indirectly in other related arts.

Claims (12)

1. A method for generating a moire image, the method comprising the steps of:
Executing a preset C# script program at the time interval of displaying each frame of water ripple image, analyzing the texture coordinates of each pixel point in the previous frame of water ripple image by using the C# script program, and storing the texture coordinates into a pre-generated array;
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 an aspect ratio value of a preset water wave resolution and 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 value 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 coordinate 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 coordinate and the material ball.
2. The method of claim 1, wherein the step of calculating the texture coordinates and corresponding color values for each pixel in the target moire image according to the texture coordinates for each pixel in the previous moire image comprises:
carrying out coordinate transformation on the texture coordinates of each pixel point in the previous frame of the ripple image to obtain the texture coordinates of each pixel point in the target ripple image;
calculating a horizontal offset and a vertical offset corresponding to the texture coordinates of each pixel point in the target water ripple image according to the texture coordinates of each pixel point in the target water ripple image;
and calculating the color value of each pixel point in the target moire image according to the horizontal offset and the vertical offset.
3. The method of claim 2, wherein the step of transforming the texture coordinates of each pixel in the previous frame of moire image to obtain texture coordinates of each pixel in the target moire image comprises:
when calculating the texture coordinates of any target pixel point in the target moire image, acquiring the texture coordinates of the target pixel point in the previous frame moire image and the texture coordinates of 8 pixel points around the target pixel point in the previous frame moire image;
Substituting texture coordinates of the target pixel point in the previous frame of water ripple image and texture coordinates of 8 pixel points around the target pixel point in the previous frame of water ripple image into a preset coordinate transformation formula for calculation to obtain texture coordinates of the target pixel point in the target water ripple image.
4. The method of claim 3, wherein 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];
the method comprises the steps of determining a target pixel point, wherein the wave B [ w, h ]' represents texture coordinates of the target pixel point in the target water ripple image, wave A [ w, h-1], wave A [ w, h+1], wave A [ w-1, h-1], wave A [ w-1, h+1], wave A [ w+1, h-1], wave A [ w+1, h ], wave A [ w+1, h+1] respectively represents texture coordinates of 8 pixel points around the target pixel point in the previous frame of water ripple image, and wave B [ w, h ] represents texture coordinates of the target pixel point in the previous frame of water ripple image.
5. The method of claim 4, wherein the calculating of the horizontal offset and the vertical offset corresponding to the texture coordinates of each pixel in the target moire image according to the texture coordinates of each pixel in the target moire image comprises:
When calculating the horizontal offset and the vertical offset corresponding to the target pixel point, obtaining texture coordinates of a left pixel point and a right pixel point which are adjacent to the target pixel point in the horizontal direction and texture coordinates of an upper pixel point and a lower pixel point which are adjacent to the target pixel point in the vertical direction;
calculating texture coordinate differences of the left pixel point and the right pixel point in the horizontal direction and texture coordinate differences 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 a 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 a vertical offset corresponding to the target pixel point.
6. A method according to claim 3, wherein the color values include color values of three primary colors R, G, and B, wherein R is calculated according to the horizontal offset, G is calculated according to the vertical offset, the values of R and G range from 0 to 1, and B is a preset value between 0 and 1.
7. The method of claim 6, wherein the method further comprises:
according to a preset ripple attenuation algorithm, carrying out attenuation treatment on texture coordinates of the target pixel point in the target ripple image;
And taking the texture coordinates after the attenuation processing as texture coordinates of the target pixel point in a water ripple image of the next frame of the target water ripple image.
8. The method of claim 7, wherein the ripple attenuation algorithm is:
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.
9. The method of any one of claims 1 to 8, wherein the method further comprises:
determining a corrugated 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 area according to the element function of the shader;
mixing the waves in the target water wave image with the new waves according to a preset mixing weight, wherein the mixing weight of the waves in the target water wave image increases with the distance from the water wave generation center point in the wave center area, and the mixing weight of the new waves decreases with the distance from the water wave generation center point.
10. A device for generating a moire image, the device comprising:
The acquisition module is used for executing a preset C# script program at the time interval of displaying each frame of water ripple image, analyzing the texture coordinates of each pixel point in the previous frame of water ripple image by using the C# script program, and storing the texture coordinates into a pre-generated array;
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 system comprises a shader creation module, a storage module and a storage module, wherein the shader creation module is used for 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 an aspect ratio value of a preset water wave resolution and texture coordinates of a water wave generation center point into the shader;
the material ball creation module is used for 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 aspect ratio value of the water wave resolution and the texture coordinates of the water wave generation center point into the material ball;
and the generating module is used for calling the vertex function of the shader, calculating the position coordinate 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 coordinate and the material ball.
11. A device for generating a moire image, the device comprising: memory, a processor and a generation program of a moire image stored on the memory and executable on the processor, which when executed by the processor, realizes the steps of the generation method of a moire image according to any one of claims 1 to 9.
12. A storage medium, wherein a generation program of a moire image is stored on the storage medium, which when executed by a processor, implements the steps of the moire image generation method according to any one of claims 1 to 9.
CN201911120405.8A 2019-11-15 2019-11-15 Method, device, equipment and storage medium for generating water ripple image Active CN110917617B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911120405.8A CN110917617B (en) 2019-11-15 2019-11-15 Method, device, equipment and storage medium for generating water ripple image

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911120405.8A CN110917617B (en) 2019-11-15 2019-11-15 Method, device, equipment and storage medium for generating water ripple image

Publications (2)

Publication Number Publication Date
CN110917617A CN110917617A (en) 2020-03-27
CN110917617B true CN110917617B (en) 2023-10-24

Family

ID=69853183

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911120405.8A Active CN110917617B (en) 2019-11-15 2019-11-15 Method, device, equipment and storage medium for generating water ripple image

Country Status (1)

Country Link
CN (1) CN110917617B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113645414B (en) * 2020-04-27 2022-09-30 北京达佳互联信息技术有限公司 Method and device for generating water ripple special effect video, electronic equipment and storage medium
CN113744124A (en) * 2020-05-29 2021-12-03 北京达佳互联信息技术有限公司 Image processing method, image processing device, electronic equipment and computer storage medium
CN112164121B (en) * 2020-09-30 2021-11-23 北京完美赤金科技有限公司 Tearing effect graph generation method and device, storage medium and electronic device
CN112258412B (en) * 2020-10-22 2021-07-13 浙江大学 Shader automatic filtering method, device and system based on convolution approximation of definition domain and value domain
CN111968213B (en) * 2020-10-23 2021-03-23 成都完美时空网络技术有限公司 Warping effect generation method, device, equipment and storage medium

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107154063B (en) * 2017-04-19 2023-03-14 腾讯科技(深圳)有限公司 Method and device for setting shape of image display area
CN107292961A (en) * 2017-06-30 2017-10-24 浙江科澜信息技术有限公司 A kind of method for realizing that earth ocean water is imitated in three-dimensional scenic
CN107958480B (en) * 2017-11-23 2021-04-30 腾讯科技(上海)有限公司 Image rendering method and device and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
Unity Shader 水波纹效果;无;《https://gameinstitute.qq.com/community/detail/122193》;20180220;第1-4页 *

Also Published As

Publication number Publication date
CN110917617A (en) 2020-03-27

Similar Documents

Publication Publication Date Title
CN110917617B (en) Method, device, equipment and storage medium for generating water ripple image
CN110196746B (en) Interactive interface rendering method and device, electronic equipment and storage medium
CN103677828B (en) Coverage drawing method, drawing engine and terminal equipment
US20050195196A1 (en) Interactive water effects using texture coordinate shifting
CN110866967B (en) Water ripple rendering method, device, equipment and storage medium
KR20080090671A (en) Apparatus and method for mapping textures to object model
JP2017527898A (en) Bandwidth reduction using texture lookup with adaptive shading
US20140071124A1 (en) Image processing apparatus
CN111476851B (en) Image processing method, device, electronic equipment and storage medium
KR20170040698A (en) Method and apparatus for performing graphics pipelines
CN110782391B (en) Image processing method and device in driving simulation scene and storage medium
US8379037B1 (en) Multi-resolution texture aggregation
CN115471598A (en) Dynamic water surface rendering method, device and equipment
CN113076152A (en) Rendering method and device, electronic equipment and computer readable storage medium
US20100053205A1 (en) Method, apparatus, and system for displaying graphics using html elements
JP3649478B2 (en) Image information processing apparatus and image information processing method
CN112734900A (en) Baking method, baking device, baking equipment and computer-readable storage medium of shadow map
CN112580213A (en) Method and apparatus for generating display image of electric field lines, and storage medium
CN113192173B (en) Image processing method and device of three-dimensional scene and electronic equipment
CN111681307A (en) Method for realizing dynamic three-dimensional coordinate axis applied to three-dimensional software
CN114494384B (en) Building shadow analysis method, device, equipment and storage medium
CN117611703A (en) Barrage character rendering method, barrage character rendering device, barrage character rendering equipment, storage medium and program product
CN117437346A (en) Image processing method, image processing apparatus, electronic device, storage medium, and program product
CN117593237A (en) Face illumination enhancement method, system, equipment and storage medium
CN116309915A (en) Remote sensing image real-time rendering method, device and storage medium based on B/S architecture

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
TA01 Transfer of patent application right
TA01 Transfer of patent application right

Effective date of registration: 20230918

Address after: B1012, Building 7, Shenzhen Bay Science and Technology Ecological Park, No. 1819 Shahe West Road, Gaoxin District, Yuehai Street, Nanshan District, Shenzhen City, Guangdong Province, 518057

Applicant after: Ruilishi Visual Creative Technology (Shenzhen) Co.,Ltd.

Address before: Room 9-12, 10th floor, block B, building 7, Shenzhen Bay science and technology ecological park, 1819 Shahe West Road, Yuehai street, Nanshan District, Shenzhen City, Guangdong Province

Applicant before: SHENZHEN REALIS MULTIMEDIA TECHNOLOGY Co.,Ltd.

GR01 Patent grant
GR01 Patent grant