Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 4th, 2012  |  syntax: C  |  size: 0.89 KB  |  views: 50  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #version 420 core
  2. layout(r32ui) coherent uniform uimage2D img2D_0;
  3. layout(RGBA32F) coherent uniform image2D img2D_1;
  4. vec4 insert(vec4 data, float new_data) {
  5.         if      (new_data<data.x) return vec4(      new_data,data.xyz);
  6.         else if (new_data<data.y) return vec4(data.x,new_data,data.yz);
  7.         else if (new_data<data.z) return vec4(data.xy,new_data,data.z);
  8.         else if (new_data<data.w) return vec4(data.xyz,new_data      );
  9.         else                      return data;
  10. }
  11. void main() {
  12.         ivec2 coord = ivec2(gl_FragCoord.xy);
  13.         bool have_written = false;
  14.         while (!have_written) {
  15.                 bool can_write = (imageAtomicExchange(img2D_0,coord,1u) != 1u);
  16.                 vec4 depths = imageLoad(img2D_1,coord);
  17.                 depths = insert(depths,gl_FragCoord.z);
  18.                 if (can_write) {
  19.                         imageStore(img2D_1,coord,depths);
  20.                         have_written = true;
  21.                 }
  22.                 memoryBarrier();
  23.                 imageAtomicExchange(img2D_0,coord,0);
  24.                 memoryBarrier();
  25.         }
  26. }
clone this paste RAW Paste Data