aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-06-04 17:12:50 +0000
committertaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-06-04 17:12:50 +0000
commitf30bb8be1f801d66590699e317fae455e35af3eb (patch)
tree70fb459c8ff2933fa5adbf05a2cf372c55c5b947
parent347c83d7467af1f21e7a85088936aa7a6da13cc3 (diff)
More matching non-shader graphics to shader graphics
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@70 84d2e878-0bd5-11dd-ad15-13eda11d74c5
-rw-r--r--data/models/lander2
-rw-r--r--data/shaders/lighting.frag32
-rw-r--r--src/glcheck.c2
-rw-r--r--src/render.c49
4 files changed, 57 insertions, 28 deletions
diff --git a/data/models/lander b/data/models/lander
index 56a4371..a95946c 100644
--- a/data/models/lander
+++ b/data/models/lander
@@ -347,7 +347,7 @@ colour 0.0 0.5 0.2
-0.10 0.35 0.05
HEMISPHERE
-colour 0.07 0.07 0.07
+colour 0.2 0.2 0.2
shiny 100.0
0.00 0.00 0.20
radius 0.25
diff --git a/data/shaders/lighting.frag b/data/shaders/lighting.frag
index e7a5b3b..4616feb 100644
--- a/data/shaders/lighting.frag
+++ b/data/shaders/lighting.frag
@@ -39,23 +39,27 @@ void main() {
/* Emission */
emit = col_emit;
-
- /* Spotlight (light 0) - positional, spotlight */
- float falloff = 1/ ( gl_LightSource[0].constantAttenuation
- + gl_LightSource[0].linearAttenuation * length(light0vc)
- + gl_LightSource[0].quadraticAttenuation * pow(length(light0vc), 2.0) );
- 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) */
if ( fill_light_enabled ) {
+
diff += col_ambi_diff * gl_LightSource[2].diffuse.rgb * max(dot(vec3(light1vc), norm), 0.0);
- spec += vec3(1.0, 1.0, 1.0) * gl_LightSource[2].specular.rgb * pow(ndothv, 80.0);
+ spec += gl_LightSource[2].specular.rgb * pow(ndothv, 80.0);
+
+ } else {
+
+ /* Spotlight (light 0) - positional, spotlight */
+ float falloff = 1/ ( gl_LightSource[0].constantAttenuation
+ + gl_LightSource[0].linearAttenuation * length(light0vc)
+ + gl_LightSource[0].quadraticAttenuation * pow(length(light0vc), 2.0) );
+ 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);
+
}
if ( texture_enabled ) {
diff --git a/src/glcheck.c b/src/glcheck.c
index 59ba4b2..9d375ee 100644
--- a/src/glcheck.c
+++ b/src/glcheck.c
@@ -122,9 +122,11 @@ static void glcheck_draw() {
GLfloat pos[] = { 0.0, 0.0, -2.0, 0.0 };
GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 };
+ GLfloat ambient[] = { 1.0, 1.0, 1.0, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
+ glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glEnable(GL_LIGHT0);
glRotatef(angle, 0.0, 1.0, 0.0);
diff --git a/src/render.c b/src/render.c
index 580c7ad..d64f2cf 100644
--- a/src/render.c
+++ b/src/render.c
@@ -325,6 +325,8 @@ static int render_model_instance_draw(ModelInstance *instance, Uint32 t, RenderC
glMaterialfv(GL_FRONT, GL_EMISSION, black);
glColor3f(1.0, 1.0, 1.0);
}
+
+ /* Set specular colour and shininess if required */
if ( p->attribs & ATTRIB_SHINY ) {
GLfloat white[] = {1.0, 1.0, 1.0, 1.0};
glMaterialfv(GL_FRONT, GL_SPECULAR, white);
@@ -404,7 +406,7 @@ static int render_model_instance_draw(ModelInstance *instance, Uint32 t, RenderC
if ( r->fbos ) {
glBindTexture(GL_TEXTURE_2D, r->fbotex);
glEnable(GL_TEXTURE_2D);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
if ( r->shaders ) glUniform1i(glGetUniformLocation(r->lighting_program, "texture_enabled"), 1);
if ( r->shaders ) glUniform1i(glGetUniformLocation(r->lighting_program, "texture_emits"), 1);
}
@@ -530,13 +532,13 @@ static void render_setup_lighting(Game *game) {
pos[1] = 0.8;
pos[2] = 4.0;
pos[3] = 0.0;
- diffuse[0] = 0.1;
- diffuse[1] = 0.1;
- diffuse[2] = 0.1;
+ diffuse[0] = 0.2;
+ diffuse[1] = 0.2;
+ diffuse[2] = 0.2;
diffuse[3] = 1.0;
- specular[0] = 0.01;
- specular[1] = 0.01;
- specular[2] = 0.01;
+ specular[0] = 0.8;
+ specular[1] = 0.8;
+ specular[2] = 0.8;
specular[3] = 1.0;
ambient[0] = 0.0;
ambient[1] = 0.0;
@@ -548,6 +550,27 @@ static void render_setup_lighting(Game *game) {
glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
glEnable(GL_LIGHT1);
+ pos[0] = -1.0;
+ pos[1] = 0.8;
+ pos[2] = 4.0;
+ pos[3] = 0.0;
+ diffuse[0] = 0.3;
+ diffuse[1] = 0.3;
+ diffuse[2] = 0.3;
+ diffuse[3] = 1.0;
+ specular[0] = 1.0;
+ specular[1] = 1.0;
+ specular[2] = 1.0;
+ specular[3] = 1.0;
+ ambient[0] = 0.0;
+ ambient[1] = 0.0;
+ ambient[2] = 0.0;
+ ambient[3] = 1.0;
+ glLightfv(GL_LIGHT2, GL_POSITION, pos);
+ glLightfv(GL_LIGHT2, GL_DIFFUSE, diffuse);
+ glLightfv(GL_LIGHT2, GL_SPECULAR, specular);
+ glLightfv(GL_LIGHT2, GL_AMBIENT, ambient);
+
}
void render_set_wireframe(int wireframe) {
@@ -711,18 +734,18 @@ void render_draw(Game *game, Uint32 t) {
render_draw_stuff(game, 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[] = { 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);
+ glDisable(GL_LIGHT0);
+ glDisable(GL_LIGHT1);
+ GLfloat amb[] = { 0.3, 0.3, 0.3, 1.0 };
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb);
glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ if ( r->shaders ) glUniform1i(glGetUniformLocation(game->render->lighting_program, "fill_light_enabled"), 1);
render_model_instance_draw(game->lander, t, r, NULL);
+ if ( r->shaders ) glUniform1i(glGetUniformLocation(game->render->lighting_program, "fill_light_enabled"), 0);
glPopClientAttrib();
if ( r->shaders ) glUniform1i(glGetUniformLocation(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);