compose.frag 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* compose.frag -- Deferred pipeline composition fragment shader
  2. *
  3. * Composes the final scene by combining the outputs from
  4. * the deferred rendering pipeline.
  5. *
  6. * Copyright (c) 2025 Victor Le Juez
  7. *
  8. * This software is distributed under the terms of the accompanying LICENSE file.
  9. * It is provided "as-is", without any express or implied warranty.
  10. */
  11. #version 330 core
  12. /* === Includes === */
  13. #include "../include/pbr.glsl"
  14. /* === Varyings === */
  15. noperspective in vec2 vTexCoord;
  16. /* === Uniforms === */
  17. uniform sampler2D uAlbedoTex;
  18. uniform sampler2D uDiffuseTex;
  19. uniform sampler2D uSpecularTex;
  20. uniform sampler2D uOrmTex;
  21. uniform sampler2D uSsrTex;
  22. uniform float uSsrNumLevels;
  23. /* === Fragments === */
  24. layout(location = 0) out vec3 FragColor;
  25. /* === Main function === */
  26. void main()
  27. {
  28. vec3 albedo = texelFetch(uAlbedoTex, ivec2(gl_FragCoord.xy), 0).rgb;
  29. vec3 diffuse = texelFetch(uDiffuseTex, ivec2(gl_FragCoord.xy), 0).rgb;
  30. vec3 specular = texelFetch(uSpecularTex, ivec2(gl_FragCoord.xy), 0).rgb;
  31. vec3 orm = texelFetch(uOrmTex, ivec2(gl_FragCoord).xy, 0).rgb;
  32. vec4 ssr = textureLod(uSsrTex, vTexCoord, orm.y * uSsrNumLevels);
  33. vec3 F0 = PBR_ComputeF0(orm.z, 0.5, albedo);
  34. vec3 kS_approx = F0 * (1.0 - orm.y * 0.5);
  35. FragColor = diffuse + mix(specular, kS_approx * ssr.rgb, ssr.a);
  36. }