turn off rain for CLOUD_MODE_NONE and adjust iterations

This commit is contained in:
IsseW 2022-06-12 01:42:29 +02:00
parent 80e29e2c20
commit e2969dc5f9
3 changed files with 101 additions and 89 deletions

View File

@ -97,63 +97,71 @@ void main() {
#if (CLOUD_MODE == CLOUD_MODE_NONE)
color.rgb = apply_point_glow(cam_pos.xyz + focus_off.xyz, dir, dist, color.rgb);
#endif
#else
vec3 old_color = color.rgb;
vec3 old_color = color.rgb;
dir = (vec4(dir, 0) * rel_rain_dir_mat).xyz;
dir = (vec4(dir, 0) * rel_rain_dir_mat).xyz;
float z = (-1 / (abs(dir.z) - 1) - 1) * sign(dir.z);
vec2 dir_2d = normalize(dir.xy);
vec2 view_pos = vec2(atan2(dir_2d.x, dir_2d.y), z);
float z = (-1 / (abs(dir.z) - 1) - 1) * sign(dir.z);
vec2 dir_2d = normalize(dir.xy);
vec2 view_pos = vec2(atan2(dir_2d.x, dir_2d.y), z);
vec3 cam_wpos = cam_pos.xyz + focus_off.xyz;
// Rain density is now only based on the cameras current position.
// This could be affected by a setting where rain_density_at is instead
// called each iteration of the loop. With the current implementation
// of rain_dir this has issues with being in a place where it doesn't rain
// and seeing rain.
if (medium.x == MEDIUM_AIR && rain_density > 0.0) {
float rain_dist = 50.0;
#if (CLOUD_MODE <= CLOUD_MODE_LOW)
int iterations = 2;
#elif (CLOUD_MODE == CLOUD_MODE_MEDIUM)
int iterations = 3;
#else
int iterations = 4;
#endif
vec3 cam_wpos = cam_pos.xyz + focus_off.xyz;
// Rain density is now only based on the cameras current position.
// This could be affected by a setting where rain_density_at is instead
// called each iteration of the loop. With the current implementation
// of rain_dir this has issues with being in a place where it doesn't rain
// and seeing rain.
if (medium.x == MEDIUM_AIR && rain_density > 0.0) {
float rain_dist = 50.0;
for (int i = 0; i < 4; i ++) {
float old_rain_dist = rain_dist;
rain_dist *= 0.3;
for (int i = 0; i < iterations; i ++) {
float old_rain_dist = rain_dist;
rain_dist *= 0.3;
vec2 drop_density = vec2(30, 1);
vec2 drop_density = vec2(30, 1);
vec2 rain_pos = (view_pos * rain_dist);
rain_pos.y += integrated_rain_vel;
vec2 rain_pos = (view_pos * rain_dist);
rain_pos.y += integrated_rain_vel;
vec2 cell = floor(rain_pos * drop_density) / drop_density;
vec2 cell = floor(rain_pos * drop_density) / drop_density;
float drop_depth = mix(
old_rain_dist,
rain_dist,
fract(hash(fract(vec4(cell, rain_dist, 0) * 0.1)))
);
vec3 rpos = vec3(vec2(dir_2d), view_pos.y) * drop_depth;
float dist_to_rain = length(rpos);
if (dist < dist_to_rain || cam_wpos.z + rpos.z > CLOUD_AVG_ALT) {
continue;
float drop_depth = mix(
old_rain_dist,
rain_dist,
fract(hash(fract(vec4(cell, rain_dist, 0) * 0.1)))
);
vec3 rpos = vec3(vec2(dir_2d), view_pos.y) * drop_depth;
float dist_to_rain = length(rpos);
if (dist < dist_to_rain || cam_wpos.z + rpos.z > CLOUD_AVG_ALT) {
continue;
}
if (dot(rpos * vec3(1, 1, 0.5), rpos) < 1.0) {
break;
}
float rain_density = rain_density * rain_occlusion_at(cam_pos.xyz + rpos.xyz) * 10.0;
if (rain_density < 0.001 || fract(hash(fract(vec4(cell, rain_dist, 0) * 0.01))) > rain_density) {
continue;
}
vec2 near_drop = cell + (vec2(0.5) + (vec2(hash(vec4(cell, 0, 0)), 0.5) - 0.5) * vec2(2, 0)) / drop_density;
vec2 drop_size = vec2(0.0008, 0.03);
float avg_alpha = (drop_size.x * drop_size.y) * 10 / 1;
float alpha = sign(max(1 - length((rain_pos - near_drop) / drop_size * 0.1), 0));
float light = sqrt(dot(old_color, vec3(1))) + (get_sun_brightness() + get_moon_brightness()) * 0.01;
color.rgb = mix(color.rgb, vec3(0.3, 0.4, 0.5) * light, mix(avg_alpha, alpha, min(1000 / dist_to_rain, 1)) * 0.25);
}
if (dot(rpos * vec3(1, 1, 0.5), rpos) < 1.0) {
break;
}
float rain_density = rain_density * rain_occlusion_at(cam_pos.xyz + rpos.xyz) * 10.0;
if (rain_density < 0.001 || fract(hash(fract(vec4(cell, rain_dist, 0) * 0.01))) > rain_density) {
continue;
}
vec2 near_drop = cell + (vec2(0.5) + (vec2(hash(vec4(cell, 0, 0)), 0.5) - 0.5) * vec2(2, 0)) / drop_density;
vec2 drop_size = vec2(0.0008, 0.03);
float avg_alpha = (drop_size.x * drop_size.y) * 10 / 1;
float alpha = sign(max(1 - length((rain_pos - near_drop) / drop_size * 0.1), 0));
float light = sqrt(dot(old_color, vec3(1))) + (get_sun_brightness() + get_moon_brightness()) * 0.01;
color.rgb = mix(color.rgb, vec3(0.3, 0.4, 0.5) * light, mix(avg_alpha, alpha, min(1000 / dist_to_rain, 1)) * 0.25);
}
}
#endif
tgt_color = vec4(color.rgb, 1);
}

View File

@ -149,27 +149,29 @@ void main() {
wave_sample_dist / slope
);
if (rain_density > 0 && surf_norm.z > 0.5) {
vec3 drop_density = vec3(2, 2, 2);
vec3 drop_pos = wave_pos + vec3(0, 0, -time_of_day.x * 0.025);
vec2 cell2d = floor(drop_pos.xy * drop_density.xy);
drop_pos.z += noise_2d(cell2d * 13.1) * 10;
drop_pos.z *= 0.5 + hash_fast(uvec3(cell2d, 0));
vec3 cell = vec3(cell2d, floor(drop_pos.z * drop_density.z));
#if (CLOUD_MODE != CLOUD_MODE_NONE)
if (rain_density > 0 && surf_norm.z > 0.5) {
vec3 drop_density = vec3(2, 2, 2);
vec3 drop_pos = wave_pos + vec3(0, 0, -time_of_day.x * 0.025);
vec2 cell2d = floor(drop_pos.xy * drop_density.xy);
drop_pos.z += noise_2d(cell2d * 13.1) * 10;
drop_pos.z *= 0.5 + hash_fast(uvec3(cell2d, 0));
vec3 cell = vec3(cell2d, floor(drop_pos.z * drop_density.z));
if (fract(hash(fract(vec4(cell, 0) * 0.01))) < rain_density * rain_occlusion_at(f_pos.xyz) * 50.0) {
vec3 off = vec3(hash_fast(uvec3(cell * 13)), hash_fast(uvec3(cell * 5)), 0);
vec3 near_cell = (cell + 0.5 + (off - 0.5) * 0.5) / drop_density;
if (fract(hash(fract(vec4(cell, 0) * 0.01))) < rain_density * rain_occlusion_at(f_pos.xyz) * 50.0) {
vec3 off = vec3(hash_fast(uvec3(cell * 13)), hash_fast(uvec3(cell * 5)), 0);
vec3 near_cell = (cell + 0.5 + (off - 0.5) * 0.5) / drop_density;
float dist = length((drop_pos - near_cell) / vec3(1, 1, 2));
float drop_rad = 0.125;
nmap.xy += (drop_pos - near_cell).xy
* max(1.0 - abs(dist - drop_rad) * 50, 0)
* 2500
* sign(dist - drop_rad)
* max(drop_pos.z - near_cell.z, 0);
float dist = length((drop_pos - near_cell) / vec3(1, 1, 2));
float drop_rad = 0.125;
nmap.xy += (drop_pos - near_cell).xy
* max(1.0 - abs(dist - drop_rad) * 50, 0)
* 2500
* sign(dist - drop_rad)
* max(drop_pos.z - near_cell.z, 0);
}
}
}
#endif
nmap = mix(f_norm, normalize(nmap), min(1.0 / pow(frag_dist, 0.75), 1));

View File

@ -234,33 +234,35 @@ void main() {
// Toggle to see rain_occlusion
// tgt_color = vec4(rain_occlusion_at(f_pos.xyz), 0.0, 0.0, 1.0);
// return;
if (rain_density > 0 && !faces_fluid && f_norm.z > 0.5) {
vec3 pos = f_pos + focus_off.xyz;
vec3 drop_density = vec3(2, 2, 2);
vec3 drop_pos = pos + vec3(pos.zz, 0) + vec3(0, 0, -tick.x * 1.0);
drop_pos.z += noise_2d(floor(drop_pos.xy * drop_density.xy) * 13.1) * 10;
vec2 cell2d = floor(drop_pos.xy * drop_density.xy);
drop_pos.z *= 0.5 + hash_fast(uvec3(cell2d, 0));
vec3 cell = vec3(cell2d, floor(drop_pos.z * drop_density.z));
#if (CLOUD_MODE != CLOUD_MODE_NONE)
if (rain_density > 0 && !faces_fluid && f_norm.z > 0.5) {
vec3 pos = f_pos + focus_off.xyz;
vec3 drop_density = vec3(2, 2, 2);
vec3 drop_pos = pos + vec3(pos.zz, 0) + vec3(0, 0, -tick.x * 1.0);
drop_pos.z += noise_2d(floor(drop_pos.xy * drop_density.xy) * 13.1) * 10;
vec2 cell2d = floor(drop_pos.xy * drop_density.xy);
drop_pos.z *= 0.5 + hash_fast(uvec3(cell2d, 0));
vec3 cell = vec3(cell2d, floor(drop_pos.z * drop_density.z));
if (fract(hash(fract(vec4(cell, 0) * 0.01))) < rain_density * rain_occlusion_at(f_pos.xyz) * 50.0) {
vec3 off = vec3(hash_fast(uvec3(cell * 13)), hash_fast(uvec3(cell * 5)), 0);
vec3 near_cell = (cell + 0.5 + (off - 0.5) * 0.5) / drop_density;
if (fract(hash(fract(vec4(cell, 0) * 0.01))) < rain_density * rain_occlusion_at(f_pos.xyz) * 50.0) {
vec3 off = vec3(hash_fast(uvec3(cell * 13)), hash_fast(uvec3(cell * 5)), 0);
vec3 near_cell = (cell + 0.5 + (off - 0.5) * 0.5) / drop_density;
float dist = length((drop_pos - near_cell) / vec3(1, 1, 2));
float drop_rad = 0.1;
float distort = max(1.0 - abs(dist - drop_rad) * 100, 0) * 1.5 * max(drop_pos.z - near_cell.z, 0);
k_a += distort;
k_d += distort;
k_s += distort;
f_norm.xy += (drop_pos - near_cell).xy
* max(1.0 - abs(dist - drop_rad) * 30, 0)
* 500.0
* max(drop_pos.z - near_cell.z, 0)
* sign(dist - drop_rad)
* max(drop_pos.z - near_cell.z, 0);
float dist = length((drop_pos - near_cell) / vec3(1, 1, 2));
float drop_rad = 0.1;
float distort = max(1.0 - abs(dist - drop_rad) * 100, 0) * 1.5 * max(drop_pos.z - near_cell.z, 0);
k_a += distort;
k_d += distort;
k_s += distort;
f_norm.xy += (drop_pos - near_cell).xy
* max(1.0 - abs(dist - drop_rad) * 30, 0)
* 500.0
* max(drop_pos.z - near_cell.z, 0)
* sign(dist - drop_rad)
* max(drop_pos.z - near_cell.z, 0);
}
}
}
#endif
// float sun_light = get_sun_brightness(sun_dir);
// float moon_light = get_moon_brightness(moon_dir);