2021-05-09 20:04:41 -04:00
|
|
|
#define SMAA_RT_METRICS viewport
|
|
|
|
|
|
|
|
#define SMAA_PRESET_ULTRA 1
|
|
|
|
#define SMAA_GLSL_4 1
|
|
|
|
#define SMAA_INCLUDE_VS 0
|
|
|
|
#define SMAA_INCLUDE_PS 1
|
|
|
|
|
2022-02-20 22:51:23 -05:00
|
|
|
layout(push_constant) uniform PushConstant {
|
2021-05-09 20:04:41 -04:00
|
|
|
vec4 viewport;
|
|
|
|
vec4 options;
|
|
|
|
vec4 transform_ops;
|
|
|
|
};
|
|
|
|
|
|
|
|
#include "smaa.glsl"
|
|
|
|
#include "common.nocompile.glsl"
|
|
|
|
|
|
|
|
layout (location = 0) in vec2 inUV;
|
|
|
|
layout(location = 1) in vec4 inOffset;
|
|
|
|
|
|
|
|
layout (location = 0) out vec4 outColor;
|
|
|
|
|
2022-03-10 10:21:03 -05:00
|
|
|
layout (binding = 1) uniform sampler2D colorSampler;
|
|
|
|
layout (binding = 3) uniform sampler2D blendSampler;
|
|
|
|
layout (binding = 5) uniform sampler2D sobelSampler;
|
2021-05-09 20:04:41 -04:00
|
|
|
|
|
|
|
float calculate_sobel() {
|
|
|
|
float x = 1.0 / viewport.z;
|
|
|
|
float y = 1.0 / viewport.w;
|
|
|
|
vec4 horizEdge = vec4( 0.0 );
|
2022-03-10 10:21:03 -05:00
|
|
|
horizEdge -= texture( sobelSampler, vec2( inUV.x - x, inUV.y - y ) ) * 1.0;
|
|
|
|
horizEdge -= texture( sobelSampler, vec2( inUV.x - x, inUV.y ) ) * 2.0;
|
|
|
|
horizEdge -= texture( sobelSampler, vec2( inUV.x - x, inUV.y + y ) ) * 1.0;
|
|
|
|
horizEdge += texture( sobelSampler, vec2( inUV.x + x, inUV.y - y ) ) * 1.0;
|
|
|
|
horizEdge += texture( sobelSampler, vec2( inUV.x + x, inUV.y ) ) * 2.0;
|
|
|
|
horizEdge += texture( sobelSampler, vec2( inUV.x + x, inUV.y + y ) ) * 1.0;
|
2021-05-09 20:04:41 -04:00
|
|
|
vec4 vertEdge = vec4( 0.0 );
|
2022-03-10 10:21:03 -05:00
|
|
|
vertEdge -= texture( sobelSampler, vec2( inUV.x - x, inUV.y - y ) ) * 1.0;
|
|
|
|
vertEdge -= texture( sobelSampler, vec2( inUV.x , inUV.y - y ) ) * 2.0;
|
|
|
|
vertEdge -= texture( sobelSampler, vec2( inUV.x + x, inUV.y - y ) ) * 1.0;
|
|
|
|
vertEdge += texture( sobelSampler, vec2( inUV.x - x, inUV.y + y ) ) * 1.0;
|
|
|
|
vertEdge += texture( sobelSampler, vec2( inUV.x , inUV.y + y ) ) * 2.0;
|
|
|
|
vertEdge += texture( sobelSampler, vec2( inUV.x + x, inUV.y + y ) ) * 1.0;
|
2021-05-09 20:04:41 -04:00
|
|
|
return sqrt((horizEdge.rgb * horizEdge.rgb) + (vertEdge.rgb * vertEdge.rgb)).r;
|
|
|
|
}
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
bool enable_dof = options.w == 2;
|
|
|
|
vec3 sceneColor = vec3(0);
|
2022-04-04 12:15:15 -04:00
|
|
|
if(options.x == 1) // enable AA
|
|
|
|
sceneColor = SMAANeighborhoodBlendingPS(inUV, inOffset, colorSampler, blendSampler).rgb;
|
|
|
|
else
|
|
|
|
sceneColor = texture(colorSampler, inUV).rgb;
|
2021-05-09 20:04:41 -04:00
|
|
|
|
|
|
|
float sobel = 0.0;
|
2022-03-10 10:21:03 -05:00
|
|
|
if(textureSize(sobelSampler, 0).x > 1)
|
2021-05-09 20:04:41 -04:00
|
|
|
sobel = calculate_sobel();
|
|
|
|
|
|
|
|
vec3 sobelColor = vec3(0, 1, 1);
|
|
|
|
|
2022-04-04 12:15:15 -04:00
|
|
|
outColor = vec4(sceneColor + (sobelColor * sobel), 1.0);
|
2021-05-09 20:04:41 -04:00
|
|
|
}
|