Advertisement
Zgragselus

Generate mipmaps max

May 25th, 2024
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.00 KB | None | 0 0
  1. [numthreads(8, 8, 1)]
  2. void GenerateMipmapsMax(uint GI : SV_GroupIndex, uint3 DTid : SV_DispatchThreadID)
  3. {
  4.     SAMPLER_TYPE src0;
  5.     SAMPLER_TYPE src1;
  6.     SAMPLER_TYPE src2;
  7.     SAMPLER_TYPE src3;
  8.    
  9.     SAMPLER_TYPE max0;
  10.  
  11.     // Sample each pixel and perform max when needed due to non-power-of-two
  12.     float2 uv = (DTid.xy + 0.5f) * texelSize;
  13.     if (npotFlag == 0)
  14.     {
  15.         src0 = srcLevel.SampleLevel(srcSampler, uv, srcMiplevel);
  16.     }
  17.     else if (npotFlag == 1)
  18.     {
  19.         src0 = max(srcLevel.SampleLevel(srcSampler, uv, srcMiplevel), srcLevel.SampleLevel(srcSampler, uv + float2(texelSize.x, 0.0f), srcMiplevel));
  20.     }
  21.     else if (npotFlag == 2)
  22.     {
  23.         src0 = max(srcLevel.SampleLevel(srcSampler, uv, srcMiplevel), srcLevel.SampleLevel(srcSampler, uv + float2(0.0f, texelSize.y), srcMiplevel));
  24.     }
  25.     else
  26.     {
  27.         src0 = max(max(srcLevel.SampleLevel(srcSampler, uv, srcMiplevel), srcLevel.SampleLevel(srcSampler, uv + float2(texelSize.x, 0.0f), srcMiplevel)),
  28.             max(srcLevel.SampleLevel(srcSampler, uv + float2(0.0f, texelSize.y), srcMiplevel), srcLevel.SampleLevel(srcSampler, uv + float2(texelSize.x, texelSize.y), srcMiplevel)));
  29.     }
  30.     StoreColor(GI, src0);
  31.     GroupMemoryBarrierWithGroupSync();
  32.  
  33.     if ((GI & 0x9) == 0)
  34.     {
  35.         src1 = LoadColor(GI + 0x01);
  36.         src2 = LoadColor(GI + 0x08);
  37.         src3 = LoadColor(GI + 0x09);
  38.  
  39.         max0 = max(max(src0, src1), max(src2, src3));
  40.  
  41.         mipLevel1[DTid.xy / 2] = max0;
  42.  
  43.         StoreColor(GI, max0);
  44.     }
  45.  
  46.     if (mipLevels == 1)
  47.     {
  48.         return;
  49.     }
  50.  
  51.     GroupMemoryBarrierWithGroupSync();
  52.  
  53.     if ((GI & 0x1B) == 0)
  54.     {
  55.         src1 = LoadColor(GI + 0x02);
  56.         src2 = LoadColor(GI + 0x10);
  57.         src3 = LoadColor(GI + 0x12);
  58.  
  59.         max0 = max(max(src0, src1), max(src2, src3));
  60.  
  61.         mipLevel2[DTid.xy / 4] = max0;
  62.  
  63.         StoreColor(GI, max0);
  64.     }
  65.  
  66.     if (mipLevels == 2)
  67.     {
  68.         return;
  69.     }
  70.  
  71.     GroupMemoryBarrierWithGroupSync();
  72.  
  73.     if (GI == 0)
  74.     {
  75.         src1 = LoadColor(GI + 0x04);
  76.         src2 = LoadColor(GI + 0x20);
  77.         src3 = LoadColor(GI + 0x24);
  78.  
  79.         max0 = max(max(src0, src1), max(src2, src3));
  80.  
  81.         mipLevel3[DTid.xy / 8] = max0;
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement