Disclosure of Invention
The embodiment of the invention provides a method, a device, equipment and a storage medium for generating a distortion effect, which are used for improving the distortion effect of a distorted image and improving the image quality of the distorted image.
In a first aspect, an embodiment of the present invention provides a distortion effect generating method, where the method includes: acquiring image textures; performing distortion processing on texture coordinates corresponding to the image textures to obtain first distorted texture coordinates, wherein the distortion processing sequentially comprises water ripple distortion, annular ripple distortion and spiral distortion; acquiring a second distorted texture coordinate input by a user, and superposing the first distorted texture coordinate and the second distorted texture coordinate input by the user to obtain a final sampling coordinate; sampling the image texture through the final sampling coordinate, and outputting a sampling result to a temporary texture cache; and carrying out radial distortion processing on the sampling result in the temporary texture cache to obtain mixed and distorted image textures, and displaying the mixed and distorted image textures in a screen.
Optionally, the warping the texture coordinate corresponding to the image texture to obtain a first warped texture coordinate, further includes: and performing warping processing on the texture coordinates of the image texture according to the sorting sequence of the warping processing, and determining the image texture obtained by performing the warping processing currently as the image texture used in the next warping processing each time the warping processing is performed on the texture coordinates of the image texture.
Optionally, the warping includes a water wave warping effect, and the warping the texture coordinates corresponding to the image texture includes: performing water ripple distortion calculation on the initial texture coordinates of each pixel point in the image texture to obtain a first distortion vector subjected to water ripple distortion; and determining texture coordinates subjected to water ripple distortion based on the initial texture coordinates of each pixel point in the image texture and the first distortion vector.
Optionally, the obtaining a second warped texture coordinate input by a user, and superimposing the first warped texture coordinate and the second warped texture coordinate input by the user to obtain a final sampling coordinate includes: acquiring a second warped texture coordinate input by a user, wherein the second warped texture coordinate comprises component values of a red r channel and a green g channel; sampling the second distorted texture coordinate through the texture coordinate subjected to the ripple distortion to obtain a third distorted vector; and adding the initial texture coordinates of each pixel point in the image texture and the corresponding third distortion vector to obtain final sampling coordinates subjected to water ripple distortion.
Optionally, the performing a water ripple distortion calculation on the initial texture coordinate of each pixel point in the image texture includes:
performing water ripple distortion calculation on the initial texture coordinates of each pixel point in the image texture through a formula; the formula is:
the formula is:
WaveDistortion.x’=sin(DistanceToCenter-Time*5)*0.2
WaveDistortion.x=WaveDistortion.x’+sin(CurrentTexcoord.y-Time*5)*0.2WaveDistortion.y’=cos(DistanceToCenter-Time*5)*0.2
WaveDistortion.y=WaveDistortion.y’+cos(CurrentTexcoord.x-Time*5)*0.2
the method comprises the steps of obtaining a current texture coordinate of an image texture, obtaining a final offset component of the initial texture coordinate of any pixel point in the image texture in the horizontal direction, obtaining the final offset component of the initial texture coordinate of any pixel point in the image texture in the vertical direction, obtaining distance center, obtaining the distance between a current pixel point in the image texture and a central point, obtaining the initial texture coordinate of the current pixel point in the image texture, obtaining the final offset component of the initial texture coordinate of any pixel point in the image texture in the horizontal direction, obtaining the distance between the current pixel point in the image texture and the central point in the image texture, obtaining the initial texture coordinate of the current pixel point in the image texture in the current texture.
Optionally, the warping processing includes an annular ripple warping effect, and the warping processing on texture coordinates corresponding to the image texture includes: performing annular ripple distortion calculation on the initial texture coordinates of each pixel point in the image texture to obtain a fourth distortion vector subjected to annular ripple distortion; and determining texture coordinates subjected to annular ripple distortion based on the initial texture coordinates of each pixel point in the image texture and the fourth distortion vector.
Optionally, the obtaining a second warped texture coordinate input by a user, and superimposing the first warped texture coordinate and the second warped texture coordinate input by the user to obtain a final sampling coordinate includes: acquiring a fifth warped texture coordinate input by a user, wherein the fifth warped texture coordinate comprises component values of a red r channel and a green g channel; sampling the fifth distorted texture coordinate through the texture coordinate subjected to annular ripple distortion to obtain a sixth distorted vector; and adding the initial texture coordinates of each pixel point in the image texture and the corresponding sixth distortion vector to obtain final sampling coordinates subjected to annular ripple distortion.
Optionally, the performing annular ripple distortion calculation on the initial texture coordinate of each pixel point in the image texture includes:
performing annular ripple distortion calculation on the initial texture coordinate of each pixel point in the image texture through a formula; the formula is:
WaveDistortion.x=sin(DistanceToCenter-Time*5)*0.2WaveDistortion.y=sin(DistanceToCenter-Time*5)*0.2
the wavelet resolution.x is a final offset component of an initial texture coordinate of any pixel point in the image texture in the horizontal direction, the wavelet resolution.y is a final offset component of the initial texture coordinate of any pixel point in the image texture in the vertical direction, and the Time is a Time difference between a program starting Time and a Time of rendering the image texture. Optionally, the warping processing includes a spiral warping effect, and the warping processing on texture coordinates corresponding to the image texture includes: performing spiral distortion calculation on the initial texture coordinate of each pixel point in the image texture to obtain a seventh distortion vector subjected to spiral distortion; and determining the texture coordinate subjected to spiral distortion based on the initial texture coordinate of each pixel point in the image texture and the seventh distortion vector.
Optionally, the performing spiral warping calculation on the initial texture coordinate of each pixel point in the image texture includes:
performing spiral distortion calculation on the initial texture coordinate of each pixel point in the image texture through a formula; the formula is:
DeltaUV=CurrentTexcoord-DistortCenter
RotatedDistortion.x=cos(RotateAngle)*DeltaUV.x-sin(RotateAngle)*DeltaUV.y
RotatedDistortion.y=sin(RotateAngle)*DeltaUV.x-cos(RotateAngle)*DeltaUV.y
the image texture processing method comprises the steps that a current Texacoord is an initial texture coordinate of a current pixel point in the image texture, a DistortCenter is a disturbance center, DeltaUV comprises DeltaUV.x and DeltaUV.y, RotatedDistortion.x is a distortion value in the horizontal direction after spiral distortion, RotatedDistortion.y is a distortion value in the vertical direction after spiral distortion, and RotateAngle is a numerical value calculated based on the distance between the Current Texacoord and the DistortCenter.
Optionally, the performing radial warping on the sampling result in the temporary texture buffer includes: acquiring a radial sampling step length; starting from a texture coordinate corresponding to a current pixel point in the image texture, sampling a sampling result in the temporary texture cache for a target number of times, and adding the radial sampling step length to the texture coordinate corresponding to the current pixel point every sampling time until the texture coordinate corresponding to the current pixel point added with the radial sampling step length reaches a target coordinate; and accumulating the color values obtained by sampling each time, and dividing the accumulated values by the target times to obtain the image texture subjected to radial distortion.
Optionally, the obtaining a radial sampling step includes: obtaining a radial sampling step length through a formula; the formula is:
BlurVector=DistortCenter-CurrentTexcoord
DeltaSampling=BlurVector/BlurStepCount
the distorstcenter is a disturbance center, the currentTexcoord is an initial texture coordinate of a current pixel point in the image texture, the Blurvector is a direction vector between the distorstcenter and the currentTexcoord, BlurStepCount is the target frequency, and DeltaSampling is the radial sampling step length.
In a second aspect, an embodiment of the present invention provides a distortion effect generating apparatus, including: the acquisition module is used for acquiring image textures; the distortion module is used for performing distortion processing on texture coordinates corresponding to the image textures to obtain first distorted texture coordinates, and the distortion processing sequentially comprises water ripple distortion, annular ripple distortion and spiral distortion; the superposition module is used for acquiring a second distorted texture coordinate input by a user, and superposing the first distorted texture coordinate and the second distorted texture coordinate input by the user to obtain a final sampling coordinate; the sampling module is used for sampling the image texture through the final sampling coordinate and outputting a sampling result to a temporary texture cache; and the mixing module is used for carrying out radial distortion processing on the sampling result in the temporary texture cache to obtain an image texture after mixed distortion, and displaying the image texture after mixed distortion in a screen.
Optionally, the sampling module is further configured to: and performing warping processing on the texture coordinates of the image texture according to the sorting sequence of the warping processing, and determining the image texture obtained by performing the warping processing currently as the image texture used in the next warping processing each time the warping processing is performed on the texture coordinates of the image texture.
Optionally, the distortion process comprises a water ripple distortion effect, the distortion module to: performing water ripple distortion calculation on the initial texture coordinates of each pixel point in the image texture to obtain a first distortion vector subjected to water ripple distortion; and determining texture coordinates subjected to water ripple distortion based on the initial texture coordinates of each pixel point in the image texture and the first distortion vector.
Optionally, the superimposing module is configured to: acquiring a second warped texture coordinate input by a user, wherein the second warped texture coordinate comprises component values of a red r channel and a green g channel; sampling the second distorted texture coordinate through the texture coordinate subjected to the ripple distortion to obtain a third distorted vector; and adding the initial texture coordinates of each pixel point in the image texture and the corresponding third distortion vector to obtain final sampling coordinates subjected to water ripple distortion.
Optionally, the distortion module is configured to: performing water ripple distortion calculation on the initial texture coordinates of each pixel point in the image texture through a formula; the formula is:
WaveDistortion.x’=sin(DistanceToCenter-Time*5)*0.2
WaveDistortion.x=WaveDistortion.x’+sin(CurrentTexcoord.y-Time*5)*0.2
WaveDistortion.y’=cos(DistanceToCenter-Time*5)*0.2
WaveDistortion.y=WaveDistortion.y’+cos(CurrentTexcoord.x-Time*5)*0.2
the method comprises the steps of obtaining a current texture coordinate of an image texture, obtaining a final offset component of the initial texture coordinate of any pixel point in the image texture in the horizontal direction, obtaining the final offset component of the initial texture coordinate of any pixel point in the image texture in the vertical direction, obtaining distance center, obtaining the distance between a current pixel point in the image texture and a central point, obtaining the initial texture coordinate of the current pixel point in the image texture, obtaining the final offset component of the initial texture coordinate of any pixel point in the image texture in the horizontal direction, obtaining the distance between the current pixel point in the image texture and the central point in the image texture, obtaining the initial texture coordinate of the current pixel point in the image texture in the current texture.
Optionally, the distortion effect processing comprises an annular ripple distortion effect, the distortion module to: performing annular ripple distortion calculation on the initial texture coordinates of each pixel point in the image texture to obtain a fourth distortion vector subjected to annular ripple distortion; and determining texture coordinates subjected to annular ripple distortion based on the initial texture coordinates of each pixel point in the image texture and the fourth distortion vector.
Optionally, the superimposing module is configured to: acquiring a fifth warped texture coordinate input by a user, wherein the fifth warped texture coordinate comprises component values of a red r channel and a green g channel; sampling the fifth distorted texture coordinate through the texture coordinate subjected to annular ripple distortion to obtain a sixth distorted vector; and adding the initial texture coordinates of each pixel point in the image texture and the corresponding sixth distortion vector to obtain final sampling coordinates subjected to annular ripple distortion.
Optionally, the distortion module is configured to: performing annular ripple distortion calculation on the initial texture coordinate of each pixel point in the image texture through a formula; the formula is:
WaveDistortion.x=sin(DistanceToCenter-Time*5)*0.2
WaveDistortion.y=sin(DistanceToCenter-Time*5)*0.2
the wavelet distorsion.x is a final offset component of an initial texture coordinate of any pixel point in the image texture in the horizontal direction, the wavelet distorsion.y is a final offset component of an initial texture coordinate of any pixel point in the image texture in the vertical direction, the distance to center is a distance between a current pixel point in the image texture and a central point, and the Time is a Time difference between a program starting Time and a Time for rendering the image texture.
Optionally, the warping effect processing comprises a helical warping effect, the warping module to: performing spiral distortion calculation on the initial texture coordinate of each pixel point in the image texture to obtain a seventh distortion vector subjected to spiral distortion; and determining the texture coordinate subjected to spiral distortion based on the initial texture coordinate of each pixel point in the image texture and the seventh distortion vector.
Optionally, the distortion module is configured to: performing spiral distortion calculation on the initial texture coordinate of each pixel point in the image texture through a formula; the formula is:
DeltaUV=CurrentTexcoord-DistortCenter
RotatedDistortion.x=cos(RotateAngle)*DeltaUV.x-sin(RotateAngle)*DeltaUV.y
RotatedDistortion.y=sin(RotateAngle)*DeltaUV.x-cos(RotateAngle)*DeltaUV.y
the image texture processing method comprises the steps that a current Texacoord is an initial texture coordinate of a current pixel point in the image texture, a DistortCenter is a disturbance center, DeltaUV comprises DeltaUV.x and DeltaUV.y, RotatedDistortion.x is a distortion value in the horizontal direction after spiral distortion, RotatedDistortion.y is a distortion value in the vertical direction after spiral distortion, and RotateAngle is a numerical value calculated based on the distance between the Current Texacoord and the DistortCenter.
Optionally, the mixing module is configured to: acquiring a radial sampling step length;
starting from a texture coordinate corresponding to a current pixel point in the image texture, sampling a sampling result in the temporary texture cache for a target number of times, and adding the radial sampling step length to the texture coordinate corresponding to the current pixel point every sampling time until the texture coordinate corresponding to the current pixel point added with the radial sampling step length reaches a target coordinate; and accumulating the color values obtained by sampling each time, and dividing the accumulated values by the target times to obtain the image texture subjected to radial distortion.
Optionally, the mixing module is configured to: obtaining a radial sampling step length through a formula; the formula is:
BlurVector=DistortCenter-CurrentTexcoord
DeltaSampling=BlurVector/BlurStepCount
the distorstcenter is a disturbance center, the currentTexcoord is an initial texture coordinate of a current pixel point in the image texture, the Blurvector is a direction vector between the distorstcenter and the currentTexcoord, BlurStepCount is the target frequency, and DeltaSampling is the radial sampling step length.
In a third aspect, an embodiment of the present invention provides an electronic device, which includes a processor and a memory, where the memory stores executable code thereon, and when the executable code is executed by the processor, the processor is enabled to implement at least the warping effect generating method in the first aspect.
In a fourth aspect, an embodiment of the present invention provides a non-transitory machine-readable storage medium having stored thereon executable code, which when executed by a processor of an electronic device, causes the processor to implement at least the warping effect generating method of the first aspect.
The invention can freely combine various distortion algorithms, and can iteratively superpose distorted image textures output by different distortion algorithms so as to realize richer and more vivid distortion effects such as picture rotation, fluctuation and the like. By adopting the method and the device, the image quality of the distorted image texture can be improved.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The terminology used in the embodiments of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the examples of the present invention and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise, and "a plurality" typically includes at least two.
The words "if", or "as used herein may be interpreted as" on "," off ", or" when "," on "," off ", or" in response to a determination "or" in response to a detection ", depending on the context. Similarly, the phrases "if determined" or "if detected (a stated condition or event)" may be interpreted as "when determined" or "in response to a determination" or "when detected (a stated condition or event)" or "in response to a detection (a stated condition or event)", depending on the context.
In addition, the sequence of steps in each method embodiment described below is only an example and is not strictly limited.
Fig. 1 is a flowchart of a distortion effect generating method according to an embodiment of the present invention, as shown in fig. 1, the method includes the following steps:
101. and acquiring image textures.
102. And performing distortion processing on texture coordinates corresponding to the image textures to obtain first distorted texture coordinates, wherein the distortion processing sequentially comprises water ripple distortion, annular ripple distortion and spiral distortion.
103. And acquiring a second distorted texture coordinate input by the user, and superposing the first distorted texture coordinate and the second distorted texture coordinate input by the user to obtain a final sampling coordinate.
104. And sampling the image texture through the final sampling coordinate, and outputting a sampling result to a temporary texture cache.
105. And carrying out radial distortion processing on the sampling result in the temporary texture cache to obtain a mixed and distorted image texture, and displaying the mixed and distorted image texture in a screen.
In the embodiment of the invention, various warping algorithms are provided, and the various warping algorithms can be freely combined by adopting the method, so that richer and more vivid warping effects such as picture rotation, fluctuation and the like are realized. The method can be applied to the special effect processing process of the science fiction film, and can also be applied to various different distortion effect processing scenes such as the underwater visual angle effect processing process in games and the like.
In practical applications, an image texture may be obtained first, and the initial image texture is an image that has not been processed by any warping effect. If the image texture needs to be subjected to warping effect processing, any two or any multiple warping effects can be selected from multiple warping effects according to actual application requirements for iterative superposition, different warping effects are fused together, and finally, the mixed and warped image texture is output. Wherein the twisting effect may include a water wave twisting effect, a ring wave twisting effect, a spiral twisting effect, a radial twisting effect, a twisting effect of a user input.
It should be noted that, as shown in fig. 2, a respective enabling switch option may be set for each distortion effect, so that when a user selects an opening option corresponding to a certain distortion effect, the distortion effect may be added, and accordingly, when the user turns off the enabling switch option corresponding to the certain distortion effect, the distortion effect may be skipped without any processing. Optionally, the warping the texture coordinate corresponding to the image texture to obtain a first warped texture coordinate, further includes: and performing warping processing on the texture coordinates of the image texture according to the sorting sequence of the warping processing, and determining the image texture obtained by performing the warping processing currently as the image texture used in the next warping processing each time the warping processing is performed on the texture coordinates of the image texture.
In practical application, the texture coordinates of the image texture can be sequentially subjected to warping effect processing in combination with the sorting order of the warping processing. When the texture coordinates of the image texture are warped each time, the image texture output to the temporary texture buffer after the previous warping may be determined as the image texture subjected to the warping this time. For example, if the image texture needs to be subjected to the water ripple distortion effect and the annular ripple distortion effect, and the image texture subjected to the water ripple distortion is obtained after the water ripple distortion effect processing, the annular ripple distortion effect processing can be performed by using the image texture subjected to the water ripple distortion as a processing object in the process of performing the annular ripple distortion effect processing, so that the processing effect of continuous iterative superposition can be achieved. The process of performing the warping effect processing this time by using the image texture output to the temporary texture buffer after the previous warping will be described in detail later, and will not be described herein again.
Water wave distortion effect
Optionally, the warping effect processing includes a water ripple warping effect, and the process of warping the texture coordinates corresponding to the image texture may be implemented as: performing water ripple distortion calculation on initial texture coordinates of each pixel point in the image texture to obtain a first distortion vector subjected to water ripple distortion; and determining texture coordinates subjected to water ripple distortion based on the initial texture coordinates and the first distortion vector of each pixel point in the image texture.
In practical applications, the image texture may be a two-dimensional image, which is a result of performing rasterization processing after a triangular patch in a three-dimensional space is projected onto a two-dimensional plane. The image texture is composed of a plurality of pixel points, each pixel point corresponds to a respective initial texture coordinate, and a first distortion vector can be obtained by performing a series of water ripple distortion calculation on each initial texture coordinate. The first warping vector may also be referred to as an offset vector, that is, the corresponding initial texture coordinate may be shifted by the first warping vector to obtain a new texture coordinate, the new texture coordinate may be used to sample the color texture corresponding to the image texture, and the water-ripple-warped image texture may be output.
The above-mentioned process of performing the water ripple distortion calculation on the initial texture coordinate of each pixel point in the image texture can be realized by formula 1 to formula 4:
wave discrimination. x' ═ sin (distance to center-Time 5) × 0.2 (formula 1)
Wave discrimination.x ═ wave discrimination.x' + sin (currenttexcoord.y-Time 5) × 0.2 (formula 2)
Wave discrimination.y ═ cos (distance center-Time 5) × 0.2 (formula 3)
Wave discrimination.y ═ wave discrimination.y' + cos (currenttexcoord. x-Time 5) × 0.2 (formula 4)
The image texture processing method comprises the steps of obtaining an initial texture coordinate of any pixel point in an image texture, obtaining a final offset component of the initial texture coordinate of the any pixel point in the image texture in the horizontal direction, obtaining the final offset component of the initial texture coordinate of the any pixel point in the image texture in the vertical direction, obtaining distance center, the distance between a current pixel point in the image texture and a central point, obtaining the initial texture coordinate of the current pixel point in the image texture, obtaining the Time, the Time difference between the starting Time of a program and the rendering Time of the image texture, obtaining the distance.
Alternatively, if the user does not provide the texture of the warp vector during the water ripple warping process, the initial texture coordinates of each pixel in the texture of the image may be added to the corresponding first warp vector to obtain the coordinates of the texture subjected to the water ripple warping, that is, the coordinates of the texture subjected to the water ripple warping may be calculated by using wavedistorsion plus CurrentTexcoord. On the other hand, if the user provides the warp vector texture during the water ripple warping process, the warp vector texture may also be taken into account during the computation of the texture coordinates that have been water ripple warped.
Optionally, the obtaining of the second warped texture coordinate input by the user, and the superimposing the first warped texture coordinate and the second warped texture coordinate input by the user to obtain the final sampling coordinate may include: acquiring a second warped texture coordinate input by a user, wherein the second warped texture coordinate comprises component values of a red r channel and a green g channel; sampling the second distorted texture coordinate through the texture coordinate subjected to the ripple distortion to obtain a third distorted vector; and adding the initial texture coordinates of each pixel point in the image texture and the corresponding third distortion vector to obtain final sampling coordinates subjected to water ripple distortion.
It is understood that the warp vector texture may also be referred to as a second warp texture coordinate, and the warp vector texture is an image texture, which is different from a general image in that a unitized two-dimensional direction vector is stored in the warp vector texture, and includes two component values of x and y stored through two channels of r channel and g channel, respectively. The warp vector texture indicates the direction in which the texture coordinates need to be warped, and the wavedistorsion is added to the warp vector in the warp vector texture to obtain a third warp vector. After the third warp vector is obtained, the final sampling coordinates after the water ripple warping can be calculated by adding the corresponding third warp vector to the CurrentTexcoord.
Finally, the final sampling coordinate subjected to the water ripple distortion can be used for sampling the color texture corresponding to the image texture
And outputting the image texture subjected to water ripple distortion. The output moire warped image texture may be stored in a color buffer.
(II) annular ripple distortion effect
Optionally, the warping effect processing includes an annular ripple warping effect, and the process of warping the texture coordinates corresponding to the image texture may be implemented as: performing annular ripple distortion calculation on the initial texture coordinates of each pixel point in the image texture to obtain a fourth distortion vector subjected to annular ripple distortion; and determining texture coordinates subjected to annular ripple distortion based on the initial texture coordinates and the fourth distortion vector of each pixel point in the image texture.
In practical application, the image texture is composed of a plurality of pixel points, each pixel point corresponds to a respective initial texture coordinate, and a fourth distortion vector can be obtained by performing a series of annular ripple distortion calculations on each initial texture coordinate. The fourth warping vector may also be regarded as an offset vector, that is, a new texture coordinate may be obtained by shifting the corresponding initial texture coordinate by the fourth warping vector, and the new texture coordinate may be used to sample the water ripple warped image texture output by the previous warping process, so as to obtain the ring ripple warped image texture.
The above-mentioned process of performing annular ripple distortion calculation on the initial texture coordinates of each pixel point in the image texture can be realized by formulas 5 to 6: wave discrimination.x ═ sin (distance to center-Time 5) × 0.2 (equation 5) wave discrimination.y ═ sin (distance to center-Time 5) × 0.2 (equation 6)
The wavelet distorsion.x is a final offset component of an initial texture coordinate of any pixel point in the image texture in the horizontal direction, the wavelet distorsion.y is a final offset component of an initial texture coordinate of any pixel point in the image texture in the vertical direction, the distance to center is a distance between a current pixel point in the image texture and a central point, and the Time is a Time difference between a program starting Time and a Time for rendering the image texture.
Alternatively, if the user does not provide the distortion vector texture during the circular ripple warping process, the initial texture coordinates of each pixel point in the image texture may be added to the corresponding first distortion vector to obtain the circular ripple warped texture coordinates, that is, the circular ripple warped texture coordinates may be calculated by adding the initial texture coordinates to the corresponding first distortion vector. On the other hand, if the user provides the warp vector texture during the circular-ripple warping process, the warp vector texture may also be taken into account during the calculation of the texture coordinates that are warped by the circular ripple.
Optionally, the obtaining of the second warped texture coordinate input by the user, and the superimposing the first warped texture coordinate and the second warped texture coordinate input by the user to obtain the final sampling coordinate may include: acquiring a fifth warped texture coordinate input by a user, wherein the fifth warped texture coordinate comprises component values of an r channel and a g channel; sampling the fifth distorted texture coordinate through the distorted texture coordinate of the annular corrugation to obtain a sixth distorted vector; and adding the initial texture coordinates of each pixel point in the image texture and the corresponding sixth distortion vector to obtain the final sampling coordinates subjected to annular ripple distortion.
It should be noted that, because the processing procedure of the distortion effect input by the second user is similar to the processing procedure of the distortion effect input by the first user, the processing procedure of the distortion effect input by the second user may refer to the processing procedure of the distortion effect input by the first user, and the processing procedure of the distortion effect input by the second user is not described herein again.
(III) helical twisting Effect
Optionally, the warping effect processing includes a spiral warping effect, and the process of warping the texture coordinates corresponding to the image texture may be implemented as: performing spiral distortion calculation on the initial texture coordinate of each pixel point in the image texture to obtain a seventh distortion vector subjected to spiral distortion; and determining the texture coordinate subjected to spiral distortion based on the initial texture coordinate and the seventh distortion vector of each pixel point in the image texture.
In practical application, the image texture is composed of a plurality of pixel points, each pixel point corresponds to a respective initial texture coordinate, and a seventh distortion vector can be obtained by performing a series of spiral distortion calculations on each initial texture coordinate. The seventh warping vector may also be regarded as an offset vector, that is, a new texture coordinate may be obtained by shifting the corresponding initial texture coordinate by the seventh warping vector, and the new texture coordinate may be used to sample the annular ripple warped image texture output by the previous warping process, so as to obtain the image texture subjected to the spiral warping.
Optionally, the process of performing the spiral warping calculation on the initial texture coordinates of each pixel point in the image texture may be
This is achieved by equations 7 to 9:
DeltaUV ═ CurrentTexcooord-DistortCenter (equation 7)
Rotateddistorsion.x ═ cos (rotaangle) × uv.x-sin (rotaangle) × uv.y (equation 8)
Rotateddistorsion.y ═ sin (rotaangle) × uv.x-cos (rotaangle) × uv.y (formula 9)
The image texture processing method comprises the steps that a current Texacord is an initial texture coordinate of a current pixel point in an image texture, a C urrentTexacord is a two-dimensional vector, a Distortcenter is a disturbance center, a Distortcenter is a two-dimensional vector, DeltaUV comprises DeltaUV.x and DeltaUV.y, a rotadDistortion.x is a distortion value in the horizontal direction after spiral distortion, a rotadDistortion.y is a distortion value in the vertical direction after spiral distortion, and a rotaAngle is a numerical value calculated based on the distance between the current Texacord and the Distortcenter.
After the rotatedDistoretation is obtained, the helically warped texture coordinates can be calculated using CurrentTexcoord plus the corresponding rotatedDistoretation. Finally, the color texture corresponding to the image texture may be sampled using the texture coordinates subjected to the spiral warping, and the image texture subjected to the spiral warping may be output. The output spiral warped image texture may be stored in a color buffer.
(IV) radial twisting Effect
Optionally, the process of performing radial warping on the sampling result in the temporary texture buffer may be implemented as: acquiring a radial sampling step length; starting from texture coordinates corresponding to a current pixel point in an image texture, sampling a sampling result in the temporary texture cache for a target number of times, and adding a radial sampling step length to the texture coordinates corresponding to the current pixel point every sampling time until the texture coordinates corresponding to the current pixel point added with the radial sampling step length reach the target coordinates; and accumulating the color values obtained by sampling each time, and dividing the accumulated values by the target times to obtain the image texture subjected to radial distortion.
The radial sampling step length may be calculated by:
BlurVector (distertcenter-CurrentTexcoord (equation 10)
Deltasampling ═ BlurVector/BlurStepCoun (equation 11)
The distorstcenter is a disturbance center, the currentTexcoord is an initial texture coordinate of a current pixel point in the image texture, the currentTexcoord is a two-dimensional vector, the Blurvector is a direction vector between the distorstcenter and the currentTexcoord, the BlurStepCount is the target frequency, and a user can set the target frequency BlurStepCount, and DeltaSampling is the radial sampling step length.
The radial sampling step length can be calculated through formulas 10 to 11, and after the radial sampling step length is obtained, the sampling result in the temporary texture cache can be sampled for BlurStepCount times from the texture coordinate corresponding to the current pixel point in the image texture. In each sampling process, the texture coordinate corresponding to the current pixel point may be superimposed with the radial sampling step length until the distertcenter is reached. Sampling at every turn can all obtain a colour value, can add up the colour value that sampling at every turn obtained, and the colour value of every pixel point in the image texture through radial distortion is calculated with accumulated value division BlurStepCount finally.
Finally, after obtaining the hybrid warped image texture, the hybrid warped image texture may be displayed in a screen.
The invention can freely combine various distortion algorithms, and can iteratively superpose distorted image textures output by different distortion algorithms so as to realize richer and more vivid distortion effects such as picture rotation, fluctuation and the like. By adopting the method and the device, the image quality of the distorted image texture can be improved.
The twisting effect generating apparatus of one or more embodiments of the present invention will be described in detail below. Those skilled in the art will appreciate that these distortion effect generating means can be constructed by configuring the steps taught in the present embodiment using commercially available hardware components.
Fig. 3 is a schematic structural diagram of a twisting effect generating apparatus according to an embodiment of the present invention, as shown in fig. 3, the apparatus includes:
an obtaining module 31, configured to obtain an image texture;
a warping module 32, configured to perform warping processing on texture coordinates corresponding to the image texture to obtain a first warped texture coordinate, where the warping processing sequentially includes water ripple warping, annular ripple warping, and spiral warping;
the superposition module 33 is configured to obtain a second warped texture coordinate input by the user, and superpose the first warped texture coordinate and the second warped texture coordinate input by the user to obtain a final sampling coordinate;
the sampling module 34 is configured to sample the image texture through the final sampling coordinate, and output a sampling result to a temporary texture cache;
and a mixing module 35, configured to perform radial warping on the sampling result in the temporary texture cache to obtain a mixed warped image texture, and display the mixed warped image texture in a screen.
Optionally, the sampling module 34 is further configured to: and performing warping processing on the texture coordinates of the image texture according to the sorting sequence of the warping processing, and determining the image texture obtained by performing the warping processing currently as the image texture used in the next warping processing each time the warping processing is performed on the texture coordinates of the image texture.
Optionally, the distortion process comprises a water wave distortion effect, the distortion module 32 being configured to: performing water ripple distortion calculation on the initial texture coordinates of each pixel point in the image texture to obtain a first distortion vector subjected to water ripple distortion; and determining texture coordinates subjected to water ripple distortion based on the initial texture coordinates of each pixel point in the image texture and the first distortion vector.
Optionally, the superimposing module 33 is configured to: acquiring a second warped texture coordinate input by a user, wherein the second warped texture coordinate comprises component values of a red r channel and a green g channel; sampling the second distorted texture coordinate through the texture coordinate subjected to the ripple distortion to obtain a third distorted vector; and adding the initial texture coordinates of each pixel point in the image texture and the corresponding third distortion vector to obtain final sampling coordinates subjected to water ripple distortion.
Optionally, the distortion module 32 is configured to: performing water ripple distortion calculation on the initial texture coordinates of each pixel point in the image texture through a formula; the formula is:
WaveDistortion.x’=sin(DistanceToCenter-Time*5)*0.2
WaveDistortion.x=WaveDistortion.x’+sin(CurrentTexcoord.y-Time*5)*0.2WaveDistortion.y’=cos(DistanceToCenter-Time*5)*0.2
WaveDistortion.y=WaveDistortion.y’+cos(CurrentTexcoord.x-Time*5)*0.2
the method comprises the steps of obtaining a current texture coordinate of an image texture, obtaining a final offset component of the initial texture coordinate of any pixel point in the image texture in the horizontal direction, obtaining the final offset component of the initial texture coordinate of any pixel point in the image texture in the vertical direction, obtaining distance center, obtaining the distance between a current pixel point in the image texture and a central point, obtaining the initial texture coordinate of the current pixel point in the image texture, obtaining the final offset component of the initial texture coordinate of any pixel point in the image texture in the horizontal direction, obtaining the distance between the current pixel point in the image texture and the central point in the image texture, obtaining the initial texture coordinate of the current pixel point in the image texture in the current texture.
Optionally, the distortion effect processing comprises an annular ripple distortion effect, the distortion module 32 is configured to: performing annular ripple distortion calculation on the initial texture coordinates of each pixel point in the image texture to obtain a fourth distortion vector subjected to annular ripple distortion; and determining texture coordinates subjected to annular ripple distortion based on the initial texture coordinates of each pixel point in the image texture and the fourth distortion vector.
Optionally, the superimposing module 33 is configured to: acquiring a fifth warped texture coordinate input by a user, wherein the fifth warped texture coordinate comprises component values of a red r channel and a green g channel; sampling the fifth distorted texture coordinate through the texture coordinate subjected to annular ripple distortion to obtain a sixth distorted vector; and adding the initial texture coordinates of each pixel point in the image texture and the corresponding sixth distortion vector to obtain final sampling coordinates subjected to annular ripple distortion.
Optionally, the distortion module 32 is configured to: performing annular ripple distortion calculation on the initial texture coordinate of each pixel point in the image texture through a formula; the formula is:
WaveDistortion.x=sin(DistanceToCenter-Time*5)*0.2WaveDistortion.y=sin(DistanceToCenter-Time*5)*0.2
the wavelet distorsion.x is a final offset component of an initial texture coordinate of any pixel point in the image texture in the horizontal direction, the wavelet distorsion.y is a final offset component of an initial texture coordinate of any pixel point in the image texture in the vertical direction, the distance to center is a distance between a current pixel point in the image texture and a central point, and the Time is a Time difference between a program starting Time and a Time for rendering the image texture.
Optionally, the warping effect processing comprises a helical warping effect, the warping module 32 is configured to: performing spiral distortion calculation on the initial texture coordinate of each pixel point in the image texture to obtain a seventh distortion vector subjected to spiral distortion; and determining the texture coordinate subjected to spiral distortion based on the initial texture coordinate of each pixel point in the image texture and the seventh distortion vector.
Optionally, the distortion module 32 is configured to: performing spiral distortion calculation on the initial texture coordinate of each pixel point in the image texture through a formula;
the formula is:
DeltaUV=CurrentTexcoord-DistortCenter
RotatedDistortion.x=cos(RotateAngle)*DeltaUV.x-sin(RotateAngle)*DeltaUV.y
RotatedDistortion.y=sin(RotateAngle)*DeltaUV.x-cos(RotateAngle)*DeltaUV.y
the image texture processing method comprises the steps that a current Texacoord is an initial texture coordinate of a current pixel point in the image texture, a DistortCenter is a disturbance center, DeltaUV comprises DeltaUV.x and DeltaUV.y, RotatedDistortion.x is a distortion value in the horizontal direction after spiral distortion, RotatedDistortion.y is a distortion value in the vertical direction after spiral distortion, and RotateAngle is a numerical value calculated based on the distance between the Current Texacoord and the DistortCenter.
Optionally, the mixing module 35 is configured to: acquiring a radial sampling step length;
starting from a texture coordinate corresponding to a current pixel point in the image texture, sampling the image subjected to spiral distortion for a target number of times, and adding the radial sampling step length to the texture coordinate corresponding to the current pixel point every sampling time until the texture coordinate corresponding to the current pixel point added with the radial sampling step length reaches a target coordinate; and accumulating the color values obtained by sampling each time, and dividing the accumulated values by the target times to obtain the image texture subjected to radial distortion.
Optionally, the mixing module 35 is configured to: obtaining a radial sampling step length through a formula; the formula is:
BlurVector=DistortCenter-CurrentTexcoord
DeltaSampling=BlurVector/BlurStepCount
the distorstcenter is a disturbance center, the currentTexcoord is an initial texture coordinate of a current pixel point in the image texture, the Blurvector is a direction vector between the distorstcenter and the currentTexcoord, BlurStepCount is the target frequency, and DeltaSampling is the radial sampling step length.
The apparatus shown in fig. 3 may perform the warping effect generating method provided in the embodiments shown in fig. 1 to fig. 2, and the detailed performing process and technical effect refer to the description in the embodiments, which is not described herein again.
In one possible design, the structure of the twisting effect generating apparatus shown in fig. 3 may be implemented as an electronic device, as shown in fig. 4, which may include: aprocessor 91, and amemory 92. Wherein thememory 92 has stored thereon executable code, which when executed by theprocessor 91, causes theprocessor 91 to at least implement the warping effect generating method as provided in the foregoing embodiments shown in fig. 1 to 2.
Optionally, the electronic device may further include acommunication interface 93 for communicating with other devices.
In addition, an embodiment of the present invention provides a non-transitory machine-readable storage medium, on which executable code is stored, and when the executable code is executed by a processor of an electronic device, the processor is enabled to implement at least the warping effect generating method provided in the foregoing embodiments shown in fig. 1 to 2.
The above-described apparatus embodiments are merely illustrative, wherein the units described as separate components may or may not be physically separate. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by adding a necessary general hardware platform, and of course, can also be implemented by a combination of hardware and software. With this understanding in mind, the above-described aspects and portions of the present technology which contribute substantially or in part to the prior art may be embodied in the form of a computer program product, which may be embodied on one or more computer-usable storage media having computer-usable program code embodied therein, including without limitation disk storage, CD-ROM, optical storage, and the like.
The distortion effect generating method provided by the embodiment of the present invention may be executed by a certain program/software, the program/software may be provided by a network side, the electronic device mentioned in the foregoing embodiment may download the program/software into a local non-volatile storage medium, and when it needs to execute the distortion effect generating method, the program/software is read into a memory by a CPU, and then the program/software is executed by the CPU to implement the distortion effect generating method provided in the foregoing embodiment, and the execution process may refer to the schematic in fig. 1 to fig. 2.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.