summaryrefslogtreecommitdiff
path: root/advanced_opengl/1.depth/shaders/depth.frag
diff options
context:
space:
mode:
authorpryazha <pryadeiniv@mail.ru>2025-02-19 22:26:48 +0500
committerpryazha <pryadeiniv@mail.ru>2025-02-19 22:26:48 +0500
commitf9ad6fa902c1167d7622ee7af2617d14b62bee21 (patch)
tree9d78792cf360ed871616a9ea66c4237018292aa7 /advanced_opengl/1.depth/shaders/depth.frag
parent926cbd0d49890772f911e6a6bedb7835605ced89 (diff)
quite a lot of changes that I, of course, are not going to describe;)
Diffstat (limited to 'advanced_opengl/1.depth/shaders/depth.frag')
-rw-r--r--advanced_opengl/1.depth/shaders/depth.frag23
1 files changed, 23 insertions, 0 deletions
diff --git a/advanced_opengl/1.depth/shaders/depth.frag b/advanced_opengl/1.depth/shaders/depth.frag
new file mode 100644
index 0000000..710b0d2
--- /dev/null
+++ b/advanced_opengl/1.depth/shaders/depth.frag
@@ -0,0 +1,23 @@
+#version 330 core
+
+out vec4 frag_color;
+
+in vec2 tex_coords;
+
+uniform sampler2D our_texture;
+
+float near = 0.1;
+float far = 100.0;
+
+float linearize_depth(float depth)
+{
+ float ndc_z = 2.0*depth-1.0;
+ return((2.0*near*far)/(far+near-ndc_z*(far-near)));
+}
+
+void main(void)
+{
+ /* frag_color = texture(our_texture, tex_coords); */
+ float depth = linearize_depth(gl_FragCoord.z)/far;
+ frag_color = vec4(vec3(depth), 1.0);
+}