浏览代码

Fixed hit weight calculate

Updated debug modes
/main
Frédéric Vauchelles 7 年前
当前提交
638799d0
共有 5 个文件被更改,包括 121 次插入78 次删除
  1. 26
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs
  2. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs.hlsl
  3. 7
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs
  4. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs.hlsl
  5. 152
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceTracing.hlsl

26
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs


public EnvShapeType proxyShapeType; // Proxy
public float projectionDistance; // Proxy
// 4x32 bits
// 5x32 bits
public float endHitWeight; // HiZ, Linear
// 2x32 bits (padding)
public Vector2 padding;
// 1x32 bits (padding)
public float padding;
public Vector2 loopStartPositionSS { get { return new Vector2(loopStartPositionSSX, loopStartPositionSSY); } }
public Vector2 endPositionSS { get { return new Vector2(endPositionSSX, endPositionSSY); } }

public static int[] debugScreenSpaceTracingProxyValues = null;
public static GUIContent[] debugScreenSpaceTracingHiZStrings = null;
public static int[] debugScreenSpaceTracingHiZValues = null;
public static GUIContent[] debugScreenSpaceTracingLinearStrings = null;
public static int[] debugScreenSpaceTracingLinearValues = null;
public static GUIContent[] debuggedAlgorithmStrings = null;
public static int[] debuggedAlgorithmValues = null;

var debugScreenSpaceTracingHiZStringsList = new List<GUIContent>();
var debugScreenSpaceTracingProxyStringsList = new List<GUIContent>();
var debugScreenSpaceTracingLinearStringsList = new List<GUIContent>();
var debugScreenSpaceTracingLinearValueList = new List<int>();
if (!g.text.StartsWith("Proxy"))
if (!g.text.StartsWith("Proxy") && !g.text.StartsWith("Linear"))
if (!g.text.StartsWith("HiZ"))
if (!g.text.StartsWith("HiZ") && !g.text.StartsWith("Linear"))
if (!g.text.StartsWith("Proxy") && !g.text.StartsWith("HiZ"))
{
debugScreenSpaceTracingLinearStringsList.Add(g);
debugScreenSpaceTracingLinearValueList.Add(v);
}
}
debugScreenSpaceTracingHiZStrings = debugScreenSpaceTracingHiZStringsList.ToArray();

debugScreenSpaceTracingLinearStrings = debugScreenSpaceTracingLinearStringsList.ToArray();
debugScreenSpaceTracingLinearValues = debugScreenSpaceTracingLinearValueList.ToArray();
debuggedAlgorithmStrings = Enum.GetNames(typeof(Lit.ProjectionModel))
.Select(t => new GUIContent(t))
.ToArray();

new DebugUI.Value { displayName = "Ray Depth", getter = () => 1f / screenSpaceTracingDebugData.loopRayDirectionSS.z },
new DebugUI.Value { displayName = "End Position", getter = () => screenSpaceTracingDebugData.endPositionSS },
new DebugUI.Value { displayName = "End Linear Depth", getter = () => screenSpaceTracingDebugData.endLinearDepth },
new DebugUI.Value { displayName = "Hit Weight", getter = () => screenSpaceTracingDebugData.endHitWeight.ToString("F4") },
}
},
new DebugUI.Container

case Lit.ProjectionModel.Linear:
{
debugSettingsContainer.children.Add(
new DebugUI.EnumField { displayName = "Debug Mode", getter = GetDebugLightingSubMode, setter = SetScreenSpaceTracingDebugMode, enumNames = debugScreenSpaceTracingHiZStrings, enumValues = debugScreenSpaceTracingHiZValues, onValueChanged = RefreshScreenSpaceTracingDebug },
new DebugUI.EnumField { displayName = "Debug Mode", getter = GetDebugLightingSubMode, setter = SetScreenSpaceTracingDebugMode, enumNames = debugScreenSpaceTracingLinearStrings, enumValues = debugScreenSpaceTracingLinearValues, onValueChanged = RefreshScreenSpaceTracingDebug },
new DebugUI.BoolField { displayName = "Display Grid", getter = () => showSSRayGrid, setter = v => showSSRayGrid = v },
new DebugUI.BoolField { displayName = "Display Depth", getter = () => showSSRayDepthPyramid, setter = v => showSSRayDepthPyramid = v }
);

new DebugUI.Value { displayName = "Ray Depth", getter = () => 1f / screenSpaceTracingDebugData.loopRayDirectionSS.z },
new DebugUI.Value { displayName = "End Position", getter = () => screenSpaceTracingDebugData.endPositionSS },
new DebugUI.Value { displayName = "End Linear Depth", getter = () => screenSpaceTracingDebugData.endLinearDepth },
new DebugUI.Value { displayName = "Hit Weight", getter = () => screenSpaceTracingDebugData.endHitWeight.ToString("F4") },
}
},
new DebugUI.Container

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs.hlsl


float endLinearDepth;
uint endPositionSSX;
uint endPositionSSY;
float2 padding;
float endHitWeight;
float padding;
};
//

{
return value.endPositionSSY;
}
float2 GetPadding(ScreenSpaceTracingDebug value)
float GetEndHitWeight(ScreenSpaceTracingDebug value)
{
return value.endHitWeight;
}
float GetPadding(ScreenSpaceTracingDebug value)
{
return value.padding;
}

7
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs


HiZRayDirNDC,
HiZIterationCount,
HiZMaxUsedMipLevel,
HiZIntersectionKind
HiZIntersectionKind,
HiZHitWeight,
LinearPositionNDC,
LinearRayDirNDC,
LinearIterationCount,
LinearHitWeight
}
public enum ShadowMapDebugMode

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs.hlsl


#define DEBUGSCREENSPACETRACING_HI_ZITERATION_COUNT (8)
#define DEBUGSCREENSPACETRACING_HI_ZMAX_USED_MIP_LEVEL (9)
#define DEBUGSCREENSPACETRACING_HI_ZINTERSECTION_KIND (10)
#define DEBUGSCREENSPACETRACING_HI_ZHIT_WEIGHT (11)
#define DEBUGSCREENSPACETRACING_LINEAR_POSITION_NDC (12)
#define DEBUGSCREENSPACETRACING_LINEAR_RAY_DIR_NDC (13)
#define DEBUGSCREENSPACETRACING_LINEAR_ITERATION_COUNT (14)
#define DEBUGSCREENSPACETRACING_LINEAR_HIT_WEIGHT (15)
#endif

152
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceTracing.hlsl


raySS = rayEndSS - rayStartSS;
}
// Check whether the depth of the ray is above the sampled depth
// Arguments are inversed linear depth
bool IsPositionAboveDepth(float invRayDepth, float2 invLinearDepth)
{
// as depth is inverted, we must invert the check as well
// rayZ > HiZ <=> 1/rayZ < 1/HiZ
return invRayDepth > invLinearDepth.r;
}
// Sample the Depth buffer at a specific mip and linear depth
float2 LoadDepth(float2 positionSS, int level)
{

float CalculateHitWeight(
ScreenSpaceRayHit hit,
float2 startPositionSS,
float2 invLinearDepth,
float minLinearDepth,
float settingsRayDepthSuccessBias,
float settingsRayMaxScreenDistance,
float settingsRayBlendScreenDistance

float thicknessWeight = (1 + ((1 / invLinearDepth.r) - hit.linearDepth) / settingsRayDepthSuccessBias);
float thicknessWeight = clamp(1 - (hit.linearDepth - minLinearDepth) / settingsRayDepthSuccessBias, 0, 1);
return thicknessWeight;
// Blend when the ray when the raymarched distance is too long

break;
}
}
void DebugComputeHiZOutput(
int iteration,
float3 startPositionSS,
float3 rayDirSS,
int maxIterations,
int maxUsedLevel,
int maxMipLevel,
int intersectionKind,
inout ScreenSpaceRayHit hit
)
{
switch (_DebugLightingSubMode)
{
case DEBUGSCREENSPACETRACING_HI_ZPOSITION_NDC:
hit.debugOutput = float3(float2(startPositionSS.xy) * _ScreenSize.zw, 0);
break;
case DEBUGSCREENSPACETRACING_HI_ZITERATION_COUNT:
hit.debugOutput = float(iteration) / float(maxIterations);
break;
case DEBUGSCREENSPACETRACING_HI_ZRAY_DIR_NDC:
hit.debugOutput = float3(rayDirSS.xy * 0.5 + 0.5, frac(0.1 / rayDirSS.z));
break;
case DEBUGSCREENSPACETRACING_HI_ZMAX_USED_MIP_LEVEL:
hit.debugOutput = float(maxUsedLevel) / float(maxMipLevel);
break;
case DEBUGSCREENSPACETRACING_HI_ZINTERSECTION_KIND:
hit.debugOutput = GetIndexColor(intersectionKind);
break;
}
}
#endif
// -------------------------------------------------

raySS *= 1 << mipLevel;
// Offset by a texel
positionSS += raySS * 1.0;
//positionSS += raySS * 1.0;
#ifdef DEBUG_DISPLAY
float3 debugIterationPositionSS = positionSS;

float2 invLinearDepth = float2(0.0, 0.0);
float minLinearDepth = 0;
float minLinearDepthWithThickness = 0;
float positionLinearDepth = 0;
for (iteration = 0u; iteration < maxIterations; ++iteration)
{
positionSS += raySS;

minLinearDepth = 1 / invLinearDepth.r;
minLinearDepthWithThickness = minLinearDepth + settingsRayDepthSuccessBias;
positionLinearDepth = 1 / positionSS.z;
bool isAboveDepth = positionLinearDepth < minLinearDepth;
bool isAboveThickness = positionLinearDepth < minLinearDepthWithThickness;
bool isBehindDepth = !isAboveThickness;
bool intersectWithDepth = !isAboveDepth && isAboveThickness;
debugIterationPositionSS = positionSS;
debugIterationLinearDepthBufferMin = 1 / invLinearDepth.r;
debugIterationLinearDepthBufferMinThickness = 1 / invLinearDepth.r + settingsRayDepthSuccessBias;
debugIterationLinearDepthBufferMax = 1 / invLinearDepth.g;
debugIteration = iteration;
debugIterationPositionSS = positionSS;
debugIterationLinearDepthBufferMin = minLinearDepth;
debugIterationLinearDepthBufferMinThickness = minLinearDepthWithThickness;
debugIterationLinearDepthBufferMax = 1 / invLinearDepth.g;
debugIteration = iteration;
if (!IsPositionAboveDepth(positionSS.z, invLinearDepth))
if (intersectWithDepth)
{
hitSuccessful = true;
break;

settingsRayMaxScreenDistance,
settingsRayBlendScreenDistance
);
switch (_DebugLightingSubMode)
{
case DEBUGSCREENSPACETRACING_LINEAR_POSITION_NDC:
hit.debugOutput = float3(float2(startPositionSS.xy) * _ScreenSize.zw, 0);
break;
case DEBUGSCREENSPACETRACING_LINEAR_ITERATION_COUNT:
hit.debugOutput = float(iteration) / float(settingsRayMaxIterations);
break;
case DEBUGSCREENSPACETRACING_LINEAR_RAY_DIR_NDC:
hit.debugOutput = float3(raySS.xy * 0.5 + 0.5, frac(0.1 / raySS.z));
break;
case DEBUGSCREENSPACETRACING_LINEAR_HIT_WEIGHT:
hit.debugOutput = float3(hitWeight, hitWeight, hitWeight);
break;
}
if (input.debug
&& _DebugScreenSpaceTracingData[0].tracingModel == -1

debug.endPositionSSY = hit.positionSS.y;
debug.iterationCellSizeW = 1 << mipLevel;
debug.iterationCellSizeH = 1 << mipLevel;
debug.endHitWeight = hitWeight;
_DebugScreenSpaceTracingData[0] = debug;
}

float3 positionSS = startPositionSS;
float2 invLinearDepth = float2(0.0, 0.0);
float positionLinearDepth = 0;
float minLinearDepth = 0;
float minLinearDepthWithThickness = 0;
while (currentLevel >= minMipLevel)
{
hitSuccessful = true;

// Sampled as 1/Z so it interpolate properly in screen space.
invLinearDepth = LoadInvDepth(positionSS.xy, currentLevel);
float positionLinearDepth = 1 / positionSS.z;
float minLinearDepth = 1 / invLinearDepth.r;
float maxLinearDepth = minLinearDepth + settingsRayDepthSuccessBias;
bool isAboveDepth = positionLinearDepth <= minLinearDepth;
bool isAboveThickness = positionLinearDepth <= maxLinearDepth;
bool isBehindDepth = !isAboveThickness;
bool intersectWithDepth = minLinearDepth >= positionLinearDepth && isAboveThickness;
positionLinearDepth = 1 / positionSS.z;
minLinearDepth = 1 / invLinearDepth.r;
minLinearDepthWithThickness = minLinearDepth + settingsRayDepthSuccessBias;
bool isAboveDepth = positionLinearDepth < minLinearDepth;
bool isAboveThickness = positionLinearDepth < minLinearDepthWithThickness;
bool isBehindDepth = !isAboveThickness;
bool intersectWithDepth = minLinearDepth >= positionLinearDepth && isAboveThickness;
intersectionKind = HIZINTERSECTIONKIND_NONE;

++iteration;
}
hit.linearDepth = 1 / positionSS.z;
hit.linearDepth = positionLinearDepth;
// hitWeight = CalculateHitWeight(
// hit,
// startPositionSS.xy,
// invLinearDepth,
// settingsRayDepthSuccessBias,
// settingsRayMaxScreenDistance,
// settingsRayBlendScreenDistance
// );
invLinearDepth,
minLinearDepth,
DebugComputeHiZOutput(
iteration,
startPositionSS,
raySS,
settingsRayMaxIterations,
debugLoopMipMaxUsedLevel,
maxMipLevel,
intersectionKind,
hit
);
switch (_DebugLightingSubMode)
{
case DEBUGSCREENSPACETRACING_HI_ZPOSITION_NDC:
hit.debugOutput = float3(float2(startPositionSS.xy) * _ScreenSize.zw, 0);
break;
case DEBUGSCREENSPACETRACING_HI_ZITERATION_COUNT:
hit.debugOutput = float(iteration) / float(settingsRayMaxIterations);
break;
case DEBUGSCREENSPACETRACING_HI_ZRAY_DIR_NDC:
hit.debugOutput = float3(raySS.xy * 0.5 + 0.5, frac(0.1 / raySS.z));
break;
case DEBUGSCREENSPACETRACING_HI_ZMAX_USED_MIP_LEVEL:
hit.debugOutput = float(debugLoopMipMaxUsedLevel) / float(maxMipLevel);
break;
case DEBUGSCREENSPACETRACING_HI_ZINTERSECTION_KIND:
hit.debugOutput = GetIndexColor(intersectionKind);
break;
case DEBUGSCREENSPACETRACING_HI_ZHIT_WEIGHT:
hit.debugOutput = float3(hitWeight, hitWeight, hitWeight);
break;
}
if (input.debug
&& _DebugScreenSpaceTracingData[0].tracingModel == -1

debug.endLinearDepth = hit.linearDepth;
debug.endPositionSSX = hit.positionSS.x;
debug.endPositionSSY = hit.positionSS.y;
debug.endHitWeight = hitWeight;
_DebugScreenSpaceTracingData[0] = debug;
}

正在加载...
取消
保存