float find_intersection(vec2 dp, vec2 ds)
{
- const float depth_step = 1.0 / 24.0;
float depth = 1.0;
- for (int i = 0 ; i < 24 ; i++) {
+ float best_depth = 0.0;
+ float size = 0.0625;
+ for (int i = 0; i < 15; i++) {
+ depth -= size;
float h = texture2D(normalTexture, dp + ds * depth).a;
- if (h >= depth)
+ if (depth <= h) {
+ best_depth = depth;
break;
- depth -= depth_step;
+ }
}
- return depth;
+ depth = best_depth;
+ for (int i = 0; i < 4; i++) {
+ size *= 0.5;
+ float h = texture2D(normalTexture,dp + ds * depth).a;
+ if (depth <= h) {
+ best_depth = depth;
+ depth += size;
+ } else {
+ depth -= size;
+ }
+ }
+ return best_depth;
}
float find_intersectionRGB(vec2 dp, vec2 ds)