WOW LUMIERE

This commit is contained in:
Mylloon 2023-05-12 14:09:26 +02:00
parent a3f04eda2b
commit b976dbb707
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 23 additions and 13 deletions

View file

@ -5,18 +5,25 @@ in vec3 vec_normal;
out vec4 fragColor; out vec4 fragColor;
const int max = 2; // should change in cpu too
uniform vec4 couleur; uniform vec4 couleur;
uniform vec4 lum_pos; uniform vec4 lum_pos[max];
uniform mat4 view; uniform mat4 view;
uniform vec4 lum_color; uniform vec4 lum_color[max];
void main() { void main() {
const vec3 vue = vec3(0, 0, -1); const vec3 vue = vec3(0, 0, -1);
const vec4 soleil_color = vec4(0.81f, 0.78f, 0.66f, 1.0f); const vec4 soleil_color = vec4(0.81f, 0.78f, 0.66f, 1.0f);
vec3 torche = normalize(pos_model.xyz - lum_pos.xyz);
float intensite_lumineuse = clamp(dot(vec_normal, -torche), 0., 1.);
vec3 reflet = (transpose(inverse(view)) * vec4(reflect(torche, vec_normal), 0)).xyz;
float intensite_specularite = pow(clamp(dot(reflet, -vue), 0., 1.), 10);
fragColor = intensite_specularite * lum_color + 0.1 * soleil_color + 0.9 * intensite_lumineuse * couleur; fragColor = vec4(1);
for(int i = 0; i < max; i++) {
vec3 torche = normalize(pos_model.xyz - lum_pos[i].xyz);
float intensite_lumineuse = clamp(dot(vec_normal, -torche), 0., 1.);
vec3 reflet = (transpose(inverse(view)) * vec4(reflect(torche, vec_normal), 0)).xyz;
float intensite_specularite = pow(clamp(dot(reflet, -vue), 0., 1.), 10);
fragColor *= intensite_specularite * lum_color[i] + 0.1 * soleil_color + 0.9 * intensite_lumineuse * couleur;
}
} }

View file

@ -9,7 +9,7 @@ struct manifestant {
GLfloat ox, oz; GLfloat ox, oz;
}; };
#define HEROS_NUMBER 70 #define HEROS_NUMBER 70 // should change in fragment shader too
static struct manifestant _herosId[HEROS_NUMBER]; static struct manifestant _herosId[HEROS_NUMBER];
static const char *matrix_proj = "proj"; static const char *matrix_proj = "proj";
@ -70,18 +70,21 @@ static void draw(void) {
GLint couleur_gpu = glGetUniformLocation(_pId, "couleur"); GLint couleur_gpu = glGetUniformLocation(_pId, "couleur");
static double deplacement = 0; static double deplacement = 0;
const GLfloat lumpos[] = {1, (GLfloat)(2 + 2 * sin(deplacement)), 1, 1}, const GLfloat lumpos[][4] = {{1, (GLfloat)(2 + 2 * sin(deplacement)), 1, 1},
lumcolor[] = {1, 0, 0, 1}; {-1, (GLfloat)(2 + 2 * sin(deplacement)), 1, 1}},
glUniform4fv(glGetUniformLocation(_pId, "lum_pos"), 1, lumpos); lumcolor[][4] = {{1, 0, 0, 1}, {0, 0, 1, 1}};
glUniform4fv(glGetUniformLocation(_pId, "lum_color"), 1, lumcolor);
glUniform4fv(glGetUniformLocation(_pId, "lum_pos"), 2, (float *)lumpos);
glUniform4fv(glGetUniformLocation(_pId, "lum_color"), 2, (float *)lumcolor);
bindAndLoadf(matrix_proj); bindAndLoadf(matrix_proj);
GLfloat ratio = (GLfloat)_dims[0] / (GLfloat)_dims[1]; GLfloat ratio = (GLfloat)_dims[0] / (GLfloat)_dims[1];
gl4duFrustumf(-1, 1, -ratio, ratio, 1, 1000); gl4duFrustumf(-1, 1, -ratio, ratio, 1, 1000);
bindAndLoadf(matrix_view); bindAndLoadf(matrix_view);
const GLfloat distance = 2; const GLfloat distance = 5;
gl4duLookAtf(0, distance, distance, 0, 0, 0, 0, 1, 0); gl4duLookAtf(0, distance, distance, 0, 0, 0, 0, 1, 0);
// gl4duRotatef(-30, 0, 1, 0);
bindAndLoadf(matrix_model); bindAndLoadf(matrix_model);
gl4duRotatef(-90, 1, 0, 0); gl4duRotatef(-90, 1, 0, 0);