m_DepthTexture is [-1,1] or [0,1]?

I read this page to lean linearizeDepth.

Now I use

float linearizeDepth(float zBuffer)
{
float zn = 2*zBuffer-1.0;
float linear = (2.0 * zNear) / (zFar + zNear - zn * (zFar - zNear));
return linear;
}

void main(){
vec4 depthColor = texture2D(m_DepthTexture,texCoord);
float startDepth = linearizeDepth(depthColor.x);
}

Am I right?

1 Like

I read DepthOfField.frag

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);

May I use this?

Of course. That’s one of the reasons it’s there.

1 Like

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);

vec3 normalVector = normalize(normal.xyz-0.5);

float startDepth = depthColor.x;

vec3 startVector = normalize(vec3((texCoord-0.5),startDepth));
vec3 reflectVector = reflect(startVector, normalVector);

vec4 reflectedColor = raytrace(reflectVector, getDepth(startDepth));	
if(startDepth>=zFar){
	gl_FragColor=color;
}else{
	gl_FragColor=mix(color,reflectedColor,0.3);
}

}
but it seems something wrong.
This is result: