aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-08-06 15:48:20 +0000
committertaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-08-06 15:48:20 +0000
commit31606fee6eb5917e602103067b1f0d85ae1ff476 (patch)
tree15db6cf920dfb0f9a4adba14f9b57f7d82c8de5f
parent56564957104fbeaa1ba41698275a28d18a194c29 (diff)
Give the spotlight an ambient component
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@223 84d2e878-0bd5-11dd-ad15-13eda11d74c5
-rw-r--r--data/shaders/fill-light.frag2
-rw-r--r--data/shaders/lighting.frag11
-rw-r--r--src/render.c5
3 files changed, 9 insertions, 9 deletions
diff --git a/data/shaders/fill-light.frag b/data/shaders/fill-light.frag
index 249c881..eb89c79 100644
--- a/data/shaders/fill-light.frag
+++ b/data/shaders/fill-light.frag
@@ -41,7 +41,7 @@ void main() {
norm = normalize(normal);
/* Ambient */
- ambi = col_ambi_diff * gl_LightModel.ambient.rgb;
+ ambi = min(1.0, col_ambi_diff * (gl_LightModel.ambient.rgb + vec3(0.5, 0.5, 0.5)));
/* Emission */
emit = col_emit;
diff --git a/data/shaders/lighting.frag b/data/shaders/lighting.frag
index e47108f..ab13e52 100644
--- a/data/shaders/lighting.frag
+++ b/data/shaders/lighting.frag
@@ -51,9 +51,6 @@ void main() {
norm += (texture2D(normalmap, gl_TexCoord[0].st).rgb - vec3(0.5, 0.5, 0.5)) / 2.0;
}
- /* Ambient */
- ambi = col_ambi_diff * gl_LightModel.ambient.rgb;
-
/* Emission */
emit = col_emit;
@@ -65,15 +62,19 @@ void main() {
spot = max(dot(normalize(-light0vc), gl_LightSource[0].spotDirection), 0.0);
spot = pow(spot, gl_LightSource[0].spotExponent);
+ /* Ambient */
+ ambi = col_ambi_diff * (gl_LightModel.ambient.rgb + gl_LightSource[0].ambient*spot*falloff);
+
+ /* Diffuse */
diff_fac = max(0.0, dot(normalize(light0vc).xyz, norm));
+ diff += col_ambi_diff * gl_LightSource[0].diffuse.rgb * spot * falloff * diff_fac;
+ /* Specular */
L = normalize(gl_LightSource[0].position.xyz - pos);
E = normalize(-pos);
R = normalize(-reflect(L, norm));
spec_fac = max(0.0, dot(R, E));
spec_fac = pow(spec_fac, shininess);
-
- diff += col_ambi_diff * gl_LightSource[0].diffuse.rgb * spot * falloff * diff_fac;
spec += vec3(1.0, 1.0, 1.0) * gl_LightSource[0].specular.rgb * spot * falloff * spec_fac;
/* Light 1: Diffuse background glow */
diff --git a/src/render.c b/src/render.c
index 53d1716..e3b5a44 100644
--- a/src/render.c
+++ b/src/render.c
@@ -405,9 +405,6 @@ static void render_setup_lighting(Game *game) {
ambient[0] = 0.07; ambient[1] = 0.07; ambient[2] = 0.07; ambient[3] = 1.0;
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
- /* All lights have zero ambient (shader will ignore them) */
- ambient[0] = 0.0; ambient[1] = 0.0; ambient[2] = 0.0;
-
/* Lander craft's headlight */
pos[0] = game->lander->x;
pos[1] = game->lander->y;
@@ -424,6 +421,7 @@ static void render_setup_lighting(Game *game) {
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.02);
glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.005);
/* Headlight colours */
+ ambient[0] = 0.2; ambient[1] = 0.2; ambient[2] = 0.2;
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); /* Initialised to zero above */
diffuse[0] = 1.0; diffuse[1] = 1.0; diffuse[2] = 1.0; diffuse[3] = 1.0;
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
@@ -432,6 +430,7 @@ static void render_setup_lighting(Game *game) {
glEnable(GL_LIGHT0);
/* A very dim fill-in light. Adds a tiny amount of shape to things, and lifts the floor a little */
+ ambient[0] = 0.0; ambient[1] = 0.0; ambient[2] = 0.0;
glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); /* Initialised to zero above */
pos[0] = -1.0; pos[1] = 0.8; pos[2] = 4.0; pos[3] = 0.0;
glLightfv(GL_LIGHT1, GL_POSITION, pos);