diff options
Diffstat (limited to 'data/shaders/lighting.frag')
-rw-r--r-- | data/shaders/lighting.frag | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/data/shaders/lighting.frag b/data/shaders/lighting.frag index 6e3fe65..1bc0afd 100644 --- a/data/shaders/lighting.frag +++ b/data/shaders/lighting.frag @@ -10,15 +10,12 @@ */ varying vec3 normal; -varying vec3 col_ambi_diff; -varying vec3 col_emit; varying vec3 light0vc; -varying vec3 light0half; -varying float light0dist; - +varying vec3 light0hvc; varying vec3 light1vc; varying vec3 light2vc; +varying vec3 light2hvc; uniform sampler2D texture; uniform sampler2D normalmap; @@ -29,6 +26,9 @@ uniform bool texture_enabled; uniform bool texture_emits; uniform float alpha; +varying vec3 col_ambi_diff; +varying vec3 col_emit; + void main() { vec3 ambi; @@ -48,37 +48,39 @@ void main() { /* Emission */ emit = col_emit; - - if ( fill_light_enabled ) { - /* Light 2: Fill-in light for lander */ - float diff_fac, spec_fac; + /* Fill-in light (light 2) */ + if ( fill_light_enabled ) { - diff_fac = max(dot(norm, normalize(light2vc)), 0.0); - diff += col_ambi_diff * gl_LightSource[2].diffuse.rgb * diff_fac; + float ndothv; + 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 { - /* Light 0: Lander craft's spotlight */ - float falloff, spot; - float diff_fac, spec_fac; - - falloff = 1.0 / ( gl_LightSource[0].constantAttenuation - + gl_LightSource[0].linearAttenuation * light0dist - + gl_LightSource[0].quadraticAttenuation * light0dist * light0dist ); + /* Spotlight (light 0) - positional, spotlight */ + float falloff; + float spot; + float ndothv; + falloff = 1/ ( 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(norm, normalize(light0vc))); - diff += col_ambi_diff * gl_LightSource[0].diffuse.rgb * spot * falloff * diff_fac; + ndothv = max(dot(norm, normalize(light0hvc)), 0.0); - //spec_fac = pow(max(0.0, dot(normalize(light0half), norm)), 80.0); - //spec += vec3(1.0, 1.0, 1.0) * gl_LightSource[0].specular.rgb * spot * falloff * spec_fac; + diff += col_ambi_diff * gl_LightSource[0].diffuse.rgb * spot * falloff * + max(dot(normalize(light0vc).xyz, norm), 0.0); - /* Light 1: Background glow */ - diff += col_ambi_diff * gl_LightSource[1].diffuse.rgb * max(0.0, dot(light1vc, norm)); + spec += vec3(1.0, 1.0, 1.0) * gl_LightSource[0].specular.rgb * spot * falloff * 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); + } if ( texture_enabled ) { |