From f9ad6fa902c1167d7622ee7af2617d14b62bee21 Mon Sep 17 00:00:00 2001 From: pryazha Date: Wed, 19 Feb 2025 22:26:48 +0500 Subject: quite a lot of changes that I, of course, are not going to describe;) --- advanced_opengl/1.depth/shaders/depth.frag | 23 +++++++++++++++++++++++ advanced_opengl/1.depth/shaders/depth.fs | 27 --------------------------- advanced_opengl/1.depth/shaders/depth.vert | 15 +++++++++++++++ advanced_opengl/1.depth/shaders/depth.vs | 16 ---------------- 4 files changed, 38 insertions(+), 43 deletions(-) create mode 100644 advanced_opengl/1.depth/shaders/depth.frag delete mode 100644 advanced_opengl/1.depth/shaders/depth.fs create mode 100644 advanced_opengl/1.depth/shaders/depth.vert delete mode 100644 advanced_opengl/1.depth/shaders/depth.vs (limited to 'advanced_opengl/1.depth/shaders') 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); +} diff --git a/advanced_opengl/1.depth/shaders/depth.fs b/advanced_opengl/1.depth/shaders/depth.fs deleted file mode 100644 index a515c15..0000000 --- a/advanced_opengl/1.depth/shaders/depth.fs +++ /dev/null @@ -1,27 +0,0 @@ -#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); -} diff --git a/advanced_opengl/1.depth/shaders/depth.vert b/advanced_opengl/1.depth/shaders/depth.vert new file mode 100644 index 0000000..68b8fe2 --- /dev/null +++ b/advanced_opengl/1.depth/shaders/depth.vert @@ -0,0 +1,15 @@ +#version 330 core +layout(location = 0) in vec3 apos; +layout(location = 1) in vec2 atex_coords; + +uniform mat4 model; +uniform mat4 view; +uniform mat4 proj; + +out vec2 tex_coords; + +void main(void) +{ + gl_Position = proj*view*model*vec4(apos, 1.0); + tex_coords = atex_coords; +} diff --git a/advanced_opengl/1.depth/shaders/depth.vs b/advanced_opengl/1.depth/shaders/depth.vs deleted file mode 100644 index 62e71a2..0000000 --- a/advanced_opengl/1.depth/shaders/depth.vs +++ /dev/null @@ -1,16 +0,0 @@ -#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.0); - tex_coords = atex_coords; -} -- cgit v1.2.3