mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Improve FxUpscale quality for distant objects
This commit is contained in:
parent
f29b1da583
commit
589f59b771
@ -6,5 +6,5 @@ vec4 aa_apply(
|
||||
vec2 fragCoord,
|
||||
vec2 resolution
|
||||
) {
|
||||
return fxaa_apply(tex, smplr, fragCoord, resolution);
|
||||
return fxaa_apply(tex, smplr, fragCoord, resolution, 1.0);
|
||||
}
|
||||
|
@ -6,19 +6,31 @@ vec4 aa_apply(
|
||||
vec2 fragCoord,
|
||||
vec2 resolution
|
||||
) {
|
||||
vec4 aa_color = fxaa_apply(tex, smplr, fragCoord, resolution);
|
||||
ivec2 dirs[] = { ivec2(-1, 0), ivec2(1, 0), ivec2(0, -1), ivec2(0, 1), /*ivec2(-1, -1), ivec2(-1, 1), ivec2(1, -1), ivec2(1, 1)*/ };
|
||||
|
||||
vec2 sz = textureSize(sampler2D(tex, smplr), 0).xy;
|
||||
|
||||
float min_depth = 1000;
|
||||
float max_depth = 0;
|
||||
for (uint i = 0u; i < dirs.length(); i ++) {
|
||||
float d = texelFetch(sampler2D(depth_tex, depth_smplr), ivec2(fragCoord / screen_res.xy * sz) + dirs[i], 0).x;
|
||||
min_depth = min(min_depth, d);
|
||||
max_depth = max(max_depth, d);
|
||||
}
|
||||
|
||||
vec4 aa_color = fxaa_apply(tex, smplr, fragCoord, resolution, 1.0 + 1.0 / (min_depth * 0 + 0.001 + (max_depth - min_depth) * 500) * 0.001);
|
||||
|
||||
vec4 closest = vec4(1000);
|
||||
float closest_dist = 1000.0;
|
||||
ivec2 dirs[] = { ivec2(-1, 0), ivec2(1, 0), ivec2(0, -1), ivec2(0, 1), /*ivec2(-1, -1), ivec2(-1, 1), ivec2(1, -1), ivec2(1, 1)*/ };
|
||||
for (uint i = 0u; i < dirs.length(); i ++) {
|
||||
vec4 col_at = texelFetch(sampler2D(tex, smplr), ivec2(fragCoord / screen_res.xy * sz) + dirs[i], 0);
|
||||
//float depth_at = texelFetch(sampler2D(depth_tex, depth_smplr), ivec2(fragCoord / screen_res.xy * sz) + dirs[i], 0).x;
|
||||
float dist = dot(pow(aa_color.rgb - col_at.rgb, ivec3(2)), vec3(1));
|
||||
if (dist < closest_dist) {
|
||||
closest = col_at;
|
||||
closest_dist = dist;
|
||||
}
|
||||
}
|
||||
return mix(aa_color, closest, clamp(1.0 - sqrt(closest_dist), 0, 1));
|
||||
//return texelFetch(sampler2D(tex, smplr), ivec2(fragCoord / screen_res.xy * sz), 0);
|
||||
return closest;//mix(aa_color, closest, clamp(1.0 - sqrt(closest_dist) / length(aa_color.rgb) * 0.25, 0, 1));
|
||||
}
|
||||
|
@ -118,7 +118,8 @@ void texcoords(vec2 fragCoord, vec2 resolution,
|
||||
vec4 fxaa_apply(
|
||||
texture2D tex, sampler smplr,
|
||||
vec2 fragCoord,
|
||||
vec2 resolution
|
||||
vec2 resolution,
|
||||
float sampleScale
|
||||
) {
|
||||
mediump vec2 v_rgbNW;
|
||||
mediump vec2 v_rgbNE;
|
||||
@ -126,7 +127,7 @@ vec4 fxaa_apply(
|
||||
mediump vec2 v_rgbSE;
|
||||
mediump vec2 v_rgbM;
|
||||
|
||||
float fxaa_scale = textureSize(sampler2D(tex, smplr), 0).x / resolution.x;
|
||||
float fxaa_scale = textureSize(sampler2D(tex, smplr), 0).x / resolution.x * sampleScale;
|
||||
|
||||
vec2 scaled_fc = fragCoord * fxaa_scale;
|
||||
vec2 scaled_res = resolution * fxaa_scale;
|
||||
|
Loading…
Reference in New Issue
Block a user