Graphics Reference
In-Depth Information
int mmax = int( ceil( delta / LAMBDAMIN ) );
fFragColor = GRAY;
if( mmin > 0 )
{
vec3 color = vec3( 0., 0., 0. );
int count = 0;
for( int m = mmin; m <= mmax; m++ )
{
float lambda = delta / float(m);
vec3 col;
int status = AssignRGB( lambda, col );
if( status > 0 )
{
color += col;
count++;
}
}
if( count > 0 )
fFragColor = vec4( color / float(count), 1. );
}
}
Two vectors are created in this
fragment shader. One vector goes from
the fragment toward the light position
(which is specified externally on sliders
when this is used with glman ), and one
goes toward the eye position (which
is at (0., 0., 0.)). Each of these is doted
with vTransfTangent , the tangent vec-
tor to the groove, which is parallel to the
grooves at this fragment and acts like the
“light channel” there.
These dot products tell us how
much of each of these vectors lies in the
direction of the transformed tangent.
Because of the direction of these three vectors, one of the dot products will be
positive and one will be negative. Because our equation calls for a subtraction
and an absolute value,
Since the dot product distributes
over vector addition, the first line of
code could have been simplified as
float sum = dot(
ToLight+ToEye,
TransfTangent );
We didn't do that here, because this
construct looks confusingly like
the “halfway vector” often used in
the specular lighting equation. It's
not. Remember this distinction, so
you are not tempted to add them
together and normalize the result.
(
)
=∗ −
d
cos
Φ
cos
Φ
,
i
r
Search WWH ::




Custom Search