Archived
1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
graph/shaders/dof.vert

40 lines
1.1 KiB
GLSL
Raw Normal View History

2018-11-03 07:24:32 -04:00
#version 460 core
layout(location = 0) out vec2 outUV;
layout(location = 1) out vec2 outLoc;
layout(location = 2) out float cocRadius;
layout(binding = 2) uniform sampler2D depthSampler;
layout(push_constant) uniform PushConstants {
vec4 dpack;
} pushConstants;
void main() {
const vec2 res = vec2(pushConstants.dpack[2], pushConstants.dpack[3]);
const vec2 loc = vec2((gl_InstanceIndex % int(res.x)), ((gl_InstanceIndex / int(res.x)) % int(res.y)));
outLoc = loc;
const float depth = texture(depthSampler, vec2(loc.x / res.x, loc.y / res.y)).r;
float size = 0.0;
2018-11-05 21:06:12 -05:00
if(depth > pushConstants.dpack[1])
size = (depth - pushConstants.dpack[1]) * 500.0 * pushConstants.dpack[0];
2018-11-03 07:24:32 -04:00
cocRadius = size;
outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
vec2 pos = outUV * 2.0 + -1.0;
pos *= vec2(1.0 / res.x, 1.0 / res.y);
pos *= min(size, 32.0);
pos.x -= 1;
pos.y -= 1;
pos.x += loc.x / (res.x / 2.0);
pos.y += loc.y / (res.y / 2.0);
gl_Position = vec4(pos, 0.0, 1.0);
}