No Description

attachmentread.frag 1005B

123456789101112131415161718192021222324252627282930313233
  1. #version 450
  2. layout (input_attachment_index = 0, binding = 0) uniform subpassInput inputColor;
  3. layout (input_attachment_index = 1, binding = 1) uniform subpassInput inputDepth;
  4. layout (binding = 2) uniform UBO {
  5. vec2 brightnessContrast;
  6. vec2 range;
  7. int attachmentIndex;
  8. } ubo;
  9. layout (location = 0) out vec4 outColor;
  10. vec3 brightnessContrast(vec3 color, float brightness, float contrast) {
  11. return (color - 0.5) * contrast + 0.5 + brightness;
  12. }
  13. void main()
  14. {
  15. // Apply brightness and contrast filer to color input
  16. if (ubo.attachmentIndex == 0) {
  17. // Read color from previous color input attachment
  18. vec3 color = subpassLoad(inputColor).rgb;
  19. outColor.rgb = brightnessContrast(color, ubo.brightnessContrast[0], ubo.brightnessContrast[1]);
  20. }
  21. // Visualize depth input range
  22. if (ubo.attachmentIndex == 1) {
  23. // Read depth from previous depth input attachment
  24. float depth = subpassLoad(inputDepth).r;
  25. outColor.rgb = vec3((depth - ubo.range[0]) * 1.0 / (ubo.range[1] - ubo.range[0]));
  26. }
  27. }