|
|
|
|
|
|
return geomSeries / (g_fFarPlane - g_fNearPlane); |
|
|
|
} |
|
|
|
|
|
|
|
float LogBase(float x, float b) |
|
|
|
{ |
|
|
|
return log2(x) / log2(b); |
|
|
|
} |
|
|
|
|
|
|
|
int SnapToClusterIdxFlex(float z_in, float suggestedBase, bool logBasePerTile) |
|
|
|
{ |
|
|
|
#if USE_LEFT_HAND_CAMERA_SPACE |
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
float userscale = g_fClustScale; |
|
|
|
if (logBasePerTile) |
|
|
|
userscale = GetScaleFromBase(suggestedBase); |
|
|
|
//float userscale = g_fClustScale; |
|
|
|
//if (logBasePerTile) |
|
|
|
// userscale = GetScaleFromBase(suggestedBase); |
|
|
|
const float dist = max(0, z - g_fNearPlane); |
|
|
|
return (int)clamp(log2(dist * userscale * (suggestedBase - 1.0f) + 1) / log2(suggestedBase), 0.0, (float)((1 << g_iLog2NumClusters) - 1)); |
|
|
|
//const float dist = max(0, z - g_fNearPlane); |
|
|
|
//return (int)clamp(log2(dist * userscale * (suggestedBase - 1.0f) + 1) / log2(suggestedBase), 0.0, (float)((1 << g_iLog2NumClusters) - 1)); |
|
|
|
|
|
|
|
const float C = (float)(1 << g_iLog2NumClusters); |
|
|
|
const float rangeFittedDistance = max(0, z - g_fNearPlane) / (g_fFarPlane - g_fNearPlane); |
|
|
|
return (int)clamp( LogBase( lerp(1.0, PositivePow(suggestedBase, C), rangeFittedDistance), suggestedBase), 0.0, (float)((1 << g_iLog2NumClusters) - 1)); |
|
|
|
} |
|
|
|
|
|
|
|
int SnapToClusterIdx(float z_in, float suggestedBase) |
|
|
|
|
|
|
{ |
|
|
|
float res; |
|
|
|
|
|
|
|
float userscale = g_fClustScale; |
|
|
|
if (logBasePerTile) |
|
|
|
userscale = GetScaleFromBase(suggestedBase); |
|
|
|
//float userscale = g_fClustScale; |
|
|
|
//if (logBasePerTile) |
|
|
|
// userscale = GetScaleFromBase(suggestedBase); |
|
|
|
|
|
|
|
//float dist = (PositivePow(suggestedBase, (float)k) - 1.0) / (userscale * (suggestedBase - 1.0f)); |
|
|
|
//res = dist + g_fNearPlane; |
|
|
|
|
|
|
|
const float C = (float)(1 << g_iLog2NumClusters); |
|
|
|
float rangeFittedDistance = (PositivePow(suggestedBase, (float)k) - 1.0) / (PositivePow(suggestedBase, C) - 1.0); |
|
|
|
res = lerp(g_fNearPlane, g_fFarPlane, rangeFittedDistance); |
|
|
|
float dist = (PositivePow(suggestedBase, (float)k) - 1.0) / (userscale * (suggestedBase - 1.0f)); |
|
|
|
res = dist + g_fNearPlane; |
|
|
|
|
|
|
|
#if USE_LEFT_HAND_CAMERA_SPACE |
|
|
|
return res; |
|
|
|