Graphics Reference
In-Depth Information
attribute vec3 aTangent; // from glman Sphere primitive
// points towards north pole
uniform float uLightX, uLightY, uLightZ; // from sliders
out vec3 vBTNx, vBTNy, vBTNz;
out vec3 vLightDir; // light direction in TNB coords
out vec2 vST;
// N is the direction of the surface normal
// T is the direction of “Tangent”, which is (dx/dt, dy/dt,
// dz/dt)
// B is the TxN, which is the direction of (dx/ds, dy/ds, dz/ds)
void main( )
{
vST = aTexCoord0.st;
// B-T-N form an X-Y-Z-looking right handed coordinate system:
vec3 N = normalize( uNormalMatrix * aNormal );
vec2 T = normalize( vec3( uModelViewMatrix*vec4(aTangent,0.)
) );
vec3 B = normalize( cross(T, N) );
// the light direction, in eye coordinates:
vec3 lightPosition = vec3( uLightX, uLightY, uLightZ );
vec3 ECpos = ( uModelViewMatrix * aVertex ).xyz;
vLightDir = normalize( lightPosition - ECpos );
// Produce the transformation from Surface coords to
// Eye coords:
vBTNx = vec3( B.x, T.x, N.x );
vBTNy = vec3( B.y, T.y, N.y );
vBTNz = vec3( B.z, T.z, N.z );
gl_Position = uModelViewProjectionMatrix * aVertex;
}
The fragment shader is shown below. This uses several uniform glman
slider variables to experiment with the surface appearance. The primary func-
tion of the shader code is to take the value of the variable vLightDir and
develop the normal based on the normal that's developed by pixel position
to create the appearance of the pyramids. The angle uAng is used to rotate the
pyramids in place.
Search WWH ::




Custom Search