From 255f450ae9ac8763db4bede075fb409161ed57cc Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 23 Feb 2020 16:53:17 +0000 Subject: [PATCH] Better LoD precision --- assets/voxygen/shaders/include/lod.glsl | 24 ++++++++++++-------- assets/voxygen/shaders/lod-terrain-frag.glsl | 1 + assets/voxygen/shaders/lod-terrain-vert.glsl | 3 +++ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/assets/voxygen/shaders/include/lod.glsl b/assets/voxygen/shaders/include/lod.glsl index c732a0885a..c5612e6c84 100644 --- a/assets/voxygen/shaders/include/lod.glsl +++ b/assets/voxygen/shaders/include/lod.glsl @@ -25,8 +25,8 @@ float splay_scale(vec2 pos, float e) { } vec3 lod_pos(vec2 v_pos) { - vec2 hpos = focus_pos.xy + splay(v_pos, 5.0) * 1000000.0; - float splay = splay_scale(v_pos, 5.0); + vec2 hpos = focus_pos.xy + splay(v_pos, 8.0) * 1000000.0; + float splay = splay_scale(v_pos, 8.0) * 1.0; return vec3(hpos, ( alt_at(hpos) + alt_at(hpos + vec2(-1, 1) * splay) + @@ -37,21 +37,25 @@ vec3 lod_pos(vec2 v_pos) { } vec3 lod_norm(vec2 pos) { - float alt00 = alt_at(pos); - float alt10 = alt_at(pos + vec2(32, 0)); - float alt01 = alt_at(pos + vec2(0, 32)); - float slope = abs(alt00 - alt10) + abs(alt00 - alt01); + const float SAMPLE_W = 8; + + float altx0 = alt_at(pos + vec2(-1, 0) * SAMPLE_W); + float altx1 = alt_at(pos + vec2(1, 0) * SAMPLE_W); + float alty0 = alt_at(pos + vec2(0, -1) * SAMPLE_W); + float alty1 = alt_at(pos + vec2(0, 1) * SAMPLE_W); + float slope = abs(altx1 - altx0) + abs(alty0 - alty1); return normalize(vec3( - (alt00 - alt10) / 32, - (alt00 - alt01) / 32, - 32 / (slope + 0.00001) // Avoid NaN + (altx0 - altx1) / SAMPLE_W, + (alty0 - alty1) / SAMPLE_W, + SAMPLE_W / (slope + 0.00001) // Avoid NaN )); } vec3 lod_col(vec2 pos) { + //return vec3(1); return texture(t_map, pos_to_uv(pos)).rgb - + texture(t_noise, pos * 0.04 + texture(t_noise, pos * 0.01).xy * 2.0 + texture(t_noise, pos * 0.06).xy * 0.6).x * 0.1; + + (texture(t_noise, pos * 0.04 + texture(t_noise, pos * 0.005).xy * 2.0 + texture(t_noise, pos * 0.06).xy * 0.6).x - 0.5) * 0.1; vec3 warmth = mix( vec3(0.05, 0.4, 0.1), diff --git a/assets/voxygen/shaders/lod-terrain-frag.glsl b/assets/voxygen/shaders/lod-terrain-frag.glsl index bf53fe3297..6aa021c2f4 100644 --- a/assets/voxygen/shaders/lod-terrain-frag.glsl +++ b/assets/voxygen/shaders/lod-terrain-frag.glsl @@ -6,6 +6,7 @@ #include in vec3 f_pos; +in vec3 f_norm; out vec4 tgt_color; diff --git a/assets/voxygen/shaders/lod-terrain-vert.glsl b/assets/voxygen/shaders/lod-terrain-vert.glsl index 589a8f2a4d..3fe274a637 100644 --- a/assets/voxygen/shaders/lod-terrain-vert.glsl +++ b/assets/voxygen/shaders/lod-terrain-vert.glsl @@ -12,11 +12,14 @@ uniform u_locals { }; out vec3 f_pos; +out vec3 f_norm; out float f_light; void main() { f_pos = lod_pos(v_pos); + f_norm = lod_norm(f_pos.xy); + //f_pos.z -= 1.0 / pow(distance(focus_pos.xy, f_pos.xy) / (view_distance.x * 0.95), 20.0); //f_pos.z -= 100.0 * pow(1.0 + 0.01 / view_distance.x, -pow(distance(focus_pos.xy, f_pos.xy), 2.0));