diff options
author | SmileTheory <SmileTheory@gmail.com> | 2014-11-10 22:11:36 -0800 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2015-03-17 11:39:01 +0000 |
commit | 25b77a481f5044dc9d8dd255ef77a101cf7f0638 (patch) | |
tree | 4fcc8f7864f82fa310244e3f83181a36e5d363da /src/renderergl2/glsl | |
parent | 6d2d70c7fd0d6f56269f611146e65a715aa7898a (diff) |
OpenGL2: Add support for parallax occlusion mapping.
Diffstat (limited to 'src/renderergl2/glsl')
-rw-r--r-- | src/renderergl2/glsl/lightall_fp.glsl | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/renderergl2/glsl/lightall_fp.glsl b/src/renderergl2/glsl/lightall_fp.glsl index f2da7821..d1155de4 100644 --- a/src/renderergl2/glsl/lightall_fp.glsl +++ b/src/renderergl2/glsl/lightall_fp.glsl @@ -100,6 +100,9 @@ float RayIntersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap) // best match found (starts with last position 1.0) float bestDepth = 1.0; + // texture depth at best depth + float texDepth = 0.0; + // search front to back for first point inside object for(int i = 0; i < linearSearchSteps - 1; ++i) { @@ -109,11 +112,19 @@ float RayIntersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap) if(bestDepth > 0.996) // if no depth found yet if(depth >= t) + { bestDepth = depth; // store best depth + texDepth = 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); +#else // recurse around first point (depth) for closest match for(int i = 0; i < binarySearchSteps; ++i) { @@ -129,6 +140,7 @@ float RayIntersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap) depth += size; } +#endif return bestDepth; } |