diff --git a/shaders/manif.fs b/shaders/manif.fs index 9fee1c8..94a322a 100644 --- a/shaders/manif.fs +++ b/shaders/manif.fs @@ -1,22 +1,8 @@ #version 330 -in vec4 mvpos; -in vec3 N; - +in float il; out vec4 fragColor; -uniform vec4 scolor; -uniform vec4 lcolor; -uniform vec4 lumpos; - void main() { - vec4 ambient = 0.15f * lcolor * scolor; - 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; + fragColor = il * vec4(0.35f, 0.35f, 0.43f, 1.0f); } diff --git a/shaders/manif.vs b/shaders/manif.vs index a2e10de..2d8df71 100644 --- a/shaders/manif.vs +++ b/shaders/manif.vs @@ -3,15 +3,12 @@ layout(location = 0) in vec3 pos; layout(location = 1) in vec3 normal; -uniform mat4 proj; -uniform mat4 mod; -uniform mat4 view; - -out vec4 mvpos; -out vec3 N; +out float il; +uniform mat4 proj, model, view; void main() { - N = (inverse(transpose(mod)) * vec4(normal, 0)).xyz; - mvpos = view * mod * vec4(pos, 1.0); - gl_Position = proj * mvpos; + vec3 Ld = normalize(vec3(0.0, -0.2, -1.0)); + vec3 n = normalize(transpose(inverse(view * model)) * vec4(normal, 0.0)).xyz; + il = clamp(dot(n, -Ld), 0.0, 1.0); + gl_Position = proj * view * model * vec4(pos, 1.0); } diff --git a/src/manif.c b/src/manif.c index 15b06bf..c0d6af6 100644 --- a/src/manif.c +++ b/src/manif.c @@ -1,6 +1,7 @@ #include "../includes/animations.h" static GLuint _pId = 0; +static GLuint _planId = 0; static void init(void); static void draw(void); @@ -21,21 +22,39 @@ void manif(int state) { } static void init(void) { + _planId = gl4dgGenQuadf(); _pId = gl4duCreateProgram("shaders/manif.vs", "shaders/manif.fs", NULL); gl4duGenMatrix(GL_FLOAT, "proj"); - gl4duGenMatrix(GL_FLOAT, "mod"); + gl4duGenMatrix(GL_FLOAT, "model"); gl4duGenMatrix(GL_FLOAT, "view"); glEnable(GL_DEPTH_TEST); } 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); + 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); }