summaryrefslogtreecommitdiff
path: root/advanced_opengl/1.depth/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'advanced_opengl/1.depth/shaders')
-rw-r--r--advanced_opengl/1.depth/shaders/depth.fs27
-rw-r--r--advanced_opengl/1.depth/shaders/depth.vs16
2 files changed, 43 insertions, 0 deletions
diff --git a/advanced_opengl/1.depth/shaders/depth.fs b/advanced_opengl/1.depth/shaders/depth.fs
new file mode 100644
index 0000000..2f3d9ca
--- /dev/null
+++ b/advanced_opengl/1.depth/shaders/depth.fs
@@ -0,0 +1,27 @@
+#version 330 core
+
+out vec4 frag_color;
+
+in vec2 tex_coords;
+
+uniform sampler2D our_texture;
+
+float near = 0.1f;
+float far = 100.0f;
+
+float
+linearize_depth(float depth)
+{
+ float ndc_z = 2.0f*depth-1.0f;
+ return((2.0f*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.0f);
+}
diff --git a/advanced_opengl/1.depth/shaders/depth.vs b/advanced_opengl/1.depth/shaders/depth.vs
new file mode 100644
index 0000000..d3d92d1
--- /dev/null
+++ b/advanced_opengl/1.depth/shaders/depth.vs
@@ -0,0 +1,16 @@
+#version 330 core
+layout(location = 0) in vec3 apos;
+layout(location = 1) in vec2 atex_coords;
+
+uniform mat4 model;
+uniform mat4 view;
+uniform mat4 projection;
+
+out vec2 tex_coords;
+
+void
+main(void)
+{
+ gl_Position = projection*view*model*vec4(apos, 1.0f);
+ tex_coords = atex_coords;
+}