Random depth for rain drops for better occlusion

This commit is contained in:
Joshua Barretto 2022-03-16 12:04:02 +00:00 committed by IsseW
parent 79cac935c8
commit bfb4769315
2 changed files with 21 additions and 14 deletions

View File

@ -114,19 +114,9 @@ void main() {
vec3 cam_wpos = cam_pos.xyz + focus_off.xyz;
float rain_dist = 150.0;
for (int i = 0; i < 7; i ++) {
float old_rain_dist = rain_dist;
rain_dist *= 0.3;
vec3 rpos = vec3(vec2(dir_2d), view_pos.y) * rain_dist;
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_at(cam_wpos.xy + rpos.xy) * rain_occlusion_at(cam_pos.xyz + rpos.xyz) * 10.0;
vec2 drop_density = vec2(30, 1);
vec2 drop_size = vec2(0.0008, 0.05);
@ -134,6 +124,23 @@ void main() {
rain_pos += vec2(0, tick.x * fall_rate + cam_wpos.z);
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;
}
if (dot(rpos * vec3(1, 1, 0.5), rpos) < 1.0) {
break;
}
float rain_density = rain_density_at(cam_wpos.xy + rpos.xy) * rain_occlusion_at(cam_pos.xyz + rpos.xyz) * 10.0;
if (fract(hash(fract(vec4(cell, rain_dist, 0) * 0.01))) > rain_density) {
continue;
}

View File

@ -16,7 +16,7 @@ uniform u_rain_occlusion {
float rain_occlusion_at(in vec3 fragPos)
{
float bias = 0.000;
float bias = 0.5;
float diskRadius = 0.01;
const vec3 sampleOffsetDirections[20] = vec3[]
(
@ -27,10 +27,10 @@ float rain_occlusion_at(in vec3 fragPos)
vec3( 0, 1, 1), vec3( 0, -1, 1), vec3( 0, -1, -1), vec3( 0, 1, -1)
);
vec4 rain_pos = occlusion_texture_mat * vec4(fragPos, 1.0);
vec4 rain_pos = occlusion_texture_mat * vec4(fragPos - vec3(0, 0, bias), 1.0);
float visibility = textureProj(sampler2DShadow(t_directed_occlusion_maps, s_directed_occlusion_maps), rain_pos);
return visibility;
}
#endif
#endif