diff options
author | pryazha <pryadeiniv@mail.ru> | 2025-02-19 22:26:48 +0500 |
---|---|---|
committer | pryazha <pryadeiniv@mail.ru> | 2025-02-19 22:26:48 +0500 |
commit | f9ad6fa902c1167d7622ee7af2617d14b62bee21 (patch) | |
tree | 9d78792cf360ed871616a9ea66c4237018292aa7 /advanced_lighting/4.normal_mapping/shaders/normal_map.frag | |
parent | 926cbd0d49890772f911e6a6bedb7835605ced89 (diff) |
quite a lot of changes that I, of course, are not going to describe;)
Diffstat (limited to 'advanced_lighting/4.normal_mapping/shaders/normal_map.frag')
-rw-r--r-- | advanced_lighting/4.normal_mapping/shaders/normal_map.frag | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/advanced_lighting/4.normal_mapping/shaders/normal_map.frag b/advanced_lighting/4.normal_mapping/shaders/normal_map.frag new file mode 100644 index 0000000..964d6f8 --- /dev/null +++ b/advanced_lighting/4.normal_mapping/shaders/normal_map.frag @@ -0,0 +1,51 @@ +#version 330 core + +in VS_OUT { + /* mat3 TBN; */ + vec3 frag_pos; + vec3 tangent_light_pos; + vec3 tangent_view_pos; + vec3 tangent_frag_pos; + vec2 tex_coords; +} fs_in; + +out vec4 frag_color; + +/* uniform vec3 light_pos; */ +/* uniform vec3 view_pos; */ + +uniform sampler2D diffuse_texture; +uniform sampler2D normal_map; + +void main(void) +{ + vec3 color = vec3(texture(diffuse_texture, fs_in.tex_coords)); + vec3 normal = vec3(texture(normal_map, fs_in.tex_coords)); + normal = normalize((normal*2.0)-1.0); + /* + normal = normalize(fs_in.TBN*normal); + + vec3 light_dir = fs_in.TBN * normalize(light_pos - fs_in.frag_pos); + vec3 view_dir = fs_in.TBN * normalize(view_pos - fs_in.frag_pos); + */ + + vec3 light_color = vec3(1.0); + + float ambient = 0.01; + + /* vec3 light_dir = normalize(light_pos-fs_in.frag_pos); */ + vec3 light_dir = normalize(fs_in.tangent_light_pos - fs_in.tangent_frag_pos); + float diff = max(dot(light_dir, normal), 0.0); + vec3 diffuse = diff*light_color; + + /* vec3 view_dir = normalize(view_pos-fs_in.frag_pos); */ + vec3 view_dir = normalize(fs_in.tangent_view_pos-fs_in.frag_pos); + vec3 halfway_dir = normalize(light_dir+view_dir); + float spec = pow(max(dot(halfway_dir, normal), 0.0), 64.0); + float spec_strength = 1.0; + vec3 specular = spec_strength*spec*light_color; + + vec3 result = (ambient+diffuse+specular)*color; + + frag_color = vec4(result, 1.0); +} |