<vertex>
uniform mat4 matTexture;
varying float depthDistance;

void main(void) {
	gl_Position = ftransform();

	vec4 pointEye = gl_ModelViewMatrix * gl_Vertex;

	vec4 pointTexture = matTexture * pointEye;
	vec4 planeTexture = matTexture * vec4(pointEye.xy, 0.0, pointEye.w);

	gl_ClipVertex = pointEye;
	gl_TexCoord[0] = pointTexture;

	depthDistance = distance(planeTexture, pointTexture);
}
</vertex>

<fragment>

varying float depthDistance;
uniform float depthDivisor;
void main(void) {
  gl_FragColor.rgb = gl_TexCoord[0].xyz;
  //Why does it crash when setting it to depthDistance only!?
  gl_FragDepth = depthDistance /depthDivisor;
}
</fragment>