positional ligthing

This commit is contained in:
Mylloon 2023-05-08 11:29:12 +02:00
parent b07c614411
commit 47a1dd5a04
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 13 additions and 6 deletions

View file

@ -5,10 +5,14 @@ layout(location = 1) in vec3 normal;
out float intensite_eclairage; out float intensite_eclairage;
uniform mat4 proj, model, view; uniform mat4 proj, model, view;
uniform vec4 lumpos;
void main() { void main() {
vec3 Ld = normalize(vec3(0.0, -0.2, -1.0)); vec4 pos_model = model * vec4(pos, 1);
vec3 n = normalize(transpose(inverse(view * model)) * vec4(normal, 0.0)).xyz; // vec3 soleil = normalize(vec3(0, -20, 0));
intensite_eclairage = clamp(dot(n, -Ld), 0.0, 1.0); vec3 torche = normalize(pos_model.xyz - lumpos.xyz);
gl_Position = proj * view * model * vec4(pos, 1.0); 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;
} }

View file

@ -44,9 +44,12 @@ static void draw(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
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},
const GLfloat couleur_heros[] = {1, 1, 0, 1}; couleur_heros[] = {1, 1, 0, 1}, lumpos[] = {-4, 0.5, 0, 1};
GLint couleur_loc = glGetUniformLocation(_pId, "couleur"); GLint couleur_loc = glGetUniformLocation(_pId, "couleur");
GLint lum_loc = glGetUniformLocation(_pId, "lumpos");
glUniform4fv(lum_loc, 1, lumpos);
gl4duBindMatrix(matrix_proj); gl4duBindMatrix(matrix_proj);
gl4duLoadIdentityf(); gl4duLoadIdentityf();