diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index 933f73c465..c9bab30d1d 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -27,6 +27,7 @@ #include // This *MUST* come after `cloud.glsl`: it contains a function that depends on `cloud.glsl` when clouds are enabled #include +#include layout(set = 2, binding = 0) uniform texture2D t_src_color; @@ -60,6 +61,16 @@ vec3 wpos_at(vec2 uv) { } } +vec3 dir_at(vec2 uv) { + vec4 view_space = all_mat_inv * vec4((uv * 2.0 - 1.0) * vec2(1, -1), 0.0, 1.0); + view_space /= view_space.w; + return normalize(view_space.xyz); +} + +float invlerp(float a, float b, float v) { + return (v - a) / (b - a); +} + void main() { vec4 color = texture(sampler2D(t_src_color, s_src_color), uv); @@ -77,6 +88,40 @@ void main() { if (color.a < 1.0) { cloud_blend = 1.0 - color.a; dist = DIST_CAP; + //color.rgb = vec3(1, 0, 0); + + vec2 uv_refl = uv; + vec3 wpos_refl = wpos; + /* for (int i = 0; i < 10; i ++) { */ + /* uv_refl.y -= 0.1; */ + /* wpos_refl += reflect(dir, vec3(0, 0, 1)) * dist * 0.5; */ + /* if (distance(wpos_at(uv_refl), cam_pos.xyz) < distance(wpos_refl, cam_pos.xyz)) { */ + /* color.rgb = mix(color.rgb, texture(sampler2D(t_src_color, s_src_color), uv_refl).rgb, 0.9); */ + /* break; */ + /* } */ + /* } */ + + if (dir.z < 0.0) { + vec3 dir_mid = dir_at(vec2(0, 0));//normalize((all_mat_inv * vec4(0, 0, 0, 0)).xyz); + vec3 dir_right = dir_at(vec2(1, 0));//normalize((all_mat_inv * vec4(1, 0, 0, 0)).xyz); + vec3 dir_up = dir_at(vec2(0, 1));//normalize((all_mat_inv * vec4(0, -1, 0, 0)).xyz); + vec3 surf_norm = normalize(vec3((vec2(noise_3d(vec3((wpos.xy + focus_off.xy) * 0.1, tick.x * 0.3)).x, noise_3d(vec3((wpos.xy + focus_off.xy).yx * 0.1, tick.x * 0.3)).x) - 0.5) * 0.03, 1)); + vec3 refl_dir = reflect(dir, surf_norm); + + float right = invlerp(dir_mid.x, dir_right.x, refl_dir.x); + float up = invlerp(dir_mid.z, dir_up.z, refl_dir.z); + + vec2 new_uv = vec2(uv.x, up); + + float merge = clamp((1.0 - abs(new_uv.y - 0.5) * 2) * 3.5, 0, 0.75); + + //vec2 new_uv = uv * vec2(1, -1) + vec2(0, 1.1) / (1.0 + dist * 0.000001) + vec2(0, dir.z); + color.rgb = mix(color.rgb, texture(sampler2D(t_src_color, s_src_color), new_uv).rgb, merge); + wpos = wpos_at(new_uv); + dist = distance(wpos, cam_pos.xyz); + dir = (wpos - cam_pos.xyz) / dist; + cloud_blend = min(merge * 2.0, 1.0); + } } color.rgb = mix(color.rgb, get_cloud_color(color.rgb, dir, cam_pos.xyz, time_of_day.x, dist, 1.0), cloud_blend); diff --git a/voxygen/src/render/pipelines/fluid.rs b/voxygen/src/render/pipelines/fluid.rs index 6c89915927..a7fcccaf58 100644 --- a/voxygen/src/render/pipelines/fluid.rs +++ b/voxygen/src/render/pipelines/fluid.rs @@ -131,7 +131,7 @@ impl FluidPipeline { alpha: wgpu::BlendComponent { src_factor: wgpu::BlendFactor::One, dst_factor: wgpu::BlendFactor::One, - operation: wgpu::BlendOperation::Add, + operation: wgpu::BlendOperation::Min, }, }), write_mask: wgpu::ColorWrite::ALL,