aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-08-06 11:57:50 +0000
committertaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-08-06 11:57:50 +0000
commita655a74010577609339013065eecdb9024f0aa1b (patch)
tree34e09bdada8c0b7fe0c9fe6deeef1619eda2927a
parent0e4e0572ca74b33c145a0baea6d46e82f60237b2 (diff)
Moving things around
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@217 84d2e878-0bd5-11dd-ad15-13eda11d74c5
-rw-r--r--data/shaders/lighting.frag35
-rw-r--r--data/shaders/lighting.vert11
2 files changed, 25 insertions, 21 deletions
diff --git a/data/shaders/lighting.frag b/data/shaders/lighting.frag
index 39caf72..7ec0d3e 100644
--- a/data/shaders/lighting.frag
+++ b/data/shaders/lighting.frag
@@ -50,41 +50,50 @@ void main() {
/* Emission */
emit = col_emit;
- /* Fill-in light (light 2) */
if ( fill_light_enabled ) {
- float ndothv;
+ float diff_fac, spec_fac;
+ vec3 L, E, R;
+
+ /* Light 2: Fill-in for lander craft */
+ L = normalize(gl_LightSource[2].position.xyz - pos);
+ E = normalize(-pos);
+ R = normalize(-reflect(L, norm));
+ diff_fac = max(0.0, dot(normalize(light2vc).xyz, norm));
+ spec_fac = max(0.0, dot(R, E));
+ spec_fac = pow(spec_fac, 80.0);
- ndothv = max(dot(norm, normalize(light2hvc)), 0.0);
- diff += col_ambi_diff * gl_LightSource[2].diffuse.rgb * max(dot(vec3(light1vc), norm), 0.0);
- spec += gl_LightSource[2].specular.rgb * pow(ndothv, 80.0);
+ diff += col_ambi_diff * gl_LightSource[2].diffuse.rgb * diff_fac;
+ spec += gl_LightSource[2].specular.rgb * spec_fac;
} else {
- /* Spotlight (light 0) - positional, spotlight */
float falloff, spot;
- float spec_fac;
+ float diff_fac, spec_fac;
vec3 L, E, R;
+ /* Light 0: Lander craft's spotlight */
falloff = 1.0 / ( gl_LightSource[0].constantAttenuation
+ gl_LightSource[0].linearAttenuation * length(light0vc)
+ gl_LightSource[0].quadraticAttenuation * pow(length(light0vc), 2.0) );
+
spot = max(dot(normalize(-light0vc), gl_LightSource[0].spotDirection), 0.0);
spot = pow(spot, gl_LightSource[0].spotExponent);
+ diff_fac = max(0.0, dot(normalize(light0vc).xyz, norm));
+
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, 80.0);
- diff += col_ambi_diff * gl_LightSource[0].diffuse.rgb * spot * falloff *
- max(dot(normalize(light0vc).xyz, norm), 0.0);
+ 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 * pow(spec_fac, 80.0);
+ spec += vec3(1.0, 1.0, 1.0) * gl_LightSource[0].specular.rgb * spot * falloff * spec_fac;
- /* Background glow (light 1) - diffuse only, directional */
- diff += col_ambi_diff * gl_LightSource[1].diffuse.rgb * max(dot(vec3(light1vc), norm), 0.0);
+ /* Light 1: Diffuse background glow */
+ diff += col_ambi_diff * gl_LightSource[1].diffuse.rgb * max(0.0, dot(vec3(light1vc), norm));
}
diff --git a/data/shaders/lighting.vert b/data/shaders/lighting.vert
index d9306e6..32aa176 100644
--- a/data/shaders/lighting.vert
+++ b/data/shaders/lighting.vert
@@ -13,10 +13,8 @@ varying vec3 pos;
varying vec3 normal;
varying vec3 light0vc;
-varying vec3 light0half;
varying vec3 light1vc;
varying vec3 light2vc;
-varying vec3 light2hvc;
varying vec3 col_ambi_diff;
varying vec3 col_emit;
@@ -29,17 +27,14 @@ void main() {
pos = vert.xyz;
normal = gl_NormalMatrix * gl_Normal;
- /* Spotlight - positional light */
+ /* Light 0: Lander craft's spotlight */
light0vc = gl_LightSource[0].position.xyz - vert.xyz; /* Don't normalise here */
- light0half = normalize(normalize(light0vc) + normalize(-vert.xyz));
- /* Diffuse "background glow" - this can be normalised only once, here, since 'position'
- * is really 'direction' and is the same for all vertices. */
+ /* Light 1: Diffuse background glow */
light1vc = normalize(vec3(gl_LightSource[1].position));
- /* Fill-in light */
+ /* Light 2: Fill-in light for lander */
light2vc = normalize(vec3(gl_LightSource[2].position));
- light2hvc = normalize(vec3(gl_LightSource[2].halfVector - vert));
/* Material properties */
col_ambi_diff = gl_Color.rgb;