aboutsummaryrefslogtreecommitdiff
path: root/data/shaders/lighting.frag
diff options
context:
space:
mode:
Diffstat (limited to 'data/shaders/lighting.frag')
-rw-r--r--data/shaders/lighting.frag34
1 files changed, 18 insertions, 16 deletions
diff --git a/data/shaders/lighting.frag b/data/shaders/lighting.frag
index 1bc0afd..5545b03 100644
--- a/data/shaders/lighting.frag
+++ b/data/shaders/lighting.frag
@@ -9,13 +9,14 @@
*
*/
+varying vec3 pos;
varying vec3 normal;
varying vec3 light0vc;
-varying vec3 light0hvc;
+varying float light0dist;
+
varying vec3 light1vc;
varying vec3 light2vc;
-varying vec3 light2hvc;
uniform sampler2D texture;
uniform sampler2D normalmap;
@@ -52,31 +53,32 @@ void main() {
/* Fill-in light (light 2) */
if ( fill_light_enabled ) {
- float ndothv;
+ float diff_fac, spec_fac;
+
+ diff_fac = max(dot(norm, normalize(light2vc)), 0.0);
+ diff += col_ambi_diff * gl_LightSource[2].diffuse.rgb * diff_fac;
- 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);
-
} else {
/* Spotlight (light 0) - positional, spotlight */
- float falloff;
- float spot;
- float ndothv;
+ float falloff, spot;
+ float diff_fac, spec_fac;
falloff = 1/ ( gl_LightSource[0].constantAttenuation
- + gl_LightSource[0].linearAttenuation * length(light0vc)
- + gl_LightSource[0].quadraticAttenuation * pow(length(light0vc), 2.0) );
+ + gl_LightSource[0].linearAttenuation * light0dist
+ + gl_LightSource[0].quadraticAttenuation * pow(light0dist, 2.0) );
+
spot = max(dot(normalize(-light0vc), gl_LightSource[0].spotDirection), 0.0);
spot = pow(spot, gl_LightSource[0].spotExponent);
- ndothv = max(dot(norm, normalize(light0hvc)), 0.0);
+ diff_fac = max(dot(norm, normalize(light0vc)), 0.0);
+ diff += col_ambi_diff * gl_LightSource[0].diffuse.rgb * spot * falloff * diff_fac;
- diff += col_ambi_diff * gl_LightSource[0].diffuse.rgb * spot * falloff *
- max(dot(normalize(light0vc).xyz, norm), 0.0);
+ vec3 E = normalize(-pos);
+ vec3 R = normalize(-reflect(light0vc, norm));
- spec += vec3(1.0, 1.0, 1.0) * gl_LightSource[0].specular.rgb * spot * falloff * pow(ndothv, 80.0);
+ spec_fac = pow(max(0.0, dot(R, E)), 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);