win
This commit is contained in:
parent
08ea9a0e7b
commit
dd544c245e
5 changed files with 81 additions and 68 deletions
|
|
@ -31,12 +31,30 @@ vec4 PhongShading(void)
|
||||||
|
|
||||||
float ShadowCoef(void){
|
float ShadowCoef(void){
|
||||||
vec4 shadow_coord = vShadowCoord / vShadowCoord.w;
|
vec4 shadow_coord = vShadowCoord / vShadowCoord.w;
|
||||||
float view = shadow_coord.z;
|
float view = shadow_coord.z - 0.0001;
|
||||||
float light = texture2D(depth_texture, shadow_coord.xy).z;
|
vec2 d[4];
|
||||||
|
float light = 1.0;
|
||||||
float shadow_coef = 1.0;
|
float shadow_coef = 1.0;
|
||||||
|
int i;
|
||||||
|
|
||||||
if(vShadowCoord.w > 0.0){
|
d[0] = vec2(-0.94201624, -0.39906216);
|
||||||
shadow_coef = light < view ? 0.0 : 1.0;
|
d[1] = vec2(0.94558609, -0.76890725);
|
||||||
|
d[2] = vec2(-0.094184101, -0.92938870);
|
||||||
|
d[3] = vec2(0.34495938, 0.29387760);
|
||||||
|
|
||||||
|
light = texture2D(depth_texture, shadow_coord.xy).z;
|
||||||
|
|
||||||
|
for(i = 0; i < 4; i++){
|
||||||
|
vec2 p = shadow_coord.xy + d[i] / 700.0;
|
||||||
|
|
||||||
|
if(p.x < 0.0) continue;
|
||||||
|
if(p.y < 0.0) continue;
|
||||||
|
if(p.x > 1.0) continue;
|
||||||
|
if(p.y > 1.0) continue;
|
||||||
|
|
||||||
|
if(texture2D(depth_texture, p).z < view){
|
||||||
|
shadow_coef -= 0.2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return shadow_coef;
|
return shadow_coef;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <GearBox/Log.h>
|
#include <GearBox/Log.h>
|
||||||
#include <GearBox/GL.h>
|
#include <GearBox/GL.h>
|
||||||
|
#include <GearBox/Math.h>
|
||||||
|
|
||||||
GBClient GBClientCreate(GBEngine engine) {
|
GBClient GBClientCreate(GBEngine engine) {
|
||||||
GBClient client = malloc(sizeof(*client));
|
GBClient client = malloc(sizeof(*client));
|
||||||
|
|
@ -10,9 +11,9 @@ GBClient GBClientCreate(GBEngine engine) {
|
||||||
|
|
||||||
client->engine = engine;
|
client->engine = engine;
|
||||||
|
|
||||||
client->camera[0] = 2;
|
client->camera[0] = 5;
|
||||||
client->camera[1] = 1.5;
|
client->camera[1] = 5;
|
||||||
client->camera[2] = 2;
|
client->camera[2] = 5;
|
||||||
|
|
||||||
client->look_at[0] = 0;
|
client->look_at[0] = 0;
|
||||||
client->look_at[1] = 0;
|
client->look_at[1] = 0;
|
||||||
|
|
@ -38,62 +39,50 @@ void GBClientDestroy(GBClient client) {
|
||||||
GBLog(GBLogInfo, "Destroyed client");
|
GBLog(GBLogInfo, "Destroyed client");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static double r = 0;
|
||||||
|
|
||||||
static void scene(void) {
|
static void scene(void) {
|
||||||
glColor3f(1, 1, 1);
|
glColor3f(1, 1, 1);
|
||||||
|
|
||||||
|
int i;
|
||||||
|
double u = 1;
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(0, fabs(sin(r)), 1);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glNormal3f(0, 1, 0);
|
glNormal3f(0, -1, 0);
|
||||||
glVertex3f(-1, 0, -1);
|
for(i = 0; i < 4; i++) {
|
||||||
glVertex3f(-1, 0, 1);
|
glVertex3f(cos(90 * i / 180.0 * GBMathPi), u, sin(90 * i / 180.0 * GBMathPi));
|
||||||
glVertex3f(1, 0, 1);
|
|
||||||
glVertex3f(1, 0, -1);
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
glColor3f(1, 0, 0);
|
|
||||||
for(i = 0; i < 2; i++) {
|
|
||||||
glPushMatrix();
|
|
||||||
glRotatef(180 * i, 0, 1, 0);
|
|
||||||
glBegin(GL_QUADS);
|
|
||||||
glNormal3f(-1, 0, 0);
|
|
||||||
glVertex3f(-1, 0.5, 0.25);
|
|
||||||
glVertex3f(-1, 0, 0.25);
|
|
||||||
glVertex3f(1, 0, 0.25);
|
|
||||||
glVertex3f(1, 0.5, 0.25);
|
|
||||||
glEnd();
|
|
||||||
glPopMatrix();
|
|
||||||
}
|
}
|
||||||
glBegin(GL_QUADS);
|
|
||||||
glNormal3f(0, 1, 0);
|
|
||||||
glVertex3f(-1, 0.5, -0.25);
|
|
||||||
glVertex3f(-1, 0.5, 0.25);
|
|
||||||
glVertex3f(1, 0.5, 0.25);
|
|
||||||
glVertex3f(1, 0.5, -0.25);
|
|
||||||
glEnd();
|
glEnd();
|
||||||
|
for(i = 0; i < 4; i++) {
|
||||||
|
double n[3];
|
||||||
|
double v0[3];
|
||||||
|
double v1[3];
|
||||||
|
double v2[3];
|
||||||
|
|
||||||
glBegin(GL_QUADS);
|
v0[0] = 0;
|
||||||
glNormal3f(0, 1, 0);
|
v0[1] = 1 + u;
|
||||||
glVertex3f(-1, -0.5, 0.25);
|
v0[2] = 0;
|
||||||
glVertex3f(-1, -0.5, -0.25);
|
|
||||||
glVertex3f(1, -0.5, -0.25);
|
|
||||||
glVertex3f(1, -0.5, 0.25);
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
glBegin(GL_QUADS);
|
v1[0] = cos(90 * (i + 1) / 180.0 * GBMathPi);
|
||||||
glNormal3f(-1, 0, 0);
|
v1[1] = u;
|
||||||
glVertex3f(-1, 0.5, 0.25);
|
v1[2] = sin(90 * (i + 1) / 180.0 * GBMathPi);
|
||||||
glVertex3f(-1, 0.5, -0.25);
|
|
||||||
glVertex3f(-1, 0, -0.25);
|
|
||||||
glVertex3f(-1, 0, 0.25);
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
glBegin(GL_QUADS);
|
v2[0] = cos(90 * i / 180.0 * GBMathPi);
|
||||||
glNormal3f(1, 0, 0);
|
v2[1] = u;
|
||||||
glVertex3f(1, 0.5, -0.25);
|
v2[2] = sin(90 * i / 180.0 * GBMathPi);
|
||||||
glVertex3f(1, 0.5, 0.25);
|
|
||||||
glVertex3f(1, 0, 0.25);
|
GBMathNormal3x3(n, v0, v1, v2);
|
||||||
glVertex3f(1, 0, -0.25);
|
|
||||||
glEnd();
|
glBegin(GL_TRIANGLES);
|
||||||
|
glNormal3f(n[0], n[1], n[2]);
|
||||||
|
glVertex3f(v0[0], v0[1], v0[2]);
|
||||||
|
glVertex3f(v1[0], v1[1], v1[2]);
|
||||||
|
glVertex3f(v2[0], v2[1], v2[2]);
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBClientStep(GBClient client) {
|
void GBClientStep(GBClient client) {
|
||||||
|
|
@ -118,18 +107,24 @@ void GBClientStep(GBClient client) {
|
||||||
scene();
|
scene();
|
||||||
GBGLShadowAfterMapping(client->gl);
|
GBGLShadowAfterMapping(client->gl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glNormal3f(0, 1, 0);
|
||||||
|
glVertex3f(-10, -0, -10);
|
||||||
|
glVertex3f(-10, -0, 10);
|
||||||
|
glVertex3f(10, -0, 10);
|
||||||
|
glVertex3f(10, -0, -10);
|
||||||
|
glEnd();
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
scene();
|
scene();
|
||||||
GBGLShadowEnd(client->gl);
|
GBGLShadowEnd(client->gl);
|
||||||
|
|
||||||
client->engine->param->gl_swapbuffer();
|
client->engine->param->gl_swapbuffer();
|
||||||
|
|
||||||
static double r = 0;
|
client->light0[0] = cos(r) * 5;
|
||||||
|
client->light0[2] = sin(r) * 5;
|
||||||
client->camera[0] = cos(r) * 2;
|
|
||||||
client->camera[2] = sin(r) * 2;
|
|
||||||
|
|
||||||
client->light0[0] = -cos(r) * 5;
|
|
||||||
client->light0[2] = -sin(r) * 5;
|
|
||||||
|
|
||||||
r += 0.1;
|
r += 0.1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ void GBGLPerspective(GBGL gl, double width, double height) {
|
||||||
int i;
|
int i;
|
||||||
double fovy = 60.0;
|
double fovy = 60.0;
|
||||||
double znear = 0.01;
|
double znear = 0.01;
|
||||||
double zfar = 10.0;
|
double zfar = 100.0;
|
||||||
|
|
||||||
aspect = width / height;
|
aspect = width / height;
|
||||||
f = GBMathCot(fovy / 180 * GBMathPi / 2);
|
f = GBMathCot(fovy / 180 * GBMathPi / 2);
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
#include <GearBox/Math.h>
|
#include <GearBox/Math.h>
|
||||||
|
|
||||||
#define SHADOW_WIDTH 1024
|
#define SHADOW_WIDTH 512
|
||||||
#define SHADOW_HEIGHT 1024
|
#define SHADOW_HEIGHT 512
|
||||||
#define SHADOW_CULL
|
#define SHADOW_CULL
|
||||||
|
|
||||||
void GBGLShadowInit(GBGL gl) {
|
void GBGLShadowInit(GBGL gl) {
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ void GBMathNormal3x3(GBVector3 r, GBVector3 v0, GBVector3 v1, GBVector3 v2) {
|
||||||
GBVector3 t0, t1;
|
GBVector3 t0, t1;
|
||||||
|
|
||||||
GBMathSubtract3(t0, v1, v0);
|
GBMathSubtract3(t0, v1, v0);
|
||||||
GBMathSubtract3(t0, v2, v0);
|
GBMathSubtract3(t1, v2, v0);
|
||||||
|
|
||||||
GBMathCross3(r, t0, t1);
|
GBMathCross3(r, t0, t1);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue