import bindless; import ibl_common; float2 SampleSphericalMap(float3 v) { const float2 InvTan = float2(0.1591f, 0.3183f); // (1/2PI, 1/PI) float2 UV = float2(atan2(-v.x, v.z), asin(-v.y)); // (-PI, -PI/2) to (PI, PI/2) UV *= InvTan; // (-1/2, -1/2) to (1/2, 1/2) UV += 0.5f.xx; // (0, 0) to (1, 1) return UV; } struct Block { Sampler2D.Handle hdrEnv; RWTexture2DArray.Handle outputTexture; uint cubeSide; }; [shader("compute")] [numthreads(16, 16, 1)] void main( uint3 GlobalInvocationID: SV_DispatchThreadID, uniform Block pcb ) { float3 LocalDir = GetCubeDir(GlobalInvocationID, pcb.cubeSide); float2 UV = SampleSphericalMap(LocalDir); pcb.outputTexture[GlobalInvocationID.xyz] = pcb.hdrEnv.SampleLevel(UV, 0); }