From 51e2e4ef2277f6518f9cf7a46c89b068034788d2 Mon Sep 17 00:00:00 2001 From: taw27 Date: Wed, 6 Aug 2008 11:57:49 +0000 Subject: Drop back to Blinn-Phong specular lighting git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@213 84d2e878-0bd5-11dd-ad15-13eda11d74c5 --- data/shaders/lighting.frag | 18 +++++++----------- data/shaders/lighting.vert | 13 +++++++------ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/data/shaders/lighting.frag b/data/shaders/lighting.frag index a9febe4..d4cb035 100644 --- a/data/shaders/lighting.frag +++ b/data/shaders/lighting.frag @@ -9,18 +9,17 @@ * */ -varying vec3 pos; varying vec3 normal; +varying vec3 col_ambi_diff; +varying vec3 col_emit; varying vec3 light0vc; +varying vec3 light0half; varying float light0dist; varying vec3 light1vc; varying vec3 light2vc; -varying vec3 col_ambi_diff; -varying vec3 col_emit; - uniform sampler2D texture; uniform sampler2D normalmap; @@ -63,7 +62,6 @@ void main() { /* Light 0: Lander craft's spotlight */ float falloff, spot; float diff_fac, spec_fac; - vec3 E, R; falloff = 1/ ( gl_LightSource[0].constantAttenuation + gl_LightSource[0].linearAttenuation * light0dist @@ -75,14 +73,12 @@ void main() { diff_fac = max(0.0, dot(norm, normalize(light0vc))); diff += col_ambi_diff * gl_LightSource[0].diffuse.rgb * spot * falloff * diff_fac; - E = normalize(-pos); - R = normalize(-reflect(light0vc, norm)); - 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; + //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; /* Light 1: Background glow */ - diff += col_ambi_diff * gl_LightSource[1].diffuse.rgb * max(0.0, dot(vec3(light1vc), norm)); - + diff += col_ambi_diff * gl_LightSource[1].diffuse.rgb * max(0.0, dot(light1vc, norm)); + } if ( texture_enabled ) { diff --git a/data/shaders/lighting.vert b/data/shaders/lighting.vert index 0178530..99e9b37 100644 --- a/data/shaders/lighting.vert +++ b/data/shaders/lighting.vert @@ -9,20 +9,19 @@ * */ -varying vec3 pos; varying vec3 normal; +varying vec3 col_ambi_diff; +varying vec3 col_emit; varying vec3 light0vc; +varying vec3 light0half; varying float light0dist; varying vec3 light1vc; varying vec3 light2vc; -varying vec3 col_ambi_diff; -varying vec3 col_emit; - vec3 v4conv3(vec4 a) { - vec4 div = a/a.w; + vec4 div = a/(a.w); return div.xyz; } @@ -30,15 +29,17 @@ void main() { vec4 vert; vec3 vert_to_light; + vec3 vert_to_eye; vert = gl_ModelViewMatrix * gl_Vertex; - pos = v4conv3(vert); 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(vert_to_eye + vert_to_light); /* Diffuse "background glow" - this can be normalised only once, here, since 'position' * is really 'direction' and is the same for all vertices. */ -- cgit v1.2.3