浏览代码

SSAO Debug View.

/projects-TheLastStand
John Parsaie 7 年前
当前提交
dbc7ce60
共有 2 个文件被更改,包括 43 次插入39 次删除
  1. 80
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  2. 2
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLit.hlsl

80
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


{
DepthPass(ref context, frameRenderingConfiguration);
RenderSSAO(m_CurrCamera, context, m_CameraPostProcessLayer);
RenderSSAO(m_CurrCamera, context, m_CameraPostProcessLayer, frameRenderingConfiguration);
// Only screen space shadowmap mode is supported.
if (shadows)

if(!LightweightUtils.HasFlag(frameRenderingConfiguration, FrameRenderingConfiguration.DebugView))
ForwardPass(visibleLights, frameRenderingConfiguration, ref context, ref lightData, stereoEnabled);
else
DebugViewPass(frameRenderingConfiguration, ref context, stereoEnabled);
DebugViewPass(visibleLights, frameRenderingConfiguration, ref context, ref lightData, stereoEnabled);
cmd.name = "After Camera Render";
#if UNITY_EDITOR

cmd.ReleaseTemporaryRT(m_ShadowMapRTID);
cmd.ReleaseTemporaryRT(m_ScreenSpaceShadowMapRTID);
cmd.ReleaseTemporaryRT(PerCameraBuffer._AmbientOcclusionBuffer);
cmd.ReleaseTemporaryRT(CameraRenderTargetID.depthCopy);
cmd.ReleaseTemporaryRT(CameraRenderTargetID.depth);
cmd.ReleaseTemporaryRT(CameraRenderTargetID.color);

StopStereoRendering(ref context, frameRenderingConfiguration);
}
private void DebugViewPass(FrameRenderingConfiguration frameRenderingConfiguration, ref ScriptableRenderContext context, bool stereoEnabled)
private void RenderSSAO(Camera camera, ScriptableRenderContext context, PostProcessLayer postProcessLayer, FrameRenderingConfiguration config)
{
CommandBuffer cmd = CommandBufferPool.Get("Render SSAO");
if(postProcessLayer != null && postProcessLayer.enabled)
{
var settings = postProcessLayer.GetSettings<AmbientOcclusion>();
if(settings.IsEnabledAndSupported(null))
{
cmd.GetTemporaryRT(PerCameraBuffer._AmbientOcclusionBuffer,
camera.pixelWidth, camera.pixelHeight, 0,
FilterMode.Bilinear, RenderTextureFormat.R8);
//Bake the AO from depth.
postProcessLayer.BakeMSVOMap(cmd, camera, m_AmbientOcclusionRT, m_DepthRT, true);
cmd.SetGlobalTexture(PerCameraBuffer._AmbientOcclusionBuffer, m_AmbientOcclusionRT);
cmd.SetGlobalVector(PerCameraBuffer._AmbientOcclusionParam, new Vector4(settings.color.value.r,
settings.color.value.g,
settings.color.value.b,
settings.directLightingStrength.value));
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
return;
}
}
cmd.SetGlobalTexture(PerCameraBuffer._AmbientOcclusionBuffer, RuntimeUtilities.blackTexture);
cmd.SetGlobalVector(PerCameraBuffer._AmbientOcclusionParam, Vector4.zero);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
private void DebugViewPass(List<VisibleLight> visibleLights, FrameRenderingConfiguration frameRenderingConfiguration, ref ScriptableRenderContext context, ref LightData lightData, bool stereoEnabled)
SetupShaderConstants(visibleLights, ref context, ref lightData);
BeginForwardRendering(ref context, frameRenderingConfiguration);
CommandBuffer cmd = CommandBufferPool.Get("Debug View Mode");

context.DrawRenderers(m_CullResults.visibleRenderers, ref debugViewDrawSettings, debugViewFilterSettings);
EndForwardRendering(ref context, frameRenderingConfiguration);
}
private void RenderSSAO(Camera camera, ScriptableRenderContext context, PostProcessLayer postProcessLayer)
{
CommandBuffer cmd = CommandBufferPool.Get("Render SSAO");
if(postProcessLayer != null && postProcessLayer.enabled)
{
var settings = postProcessLayer.GetSettings<AmbientOcclusion>();
if(settings.IsEnabledAndSupported(null))
{
cmd.GetTemporaryRT(PerCameraBuffer._AmbientOcclusionBuffer,
camera.pixelWidth, camera.pixelHeight, 0,
FilterMode.Bilinear, RenderTextureFormat.R8);
postProcessLayer.BakeMSVOMap(cmd, camera, m_AmbientOcclusionRT, m_DepthRT, true);
cmd.SetGlobalTexture(PerCameraBuffer._AmbientOcclusionBuffer, m_AmbientOcclusionRT);
cmd.SetGlobalVector(PerCameraBuffer._AmbientOcclusionParam, new Vector4(settings.color.value.r,
settings.color.value.g,
settings.color.value.b,
settings.directLightingStrength.value));
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
return;
}
}
cmd.SetGlobalTexture(PerCameraBuffer._AmbientOcclusionBuffer, RuntimeUtilities.blackTexture);
cmd.SetGlobalVector(PerCameraBuffer._AmbientOcclusionParam, Vector4.zero);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
AfterOpaque(ref context, frameRenderingConfiguration);
AfterTransparent(ref context, frameRenderingConfiguration);
EndForwardRendering(ref context, frameRenderingConfiguration);
}
private void ForwardPass(List<VisibleLight> visibleLights, FrameRenderingConfiguration frameRenderingConfiguration, ref ScriptableRenderContext context, ref LightData lightData, bool stereoEnabled)

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


float2 texcoord : TEXCOORD0;
float2 lightmapUV : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct LightweightVertexOutput

return LightweightFragmentBlinnPhong(inputData, diffuse, specularGloss, shininess, emission, alpha);
};
// Used for StandardSimpleLighting shader
half4 LitPassFragmentSimpleNull(LightweightVertexOutput IN) : SV_Target

正在加载...
取消
保存