RetroArch-Wii-U-Slang-Shaders/blurs/smart-blur.ppslang
2020-04-26 18:03:54 -05:00

108 lines
2 KiB
Text

#version 450
layout(push_constant)uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float SB_RED_THRESHOLD;
float SB_GREEN_THRESHOLD;
float SB_BLUE_THRESHOLD;
} params;
#pragma parameterSB_RED_THRESHOLD¡0.20.00.60.01
#pragma parameterSB_GREEN_THRESHOLD¡0.20.00.60.01
#pragma parameterSB_BLUE_THRESHOLD¡0.20.00.60.01
layout(std140, set = 0, binding = 0)uniform UBO
{
mat4 MVP;
} global;
#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;
void main()
{
gl_Position = global . MVP * Position;
vTexCoord = TexCoord;
float dx = params . SourceSize . z;
float dy = params . SourceSize . w;
t1 = vTexCoord . xxxy + vec4(- dx, 0.0, dx, - dy);
t2 = vTexCoord . xxxy + vec4(- dx, 0.0, dx, 0.0);
t3 = vTexCoord . xxxy + vec4(- dx, 0.0, 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 = 0)out vec4 FragColor;
layout(set = 0, binding = 2)uniform sampler2D Source;
bool eq(vec3 c1, vec3 c2){
vec3 df = abs(c1 - c2);
return(df . r < params . SB_RED_THRESHOLD)&&(df . g < params . SB_GREEN_THRESHOLD)&&(df . b < params . SB_BLUE_THRESHOLD);
}
void main()
{
vec3 A = texture(Source, t1 . xw). xyz;
vec3 B = texture(Source, t1 . yw). xyz;
vec3 C = texture(Source, t1 . zw). xyz;
vec3 D = texture(Source, t2 . xw). xyz;
vec3 E = texture(Source, t2 . yw). xyz;
vec3 F = texture(Source, t2 . zw). xyz;
vec3 G = texture(Source, t3 . xw). xyz;
vec3 H = texture(Source, t3 . yw). xyz;
vec3 I = texture(Source, t3 . zw). xyz;
vec3 sum = vec3(0., 0., 0.);
if(eq(E, F)&& eq(E, H)&& eq(E, I)&& eq(E, B)&& eq(E, C)&& eq(E, A)&& eq(E, D)&& eq(E, G))
{
sum =(E + A + C + D + F + G + I + B + H)/ 9.0;
E = sum;
}
FragColor = vec4(E, 1.0);
}