summaryrefslogtreecommitdiff
path: root/source/lessons/stencil_testing/shaders/depth_test.fs.glsl
blob: 796d8494c72b228916d8ead49128ade5fcc49462 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#version 330 core


in vec2 TexCoords;
in vec3 VertexWorldPos;
uniform sampler2D TexId;
out vec4 FragColor;

uniform float near = 0.1f;
uniform float far = 100.0f;

/* @note
float linear_fragment_depth = MakeDepthLinear(non_linear_fragment_depth);
float scaled_lfd = linear_fragment_depth/far;

gives us the z value in eye space.
This is purely for learning purposes.
The equation used in MakeDepthLinear is derived from the PerspectiveProjectionMatrix.
Take a look at the equation for that in the codebase 
or here: https://www.songho.ca/opengl/gl_projectionmatrix.html
*/
float MakeDepthLinear(float depth) {
  float ndc = 2.0f*depth - 1;
  float linear_depth = (2.0 * far * near)/(far + near - ndc*(far - near));
  return linear_depth;
}

void main() {
    FragColor = texture(TexId, TexCoords);
}