Graphics Reference
In-Depth Information
{
float mag = 1.+uPeristaltic*(1.+cos(PI*(t-timer)/
HALFWIDTH) )/2.;
vertex.yz *= vec2(mag,mag);
}
float x = R*cos( TWOPI*uN*t );
float y = R*sin( TWOPI*uN*t );
float z = uK * t;
float xd = -R*TWOPI*uN*sin( TWOPI*uN*t );
float yd = R*TWOPI*uN*cos( TWOPI*uN*t );
float zd = uK;
float xdd = -( TWOPI*TWOPI*uN*uN ) * x;
float ydd = -( TWOPI*TWOPI*uN*uN ) * y;
float zdd = 0.;
vec3 T = normalize( vec3(xd,yd,zd) );
vec3 B = normalize( cross( vec3(xd,yd,zd),
vec3(xdd,ydd,zdd) ) );
vec3 N = normalize( cross(B,T) );
vec3 xyz = vec3( 0., vertex.y, vertex.z );
float xp = dot( vec3(T.x,N.x,B.x), xyz );
float yp = dot( vec3(T.y,N.y,B.y), xyz );
float zp = dot( vec3(T.z,N.z,B.z), xyz );
vec3 newposition = vec3( x+xp, y+yp, z+zp );
vec3 tpos = vec3( uModelViewMatrix *
vec4( newposition, 1. ) );
float nxp = dot( T, aNormal );
float nyp = dot( N, aNormal );
float nzp = dot( B, aNormal );
vec3 newnormal = vec3(nxp,nyp,nzp);
vec3 tnorm = normalize( uNormalMatrix * newnormal );
vLightIntensity = dot( normalize(LIGHTPOS - tpos), tnorm );
vLightIntensity = abs( vLightIntensity );
gl_Position = uModelViewProjectionMatrix *
vec4(newposition, 1.);
}
This vertex shader and a very standard fragment shader give you the warped
arrow object shown in Figure 15.34.
Search WWH ::




Custom Search