From 8888190eb49e98429c666b22e5da2f8c4cdda5f0 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 9 Feb 2022 12:56:21 +0000 Subject: [PATCH] Added BareMinimum shader effect --- assets/voxygen/shaders/clouds-frag.glsl | 5 ++++ assets/voxygen/shaders/figure-frag.glsl | 6 +++++ assets/voxygen/shaders/include/lod.glsl | 19 +++++++++------- assets/voxygen/shaders/lod-terrain-frag.glsl | 5 ++++ assets/voxygen/shaders/lod-terrain-vert.glsl | 8 ++++--- assets/voxygen/shaders/particle-frag.glsl | 5 ++++ assets/voxygen/shaders/postprocess-frag.glsl | 5 ++++ assets/voxygen/shaders/skybox-frag.glsl | 6 +++-- assets/voxygen/shaders/sprite-frag.glsl | 5 ++++ assets/voxygen/shaders/sprite-vert.glsl | 24 ++++++++++++-------- assets/voxygen/shaders/terrain-frag.glsl | 6 +++++ assets/voxygen/shaders/terrain-vert.glsl | 6 +++-- voxygen/src/render/mod.rs | 3 +++ 13 files changed, 78 insertions(+), 25 deletions(-) diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index d0e080bf21..057dabe157 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -65,6 +65,11 @@ vec3 wpos_at(vec2 uv) { void main() { vec4 color = texture(sampler2D(t_src_color, s_src_color), uv); + #ifdef EXPERIMENTAL_BAREMINIMUM + tgt_color = vec4(color.rgb, 1); + return; + #endif + vec3 wpos = wpos_at(uv); float dist = distance(wpos, cam_pos.xyz); vec3 dir = (wpos - cam_pos.xyz) / dist; diff --git a/assets/voxygen/shaders/figure-frag.glsl b/assets/voxygen/shaders/figure-frag.glsl index 66b6a0e362..203e2b0f3b 100644 --- a/assets/voxygen/shaders/figure-frag.glsl +++ b/assets/voxygen/shaders/figure-frag.glsl @@ -95,6 +95,12 @@ void main() { float f_ao, f_glow; uint material = 0xFFu; vec3 f_col = greedy_extract_col_light_attr(t_col_light, s_col_light, f_uv_pos, f_ao, f_glow, material); + + #ifdef EXPERIMENTAL_BAREMINIMUM + tgt_color = vec4(f_col * f_ao, 1); + return; + #endif + // float /*f_light*/f_ao = textureProj(t_col_light, vec3(f_uv_pos, texSize)).a;//1.0;//f_col_light.a * 4.0;// f_light = float(v_col_light & 0x3Fu) / 64.0; // vec3 my_chunk_pos = (vec3((uvec3(f_pos_norm) >> uvec3(0, 9, 18)) & uvec3(0x1FFu)) - 256.0) / 2.0; diff --git a/assets/voxygen/shaders/include/lod.glsl b/assets/voxygen/shaders/include/lod.glsl index 169f4115af..5b755fbb4b 100644 --- a/assets/voxygen/shaders/include/lod.glsl +++ b/assets/voxygen/shaders/include/lod.glsl @@ -336,14 +336,17 @@ vec3 lod_pos(vec2 pos, vec2 focus_pos) { // Remove spiking by "pushing" vertices towards local optima vec2 delta = splay(pos); vec2 hpos = focus_pos + delta; - vec2 nhpos = hpos; - // vec2 lod_shift = splay(abs(pos) - 1.0 / view_distance.y); - float shift = 15.0;// min(lod_shift.x, lod_shift.y) * 0.5; - for (int i = 0; i < 3; i ++) { - // vec4 square = focus_pos.xy + vec4(splay(pos - vec2(1.0, 1.0), splay(pos + vec2(1.0, 1.0)))); - nhpos -= lod_norm(hpos).xy * shift; - } - hpos = hpos + normalize(nhpos - hpos + 0.001) * min(length(nhpos - hpos), 32); + + #ifndef EXPERIMENTAL_BAREMINIMUM + vec2 nhpos = hpos; + // vec2 lod_shift = splay(abs(pos) - 1.0 / view_distance.y); + float shift = 15.0;// min(lod_shift.x, lod_shift.y) * 0.5; + for (int i = 0; i < 3; i ++) { + // vec4 square = focus_pos.xy + vec4(splay(pos - vec2(1.0, 1.0), splay(pos + vec2(1.0, 1.0)))); + nhpos -= lod_norm(hpos).xy * shift; + } + hpos = hpos + normalize(nhpos - hpos + 0.001) * min(length(nhpos - hpos), 32); + #endif return vec3(hpos, alt_at_real(hpos)); } diff --git a/assets/voxygen/shaders/lod-terrain-frag.glsl b/assets/voxygen/shaders/lod-terrain-frag.glsl index 471e725563..12fd791860 100644 --- a/assets/voxygen/shaders/lod-terrain-frag.glsl +++ b/assets/voxygen/shaders/lod-terrain-frag.glsl @@ -46,6 +46,11 @@ void main() { // vec4 vert_pos4 = view_mat * vec4(f_pos, 1.0); // vec3 view_dir = normalize(-vec3(vert_pos4)/* / vert_pos4.w*/); + #ifdef EXPERIMENTAL_BAREMINIMUM + tgt_color = vec4(lod_col(f_pos.xy), 1); + return; + #endif + float my_alt = /*f_pos.z;*/alt_at_real(f_pos.xy); // vec3 f_pos = vec3(f_pos.xy, max(my_alt, f_pos.z)); /* gl_Position = diff --git a/assets/voxygen/shaders/lod-terrain-vert.glsl b/assets/voxygen/shaders/lod-terrain-vert.glsl index 6c50af35c1..da9f890bfd 100644 --- a/assets/voxygen/shaders/lod-terrain-vert.glsl +++ b/assets/voxygen/shaders/lod-terrain-vert.glsl @@ -33,9 +33,11 @@ layout(location = 2) out float pull_down; void main() { // Find distances between vertices. Pull down a tiny bit more to reduce z fighting near the ocean. f_pos = lod_pos(v_pos, focus_pos.xy) - vec3(0, 0, 0.1); - vec2 dims = vec2(1.0 / view_distance.y); - vec4 f_square = focus_pos.xyxy + vec4(splay(v_pos - dims), splay(v_pos + dims)); - f_norm = lod_norm(f_pos.xy, f_square); + #ifndef EXPERIMENTAL_BAREMINIMUM + vec2 dims = vec2(1.0 / view_distance.y); + vec4 f_square = focus_pos.xyxy + vec4(splay(v_pos - dims), splay(v_pos + dims)); + f_norm = lod_norm(f_pos.xy, f_square); + #endif // v_pos_orig = v_pos; // f_pos = lod_pos(focus_pos.xy + splay(v_pos) * /*1000000.0*/(1 << 20), square); diff --git a/assets/voxygen/shaders/particle-frag.glsl b/assets/voxygen/shaders/particle-frag.glsl index 3e5433341a..97f5b3e0d3 100644 --- a/assets/voxygen/shaders/particle-frag.glsl +++ b/assets/voxygen/shaders/particle-frag.glsl @@ -34,6 +34,11 @@ layout(location = 0) out vec4 tgt_color; const float FADE_DIST = 32.0; void main() { + #ifdef EXPERIMENTAL_BAREMINIMUM + tgt_color = vec4(f_col.rgb, 1); + return; + #endif + vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz); vec3 view_dir = -cam_to_frag; diff --git a/assets/voxygen/shaders/postprocess-frag.glsl b/assets/voxygen/shaders/postprocess-frag.glsl index 50059e245c..85616fe6ea 100644 --- a/assets/voxygen/shaders/postprocess-frag.glsl +++ b/assets/voxygen/shaders/postprocess-frag.glsl @@ -161,6 +161,11 @@ vec3 aa_sample(vec2 uv, vec2 off) { #endif void main() { + #ifdef EXPERIMENTAL_BAREMINIMUM + tgt_color = vec4(texture(sampler2D(t_src_color, s_src_color), uv).rgb, 1); + return; + #endif + /* if (medium.x == 1u) { uv = clamp(uv + vec2(sin(uv.y * 16.0 + tick.x), sin(uv.x * 24.0 + tick.x)) * 0.005, 0, 1); } */ diff --git a/assets/voxygen/shaders/skybox-frag.glsl b/assets/voxygen/shaders/skybox-frag.glsl index a007a0b8eb..af28a40aa9 100644 --- a/assets/voxygen/shaders/skybox-frag.glsl +++ b/assets/voxygen/shaders/skybox-frag.glsl @@ -25,8 +25,10 @@ layout(location = 0) in vec3 f_pos; layout(location = 0) out vec4 tgt_color; void main() { - // tgt_color = vec4(MU_SCATTER, 1.0); - // return; + #ifdef EXPERIMENTAL_BAREMINIMUM + tgt_color = vec4(get_sky_color(), 1); + return; + #endif vec3 cam_dir = normalize(f_pos - cam_pos.xyz); diff --git a/assets/voxygen/shaders/sprite-frag.glsl b/assets/voxygen/shaders/sprite-frag.glsl index c3a0ceb93c..d813ec590b 100644 --- a/assets/voxygen/shaders/sprite-frag.glsl +++ b/assets/voxygen/shaders/sprite-frag.glsl @@ -43,6 +43,11 @@ void main() { float f_ao, f_glow; vec3 f_col = greedy_extract_col_light_glow(t_col_light, s_col_light, f_uv_pos, f_ao, f_glow); + #ifdef EXPERIMENTAL_BAREMINIMUM + tgt_color = vec4(f_col * f_ao, 1); + return; + #endif + vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz); vec3 view_dir = -cam_to_frag; diff --git a/assets/voxygen/shaders/sprite-vert.glsl b/assets/voxygen/shaders/sprite-vert.glsl index 156a91380d..44ee20bfe8 100644 --- a/assets/voxygen/shaders/sprite-vert.glsl +++ b/assets/voxygen/shaders/sprite-vert.glsl @@ -82,21 +82,25 @@ void main() { // Transform info world space f_pos += chunk_offs; - // Terrain 'pop-in' effect - f_pos.z -= 250.0 * (1.0 - min(1.0001 - 0.02 / pow(tick.x - load_time, 10.0), 1.0)); + #ifndef EXPERIMENTAL_BAREMINIMUM + // Terrain 'pop-in' effect + f_pos.z -= 250.0 * (1.0 - min(1.0001 - 0.02 / pow(tick.x - load_time, 10.0), 1.0)); + #endif #ifdef EXPERIMENTAL_CURVEDWORLD f_pos.z -= pow(distance(f_pos.xy + focus_off.xy, focus_pos.xy + focus_off.xy) * 0.05, 2); #endif - // Wind sway effect - f_pos += model_wind_sway * vec3( - sin(tick.x * 1.5 + f_pos.y * 0.1) * sin(tick.x * 0.35), - sin(tick.x * 1.5 + f_pos.x * 0.1) * sin(tick.x * 0.25), - 0.0 - // NOTE: could potentially replace `v_pos.z * model_z_scale` with a calculation using `inst_chunk_pos` from below - //) * pow(abs(v_pos.z * model_z_scale), 1.3) * SCALE_FACTOR; - ) * v_pos.z * model_z_scale * SCALE_FACTOR; + #ifndef EXPERIMENTAL_BAREMINIMUM + // Wind sway effect + f_pos += model_wind_sway * vec3( + sin(tick.x * 1.5 + f_pos.y * 0.1) * sin(tick.x * 0.35), + sin(tick.x * 1.5 + f_pos.x * 0.1) * sin(tick.x * 0.25), + 0.0 + // NOTE: could potentially replace `v_pos.z * model_z_scale` with a calculation using `inst_chunk_pos` from below + //) * pow(abs(v_pos.z * model_z_scale), 1.3) * SCALE_FACTOR; + ) * v_pos.z * model_z_scale * SCALE_FACTOR; + #endif // Determine normal // TODO: do changes here effect perf on vulkan diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index 9e7153a91a..af0719fd61 100644 --- a/assets/voxygen/shaders/terrain-frag.glsl +++ b/assets/voxygen/shaders/terrain-frag.glsl @@ -86,6 +86,12 @@ void main() { // float f_light = textureProj(t_col_light, vec3(f_uv_pos + 0.5, textureSize(t_col_light, 0))).a;//1.0;//f_col_light.a * 4.0;// f_light = float(v_col_light & 0x3Fu) / 64.0; float f_light, f_glow; vec3 f_col = greedy_extract_col_light_glow(t_col_light, s_col_light, f_uv_pos, f_light, f_glow); + + #ifdef EXPERIMENTAL_BAREMINIMUM + tgt_color = vec4(f_col * f_light, 1); + return; + #endif + //float f_light = (uint(texture(t_col_light, (f_uv_pos + 0.5) / textureSize(t_col_light, 0)).r * 255.0) & 0x1Fu) / 31.0; // vec2 texSize = textureSize(t_col_light, 0); // float f_light = texture(t_col_light, f_uv_pos/* + vec2(atlas_offs.xy)*/).a;//1.0;//f_col_light.a * 4.0;// f_light = float(v_col_light & 0x3Fu) / 64.0; diff --git a/assets/voxygen/shaders/terrain-vert.glsl b/assets/voxygen/shaders/terrain-vert.glsl index 2073bf9b3c..2751b04d81 100644 --- a/assets/voxygen/shaders/terrain-vert.glsl +++ b/assets/voxygen/shaders/terrain-vert.glsl @@ -80,8 +80,10 @@ void main() { vec3 v_pos = f_pos; // Terrain 'pop-in' effect - v_pos.z -= 250.0 * (1.0 - min(1.0001 - 0.02 / pow(tick.x - load_time, 10.0), 1.0)); - // f_pos.z -= min(32.0, 25.0 * pow(distance(focus_pos.xy, f_pos.xy) / view_distance.x, 20.0)); + #ifndef EXPERIMENTAL_BAREMINIMUM + v_pos.z -= 250.0 * (1.0 - min(1.0001 - 0.02 / pow(tick.x - load_time, 10.0), 1.0)); + // f_pos.z -= min(32.0, 25.0 * pow(distance(focus_pos.xy, f_pos.xy) / view_distance.x, 20.0)); + #endif #ifdef EXPERIMENTAL_CURVEDWORLD v_pos.z -= pow(distance(v_pos.xy + focus_off.xy, focus_pos.xy + focus_off.xy) * 0.05, 2); diff --git a/voxygen/src/render/mod.rs b/voxygen/src/render/mod.rs index 3da8c2f4d8..19aad1168b 100644 --- a/voxygen/src/render/mod.rs +++ b/voxygen/src/render/mod.rs @@ -453,4 +453,7 @@ pub enum ExperimentalShader { NonSrgbDither, /// Use triangle PDF noise for dithering instead of uniform noise. TriangleNoiseDither, + /// Removes as many effects (including lighting) as possible in the name of + /// performance. + BareMinimum, }