float zBuffer = texture2D( m_DepthTexture, texCoord ).r;
//
// z_buffer_value = a + b / z;
//
// Where:
// a = zFar / ( zFar - zNear )
// b = zFar * zNear / ( zNear - zFar )
// z = distance from the eye to the object
//
// Which means:
// zb - a = b / z;
// z * (zb - a) = b
// z = b / (zb - a)
//
float a = m_NearFar.y / (m_NearFar.y - m_NearFar.x);
float b = m_NearFar.y * m_NearFar.x / (m_NearFar.x - m_NearFar.y);
float z = b / (zBuffer - a);
I’m working on screen space reflection. And how to calculate reflect vector in view?
I use :
void main(){
vec4 color = texture2D(m_Texture,texCoord);
vec4 normal = texture2D(m_Normal,texCoord);
vec4 depthColor = texture2D(m_DepthTexture,texCoord);