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;) --- .../2.gamma_correction/shaders/blinn_phong.frag | 55 ++++++++++++++++++++ .../2.gamma_correction/shaders/blinn_phong.fs | 58 ---------------------- .../2.gamma_correction/shaders/blinn_phong.vert | 22 ++++++++ .../2.gamma_correction/shaders/blinn_phong.vs | 23 --------- .../2.gamma_correction/shaders/light.frag | 8 +++ .../2.gamma_correction/shaders/light.fs | 9 ---- .../2.gamma_correction/shaders/light.vert | 11 ++++ .../2.gamma_correction/shaders/light.vs | 12 ----- 8 files changed, 96 insertions(+), 102 deletions(-) create mode 100644 advanced_lighting/2.gamma_correction/shaders/blinn_phong.frag delete mode 100644 advanced_lighting/2.gamma_correction/shaders/blinn_phong.fs create mode 100644 advanced_lighting/2.gamma_correction/shaders/blinn_phong.vert delete mode 100644 advanced_lighting/2.gamma_correction/shaders/blinn_phong.vs create mode 100644 advanced_lighting/2.gamma_correction/shaders/light.frag delete mode 100644 advanced_lighting/2.gamma_correction/shaders/light.fs create mode 100644 advanced_lighting/2.gamma_correction/shaders/light.vert delete mode 100644 advanced_lighting/2.gamma_correction/shaders/light.vs (limited to 'advanced_lighting/2.gamma_correction/shaders') diff --git a/advanced_lighting/2.gamma_correction/shaders/blinn_phong.frag b/advanced_lighting/2.gamma_correction/shaders/blinn_phong.frag new file mode 100644 index 0000000..331fc8b --- /dev/null +++ b/advanced_lighting/2.gamma_correction/shaders/blinn_phong.frag @@ -0,0 +1,55 @@ +#version 330 core + +in VS_OUT { + vec3 frag_pos; + vec3 normal; + vec2 tex_coords; +} fs_in; + +out vec4 frag_color; + +uniform sampler2D texture0; +uniform vec3 light_positions[4]; +uniform vec3 light_colors[4]; +uniform vec3 view_pos; +uniform bool gamma_correction; + +vec3 blinn_phong(vec3 light_dir, vec3 view_dir, vec3 normal, + vec3 light_pos, vec3 light_color) +{ + float diff = max(dot(normal, light_dir), 0.0); + vec3 diffuse = diff*light_color; + + vec3 halfway_dir = normalize(light_dir+view_dir); + float spec = pow(max(dot(normal, halfway_dir), 0.0), 16.0); + vec3 specular = spec*light_color; + + float distance = length(light_pos-fs_in.frag_pos); + float attenuation = 1.0/(gamma_correction ? distance*distance : distance); + + return((diffuse+specular)*attenuation); +} + +void main(void) +{ + vec3 view_dir = normalize(view_pos-fs_in.frag_pos); + vec3 normal = normalize(fs_in.normal); + vec3 texture_color = texture(texture0, fs_in.tex_coords).rgb; + + vec3 lighting = vec3(0.0); + for (int i = 0; i < 4; i++) { + vec3 light_pos = light_positions[i]; + vec3 light_color = light_colors[i]; + vec3 light_dir = normalize(light_pos-fs_in.frag_pos); + lighting += blinn_phong(light_dir, view_dir, normal, + light_pos, light_color); + } + + texture_color *= lighting; + + float gamma = 2.2; + if (gamma_correction) + texture_color = pow(texture_color, vec3(1.0/gamma)); + + frag_color = vec4(texture_color, 1.0); +} diff --git a/advanced_lighting/2.gamma_correction/shaders/blinn_phong.fs b/advanced_lighting/2.gamma_correction/shaders/blinn_phong.fs deleted file mode 100644 index 35e701c..0000000 --- a/advanced_lighting/2.gamma_correction/shaders/blinn_phong.fs +++ /dev/null @@ -1,58 +0,0 @@ -#version 330 core - -in VS_OUT { - vec3 frag_pos; - vec3 normal; - vec2 tex_coords; -} fs_in; - -out vec4 frag_color; - -uniform sampler2D texture0; -uniform vec3 light_positions[4]; -uniform vec3 light_colors[4]; -uniform vec3 view_pos; -uniform bool gamma_correction; - -vec3 -blinn_phong(vec3 light_dir, vec3 view_dir, vec3 normal, - vec3 light_pos, vec3 light_color) -{ - float diff = max(dot(normal, light_dir), 0.0); - vec3 diffuse = diff*light_color; - - vec3 halfway_dir = normalize(light_dir+view_dir); - float spec = pow(max(dot(normal, halfway_dir), 0.0), 16.0); - vec3 specular = spec*light_color; - - float distance = length(light_pos-fs_in.frag_pos); - float attenuation = 1.0/(gamma_correction ? distance*distance : distance); - - return((diffuse+specular)*attenuation); -} - -void -main(void) -{ - vec3 view_dir = normalize(view_pos-fs_in.frag_pos); - vec3 normal = normalize(fs_in.normal); - vec3 texture_color = texture(texture0, fs_in.tex_coords).rgb; - - vec3 lighting = vec3(0.0); - for (int i = 0; i < 4; i++) - { - vec3 light_pos = light_positions[i]; - vec3 light_color = light_colors[i]; - vec3 light_dir = normalize(light_pos-fs_in.frag_pos); - lighting += blinn_phong(light_dir, view_dir, normal, - light_pos, light_color); - } - - texture_color *= lighting; - - float gamma = 2.2; - if (gamma_correction) - texture_color = pow(texture_color, vec3(1.0/gamma)); - - frag_color = vec4(texture_color, 1.0); -} diff --git a/advanced_lighting/2.gamma_correction/shaders/blinn_phong.vert b/advanced_lighting/2.gamma_correction/shaders/blinn_phong.vert new file mode 100644 index 0000000..870e7dc --- /dev/null +++ b/advanced_lighting/2.gamma_correction/shaders/blinn_phong.vert @@ -0,0 +1,22 @@ +#version 330 core +layout(location = 0) in vec3 apos; +layout(location = 1) in vec3 anormal; +layout(location = 2) in vec2 atex_coords; + +out VS_OUT { + vec3 frag_pos; + vec3 normal; + vec2 tex_coords; +} vs_out; + +uniform mat4 proj; +uniform mat4 view; +uniform mat4 model; + +void main(void) +{ + vs_out.frag_pos = vec3(model*vec4(apos, 1.0)); + vs_out.normal = mat3(transpose(inverse(model)))*anormal; + vs_out.tex_coords = atex_coords; + gl_Position = proj*view*model*vec4(apos, 1.0); +} diff --git a/advanced_lighting/2.gamma_correction/shaders/blinn_phong.vs b/advanced_lighting/2.gamma_correction/shaders/blinn_phong.vs deleted file mode 100644 index 4d1b792..0000000 --- a/advanced_lighting/2.gamma_correction/shaders/blinn_phong.vs +++ /dev/null @@ -1,23 +0,0 @@ -#version 330 core -layout(location = 0) in vec3 apos; -layout(location = 1) in vec3 anormal; -layout(location = 2) in vec2 atex_coords; - -out VS_OUT { - vec3 frag_pos; - vec3 normal; - vec2 tex_coords; -} vs_out; - -uniform mat4 projection; -uniform mat4 view; -uniform mat4 model; - -void -main(void) -{ - vs_out.frag_pos = vec3(model*vec4(apos, 1.0)); - vs_out.normal = mat3(transpose(inverse(model)))*anormal; - vs_out.tex_coords = atex_coords; - gl_Position = projection*view*model*vec4(apos, 1.0); -} diff --git a/advanced_lighting/2.gamma_correction/shaders/light.frag b/advanced_lighting/2.gamma_correction/shaders/light.frag new file mode 100644 index 0000000..c01da99 --- /dev/null +++ b/advanced_lighting/2.gamma_correction/shaders/light.frag @@ -0,0 +1,8 @@ +#version 330 core + +out vec4 frag_color; + +void main(void) +{ + frag_color = vec4(1.0); +} diff --git a/advanced_lighting/2.gamma_correction/shaders/light.fs b/advanced_lighting/2.gamma_correction/shaders/light.fs deleted file mode 100644 index bd00d82..0000000 --- a/advanced_lighting/2.gamma_correction/shaders/light.fs +++ /dev/null @@ -1,9 +0,0 @@ -#version 330 core - -out vec4 frag_color; - -void -main(void) -{ - frag_color = vec4(1.0); -} diff --git a/advanced_lighting/2.gamma_correction/shaders/light.vert b/advanced_lighting/2.gamma_correction/shaders/light.vert new file mode 100644 index 0000000..a8b1247 --- /dev/null +++ b/advanced_lighting/2.gamma_correction/shaders/light.vert @@ -0,0 +1,11 @@ +#version 330 core +layout(location = 0) in vec3 apos; + +uniform mat4 proj; +uniform mat4 view; +uniform mat4 model; + +void main(void) +{ + gl_Position = proj*view*model*vec4(apos, 1.0); +} diff --git a/advanced_lighting/2.gamma_correction/shaders/light.vs b/advanced_lighting/2.gamma_correction/shaders/light.vs deleted file mode 100644 index ade669b..0000000 --- a/advanced_lighting/2.gamma_correction/shaders/light.vs +++ /dev/null @@ -1,12 +0,0 @@ -#version 330 core -layout(location = 0) in vec3 apos; - -uniform mat4 projection; -uniform mat4 view; -uniform mat4 model; - -void -main(void) -{ - gl_Position = projection*view*model*vec4(apos, 1.0); -} -- cgit v1.2.3