浏览代码

add a few guards for better forward-compatibility

/main
Lasse Jon Fuglsang Pedersen 4 年前
当前提交
35706698
共有 2 个文件被更改,包括 81 次插入19 次删除
  1. 81
      Runtime/CustomPass/NormalBufferBlurPass.cs
  2. 19
      Runtime/SnappersHeadImporter.cs

81
Runtime/CustomPass/NormalBufferBlurPass.cs


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();
}

19
Runtime/SnappersHeadImporter.cs


sb.AppendLine("using UnityEngine;");
sb.AppendLine("using Unity.DemoTeam.DigitalHuman;");
sb.AppendLine("using Unity.Collections.LowLevel.Unsafe;// for UnsafeUtilityEx.AsRef<T>");
sb.AppendLine("using Unity.Collections.LowLevel.Unsafe;// for UnsafeUtility.AsRef<T>");
sb.AppendLine();
sb.AppendFormat("namespace {0}\n", csNamespace);
sb.AppendLine("{");

sb.Clear();
sb.AppendLine("#pragma warning disable 0219");
if (csCompacted == false)
{
sb.AppendLine();
sb.AppendLine("using Unity.DemoTeam.DigitalHuman;");
}
sb.AppendLine();
sb.AppendFormat("namespace {0}\n", csNamespace);
sb.AppendLine("{");

}
else
{
sb.AppendLine("#if UNITY_2020_1_OR_NEWER");
sb.AppendLine(" ref UnsafeUtility.AsRef<SnappersControllers>(ptrSnappersControllers),");
sb.AppendLine(" ref UnsafeUtility.AsRef<SnappersBlendShapes>(ptrSnappersBlendShapes),");
sb.AppendLine(" ref UnsafeUtility.AsRef<SnappersShaderParam>(ptrSnappersShaderParam)");
sb.AppendLine("#else");
sb.AppendLine("#endif");
}
sb.AppendLine(" );");

}
else
{
sb.AppendLine("#if UNITY_2020_1_OR_NEWER");
sb.AppendLine(" ref UnsafeUtility.AsRef<SnappersControllers>(ptrSnappersControllers)");
sb.AppendLine("#else");
sb.AppendLine("#endif");
}
sb.AppendLine(" );");

正在加载...
取消
保存