RetroArch-Wii-U-Slang-Shaders/anti-aliasing/shaders/aa-shader-4.0-level2/aa-shader-4.0-level2-pass1.frag
2020-04-26 18:03:54 -05:00

91 lines
2.4 KiB
GLSL

#version 150
#define float2 vec2
#define float3 vec3
#define float4 vec4
uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float AAOFFSET;
}params;
#pragma parameterAAOFFSET¡1.00.252.00.05
layout(std140) uniform UBO
{
mat4 MVP;
}global;
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
uniform sampler2D Source;
void main()
{
vec2 tex = vTexCoord;
vec2 texsize = params . SourceSize . xy;
float dx = params . AAOFFSET / texsize . x;
float dy = params . AAOFFSET / texsize . y;
vec3 dt = vec3(1.0, 1.0, 1.0);
vec4 yx = vec4(dx, dy, - dx, - dy);
vec4 xh = yx * vec4(4.0, 1.5, 4.0, 1.5);
vec4 yv = yx * vec4(1.5, 4.0, 1.5, 4.0);
vec3 c11 = texture(Source, tex). xyz;
vec3 s00 = texture(Source, tex + yx . zw). xyz;
vec3 s20 = texture(Source, tex + yx . xw). xyz;
vec3 s22 = texture(Source, tex + yx . xy). xyz;
vec3 s02 = texture(Source, tex + yx . zy). xyz;
vec3 h00 = texture(Source, tex + xh . zw). xyz;
vec3 h20 = texture(Source, tex + xh . xw). xyz;
vec3 h22 = texture(Source, tex + xh . xy). xyz;
vec3 h02 = texture(Source, tex + xh . zy). xyz;
vec3 v00 = texture(Source, tex + yv . zw). xyz;
vec3 v20 = texture(Source, tex + yv . xw). xyz;
vec3 v22 = texture(Source, tex + yv . xy). xyz;
vec3 v02 = texture(Source, tex + yv . zy). xyz;
float m1 = 1.0 /(dot(abs(s00 - s22), dt)+ 0.00001);
float m2 = 1.0 /(dot(abs(s02 - s20), dt)+ 0.00001);
float h1 = 1.0 /(dot(abs(s00 - h22), dt)+ 0.00001);
float h2 = 1.0 /(dot(abs(s02 - h20), dt)+ 0.00001);
float h3 = 1.0 /(dot(abs(h00 - s22), dt)+ 0.00001);
float h4 = 1.0 /(dot(abs(h02 - s20), dt)+ 0.00001);
float v1 = 1.0 /(dot(abs(s00 - v22), dt)+ 0.00001);
float v2 = 1.0 /(dot(abs(s02 - v20), dt)+ 0.00001);
float v3 = 1.0 /(dot(abs(v00 - s22), dt)+ 0.00001);
float v4 = 1.0 /(dot(abs(v02 - s20), dt)+ 0.00001);
vec3 t1 = 0.5 *(m1 *(s00 + s22)+ m2 *(s02 + s20))/(m1 + m2);
vec3 t2 = 0.5 *(h1 *(s00 + h22)+ h2 *(s02 + h20)+ h3 *(h00 + s22)+ h4 *(h02 + s20))/(h1 + h2 + h3 + h4);
vec3 t3 = 0.5 *(v1 *(s00 + v22)+ v2 *(s02 + v20)+ v3 *(v00 + s22)+ v4 *(v02 + s20))/(v1 + v2 + v3 + v4);
float k1 = 1.0 /(dot(abs(t1 - c11), dt)+ 0.00001);
float k2 = 1.0 /(dot(abs(t2 - c11), dt)+ 0.00001);
float k3 = 1.0 /(dot(abs(t3 - c11), dt)+ 0.00001);
FragColor = vec4((k1 * t1 + k2 * t2 + k3 * t3)/(k1 + k2 + k3), 1.0);
}