浏览代码

fix namespace related issues (2021.2+), fix NormalBufferBlurPass when HDRP RenderGraph is enabled (2020.2+), fix nullref issue when resolving disabled attachment

/main
Lasse Jon Fuglsang Pedersen 4 年前
当前提交
e79a543f
共有 7 个文件被更改,包括 84 次插入39 次删除
  1. 2
      Editor/Unity.DemoTeam.DigitalHuman.Editor.asmdef
  2. 75
      Runtime/CustomPass/NormalBufferBlurPass.cs
  3. 1
      Runtime/CustomPass/Resources/NormalBufferBlurPass.shader
  4. 3
      Runtime/SkinAttachmentTarget.cs
  5. 8
      Runtime/Utility/MeshInstanceBehaviour.cs
  6. 28
      Runtime/Utility/NativeMeshObjLoader.cs
  7. 6
      Runtime/Utility/PrefabTransformHierarchy.cs

2
Editor/Unity.DemoTeam.DigitalHuman.Editor.asmdef


{
"name": "Unity.DemoTeam.DigitalHuman.Editor",
"rootNamespace": "",
"GUID:e0cd26848372d4e5c891c569017e11f1",
"GUID:d8b63aba1907145bea998dd612889d6b",
"GUID:78bd2ddd6e276394a9615c203e574844",
"GUID:457756d89b35d2941b3e7b37b4ece6f1",

75
Runtime/CustomPass/NormalBufferBlurPass.cs


RenderTargetIdentifier[] dbufferNormalMaskRTIDs;
#if UNITY_2020_2_OR_NEWER
FieldInfo cachedField_m_EnableRenderGraph;
FieldInfo cachedField_m_DBufferOutput_mrt;
object cachedValue_m_DBufferOutput;
void UpdateDBufferNormalMaskRTIDs(HDRenderPipeline hdPipeline)
{
if (cachedField_m_EnableRenderGraph != null && ((bool)cachedField_m_EnableRenderGraph.GetValue(hdPipeline) == true))
{
if (cachedField_m_DBufferOutput_mrt != null && cachedValue_m_DBufferOutput != null)
{
var mrt = cachedField_m_DBufferOutput_mrt.GetValue(cachedValue_m_DBufferOutput) as TextureHandle[];
if (mrt != null)
{
if (dbufferNormalMaskRTIDs != null && dbufferNormalMaskRTIDs.Length == 2)
{
dbufferNormalMaskRTIDs[0] = mrt[DBUFFER_NORMALS];
dbufferNormalMaskRTIDs[1] = mrt[DBUFFER_MASK];
}
}
}
}
}
#endif
void FindDBufferNormalMaskRTIDs(HDRenderPipeline hdPipeline)
{
dbufferNormalMaskRTIDs = null;

var fieldInfo_m_EnableRenderGraph = typeof(HDRenderPipeline).GetField("m_EnableRenderGraph", BindingFlags.NonPublic | BindingFlags.Instance);
if (fieldInfo_m_EnableRenderGraph != null && (bool)fieldInfo_m_EnableRenderGraph.GetValue(hdPipeline) == true)
var field_m_EnableRenderGraph = typeof(HDRenderPipeline).GetField("m_EnableRenderGraph", BindingFlags.NonPublic | BindingFlags.Instance);
if (field_m_EnableRenderGraph != null && (bool)field_m_EnableRenderGraph.GetValue(hdPipeline) == true)
var fieldInfo_m_DBufferOutput = typeof(HDRenderPipeline).GetField("m_DBufferOutput", BindingFlags.NonPublic | BindingFlags.Instance);
if (fieldInfo_m_DBufferOutput != null)
var field_m_DBufferOutput = typeof(HDRenderPipeline).GetField("m_DBufferOutput", BindingFlags.NonPublic | BindingFlags.Instance);
if (field_m_DBufferOutput != null)
var m_DBufferOutput = fieldInfo_m_DBufferOutput.GetValue(hdPipeline);
if (m_DBufferOutput != null)
var value_m_DBufferOutput = field_m_DBufferOutput.GetValue(hdPipeline);
if (value_m_DBufferOutput != null)
var fieldInfo_mrt = m_DBufferOutput.GetType().GetField("mrt", BindingFlags.Public | BindingFlags.Instance);
if (fieldInfo_mrt != null)
var field_mrt = value_m_DBufferOutput.GetType().GetField("mrt", BindingFlags.Public | BindingFlags.Instance);
if (field_mrt != null)
var mrt = fieldInfo_mrt.GetValue(m_DBufferOutput) as TextureHandle[];
if (mrt != null)
var value_mrt = field_mrt.GetValue(value_m_DBufferOutput) as TextureHandle[];
if (value_mrt != null)
dbufferNormalMaskRTIDs[0] = mrt[DBUFFER_NORMALS];
dbufferNormalMaskRTIDs[1] = mrt[DBUFFER_MASK];
cachedField_m_EnableRenderGraph = field_m_EnableRenderGraph;
cachedField_m_DBufferOutput_mrt = field_mrt;
cachedValue_m_DBufferOutput = value_m_DBufferOutput;
UpdateDBufferNormalMaskRTIDs(hdPipeline);
var fieldInfo_m_DbufferManager = typeof(HDRenderPipeline).GetField("m_DbufferManager", BindingFlags.NonPublic | BindingFlags.Instance);
if (fieldInfo_m_DbufferManager != null)
var field_m_DbufferManager = typeof(HDRenderPipeline).GetField("m_DbufferManager", BindingFlags.NonPublic | BindingFlags.Instance);
if (field_m_DbufferManager != null)
var m_DbufferManager = fieldInfo_m_DbufferManager.GetValue(hdPipeline);
if (m_DbufferManager != null)
var value_m_DbufferManager = field_m_DbufferManager.GetValue(hdPipeline);
if (value_m_DbufferManager != null)
var fieldInfo_m_RTs = m_DbufferManager.GetType().GetField("m_RTs", BindingFlags.NonPublic | BindingFlags.Instance);
if (fieldInfo_m_RTs != null)
var field_m_RTs = value_m_DbufferManager.GetType().GetField("m_RTs", BindingFlags.NonPublic | BindingFlags.Instance);
if (field_m_RTs != null)
var m_RTs = fieldInfo_m_RTs.GetValue(m_DbufferManager) as RTHandle[];
if (m_RTs != null)
var value_m_RTs = field_m_RTs.GetValue(value_m_DbufferManager) as RTHandle[];
if (value_m_RTs != null)
dbufferNormalMaskRTIDs[0] = m_RTs[DBUFFER_NORMALS].nameID;
dbufferNormalMaskRTIDs[1] = m_RTs[DBUFFER_MASK].nameID;
dbufferNormalMaskRTIDs[0] = value_m_RTs[DBUFFER_NORMALS].nameID;
dbufferNormalMaskRTIDs[1] = value_m_RTs[DBUFFER_MASK].nameID;
}
}
}

protected override void Execute(CustomPassContext ctx)
{
Profiler.BeginSample("NormalBufferBlurPass");
UpdateDBufferNormalMaskRTIDs(RenderPipelineManager.currentPipeline as HDRenderPipeline);
ExecuteNormalBufferBlur(
ctx.renderContext,
ctx.cmd,

1
Runtime/CustomPass/Resources/NormalBufferBlurPass.shader


#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"

3
Runtime/SkinAttachmentTarget.cs


case SkinAttachment.AttachmentType.Mesh:
case SkinAttachment.AttachmentType.MeshRoots:
{
if (subject.meshInstance == null)
break;
if (subject.meshInstance.vertexCount != stagingData[indexPos].Length)
{
Debug.LogError("mismatching vertex- and attachment count", subject);

8
Runtime/Utility/MeshInstanceBehaviour.cs


using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.Experimental.SceneManagement;
using UnityEditor;
#if UNITY_2021_2_OR_NEWER
using UnityEditor.SceneManagement;
#else
using UnityEditor.Experimental.SceneManagement;
#endif
#endif
namespace Unity.DemoTeam.DigitalHuman

28
Runtime/Utility/NativeMeshObjLoader.cs


public InputVertex v2;
}
public unsafe static NativeMeshSOA Parse(string path, Allocator outputAllocator = Allocator.Persistent, VertexAttribs vertexAttribs = VertexAttribs.Position, VertexOrder vertexOrder = VertexOrder.ByDefinition)
public unsafe static NativeMeshSOA Parse(string path, Allocator allocator = Allocator.Persistent, VertexAttribs vertexAttribs = VertexAttribs.Position, VertexOrder vertexOrder = VertexOrder.ByDefinition)
{
#if VERBOSE
Debug.LogFormat("trying {0}", path);

#endif
// allocate buffers
var inputPositions = new NativeArray<Vector3>(numPositions, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
var inputTexCoords = new NativeArray<Vector2>(numTexCoords, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
var inputNormals = new NativeArray<Vector3>(numNormals, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
var inputFaces = new NativeArray<InputFace>(numFaces, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
var inputPositions = new NativeArray<Vector3>(numPositions, allocator, NativeArrayOptions.UninitializedMemory);
var inputTexCoords = new NativeArray<Vector2>(numTexCoords, allocator, NativeArrayOptions.UninitializedMemory);
var inputNormals = new NativeArray<Vector3>(numNormals, allocator, NativeArrayOptions.UninitializedMemory);
var inputFaces = new NativeArray<InputFace>(numFaces, allocator, NativeArrayOptions.UninitializedMemory);
var outputIndicesLUT = new NativeHashMap<Hash128, int>(outputIndicesMax, Allocator.Temp);
var outputPositions = new NativeArray<Vector3>(outputIndicesMax, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
var outputTexCoords = new NativeArray<Vector2>(outputIndicesMax, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
var outputNormals = new NativeArray<Vector3>(outputIndicesMax, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
var outputIndices = new NativeArray<int>(outputIndicesMax, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
var outputIndicesLUT = new NativeHashMap<Hash128, int>(outputIndicesMax, allocator);
var outputPositions = new NativeArray<Vector3>(outputIndicesMax, allocator, NativeArrayOptions.UninitializedMemory);
var outputTexCoords = new NativeArray<Vector2>(outputIndicesMax, allocator, NativeArrayOptions.UninitializedMemory);
var outputNormals = new NativeArray<Vector3>(outputIndicesMax, allocator, NativeArrayOptions.UninitializedMemory);
var outputIndices = new NativeArray<int>(outputIndicesMax, allocator, NativeArrayOptions.UninitializedMemory);
// read the data
numPositions = 0;

// copy to container
NativeMeshSOA mesh = new NativeMeshSOA()
{
vertexPositions = new NativeArray<Vector3>(numOutputVertices, outputAllocator, NativeArrayOptions.UninitializedMemory),
vertexTexCoords = new NativeArray<Vector2>(numOutputVertices, outputAllocator, NativeArrayOptions.UninitializedMemory),
vertexNormals = new NativeArray<Vector3>(numOutputVertices, outputAllocator, NativeArrayOptions.UninitializedMemory),
vertexPositions = new NativeArray<Vector3>(numOutputVertices, allocator, NativeArrayOptions.UninitializedMemory),
vertexTexCoords = new NativeArray<Vector2>(numOutputVertices, allocator, NativeArrayOptions.UninitializedMemory),
vertexNormals = new NativeArray<Vector3>(numOutputVertices, allocator, NativeArrayOptions.UninitializedMemory),
faceIndices = new NativeArray<int>(numOutputIndices, outputAllocator, NativeArrayOptions.UninitializedMemory),
faceIndices = new NativeArray<int>(numOutputIndices, allocator, NativeArrayOptions.UninitializedMemory),
faceIndicesCount = numOutputIndices,
};

6
Runtime/Utility/PrefabTransformHierarchy.cs


using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor.Experimental.SceneManagement;
#if UNITY_2021_2_OR_NEWER
using UnityEditor.SceneManagement;
#else
using UnityEditor.Experimental.SceneManagement;
#endif
#endif
namespace Unity.DemoTeam.DigitalHuman

正在加载...
取消
保存