2018-10-17 10:06:38 -04:00
|
|
|
#version 460 core
|
2018-12-19 13:11:27 -05:00
|
|
|
#extension GL_GOOGLE_include_directive : enable
|
|
|
|
|
|
|
|
#define SMAA_RT_METRICS vec4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0)
|
|
|
|
|
|
|
|
#define SMAA_PRESET_ULTRA 1
|
|
|
|
#define SMAA_GLSL_4 1
|
|
|
|
#define SMAA_INCLUDE_VS 0
|
|
|
|
#define SMAA_INCLUDE_PS 1
|
|
|
|
#define SMAA_PREDICATION 1
|
|
|
|
#define SMAA_FLIP_Y 0
|
|
|
|
|
|
|
|
#include "smaa.glsl"
|
2018-10-17 10:06:38 -04:00
|
|
|
|
|
|
|
layout(location = 0) in vec2 inUV;
|
2018-12-19 13:11:27 -05:00
|
|
|
layout(location = 1) in vec4 inOffset;
|
2018-10-17 10:06:38 -04:00
|
|
|
|
|
|
|
layout(location = 0) out vec4 outColor;
|
|
|
|
|
2018-11-03 07:24:32 -04:00
|
|
|
layout(binding = 0) uniform sampler2D sceneSampler;
|
|
|
|
layout(binding = 1) uniform sampler2D depthSampler;
|
|
|
|
layout(binding = 2) uniform sampler2D nearFieldSampler;
|
|
|
|
layout(binding = 3) uniform sampler2D farFieldSampler;
|
2018-12-19 13:11:27 -05:00
|
|
|
layout(binding = 4) uniform sampler2D blendSampler;
|
2018-10-17 10:06:38 -04:00
|
|
|
|
2018-11-08 08:57:41 -05:00
|
|
|
void main() {
|
2018-12-19 13:11:27 -05:00
|
|
|
vec3 sceneColor = vec3(0);
|
|
|
|
sceneColor = SMAANeighborhoodBlendingPS(inUV, inOffset, sceneSampler, blendSampler).rgb;
|
2018-11-03 07:24:32 -04:00
|
|
|
|
|
|
|
// alpha divide reconstruction
|
|
|
|
vec3 farColor = texture(farFieldSampler, inUV).rgb / max(texture(farFieldSampler, inUV).a, 0.0001) * 0.02;
|
|
|
|
vec3 nearColor = texture(nearFieldSampler, inUV).rgb / max(texture(nearFieldSampler, inUV).a, 0.0001) * 0.02;
|
2018-11-08 08:57:41 -05:00
|
|
|
|
2018-11-03 07:24:32 -04:00
|
|
|
// read coc stored in the alpha channel
|
|
|
|
float coc = texture(farFieldSampler, inUV).a;
|
2018-11-08 08:57:41 -05:00
|
|
|
|
2018-11-03 07:24:32 -04:00
|
|
|
// transistion between out of focus and regular scene
|
|
|
|
vec3 farColorBlurred = mix(sceneColor, farColor, clamp(coc, 0.0, 1.0));
|
2018-11-08 08:57:41 -05:00
|
|
|
|
2018-11-03 07:24:32 -04:00
|
|
|
// smoother transistion between the normal scene and the "out of focus" portions
|
|
|
|
farColorBlurred = mix(sceneColor, farColorBlurred, clamp(0.5 * coc + 1.0, 0.0, 1.0));
|
2018-11-08 08:57:41 -05:00
|
|
|
|
2018-11-03 07:24:32 -04:00
|
|
|
//float coc2 = texture(nearFieldSampler, inUV).a;
|
|
|
|
//vec3 finalColor = mix(farColorBlurred, nearColor, clamp(clamp(-coc2 - 1.0, 0.0, 1.0) + texture(nearFieldSampler, inUV).a * 8.0, 0.0, 1.0));
|
2018-11-08 08:57:41 -05:00
|
|
|
|
2018-11-03 07:24:32 -04:00
|
|
|
outColor = vec4(farColorBlurred, 1.0);
|
2018-10-17 10:06:38 -04:00
|
|
|
}
|