48 lines
1.8 KiB
Plaintext
48 lines
1.8 KiB
Plaintext
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/TextureXR.hlsl"
|
|
|
|
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
|
|
|
|
#pragma kernel KDepthDownsample8DualUav KERNEL_SIZE=8 KERNEL_NAME=KDepthDownsample8DualUav
|
|
|
|
RW_TEXTURE2D_X(float, _DepthMipChain);
|
|
|
|
CBUFFER_START(cb)
|
|
uint4 _SrcOffsetAndLimit; // {x, y, w - 1, h - 1}
|
|
uint4 _DstOffset; // {x, y, 0, 0}
|
|
CBUFFER_END
|
|
|
|
#if UNITY_REVERSED_Z
|
|
# define MIN_DEPTH(l, r) max(l, r)
|
|
#else
|
|
# define MIN_DEPTH(l, r) min(l, r)
|
|
#endif
|
|
|
|
// Downsample a depth texture by taking the min value of sampled pixels
|
|
// The size of the dispatch is (DstMipSize / KernelSize).
|
|
[numthreads(KERNEL_SIZE, KERNEL_SIZE, 1)]
|
|
void KERNEL_NAME(uint3 dispatchThreadId : SV_DispatchThreadID)
|
|
{
|
|
UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadId.z);
|
|
|
|
uint2 srcOffset = _SrcOffsetAndLimit.xy;
|
|
uint2 srcLimit = _SrcOffsetAndLimit.zw;
|
|
uint2 dstOffset = _DstOffset.xy;
|
|
|
|
// Upper-left pixel coordinate of quad that this thread will read
|
|
uint2 srcPixelUL = srcOffset + (dispatchThreadId.xy << 1);
|
|
|
|
float p00 = _DepthMipChain[COORD_TEXTURE2D_X(min(srcPixelUL + uint2(0u, 0u), srcLimit))];
|
|
float p10 = _DepthMipChain[COORD_TEXTURE2D_X(min(srcPixelUL + uint2(1u, 0u), srcLimit))];
|
|
float p01 = _DepthMipChain[COORD_TEXTURE2D_X(min(srcPixelUL + uint2(0u, 1u), srcLimit))];
|
|
float p11 = _DepthMipChain[COORD_TEXTURE2D_X(min(srcPixelUL + uint2(1u, 1u), srcLimit))];
|
|
float4 depths = float4(p00, p10, p01, p11);
|
|
|
|
// Select the closest sample
|
|
float minDepth = MIN_DEPTH(MIN_DEPTH(depths.x, depths.y), MIN_DEPTH(depths.z, depths.w));
|
|
|
|
_DepthMipChain[COORD_TEXTURE2D_X(dstOffset + dispatchThreadId.xy)] = minDepth;
|
|
}
|
|
|
|
#undef MIN_DEPTH
|