浏览代码

debug fixes

/feature-ScreenSpaceProjection
Frédéric Vauchelles 6 年前
当前提交
801f262f
共有 9 个文件被更改,包括 114 次插入50 次删除
  1. 15
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/ScreenSpaceRaymarching.hlsl
  2. 69
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs
  3. 48
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs.custom.hlsl
  4. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs.hlsl
  5. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.hlsl
  6. 21
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugFullScreen.shader
  7. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  8. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
  9. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl

15
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/ScreenSpaceRaymarching.hlsl


#ifdef DEBUG_DISPLAY
bool writeStepDebug;
uint2 sourcePositionSS;
float sourceDepth;
#endif
};

debug.level = maxUsedLevel;
debug.iteration = iteration;
//if (input.writeStepDebug)
if (input.writeStepDebug)
debug.cellSizeW = 16;
debug.cellSizeH = 16;
uint4 v01 = 0;
uint4 v02 = 0;
uint4 v03 = 0;
PackScreenSpaceTracingDebug(debug, v01, v02, v03);
_DebugScreenSpaceTracing[uint2(0, 0)] = v01;
_DebugScreenSpaceTracing[uint2(1, 0)] = v02;
_DebugScreenSpaceTracing[uint2(0, 1)] = v03;
_DebugScreenSpaceTracingData[0] = debug;
}
if (_DebugLightingMode == DEBUGLIGHTINGMODE_SCREEN_SPACE_TRACING_REFRACTION)

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


using System.Collections.Generic;
using UnityEditor;
using UnityEngine.Experimental.Rendering.HDPipeline.Attributes;
using System.Linq;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{

public uint levelMax;
public uint iteration;
public uint iterationMax;
public override string ToString()
{
return string.Format(
@"startPositionSS : ({0}, {1})
positionTXS : ({2}, {3})
positionDepth : {4}
cellSize : ({5}, {6})
level : {7}
levelMax : {8}
iteration : {9}
iterationMax : {10}
",
startPositionSSX, startPositionSSY,
positionTXS.x, positionTXS.y,
positionTXS.z,
cellSizeW, cellSizeH,
level,
levelMax,
iteration,
iterationMax
);
}
}
public class DebugDisplaySettings

public static int[] lightingFullScreenDebugValues = null;
public static GUIContent[] renderingFullScreenDebugStrings = null;
public static int[] renderingFullScreenDebugValues = null;
public static GUIContent[] debugScreenSpaceTracingStrings = null;
public static int[] debugScreenSpaceTracingValues = null;
debugScreenSpaceTracingStrings = Enum.GetNames(typeof(DebugScreenSpaceTracing)).Select(s => new GUIContent(s)).ToArray();
debugScreenSpaceTracingValues = (int[])Enum.GetValues(typeof(DebugScreenSpaceTracing));
}
public int GetDebugMaterialIndex()

list.Add(new DebugUI.FloatField { displayName = "Shadow Range Max Value", getter = () => lightingDebugSettings.shadowMaxValue, setter = value => lightingDebugSettings.shadowMaxValue = value });
list.Add(new DebugUI.EnumField { displayName = "Lighting Debug Mode", getter = () => (int)lightingDebugSettings.debugLightingMode, setter = value => SetDebugLightingMode((DebugLightingMode)value), autoEnum = typeof(DebugLightingMode), onValueChanged = RefreshLightingDebug });
if (lightingDebugSettings.debugLightingMode == DebugLightingMode.EnvironmentProxyVolume)
switch (lightingDebugSettings.debugLightingMode)
list.Add(new DebugUI.Container
case DebugLightingMode.EnvironmentProxyVolume:
{
list.Add(new DebugUI.Container
{
children =
{
new DebugUI.FloatField { displayName = "Debug Environment Proxy Depth Scale", getter = () => lightingDebugSettings.environmentProxyDepthScale, setter = value => lightingDebugSettings.environmentProxyDepthScale = value, min = () => 0.1f, max = () => 50f }
}
});
break;
}
case DebugLightingMode.ScreenSpaceTracingRefraction:
children =
list.Add(new DebugUI.Container
new DebugUI.FloatField { displayName = "Debug Environment Proxy Depth Scale", getter = () => lightingDebugSettings.environmentProxyDepthScale, setter = value => lightingDebugSettings.environmentProxyDepthScale = value, min = () => 0.1f, max = () => 50f }
}
});
children =
{
new DebugUI.EnumField
{
displayName = "Screen Space Tracing Debug Mode",
getter = GetDebugLightingSubMode,
setter = value => lightingDebugSettings.debugScreenSpaceTracingMode = (DebugScreenSpaceTracing)value,
enumNames = debugScreenSpaceTracingStrings,
enumValues = debugScreenSpaceTracingValues,
onValueChanged = RefreshLightingDebug
}
}
});
break;
}
}
list.Add(new DebugUI.EnumField { displayName = "Fullscreen Debug Mode", getter = () => (int)fullScreenDebugMode, setter = value => fullScreenDebugMode = (FullScreenDebugMode)value, enumNames = lightingFullScreenDebugStrings, enumValues = lightingFullScreenDebugValues, onValueChanged = RefreshLightingDebug });

}
}
});
break;
}
case FullScreenDebugMode.ScreenSpaceTracingRefraction:
{
break;
}
default:

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


#ifndef DEBUGDISPLAY_CS_CUSTOM_HLSL
#ifndef DEBUGDISPLAY_CS_CUSTOM_HLSL
void PackScreenSpaceTracingDebug(ScreenSpaceTracingDebug input, out uint4 v01, out uint4 v02, out uint4 v03)
{
v01 = uint4(input.startPositionSSX, input.startPositionSSY, input.cellSizeW, input.cellSizeH);
v02 = uint4(asuint(input.positionTXS.x), asuint(input.positionTXS.y), asuint(input.positionTXS.z), asuint(input.startLinearDepth));
v03 = uint4(input.level, input.levelMax, input.iteration, input.iterationMax);
}
void UnpackScreenSpaceTracingDebug(uint4 v01, uint4 v02, uint4 v03, out ScreenSpaceTracingDebug input)
{
input.startPositionSSX = v01.x;
input.startPositionSSY = v01.y;
input.cellSizeW = v01.z;
input.cellSizeH = v01.w;
input.positionTXS.x = asfloat(v02.x);
input.positionTXS.y = asfloat(v02.y);
input.positionTXS.z = asfloat(v02.z);
input.startLinearDepth = asfloat(v02.w);
input.level = v03.x;
input.levelMax = v03.y;
input.iteration = v03.z;
input.iterationMax = v03.w;
}
//void PackScreenSpaceTracingDebug(ScreenSpaceTracingDebug input, out uint4 v01, out uint4 v02, out uint4 v03)
//{
// v01 = uint4(input.startPositionSSX, input.startPositionSSY, input.cellSizeW, input.cellSizeH);
// v02 = uint4(uint(input.positionTXS.x), uint(input.positionTXS.y), uint(input.positionTXS.z), uint(input.startLinearDepth));
// v03 = uint4(input.level, input.levelMax, input.iteration, input.iterationMax);
//}
//
//void UnpackScreenSpaceTracingDebug(uint4 v01, uint4 v02, uint4 v03, out ScreenSpaceTracingDebug input)
//{
// input.startPositionSSX = v01.x;
// input.startPositionSSY = v01.y;
// input.cellSizeW = v01.z;
// input.cellSizeH = v01.w;
// input.positionTXS.x = float(v02.x);
// input.positionTXS.y = float(v02.y);
// input.positionTXS.z = float(v02.z);
// input.startLinearDepth = float(v02.w);
// input.level = v03.x;
// input.levelMax = v03.y;
// input.iteration = v03.z;
// input.iterationMax = v03.w;
//}
#endif
#endif

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


#endif
#include "DebugDisplay.cs.custom.hlsl"

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.hlsl


CBUFFER_END
RW_TEXTURE2D(float4, _DebugScreenSpaceTracing) : register(u1);
RWStructuredBuffer<ScreenSpaceTracingDebug> _DebugScreenSpaceTracingData : register(u2);
TEXTURE2D(_DebugFont); // Debug font to write string in shader

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


#include "../Debug/DebugDisplay.cs.hlsl"
TEXTURE2D(_DebugFullScreenTexture);
StructuredBuffer<ScreenSpaceTracingDebug> _DebugScreenSpaceTracingData;
float _FullScreenDebugMode;
float _RequireToFlipInputTexture;
TEXTURE2D(_DebugScreenSpaceTracing);

uint4 v01 = LOAD_TEXTURE2D(_DebugScreenSpaceTracing, uint2(0, 0));
uint4 v02 = LOAD_TEXTURE2D(_DebugScreenSpaceTracing, uint2(1, 0));
uint4 v03 = LOAD_TEXTURE2D(_DebugScreenSpaceTracing, uint2(0, 1));
ScreenSpaceTracingDebug debug;
UnpackScreenSpaceTracingDebug(v01, v02, v03, debug);
ScreenSpaceTracingDebug debug = _DebugScreenSpaceTracingData[0];
uint2 positionTXS = uint2((input.positionCS.xy * 0.5 + 0.5) * _ScreenParams.zw);
uint2 startPositionSS = uint2(debug.startPositionSSX, debug.startPositionSSY);
PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw, 10, UNITY_MATRIX_I_VP, UNITY_MATRIX_VP);
float2 distanceToCell = abs(float2(positionTXS % cellSize) - float2(cellSize) / float2(2, 2));
float2 distanceToCell = abs(float2(posInput.positionSS % cellSize) - float2(cellSize) / float2(2, 2));
float distanceToPosition = length(positionTXS - debug.positionTXS.xy);
float positionSDF = clamp(2 - distanceToPosition, 0, 1);
float distanceToPosition = length(int2(posInput.positionSS) - int2(debug.positionTXS.xy));
float positionSDF = clamp(4 - distanceToPosition, 0, 1);
float distanceToStartPosition = length(int2(posInput.positionSS) - int2(startPositionSS));
float startPositionSDF = clamp(4 - distanceToStartPosition, 0, 1);
0,
startPositionSDF,
return float4(debugColor * 0.5 + color.rgb * 0.5, 1);
}

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.Experimental.GlobalIllumination;

FrameSettings m_FrameSettings; // Init every frame
RTHandle m_DebugScreenSpaceTracing = null;
ComputeBuffer m_DebugScreenSpaceTracingData = null;
public HDRenderPipeline(HDRenderPipelineAsset asset)
{

#endif
m_DebugScreenSpaceTracing = RTHandle.Alloc(2, 2, colorFormat: RenderTextureFormat.ARGBFloat, sRGB: false, enableRandomWrite: true);
m_DebugScreenSpaceTracingData = new ComputeBuffer(1, Marshal.SizeOf(typeof(ScreenSpaceTracingDebug)));
InitializeRenderTextures();

RTHandle.Release(m_DebugFullScreenTempBuffer);
RTHandle.Release(m_DebugScreenSpaceTracing);
m_DebugScreenSpaceTracingData.Release();
}

RenderGaussianPyramidColor(hdCamera, cmd, renderContext, true);
cmd.SetGlobalTexture(HDShaderIDs._DebugScreenSpaceTracing, m_DebugScreenSpaceTracing);
cmd.SetGlobalBuffer(HDShaderIDs._DebugScreenSpaceTracingData, m_DebugScreenSpaceTracingData);
cmd.SetRandomWriteTarget(2, m_DebugScreenSpaceTracingData);
// Render all type of transparent forward (unlit, lit, complex (hair...)) to keep the sorting between transparent objects.
RenderForward(m_CullResults, hdCamera, renderContext, cmd, ForwardPass.Transparent);
cmd.ClearRandomWriteTargets();

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs


public static readonly int _RequireToFlipInputTexture = Shader.PropertyToID("_RequireToFlipInputTexture");
public static readonly int _DebugFullScreenTexture = Shader.PropertyToID("_DebugFullScreenTexture");
public static readonly int _DebugScreenSpaceTracingData = Shader.PropertyToID("_DebugScreenSpaceTracingData");
public static readonly int _BlitTexture = Shader.PropertyToID("_BlitTexture");
public static readonly int _BlitScaleBias = Shader.PropertyToID("_BlitScaleBias");
public static readonly int _BlitMipLevel = Shader.PropertyToID("_BlitMipLevel");

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


ssInput.maxLevel = int(_PyramidDepthMipSize.z);
#ifdef DEBUG_DISPLAY
ssInput.writeStepDebug = (uint2(_MouseClickPixelCoord.xy) == posInput.positionSS);
ssInput.writeStepDebug = !any(int2(_MouseClickPixelCoord.xy) - int2(posInput.positionSS));
#endif
bool hitSuccessful = ScreenSpaceRaymarch(ssInput, hit);

正在加载...
取消
保存