您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
44 行
1.7 KiB
44 行
1.7 KiB
#include "CoreRP/ShaderLibrary/Common.hlsl"
|
|
|
|
#pragma kernel KMain_8 KERNEL_SIZE=8 KERNEL_NAME=KMain_8
|
|
#pragma kernel KMain_1 KERNEL_SIZE=1 KERNEL_NAME=KMain_1
|
|
|
|
Texture2D<float> _Source;
|
|
RWTexture2D<float> _Result;
|
|
|
|
SamplerState sampler_PointClamp; //TODO: could we use min-sampler instead of using ALU?
|
|
|
|
CBUFFER_START(cb)
|
|
float4 _SrcSize;
|
|
CBUFFER_END
|
|
|
|
|
|
[numthreads(KERNEL_SIZE, KERNEL_SIZE, 1)]
|
|
void KERNEL_NAME(uint2 groupId : SV_GroupID, uint2 groupThreadId : SV_GroupThreadID, uint2 dispatchThreadId : SV_DispatchThreadID)
|
|
{
|
|
// Upper-left pixel coordinate of quad that this thread will read
|
|
int2 threadUL = dispatchThreadId;
|
|
|
|
// Downsample the block
|
|
float2 offset = float2(threadUL) * 2.0f + 1.0f;
|
|
#if defined(PLATFORM_SUPPORT_GATHER)
|
|
float4 depths = GATHER_RED_TEXTURE2D(_Source, sampler_PointClamp, offset * _SrcSize.zw, 0.0);
|
|
#else
|
|
// Downsample the block
|
|
float p00 = SAMPLE_TEXTURE2D_LOD(_Source, sampler_PointClamp, (offset) * _SrcSize.zw, 0.0).x;
|
|
float p10 = SAMPLE_TEXTURE2D_LOD(_Source, sampler_PointClamp, (offset + float2(1.0, 0.0)) * _SrcSize.zw, 0.0).x;
|
|
float p01 = SAMPLE_TEXTURE2D_LOD(_Source, sampler_PointClamp, (offset + float2(0.0, 1.0)) * _SrcSize.zw, 0.0).x;
|
|
float p11 = SAMPLE_TEXTURE2D_LOD(_Source, sampler_PointClamp, (offset + float2(1.0, 1.0)) * _SrcSize.zw, 0.0).x;
|
|
float4 depths = float4(p00, p10, p01, p11);
|
|
#endif
|
|
|
|
// Select the nearest sample
|
|
#if UNITY_REVERSED_Z
|
|
float minDepth = max(max(depths.x, depths.y), max(depths.z, depths.w));
|
|
#else
|
|
float minDepth = min(min(depths.x, depths.y), min(depths.z, depths.w));
|
|
#endif
|
|
|
|
// Write to the final target
|
|
_Result[dispatchThreadId] = minDepth;
|
|
}
|