No Description

composition.frag 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. layout (binding = 0) uniform sampler2D samplerposition;
  5. layout (binding = 1) uniform sampler2D samplerNormal;
  6. layout (binding = 2) uniform sampler2D samplerAlbedo;
  7. layout (binding = 3) uniform sampler2D samplerSSAO;
  8. layout (binding = 4) uniform sampler2D samplerSSAOBlur;
  9. layout (binding = 5) uniform UBO
  10. {
  11. mat4 _dummy;
  12. int ssao;
  13. int ssaoOnly;
  14. int ssaoBlur;
  15. } uboParams;
  16. layout (location = 0) in vec2 inUV;
  17. layout (location = 0) out vec4 outFragColor;
  18. void main()
  19. {
  20. vec3 fragPos = texture(samplerposition, inUV).rgb;
  21. vec3 normal = normalize(texture(samplerNormal, inUV).rgb * 2.0 - 1.0);
  22. vec4 albedo = texture(samplerAlbedo, inUV);
  23. float ssao = (uboParams.ssaoBlur == 1) ? texture(samplerSSAOBlur, inUV).r : texture(samplerSSAO, inUV).r;
  24. vec3 lightPos = vec3(0.0);
  25. vec3 L = normalize(lightPos - fragPos);
  26. float NdotL = max(0.5, dot(normal, L));
  27. if (uboParams.ssaoOnly == 1)
  28. {
  29. outFragColor.rgb = ssao.rrr;
  30. }
  31. else
  32. {
  33. vec3 baseColor = albedo.rgb * NdotL;
  34. if (uboParams.ssao == 1)
  35. {
  36. outFragColor.rgb = ssao.rrr;
  37. if (uboParams.ssaoOnly != 1)
  38. outFragColor.rgb *= baseColor;
  39. }
  40. else
  41. {
  42. outFragColor.rgb = baseColor;
  43. }
  44. }
  45. }