1 #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
2 #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/BC6H.hlsl"
3 #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Sampling/Sampling.hlsl"
5 #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch
7 TextureCube<float4> _Source;
8 RWTexture2DArray<uint4> _Target;
11 SAMPLER(s_point_clamp);
13 static const uint2 kOffsets[] =
15 uint2(0, 0), uint2(1, 0), uint2(2, 0), uint2(3, 0),
16 uint2(0, 1), uint2(1, 1), uint2(2, 1), uint2(3, 1),
17 uint2(0, 2), uint2(1, 2), uint2(2, 2), uint2(3, 2),
18 uint2(0, 3), uint2(1, 3), uint2(2, 3), uint2(3, 3),
21 #pragma kernel KEncodeFastCubemapMip
23 void KEncodeFastCubemapMip(uint3 groupId : SV_GroupID, uint3 groupThreadId : SV_GroupThreadID, uint3 dispatchThreadId : SV_DispatchThreadID)
27 _Source.GetDimensions(width, height);
28 int size = width >> _MipIndex;
30 // Load 4x4 pixel block
33 uint2 topLeftSourceID = dispatchThreadId.xy << 2;
34 uint faceId = dispatchThreadId.z;
38 for (uint i = 0u; i < 16; ++i)
40 nvc = CubemapTexelToNVC(topLeftSourceID + kOffsets[i], size);
41 dir = CubemapTexelToDirection(nvc, faceId);
42 texels[i] = SAMPLE_TEXTURECUBE_LOD(_Source, s_point_clamp, dir, _MipIndex).rgb;
45 uint4 block = uint4(0, 0, 0, 0);
48 EncodeMode11(block, blockMSLE, texels);
50 _Target[dispatchThreadId] = block;