From 0e4e0572ca74b33c145a0baea6d46e82f60237b2 Mon Sep 17 00:00:00 2001 From: taw27 Date: Wed, 6 Aug 2008 11:57:50 +0000 Subject: Shuffle stuff around. Back to Phong... git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@216 84d2e878-0bd5-11dd-ad15-13eda11d74c5 --- data/shaders/lighting.frag | 19 ++++++++++++------- data/shaders/lighting.vert | 15 ++++++++++----- 2 files changed, 22 insertions(+), 12 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); diff --git a/data/shaders/lighting.vert b/data/shaders/lighting.vert index 914d6ac..d9306e6 100644 --- a/data/shaders/lighting.vert +++ b/data/shaders/lighting.vert @@ -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; @@ -22,10 +23,15 @@ varying vec3 col_emit; void main() { + vec4 vert; + + vert = gl_ModelViewMatrix * gl_Vertex; + pos = vert.xyz; + normal = gl_NormalMatrix * gl_Normal; + /* Spotlight - positional light */ - vec4 vert = gl_ModelViewMatrix * gl_Vertex; - light0vc = gl_LightSource[0].position.xyz - vert.xyz; - light0hvc = vec3(gl_LightSource[0].halfVector - vert); + light0vc = gl_LightSource[0].position.xyz - vert.xyz; /* Don't normalise here */ + light0half = normalize(normalize(light0vc) + normalize(-vert.xyz)); /* Diffuse "background glow" - this can be normalised only once, here, since 'position' * is really 'direction' and is the same for all vertices. */ @@ -36,7 +42,6 @@ void main() { 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