From 20999a1b68a515d7bd5602d0745a0bc9885ba964 Mon Sep 17 00:00:00 2001 From: Joey de Vries Date: Wed, 12 Aug 2015 10:07:53 +0200 Subject: [PATCH] Update to depth testing article Instead of directly dividing by far in the LinearizeDepth function, divide by far in the main() function to make it explicitly clear the LinearizeDepth value returns the depth value up to far. --- .../1.depth_testing/depth_testing.frag | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/4.advanced_opengl/1.depth_testing/depth_testing.frag b/src/4.advanced_opengl/1.depth_testing/depth_testing.frag index 5f3992f..06169f4 100644 --- a/src/4.advanced_opengl/1.depth_testing/depth_testing.frag +++ b/src/4.advanced_opengl/1.depth_testing/depth_testing.frag @@ -1,16 +1,16 @@ #version 330 core out vec4 color; -float LinearizeDepth(float depth) // Note that this ranges from [0,1] instead of up to 'far plane distance' since we divide by 'far' +float near = 1.0; +float far = 100.0; +float LinearizeDepth(float depth) { - float near = 0.1; - float far = 100.0; float z = depth * 2.0 - 1.0; // Back to NDC - return (2.0 * near) / (far + near - z * (far - near)); + return (2.0 * near * far) / (far + near - z * (far - near)); } void main() { - float depth = LinearizeDepth(gl_FragCoord.z); + float depth = LinearizeDepth(gl_FragCoord.z) / far; // divide by far to get depth in range [0,1] for visualization purposes. color = vec4(vec3(depth), 1.0f); } \ No newline at end of file