Graphics Reference
In-Depth Information
ing flight path. So, now vDirSTP is how much s , t , and p will change with each
casting step in the fragment shader's flight path.
const float SQRT3 = 1.73205; // longest path through a volume
// that is 1x1x1 in texture coords
uniform int uNumSteps; // # of steps to take through the
// volume
out vec3 vSTP0; // starting location in texture coords
out vec3 vDirSTP; // tracing step in texture coords
void main( )
{
vSTP0 = (aVertex.xyz + 1.)/2.; // Convert [-1.,+1.]->[0.,1.]
// leave the STP alone, rotate the position forward,
// rotate the Dir backward
vec3 stpvec; // the vector to take through the volume
// in texture coords
if( <<we're using orthographic projection >> )
stpvec = vec3( 0., 0., -1. ); // all point in the
// same direction
if( <<we're using perspective projection >> )
{ vec4 vxyz = uModelViewMatrix * aVertex;
// where this vertex is in eye space
vec3 vstp = ( vxyz.xyz + 1. ) / 2.;
// where the vertex is in texture coords
vec3 eye = ( vec3(0.,0.,0.) + 1. ) / 2.;
// where the eye is in texture coords
stpvec = vstp - eye;
// in perspective, the direction is a vector from
// the eye to the vertex
}
vDirSTP = normalize( (uModelViewMatrixInverse *
vec4(stpvec, 0.) );
vDirSTP *= SQRT3;
vDirSTP /= float(uNumSteps);
gl_Position = uModelViewProjectionMatrix * aVertex;
}
Search WWH ::




Custom Search