2023-08-10 21:53:51 +00:00
|
|
|
uniform sampler2D u_texture;
|
|
|
|
|
|
|
|
in vec2 vTexCoord;
|
|
|
|
in vec4 vColor;
|
|
|
|
out vec4 fragColor;
|
|
|
|
|
2023-08-10 22:46:04 +00:00
|
|
|
// [src] https://www.shadertoy.com/view/MllBWf CC1.0
|
2023-08-10 21:53:51 +00:00
|
|
|
vec4 texture_AA(sampler2D tx, vec2 uv) {
|
|
|
|
vec2 res = vec2(textureSize(tx, 0));
|
|
|
|
uv = uv*res + 0.5;
|
2023-08-10 22:46:04 +00:00
|
|
|
// tweak fractionnal value of the texture coordinate
|
2023-08-10 21:53:51 +00:00
|
|
|
vec2 fl = floor(uv);
|
|
|
|
vec2 fr = fract(uv);
|
|
|
|
vec2 aa = fwidth(uv)*0.75;
|
|
|
|
fr = smoothstep( vec2(0.5)-aa, vec2(0.5)+aa, fr);
|
2023-08-10 22:46:04 +00:00
|
|
|
// return value
|
2023-08-10 21:53:51 +00:00
|
|
|
uv = (fl+fr-0.5) / res;
|
|
|
|
return texture(tx, uv);
|
|
|
|
}
|
|
|
|
|
2023-08-10 22:46:04 +00:00
|
|
|
// [src] https://www.shadertoy.com/view/MllBWf CC1.0
|
2023-08-10 21:53:51 +00:00
|
|
|
vec4 texture_AA2( sampler2D tex, vec2 uv) {
|
|
|
|
vec2 res = vec2(textureSize(tex,0));
|
|
|
|
uv = uv*res;
|
|
|
|
vec2 seam = floor(uv+0.5);
|
|
|
|
uv = seam + clamp( (uv-seam)/fwidth(uv), -0.5, 0.5);
|
|
|
|
return texture(tex, uv/res);
|
|
|
|
}
|
|
|
|
|
2023-08-10 22:46:04 +00:00
|
|
|
// [src] https://www.shadertoy.com/view/ltBfRD
|
2023-08-10 21:53:51 +00:00
|
|
|
vec4 texture_AA3(sampler2D tex, vec2 uv) {
|
|
|
|
vec2 res = vec2(textureSize(tex,0));
|
|
|
|
float width = 2.0;
|
|
|
|
uv = uv * res;
|
2023-08-10 22:46:04 +00:00
|
|
|
// ---
|
2023-08-10 21:53:51 +00:00
|
|
|
vec2 uv_floor = floor(uv + 0.5);
|
|
|
|
vec2 uv_fract = fract(uv + 0.5);
|
|
|
|
vec2 uv_aa = fwidth(uv) * width * 0.5;
|
|
|
|
uv_fract = smoothstep(
|
|
|
|
vec2(0.5) - uv_aa,
|
|
|
|
vec2(0.5) + uv_aa,
|
|
|
|
uv_fract
|
|
|
|
);
|
|
|
|
uv = (uv_floor + uv_fract - 0.5) / res;
|
|
|
|
return texture(tex, uv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
vec4 texColor = texture_AA2(u_texture, vTexCoord);
|
|
|
|
if(texColor.a < 0.9) discard;
|
|
|
|
fragColor = vColor * texColor;
|
|
|
|
}
|