Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #version 450
  2.  
  3. #extension GL_AMD_shader_fragment_mask: enable
  4.  
  5. layout(set = 0, binding = 0)
  6. uniform sampler2DMSArray s_image;
  7.  
  8. layout(location = 0) out vec4 o_color;
  9.  
  10. void main() {
  11. int sampleCount = textureSamples(s_image);
  12. ivec3 coord = ivec3(gl_FragCoord.xy, gl_Layer);
  13.  
  14. // get a four-bit fragment index for each sample
  15. uint fragMask = fragmentMaskFetchAMD(s_image, coord);
  16.  
  17. // count number of occurences of each fragment
  18. // index in one four-bit counter for each sample
  19. uint fragCount = 0u;
  20.  
  21. for (int i = 0; i < 4 * sampleCount; i += 4) {
  22. uint fragIndex = bitfieldExtract(fragMask, i, 4);
  23. fragCount += 1u << (fragIndex << 2);
  24. }
  25.  
  26. // perform necessary texture lookups to compute
  27. // final fragment color
  28. o_color = vec4(0.0f);
  29.  
  30. while (fragCount != 0) {
  31. int fragIndex = findLSB(fragCount) >> 2;
  32. int fragShift = fragIndex << 2;
  33.  
  34. o_color += fragmentFetchAMD(s_image, coord, fragIndex)
  35. * float(bitfieldExtract(fragCount, fragShift, 4));
  36.  
  37. fragCount = bitfieldInsert(fragCount, 0, fragShift, 4);
  38. }
  39.  
  40. o_color /= float(sampleCount);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement