浏览代码

(wip) screen space tracing debug - using a RT instead of a StructuredBuffer for UAV target in pixel shader

/feature-ScreenSpaceProjection
Frédéric Vauchelles 7 年前
当前提交
177273e3
共有 6 个文件被更改,包括 69 次插入17 次删除
  1. 15
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/ScreenSpaceRaymarching.hlsl
  2. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.hlsl
  3. 15
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugFullScreen.shader
  4. 18
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  5. 27
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs.custom.hlsl
  6. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs.custom.hlsl.meta

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


debug.level = maxUsedLevel;
debug.iteration = iteration;
if (input.writeStepDebug)
_DebugScreenSpaceTracing[0] = debug;
//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;
}
if (_DebugLightingMode == DEBUGLIGHTINGMODE_SCREEN_SPACE_TRACING_REFRACTION)
{

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


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

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


TEXTURE2D(_DebugFullScreenTexture);
float _FullScreenDebugMode;
float _RequireToFlipInputTexture;
RWStructuredBuffer<ScreenSpaceTracingDebug> _DebugScreenSpaceTracing;
TEXTURE2D(_DebugScreenSpaceTracing);
struct Attributes
{

}
if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_SCREEN_SPACE_TRACING_REFRACTION)
{
ScreenSpaceTracingDebug debug = _DebugScreenSpaceTracing[0];
float4 color = SAMPLE_TEXTURE2D(_DebugFullScreenTexture, s_point_clamp_sampler, input.texcoord);
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);
uint2 startPositionSS = uint2(debug.startPositionSSX, debug.startPositionSSY);
uint2 cellSize = uint2(debug.cellSizeW, debug.cellSizeH);
float2 distanceToCell = abs(float2(positionTXS % cellSize) - float2(cellSize) / float2(2, 2));

float distanceToPosition = length(positionTXS - debug.positionTXS.xy);
float positionSDF = clamp(3 - distanceToPosition, 0, 1);
float positionSDF = clamp(2 - distanceToPosition, 0, 1);
float3 debugColor = float3(
0,

return float4(debugColor * 0.5 + frac(debug.startLinearDepth * 0.1).xxx * 0.5, 1);
return float4(debugColor * 0.5 + color.rgb * 0.5, 1);
}
return float4(0.0, 0.0, 0.0, 0.0);

18
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


FrameSettings m_FrameSettings; // Init every frame
static ComputeBuffer s_DebugScreenSpaceTracing = null;
static ScreenSpaceTracingDebug[] s_DebugScreenSpaceTracingArray = new ScreenSpaceTracingDebug[1];
RTHandle m_DebugScreenSpaceTracing = null;
public HDRenderPipeline(HDRenderPipelineAsset asset)
{

FrameSettings.RegisterDebug("Default Camera", m_Asset.GetFrameSettings());
#endif
// struct ScreenSpaceTracingDebug, defined in ScreenSpaceRaymarching.hlsl
s_DebugScreenSpaceTracing = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(ScreenSpaceTracingDebug)));
m_DebugScreenSpaceTracing = RTHandle.Alloc(2, 2, colorFormat: RenderTextureFormat.ARGBFloat, sRGB: false, enableRandomWrite: true);
InitializeRenderTextures();

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

foreach (var material in m_MaterialList)
material.RenderInit(cmd);
s_DebugScreenSpaceTracingArray[0] = new ScreenSpaceTracingDebug();
s_DebugScreenSpaceTracing.SetData(s_DebugScreenSpaceTracingArray);
using (new ProfilingSample(cmd, "HDRenderPipeline::Render", CustomSamplerId.HDRenderPipelineRender.GetSampler()))
{
// Do anything we need to do upon a new frame.

RenderGaussianPyramidColor(hdCamera, cmd, renderContext, true);
cmd.SetGlobalTexture(HDShaderIDs._DebugScreenSpaceTracing, m_DebugScreenSpaceTracing);
cmd.SetRandomWriteTarget(1, m_DebugScreenSpaceTracing);
cmd.ClearRandomWriteTargets();
RenderForwardError(m_CullResults, hdCamera, renderContext, cmd, ForwardPass.Transparent);
// Fill depth buffer to reduce artifact for transparent object during postprocess

cmd.SetGlobalVector(HDShaderIDs._MouseClickPixelCoord, HDUtils.GetMouseClickCoordinates(hdCamera));
cmd.SetGlobalTexture(HDShaderIDs._DebugFont, m_Asset.renderPipelineResources.debugFontTexture);
cmd.SetGlobalBuffer(HDShaderIDs._DebugScreenSpaceTracing, s_DebugScreenSpaceTracing);
cmd.SetGlobalTexture(HDShaderIDs._DebugScreenSpaceTracing, m_DebugScreenSpaceTracing);
}
else
{

// Everything we have capture is flipped (as it happen before FinalPass/postprocess/Blit. So if we are not in SceneView
// (i.e. we have perform a flip, we need to flip the input texture)
m_DebugFullScreen.SetFloat(HDShaderIDs._RequireToFlipInputTexture, hdCamera.camera.cameraType != CameraType.SceneView ? 1.0f : 0.0f);
m_DebugFullScreen.SetBuffer(HDShaderIDs._DebugScreenSpaceTracing, s_DebugScreenSpaceTracing);
m_DebugFullScreen.SetTexture(HDShaderIDs._DebugScreenSpaceTracing, m_DebugScreenSpaceTracing);
HDUtils.DrawFullScreen(cmd, hdCamera, m_DebugFullScreen, (RenderTargetIdentifier)BuiltinRenderTextureType.CameraTarget);
PushColorPickerDebugTexture(cmd, (RenderTargetIdentifier)BuiltinRenderTextureType.CameraTarget, hdCamera);

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


#ifndef DEBUGDISPLAY_CS_CUSTOM_HLSL
#define 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;
}
#endif

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


fileFormatVersion: 2
guid: da3076e1b52b2864ab58a22646df0b26
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存