From 31606fee6eb5917e602103067b1f0d85ae1ff476 Mon Sep 17 00:00:00 2001 From: taw27 Date: Wed, 6 Aug 2008 15:48:20 +0000 Subject: Give the spotlight an ambient component git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@223 84d2e878-0bd5-11dd-ad15-13eda11d74c5 --- data/shaders/fill-light.frag | 2 +- data/shaders/lighting.frag | 11 ++++++----- src/render.c | 5 ++--- 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); -- cgit v1.2.3