RetroArch-Wii-U-Slang-Shaders/anti-aliasing/shaders/advanced-aa.ppslang
2020-04-26 18:03:54 -05:00

114 lines
2.5 KiB
Text

#version 450
layout(push_constant)uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float AA_RESOLUTION_X;
float AA_RESOLUTION_Y;
} params;
#pragma parameterAA_RESOLUTION_X¡0.00.01920.01.0
#pragma parameterAA_RESOLUTION_Y¡0.00.01920.01.0
layout(std140, set = 0, binding = 0)uniform UBO
{
mat4 MVP;
} global;
vec3 dt = vec3(1, 1, 1);
#pragma stagevertex
layout(location = 0)in vec4 Position;
layout(location = 1)in vec2 TexCoord;
layout(location = 0)out vec2 vTexCoord;
layout(location = 1)out vec4 t1;
layout(location = 2)out vec4 t2;
layout(location = 3)out vec4 t3;
layout(location = 4)out vec4 t4;
void main()
{
gl_Position = global . MVP * Position;
vTexCoord = TexCoord;
vec2 ps = vec2(1.0 /((params . AA_RESOLUTION_X == 0)? params . SourceSize . x : params . AA_RESOLUTION_X), 1.0 /((params . AA_RESOLUTION_Y == 0)? params . SourceSize . y : params . AA_RESOLUTION_Y));
float dx = ps . x * 0.5;
float dy = ps . y * 0.5;
t1 . xy = vTexCoord + vec2(- dx, 0);
t2 . xy = vTexCoord + vec2(dx, 0);
t3 . xy = vTexCoord + vec2(0, - dy);
t4 . xy = vTexCoord + vec2(0, dy);
t1 . zw = vTexCoord + vec2(- dx, - dy);
t2 . zw = vTexCoord + vec2(- dx, dy);
t3 . zw = vTexCoord + vec2(dx, - dy);
t4 . zw = vTexCoord + vec2(dx, dy);
}
#pragma stagefragment
layout(location = 0)in vec2 vTexCoord;
layout(location = 1)in vec4 t1;
layout(location = 2)in vec4 t2;
layout(location = 3)in vec4 t3;
layout(location = 4)in vec4 t4;
layout(location = 0)out vec4 FragColor;
layout(set = 0, binding = 2)uniform sampler2D Source;
void main()
{
vec3 c00 = texture(Source, t1 . zw). xyz;
vec3 c10 = texture(Source, t3 . xy). xyz;
vec3 c20 = texture(Source, t3 . zw). xyz;
vec3 c01 = texture(Source, t1 . xy). xyz;
vec3 c11 = texture(Source, vTexCoord). xyz;
vec3 c21 = texture(Source, t2 . xy). xyz;
vec3 c02 = texture(Source, t2 . zw). xyz;
vec3 c12 = texture(Source, t4 . xy). xyz;
vec3 c22 = texture(Source, t4 . zw). xyz;
float d1 = dot(abs(c00 - c22), dt)+ 0.0001;
float d2 = dot(abs(c20 - c02), dt)+ 0.0001;
float hl = dot(abs(c01 - c21), dt)+ 0.0001;
float vl = dot(abs(c10 - c12), dt)+ 0.0001;
float k1 = 0.5 *(hl + vl);
float k2 = 0.5 *(d1 + d2);
vec3 t1 =(hl *(c10 + c12)+ vl *(c01 + c21)+ k1 * c11)/(2.5 *(hl + vl));
vec3 t2 =(d1 *(c20 + c02)+ d2 *(c00 + c22)+ k2 * c11)/(2.5 *(d1 + d2));
k1 = dot(abs(t1 - c11), dt)+ 0.0001;
k2 = dot(abs(t2 - c11), dt)+ 0.0001;
FragColor = vec4((k1 * t2 + k2 * t1)/(k1 + k2), 1);
}