2023-05-01 01:00:50 +02:00
|
|
|
#version 330
|
|
|
|
|
2023-05-08 12:16:29 +02:00
|
|
|
in vec4 pos_model;
|
|
|
|
in vec3 vec_normal;
|
2023-05-27 04:22:31 +02:00
|
|
|
in vec4 shadowMapCoord;
|
2023-05-08 12:16:29 +02:00
|
|
|
|
2023-05-01 01:00:50 +02:00
|
|
|
out vec4 fragColor;
|
|
|
|
|
2023-05-21 08:26:20 +02:00
|
|
|
const int max = 3; // should change in cpu too
|
2023-05-12 14:09:26 +02:00
|
|
|
|
2023-05-08 10:38:45 +02:00
|
|
|
uniform vec4 couleur;
|
2023-05-21 07:52:10 +02:00
|
|
|
uniform vec4 lumPos[max];
|
2023-05-08 15:06:42 +02:00
|
|
|
uniform mat4 view;
|
2023-05-21 07:52:10 +02:00
|
|
|
uniform vec4 lumColor[max];
|
2023-05-27 04:22:31 +02:00
|
|
|
uniform sampler2D shadowmap;
|
2023-05-08 10:38:45 +02:00
|
|
|
|
2023-05-01 01:00:50 +02:00
|
|
|
void main() {
|
2023-05-08 15:06:42 +02:00
|
|
|
const vec3 vue = vec3(0, 0, -1);
|
|
|
|
const vec4 soleil_color = vec4(0.81f, 0.78f, 0.66f, 1.0f);
|
|
|
|
|
2023-05-12 14:09:26 +02:00
|
|
|
for(int i = 0; i < max; i++) {
|
2023-05-21 07:52:10 +02:00
|
|
|
vec3 torche = normalize(pos_model.xyz - lumPos[i].xyz);
|
2023-05-12 14:09:26 +02:00
|
|
|
float intensite_lumineuse = clamp(dot(vec_normal, -torche), 0., 1.);
|
2023-05-27 04:22:31 +02:00
|
|
|
|
|
|
|
vec3 shadowMapPcoord = shadowMapCoord.xyz / shadowMapCoord.w;
|
|
|
|
if(texture(shadowmap, shadowMapPcoord.xy).r < shadowMapPcoord.z) {
|
|
|
|
intensite_lumineuse = 0;
|
|
|
|
}
|
|
|
|
|
2023-05-12 14:09:26 +02:00
|
|
|
vec3 reflet = (transpose(inverse(view)) * vec4(reflect(torche, vec_normal), 0)).xyz;
|
|
|
|
float intensite_specularite = pow(clamp(dot(reflet, -vue), 0., 1.), 10);
|
|
|
|
|
2023-05-21 07:52:10 +02:00
|
|
|
vec4 color = intensite_specularite * lumColor[i] + 0.1 * soleil_color + 0.9 * intensite_lumineuse * couleur;
|
2023-05-12 18:14:54 +02:00
|
|
|
if(i == 0) {
|
|
|
|
fragColor = color;
|
|
|
|
} else {
|
2023-05-12 18:17:35 +02:00
|
|
|
fragColor = mix(fragColor, color, 1. * (i / 1));
|
2023-05-12 18:14:54 +02:00
|
|
|
}
|
2023-05-12 14:09:26 +02:00
|
|
|
}
|
2023-05-01 01:00:50 +02:00
|
|
|
}
|