Graphics Reference
In-Depth Information
Following the same patern as before, we see that the normal vector, n , is
π
π
x
2
2 201
n
=−∗∗ −
a
sin
π
t
,
., ..
P
P
d
d
This is true along just the X axis. Because the ripples are propagating out
in a circular patern, we need to rotate the normal vector into where it really is.
Because we are just talking about a rotation, the transformation is the same as
if we were rotating a vertex. Noting that the unrotated N y is equal to 0., we get
=∗ −∗ =∗
=∗ +∗ =∗
=
Nx
Nx
cos
Θ
Ny
sin
Θ
Nx
cos
Θ
Ny
Nx
sin
Θ
Ny
cos
Θ
Nx
sin
Θ
Nz
Nz =1.
As we said at the beginning, so far we have been working in 2D, not 3D;
for the final version of the fragment shader in the ripples case above, you need
to think in polar coordinates, so you need to substitute R , the polar coordinate
radius, for x in the slope equation.
uniform float uTime;
uniform float uAmp0, uAmp1;
uniform float uPhaseShift;
uniform float uPd;
uniform float uLightX, uLightY, uLightZ;
uniform vec4 uColor;
in vec3 vMCposition;
in vec3 vECposition;
out vec4 fFragColor;
const float TWOPI = 2.*3.14159265;
void main( )
{
const vec3 C0 = vec3( -2.5, 0., 0. );
const vec3 C1 = vec3( 2.5, 0., 0. );
// first set of ripples:
float rad0 = length( vMCposition - C0 ); // ripple center 0
float H0 = -uAmp0 * cos( TWOPI*rad0/uPd - TWOPI*uTime );
float u = -uAmp0 * (TWOPI/uPd) * sin(TWOPI*rad0/uPd -
TWOPI*uTime);
Search WWH ::




Custom Search