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.frag19
1 files changed, 12 insertions, 7 deletions
diff --git a/data/shaders/lighting.frag b/data/shaders/lighting.frag
index 1bc0afd..39caf72 100644
--- a/data/shaders/lighting.frag
+++ b/data/shaders/lighting.frag
@@ -9,10 +9,11 @@
*
*/
+varying vec3 pos;
varying vec3 normal;
varying vec3 light0vc;
-varying vec3 light0hvc;
+varying vec3 light0half;
varying vec3 light1vc;
varying vec3 light2vc;
varying vec3 light2hvc;
@@ -61,22 +62,26 @@ void main() {
} else {
/* Spotlight (light 0) - positional, spotlight */
- float falloff;
- float spot;
- float ndothv;
+ float falloff, spot;
+ float spec_fac;
+ vec3 L, E, R;
- falloff = 1/ ( gl_LightSource[0].constantAttenuation
+ 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);
- ndothv = max(dot(norm, normalize(light0hvc)), 0.0);
+ L = normalize(gl_LightSource[0].position.xyz - pos);
+ E = normalize(-pos);
+ R = normalize(-reflect(L, norm));
+
+ spec_fac = max(0.0, dot(R, E));
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 * spot * falloff * pow(ndothv, 80.0);
+ spec += vec3(1.0, 1.0, 1.0) * gl_LightSource[0].specular.rgb * spot * falloff * pow(spec_fac, 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);