blob: 23e2968e49866a9933bb887aa1167194fca9fe6f (
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
52
53
54
55
56
57
58
59
60
61
62
|
#version 330 core
in vec2 tex_coords;
in vec3 normal;
in vec3 frag_pos;
out vec4 frag_color;
uniform sampler2D texture_diffuse;
uniform sampler2D texture_specular;
uniform vec3 light_pos;
uniform vec3 view_pos;
uniform float ambient_strength;
uniform float specular_strength;
uniform float shininess;
vec4
spotlight(vec3 light_dir, vec3 view_dir)
{
vec3 tex_color_diff = texture(texture_diffuse, tex_coords);
float ambient_strength = 0.1f;
vec4 ambient = tex_color_diff*ambient_strength;
vec4 diffuse = tex_color_diff*dot(-light_dir, )
return(color);
}
vec4
blinn_phong()
{
// Sample the diffuse color from the texture
vec3 diffuse_color = texture(texture_diffuse, tex_coords).rgb;
// Sample the specular color from the texture (if available)
vec3 specular_color = texture(texture_specular, tex_coords).rgb;
// Ambient lighting
vec3 ambient = ambient_strength*diffuse_color;
// Diffuse lighting
vec3 norm = normalize(normal);
vec3 light_dir = normalize(light_pos-frag_pos);
float diff = max(dot(norm, light_dir), 0.0);
vec3 diffuse = diff * diffuse_color;
// Specular lighting
vec3 view_dir = normalize(view_pos-frag_pos);
vec3 halfway_dir = normalize(light_dir+view_dir); // Halfway vector
float spec = pow(max(dot(norm, halfway_dir), 0.0), shininess);
vec3 specular = specular_strength*spec*specular_color;
// Combine all components
vec3 result = (ambient+diffuse+specular);
return((result, 1.0));
}
void
main(void)
{
frag_color = blinn_phong();
}
|