aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Barker <jesse.barker@linaro.org>2012-12-11 10:08:49 -0800
committerJesse Barker <jesse.barker@linaro.org>2012-12-11 10:08:49 -0800
commite111ecb6f946b4bbe22ed7b3d26437aa175c5fbe (patch)
treed29bed677b29c28d2ed8a1fd0ba46dc06567e1a0
parent711afadffe53d151872c160c9db64357bce6ef4b (diff)
downloadglmark2-e111ecb6f946b4bbe22ed7b3d26437aa175c5fbe.tar.gz
SceneRefract: Use the eye direction, rather than the light direction as the
incident vector for the front facing refraction. The light direction is still used to compute surface reflection for the specular component.
-rw-r--r--data/shaders/light-refract.frag10
1 files changed, 5 insertions, 5 deletions
diff --git a/data/shaders/light-refract.frag b/data/shaders/light-refract.frag
index 1dcd751..184ba29 100644
--- a/data/shaders/light-refract.frag
+++ b/data/shaders/light-refract.frag
@@ -12,12 +12,11 @@ void main()
const vec4 matSpecular = vec4(1.0, 1.0, 1.0, 1.0);
const float matShininess = 100.0;
const vec2 point_five = vec2(0.5);
- // Need the normalized light direction and surface normal vectors to
+ // Need the normalized eye direction and surface normal vectors to
// compute the refraction vector through the "front" surface of the object.
- vec3 light_direction = normalize(vertex_position.xyz/vertex_position.w -
- LightSourcePosition.xyz/LightSourcePosition.w);
+ vec3 eye_direction = normalize(-vertex_position.xyz);
vec3 normalized_normal = normalize(vertex_normal);
- vec3 front_refraction = refract(light_direction, normalized_normal, 1.5);
+ vec3 front_refraction = refract(eye_direction, normalized_normal, 1.5);
// Offset the base map coordinate by the refaction vector, and re-normalize
// to texture coordinate space [0, 1].
vec2 normcoord = (MapCoord.st + front_refraction.st + point_five) * point_five;
@@ -27,8 +26,9 @@ void main()
vec2 imagecoord = (normcoord + back_refraction.st + point_five) * point_five;
vec4 texel = texture2D(ImageMap, imagecoord);
// Add in a specular component
+ vec3 light_direction = normalize(vertex_position.xyz/vertex_position.w -
+ LightSourcePosition.xyz/LightSourcePosition.w);
vec3 reflection = reflect(light_direction, normalized_normal);
- vec3 eye_direction = normalize(-vertex_position.xyz);
float specularTerm = pow(max(0.0, dot(reflection, eye_direction)), matShininess);
vec4 specular = (lightSpecular * matSpecular);
gl_FragColor = (specular * specularTerm) + texel;