From 7506dc2a4140385006f8a53db7640aad614cb95e Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Tue, 18 Jan 2022 23:06:02 +0000 Subject: [PATCH] Added procedural LoD detail shader --- assets/voxygen/shaders/include/lod.glsl | 34 ++++++++++++++++++++----- voxygen/src/render/mod.rs | 6 +++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/assets/voxygen/shaders/include/lod.glsl b/assets/voxygen/shaders/include/lod.glsl index e40da75ea8..9d3356d76e 100644 --- a/assets/voxygen/shaders/include/lod.glsl +++ b/assets/voxygen/shaders/include/lod.glsl @@ -313,7 +313,16 @@ vec3 lod_norm(vec2 f_pos/*vec3 pos*/, vec4 square) { vec3 lod_norm(vec2 f_pos/*vec3 pos*/) { const float SAMPLE_W = 32; - return lod_norm(f_pos, vec4(f_pos - vec2(SAMPLE_W), f_pos + vec2(SAMPLE_W))); + vec3 norm = lod_norm(f_pos, vec4(f_pos - vec2(SAMPLE_W), f_pos + vec2(SAMPLE_W))); + + #ifdef EXPERIMENTAL_PROCEDURALLODDETAIL + norm.xy += vec2( + textureLod(sampler2D(t_noise, s_noise), f_pos / 400, 0).x - 0.5, + textureLod(sampler2D(t_noise, s_noise), f_pos / 400 + 0.5, 0).x - 0.5 + ) * 0.35; + #endif + + return normalize(norm); } @@ -340,11 +349,24 @@ layout(set = 0, binding = 11) uniform sampler s_map; vec3 lod_col(vec2 pos) { - //return vec3(0, 0.5, 0); - // return /*linear_to_srgb*/vec3(alt_at(pos), textureBicubic(t_map, pos_to_tex(pos)).gb); - return /*linear_to_srgb*/(textureBicubic(t_map, s_map, pos_to_tex(pos)).rgb) - ;//+ (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; - //+ (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; + #ifdef EXPERIMENTAL_PROCEDURALLODDETAIL + pos += vec2( + textureLod(sampler2D(t_noise, s_noise), pos / 200, 0).x - 0.5, + textureLod(sampler2D(t_noise, s_noise), pos / 200 + 0.5, 0).x - 0.5 + ) * 64; + #endif + + vec3 col = textureBicubic(t_map, s_map, pos_to_tex(pos)).rgb; + + #ifdef EXPERIMENTAL_PROCEDURALLODDETAIL + col *= pow(vec3( + textureLod(sampler2D(t_noise, s_noise), pos / 50, 0).x, + textureLod(sampler2D(t_noise, s_noise), pos / 50 + 0.5, 0).x, + textureLod(sampler2D(t_noise, s_noise), pos / 50 + 0.5, 0).x + ), vec3(0.5)); + #endif + + return col; } #endif diff --git a/voxygen/src/render/mod.rs b/voxygen/src/render/mod.rs index 16c910d32e..d17502e66c 100644 --- a/voxygen/src/render/mod.rs +++ b/voxygen/src/render/mod.rs @@ -391,6 +391,10 @@ struct OtherModes { profiler_enabled: bool, } +/// Experimental shader modes. +/// +/// You can enable these using Voxygen's `settings.ron`. See +/// [here](https://book.veloren.net/players/voxygen.html#experimental-shaders) for more information. #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum ExperimentalShader { /// Add brick-like normal mapping to the world. @@ -402,4 +406,6 @@ pub enum ExperimentalShader { /// Remove the glow effect around point lights (this is *not* the same thing /// as bloom). NoPointGlow, + /// Adds extra detail to distant LoD (Level of Detail) terrain procedurally. + ProceduralLodDetail, }