Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cbuffer InputDimensions : register(b0)
- {
- uint3 dimensions;
- }
- cbuffer InputMiplevels : register(b1)
- {
- uint srcMiplevel;
- uint miplevels;
- float texelSize;
- }
- SamplerState srcSampler : register(s0);
- Texture3D<float4> srcLevel : register(t0);
- RWTexture3D<float4> mipLevel1 : register(u0);
- RWTexture3D<float4> mipLevel2 : register(u1);
- groupshared float tmpR[64];
- groupshared float tmpG[64];
- groupshared float tmpB[64];
- groupshared float tmpA[64];
- void StoreColor(uint idx, float4 color)
- {
- tmpR[idx] = color.r;
- tmpG[idx] = color.g;
- tmpB[idx] = color.b;
- tmpA[idx] = color.a;
- }
- float4 LoadColor(uint idx)
- {
- return float4(tmpR[idx], tmpG[idx], tmpB[idx], tmpA[idx]);
- }
- float HasVoxel(float4 color)
- {
- return color.a > 0.0f ? 1.0f : 0.0f;
- }
- [numthreads(4, 4, 4)]
- void CS(uint GI : SV_GroupIndex, uint3 DTid : SV_DispatchThreadID)
- {
- float4 src[8];
- float3 uvw = (DTid.xyz + 0.5f) * texelSize;
- src[0] = srcLevel.SampleLevel(srcSampler, uvw, (float)srcMiplevel);
- StoreColor(GI, src[0]);
- GroupMemoryBarrierWithGroupSync();
- if ((GI & 0x15) == 0)
- {
- src[1] = LoadColor(GI + 0x01);
- src[2] = LoadColor(GI + 0x04);
- src[3] = LoadColor(GI + 0x05);
- src[4] = LoadColor(GI + 0x10);
- src[5] = LoadColor(GI + 0x11);
- src[6] = LoadColor(GI + 0x14);
- src[7] = LoadColor(GI + 0x15);
- float div = 0.0f;
- for (int i = 0; i < 8; i++)
- {
- div += HasVoxel(src[i]);
- }
- if (div == 0.0f)
- {
- src[0] = 0.0f;
- }
- else
- {
- src[0] = (src[0] + src[1] + src[2] + src[3] + src[4] + src[5] + src[6] + src[7]) / div;
- }
- mipLevel1[DTid / 2] = src[0];
- StoreColor(GI, src[0]);
- }
- if (miplevels == 1)
- {
- return;
- }
- GroupMemoryBarrierWithGroupSync();
- if (GI == 0)
- {
- src[1] = LoadColor(GI + 0x02);
- src[2] = LoadColor(GI + 0x08);
- src[3] = LoadColor(GI + 0x0A);
- src[4] = LoadColor(GI + 0x10);
- src[5] = LoadColor(GI + 0x12);
- src[6] = LoadColor(GI + 0x18);
- src[7] = LoadColor(GI + 0x1A);
- float div = 0.0f;
- for (int i = 0; i < 8; i++)
- {
- div += HasVoxel(src[i]);
- }
- if (div == 0.0f)
- {
- src[0] = 0.0f;
- }
- else
- {
- src[0] = (src[0] + src[1] + src[2] + src[3] + src[4] + src[5] + src[6] + src[7]) / div;
- }
- mipLevel2[DTid / 4] = src[0];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement