2022-10-25 20:46:55 +00:00
|
|
|
#include <fxaa.glsl>
|
|
|
|
|
|
|
|
vec4 aa_apply(
|
|
|
|
texture2D tex, sampler smplr,
|
|
|
|
texture2D depth_tex, sampler depth_smplr,
|
|
|
|
vec2 fragCoord,
|
|
|
|
vec2 resolution
|
|
|
|
) {
|
2022-10-26 20:10:43 +00:00
|
|
|
ivec2 dirs[] = { ivec2(-1, 0), ivec2(1, 0), ivec2(0, -1), ivec2(0, 1) };
|
2022-10-25 20:46:55 +00:00
|
|
|
|
|
|
|
vec2 sz = textureSize(sampler2D(tex, smplr), 0).xy;
|
2022-10-25 23:51:23 +00:00
|
|
|
|
2022-10-26 20:10:43 +00:00
|
|
|
//float center_d = texelFetch(sampler2D(depth_tex, depth_smplr), ivec2(fragCoord / screen_res.xy * sz), 0).x;
|
|
|
|
|
2022-10-25 23:51:23 +00:00
|
|
|
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);
|
2022-10-26 20:10:43 +00:00
|
|
|
vec4 lerped = texture(sampler2D(tex, smplr), fragCoord / screen_res.xy);
|
|
|
|
//aa_color = lerped;
|
2022-10-25 23:51:23 +00:00
|
|
|
|
2022-10-26 20:10:43 +00:00
|
|
|
vec4 closest = aa_color;
|
2022-10-25 20:46:55 +00:00
|
|
|
float closest_dist = 1000.0;
|
|
|
|
for (uint i = 0u; i < dirs.length(); i ++) {
|
|
|
|
vec4 col_at = texelFetch(sampler2D(tex, smplr), ivec2(fragCoord / screen_res.xy * sz) + dirs[i], 0);
|
2022-10-25 23:51:23 +00:00
|
|
|
//float depth_at = texelFetch(sampler2D(depth_tex, depth_smplr), ivec2(fragCoord / screen_res.xy * sz) + dirs[i], 0).x;
|
2022-10-25 20:46:55 +00:00
|
|
|
float dist = dot(pow(aa_color.rgb - col_at.rgb, ivec3(2)), vec3(1));
|
|
|
|
if (dist < closest_dist) {
|
2022-10-26 20:10:43 +00:00
|
|
|
closest = mix(col_at, lerped, min(length(lerped.rgb - col_at.rgb) * 0.25, 1));
|
2022-10-25 20:46:55 +00:00
|
|
|
closest_dist = dist;
|
|
|
|
}
|
|
|
|
}
|
2022-10-25 23:51:23 +00:00
|
|
|
//return texelFetch(sampler2D(tex, smplr), ivec2(fragCoord / screen_res.xy * sz), 0);
|
2022-10-26 20:10:43 +00:00
|
|
|
return closest;//mix(aa_color, closest, clamp(1.0 - sqrt(closest_dist) / length(aa_color.rgb) * 0.75, 0, 1));
|
2022-10-25 20:46:55 +00:00
|
|
|
}
|