This commit is contained in:
Mylloon 2023-05-08 15:26:47 +02:00
parent e844a8b94a
commit 401f3e0cb2
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 7 additions and 9 deletions

View file

@ -6,17 +6,17 @@ in vec3 vec_normal;
out vec4 fragColor; out vec4 fragColor;
uniform vec4 couleur; uniform vec4 couleur;
uniform vec4 lumpos; uniform vec4 lum_pos;
uniform mat4 view; uniform mat4 view;
uniform vec4 lumcolor; uniform vec4 lum_color;
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 - lumpos.xyz); vec3 torche = normalize(pos_model.xyz - lum_pos.xyz);
float intensite_lumineuse = clamp(dot(vec_normal, -torche), 0, 1); float intensite_lumineuse = clamp(dot(vec_normal, -torche), 0, 1);
vec3 reflet = (transpose(inverse(view)) * vec4(reflect(torche, vec_normal), 0)).xyz; vec3 reflet = (transpose(inverse(view)) * vec4(reflect(torche, vec_normal), 0)).xyz;
float intensite_specularite = pow(clamp(dot(reflet, -vue), 0, 1), 10); float intensite_specularite = pow(clamp(dot(reflet, -vue), 0, 1), 10);
fragColor = intensite_specularite * lumcolor + 0.1 * soleil_color + 0.9 * intensite_lumineuse * couleur; fragColor = intensite_specularite * lum_color + 0.1 * soleil_color + 0.9 * intensite_lumineuse * couleur;
} }

View file

@ -54,8 +54,8 @@ static void draw(void) {
const GLfloat lumpos[] = {1, (GLfloat)(2 + 2 * sin(deplacement)), 1, 1}, const GLfloat lumpos[] = {1, (GLfloat)(2 + 2 * sin(deplacement)), 1, 1},
lumcolor[] = {1, 0, 0, 1}; lumcolor[] = {1, 0, 0, 1};
glUniform4fv(glGetUniformLocation(_pId, "lumpos"), 1, lumpos); glUniform4fv(glGetUniformLocation(_pId, "lum_pos"), 1, lumpos);
glUniform4fv(glGetUniformLocation(_pId, "lumcolor"), 1, lumcolor); glUniform4fv(glGetUniformLocation(_pId, "lum_color"), 1, lumcolor);
bindAndLoadf(matrix_proj); bindAndLoadf(matrix_proj);
GLfloat ratio = (GLfloat)_dims[0] / (GLfloat)_dims[1]; GLfloat ratio = (GLfloat)_dims[0] / (GLfloat)_dims[1];
@ -63,9 +63,7 @@ static void draw(void) {
bindAndLoadf(matrix_view); bindAndLoadf(matrix_view);
const GLfloat distance = 2; const GLfloat distance = 2;
const GLfloat eye[3] = {0, distance, distance}; gl4duLookAtf(0, distance, distance, 0, 0, 0, 0, 1, 0);
gl4duLookAtf(eye[0], eye[1], eye[2], 0, 0, 0, 0, 1, 0);
glUniform4fv(glGetUniformLocation(_pId, "camerapos"), 1, eye);
bindAndLoadf(matrix_model); bindAndLoadf(matrix_model);
gl4duRotatef(-90, 1, 0, 0); gl4duRotatef(-90, 1, 0, 0);