OpenGL2: Bit more parallax optimization.

This commit is contained in:
SmileTheory 2014-11-14 01:12:41 -08:00
parent d9e2184c1a
commit 89b719ec8d

View file

@ -103,6 +103,9 @@ float RayIntersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap)
// texture depth at best depth
float texDepth = 0.0;
float prevT = SampleDepth(normalMap, dp);
float prevTexDepth = prevT;
// search front to back for first point inside object
for(int i = 0; i < linearSearchSteps - 1; ++i)
{
@ -115,15 +118,16 @@ float RayIntersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap)
{
bestDepth = depth; // store best depth
texDepth = t;
prevTexDepth = prevT;
}
prevT = t;
}
depth = bestDepth;
#if !defined (USE_RELIEFMAP)
float prevDepth = depth - size;
float prevTexDepth = SampleDepth(normalMap, dp + ds * prevDepth);
bestDepth -= size * (prevDepth - prevTexDepth) / (size - texDepth + prevTexDepth);
float div = 1.0 / (1.0 + (prevTexDepth - texDepth) * float(linearSearchSteps));
bestDepth -= (depth - size - prevTexDepth) * div;
#else
// recurse around first point (depth) for closest match
for(int i = 0; i < binarySearchSteps; ++i)
@ -369,7 +373,7 @@ void main()
vec2 texCoords = var_TexCoords.xy;
#if defined(USE_PARALLAXMAP)
vec3 offsetDir = normalize(E * tangentToWorld);
vec3 offsetDir = viewDir * tangentToWorld;
offsetDir.xy *= -u_NormalScale.a / offsetDir.z;