diff options
author | Jesse Barker <jesse.barker@linaro.org> | 2012-12-12 16:00:35 -0800 |
---|---|---|
committer | Jesse Barker <jesse.barker@linaro.org> | 2012-12-12 16:00:35 -0800 |
commit | b44efa6db340d984a623f6d03d1f451c06050037 (patch) | |
tree | dbeeda5d0f2da5987bd0a3e311d2782d91569bfe | |
parent | 11732cabe90df44a62936c73ea406791323597c6 (diff) | |
download | glmark2-b44efa6db340d984a623f6d03d1f451c06050037.tar.gz |
SceneRefract: What should be a more correct computation for the back refraction
based upon an approximation of the projection of the front refraction to a point
on the back of the object. Use that point to do the back refraction.
-rw-r--r-- | data/shaders/light-refract.frag | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/data/shaders/light-refract.frag b/data/shaders/light-refract.frag index b1b8562..f71a283 100644 --- a/data/shaders/light-refract.frag +++ b/data/shaders/light-refract.frag @@ -19,10 +19,14 @@ void main() 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; - vec4 back_normal = texture2D(NormalMap, normcoord); - // Now refract again, using the minus normal from the lookup. - vec3 back_refraction = refract(front_refraction, back_normal.xyz, 1.0); + vec4 mc_perspective = MapCoord / MapCoord.w; + vec4 distance_value = texture2D(DistanceMap, mc_perspective.st); + float frontToBack = distance_value.z - mc_perspective.z; + vec3 back_position = (front_refraction - vertex_position) + frontToBack; + vec2 normcoord = (mc_perspective.st + front_refraction.st + point_five) * point_five; + vec3 back_normal = texture2D(NormalMap, normcoord).xyz; + // Now refract again, using the normal from the lookup. + vec3 back_refraction = refract(back_position, back_normal.xyz, 1.0); vec2 imagecoord = (normcoord + back_refraction.st + point_five) * point_five; vec4 texel = texture2D(ImageMap, imagecoord); // Add in a specular component |