Added SSR to wet surfaces

This commit is contained in:
Joshua Barretto 2022-10-22 16:37:25 +01:00
parent a7c24ed518
commit d0894a189e
4 changed files with 26 additions and 17 deletions

View File

@ -90,7 +90,6 @@ void main() {
// Apply clouds
float cloud_blend = 1.0;
bool is_reflection = false;
if (color.a < 1.0 && medium.x != MEDIUM_WATER) {
cloud_blend = 1.0 - color.a;
@ -155,14 +154,13 @@ void main() {
clamp((1.0 - abs(new_uv.y - 0.5) * 2) * 3.0, 0, 1),
// Depth merge factor
clamp((new_dist - dist * 0.5) / (dist * 0.5), 0.0, 1.0)
) * 0.85;
);
if (merge > 0.0) {
vec3 new_col = texture(sampler2D(t_src_color, s_src_color), new_uv).rgb;
new_col = get_cloud_color(new_col.rgb, refl_dir, wpos, time_of_day.x, distance(new_wpos, wpos.xyz), 1.0);
color.rgb = mix(color.rgb, new_col, merge);
color.rgb = mix(color.rgb, new_col, merge * (1.0 - color.a));
cloud_blend = 1;
is_reflection = true;
} else {
cloud_blend = 1;
}
@ -180,7 +178,7 @@ void main() {
#if (CLOUD_MODE == CLOUD_MODE_NONE)
color.rgb = apply_point_glow(cam_pos.xyz + focus_off.xyz, dir, dist, color.rgb);
#else
if (medium.x == MEDIUM_AIR && rain_density > 0.001 && !is_reflection) {
if (medium.x == MEDIUM_AIR && rain_density > 0.001) {
vec3 cam_wpos = cam_pos.xyz + focus_off.xyz;
vec3 adjusted_dir = (vec4(dir, 0) * rain_dir_mat).xyz;

View File

@ -165,16 +165,19 @@ void main() {
vec3 surf_color;
// If the figure is large enough to be 'terrain-like', we apply a noise effect to it
if (scale >= 0.5) {
float noise = hash(vec4(floor(m_pos * 3.0 - f_norm * 0.5), 0));
#ifndef EXPERIMENTAL_NONOISE
if (scale >= 0.5) {
float noise = hash(vec4(floor(m_pos * 3.0 - f_norm * 0.5), 0));
const float A = 0.055;
const float W_INV = 1 / (1 + A);
const float W_2 = W_INV * W_INV;
const float NOISE_FACTOR = 0.015;
vec3 noise_delta = (sqrt(f_col) * W_INV + noise * NOISE_FACTOR);
surf_color = noise_delta * noise_delta * W_2;
} else {
const float A = 0.055;
const float W_INV = 1 / (1 + A);
const float W_2 = W_INV * W_INV;
const float NOISE_FACTOR = 0.015;
vec3 noise_delta = (sqrt(f_col) * W_INV + noise * NOISE_FACTOR);
surf_color = noise_delta * noise_delta * W_2;
} else
#endif
{
surf_color = f_col;
}

View File

@ -672,8 +672,10 @@ void main() {
const vec3 underwater_col = vec3(0.0);
float min_refl = min(emitted_light.r, min(emitted_light.g, emitted_light.b));
surf_color = mix(underwater_col, surf_color, (1.0 - passthrough) * 1.0 / (1.0 + min_refl));
surf_alpha = passthrough;
#else
surf_alpha = 0.5;
#endif
surf_alpha = 0.99;
} else {
surf_color = illuminate(max_light, view_dir, f_col * emitted_light, f_col * reflected_light);
}

View File

@ -234,6 +234,11 @@ void main() {
// Toggle to see rain_occlusion
// tgt_color = vec4(rain_occlusion_at(f_pos.xyz), 0.0, 0.0, 1.0);
// return;
#ifdef EXPERIMENTAL_WETNESS
float f_alpha = 1.0;
#else
const float f_alpha = 1.0;
#endif
#if (CLOUD_MODE != CLOUD_MODE_NONE)
if (rain_density > 0 && !faces_fluid && f_norm.z > 0.5) {
vec3 pos = f_pos + focus_off.xyz;
@ -247,13 +252,14 @@ void main() {
#ifdef EXPERIMENTAL_WETNESS
float puddle = clamp((noise_2d((f_pos.xy + focus_off.xy + vec2(0.1, 0)) * 0.03) - 0.5) * 20.0, 0.0, 1.0)
* min(rain_density * 10.0, 1.0)
* clamp((f_sky_exposure - 0.9) * 50.0, 0.0, 1.0);
* clamp((f_sky_exposure - 0.95) * 50.0, 0.0, 1.0);
#else
const float puddle = 1.0;
#endif
#ifdef EXPERIMENTAL_WETNESS
if (puddle > 0.0) {
f_alpha = 1.0 - puddle * 0.1;
float h = (noise_2d((f_pos.xy + focus_off.xy) * 0.3) - 0.5) * sin(tick.x * 8.0 + f_pos.x * 3)
+ (noise_2d((f_pos.xy + focus_off.xy) * 0.6) - 0.5) * sin(tick.x * 3.5 - f_pos.y * 6);
float hx = (noise_2d((f_pos.xy + focus_off.xy + vec2(0.1, 0)) * 0.3) - 0.5) * sin(tick.x * 8.0 + f_pos.x * 3)
@ -525,5 +531,5 @@ void main() {
float f_select = (select_pos.w > 0 && select_pos.xyz == floor(f_pos - f_norm * 0.5)) ? 1.0 : 0.0;
surf_color += f_select * (surf_color + 0.1) * vec3(0.5, 0.5, 0.5);
tgt_color = vec4(surf_color, 1.0);
tgt_color = vec4(surf_color, f_alpha);
}