diff options
author | SmileTheory <SmileTheory@gmail.com> | 2014-11-14 01:12:41 -0800 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2015-03-17 11:39:01 +0000 |
commit | 2a56a835b35d00b975bdaee659b3b9d1054671b4 (patch) | |
tree | 6d118d5b4b365cf488c9d9d64bc0f6f3e844238c /src/renderergl2 | |
parent | 25b77a481f5044dc9d8dd255ef77a101cf7f0638 (diff) |
OpenGL2: Bit more parallax optimization.
Diffstat (limited to 'src/renderergl2')
-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; |