|
|
|
|
|
|
ScreenSpaceRayHit hit, |
|
|
|
float2 startPositionSS, |
|
|
|
float minLinearDepth, |
|
|
|
float settingsRayDepthSuccessBias, |
|
|
|
float settingsDepthBufferThickness, |
|
|
|
float thicknessWeight = clamp(1 - (hit.linearDepth - minLinearDepth) / settingsRayDepthSuccessBias, 0, 1); |
|
|
|
return thicknessWeight; |
|
|
|
float thicknessWeight = clamp(1 - (hit.linearDepth - minLinearDepth) / settingsDepthBufferThickness, 0, 1); |
|
|
|
// float2 screenDistanceNDC = abs(hit.positionSS.xy - startPositionSS) * _ScreenSize.zw; |
|
|
|
// float2 screenDistanceWeights = clamp((settingsRayMaxScreenDistance - screenDistanceNDC) / settingsRayBlendScreenDistance, 0, 1); |
|
|
|
// float screenDistanceWeight = min(screenDistanceWeights.x, screenDistanceWeights.y); |
|
|
|
float2 screenDistanceNDC = abs(hit.positionSS.xy - startPositionSS) * _ScreenSize.zw; |
|
|
|
float2 screenDistanceWeights = clamp((settingsRayMaxScreenDistance - screenDistanceNDC) / settingsRayBlendScreenDistance, 0, 1); |
|
|
|
float screenDistanceWeight = min(screenDistanceWeights.x, screenDistanceWeights.y); |
|
|
|
// return thicknessWeight * screenDistanceWeight; |
|
|
|
return thicknessWeight * screenDistanceWeight; |
|
|
|
} |
|
|
|
|
|
|
|
#ifdef DEBUG_DISPLAY |
|
|
|
|
|
|
// Settings |
|
|
|
int settingRayLevel, // Mip level to use to ray march depth buffer |
|
|
|
uint settingsRayMaxIterations, // Maximum number of iterations (= max number of depth samples) |
|
|
|
float settingsRayDepthSuccessBias, // Bias to use when trying to detect whenever we raymarch behind a surface |
|
|
|
float settingsDepthBufferThickness, // Bias to use when trying to detect whenever we raymarch behind a surface |
|
|
|
float settingsRayMaxScreenDistance, // Maximum screen distance raymarched |
|
|
|
float settingsRayBlendScreenDistance, // Distance to blend before maximum screen distance is reached |
|
|
|
int settingsDebuggedAlgorithm, // currently debugged algorithm (see PROJECTIONMODEL defines) |
|
|
|
|
|
|
invLinearDepth = LoadInvDepth(positionSS.xy, mipLevel); |
|
|
|
|
|
|
|
minLinearDepth = 1 / invLinearDepth.r; |
|
|
|
minLinearDepthWithThickness = minLinearDepth + settingsRayDepthSuccessBias; |
|
|
|
minLinearDepthWithThickness = minLinearDepth + settingsDepthBufferThickness; |
|
|
|
positionLinearDepth = 1 / positionSS.z; |
|
|
|
bool isAboveDepth = positionLinearDepth < minLinearDepth; |
|
|
|
bool isAboveThickness = positionLinearDepth < minLinearDepthWithThickness; |
|
|
|
|
|
|
hit, |
|
|
|
startPositionSS.xy, |
|
|
|
invLinearDepth, |
|
|
|
settingsRayDepthSuccessBias, |
|
|
|
settingsDepthBufferThickness, |
|
|
|
settingsRayMaxScreenDistance, |
|
|
|
settingsRayBlendScreenDistance |
|
|
|
); |
|
|
|
|
|
|
// Settings (linear) |
|
|
|
int settingRayLevel, // Mip level to use to ray march depth buffer |
|
|
|
uint settingsRayMaxIterations, // Maximum number of iterations (= max number of depth samples) |
|
|
|
float settingsRayDepthSuccessBias, // Bias to use when trying to detect whenever we raymarch behind a surface |
|
|
|
float settingsDepthBufferThickness, // Bias to use when trying to detect whenever we raymarch behind a surface |
|
|
|
float settingsRayMaxScreenDistance, // Maximum screen distance raymarched |
|
|
|
float settingsRayBlendScreenDistance, // Distance to blend before maximum screen distance is reached |
|
|
|
// Settings (common) |
|
|
|
|
|
|
// Settings |
|
|
|
settingRayLevel, |
|
|
|
settingsRayMaxIterations, |
|
|
|
settingsRayDepthSuccessBias, |
|
|
|
settingsDepthBufferThickness, |
|
|
|
settingsRayMaxScreenDistance, |
|
|
|
settingsRayBlendScreenDistance, |
|
|
|
settingsDebuggedAlgorithm, |
|
|
|
|
|
|
uint settingsRayMaxLevel, // Maximum mip level to use for ray marching the depth buffer in HiZ |
|
|
|
uint settingsRayMaxIterations, // Maximum number of iteration for the HiZ raymarching (= number of depth sample for HiZ) |
|
|
|
uint settingsRayMaxLinearIterations, // Maximum number of iteration for the linear raymarching (= number of depth sample for linear) |
|
|
|
float settingsRayDepthSuccessBias, // Bias to use when trying to detect whenever we raymarch behind a surface |
|
|
|
float settingsDepthBufferThickness, // Bias to use when trying to detect whenever we raymarch behind a surface |
|
|
|
float settingsRayMaxScreenDistance, // Maximum screen distance raymarched |
|
|
|
float settingsRayBlendScreenDistance, // Distance to blend before maximum screen distance is reached |
|
|
|
int settingsDebuggedAlgorithm, // currently debugged algorithm (see PROJECTIONMODEL defines) |
|
|
|
|
|
|
// settings |
|
|
|
settingsRayLevel, |
|
|
|
settingsRayMaxLinearIterations, |
|
|
|
settingsRayDepthSuccessBias, |
|
|
|
settingsDepthBufferThickness, |
|
|
|
settingsRayMaxScreenDistance, |
|
|
|
settingsRayBlendScreenDistance, |
|
|
|
settingsDebuggedAlgorithm, |
|
|
|
|
|
|
|
|
|
|
positionLinearDepth = 1 / positionSS.z; |
|
|
|
minLinearDepth = 1 / invLinearDepth.r; |
|
|
|
minLinearDepthWithThickness = minLinearDepth + settingsRayDepthSuccessBias; |
|
|
|
minLinearDepthWithThickness = minLinearDepth + settingsDepthBufferThickness; |
|
|
|
bool isAboveDepth = positionLinearDepth < minLinearDepth; |
|
|
|
bool isAboveThickness = positionLinearDepth < minLinearDepthWithThickness; |
|
|
|
bool isBehindDepth = !isAboveThickness; |
|
|
|
|
|
|
debugLoopMipMaxUsedLevel = max(debugLoopMipMaxUsedLevel, currentLevel); |
|
|
|
debugIterationPositionSS = positionSS; |
|
|
|
debugIterationLinearDepthBufferMin = 1 / invLinearDepth.r; |
|
|
|
debugIterationLinearDepthBufferMinThickness = 1 / invLinearDepth.r + settingsRayDepthSuccessBias; |
|
|
|
debugIterationLinearDepthBufferMinThickness = 1 / invLinearDepth.r + settingsDepthBufferThickness; |
|
|
|
debugIterationLinearDepthBufferMax = 1 / invLinearDepth.g; |
|
|
|
debugIteration = iteration; |
|
|
|
debugIterationIntersectionKind = intersectionKind; |
|
|
|
|
|
|
// hit, |
|
|
|
// startPositionSS.xy, |
|
|
|
// invLinearDepth, |
|
|
|
// settingsRayDepthSuccessBias, |
|
|
|
// settingsDepthBufferThickness, |
|
|
|
// settingsRayMaxScreenDistance, |
|
|
|
// settingsRayBlendScreenDistance |
|
|
|
// ); |
|
|
|
|
|
|
startPositionSS.xy, |
|
|
|
minLinearDepth, |
|
|
|
settingsRayDepthSuccessBias, |
|
|
|
settingsDepthBufferThickness, |
|
|
|
settingsRayMaxScreenDistance, |
|
|
|
settingsRayBlendScreenDistance |
|
|
|
); |
|
|
|
|
|
|
int SSRT_SETTING(RayMaxLevel, SSRTID); |
|
|
|
int SSRT_SETTING(RayMaxLinearIterations, SSRTID); |
|
|
|
int SSRT_SETTING(RayMaxIterations, SSRTID); |
|
|
|
float SSRT_SETTING(RayDepthSuccessBias, SSRTID); |
|
|
|
float SSRT_SETTING(DepthBufferThickness, SSRTID); |
|
|
|
float SSRT_SETTING(RayMaxScreenDistance, SSRTID); |
|
|
|
float SSRT_SETTING(RayBlendScreenDistance, SSRTID); |
|
|
|
|
|
|
|
|
|
|
// settings |
|
|
|
SSRT_SETTING(RayLevel, SSRTID), |
|
|
|
SSRT_SETTING(RayMaxIterations, SSRTID), |
|
|
|
max(0.01, SSRT_SETTING(RayDepthSuccessBias, SSRTID)), |
|
|
|
max(0.01, SSRT_SETTING(DepthBufferThickness, SSRTID)), |
|
|
|
SSRT_SETTING(RayMaxScreenDistance, SSRTID), |
|
|
|
SSRT_SETTING(RayBlendScreenDistance, SSRTID), |
|
|
|
#ifdef DEBUG_DISPLAY |
|
|
|
|
|
|
SSRT_SETTING(RayMaxLevel, SSRTID), |
|
|
|
SSRT_SETTING(RayMaxIterations, SSRTID), |
|
|
|
SSRT_SETTING(RayMaxLinearIterations, SSRTID), |
|
|
|
max(0.01, SSRT_SETTING(RayDepthSuccessBias, SSRTID)), |
|
|
|
max(0.01, SSRT_SETTING(DepthBufferThickness, SSRTID)), |
|
|
|
SSRT_SETTING(RayMaxScreenDistance, SSRTID), |
|
|
|
SSRT_SETTING(RayBlendScreenDistance, SSRTID), |
|
|
|
#ifdef DEBUG_DISPLAY |
|
|
|