#version 460 core layout(location = 0) in vec2 inUV; layout(location = 0) out vec4 outColor; layout(binding = 0) uniform sampler2D sceneSampler; layout(binding = 1) uniform sampler2D depthSampler; layout(binding = 2) uniform sampler2D nearFieldSampler; layout(binding = 3) uniform sampler2D farFieldSampler; void main() { vec3 sceneColor = texture(sceneSampler, inUV).rgb; // 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; // read coc stored in the alpha channel float coc = texture(farFieldSampler, inUV).a; // transistion between out of focus and regular scene vec3 farColorBlurred = mix(sceneColor, farColor, clamp(coc, 0.0, 1.0)); // 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)); //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)); outColor = vec4(farColorBlurred, 1.0); }