From 69629eb9417d38dc9d6cd2ae3572aa75fd72a37c Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 8 May 2023 12:16:29 +0200 Subject: [PATCH] phong! --- shaders/manif.fs | 7 ++++++- shaders/manif.vs | 12 +++++------- src/manif.c | 5 +++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/shaders/manif.fs b/shaders/manif.fs index cac5047..855c144 100644 --- a/shaders/manif.fs +++ b/shaders/manif.fs @@ -1,10 +1,15 @@ #version 330 -in float intensite_eclairage; +in vec4 pos_model; +in vec3 vec_normal; + out vec4 fragColor; uniform vec4 couleur; +uniform vec4 lumpos; void main() { + vec3 torche = normalize(pos_model.xyz - lumpos.xyz); + float intensite_eclairage = clamp(dot(vec_normal, -torche), 0, 1); fragColor = intensite_eclairage * couleur; } diff --git a/shaders/manif.vs b/shaders/manif.vs index ddef811..5488365 100644 --- a/shaders/manif.vs +++ b/shaders/manif.vs @@ -3,16 +3,14 @@ layout(location = 0) in vec3 pos; layout(location = 1) in vec3 normal; -out float intensite_eclairage; +out vec4 pos_model; +out vec3 vec_normal; + uniform mat4 proj, model, view; -uniform vec4 lumpos; void main() { - 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; + pos_model = model * vec4(pos, 1); + 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 18e95a6..46c6a10 100644 --- a/src/manif.c +++ b/src/manif.c @@ -45,10 +45,11 @@ static void draw(void) { glUseProgram(_pId); 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 lum_loc = glGetUniformLocation(_pId, "lumpos"); + const GLfloat lumpos[] = {1, 2, 3, 1}; + GLint lum_loc = glGetUniformLocation(_pId, "lumpos"); glUniform4fv(lum_loc, 1, lumpos); gl4duBindMatrix(matrix_proj);