worldPostFragment.fs 895 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #version 430
  2. layout (binding = 0) uniform sampler2D colorSamp;
  3. layout (binding = 1) uniform sampler2D ssaoSamp;
  4. layout (binding = 2) uniform sampler2D shadowSamp;
  5. uniform bool useSSAO;
  6. in vec2 varTex;
  7. out vec4 color;
  8. void main()
  9. {
  10. if(useSSAO)
  11. {
  12. color = vec4(texture(colorSamp, varTex).xyz * (texture(ssaoSamp, varTex).r + 0.5), 1.0);
  13. }
  14. else
  15. {
  16. color = vec4(texture(colorSamp, varTex).xyz, 1.0);
  17. }
  18. vec2 texelSize = 1.0 / vec2(textureSize(shadowSamp, 0));
  19. float result = 0.0;
  20. const int radius = 5;
  21. for(int x = -radius; x < radius; x++)
  22. {
  23. for(int y = -radius; y < radius; y++)
  24. {
  25. vec2 offset = vec2(float(x), float(y)) * texelSize;
  26. result += texture(shadowSamp, varTex + offset).r;
  27. }
  28. }
  29. result /= (radius * radius * 4);
  30. result = result * 0.5 + 0.5;
  31. color *= result;
  32. }