visualizer.frag 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* visualizer.frag -- Buffer visualizer fragment shader
  2. *
  3. * Copyright (c) 2025 Victor Le Juez
  4. *
  5. * This software is distributed under the terms of the accompanying LICENSE file.
  6. * It is provided "as-is", without any express or implied warranty.
  7. */
  8. #version 330 core
  9. /* === Includes === */
  10. #include "../include/math.glsl"
  11. /* === Constants === */
  12. #define OUTPUT_ALBEDO 1
  13. #define OUTPUT_NORMAL 2
  14. #define OUTPUT_ORM 3
  15. #define OUTPUT_DIFFUSE 4
  16. #define OUTPUT_SPECULAR 5
  17. #define OUTPUT_SSAO 6
  18. #define OUTPUT_SSIL 7
  19. #define OUTPUT_SSR 8
  20. #define OUTPUT_BLOOM 9
  21. #define OUTPUT_DOF 10
  22. /* === Varyings === */
  23. noperspective in vec2 vTexCoord;
  24. /* === Uniforms === */
  25. uniform sampler2D uSourceTex;
  26. uniform int uOutputMode;
  27. /* === Fragments === */
  28. out vec4 FragColor;
  29. /* === Main Program === */
  30. void main()
  31. {
  32. FragColor = texture(uSourceTex, vTexCoord);
  33. switch (uOutputMode) {
  34. case OUTPUT_ALBEDO:
  35. FragColor = vec4(FragColor.rgb, 1.0);
  36. break;
  37. case OUTPUT_NORMAL:
  38. FragColor = vec4(0.5 * M_DecodeOctahedral(FragColor.rg) + 0.5, 1.0);
  39. break;
  40. case OUTPUT_ORM:
  41. FragColor = vec4(FragColor.rgb, 1.0);
  42. break;
  43. case OUTPUT_DIFFUSE:
  44. FragColor = vec4(FragColor.rgb, 1.0);
  45. break;
  46. case OUTPUT_SPECULAR:
  47. FragColor = vec4(FragColor.rgb, 1.0);
  48. break;
  49. case OUTPUT_SSAO:
  50. FragColor = vec4(FragColor.xxx, 1.0);
  51. break;
  52. case OUTPUT_SSIL:
  53. FragColor = vec4(mix(FragColor.rgb, vec3(FragColor.a), 0.2), 1.0);
  54. break;
  55. case OUTPUT_SSR:
  56. FragColor = vec4(FragColor.rgb * FragColor.a, 1.0);
  57. break;
  58. case OUTPUT_BLOOM:
  59. FragColor = vec4(FragColor.rgb, 1.0);
  60. break;
  61. case OUTPUT_DOF:
  62. float front = clamp(-FragColor.r, 0.0, 1.0); // in front of focus plane (near)
  63. float back = clamp(FragColor.r, 0.0, 1.0); // behind the focus plane (far)
  64. vec3 tint = vec3(0.0, front, back); // green front, blue back, black at focus
  65. FragColor = vec4(tint, 1.0);
  66. break;
  67. default:
  68. break;
  69. }
  70. }