#version 450 layout(location = 0) in vec2 uv; layout(location = 0) out vec4 out_color; layout(set = 2, binding = 0) uniform sampler2D screen; layout(std140, set = 3, binding = 0) uniform UniformBlock { mat4 model; mat4 view; mat4 projection; mat4 inv_view; mat4 inv_projection; vec4 time_padded; vec4 cam_pos; }; float t(float x, float y) { return length(texture(screen, vec2(x, y)).xyz); } mat3 neighborhood() { vec2 d = 1.0 / vec2(textureSize(screen, 0)); return mat3(t(uv.x - d.x, uv.y - d.y), t(uv.x + 0.0, uv.y - d.y), t(uv.x + d.x, uv.y - d.y), t(uv.x - d.x, uv.y - 0.0), t(uv.x + 0.0, uv.y + 0.0), t(uv.x + d.x, uv.y - 0.0), t(uv.x - d.x, uv.y + d.y), t(uv.x + 0.0, uv.y + d.y), t(uv.x + d.x, uv.y + d.y)); } float sum3(mat3 m) { float s = 0.0; for (int c = 0; c < 3; ++c) { vec3 col = m[c]; s += col.x + col.y + col.z; } return s; } float f(mat3 kernel) { return abs(sum3(matrixCompMult(kernel, neighborhood()))); } void main() { const mat3 sobelx = mat3(-1.0, -2.0, -1.0, 0.0, 0.0, 0.0, 1.0, 2.0, 1.0); const mat3 sobely = mat3(-1.0, 0.0, 1.0, -2.0, 0.0, 2.0, -1.0, 0.0, 1.0); out_color = texture(screen, uv) + 0.01 * ((t(uv.x, uv.y) > 0.01)? vec4(abs(f(sobelx) + f(sobely)), 0.0, 0.0, 1.0) : vec4(0.0)); }