浏览代码

Fixed DBuffer HTile binding when ShadowMask or enabled.

/main
Julien Ignace 7 年前
当前提交
55ae07e1
共有 2 个文件被更改,包括 33 次插入4 次删除
  1. 8
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  2. 29
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/GBufferManager.cs

8
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


RenderDBuffer(hdCamera, renderContext, cmd);
RenderGBuffer(m_CullResults, hdCamera, renderContext, cmd);
RenderGBuffer(m_CullResults, hdCamera, enableBakeShadowMask, renderContext, cmd);
// In both forward and deferred, everything opaque should have been rendered at this point so we can safely copy the depth buffer for later processing.
CopyDepthBufferIfNeeded(cmd);

// RenderGBuffer do the gbuffer pass. This is solely call with deferred. If we use a depth prepass, then the depth prepass will perform the alpha testing for opaque apha tested and we don't need to do it anymore
// during Gbuffer pass. This is handled in the shader and the depth test (equal and no depth write) is done here.
void RenderGBuffer(CullResults cull, HDCamera hdCamera, ScriptableRenderContext renderContext, CommandBuffer cmd)
void RenderGBuffer(CullResults cull, HDCamera hdCamera, bool enableShadowMask, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
if (m_FrameSettings.enableForwardRenderingOnly)
return;

using (new ProfilingSample(cmd, m_CurrentDebugDisplaySettings.IsDebugDisplayEnabled() ? "GBufferDebugDisplay" : "GBuffer", CustomSamplerId.GBuffer.GetSampler()))
{
// setup GBuffer for rendering
HDUtils.SetRenderTarget(cmd, hdCamera, m_GbufferManager.GetBuffersRTI(), m_CameraDepthStencilBuffer);
HDUtils.SetRenderTarget(cmd, hdCamera, m_GbufferManager.GetBuffersRTI(enableShadowMask), m_CameraDepthStencilBuffer);
m_DbufferManager.SetHTile(m_GbufferManager.bufferCount, cmd);
m_DbufferManager.SetHTile(m_GbufferManager.GetBufferCount(enableShadowMask), cmd);
}
// Render opaque objects into GBuffer

29
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/GBufferManager.cs


int m_GBufferCount = 0;
bool m_EnableShadowMask = false;
RenderPipelineMaterial m_DeferredMaterial;
protected RenderTargetIdentifier[] m_RTIDsNoShadowMask;
public GBufferManager(RenderPipelineMaterial deferredMaterial, bool enableBakeShadowMask)
: base(deferredMaterial.GetMaterialGBufferCount() + (enableBakeShadowMask ? 1 : 0))

m_DeferredMaterial = deferredMaterial;
m_GBufferCount = deferredMaterial.GetMaterialGBufferCount();
m_EnableShadowMask = enableBakeShadowMask;
m_RTIDsNoShadowMask = new RenderTargetIdentifier[m_GBufferCount];
}
public override void CreateBuffers()

m_RTs[gbufferIndex] = RTHandle.Alloc(Vector2.one, colorFormat: rtFormat[gbufferIndex], sRGB: sRGBFlags[gbufferIndex], filterMode: FilterMode.Point);
m_RTIDs[gbufferIndex] = m_RTs[gbufferIndex].nameID;
m_TextureShaderIDs[gbufferIndex] = HDShaderIDs._GBufferTexture[gbufferIndex];
m_RTIDsNoShadowMask[gbufferIndex] = HDShaderIDs._GBufferTexture[gbufferIndex];
}
if (m_EnableShadowMask)

m_TextureShaderIDs[m_GBufferCount] = HDShaderIDs._ShadowMaskTexture;
}
}
public RenderTargetIdentifier[] GetBuffersRTI(bool enableShadowMask)
{
if(!enableShadowMask)
{
// nameID can change from one frame to another depending on the msaa flag so so we need to update this array to be sure it's up to date.
// Moreover, if we don't have shadow masks we only need to bind the first GBuffers
// This is important because in the shader the shadowmask buffer gets optimized out so anything bound after (like the DBuffer HTile) has a different bind point.
for (int i = 0; i < m_GBufferCount; ++i)
{
m_RTIDsNoShadowMask[i] = m_RTs[i].nameID;
}
return m_RTIDsNoShadowMask;
}
else
{
return GetBuffersRTI();
}
}
public int GetBufferCount(bool enableShadowMask)
{
return enableShadowMask ? m_BufferCount : m_GBufferCount;
}
}
}
正在加载...
取消
保存