From a0b70225f13afa534e6dbea37e46c2f46065a80f Mon Sep 17 00:00:00 2001 From: taw27 Date: Wed, 6 Aug 2008 11:57:49 +0000 Subject: Revert shaders to a previous working version git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@215 84d2e878-0bd5-11dd-ad15-13eda11d74c5 --- data/shaders/lighting.frag | 50 ++++++++++++++++++++++++---------------------- data/shaders/lighting.vert | 34 ++++++++++--------------------- 2 files changed, 37 insertions(+), 47 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 ) { diff --git a/data/shaders/lighting.vert b/data/shaders/lighting.vert index af80574..914d6ac 100644 --- a/data/shaders/lighting.vert +++ b/data/shaders/lighting.vert @@ -10,45 +10,33 @@ */ 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; -vec3 v4conv3(vec4 a) { - vec4 div = a/(a.w); - return div.xyz; -} +varying vec3 col_ambi_diff; +varying vec3 col_emit; void main() { - vec4 vert; - vec3 vert_to_light; - vec3 vert_to_eye; - - vert = gl_ModelViewMatrix * gl_Vertex; - normal = gl_NormalMatrix * gl_Normal; - /* Spotlight - positional light */ - vert_to_light = v4conv3(gl_LightSource[0].position - vert); - light0dist = length(vert_to_light); - light0vc = normalize(vert_to_light); - vert_to_eye = v4conv3(-vert); - light0half = normalize(normalize(vert_to_eye) + light0vc); + vec4 vert = gl_ModelViewMatrix * gl_Vertex; + light0vc = gl_LightSource[0].position.xyz - vert.xyz; + light0hvc = vec3(gl_LightSource[0].halfVector - vert); /* Diffuse "background glow" - this can be normalised only once, here, since 'position' * is really 'direction' and is the same for all vertices. */ - light1vc = normalize(v4conv3(gl_LightSource[1].position)); + light1vc = normalize(vec3(gl_LightSource[1].position)); /* Fill-in light */ - light2vc = normalize(v4conv3(gl_LightSource[2].position)); + light2vc = normalize(vec3(gl_LightSource[2].position)); + light2hvc = normalize(vec3(gl_LightSource[2].halfVector - vert)); /* Material properties */ + normal = gl_NormalMatrix * gl_Normal; col_ambi_diff = gl_Color.rgb; col_emit = gl_FrontMaterial.emission.rgb; -- cgit v1.2.3