mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-30 20:13:22 +08:00
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.
This commit is contained in:
@@ -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 = 0.1;
|
||||
float near = 1.0;
|
||||
float far = 100.0;
|
||||
float LinearizeDepth(float depth)
|
||||
{
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user