diff --git a/assets/voxygen/shaders/fluid-frag/cheap.glsl b/assets/voxygen/shaders/fluid-frag/cheap.glsl index 05584aaccf..268b0a0b5d 100644 --- a/assets/voxygen/shaders/fluid-frag/cheap.glsl +++ b/assets/voxygen/shaders/fluid-frag/cheap.glsl @@ -53,18 +53,16 @@ layout(location = 1) out uvec4 tgt_mat; #include vec4 water_col(vec2 pos) { - pos = pos + focus_off.xy; - vec2 v = floor(f_vel); - float x0 = tick_loop(1, -v.x * 0.1, pos.x * 0.1); - float x1 = tick_loop(1, -(v.x + 1) * 0.1, pos.x * 0.1); - float y0 = tick_loop(1, -v.y * 0.1, pos.y * 0.1); - float y1 = tick_loop(1, -(v.y + 1) * 0.1, pos.y * 0.1); + pos += focus_off.xy; + pos *= 0.1; + vec2 v = floor(f_vel) * 0.1; + vec4 uv = tick_loop4(1, -v.xxyy - vec2(0, 0.1).xyxy, pos.xxyy); return 0.5 + (vec4( - textureLod(sampler2D(t_noise, s_noise), vec2(x0, y0), 0).x, - textureLod(sampler2D(t_noise, s_noise), vec2(x1, y0), 0).x, - textureLod(sampler2D(t_noise, s_noise), vec2(x0, y1), 0).x, - textureLod(sampler2D(t_noise, s_noise), vec2(x1, y1), 0).x + textureLod(sampler2D(t_noise, s_noise), uv.xz, 0).x, + textureLod(sampler2D(t_noise, s_noise), uv.yz, 0).x, + textureLod(sampler2D(t_noise, s_noise), uv.xw, 0).x, + textureLod(sampler2D(t_noise, s_noise), uv.yw, 0).x ) - 0.5) * 1.0; } diff --git a/assets/voxygen/shaders/fluid-frag/shiny.glsl b/assets/voxygen/shaders/fluid-frag/shiny.glsl index 56958ce57d..39b9946f17 100644 --- a/assets/voxygen/shaders/fluid-frag/shiny.glsl +++ b/assets/voxygen/shaders/fluid-frag/shiny.glsl @@ -55,14 +55,14 @@ layout(location = 1) out uvec4 tgt_mat; #include void wave_dx(vec2 pos, vec2 dir, float speed, float frequency, float factor, vec4 accumx, vec4 accumy, out vec4 wave, out vec4 dx) { - vec2 v = floor(f_vel); float ff = frequency * factor; - vec4 x = vec4( - tick_loop(2.0 * PI, speed - ff * (dir.x * v.x + dir.y * v.y), frequency * (dir.x * (factor * pos.x + accumx.x) + dir.y * (factor * pos.y + accumy.x))), - tick_loop(2.0 * PI, speed - ff * (dir.x * (v.x + 1.0) + dir.y * v.y), frequency * (dir.x * (factor * pos.x + accumx.y) + dir.y * (factor * pos.y + accumy.y))), - tick_loop(2.0 * PI, speed - ff * (dir.x * v.x + dir.y * (v.y + 1.0)), frequency * (dir.x * (factor * pos.x + accumx.z) + dir.y * (factor * pos.y + accumy.z))), - tick_loop(2.0 * PI, speed - ff * (dir.x * (v.x + 1.0) + dir.y * (v.y + 1.0)), frequency * (dir.x * (factor * pos.x + accumx.w) + dir.y * (factor * pos.y + accumy.w))) - ); + + vec2 v = floor(f_vel); + vec4 kx = (v.x + vec2(0, 1)).xyxy; + vec4 ky = (v.y + vec2(0, 1)).xxyy; + vec4 p = speed - ff * (dir.x * kx + dir.y * ky); + vec4 q = frequency * ((dir.x * factor * pos.x + accumx) + dir.y * (factor * pos.y + accumy)); + vec4 x = tick_loop4(2 * PI, p, q); wave = sin(x) + 0.5; wave *= wave; @@ -82,13 +82,13 @@ vec4 wave_height(vec2 pos) { const float speed_per_iter = 0.1; #if (FLUID_MODE == FLUID_MODE_HIGH) float speed = 1.0; - float factor = 0.2; + const float factor = 0.2; const float drag_factor = 0.035; const int iters = 21; const float scale = 15.0; #else float speed = 2.0; - float factor = 0.3; + const float factor = 0.3; const float drag_factor = 0.04; const int iters = 11; const float scale = 3.0; diff --git a/assets/voxygen/shaders/include/globals.glsl b/assets/voxygen/shaders/include/globals.glsl index 9c0ec2f248..41580c5d0d 100644 --- a/assets/voxygen/shaders/include/globals.glsl +++ b/assets/voxygen/shaders/include/globals.glsl @@ -54,6 +54,15 @@ float tick_loop(float period) { return tick_loop(period, 1.0, 0.0); } + +vec4 tick_loop4(float period, vec4 scale, vec4 offset) { + vec4 loop = tick_loop_time * scale; + vec4 rem = mod(loop, period); + vec4 rest = rem * tick.y; + + return mod(rest + tick.x * scale + offset, period); +} + // Only works if t happened within tick_loop_time float time_since(float t) { return tick.x < t ? (tick_loop_time - t + tick.x) : (tick.x - t);