aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-05-25 22:12:04 +0000
committertaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-05-25 22:12:04 +0000
commit841a4d35b5f90abb569fdb8a79c7786e6c0a6123 (patch)
tree9ba313f2351c206cefcce2a054018f03ddec19fc
parent31b50dfc5ebfb3b2444cbea985195c24c8918ea2 (diff)
Shader fixes
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@42 84d2e878-0bd5-11dd-ad15-13eda11d74c5
-rw-r--r--data/shaders/lighting.frag20
-rw-r--r--data/shaders/lighting.vert2
-rw-r--r--src/render.c27
3 files changed, 27 insertions, 22 deletions
diff --git a/data/shaders/lighting.frag b/data/shaders/lighting.frag
index 77102e9..1008734 100644
--- a/data/shaders/lighting.frag
+++ b/data/shaders/lighting.frag
@@ -17,7 +17,8 @@ varying vec3 light2vc;
varying vec3 light2hvc;
uniform sampler2D texture;
-uniform int fill_light_enabled;
+uniform bool fill_light_enabled;
+uniform bool texture_enabled;
varying vec3 col_ambi_diff;
varying vec3 col_emit;
@@ -30,6 +31,7 @@ void main() {
vec3 spec = vec3(0.0, 0.0, 0.0);
vec3 norm = normalize(normal);
+ float ndothv = max(dot(norm, normalize(light2hvc)), 0.0);
/* Ambient */
ambi = col_ambi_diff * gl_LightModel.ambient.rgb;
@@ -37,22 +39,20 @@ void main() {
/* Emission */
emit = col_emit;
- /* Spotlight (light 0) - diffuse only, positional, spotlight */
+ /* Spotlight (light 0) - positional, spotlight */
float falloff = 1 - length(light0vc) * gl_LightSource[0].linearAttenuation;
float spot = max(dot(normalize(-light0vc), gl_LightSource[0].spotDirection), 0.0);
spot = pow(spot, gl_LightSource[0].spotExponent);
diff += col_ambi_diff * gl_LightSource[0].diffuse.rgb * spot * falloff * max(dot(normalize(light0vc).xyz, norm), 0.0);
+ spec += vec3(1.0, 1.0, 1.0) * gl_LightSource[0].specular.rgb * pow(ndothv, 80.0);
/* Background glow (light 1) - diffuse only, directional */
diff += col_ambi_diff * gl_LightSource[1].diffuse.rgb * max(dot(vec3(light1vc), norm), 0.0);
- /* Fill-in light (light 2) - this is the only one which has a specular component */
- if ( fill_light_enabled == 1 ) {
- /* Diffuse */
+ /* Fill-in light (light 2) */
+ if ( fill_light_enabled ) {
diff += col_ambi_diff * gl_LightSource[2].diffuse.rgb * max(dot(vec3(light1vc), norm), 0.0);
- /* Specular */
- float ndothv = max(dot(norm, normalize(light2hvc)), 0.0);
- spec = vec3(1.0, 1.0, 1.0) * gl_LightSource[2].specular.rgb * pow(ndothv, 80.0);
+ spec += vec3(1.0, 1.0, 1.0) * gl_LightSource[2].specular.rgb * pow(ndothv, 80.0);
}
gl_FragColor = vec4(min(emit.r + ambi.r + diff.r + spec.r, 1.0),
@@ -60,7 +60,9 @@ void main() {
min(emit.b + ambi.b + diff.b + spec.b, 1.0),
1.0);
- gl_FragColor *= texture2D(texture, gl_TexCoord[0].st);
+ if ( texture_enabled ) {
+ gl_FragColor *= texture2D(texture, gl_TexCoord[0].st);
+ }
}
diff --git a/data/shaders/lighting.vert b/data/shaders/lighting.vert
index 1817e9f..294d5ba 100644
--- a/data/shaders/lighting.vert
+++ b/data/shaders/lighting.vert
@@ -16,8 +16,6 @@ varying vec3 light1vc;
varying vec3 light2vc;
varying vec3 light2hvc;
-uniform int fill_light_enabled;
-
varying vec3 col_ambi_diff;
varying vec3 col_emit;
diff --git a/src/render.c b/src/render.c
index d07f2fc..3d92f31 100644
--- a/src/render.c
+++ b/src/render.c
@@ -229,7 +229,7 @@ static int render_model_instance_draw(ModelInstance *instance, Uint32 t, RenderC
int j;
Model *m;
GLfloat x, y, z;
- GLfloat black[] = {0.0, 0.0, 0.0};
+ GLfloat black[] = {0.0, 0.0, 0.0, 1.0};
int wibble;
if ( nvert == NULL ) nvert = &wibble;
@@ -249,7 +249,7 @@ static int render_model_instance_draw(ModelInstance *instance, Uint32 t, RenderC
if ( p->attribs & ATTRIB_PULSE ) {
float s;
s = fabsf(0.4*cosf(t * 0.001));
- GLfloat c[] = {s*p->col_r, s*p->col_g, s*p->col_b};
+ GLfloat c[] = {s*p->col_r, s*p->col_g, s*p->col_b, 1.0};
glMaterialfv(GL_FRONT, GL_EMISSION, c);
glColor3f(0.3, 0.3, 0.3);
} else if ( p->attribs & ATTRIB_COLOUR ) {
@@ -260,7 +260,7 @@ static int render_model_instance_draw(ModelInstance *instance, Uint32 t, RenderC
glColor3f(1.0, 1.0, 1.0);
}
if ( p->attribs & ATTRIB_SHINY ) {
- GLfloat white[] = {1.0, 1.0, 1.0};
+ GLfloat white[] = {1.0, 1.0, 1.0, 1.0};
glMaterialfv(GL_FRONT, GL_SPECULAR, white);
glMaterialf(GL_FRONT, GL_SHININESS, p->shininess);
} else {
@@ -282,7 +282,13 @@ static int render_model_instance_draw(ModelInstance *instance, Uint32 t, RenderC
glBindTexture(GL_TEXTURE_2D, texture->texname);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glUniform1iARB(glGetUniformLocationARB(r->lighting_program, "texture_enabled"), 1);
+
+ } else {
+ glUniform1iARB(glGetUniformLocationARB(r->lighting_program, "texture_enabled"), 0);
}
+ } else {
+ glUniform1iARB(glGetUniformLocationARB(r->lighting_program, "texture_enabled"), 0);
}
glBindBufferARB(GL_ARRAY_BUFFER, p->vertices_buffer);
@@ -323,6 +329,7 @@ static int render_model_instance_draw(ModelInstance *instance, Uint32 t, RenderC
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glUniform1iARB(glGetUniformLocationARB(r->lighting_program, "texture_enabled"), 0);
glDrawArrays(GL_QUADS, 0, HEMI_NUM_VERTICES);
*nvert += HEMI_NUM_VERTICES;
@@ -417,6 +424,7 @@ static void render_setup_lighting(Game *game) {
dir[0] = sinf(game->lander->yaw);
dir[1] = cosf(game->lander->yaw);
dir[2] = 0.0;
+ dir[3] = 1.0;
diffuse[0] = 1.0;
diffuse[1] = 1.0;
diffuse[2] = 1.0;
@@ -549,6 +557,7 @@ void render_draw(Game *game, Uint32 t) {
r = game->render;
+#if 0
/* First pass: Looking upwards */
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, r->fbo);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -565,6 +574,7 @@ void render_draw(Game *game, Uint32 t) {
GLfloat amb[] = { 1.0, 1.0, 1.0, 1.0 };
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb);
render_draw_stuff(game, t);
+#endif
/* Second pass: Main view */
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
@@ -583,6 +593,7 @@ void render_draw(Game *game, Uint32 t) {
sqrtf(2.0)*cosf(game->lander->yaw)*sinf(game->view_angle), sqrtf(2.0)*cosf(game->view_angle));
glUseProgramObjectARB(r->lighting_program);
glUniform1iARB(glGetUniformLocationARB(game->render->lighting_program, "texture"), 0);
+ glUniform1iARB(glGetUniformLocationARB(game->render->lighting_program, "texture_enabled"), 1);
glUniform1iARB(glGetUniformLocationARB(game->render->lighting_program, "fill_light_enabled"), 0);
render_setup_lighting(game);
render_draw_stuff(game, t);
@@ -590,24 +601,18 @@ void render_draw(Game *game, Uint32 t) {
/* Finally, draw the lander */
GLfloat pos[] = { -1.0, 0.8, 4.0, 0.0 };
GLfloat diffuse[] = { 0.4, 0.4, 0.4, 1.0 };
- GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 };
+ GLfloat specular[] = { 0.1, 0.1, 0.1, 1.0 };
glLightfv(GL_LIGHT2, GL_POSITION, pos);
glLightfv(GL_LIGHT2, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT2, GL_SPECULAR, specular);
glEnable(GL_LIGHT2);
- glUniform1iARB(glGetUniformLocationARB(game->render->lighting_program, "fill_light_enabled"), 1);
glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
- glEnable(GL_TEXTURE_GEN_S);
- glEnable(GL_TEXTURE_GEN_T);
- glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
- glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
render_model_instance_draw(game->lander, t, r, NULL);
glPopClientAttrib();
+ glUniform1iARB(glGetUniformLocationARB(game->render->lighting_program, "texture_enabled"), 0);
render_draw_line(game->lander->x, game->lander->y, game->lander->z, game->lander->x, game->lander->y, game->lander->z-200.0);
- glDisable(GL_TEXTURE_GEN_S);
- glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_LIGHT2);
glUseProgramObjectARB(0);