From 47a1dd5a041d7ccc766e38d4281e75c58f363c67 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 8 May 2023 11:29:12 +0200 Subject: [PATCH] positional ligthing --- shaders/manif.vs | 12 ++++++++---- src/manif.c | 7 +++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/shaders/manif.vs b/shaders/manif.vs index f7ab19b..ddef811 100644 --- a/shaders/manif.vs +++ b/shaders/manif.vs @@ -5,10 +5,14 @@ layout(location = 1) in vec3 normal; out float intensite_eclairage; uniform mat4 proj, model, view; +uniform vec4 lumpos; void main() { - vec3 Ld = normalize(vec3(0.0, -0.2, -1.0)); - vec3 n = normalize(transpose(inverse(view * model)) * vec4(normal, 0.0)).xyz; - intensite_eclairage = clamp(dot(n, -Ld), 0.0, 1.0); - gl_Position = proj * view * model * vec4(pos, 1.0); + vec4 pos_model = model * vec4(pos, 1); + // vec3 soleil = normalize(vec3(0, -20, 0)); + 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; } diff --git a/src/manif.c b/src/manif.c index 5ac2e0c..18e95a6 100644 --- a/src/manif.c +++ b/src/manif.c @@ -44,9 +44,12 @@ static void draw(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(_pId); - const GLfloat couleur_plan[] = {0.3f, 0.3f, 0.3f, 1}; - const GLfloat couleur_heros[] = {1, 1, 0, 1}; + const GLfloat couleur_plan[] = {0.3f, 0.3f, 0.3f, 1}, + couleur_heros[] = {1, 1, 0, 1}, lumpos[] = {-4, 0.5, 0, 1}; GLint couleur_loc = glGetUniformLocation(_pId, "couleur"); + GLint lum_loc = glGetUniformLocation(_pId, "lumpos"); + + glUniform4fv(lum_loc, 1, lumpos); gl4duBindMatrix(matrix_proj); gl4duLoadIdentityf();