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.
prism/engine/shaders/dof.vert.glsl
Joshua Goins 3229c4fa2c Another big WebGPU compatibility patch
All specialization constants are removed (they cause trouble in
WebGPU, since they don't support array sizing, and it was a pain
in Metal anyway) - they are now macro defined. WebGPU now runs, although
push constant emulation is not implemented yet.
2022-03-07 00:33:44 -05:00

32 lines
866 B
GLSL

layout(location = 0) out vec2 outUV;
layout(location = 1) out flat ivec2 outPixel;
layout(location = 2) out float outDepth;
layout(binding = 1) uniform sampler2D depth_sampler;
layout(push_constant) uniform readonly PushConstant{
vec4 params;
};
void main() {
outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
ivec2 pixel = ivec2(gl_InstanceIndex % DOF_WIDTH, gl_InstanceIndex / DOF_WIDTH);
outPixel = pixel;
const float depth = texture(depth_sampler, vec2(pixel) / vec2(DOF_WIDTH, DOF_HEIGHT)).r;
outDepth = depth;
vec2 pos = vec2(outUV * 2.0 + -1.0);
// far field mode
if(params.y == 0) {
pos *= params.x * depth;
}
pos += vec2(pixel.x, pixel.y);
pos *= 2.0 / vec2(DOF_WIDTH, DOF_HEIGHT);
pos += vec2(-1, -1);
gl_Position = vec4(pos.x, pos.y, 0.0, 1.0);
}