Advertisement
Zgragselus

Mipmap.hlsl

May 27th, 2025
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. //#include "Mipmap.hlsli"
  2.  
  3. SamplerState srcSampler : register(s0);
  4. Texture2D<float4> srcLevel : register(t0);
  5. RWTexture2D<float4> mipLevel1 : register(u0);
  6. RWTexture2D<float4> mipLevel2 : register(u1);
  7. RWTexture2D<float4> mipLevel3 : register(u2);
  8. RWTexture2D<float4> mipLevel4 : register(u3);
  9.  
  10. cbuffer InputMiplevels : register(b0)
  11. {
  12. uint srcMiplevel;
  13. uint miplevels;
  14. float2 texelSize;
  15. }
  16.  
  17. groupshared float4 tmp[8];
  18.  
  19. void StoreColor(uint idx, float4 color)
  20. {
  21. tmp[idx] = color;
  22. }
  23.  
  24. float4 LoadColor(uint idx)
  25. {
  26. return tmp[idx];
  27. }
  28.  
  29. [numthreads(2, 2, 1)]
  30. void GenerateMipmaps(uint GI : SV_GroupIndex, uint3 DTid : SV_DispatchThreadID)
  31. {
  32. float4 src0;
  33. float4 src1;
  34. float4 src2;
  35. float4 src3;
  36. float2 uv = (DTid.xy + 0.5f) * texelSize;
  37. src0 = srcLevel.SampleLevel(srcSampler, uv, srcMiplevel);
  38. StoreColor(GI, src0);
  39. GroupMemoryBarrierWithGroupSync();
  40.  
  41. if (GI == 0)
  42. {
  43. src1 = LoadColor(GI + 0x01);
  44. src2 = LoadColor(GI + 0x02);
  45. src3 = LoadColor(GI + 0x03);
  46.  
  47. //mipLevel1[DTid.xy / 2] = float4(min(min(src0.x, src1.x), min(src2.x, src3.x)), max(max(src0.x, src1.x), max(src2.x, src3.x)), 0.0f, 0.0f);
  48. mipLevel1[DTid.xy / 2] = (src0 + src1 + src2 + src3) / 4;
  49. }
  50. }
  51.  
  52. [numthreads(2, 2, 1)]
  53. void GenerateMipmapsMinMax(uint GI : SV_GroupIndex, uint3 DTid : SV_DispatchThreadID)
  54. {
  55. float4 src0;
  56. float4 src1;
  57. float4 src2;
  58. float4 src3;
  59. float2 uv = (DTid.xy + 0.5f) * texelSize;
  60. src0 = srcLevel.SampleLevel(srcSampler, uv, srcMiplevel);
  61. StoreColor(GI, src0);
  62. GroupMemoryBarrierWithGroupSync();
  63.  
  64. if (GI == 0)
  65. {
  66. src1 = LoadColor(GI + 0x01);
  67. src2 = LoadColor(GI + 0x02);
  68. src3 = LoadColor(GI + 0x03);
  69.  
  70. mipLevel1[DTid.xy / 2] = float4(min(min(src0.x, src1.x), min(src2.x, src3.x)), max(max(src0.x, src1.x), max(src2.x, src3.x)), 0.0f, 0.0f);
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement