trying something with colors

This commit is contained in:
Mylloon 2023-05-12 18:14:54 +02:00
parent 59dcac9bac
commit 58321c76a5
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 21 additions and 15 deletions

View file

@ -5,7 +5,7 @@ in vec3 vec_normal;
out vec4 fragColor; out vec4 fragColor;
const int max = 1; // should change in cpu too const int max = 5; // should change in cpu too
uniform vec4 couleur; uniform vec4 couleur;
uniform vec4 lum_pos[max]; uniform vec4 lum_pos[max];
@ -16,13 +16,18 @@ void main() {
const vec3 vue = vec3(0, 0, -1); const vec3 vue = vec3(0, 0, -1);
const vec4 soleil_color = vec4(0.81f, 0.78f, 0.66f, 1.0f); const vec4 soleil_color = vec4(0.81f, 0.78f, 0.66f, 1.0f);
fragColor = vec4(1);
for(int i = 0; i < max; i++) { for(int i = 0; i < max; i++) {
vec3 torche = normalize(pos_model.xyz - lum_pos[i].xyz); vec3 torche = normalize(pos_model.xyz - lum_pos[i].xyz);
float intensite_lumineuse = clamp(dot(vec_normal, -torche), 0., 1.); float intensite_lumineuse = clamp(dot(vec_normal, -torche), 0., 1.);
vec3 reflet = (transpose(inverse(view)) * vec4(reflect(torche, vec_normal), 0)).xyz; vec3 reflet = (transpose(inverse(view)) * vec4(reflect(torche, vec_normal), 0)).xyz;
float intensite_specularite = pow(clamp(dot(reflet, -vue), 0., 1.), 10); 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; vec4 color = intensite_specularite * lum_color[i] + 0.1 * soleil_color + 0.9 * intensite_lumineuse * couleur;
if(i == 0) {
fragColor = color;
} else {
fragColor = mix(fragColor, color, i / 2.);
}
} }
} }

View file

@ -9,7 +9,7 @@ struct manifestant {
GLfloat ox, oz; GLfloat ox, oz;
}; };
#define HEROS_NUMBER 10 // should change in fragment shader too #define HEROS_NUMBER 5 // should change in fragment shader too
static struct manifestant _herosId[HEROS_NUMBER]; static struct manifestant _herosId[HEROS_NUMBER];
static const char *matrix_proj = "proj"; static const char *matrix_proj = "proj";
@ -76,14 +76,14 @@ static void draw(void) {
const GLfloat couleur_plan[] = {0.3f, 0.3f, 0.3f, 1}, const GLfloat couleur_plan[] = {0.3f, 0.3f, 0.3f, 1},
couleur_heros[] = {1, 1, 0, 1}; couleur_heros[] = {1, 1, 0, 1};
GLint couleur_gpu = glGetUniformLocation(_pId, "couleur"); GLint couleur_gpu = glGetUniformLocation(_pId, "couleur");
static double deplacement = 0; static float deplacement = 0;
bindAndLoadf(matrix_proj); bindAndLoadf(matrix_proj);
GLfloat ratio = (GLfloat)_dims[0] / (GLfloat)_dims[1]; GLfloat ratio = (GLfloat)_dims[0] / (GLfloat)_dims[1];
gl4duFrustumf(-1, 1, -ratio, ratio, 1, 1000); gl4duFrustumf(-1, 1, -ratio, ratio, 1, 1000);
bindAndLoadf(matrix_view); bindAndLoadf(matrix_view);
const GLfloat distance = 4; // distance from the scene const GLfloat distance = 10; // distance from the scene
gl4duLookAtf(0, distance, distance, 0, 0, 0, 0, 1, 0); gl4duLookAtf(0, distance, distance, 0, 0, 0, 0, 1, 0);
// gl4duRotatef(-90, 0, 1, 0); // rotation camera // gl4duRotatef(-90, 0, 1, 0); // rotation camera
@ -101,18 +101,19 @@ static void draw(void) {
for (int i = 0; i < HEROS_NUMBER; ++i) { for (int i = 0; i < HEROS_NUMBER; ++i) {
// Torchs // Torchs
// Position // Position
const GLfloat lumpos_i[] = {0, 1 + (float)deplacement, -0.5f, 0}; const GLfloat lumpos_i[] = {(_herosId[i].ox / 10) + (deplacement / 10), 1,
(_herosId[i].oz / 20) - 1, 0};
memcpy(lumpos[i], lumpos_i, sizeof(lumpos_i)); memcpy(lumpos[i], lumpos_i, sizeof(lumpos_i));
// Color // Color
const GLfloat lumcolor_red[] = {1, (float)deplacement, 0, 1}; const GLfloat lumcolor_red[] = {1, 0, 0, 1};
memcpy(lumcolor[i], lumcolor_red, sizeof(lumcolor_red)); memcpy(lumcolor[i], lumcolor_red, sizeof(lumcolor_red));
// Draw corps // Draw corps
bindAndLoadf(matrix_model); bindAndLoadf(matrix_model);
gl4duScalef(0.1f, 0.5f, 0.2f); gl4duScalef(0.1f, 0.5f, 0.2f);
gl4duTranslatef(0, 3, -1); gl4duTranslatef(0, 3, -1);
move(_herosId[i].ox + (float)deplacement, 0, _herosId[i].oz); move(_herosId[i].ox + deplacement, 0, _herosId[i].oz);
gl4duSendMatrices(); gl4duSendMatrices();
gl4dgDraw(_herosId[i].corps); gl4dgDraw(_herosId[i].corps);
@ -121,7 +122,7 @@ static void draw(void) {
bindAndLoadf(matrix_model); bindAndLoadf(matrix_model);
gl4duScalef(0.1f, 0.2f, 0.2f); gl4duScalef(0.1f, 0.2f, 0.2f);
gl4duTranslatef(0, 10.9f, -1); gl4duTranslatef(0, 10.9f, -1);
move(_herosId[i].ox + (float)deplacement, 0, _herosId[i].oz); move(_herosId[i].ox + deplacement, 0, _herosId[i].oz);
gl4duSendMatrices(); gl4duSendMatrices();
gl4dgDraw(_herosId[i].tete); gl4dgDraw(_herosId[i].tete);
@ -130,7 +131,7 @@ static void draw(void) {
bindAndLoadf(matrix_model); bindAndLoadf(matrix_model);
gl4duScalef(0.1f, 1, 0.05f); gl4duScalef(0.1f, 1, 0.05f);
gl4duTranslatef(0, 0, -1); gl4duTranslatef(0, 0, -1);
move(_herosId[i].ox + (float)deplacement, 0, _herosId[i].oz * part_mult); move(_herosId[i].ox + deplacement, 0, _herosId[i].oz * part_mult);
gl4duSendMatrices(); gl4duSendMatrices();
gl4dgDraw(_herosId[i].jambe_g); gl4dgDraw(_herosId[i].jambe_g);
@ -139,7 +140,7 @@ static void draw(void) {
bindAndLoadf(matrix_model); bindAndLoadf(matrix_model);
gl4duScalef(0.1f, 1, 0.05f); gl4duScalef(0.1f, 1, 0.05f);
gl4duTranslatef(0, 0, -7); gl4duTranslatef(0, 0, -7);
move(_herosId[i].ox + (float)deplacement, 0, _herosId[i].oz * part_mult); move(_herosId[i].ox + deplacement, 0, _herosId[i].oz * part_mult);
gl4duSendMatrices(); gl4duSendMatrices();
gl4dgDraw(_herosId[i].jambe_d); gl4dgDraw(_herosId[i].jambe_d);
@ -148,7 +149,7 @@ static void draw(void) {
bindAndLoadf(matrix_model); bindAndLoadf(matrix_model);
gl4duScalef(0.1f, 0.4f, 0.05f); gl4duScalef(0.1f, 0.4f, 0.05f);
gl4duTranslatef(0, 4, 1); gl4duTranslatef(0, 4, 1);
move(_herosId[i].ox + (float)deplacement, 0, _herosId[i].oz * part_mult); move(_herosId[i].ox + deplacement, 0, _herosId[i].oz * part_mult);
gl4duSendMatrices(); gl4duSendMatrices();
gl4dgDraw(_herosId[i].bras_g); gl4dgDraw(_herosId[i].bras_g);
@ -157,7 +158,7 @@ static void draw(void) {
bindAndLoadf(matrix_model); bindAndLoadf(matrix_model);
gl4duScalef(0.1f, 0.4f, 0.05f); gl4duScalef(0.1f, 0.4f, 0.05f);
gl4duTranslatef(0, 4, -8); gl4duTranslatef(0, 4, -8);
move(_herosId[i].ox + (float)deplacement, 0, _herosId[i].oz * part_mult); move(_herosId[i].ox + deplacement, 0, _herosId[i].oz * part_mult);
gl4duSendMatrices(); gl4duSendMatrices();
gl4dgDraw(_herosId[i].bras_d); gl4dgDraw(_herosId[i].bras_d);
@ -168,6 +169,6 @@ static void draw(void) {
glUniform4fv(glGetUniformLocation(_pId, "lum_color"), HEROS_NUMBER, glUniform4fv(glGetUniformLocation(_pId, "lum_color"), HEROS_NUMBER,
(float *)lumcolor); (float *)lumcolor);
deplacement += 0.4 * M_PI * dt; deplacement += (float)(0.4 * M_PI * dt);
glUseProgram(0); glUseProgram(0);
} }