blob: 3e9f740dea97d63b89f7f07ed8bb80debc6a5635 (
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
|
#version 330 core
in vert_t {
vec2 tex_coords;
} vert;
out vec4 frag_color;
uniform sampler2D positions;
uniform sampler2D normals;
uniform sampler2D colors;
uniform sampler2D ssao;
uniform vec3 view_position;
struct light_t {
vec3 position;
vec3 color;
};
uniform light_t light;
const float linear = 0.7f;
const float quadratic = 1.8f;
void main()
{
vec3 position = texture(positions, vert.tex_coords).xyz;
vec3 normal = texture(normals, vert.tex_coords).xyz;
vec3 color = texture(colors, vert.tex_coords).rgb;
float occlusion = texture(ssao, vert.tex_coords).r;
vec3 ambient = 0.1 * color * occlusion;
vec3 result = ambient;
vec3 view_dir = normalize(-position);
vec3 light_dir = normalize(light.position - position);
vec3 diffuse = max(dot(normal, light_dir), 0.0) * color * light.color;
vec3 halfway_dir = normalize(view_dir + light_dir);
vec3 specular = pow(max(dot(halfway_dir, normal), 0.0), 16.0) * vec3(0.5);
float distance = length(light.position - position);
float attenuation = 1.0 / (1.0 + linear * distance + quadratic * distance * distance);
result += (diffuse + specular) * attenuation;
frag_color = vec4(result, 1.0);
}
|