diff options
-rw-r--r-- | src/renderergl2/glsl/lightall_fp.glsl | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/renderergl2/glsl/lightall_fp.glsl b/src/renderergl2/glsl/lightall_fp.glsl index d1155de4..d1182781 100644 --- a/src/renderergl2/glsl/lightall_fp.glsl +++ b/src/renderergl2/glsl/lightall_fp.glsl @@ -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; |