浏览代码

simplify expression for linear depth <--> cluster Idx

simplify expression for linear depth <--> cluster Idx.
Distribution still identical.
/main
mmikk 7 年前
当前提交
8c27de69
共有 2 个文件被更改,包括 48 次插入20 次删除
  1. 34
      Assets/ScriptableRenderPipeline/Fptl/ClusteredUtils.h
  2. 34
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/ClusteredUtils.hlsl

34
Assets/ScriptableRenderPipeline/Fptl/ClusteredUtils.h


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_LEFTHAND_CAMERASPACE

#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_LEFTHAND_CAMERASPACE
return res;

34
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/ClusteredUtils.hlsl


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;

正在加载...
取消
保存