|
|
|
|
|
|
|
|
|
|
#ifdef SSRTID |
|
|
|
|
|
|
|
#define SSRT_SETTING(name) _SS#SSRTID#name |
|
|
|
#define SSRT_FUNC(name) name#SSRTID |
|
|
|
#define SSRT_SETTING(name) _SS ## SSRTID ## name |
|
|
|
#define SSRT_FUNC(name) name ## SSRTID |
|
|
|
CBUFFER_START(SSRT_FUNC(UnityScreenSpaceRaymarching) |
|
|
|
CBUFFER_START(SSRT_FUNC(UnityScreenSpaceRaymarching)) |
|
|
|
int SSRT_SETTING(RayMinLevel); |
|
|
|
int SSRT_SETTING(RayMaxLevel); |
|
|
|
int SSRT_SETTING(RayMaxIterations); |
|
|
|
|
|
|
|
|
|
|
bool SSRT_FUNC(ScreenSpaceProxyRaycast)( |
|
|
|
ScreenSpaceEstimateRaycastInput input, |
|
|
|
ScreenSpaceProxyRaycastInput input, |
|
|
|
out ScreenSpaceRayHit hit |
|
|
|
) |
|
|
|
{ |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
float3 hitPositionWS = input.rayOriginWS + input.rayDirWS * projectionDistance; |
|
|
|
float3 hitPositionCS = ComputeClipSpacePosition(hitPositionWS, GetWorldToHClipMatrix()); |
|
|
|
float4 hitPositionCS = ComputeClipSpacePosition(hitPositionWS, GetWorldToHClipMatrix()); |
|
|
|
float2 hitPositionNDC = ComputeNormalizedDeviceCoordinates(hitPositionWS, GetWorldToHClipMatrix()); |
|
|
|
uint2 hitPositionSS = uint2(hitPositionNDC *_ScreenSize.xy); |
|
|
|
float hitLinearDepth = hitPositionCS.w; |
|
|
|
|
|
|
input.positionNDC = hitPositionNDC; |
|
|
|
input.positionSS = hitPositionSS; |
|
|
|
input.linearDepth = hitLinearDepth; |
|
|
|
hit.positionNDC = hitPositionNDC; |
|
|
|
hit.positionSS = hitPositionSS; |
|
|
|
hit.linearDepth = hitLinearDepth; |
|
|
|
|
|
|
|
bool hitSuccessful = linearDepth >= hitLinearDepth; |
|
|
|
|
|
|
|
|
|
|
ZERO_INITIALIZE(ScreenSpaceRayHit, hit); |
|
|
|
bool hitSuccessful = true; |
|
|
|
uint iteration = 0u; |
|
|
|
int minMipLevel = max(SSRT_SETTING(MinLevel), 0); |
|
|
|
int maxMipLevel = min(SSRT_SETTING(MaxLevel), int(_DepthPyramidScale.z)); |
|
|
|
int minMipLevel = max(SSRT_SETTING(RayMinLevel), 0); |
|
|
|
int maxMipLevel = min(SSRT_SETTING(RayMaxLevel), int(_DepthPyramidScale.z)); |
|
|
|
uint maxIterations = min(input.maxIterations, SSRT_SETTING(MaxIterations)); |
|
|
|
uint maxIterations = min(input.maxIterations, SSRT_SETTING(RayMaxIterations)); |
|
|
|
|
|
|
|
float3 startPositionSS; |
|
|
|
float3 raySS; |
|
|
|
|
|
|
hit.positionNDC = float2(positionSS.xy) / float2(bufferSize); |
|
|
|
hit.positionSS = uint2(positionSS.xy); |
|
|
|
|
|
|
|
if (hit.linearDepth > (1 / invHiZDepth) + SSRT_SETTING(DepthSuccessBias)) |
|
|
|
if (hit.linearDepth > (1 / invHiZDepth) + SSRT_SETTING(RayDepthSuccessBias)) |
|
|
|
hitSuccessful = false; |
|
|
|
|
|
|
|
#ifdef DEBUG_DISPLAY |
|
|
|
|
|
|
startPositionSS, |
|
|
|
hitSuccessful, |
|
|
|
iteration, |
|
|
|
SSRT_SETTING(MaxIterations), |
|
|
|
SSRT_SETTING(RayMaxIterations), |
|
|
|
maxMipLevel, |
|
|
|
maxUsedLevel, |
|
|
|
intersectionKind, |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#undef SSRT_SETTING |
|
|
|
#undef SSRT_FUNC |
|
|
|
#endif |