specularite

This commit is contained in:
Mylloon 2023-05-08 15:06:42 +02:00
parent 0e93d13a74
commit f9ebf9066c
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 21 additions and 17 deletions

View file

@ -7,9 +7,15 @@ out vec4 fragColor;
uniform vec4 couleur; uniform vec4 couleur;
uniform vec4 lumpos; uniform vec4 lumpos;
uniform mat4 view;
void main() { void main() {
const vec3 vue = vec3(0, 0, -1);
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 - lumpos.xyz);
float intensite_eclairage = clamp(dot(vec_normal, -torche), 0, 1); float intensite_lumineuse = clamp(dot(vec_normal, -torche), 0, 1);
fragColor = intensite_eclairage * couleur; 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 * vec4(1.0f, 0.0f, 0.0f, 1.0f) + 0.1 * soleil_color + 0.9 * intensite_lumineuse * couleur;
} }

View file

@ -49,38 +49,36 @@ static void draw(void) {
const GLfloat couleur_plan[] = {0.3f, 0.3f, 0.3f, 1}, const GLfloat couleur_plan[] = {0.3f, 0.3f, 0.3f, 1},
couleur_heros[] = {1, 1, 0, 1}; couleur_heros[] = {1, 1, 0, 1};
GLint couleur_loc = glGetUniformLocation(_pId, "couleur"); GLint couleur_gpu = glGetUniformLocation(_pId, "couleur");
static double deplacement = 0; static double deplacement = 0;
const GLfloat lumpos[] = {1, 2, 3, 1}; const GLfloat lumpos[] = {1, (GLfloat)(2 + 2 * sin(deplacement)), 1, 1};
GLint lum_loc = glGetUniformLocation(_pId, "lumpos"); glUniform4fv(glGetUniformLocation(_pId, "lumpos"), 1, lumpos);
glUniform4fv(lum_loc, 1, lumpos);
gl4duBindMatrix(matrix_proj); bindAndLoadf(matrix_proj);
gl4duLoadIdentityf();
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);
gl4duBindMatrix(matrix_view); bindAndLoadf(matrix_view);
gl4duLoadIdentityf();
const GLfloat distance = 2; const GLfloat distance = 2;
gl4duLookAtf(0, distance, distance, 0, 0, 0, 0, 1, 0); const GLfloat eye[3] = {0, distance, distance};
gl4duLookAtf(eye[0], eye[1], eye[2], 0, 0, 0, 0, 1, 0);
glUniform4fv(glGetUniformLocation(_pId, "camerapos"), 1, eye);
gl4duBindMatrix(matrix_model); bindAndLoadf(matrix_model);
gl4duLoadIdentityf();
gl4duRotatef(-90, 1, 0, 0); gl4duRotatef(-90, 1, 0, 0);
gl4duScalef(4 * distance, 2 * distance, 1); gl4duScalef(4 * distance, 2 * distance, 1);
gl4duSendMatrices(); gl4duSendMatrices();
glUniform4fv(couleur_loc, 1, couleur_plan); glUniform4fv(couleur_gpu, 1, couleur_plan);
gl4dgDraw(_planId); gl4dgDraw(_planId);
gl4duBindMatrix(matrix_model); bindAndLoadf(matrix_model);
gl4duLoadIdentityf();
gl4duScalef(1, 1.5, 1); gl4duScalef(1, 1.5, 1);
gl4duRotatef((GLfloat)(180 * deplacement / M_PI), 0, 1, 0);
gl4duSendMatrices(); gl4duSendMatrices();
glUniform4fv(couleur_loc, 1, couleur_heros); glUniform4fv(couleur_gpu, 1, couleur_heros);
gl4dgDraw(_herosId); gl4dgDraw(_herosId);
deplacement += 0.4 * M_PI * dt; deplacement += 0.4 * M_PI * dt;
glUseProgram(0); glUseProgram(0);