daily pastebin goal
84%
SHARE
TWEET

Untitled

a guest May 20th, 2017 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cbuffer InputDimensions : register(b0)
  2. {
  3.     uint3 dimensions;
  4. }
  5.  
  6. cbuffer InputMiplevels : register(b1)
  7. {
  8.     uint srcMiplevel;
  9.     uint miplevels;
  10.     float texelSize;
  11. }
  12.  
  13. SamplerState srcSampler : register(s0);
  14. Texture3D<float4> srcLevel : register(t0);
  15. RWTexture3D<float4> mipLevel1 : register(u0);
  16. RWTexture3D<float4> mipLevel2 : register(u1);
  17.  
  18. groupshared float tmpR[64];
  19. groupshared float tmpG[64];
  20. groupshared float tmpB[64];
  21. groupshared float tmpA[64];
  22.  
  23. void StoreColor(uint idx, float4 color)
  24. {
  25.     tmpR[idx] = color.r;
  26.     tmpG[idx] = color.g;
  27.     tmpB[idx] = color.b;
  28.     tmpA[idx] = color.a;
  29. }
  30.  
  31. float4 LoadColor(uint idx)
  32. {
  33.     return float4(tmpR[idx], tmpG[idx], tmpB[idx], tmpA[idx]);
  34. }
  35.  
  36. float HasVoxel(float4 color)
  37. {
  38.     return color.a > 0.0f ? 1.0f : 0.0f;
  39. }
  40.  
  41. [numthreads(4, 4, 4)]
  42. void CS(uint GI : SV_GroupIndex, uint3 DTid : SV_DispatchThreadID)
  43. {
  44.     float4 src[8];
  45.     float3 uvw = (DTid.xyz + 0.5f) * texelSize;
  46.     src[0] = srcLevel.SampleLevel(srcSampler, uvw, (float)srcMiplevel);
  47.     StoreColor(GI, src[0]);
  48.     GroupMemoryBarrierWithGroupSync();
  49.  
  50.     if ((GI & 0x15) == 0)
  51.     {
  52.         src[1] = LoadColor(GI + 0x01);
  53.         src[2] = LoadColor(GI + 0x04);
  54.         src[3] = LoadColor(GI + 0x05);
  55.         src[4] = LoadColor(GI + 0x10);
  56.         src[5] = LoadColor(GI + 0x11);
  57.         src[6] = LoadColor(GI + 0x14);
  58.         src[7] = LoadColor(GI + 0x15);
  59.  
  60.         float div = 0.0f;
  61.         for (int i = 0; i < 8; i++)
  62.         {
  63.             div += HasVoxel(src[i]);
  64.         }
  65.  
  66.         if (div == 0.0f)
  67.         {
  68.             src[0] = 0.0f;
  69.         }
  70.         else
  71.         {
  72.             src[0] = (src[0] + src[1] + src[2] + src[3] + src[4] + src[5] + src[6] + src[7]) / div;
  73.         }
  74.  
  75.         mipLevel1[DTid / 2] = src[0];
  76.         StoreColor(GI, src[0]);
  77.     }
  78.  
  79.     if (miplevels == 1)
  80.     {
  81.         return;
  82.     }
  83.  
  84.     GroupMemoryBarrierWithGroupSync();
  85.  
  86.     if (GI == 0)
  87.     {
  88.         src[1] = LoadColor(GI + 0x02);
  89.         src[2] = LoadColor(GI + 0x08);
  90.         src[3] = LoadColor(GI + 0x0A);
  91.         src[4] = LoadColor(GI + 0x10);
  92.         src[5] = LoadColor(GI + 0x12);
  93.         src[6] = LoadColor(GI + 0x18);
  94.         src[7] = LoadColor(GI + 0x1A);
  95.  
  96.         float div = 0.0f;
  97.         for (int i = 0; i < 8; i++)
  98.         {
  99.             div += HasVoxel(src[i]);
  100.         }
  101.  
  102.         if (div == 0.0f)
  103.         {
  104.             src[0] = 0.0f;
  105.         }
  106.         else
  107.         {
  108.             src[0] = (src[0] + src[1] + src[2] + src[3] + src[4] + src[5] + src[6] + src[7]) / div;
  109.         }
  110.  
  111.         mipLevel2[DTid / 4] = src[0];
  112.     }
  113. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top