浏览代码

Added debugs

Fixed screen space ray computation
/main
Frédéric Vauchelles 6 年前
当前提交
262145d7
共有 5 个文件被更改,包括 98 次插入39 次删除
  1. 48
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs
  2. 10
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs.hlsl
  3. 62
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugFullScreen.shader
  4. 12
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceTracing.hlsl
  5. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl

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


public uint endPositionSSY; // Proxy, HiZ, Linear
public float endHitWeight; // HiZ, Linear
// 3x32 Lighting
// 7x32 Lighting
public Vector3 lightingSpecularFGD; // All
public float lightingWeight; // All
// 2x32 bits (padding)
public Vector2 padding;

};
settingsContainer.children.Add(debugSettingsContainer);
var lightingDebug = new DebugUI.Container
{
displayName = "Lighting",
children =
{
new DebugUI.Value { displayName = "Sampled Color", getter = () => FormatVector(screenSpaceTracingDebugData.lightingSampledColor) },
new DebugUI.Value { displayName = "Specular FGD", getter = () => FormatVector(screenSpaceTracingDebugData.lightingSpecularFGD) },
new DebugUI.Value { displayName = "Weight", getter = () => screenSpaceTracingDebugData.lightingWeight.ToString("F6") },
new DebugUI.Value { displayName = "Weighted Color", getter = () => FormatVector(Vector3.Scale(screenSpaceTracingDebugData.lightingSpecularFGD, screenSpaceTracingDebugData.lightingSampledColor) * screenSpaceTracingDebugData.lightingWeight) },
}
};
switch (screenSpaceTracingDebugData.tracingModel)
{
case Lit.ProjectionModel.Proxy:

new DebugUI.Value { displayName = "End Position", getter = () => screenSpaceTracingDebugData.endPositionSS },
}
},
new DebugUI.Container
{
displayName = "Lighting",
children =
{
new DebugUI.Value { displayName = "Sampled Color", getter = () => string.Format("({0:F6}, {1:F6}, {2:F6})", screenSpaceTracingDebugData.lightingSampledColor.x, screenSpaceTracingDebugData.lightingSampledColor.y, screenSpaceTracingDebugData.lightingSampledColor.z) },
}
}
lightingDebug
);
break;
}

new DebugUI.Value { displayName = "Intersection Kind", getter = () => k_HiZIntersectionKind[(int)screenSpaceTracingDebugData.iterationIntersectionKind] },
}
},
new DebugUI.Container
{
displayName = "Lighting",
children =
{
new DebugUI.Value { displayName = "Sampled Color", getter = () => string.Format("({0:F6}, {1:F6}, {2:F6})", screenSpaceTracingDebugData.lightingSampledColor.x, screenSpaceTracingDebugData.lightingSampledColor.y, screenSpaceTracingDebugData.lightingSampledColor.z) },
}
}
lightingDebug
);
break;
}

new DebugUI.Value { displayName = "Cell Size", getter = () => screenSpaceTracingDebugData.iterationCellSize },
}
},
new DebugUI.Container
{
displayName = "Lighting",
children =
{
new DebugUI.Value { displayName = "Sampled Color", getter = () => string.Format("({0:F6}, {1:F6}, {2:F6})", screenSpaceTracingDebugData.lightingSampledColor.x, screenSpaceTracingDebugData.lightingSampledColor.y, screenSpaceTracingDebugData.lightingSampledColor.z) },
}
}
lightingDebug
);
break;
}

values[index] = i;
index++;
}
}
static string FormatVector(Vector3 v)
{
return string.Format("({0:F6}, {1:F6}, {2:F6})", v.x, v.y, v.z);
}
}
}

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


uint endPositionSSY;
float endHitWeight;
float3 lightingSampledColor;
float3 lightingSpecularFGD;
float lightingWeight;
float2 padding;
};

float3 GetLightingSampledColor(ScreenSpaceTracingDebug value)
{
return value.lightingSampledColor;
}
float3 GetLightingSpecularFGD(ScreenSpaceTracingDebug value)
{
return value.lightingSpecularFGD;
}
float GetLightingWeight(ScreenSpaceTracingDebug value)
{
return value.lightingWeight;
}
float2 GetPadding(ScreenSpaceTracingDebug value)
{

62
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugFullScreen.shader


return max(dist1, dist2);
}
void ColorWidget(
int2 positionSS,
float4 rect,
float3 borderColor,
float3 innerColor,
inout float4 debugColor,
inout float4 backgroundColor
)
{
const float4 distToRects = float4(rect.zw - positionSS, positionSS - rect.xy);
if (all(distToRects > 0))
{
const float distToRect = min(min(distToRects.x, distToRects.y), min(distToRects.z, distToRects.w));
const float sdf = clamp(distToRect * 0.5, 0, 1);
debugColor = float4(
lerp(borderColor, innerColor, sdf),
1.0
);
backgroundColor.a = 0;
}
}
float DrawArrow(float2 texcoord, float body, float head, float height, float linewidth, float antialias)
{
float w = linewidth / 2.0 + antialias;

const float w = clamp(1 - startPositionRingSDF - positionRingSDF, 0, 1);
col.rgb = col.rgb * w + float3(1, 1, 1) * (1 - w);
// Draw sampled color
// Draw color widgets
const float4 rect = float4(endPositionSS + float2(10, 10), endPositionSS + float2(60, 60));
const float4 distToRects = float4(rect.zw - posInput.positionSS, posInput.positionSS - rect.xy);
if (all(distToRects > 0))
{
const float distToRect = min(min(distToRects.x, distToRects.y), min(distToRects.z, distToRects.w));
const float sdf = clamp(distToRect * 0.5, 0, 1);
col = float4(
lerp(float3(1, 1, 1), debug.lightingSampledColor, sdf),
1.0
);
color.a = 0;
}
// Sampled color
ColorWidget(
posInput.positionSS,
float4(10, 10, 50, 50) + endPositionSS.xyxy,
float3(1, 0, 0), debug.lightingSampledColor,
col,
color
);
// Specular FGD
ColorWidget(
posInput.positionSS,
float4(-50, 10, -10, 50) + endPositionSS.xyxy,
float3(0, 1, 0), debug.lightingSpecularFGD,
col,
color
);
// Weighted
ColorWidget(
posInput.positionSS,
float4(-50, -50, -10, -10) + endPositionSS.xyxy,
float3(0, 0, 1), debug.lightingSampledColor * debug.lightingSpecularFGD * debug.lightingWeight,
col,
color
);
}
if (_ShowDepthPyramidDebug == 1)

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


out float rayEndDepth // Linear depth of the end point used to calculate raySS
)
{
const float kNearClipPlane = -0.01;
const float kMaxRayTraceDistance = 1000;
float3 rayOriginVS = mul(GetWorldToViewMatrix(), float4(rayOriginWS, 1.0)).xyz;
float3 rayDirVS = mul((float3x3)GetWorldToViewMatrix(), rayDirWS);
// Clip ray to near plane to avoid raymarching behind camera
float rayLength = ((rayOriginVS.z + rayDirVS.z * kMaxRayTraceDistance) > kNearClipPlane)
? ((kNearClipPlane - rayOriginVS.z) / rayDirVS.z)
: kMaxRayTraceDistance;
float3 rayEndWS = rayOriginWS + rayDirWS * 1;
float3 rayEndWS = rayOriginWS + rayDirWS * rayLength;
float4 positionCS = ComputeClipSpacePosition(positionWS, GetWorldToHClipMatrix());
float4 rayEndCS = ComputeClipSpacePosition(rayEndWS, GetWorldToHClipMatrix());

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl


{
ScreenSpaceTracingDebug debug = _DebugScreenSpaceTracingData[0];
debug.lightingSampledColor = preLD;
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFRACTION)
debug.lightingSpecularFGD = 1.0 - F;
else if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFLECTION)
debug.lightingSpecularFGD = F;
debug.lightingWeight = weight;
_DebugScreenSpaceTracingData[0] = debug;
}

正在加载...
取消
保存