-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColorFragmentShader.fragmentshader
50 lines (35 loc) · 1.5 KB
/
ColorFragmentShader.fragmentshader
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
#version 330 core
// Interpolated values from the vertex shaders
in vec4 fragment_colour;
in vec2 UV;
in vec3 light_direction;
in vec3 light_direction_tangent_space;
in vec3 surface_normal;
out vec3 colour;
uniform sampler2D GRASS_TEXTURE;
uniform sampler2D NORMAL_MAP_TEXTURE;
uniform vec3 AMBIENT_LIGHT_COLOUR;
uniform vec3 LIGHT_COLOUR;
void main()
{
vec4 texture_colour = texture(GRASS_TEXTURE, UV);
texture_colour = vec4(texture_colour.b, texture_colour.g, texture_colour.r, texture_colour.a);
vec3 surface_colour = texture_colour.rgb * fragment_colour.rgb;
vec3 map_normal_colour = normalize(texture(NORMAL_MAP_TEXTURE, UV).rgb);
vec3 map_normal = (map_normal_colour*2) - 1;
vec3 normal = surface_normal;// * map_normal;
vec3 ambient_light_colour = AMBIENT_LIGHT_COLOUR;
float diffuse_light = clamp(dot(light_direction, normal), 0, 1);
vec3 diffuse_light_colour = diffuse_light * LIGHT_COLOUR;
colour = (ambient_light_colour + diffuse_light_colour) * surface_colour;
// colour = (fragment_colour.rgb + 1)*0.5;
// // Direction of the light (from the fragment to the light)
// // Cosine of the angle between the normal and the light direction,
// // clamped above 0
// // - light is at the vertical of the triangle -> 1
// // - light is perpendicular to the triangle -> 0
// // - light is behind the triangle -> 0
// float cosTheta = clamp( dot(normal, light_direction_tangent_space), 0,1 );
// colour = vec3(cosTheta, cosTheta, cosTheta);
// colour = texture_colour.rgb;
}