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;) --- .../1.blinn_phong/shaders/blinn_phong.frag | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 advanced_lighting/1.blinn_phong/shaders/blinn_phong.frag (limited to 'advanced_lighting/1.blinn_phong/shaders/blinn_phong.frag') diff --git a/advanced_lighting/1.blinn_phong/shaders/blinn_phong.frag b/advanced_lighting/1.blinn_phong/shaders/blinn_phong.frag new file mode 100644 index 0000000..80f3e47 --- /dev/null +++ b/advanced_lighting/1.blinn_phong/shaders/blinn_phong.frag @@ -0,0 +1,40 @@ +#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_pos; +uniform vec3 view_pos; +uniform bool blinn; + +void main(void) +{ + vec3 light_dir = normalize(light_pos-fs_in.frag_pos); + 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; + + float diff = max(dot(normal, light_dir), 0.0); + + float spec = 0.0; + if (blinn) { + vec3 halfway_dir = normalize(light_dir+view_dir); + spec = pow(max(dot(normal, halfway_dir), 0.0), 16.0); + } else { + vec3 reflect_dir = reflect(-light_dir, normal); + spec = pow(max(dot(view_dir, reflect_dir), 0.0), 8.0); + } + + vec3 ambient = 0.05*texture_color; + vec3 diffuse = diff*texture_color; + vec3 specular = vec3(0.3)*spec; + + frag_color = vec4(ambient+diffuse+specular, 1.0); +} -- cgit v1.2.3