|
|
|
|
|
|
int settingRayLevel, // Mip level to use to ray march depth buffer |
|
|
|
uint settingsRayMaxIterations, // Maximum number of iterations (= max number of depth samples) |
|
|
|
int settingsDebuggedAlgorithm, // currently debugged algorithm (see PROJECTIONMODEL defines) |
|
|
|
float settingsRayDepthSuccessBias, // Bias to use when trying to detect whenever we raymarch behind a surface |
|
|
|
// Precomputed properties |
|
|
|
float3 startPositionSS, // Start position in Screen Space (x in pixel, y in pixel, z = 1/linearDepth) |
|
|
|
float3 raySS, // Ray direction in Screen Space (dx in pixel, dy in pixel, z = 1/endPointLinearDepth - 1/startPointLinearDepth) |
|
|
|
|
|
|
) |
|
|
|
{ |
|
|
|
ZERO_INITIALIZE(ScreenSpaceRayHit, hit); |
|
|
|
bool hitSuccessful = true; |
|
|
|
bool hitSuccessful = false; |
|
|
|
iteration = 0u; |
|
|
|
int mipLevel = min(max(settingRayLevel, 0), int(_DepthPyramidScale.z)); |
|
|
|
uint maxIterations = settingsRayMaxIterations; |
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_DISPLAY |
|
|
|
// Fetch post iteration debug values |
|
|
|
if (input.debug && _DebugStep >= iteration) |
|
|
|
if (input.debug && _DebugStep >= int(iteration)) |
|
|
|
{ |
|
|
|
debugIterationPositionSS = positionSS; |
|
|
|
debugIterationLinearDepthBuffer = 1 / invLinearDepth; |
|
|
|
|
|
|
|
|
|
|
if (!IsPositionAboveDepth(positionSS.z, invLinearDepth)) |
|
|
|
{ |
|
|
|
hitSuccessful = true; |
|
|
|
} |
|
|
|
|
|
|
|
// Check if we are out of the buffer |
|
|
|
if (any(int2(positionSS.xy) > int2(bufferSize)) |
|
|
|
|
|
|
hit.linearDepth = 1 / positionSS.z; |
|
|
|
hit.positionNDC = float2(positionSS.xy) / float2(bufferSize); |
|
|
|
hit.positionSS = uint2(positionSS.xy); |
|
|
|
|
|
|
|
if (hit.linearDepth > (1 / invLinearDepth) + settingsRayDepthSuccessBias) |
|
|
|
hitSuccessful = false; |
|
|
|
|
|
|
|
#ifdef DEBUG_DISPLAY |
|
|
|
DebugComputeCommonOutput(input.rayDirWS, hitSuccessful, PROJECTIONMODEL_LINEAR, hit); |
|
|
|
|
|
|
// Settings (linear) |
|
|
|
int settingRayLevel, // Mip level to use to ray march depth buffer |
|
|
|
uint settingsRayMaxIterations, // Maximum number of iterations (= max number of depth samples) |
|
|
|
uint settingsIterationBlending, // Number of linear raymarching iterations to blend with proxy raycast |
|
|
|
float settingsRayDepthSuccessBias, // Bias to use when trying to detect whenever we raymarch behind a surface |
|
|
|
out ScreenSpaceRayHit linearHit, // Linear raymarching hit |
|
|
|
out ScreenSpaceRayHit proxyHit, // Proxy raycasting hit |
|
|
|
float hitBlending // hit = linearHit * (1.0 - hitBlending) + proxyHit * hitBlending |
|
|
|
out ScreenSpaceRayHit hit |
|
|
|
) |
|
|
|
{ |
|
|
|
// Perform linear raymarch |
|
|
|
|
|
|
settingRayLevel, |
|
|
|
settingsRayMaxIterations, |
|
|
|
settingsDebuggedAlgorithm, |
|
|
|
settingsRayDepthSuccessBias, |
|
|
|
// Precomputed properties |
|
|
|
startPositionSS, |
|
|
|
raySS, |
|
|
|
|
|
|
linearHit, |
|
|
|
hit, |
|
|
|
hitBlending = settingsIterationBlending > 0 |
|
|
|
? 1.0 + (int(iteration) - int(settingsRayMaxIterations)) / float(settingsIterationBlending) |
|
|
|
: 0; |
|
|
|
|
|
|
|
if (!hitSuccessful || hitBlending > 0) |
|
|
|
if (!hitSuccessful) |
|
|
|
bool proxyHitSuccessful = ScreenSpaceProxyRaycast( |
|
|
|
hitSuccessful = ScreenSpaceProxyRaycast( |
|
|
|
proxyHit |
|
|
|
hit |
|
|
|
|
|
|
|
hitSuccessful = hitSuccessful && proxyHitSuccessful; |
|
|
|
} |
|
|
|
|
|
|
|
return hitSuccessful; |
|
|
|
|
|
|
|
|
|
|
// Initialize loop |
|
|
|
ZERO_INITIALIZE(ScreenSpaceRayHit, hit); |
|
|
|
bool hitSuccessful = true; |
|
|
|
bool hitSuccessful = false; |
|
|
|
uint iteration = 0u; |
|
|
|
int minMipLevel = max(settingsRayMinLevel, 0u); |
|
|
|
int maxMipLevel = min(settingsRayMaxLevel, uint(_DepthPyramidScale.z)); |
|
|
|
|
|
|
// settings |
|
|
|
settingsRayLevel, |
|
|
|
settingsRayMaxLinearIterations, |
|
|
|
settingsRayDepthSuccessBias, |
|
|
|
#ifdef DEBUG_DISPLAY |
|
|
|
settingsDebuggedAlgorithm, |
|
|
|
#else |
|
|
|
|
|
|
|
|
|
|
while (currentLevel >= minMipLevel) |
|
|
|
{ |
|
|
|
hitSuccessful = true; |
|
|
|
if (iteration >= maxIterations) |
|
|
|
{ |
|
|
|
hitSuccessful = false; |
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_DISPLAY |
|
|
|
// Fetch pre iteration debug values |
|
|
|
if (input.debug && _DebugStep >= iteration) |
|
|
|
if (input.debug && _DebugStep >= int(iteration)) |
|
|
|
debugIterationMipLevel = currentLevel; |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_DISPLAY |
|
|
|
// Fetch post iteration debug values |
|
|
|
if (input.debug && _DebugStep >= iteration) |
|
|
|
if (input.debug && _DebugStep >= int(iteration)) |
|
|
|
{ |
|
|
|
debugLoopMipMaxUsedLevel = max(debugLoopMipMaxUsedLevel, currentLevel); |
|
|
|
debugIterationPositionSS = positionSS; |
|
|
|
|
|
|
int SSRT_SETTING(RayMaxLevel, SSRTID); |
|
|
|
int SSRT_SETTING(RayMaxLinearIterations, SSRTID); |
|
|
|
int SSRT_SETTING(RayMaxIterations, SSRTID); |
|
|
|
int SSRT_SETTING(RayIterationBlending, SSRTID); |
|
|
|
float SSRT_SETTING(RayDepthSuccessBias, SSRTID); |
|
|
|
|
|
|
|
#ifdef DEBUG_DISPLAY |
|
|
|
|
|
|
// settings |
|
|
|
SSRT_SETTING(RayLevel, SSRTID), |
|
|
|
SSRT_SETTING(RayMaxIterations, SSRTID), |
|
|
|
SSRT_SETTING(RayDepthSuccessBias, SSRTID), |
|
|
|
#ifdef DEBUG_DISPLAY |
|
|
|
SSRT_SETTING(DebuggedAlgorithm, SSRTID), |
|
|
|
#else |
|
|
|
|
|
|
// ------------------------------------------------- |
|
|
|
bool MERGE_NAME(ScreenSpaceProxyRaycast, SSRTID)( |
|
|
|
ScreenSpaceProxyRaycastInput input, |
|
|
|
out ScreenSpaceRayHit primaryHit, |
|
|
|
out ScreenSpaceRayHit secondaryHit, |
|
|
|
out float hitBlending |
|
|
|
out ScreenSpaceRayHit hit |
|
|
|
hitBlending = 0; |
|
|
|
return ScreenSpaceLinearProxyRaycast( |
|
|
|
return ScreenSpaceProxyRaycast( |
|
|
|
// Settings (linear) |
|
|
|
SSRT_SETTING(RayLevel, SSRTID), |
|
|
|
SSRT_SETTING(RayMaxLinearIterations, SSRTID), |
|
|
|
SSRT_SETTING(RayIterationBlending, SSRTID), |
|
|
|
// Settings (common) |
|
|
|
// Settings |
|
|
|
PROJECTIONMODEL_NONE, |
|
|
|
int(PROJECTIONMODEL_NONE), |
|
|
|
primaryHit, |
|
|
|
secondaryHit, |
|
|
|
hitBlending |
|
|
|
hit |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|