No Description

transparent.frag 929B

123456789101112131415161718192021222324252627282930313233
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. layout (input_attachment_index = 0, binding = 1) uniform subpassInput samplerPositionDepth;
  5. layout (binding = 2) uniform sampler2D samplerTexture;
  6. layout (location = 0) in vec3 inColor;
  7. layout (location = 1) in vec2 inUV;
  8. layout (location = 0) out vec4 outColor;
  9. layout (constant_id = 0) const float NEAR_PLANE = 0.1f;
  10. layout (constant_id = 1) const float FAR_PLANE = 256.0f;
  11. float linearDepth(float depth)
  12. {
  13. float z = depth * 2.0f - 1.0f;
  14. return (2.0f * NEAR_PLANE * FAR_PLANE) / (FAR_PLANE + NEAR_PLANE - z * (FAR_PLANE - NEAR_PLANE));
  15. }
  16. void main ()
  17. {
  18. // Sample depth from deferred depth buffer and discard if obscured
  19. float depth = subpassLoad(samplerPositionDepth).a;
  20. if ((depth != 0.0) && (linearDepth(gl_FragCoord.z) > depth))
  21. {
  22. discard;
  23. };
  24. outColor = texture(samplerTexture, inUV);
  25. }