// Viewer position
uniform vec3 viewer;
// Depth vertex color
varying vec4 vVertexColor; // Black/near --> White/far
// Text coord
varying vec2 vTexCoords;
attribute vec2 texCoords0;
const float MAX_DISTANCE = 1000.0;
void main( void )
{
// Calculate world space position
vec4 pos = calcWorldPos( gl_Vertex );
// Calculate view space position
vec4 vsPos = calcViewPos( pos );
// Calculate Depth
float distance = -vsPos.z / MAX_DISTANCE;//length(pos.xyz - viewer) / MAX_DISTANCE;
// Colorize the vertex with the distance
vVertexColor = vec4(distance);
gl_Position = gl_ModelViewProjectionMatrix * pos;
}