I am trying to calculate depth relative to the object.
Here is a good solution to retrieve depth relative to camera : Depth as distance to camera plane in GLSL
varying float distToCamera;
void main()
{
vec4 cs_position = glModelViewMatrix * gl_Vertex;
distToCamera = -cs_position.z;
gl_Position = gl_ProjectionMatrix * cs_position;
}
With this example the depth is relative to the camera.
But I would like get the depth relative to the object. I would like the same depth and value if I am near from the object or if I am far.
Here is an example of what I am trying to achieve. On the left you can see that the depth is relative to the camera. And on the right even if the camera moves back from the object, the depth remains the same because it is dependant to the object.