Improved SSR quality

This commit is contained in:
Joshua Barretto 2022-10-10 00:30:20 +01:00
parent daef86d813
commit 387d7e65d2
3 changed files with 26 additions and 9 deletions

View File

@ -49,7 +49,9 @@ uniform u_locals {
layout(location = 0) out vec4 tgt_color;
vec3 wpos_at(vec2 uv) {
float buf_depth = texture(sampler2D(t_src_depth, s_src_depth), uv).x;
uvec2 sz = textureSize(sampler2D(t_src_depth, s_src_depth), 0);
float buf_depth = texelFetch(sampler2D(t_src_depth, s_src_depth), clamp(ivec2(uv * sz), ivec2(0), ivec2(sz) - 1), 0).x;
//float buf_depth = texture(sampler2D(t_src_depth, s_src_depth), uv).x;
vec4 clip_space = vec4((uv * 2.0 - 1.0) * vec2(1, -1), buf_depth, 1.0);
vec4 view_space = all_mat_inv * clip_space;
view_space /= view_space.w;
@ -105,17 +107,30 @@ void main() {
vec3 dir_mid = dir_at(vec2(0, 0));
vec3 dir_right = dir_at(vec2(1, 0));
vec3 dir_up = dir_at(vec2(0, 1));
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));
vec2 nz = (vec2(
noise_3d(vec3((wpos.xy + focus_off.xy) * 0.1, tick.x * 0.2 + wpos.x * 0.01)).x,
noise_3d(vec3((wpos.yx + focus_off.yx) * 0.1, tick.x * 0.2 + wpos.y * 0.01)).x
) - 0.5) * 1.5;
vec3 surf_norm = normalize(vec3(nz * 0.03 / (1.0 + dist * 0.01), 1));
vec3 refl_dir = reflect(dir, surf_norm);
//float right = invlerp(atan2(dir_mid.x, dir_mid.y), atan2(dir_right.x, dir_right.y), atan2(refl_dir.x, refl_dir.y));
float up = invlerp(dir_mid.z, dir_up.z, refl_dir.z);
float up = invlerp(dir_mid.z, dir_up.z, refl_dir.z) + (cam_pos.z - wpos.z) / dist * 0.8;
vec2 new_uv = vec2(uv.x, up);
float look_z = dir_at(vec2(0.5, 0.5)).z;
float x_shift = (up - uv.y) * pow(abs(look_z), 0.5)
* sign(look_z) * 0.6
* (uv.x - 0.5) * (1.0 - pow(abs(uv.x - 0.5) * 2.0, 3.0));
vec2 new_uv = vec2(uv.x + x_shift, up);
float new_dist = distance(wpos_at(new_uv), cam_pos.xyz);
if (new_dist > dist) {
float merge = clamp((1.0 - abs(new_uv.y - 0.5) * 2) * 3.5, 0, 0.75);
if (new_dist > dist * 0.5) {
float merge = min(
// Off-screen merge factor
clamp((1.0 - abs(new_uv.y - 0.5) * 2) * 5.0, 0, 1.0),
// Depth merge factor
clamp((new_dist - dist * 0.5) / (dist * 0.5), 0.0, 1.0)
);
//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);
@ -130,7 +145,7 @@ void main() {
#else
{
#endif
dist = DIST_CAP;
//dist = DIST_CAP;
}
}
color.rgb = mix(color.rgb, get_cloud_color(color.rgb, dir, cam_pos.xyz, time_of_day.x, dist, 1.0), cloud_blend);

View File

@ -107,7 +107,7 @@ vec4 wave_height(vec4 posx, vec4 posy) {
return w / ws * 5.0;
}
float wave_height_vel(vec2 pos){
float wave_height_vel(vec2 pos) {
vec4 heights = wave_height(
pos.x - tick.x * floor(f_vel.x) - vec2(0.0, tick.x).xyxy,
pos.y - tick.x * floor(f_vel.y) - vec2(0.0, tick.x).xxyy

View File

@ -648,6 +648,7 @@ void main() {
// vec3 surf_color = illuminate(f_col, light, diffuse_light, ambient_light);
// f_col = f_col + (hash(vec4(floor(vec3(focus_pos.xy + splay(v_pos_orig), f_pos.z)) * 3.0 - round(f_norm) * 0.5, 0)) - 0.5) * 0.05; // Small-scale noise
vec3 surf_color;
float surf_alpha = 1.0;
#if (FLUID_MODE >= FLUID_MODE_MEDIUM)
if (length(f_col_raw - vec3(0.02, 0.06, 0.22)) < 0.025 && dot(vec3(0, 0, 1), f_norm) > 0.9) {
vec3 water_color = (1.0 - MU_WATER) * MU_SCATTER;
@ -671,6 +672,7 @@ 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 = 0.99;
} else {
surf_color = illuminate(max_light, view_dir, f_col * emitted_light, f_col * reflected_light);
}
@ -683,5 +685,5 @@ void main() {
// color = mix(color, vec3(1.0) * /*diffuse_light*/reflected_light, clamp(mist_factor * 0.00005 * distance(f_pos.xy, focus_pos.xy), 0, 0.3));
// color = surf_color;
tgt_color = vec4(surf_color, 1.0);
tgt_color = vec4(surf_color, surf_alpha);
}