WOW LUMIERE
This commit is contained in:
parent
a3f04eda2b
commit
b976dbb707
2 changed files with 23 additions and 13 deletions
|
@ -5,18 +5,25 @@ in vec3 vec_normal;
|
|||
|
||||
out vec4 fragColor;
|
||||
|
||||
const int max = 2; // should change in cpu too
|
||||
|
||||
uniform vec4 couleur;
|
||||
uniform vec4 lum_pos;
|
||||
uniform vec4 lum_pos[max];
|
||||
uniform mat4 view;
|
||||
uniform vec4 lum_color;
|
||||
uniform vec4 lum_color[max];
|
||||
|
||||
void main() {
|
||||
const vec3 vue = vec3(0, 0, -1);
|
||||
const vec4 soleil_color = vec4(0.81f, 0.78f, 0.66f, 1.0f);
|
||||
vec3 torche = normalize(pos_model.xyz - lum_pos.xyz);
|
||||
float intensite_lumineuse = clamp(dot(vec_normal, -torche), 0., 1.);
|
||||
vec3 reflet = (transpose(inverse(view)) * vec4(reflect(torche, vec_normal), 0)).xyz;
|
||||
float intensite_specularite = pow(clamp(dot(reflet, -vue), 0., 1.), 10);
|
||||
|
||||
fragColor = intensite_specularite * lum_color + 0.1 * soleil_color + 0.9 * intensite_lumineuse * couleur;
|
||||
fragColor = vec4(1);
|
||||
for(int i = 0; i < max; i++) {
|
||||
|
||||
vec3 torche = normalize(pos_model.xyz - lum_pos[i].xyz);
|
||||
float intensite_lumineuse = clamp(dot(vec_normal, -torche), 0., 1.);
|
||||
vec3 reflet = (transpose(inverse(view)) * vec4(reflect(torche, vec_normal), 0)).xyz;
|
||||
float intensite_specularite = pow(clamp(dot(reflet, -vue), 0., 1.), 10);
|
||||
|
||||
fragColor *= intensite_specularite * lum_color[i] + 0.1 * soleil_color + 0.9 * intensite_lumineuse * couleur;
|
||||
}
|
||||
}
|
||||
|
|
15
src/manif.c
15
src/manif.c
|
@ -9,7 +9,7 @@ struct manifestant {
|
|||
GLfloat ox, oz;
|
||||
};
|
||||
|
||||
#define HEROS_NUMBER 70
|
||||
#define HEROS_NUMBER 70 // should change in fragment shader too
|
||||
static struct manifestant _herosId[HEROS_NUMBER];
|
||||
|
||||
static const char *matrix_proj = "proj";
|
||||
|
@ -70,18 +70,21 @@ static void draw(void) {
|
|||
GLint couleur_gpu = glGetUniformLocation(_pId, "couleur");
|
||||
static double deplacement = 0;
|
||||
|
||||
const GLfloat lumpos[] = {1, (GLfloat)(2 + 2 * sin(deplacement)), 1, 1},
|
||||
lumcolor[] = {1, 0, 0, 1};
|
||||
glUniform4fv(glGetUniformLocation(_pId, "lum_pos"), 1, lumpos);
|
||||
glUniform4fv(glGetUniformLocation(_pId, "lum_color"), 1, lumcolor);
|
||||
const GLfloat lumpos[][4] = {{1, (GLfloat)(2 + 2 * sin(deplacement)), 1, 1},
|
||||
{-1, (GLfloat)(2 + 2 * sin(deplacement)), 1, 1}},
|
||||
lumcolor[][4] = {{1, 0, 0, 1}, {0, 0, 1, 1}};
|
||||
|
||||
glUniform4fv(glGetUniformLocation(_pId, "lum_pos"), 2, (float *)lumpos);
|
||||
glUniform4fv(glGetUniformLocation(_pId, "lum_color"), 2, (float *)lumcolor);
|
||||
|
||||
bindAndLoadf(matrix_proj);
|
||||
GLfloat ratio = (GLfloat)_dims[0] / (GLfloat)_dims[1];
|
||||
gl4duFrustumf(-1, 1, -ratio, ratio, 1, 1000);
|
||||
|
||||
bindAndLoadf(matrix_view);
|
||||
const GLfloat distance = 2;
|
||||
const GLfloat distance = 5;
|
||||
gl4duLookAtf(0, distance, distance, 0, 0, 0, 0, 1, 0);
|
||||
// gl4duRotatef(-30, 0, 1, 0);
|
||||
|
||||
bindAndLoadf(matrix_model);
|
||||
gl4duRotatef(-90, 1, 0, 0);
|
||||
|
|
Reference in a new issue