From 52697653c2b347f1562b74cc0e04e20e4a385f23 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 26 Mar 2019 06:08:28 +0100 Subject: [PATCH 1/3] =?UTF-8?q?glsl/parallax:=20ifless=20reflection=20mapp?= =?UTF-8?q?ing=20=F0=9F=A4=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/engine/renderer/glsl_source/reliefMapping_fp.glsl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/engine/renderer/glsl_source/reliefMapping_fp.glsl b/src/engine/renderer/glsl_source/reliefMapping_fp.glsl index dfe5dbbc8b..edc9921b91 100644 --- a/src/engine/renderer/glsl_source/reliefMapping_fp.glsl +++ b/src/engine/renderer/glsl_source/reliefMapping_fp.glsl @@ -302,6 +302,7 @@ vec2 ParallaxTexOffset(sampler2D normalMap, vec2 rayStartTexCoords, float parall float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + /* if(bestDepth > 0.996) // if no depth found yet { if(currentDepth >= heightMapDepth) @@ -309,6 +310,10 @@ vec2 ParallaxTexOffset(sampler2D normalMap, vec2 rayStartTexCoords, float parall bestDepth = currentDepth; } } + */ + + bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); } currentDepth = bestDepth; @@ -320,13 +325,17 @@ vec2 ParallaxTexOffset(sampler2D normalMap, vec2 rayStartTexCoords, float parall float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + /* if(currentDepth >= heightMapDepth) { bestDepth = currentDepth; currentDepth -= 2.0 * currentSize; } + */ - currentDepth += currentSize; + bool test = currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + currentDepth += int(test) * currentSize; } return bestDepth * displacement; From 0923683ced8ad52cb95d3eaeebe093a1a7f4bbaf Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 26 Mar 2019 06:31:28 +0100 Subject: [PATCH 2/3] =?UTF-8?q?glsl/parallax:=20forless=20reflection=20map?= =?UTF-8?q?ping=20=F0=9F=99=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../glsl_source/reliefMapping_fp.glsl | 143 +++++++++++++++++- 1 file changed, 139 insertions(+), 4 deletions(-) diff --git a/src/engine/renderer/glsl_source/reliefMapping_fp.glsl b/src/engine/renderer/glsl_source/reliefMapping_fp.glsl index edc9921b91..98750611b9 100644 --- a/src/engine/renderer/glsl_source/reliefMapping_fp.glsl +++ b/src/engine/renderer/glsl_source/reliefMapping_fp.glsl @@ -281,7 +281,9 @@ vec2 ParallaxTexOffset(sampler2D normalMap, vec2 rayStartTexCoords, float parall vec2 displacement = tangentViewDir.xy * -parallaxDepthScale / tangentViewDir.z; const int linearSearchSteps = 16; + /* const int binarySearchSteps = 6; + */ float depthStep = 1.0 / float(linearSearchSteps); float topDepth = 1.0 - parallaxOffsetBias; @@ -296,13 +298,13 @@ vec2 ParallaxTexOffset(sampler2D normalMap, vec2 rayStartTexCoords, float parall float bestDepth = 1.0; // search front to back for first point inside object + /* for(int i = 0; i < linearSearchSteps - 1; ++i) { currentDepth += currentSize; float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - /* if(bestDepth > 0.996) // if no depth found yet { if(currentDepth >= heightMapDepth) @@ -310,8 +312,102 @@ vec2 ParallaxTexOffset(sampler2D normalMap, vec2 rayStartTexCoords, float parall bestDepth = currentDepth; } } - */ + } + */ + { + currentDepth += currentSize; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + } + { + currentDepth += currentSize; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + } + { + currentDepth += currentSize; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + } + { + currentDepth += currentSize; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + } + { + currentDepth += currentSize; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + } + { + currentDepth += currentSize; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + } + { + currentDepth += currentSize; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + } + { + currentDepth += currentSize; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + } + { + currentDepth += currentSize; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + } + { + currentDepth += currentSize; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + } + { + currentDepth += currentSize; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + } + { + currentDepth += currentSize; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + } + { + currentDepth += currentSize; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + } + { + currentDepth += currentSize; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + } + { + currentDepth += currentSize; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + } + { + currentDepth += currentSize; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); } @@ -319,20 +415,59 @@ vec2 ParallaxTexOffset(sampler2D normalMap, vec2 rayStartTexCoords, float parall currentDepth = bestDepth; // recurse around first point (depth) for closest match + /* for(int i = 0; i < binarySearchSteps; ++i) { currentSize *= 0.5; float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - /* if(currentDepth >= heightMapDepth) { bestDepth = currentDepth; currentDepth -= 2.0 * currentSize; } - */ + } + */ + { + currentSize *= 0.5; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + currentDepth += int(test) * currentSize; + } + { + currentSize *= 0.5; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + currentDepth += int(test) * currentSize; + } + { + currentSize *= 0.5; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + currentDepth += int(test) * currentSize; + } + { + currentSize *= 0.5; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + currentDepth += int(test) * currentSize; + } + { + currentSize *= 0.5; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + bool test = currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + currentDepth += int(test) * currentSize; + } + { + currentSize *= 0.5; + float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; bool test = currentDepth >= heightMapDepth; bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); currentDepth += int(test) * currentSize; From dca3c68ecc9f75a0f936836a8a67347dde7a932d Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 26 Mar 2019 06:49:36 +0100 Subject: [PATCH 3/3] =?UTF-8?q?glsl/parallax:=20blockless=20reflection=20m?= =?UTF-8?q?apping=20=F0=9F=98=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../glsl_source/reliefMapping_fp.glsl | 255 ++++++++---------- 1 file changed, 117 insertions(+), 138 deletions(-) diff --git a/src/engine/renderer/glsl_source/reliefMapping_fp.glsl b/src/engine/renderer/glsl_source/reliefMapping_fp.glsl index 98750611b9..f96baa8459 100644 --- a/src/engine/renderer/glsl_source/reliefMapping_fp.glsl +++ b/src/engine/renderer/glsl_source/reliefMapping_fp.glsl @@ -315,102 +315,88 @@ vec2 ParallaxTexOffset(sampler2D normalMap, vec2 rayStartTexCoords, float parall } */ - { - currentDepth += currentSize; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - } - { - currentDepth += currentSize; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - } - { - currentDepth += currentSize; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - } - { - currentDepth += currentSize; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - } - { - currentDepth += currentSize; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - } - { - currentDepth += currentSize; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - } - { - currentDepth += currentSize; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - } - { - currentDepth += currentSize; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - } - { - currentDepth += currentSize; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - } - { - currentDepth += currentSize; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - } - { - currentDepth += currentSize; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - } - { - currentDepth += currentSize; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - } - { - currentDepth += currentSize; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - } - { - currentDepth += currentSize; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - } - { - currentDepth += currentSize; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - } - { - currentDepth += currentSize; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = bestDepth > 0.996 && currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - } + float heightMapDepth; + bool test; + + currentDepth += currentSize; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + + currentDepth += currentSize; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + + currentDepth += currentSize; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + + currentDepth += currentSize; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + + currentDepth += currentSize; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + + currentDepth += currentSize; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + + currentDepth += currentSize; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + + currentDepth += currentSize; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + + currentDepth += currentSize; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + + currentDepth += currentSize; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + + currentDepth += currentSize; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + + currentDepth += currentSize; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + + currentDepth += currentSize; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + + currentDepth += currentSize; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + + currentDepth += currentSize; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + + currentDepth += currentSize; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = bestDepth > 0.996 && currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); currentDepth = bestDepth; @@ -430,48 +416,41 @@ vec2 ParallaxTexOffset(sampler2D normalMap, vec2 rayStartTexCoords, float parall } */ - { - currentSize *= 0.5; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - currentDepth += int(test) * currentSize; - } - { - currentSize *= 0.5; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - currentDepth += int(test) * currentSize; - } - { - currentSize *= 0.5; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - currentDepth += int(test) * currentSize; - } - { - currentSize *= 0.5; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - currentDepth += int(test) * currentSize; - } - { - currentSize *= 0.5; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - currentDepth += int(test) * currentSize; - } - { - currentSize *= 0.5; - float heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; - bool test = currentDepth >= heightMapDepth; - bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); - currentDepth += int(test) * currentSize; - } + currentSize *= 0.5; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + currentDepth += int(test) * currentSize; + + currentSize *= 0.5; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + currentDepth += int(test) * currentSize; + + currentSize *= 0.5; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + currentDepth += int(test) * currentSize; + + currentSize *= 0.5; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + currentDepth += int(test) * currentSize; + + currentSize *= 0.5; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + currentDepth += int(test) * currentSize; + + currentSize *= 0.5; + heightMapDepth = topDepth - texture2D(normalMap, rayStartTexCoords + displacement * currentDepth).a; + test = currentDepth >= heightMapDepth; + bestDepth = (int(test) * currentDepth) + (int(!test) * bestDepth); + currentDepth += int(test) * currentSize; return bestDepth * displacement; }