From f6a200d0cb866196ba57697466755f9e0c7ea5d8 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 22 Nov 2019 10:09:00 +0000 Subject: [PATCH] Improved long-range depth precision, removed unnecessary LoD polygons --- assets/voxygen/shaders/include/lod.glsl | 4 ++-- assets/voxygen/shaders/include/sky.glsl | 2 ++ assets/voxygen/shaders/lod-terrain-frag.glsl | 3 ++- assets/voxygen/shaders/lod-terrain-vert.glsl | 2 +- assets/voxygen/shaders/terrain-frag.glsl | 2 +- voxygen/src/mesh/terrain.rs | 4 ++-- voxygen/src/scene/lod.rs | 16 +++++++++------- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/assets/voxygen/shaders/include/lod.glsl b/assets/voxygen/shaders/include/lod.glsl index 41549a79ab..6e8af1dee8 100644 --- a/assets/voxygen/shaders/include/lod.glsl +++ b/assets/voxygen/shaders/include/lod.glsl @@ -31,14 +31,14 @@ vec3 lod_norm(vec2 pos) { vec3 lod_col(vec2 pos) { vec3 warmth = mix( - vec3(0.05, 0.4, 0.15), + vec3(0.05, 0.4, 0.1), vec3(0.5, 0.4, 0.0), (texture(t_noise, pos * 0.0002).x - 0.5) * 2.0 + 0.5 ); vec3 color = mix( warmth, - vec3(0.5, 0.5, 0.5), + vec3(0.3, 0.3, 0.4), alt_at(pos) / 1200.0 ); diff --git a/assets/voxygen/shaders/include/sky.glsl b/assets/voxygen/shaders/include/sky.glsl index 39bb8c920f..1e1c104130 100644 --- a/assets/voxygen/shaders/include/sky.glsl +++ b/assets/voxygen/shaders/include/sky.glsl @@ -267,6 +267,8 @@ vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float q } float fog(vec3 f_pos, vec3 focus_pos, uint medium) { + return max(1.0 - 10000.0 / (1.0 + distance(f_pos.xy, focus_pos.xy)), 0.0); + float fog_radius = view_distance.x; float mist_radius = 10000000.0; diff --git a/assets/voxygen/shaders/lod-terrain-frag.glsl b/assets/voxygen/shaders/lod-terrain-frag.glsl index 119055e58c..1481b8b189 100644 --- a/assets/voxygen/shaders/lod-terrain-frag.glsl +++ b/assets/voxygen/shaders/lod-terrain-frag.glsl @@ -13,6 +13,7 @@ out vec4 tgt_color; void main() { vec3 f_norm = lod_norm(f_pos.xy); + vec3 f_col = lod_col(f_pos.xy); vec3 light, diffuse_light, ambient_light; @@ -22,7 +23,7 @@ void main() { float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x); vec4 clouds; vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, cam_pos.xyz, f_pos, 1.0, true, clouds); - vec3 color = mix(mix(surf_color, fog_color, 0.0), clouds.rgb, clouds.a); + vec3 color = mix(mix(surf_color, vec3(1), fog_level), clouds.rgb, clouds.a); tgt_color = vec4(color, 1.0); } diff --git a/assets/voxygen/shaders/lod-terrain-vert.glsl b/assets/voxygen/shaders/lod-terrain-vert.glsl index 996bc7c366..5801c5d0cf 100644 --- a/assets/voxygen/shaders/lod-terrain-vert.glsl +++ b/assets/voxygen/shaders/lod-terrain-vert.glsl @@ -25,5 +25,5 @@ void main() { proj_mat * view_mat * vec4(f_pos, 1); - gl_Position.z = 1.0 / (1.0 - gl_Position.z - 10.0); + gl_Position.z = 1.0 / (1.0 - gl_Position.z * 0.001 - 100.0); } diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index 615947d70a..263b9c0c46 100644 --- a/assets/voxygen/shaders/terrain-frag.glsl +++ b/assets/voxygen/shaders/terrain-frag.glsl @@ -36,7 +36,7 @@ void main() { float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x); vec4 clouds; vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, cam_pos.xyz, f_pos, 1.0, true, clouds); - vec3 color = mix(mix(surf_color, fog_color, 0.0), clouds.rgb, clouds.a); + vec3 color = mix(mix(surf_color, vec3(1), fog_level), clouds.rgb, clouds.a); tgt_color = vec4(color, 1.0); } diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index 50a76f1b55..12b26c2ed8 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -371,7 +371,7 @@ impl + ReadVol + Debug> Meshable + ReadVol + Debug> Meshable Self { Self { model: renderer - .create_model(&create_lod_terrain_mesh(100)) + .create_model(&create_lod_terrain_mesh(175)) .unwrap(), locals: renderer.create_consts(&[Locals::default()]).unwrap(), } @@ -31,12 +31,14 @@ fn create_lod_terrain_mesh(detail: usize) -> Mesh { for x in 0..detail { for y in 0..detail { - mesh.push_quad(Quad::new( - Vertex::new(Vec2::new(x + 0, y + 0).map(transform)), - Vertex::new(Vec2::new(x + 1, y + 0).map(transform)), - Vertex::new(Vec2::new(x + 1, y + 1).map(transform)), - Vertex::new(Vec2::new(x + 0, y + 1).map(transform)), - )); + if Vec2::new(x, y).map(transform).magnitude() <= 1.0 { + mesh.push_quad(Quad::new( + Vertex::new(Vec2::new(x + 0, y + 0).map(transform)), + Vertex::new(Vec2::new(x + 1, y + 0).map(transform)), + Vertex::new(Vec2::new(x + 1, y + 1).map(transform)), + Vertex::new(Vec2::new(x + 0, y + 1).map(transform)), + )); + } } }