浏览代码

Initial implementation of debug views

/projects-TheLastStand
John Parsaie 6 年前
当前提交
c285e71c
共有 7 个文件被更改,包括 154 次插入19 次删除
  1. 56
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  2. 3
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineUtils.cs
  3. 39
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightShaderUtils.cs
  4. 23
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLit.hlsl
  5. 37
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandard.shader
  6. 6
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassDebug.hlsl
  7. 9
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassDebug.hlsl.meta

56
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


Subtractive,
};
public static class AdvancedFeatureIDs
{
//SSAO
//############################################
public static readonly int _AmbientOcclusionTexture = Shader.PropertyToID("_AmbientOcclusionTexture");
public static readonly int _AmbientOcclusionParam = Shader.PropertyToID("_AmbientOcclusionParam");
//############################################
}
public static class CameraRenderTargetID
{
// Camera color target. Not used when camera is rendering to backbuffer or camera

private int m_ShadowCasterCascadesCount;
private int m_ShadowMapRTID;
private int m_ScreenSpaceShadowMapRTID;
private int m_DebugViewRTID;
private RenderTargetIdentifier m_DebugViewRT;
private RenderTargetIdentifier m_ColorRT;
private RenderTargetIdentifier m_CopyColorRT;
private RenderTargetIdentifier m_DepthRT;

m_ShadowMapRTID = Shader.PropertyToID("_ShadowMap");
m_ScreenSpaceShadowMapRTID = Shader.PropertyToID("_ScreenSpaceShadowMap");
m_DebugViewRTID = Shader.PropertyToID("_DebugViewRT");
CameraRenderTargetID.color = Shader.PropertyToID("_CameraColorRT");
CameraRenderTargetID.copyColor = Shader.PropertyToID("_CameraCopyColorRT");
CameraRenderTargetID.depth = Shader.PropertyToID("_CameraDepthTexture");

m_ScreenSpaceShadowMapRT = new RenderTargetIdentifier(m_ScreenSpaceShadowMapRTID);
m_DebugViewRT = new RenderTargetIdentifier(m_DebugViewRTID);
m_ColorRT = new RenderTargetIdentifier(CameraRenderTargetID.color);
m_CopyColorRT = new RenderTargetIdentifier(CameraRenderTargetID.copyColor);
m_DepthRT = new RenderTargetIdentifier(CameraRenderTargetID.depth);

}
//TODO: Editor only?
if(m_Asset.DebugView == DebugViewMode.None)
if(!LightweightUtils.HasFlag(frameRenderingConfiguration, FrameRenderingConfiguration.DebugView))
ForwardPass(visibleLights, frameRenderingConfiguration, ref context, ref lightData, stereoEnabled);
else
DebugViewPass(frameRenderingConfiguration, ref context, stereoEnabled);

private void DebugViewPass(FrameRenderingConfiguration frameRenderingConfiguration, ref ScriptableRenderContext context, bool stereoEnabled)
{
//Set up buffers.
//CommandBuffer cmd = CommandBufferPool.Get("Debug View");
//cmd.GetTemporaryRT(m_DebugViewRTID, m_CurrCamera.pixelWidth, m_CurrCamera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGB32);
//SetRenderTarget(cmd, m_DebugViewRT, ClearFlag.Color);
//context.ExecuteCommandBuffer(cmd);
BeginForwardRendering(ref context, frameRenderingConfiguration);
CommandBuffer cmd = CommandBufferPool.Get("Debug View Mode");
LightweightShaderUtils.ResetDebugModes(cmd);
switch(m_Asset.DebugView)
{
case DebugViewMode.Albedo:
LightweightShaderUtils.SetDebugMode(cmd, DebugViewKeyword.ALBEDO);
break;
case DebugViewMode.Metallness:
LightweightShaderUtils.SetDebugMode(cmd, DebugViewKeyword.METALNESS);
break;
case DebugViewMode.Normals:
LightweightShaderUtils.SetDebugMode(cmd, DebugViewKeyword.NORMALS);
break;
case DebugViewMode.Roughness:
LightweightShaderUtils.SetDebugMode(cmd, DebugViewKeyword.ROUGHNESS);
break;
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
//Draw
var debugViewDrawSettings = new DrawRendererSettings(m_CurrCamera, m_DebugViewPass);
debugViewDrawSettings.sorting.flags = SortFlags.CommonOpaque;

};
context.DrawRenderers(m_CullResults.visibleRenderers, ref debugViewDrawSettings, debugViewFilterSettings);
EndForwardRendering(ref context, frameRenderingConfiguration);
}
private void ForwardPass(List<VisibleLight> visibleLights, FrameRenderingConfiguration frameRenderingConfiguration, ref ScriptableRenderContext context, ref LightData lightData, bool stereoEnabled)

if (intermediateTexture)
configuration |= FrameRenderingConfiguration.IntermediateTexture;
if(m_Asset.DebugView != DebugViewMode.None)
configuration |= FrameRenderingConfiguration.DebugView;
}
private void SetupIntermediateResources(FrameRenderingConfiguration renderingConfig, ref ScriptableRenderContext context)

blitMaterial = null;
// If PostProcessing is enabled, it is already blit to CameraTarget.
if (!LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.PostProcess))
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.DebugView) || !LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.PostProcess))
Blit(cmd, renderingConfig, m_CurrCameraColorRT, BuiltinRenderTextureType.CameraTarget, blitMaterial);
}

3
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineUtils.cs


DepthPrePass = (1 << 4),
DepthCopy = (1 << 5),
DefaultViewport = (1 << 6),
IntermediateTexture = (1 << 7)
IntermediateTexture = (1 << 7),
DebugView = (1 << 8)
}
public static class LightweightUtils

39
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightShaderUtils.cs


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public enum ShaderPathID

SHADER_PATH_COUNT
}
public enum DebugViewKeyword
{
ALBEDO,
METALNESS,
NORMALS,
ROUGHNESS,
NUM_VIEWS
}
public static class LightweightShaderUtils
{
private static readonly string[] m_ShaderPaths =

"LightweightPipeline/Particles/Standard Unlit",
"Hidden/LightweightPipeline/Blit",
"Hidden/LightweightPipeline/CopyDepth"
};
private static readonly string[] m_DebugViewKeywords =
{
"_DEBUG_ALBEDO",
"_DEBUG_METALNESS",
"_DEBUG_NORMALS",
"_DEBUG_ROUGHNESS"
};
public static string GetShaderPath(ShaderPathID id)

}
return m_ShaderPaths[index];
}
public static void ResetDebugModes(CommandBuffer cmd)
{
for(int i = 0; i < (int)DebugViewKeyword.NUM_VIEWS; i++)
{
cmd.DisableShaderKeyword(m_DebugViewKeywords[i]);
}
}
public static void SetDebugMode(CommandBuffer cmd, DebugViewKeyword mode)
{
int m = (int)mode;
if(m < 0 && m >= (int)DebugViewKeyword.NUM_VIEWS)
{
Debug.LogError("Debug view does not exist.");
}
cmd.EnableShaderKeyword(m_DebugViewKeywords[m]);
}
}
}

23
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLit.hlsl


return result.a;
}
half4 DebugPassFragment(LightweightVertexOutput IN) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(IN);
SurfaceData surfaceData;
InitializeStandardLitSurfaceData(IN.uv, surfaceData);
InputData inputData;
InitializeInputData(IN, surfaceData.normalTS, inputData);
half3 debug = half3(0, 0, 0);
#if defined(_DEBUG_ALBEDO)
debug = surfaceData.albedo;
#elif defined(_DEBUG_METALNESS)
debug = surfaceData.metallic;
#elif defined(_DEBUG_NORMALS)
debug = inputData.normalWS;
#elif defined(_DEBUG_ROUGHNESS)
debug = 1.0 - surfaceData.smoothness;
#endif
return half4(debug, 1);
}
#endif

37
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandard.shader


ENDHLSL
}
Pass
{
Tags{"LightMode" = "DebugView"}
ZWrite On
Cull[_Cull]
HLSLPROGRAM
// Required to compile gles 2.0 with standard SRP library
// All shaders must be compiled with HLSLcc and currently only gles is not using HLSLcc by default
#pragma prefer_hlslcc gles
#pragma target 3.0
// -------------------------------------
// Material Keywords
#pragma shader_feature _NORMALMAP
#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _ALPHAPREMULTIPLY_ON
#pragma shader_feature _EMISSION
#pragma shader_feature _METALLICSPECGLOSSMAP
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _OCCLUSIONMAP
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#pragma multi_compile _ _DEBUG_ALBEDO _DEBUG_METALNESS _DEBUG_NORMALS _DEBUG_ROUGHNESS
#pragma vertex LitPassVertex
#pragma fragment DebugPassFragment
//#include "LWRP/ShaderLibrary/LightweightPassDebug.hlsl"
#include "LWRP/ShaderLibrary/LightweightPassLit.hlsl"
ENDHLSL
}
}
FallBack "Hidden/InternalErrorShader"
CustomEditor "LightweightStandardGUI"

6
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassDebug.hlsl


#ifndef LIGHTWEIGHT_PASS_DEBUG_INCLUDED
#define LIGHTWEIGHT_PASS_DEBUG_INCLUDED
#endif

9
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassDebug.hlsl.meta


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