aboutsummaryrefslogtreecommitdiff
path: root/data
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 /data
parent31b50dfc5ebfb3b2444cbea985195c24c8918ea2 (diff)
Shader fixes
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@42 84d2e878-0bd5-11dd-ad15-13eda11d74c5
Diffstat (limited to 'data')
-rw-r--r--data/shaders/lighting.frag20
-rw-r--r--data/shaders/lighting.vert2
2 files changed, 11 insertions, 11 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;