blob: 964d6f8ac551b61853b8d18c34b7488143fc1798 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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);
}
|