visualizer.frag 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_SSGI 8
  20. #define OUTPUT_SSR 9
  21. #define OUTPUT_BLOOM 10
  22. #define OUTPUT_DOF 11
  23. /* === Varyings === */
  24. noperspective in vec2 vTexCoord;
  25. /* === Uniforms === */
  26. uniform sampler2D uSourceTex;
  27. uniform int uOutputMode;
  28. /* === Fragments === */
  29. out vec4 FragColor;
  30. /* === Main Program === */
  31. void main()
  32. {
  33. FragColor = texture(uSourceTex, vTexCoord);
  34. switch (uOutputMode) {
  35. case OUTPUT_ALBEDO:
  36. FragColor = vec4(FragColor.rgb, 1.0);
  37. break;
  38. case OUTPUT_NORMAL:
  39. FragColor = vec4(0.5 * M_DecodeOctahedral(FragColor.rg) + 0.5, 1.0);
  40. break;
  41. case OUTPUT_ORM:
  42. FragColor = vec4(FragColor.rgb, 1.0);
  43. break;
  44. case OUTPUT_DIFFUSE:
  45. FragColor = vec4(FragColor.rgb, 1.0);
  46. break;
  47. case OUTPUT_SPECULAR:
  48. FragColor = vec4(FragColor.rgb, 1.0);
  49. break;
  50. case OUTPUT_SSAO:
  51. FragColor = vec4(FragColor.xxx, 1.0);
  52. break;
  53. case OUTPUT_SSIL:
  54. FragColor = vec4(mix(FragColor.rgb, vec3(FragColor.a), 0.2), 1.0);
  55. break;
  56. case OUTPUT_SSGI:
  57. FragColor = vec4(FragColor.rgb, 1.0);
  58. break;
  59. case OUTPUT_SSR:
  60. FragColor = vec4(FragColor.rgb * FragColor.a, 1.0);
  61. break;
  62. case OUTPUT_BLOOM:
  63. FragColor = vec4(FragColor.rgb, 1.0);
  64. break;
  65. case OUTPUT_DOF:
  66. float front = clamp(-FragColor.r, 0.0, 1.0); // in front of focus plane (near)
  67. float back = clamp(FragColor.r, 0.0, 1.0); // behind the focus plane (far)
  68. vec3 tint = vec3(0.0, front, back); // green front, blue back, black at focus
  69. FragColor = vec4(tint, 1.0);
  70. break;
  71. default:
  72. break;
  73. }
  74. }