This commit is contained in:
Mylloon 2023-05-08 10:23:45 +02:00
parent c4da7f3905
commit 34def9d200
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 30 additions and 28 deletions

View file

@ -1,22 +1,8 @@
#version 330 #version 330
in vec4 mvpos; in float il;
in vec3 N;
out vec4 fragColor; out vec4 fragColor;
uniform vec4 scolor;
uniform vec4 lcolor;
uniform vec4 lumpos;
void main() { void main() {
vec4 ambient = 0.15f * lcolor * scolor; fragColor = il * vec4(0.35f, 0.35f, 0.43f, 1.0f);
vec3 Ld = normalize(mvpos.xyz - lumpos.xyz);
float ild = clamp(dot(normalize(N), -normalize(Ld)), 0, 1);
vec4 diffus = (ild * lcolor) * scolor;
vec3 R = reflect(Ld, N);
vec3 Vue = vec3(0, 0, -1);
float ils = pow(clamp(dot(R, -Vue), 0, 1), 10);
vec4 spec = ils * lcolor;
fragColor = ambient + diffus + spec;
} }

View file

@ -3,15 +3,12 @@
layout(location = 0) in vec3 pos; layout(location = 0) in vec3 pos;
layout(location = 1) in vec3 normal; layout(location = 1) in vec3 normal;
uniform mat4 proj; out float il;
uniform mat4 mod; uniform mat4 proj, model, view;
uniform mat4 view;
out vec4 mvpos;
out vec3 N;
void main() { void main() {
N = (inverse(transpose(mod)) * vec4(normal, 0)).xyz; vec3 Ld = normalize(vec3(0.0, -0.2, -1.0));
mvpos = view * mod * vec4(pos, 1.0); vec3 n = normalize(transpose(inverse(view * model)) * vec4(normal, 0.0)).xyz;
gl_Position = proj * mvpos; il = clamp(dot(n, -Ld), 0.0, 1.0);
gl_Position = proj * view * model * vec4(pos, 1.0);
} }

View file

@ -1,6 +1,7 @@
#include "../includes/animations.h" #include "../includes/animations.h"
static GLuint _pId = 0; static GLuint _pId = 0;
static GLuint _planId = 0;
static void init(void); static void init(void);
static void draw(void); static void draw(void);
@ -21,21 +22,39 @@ void manif(int state) {
} }
static void init(void) { static void init(void) {
_planId = gl4dgGenQuadf();
_pId = _pId =
gl4duCreateProgram("<vs>shaders/manif.vs", "<fs>shaders/manif.fs", NULL); gl4duCreateProgram("<vs>shaders/manif.vs", "<fs>shaders/manif.fs", NULL);
gl4duGenMatrix(GL_FLOAT, "proj"); gl4duGenMatrix(GL_FLOAT, "proj");
gl4duGenMatrix(GL_FLOAT, "mod"); gl4duGenMatrix(GL_FLOAT, "model");
gl4duGenMatrix(GL_FLOAT, "view"); gl4duGenMatrix(GL_FLOAT, "view");
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
} }
static void draw(void) { static void draw(void) {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearColor(0.2f, 0.2f, 0.8f, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(_pId);
/* */ gl4duBindMatrix("proj");
gl4duLoadIdentityf();
GLfloat ratio = (GLfloat)_dims[0] / (GLfloat)_dims[1];
gl4duFrustumf(-1, 1, -ratio, ratio, 1, 1000);
gl4duBindMatrix("view");
gl4duLoadIdentityf();
const GLfloat distance = 2;
gl4duLookAtf(0, distance, distance, 0, 0, 0, 0, 1, 0);
gl4duBindMatrix("model");
gl4duLoadIdentityf();
gl4duRotatef(-90, 1, 0, 0);
gl4duScalef(4 * distance, 2 * distance, 1);
gl4duSendMatrices();
gl4dgDraw(_planId);
glUseProgram(0); glUseProgram(0);
} }