positional ligthing
This commit is contained in:
parent
b07c614411
commit
47a1dd5a04
2 changed files with 13 additions and 6 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Reference in a new issue