No Description

debug.frag 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. layout (binding = 1) uniform sampler2DMS samplerPosition;
  5. layout (binding = 2) uniform sampler2DMS samplerNormal;
  6. layout (binding = 3) uniform sampler2DMS samplerAlbedo;
  7. layout (location = 0) in vec3 inUV;
  8. layout (location = 0) out vec4 outFragColor;
  9. #define NUM_SAMPLES 8
  10. vec4 resolve(sampler2DMS tex, ivec2 uv)
  11. {
  12. vec4 result = vec4(0.0);
  13. int count = 0;
  14. for (int i = 0; i < NUM_SAMPLES; i++)
  15. {
  16. vec4 val = texelFetch(tex, uv, i);
  17. result += val;
  18. count++;
  19. }
  20. return result / float(NUM_SAMPLES);
  21. }
  22. void main()
  23. {
  24. ivec2 attDim = textureSize(samplerPosition);
  25. ivec2 UV = ivec2(inUV.st * attDim * 2.0);
  26. highp int index = 0;
  27. if (inUV.s > 0.5)
  28. {
  29. index = 1;
  30. UV.s -= attDim.x;
  31. }
  32. if (inUV.t > 0.5)
  33. {
  34. index = 2;
  35. UV.t -= attDim.y;
  36. }
  37. vec3 components[3];
  38. components[0] = resolve(samplerPosition, UV).rgb;
  39. components[1] = resolve(samplerNormal, UV).rgb;
  40. components[2] = resolve(samplerAlbedo, UV).rgb;
  41. // Uncomment to display specular component
  42. //components[2] = vec3(texture(samplerAlbedo, inUV.st).a);
  43. // Select component depending on UV
  44. outFragColor.rgb = components[index];
  45. }