Added experimental BetterAA shader

This commit is contained in:
Joshua Barretto 2022-09-09 11:59:40 +01:00
parent b4234523cb
commit 03e8eb42ad
3 changed files with 45 additions and 3 deletions

View File

@ -124,8 +124,14 @@ vec4 aa_apply(texture2D tex, sampler smplr, vec2 fragCoord, vec2 resolution) {
mediump vec2 v_rgbSE;
mediump vec2 v_rgbM;
vec2 scaled_fc = fragCoord * FXAA_SCALE;
vec2 scaled_res = resolution * FXAA_SCALE;
#ifdef EXPERIMENTAL_BETTERAA
float fxaa_scale = textureSize(sampler2D(tex, smplr), 0).x / 900.0;
#else
float fxaa_scale = FXAA_SCALE;
#endif
vec2 scaled_fc = fragCoord * fxaa_scale;
vec2 scaled_res = resolution * fxaa_scale;
//compute the texture coords
texcoords(scaled_fc, scaled_res, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);

View File

@ -22,6 +22,7 @@
#include <srgb.glsl>
#include <cloud.glsl>
#include <random.glsl>
#include <lod.glsl>
layout(set = 1, binding = 0)
uniform texture2D t_src_color;
@ -43,6 +44,34 @@ uniform texture2D t_src_bloom;
layout(location = 0) out vec4 tgt_color;
#ifdef EXPERIMENTAL_BETTERAA
vec4 clever_aa_apply(texture2D tex, sampler smplr, vec2 fragCoord, vec2 resolution) {
uvec2 src_sz = textureSize(sampler2D(tex, smplr), 0).xy;
/* vec4 interp = texture(sampler2D(tex, smplr), fragCoord / resolution); */
/* vec4 interp = textureBicubic(tex, smplr, fragCoord * src_sz / resolution); */
vec4 interp = aa_apply(tex, smplr, fragCoord, resolution);
vec4 original = texelFetch(sampler2D(tex, smplr), ivec2(fragCoord / resolution * src_sz), 0);
vec4 closest = vec4(0.0);
float closest_dist = 100000.0;
for (int i = -1; i < 2; i ++) {
for (int j = -1; j < 2; j ++) {
ivec2 rpos = ivec2(i, j);
vec4 texel = texelFetch(sampler2D(tex, smplr), ivec2(fragCoord / resolution * src_sz) + rpos, 0);
float dist = distance(interp.rgb, texel.rgb);
if (dist < closest_dist) {
closest = texel;
closest_dist = dist;
}
}
}
return mix(closest, interp, 0.0);
}
#endif
vec3 rgb2hsv(vec3 c) {
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
@ -209,7 +238,12 @@ void main() {
}
#endif
vec4 aa_color = aa_apply(t_src_color, s_src_color, sample_uv * screen_res.xy, screen_res.xy);
#ifdef EXPERIMENTAL_BETTERAA
vec4 aa_color = clever_aa_apply(t_src_color, s_src_color, sample_uv * screen_res.xy, screen_res.xy);
#else
vec4 aa_color = aa_apply(t_src_color, s_src_color, sample_uv * screen_res.xy, screen_res.xy);
#endif
#ifdef EXPERIMENTAL_SOBEL
vec3 s[8];

View File

@ -482,4 +482,6 @@ pub enum ExperimentalShader {
NoRainbows,
/// Make objects appear wet when appropriate.
Wetness,
/// An attempt at better anti-aliasing (requires FXAA).
BetterAA,
}