Graphics Reference
In-Depth Information
vec3 BP = vECpos - BALLPOS;
float angle = radians(Timer*360.);
float c = cos( angle );
float s = sin( angle );
vec3 bp;
bp.x = c*BP.x + s*BP.z;
bp.y = BP.y;
bp.z = -s*BP.x + c*BP.z;
vec3 BL = LIGHTPOS - BALLPOS;
vec3 H = normalize( normalize(BL) + normalize(bp) );
float x = H.x;
float y = H.y;
float z = H.z;
float xz = length( H.xz ); // = sqrt( x^2 + z^2 );
float phi = atan( y, xz );
float theta = atan( z, x );
int itheta = int( floor( ( theta + dtheta/2. ) / dtheta ) );
int iphi = int( floor( ( phi + dphi/2. ) / dphi ) );
float theta0 = dtheta * float(itheta);
float phi0 = dphi * float(iphi);
vec3 N0;
N0.y = sin(phi0);
xz = cos(phi0);
N0.x = xz*cos(theta0);
N0.z = xz*sin(theta0);
float d = max( dot( N0, H ), 0. );
if( d < DMIN )
d = 0.;
d = pow( d, 5000. ); // much quicker drop-off
fFragColor = vec4( vColor.rgb * vLightIntensity +
d * LIGHTCOLOR, vColor.a ) ;
}
Figure 16.24 (left) shows how this would look if a group of GLUT solids
were on the dance floor together. Of course, lighting equations can apply to
the inside of objects just as well as the outside, if you want them to (as you usu-
ally do). Figure 16.24 (right) shows the inside of the teapot. If the SIGGRAPH
conference ever creates a nightclub venue, we have no doubt it will look like
this!
Search WWH ::




Custom Search