diff options
author | RealBadAngel <maciej.kasatkin@o2.pl> | 2015-12-09 23:08:55 +0100 |
---|---|---|
committer | est31 <MTest31@outlook.com> | 2015-12-10 18:24:11 +0100 |
commit | a64d78a37e95b99f32c29c8dec2e0cdae85a8b41 (patch) | |
tree | 513bb8f6660132f71acc246597db5923d151d344 | |
parent | 696148e29889b2923f926b27f76979454676506d (diff) | |
download | minetest-a64d78a37e95b99f32c29c8dec2e0cdae85a8b41.tar.gz minetest-a64d78a37e95b99f32c29c8dec2e0cdae85a8b41.tar.bz2 minetest-a64d78a37e95b99f32c29c8dec2e0cdae85a8b41.zip |
Speed up and make more accurate relief mapping
using linear + binary search.
-rw-r--r-- | client/shaders/nodes_shader/opengl_fragment.glsl | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/client/shaders/nodes_shader/opengl_fragment.glsl b/client/shaders/nodes_shader/opengl_fragment.glsl index 424d32177..b3789e1cb 100644 --- a/client/shaders/nodes_shader/opengl_fragment.glsl +++ b/client/shaders/nodes_shader/opengl_fragment.glsl @@ -47,15 +47,29 @@ vec4 get_normal_map(vec2 uv) 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) |