Unity Shader:waveform Waveform (3)-composite wave

Source: Internet
Author: User
Tags cos sin
1,2d Composite Wave


(Above: There are three waves in the XY plane, y=sinx,y=sin2x,y=sin3x. )
These three waves can be combined into a composite waveform, according to the superposition principle (superposition principle), the composite wave is the result of the addition of three waveforms:
Y=sinx+sin2x+sin3x.
2,3d composite Wave using direction vectors to change the direction of a plane waveform in 3D space

Set any bit of p, direction vector float2 (1,0).
P.xy=dot (FLOAT2 (1,0), P.xy)
Then ask for its sine function:

(pictured above, left-handed coordinate system.) Z=sin (Dot (float2 (1,0), p.xy))
If you change the direction vector to 0, 1. P.xy=dot (FLOAT2 (0,1), p.xy)

(pictured above, left-handed coordinate system.) Z=sin (dot (float2 (0,1), p.xy))
If you change the direction vector to (). P.xy=dot (Float2 (), P.xy)

(pictured above, left-handed coordinate system.) Z=sin (dot (float2), P.xy)
The above indicates that each point of a plane in 3D space is multiplied by a direction vector, so the direction of the waveform computed by these points is consistent with the direction of the vector. It is possible to interpret the point multiplication as a set that assigns the direction and intensity of the direction vector to a point. synthesis of medium wave in 3D space

In 3D space, the superposition principle still applies:

(Above, left-hand coordinate system, Z=sin (y) +sin (x) +sin (x+y)) 3, applying composite waves to the complex system to test the above waveform

The following is the effect of shader the pixel position and normal in the fragment shader with a variant of the sine function, with pixel-level illumination.


The above 1,0 wave is applied to this system.

1,0 wave and 0,1 wave synthesis.

(1,0), (0,1), and (a) wave synthesis. Round Wave

The idea is the same as above, except that the direction of the wave is no longer constant, the center of the wave is computed in the shader, and all vertices are calculated according to the center of the wave.

(Above: a circular wave)

(Above: Two round wave synthesis with different frequencies)

(Above: Four round wave synthesis with different frequencies)

(Above: Four round wave synthesis with different frequencies.) The wave Center can be seen more clearly, depending on the distance from the center of the wave to attenuate the wave's intensity.

With this combination of waveforms coupled with specific algorithms, some complex simulations can be performed in 3D space. waves and Ripples

In the Water4 water simulation shader in Unity standard assets, there is a piece of code about Gerstner wave that uses the composite wave:

 Half3 gerstneroffset4_official (half2 xzvtx, half4 steepness, Half4 amp, Half4 freq,  

                Half4 speed, Half4 dirab, Half4 dircd) {half3 offsets;  
                Half4 AB = steepness.xxyy * AMP.XXYY * DIRAB.XYZW;  

                Half4 CD = steepness.zzww * AMP.ZZWW * DIRCD.XYZW;   
                Half4 DOTABCD = freq.xyzw * HALF4 (dot (dirab.xy, xzvtx), Dot (dirab.zw, xzvtx), Dot (Dircd.xy, xzvtx), Dot (dircd.zw, xzvtx));  

                Half4 time = _time.yyyy * speed;  
                Half4 cos = cos (DOTABCD + time);  

                Half4 sin = sin (dotabcd + time);  
                Offsets.x =dot (COS, Half4 (AB.XZ, cd.xz));  
                Offsets.z =dot (COS, Half4 (Ab.yw, cd.yw));  

                Offsets.y = dot (SIN, AMP);           
            return offsets; }  

The dirab.xy,dirab.zw,dircd,xy,dircd.zw is a directional vector (x, y) of four waves. XZVTX holds the x,z coordinate point of world space. In this way, each point of the XZ plane in world space and 4 direction vectors are calculated with the height offset.y, and the superposition of four waves is completed. The amp,freq,speed and other variables are used to control the shape of the waveform (visible in the previous article).

In addition to calculating the height y value, the above method also makes a displacement calculation of the XZ coordinates according to the Gerstner wave formula, forming a more complex waveform. This waveform, both Gerstner wave, the characteristics of both peaks are more sharp, XZ coordinates gradually toward the crest, and the real ocean waves more similar.

Original formula: (Jerry Tessendorf 2004)
x = x0− (k/k) A sin (k x0−ωt)
y = A cos (k x0−ωt)
(The original formula has not yet been found, yet it does not understand how to correctly understand the XY coordinate system above.) )

In the first chapter of the GPU Gems1 (Equation 9), Nvidia has the ability to expand it into a function that can be computed in 3D space, which is basically consistent with the algorithm. (The method and source from which the function is converted from the original source is not yet understood.)


(Above: vertex displacement and illumination based on Gerstner wave to a planar mesh)


(pictured above: Water4 's ocean.) Waves are calculated from Gerstner wave)
The actual effect also has a considerable dependence on the parameters given by the 4 waveforms.

Use circular Polly for refraction effects:

(Scene original)

(One wave)

(One wave)

(Two waves)

(Two waves, the plane vertex does not change, but the three-dimensional sense is still strong)

————————————————————————————
Reference:
Shader fx/water4-unity
GPU gems1-nvidia
-https://developer.nvid ia.com/gpugems/gpugems/gpugems_app01.html
Simulating Ocean water-jerry Tessendorf
-http:// www-evasion.imag.fr/membres/fabrice.neyret/naturalscenes/fluids/water/waves/fluids-nuages/waves/jonathan/ Articlescg/simulating-ocean-water-01.pdf
Maintenance log:
2017-11-19: Change a clerical error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.