Graphics Reference
In-Depth Information
void
main( )
{
vECposition = ( uModelViewMatrix * aVertex ).xyz;
vTransfTangent = uNormalMatrix * vec3( -aVertex.y,
aVertex.x, 0. );
vTransfTangent = normalize( vTransfTangent ) ;
gl_Position = uModelViewProjectionMatrix * aVertex;
}
The fragment shader for the CD/DVD simulation is shown here:
uniform float uLightX, uLightY, uLightZ; // from a slider
uniform float uD; // from a slider
in vec3 vECposition;
in vec3 vTransfTangent;
out vec4 fFragColor;
const float LAMBDAMIN = 400.; // blue
const float LAMBDAMAX = 600.; // red
const vec4 GRAY = vec4( .2, .2, .2, 1. );
int
AssignRGB( in float lambda, out vec3 color )
{
if( lambda < LAMBDAMIN || lambda > LAMBDAMAX )
return 0;
float t = ( lambda - LAMBDAMIN ) / ( LAMBDAMAX - LAMBDAMIN );
color = Rainbow( t );
return 1;
}
void main( )
{
vec3 ToLight = normalize(vec3(uLightX,uLightY,uLightZ)
-vECposition);
vec3 ToEye = normalize(vec3(0.,0.,0.)
-vECposition);
float sum = dot(ToLight,vTransfTangent)
+dot(ToEye,vTransfTangent);
float delta = uD * abs( sum );
int mmin = int( floor( delta / LAMBDAMAX ) );
Search WWH ::




Custom Search