|
|
|
|
|
|
const int DBUFFER_MASK = 2; |
|
|
|
|
|
|
|
private RTHandle[] dbufferRTs; |
|
|
|
private RenderTargetIdentifier[] dbufferNormalMaskRTI; |
|
|
|
private RenderTargetIdentifier[] dbufferRTIDs; |
|
|
|
private RenderTargetIdentifier[] dbufferNormalMaskRTIDs; |
|
|
|
|
|
|
|
dbufferRTs = null; |
|
|
|
dbufferRTIDs = null; |
|
|
|
|
|
|
|
var fieldInfo_m_DbufferManager = typeof(HDRenderPipeline).GetField("m_DbufferManager", BindingFlags.NonPublic | BindingFlags.Instance); |
|
|
|
if (fieldInfo_m_DbufferManager != null) |
|
|
|
|
|
|
//Debug.Log("FindDbufferRTs : " + fieldInfo_m_RTs);
|
|
|
|
dbufferRTs = fieldInfo_m_RTs.GetValue(m_DbufferManager) as RTHandle[]; |
|
|
|
} |
|
|
|
|
|
|
|
var fieldInfo_m_RTIDs = m_DbufferManager.GetType().GetField("m_RTIDs", BindingFlags.NonPublic | BindingFlags.Instance); |
|
|
|
if (fieldInfo_m_RTIDs != null) |
|
|
|
{ |
|
|
|
//Debug.Log("FindDbufferRTIDs : " + fieldInfo_m_RTIDs);
|
|
|
|
dbufferRTIDs = fieldInfo_m_RTIDs.GetValue(m_DbufferManager) as RenderTargetIdentifier[]; |
|
|
|
} |
|
|
|
} |
|
|
|
private RenderTargetIdentifier[] GetDbufferNormalMaskRTIDs() |
|
|
|
{ |
|
|
|
dbufferNormalMaskRTI = new RenderTargetIdentifier[2]; |
|
|
|
dbufferNormalMaskRTI[0] = dbufferRTs[DBUFFER_NORMALS].nameID; |
|
|
|
dbufferNormalMaskRTI[1] = dbufferRTs[DBUFFER_MASK].nameID; |
|
|
|
if (dbufferRTs[DBUFFER_NORMALS] == null || dbufferRTs[DBUFFER_MASK] == null) |
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
else |
|
|
|
|
|
|
|
if (dbufferRTIDs != null) |
|
|
|
dbufferNormalMaskRTI = null; |
|
|
|
if (dbufferNormalMaskRTIDs == null) |
|
|
|
dbufferNormalMaskRTIDs = new RenderTargetIdentifier[2]; |
|
|
|
|
|
|
|
dbufferNormalMaskRTIDs[0] = dbufferRTIDs[DBUFFER_NORMALS]; |
|
|
|
dbufferNormalMaskRTIDs[1] = dbufferRTIDs[DBUFFER_MASK]; |
|
|
|
|
|
|
|
return dbufferNormalMaskRTIDs; |
|
|
|
} |
|
|
|
|
|
|
|
static bool EnsureMaterial(ref Material material, string shaderName) |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#if UNITY_2020_2_OR_NEWER
|
|
|
|
protected override void Execute(CustomPassContext ctx) |
|
|
|
{ |
|
|
|
Profiler.BeginSample("NormalBufferBlurPass"); |
|
|
|
ExecuteNormalBufferBlur( |
|
|
|
ctx.renderContext, |
|
|
|
ctx.cmd, |
|
|
|
ctx.hdCamera, |
|
|
|
ctx.cameraColorBuffer, |
|
|
|
ctx.cameraDepthBuffer, |
|
|
|
ctx.cameraNormalBuffer, |
|
|
|
ctx.cullingResults |
|
|
|
); |
|
|
|
Profiler.EndSample(); |
|
|
|
} |
|
|
|
#else
|
|
|
|
RTHandle cameraColor; |
|
|
|
RTHandle cameraDepth; |
|
|
|
GetCameraBuffers(out cameraColor, out cameraDepth); |
|
|
|
|
|
|
|
ExecuteNormalBufferBlur(renderContext, cmd, hdCamera, cullingResults); |
|
|
|
ExecuteNormalBufferBlur( |
|
|
|
renderContext, |
|
|
|
cmd, |
|
|
|
hdCamera, |
|
|
|
cameraColor, |
|
|
|
cameraDepth, |
|
|
|
GetNormalBuffer(), |
|
|
|
cullingResults |
|
|
|
); |
|
|
|
#endif
|
|
|
|
void ExecuteNormalBufferBlur(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera hdCamera, CullingResults cullingResults) |
|
|
|
void ExecuteNormalBufferBlur(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera hdCamera, RTHandle cameraColor, RTHandle cameraDepth, RTHandle cameraNormal, CullingResults cullingResults) |
|
|
|
{ |
|
|
|
if (!EnsureMaterial(ref passMaterial, NAME_SHADER)) |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
if (!hdCamera.frameSettings.IsEnabled(FrameSettingsField.Decals)) |
|
|
|
return; |
|
|
|
|
|
|
|
RTHandle cameraColor; |
|
|
|
RTHandle cameraDepth; |
|
|
|
GetCameraBuffers(out cameraColor, out cameraDepth); |
|
|
|
|
|
|
|
int bufferW = cameraColor.rt.width; |
|
|
|
int bufferH = cameraColor.rt.height; |
|
|
|
|
|
|
); |
|
|
|
CoreUtils.SetViewport(cmd, cameraDepth); |
|
|
|
|
|
|
|
cmd.SetRandomWriteTarget(2, GetNormalBuffer()); |
|
|
|
cmd.SetRandomWriteTarget(2, cameraNormal); |
|
|
|
cmd.DrawProcedural(Matrix4x4.identity, passMaterial, PASS_DECODE, MeshTopology.Triangles, 3, 1); |
|
|
|
cmd.ClearRandomWriteTargets(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (dbufferNormalMaskRTI != null) |
|
|
|
if (GetDbufferNormalMaskRTIDs() != null) |
|
|
|
dbufferNormalMaskRTI, |
|
|
|
GetDbufferNormalMaskRTIDs(), |
|
|
|
cmd.SetRandomWriteTarget(2, GetNormalBuffer()); |
|
|
|
cmd.SetRandomWriteTarget(2, cameraNormal); |
|
|
|
cmd.DrawProcedural(Matrix4x4.identity, passMaterial, PASS_BLUR_AND_ENCODE_AND_DECAL, MeshTopology.Triangles, 3, 1); |
|
|
|
cmd.ClearRandomWriteTargets(); |
|
|
|
} |
|
|
|
|
|
|
); |
|
|
|
CoreUtils.SetViewport(cmd, cameraDepth); |
|
|
|
|
|
|
|
cmd.SetRandomWriteTarget(2, GetNormalBuffer()); |
|
|
|
cmd.SetRandomWriteTarget(2, cameraNormal); |
|
|
|
cmd.DrawProcedural(Matrix4x4.identity, passMaterial, PASS_BLUR_AND_ENCODE, MeshTopology.Triangles, 3, 1); |
|
|
|
cmd.ClearRandomWriteTargets(); |
|
|
|
} |
|
|
|