plan
This commit is contained in:
parent
c4da7f3905
commit
34def9d200
3 changed files with 30 additions and 28 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
25
src/manif.c
25
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("<vs>shaders/manif.vs", "<fs>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);
|
||||
}
|
||||
|
|
Reference in a new issue