#include "ibl_common.hlsli" struct Block { uint HdrEnvHandle; uint OutputTextureHandle; int CubeSide; }; [[vk::push_constant]] Block pcb; 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; } [numthreads(16, 16, 1)] void main(uint3 GlobalInvocationID : SV_DispatchThreadID) { float3 LocalDir = GetCubeDir(GlobalInvocationID, pcb.CubeSide); float2 UV = SampleSphericalMap(LocalDir); StorageTextureArrays[pcb.OutputTextureHandle][GlobalInvocationID.xyz] = Textures[pcb.HdrEnvHandle].SampleLevel(ImmutableSamplers[pcb.HdrEnvHandle], UV, 0); }