This commit is contained in:
Mylloon 2023-05-08 12:16:29 +02:00
parent 2bb1a19e4b
commit 69629eb941
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 14 additions and 10 deletions

View file

@ -1,10 +1,15 @@
#version 330 #version 330
in float intensite_eclairage; in vec4 pos_model;
in vec3 vec_normal;
out vec4 fragColor; out vec4 fragColor;
uniform vec4 couleur; uniform vec4 couleur;
uniform vec4 lumpos;
void main() { void main() {
vec3 torche = normalize(pos_model.xyz - lumpos.xyz);
float intensite_eclairage = clamp(dot(vec_normal, -torche), 0, 1);
fragColor = intensite_eclairage * couleur; fragColor = intensite_eclairage * couleur;
} }

View file

@ -3,16 +3,14 @@
layout(location = 0) in vec3 pos; layout(location = 0) in vec3 pos;
layout(location = 1) in vec3 normal; layout(location = 1) in vec3 normal;
out float intensite_eclairage; out vec4 pos_model;
out vec3 vec_normal;
uniform mat4 proj, model, view; uniform mat4 proj, model, view;
uniform vec4 lumpos;
void main() { void main() {
vec4 pos_model = model * vec4(pos, 1); pos_model = model * vec4(pos, 1);
// vec3 soleil = normalize(vec3(0, -20, 0)); vec_normal = normalize(transpose(inverse(model)) * vec4(normal, 0)).xyz;
vec3 torche = normalize(pos_model.xyz - lumpos.xyz);
vec3 vec_normal = normalize(transpose(inverse(model)) * vec4(normal, 0)).xyz;
intensite_eclairage = clamp(dot(vec_normal, -(torche)), 0, 1);
gl_Position = proj * view * pos_model; gl_Position = proj * view * pos_model;
} }

View file

@ -45,10 +45,11 @@ static void draw(void) {
glUseProgram(_pId); glUseProgram(_pId);
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}, lumpos[] = {-4, 0.5, 0, 1}; couleur_heros[] = {1, 1, 0, 1};
GLint couleur_loc = glGetUniformLocation(_pId, "couleur"); GLint couleur_loc = glGetUniformLocation(_pId, "couleur");
GLint lum_loc = glGetUniformLocation(_pId, "lumpos");
const GLfloat lumpos[] = {1, 2, 3, 1};
GLint lum_loc = glGetUniformLocation(_pId, "lumpos");
glUniform4fv(lum_loc, 1, lumpos); glUniform4fv(lum_loc, 1, lumpos);
gl4duBindMatrix(matrix_proj); gl4duBindMatrix(matrix_proj);