Skip to content

Fix custom pass prefabs #419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Tentative fix for missing include in depth of field shaders.
- Fixed the light overlap scene view draw mode (wasn't working at all).
- Fixed taaFrameIndex and XR tests 4052 and 4053
- Fixed the prefab integration of custom passes (Prefab Override Highlight not working as expected).

### Changed
- Improve MIP selection for decals on Transparents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,36 +158,33 @@ void DoCommonSettingsGUI(ref Rect rect)
rect.y += Styles.defaultLineSpace;
}

#if true
if ((commonPassUIFlags & PassUIFlag.TargetColorBuffer) != 0)
{
m_TargetColorBuffer.intValue = (int)(CustomPass.TargetBuffer)EditorGUI.EnumPopup(rect, Styles.targetColorBuffer, (CustomPass.TargetBuffer)m_TargetColorBuffer.intValue);
EditorGUI.BeginProperty(rect, Styles.targetColorBuffer, m_TargetColorBuffer);
// There is still a bug with SerializedReference and PropertyField so we can't use it yet
// EditorGUI.PropertyField(rect, m_TargetColorBuffer, Styles.targetColorBuffer);
m_TargetColorBuffer.intValue = (int)(CustomPass.TargetBuffer)EditorGUI.EnumPopup(rect, Styles.targetColorBuffer, (CustomPass.TargetBuffer)m_TargetColorBuffer.intValue);
EditorGUI.EndProperty();
rect.y += Styles.defaultLineSpace;
}

if ((commonPassUIFlags & PassUIFlag.TargetDepthBuffer) != 0)
{
m_TargetDepthBuffer.intValue = (int)(CustomPass.TargetBuffer)EditorGUI.EnumPopup(rect, Styles.targetDepthBuffer, (CustomPass.TargetBuffer)m_TargetDepthBuffer.intValue);
EditorGUI.BeginProperty(rect, Styles.targetColorBuffer, m_TargetDepthBuffer);
// EditorGUI.PropertyField(rect, m_TargetDepthBuffer, Styles.targetDepthBuffer);
m_TargetDepthBuffer.intValue = (int)(CustomPass.TargetBuffer)EditorGUI.EnumPopup(rect, Styles.targetDepthBuffer, (CustomPass.TargetBuffer)m_TargetDepthBuffer.intValue);
EditorGUI.EndProperty();
rect.y += Styles.defaultLineSpace;
}

if ((commonPassUIFlags & PassUIFlag.ClearFlags) != 0)
{
m_ClearFlags.intValue = (int)(ClearFlag)EditorGUI.EnumPopup(rect, Styles.clearFlags, (ClearFlag)m_ClearFlags.intValue);
EditorGUI.BeginProperty(rect, Styles.clearFlags, m_ClearFlags);
// EditorGUI.PropertyField(rect, m_ClearFlags, Styles.clearFlags);
m_ClearFlags.intValue = (int)(ClearFlag)EditorGUI.EnumPopup(rect, Styles.clearFlags, (ClearFlag)m_ClearFlags.intValue);
EditorGUI.EndProperty();
rect.y += Styles.defaultLineSpace;
}

#else // TODO: remove all this code when the fix for SerializedReference lands

EditorGUI.PropertyField(rect, m_TargetColorBuffer, Styles.targetColorBuffer);
rect.y += Styles.defaultLineSpace;

EditorGUI.PropertyField(rect, m_TargetDepthBuffer, Styles.targetDepthBuffer);
rect.y += Styles.defaultLineSpace;

EditorGUI.PropertyField(rect, m_ClearFlags, Styles.clearFlags);
rect.y += Styles.defaultLineSpace;
#endif
}

/// <summary>
Expand Down Expand Up @@ -216,10 +213,18 @@ void DoHeaderGUI(ref Rect rect)
enabledRect.x = rect.xMax - enabledSize.x;
enabledRect.width = enabledSize.x;

m_PassFoldout.boolValue = EditorGUI.Foldout(headerRect, m_PassFoldout.boolValue, $"{m_Name.stringValue} ({m_PassType.Name})", true, EditorStyles.boldLabel);
EditorGUIUtility.labelWidth = enabledRect.width - 14;
m_Enabled.boolValue = EditorGUI.Toggle(enabledRect, Styles.enabled, m_Enabled.boolValue);
EditorGUIUtility.labelWidth = 0;
EditorGUI.BeginProperty(headerRect, GUIContent.none, m_PassFoldout);
{
m_PassFoldout.boolValue = EditorGUI.Foldout(headerRect, m_PassFoldout.boolValue, $"{m_Name.stringValue} ({m_PassType.Name})", true, EditorStyles.boldLabel);
}
EditorGUI.EndProperty();
EditorGUI.BeginProperty(enabledRect, Styles.enabled, m_Enabled);
{
EditorGUIUtility.labelWidth = enabledRect.width - 14;
m_Enabled.boolValue = EditorGUI.Toggle(enabledRect, Styles.enabled, m_Enabled.boolValue);
EditorGUIUtility.labelWidth = 0;
}
EditorGUI.EndProperty();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public override void OnInspectorGUI()
}

List<Material> GatherCustomPassesMaterials()
=> m_Volume.customPasses.SelectMany(p => p.RegisterMaterialForInspector()).Where(m => m != null).ToList();
=> m_Volume.customPasses.Where(p => p != null).SelectMany(p => p.RegisterMaterialForInspector()).Where(m => m != null).ToList();

void UpdateMaterialEditors()
{
Expand Down Expand Up @@ -113,6 +113,9 @@ CustomPassDrawer GetCustomPassDrawer(SerializedProperty pass, int listIndex)

var customPass = m_Volume.customPasses[listIndex];

if (customPass == null)
return null;

foreach (var drawerType in TypeCache.GetTypesWithAttribute(typeof(CustomPassDrawerAttribute)))
{
var attr = drawerType.GetCustomAttributes(typeof(CustomPassDrawerAttribute), true)[0] as CustomPassDrawerAttribute;
Expand Down Expand Up @@ -140,7 +143,12 @@ void DrawSettingsGUI()

EditorGUI.BeginChangeCheck();
{
m_SerializedPassVolume.isGlobal.boolValue = EditorGUILayout.Popup(Styles.isGlobal, m_SerializedPassVolume.isGlobal.boolValue ? 0 : 1, Styles.modes) == 0;
Rect isGlobalRect = EditorGUILayout.GetControlRect();
EditorGUI.BeginProperty(isGlobalRect, Styles.isGlobal, m_SerializedPassVolume.isGlobal);
{
m_SerializedPassVolume.isGlobal.boolValue = EditorGUI.Popup(isGlobalRect, Styles.isGlobal, m_SerializedPassVolume.isGlobal.boolValue ? 0 : 1, Styles.modes) == 0;
}
EditorGUI.EndProperty();
EditorGUILayout.PropertyField(m_SerializedPassVolume.injectionPoint, Styles.injectionPoint);
EditorGUILayout.PropertyField(m_SerializedPassVolume.priority, Styles.priority);
if (!m_SerializedPassVolume.isGlobal.boolValue)
Expand All @@ -163,9 +171,15 @@ void DrawCustomPassReorderableList()
}
}

EditorGUILayout.BeginVertical();
m_CustomPassList.DoLayoutList();
EditorGUILayout.EndVertical();
float customPassListHeight = m_CustomPassList.GetHeight();
var customPassRect = EditorGUILayout.GetControlRect(false, customPassListHeight);
EditorGUI.BeginProperty(customPassRect, GUIContent.none, m_SerializedPassVolume.customPasses);
{
EditorGUILayout.BeginVertical();
m_CustomPassList.DoList(customPassRect);
EditorGUILayout.EndVertical();
}
EditorGUI.EndProperty();
}

void CreateReorderableList(SerializedProperty passList)
Expand Down Expand Up @@ -200,28 +214,34 @@ void CreateReorderableList(SerializedProperty passList)
};

m_CustomPassList.onAddCallback += (list) => {
Undo.RegisterCompleteObjectUndo(target, "Remove custom pass");
Undo.RegisterCompleteObjectUndo(target, "Add custom pass");

var menu = new GenericMenu();
foreach (var customPassType in TypeCache.GetTypesDerivedFrom<CustomPass>())
{
if (customPassType.IsAbstract)
continue;

menu.AddItem(new GUIContent(customPassType.Name), false, () => {
m_Volume.AddPassOfType(customPassType);
passList.serializedObject.Update();
m_Volume.AddPassOfType(customPassType);
UpdateMaterialEditors();
});
passList.serializedObject.ApplyModifiedProperties();
// Notify the prefab that something have changed:
PrefabUtility.RecordPrefabInstancePropertyModifications(target);
});
}
menu.ShowAsContext();
};

m_CustomPassList.onRemoveCallback = (list) => {
passList.serializedObject.Update();
Undo.RegisterCompleteObjectUndo(target, "Remove custom pass");
m_Volume.customPasses.RemoveAt(list.index);
passList.serializedObject.Update();
UpdateMaterialEditors();
passList.serializedObject.ApplyModifiedProperties();
// Notify the prefab that something have changed:
PrefabUtility.RecordPrefabInstancePropertyModifications(target);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ protected override void DoPassGUI(SerializedProperty customPass, Rect rect)
#endif

// TODO: remove all this code when the fix for SerializedReference lands
// EditorGUI.PropertyField(rect, m_SortingCriteria, Styles.sortingCriteria);
m_SortingCriteria.intValue = (int)(SortingCriteria)EditorGUI.EnumPopup(rect, Styles.sortingCriteria, (SortingCriteria)m_SortingCriteria.intValue);
EditorGUI.PropertyField(rect, m_SortingCriteria, Styles.sortingCriteria);
rect.y += Styles.defaultLineSpace;

EditorGUI.indentLevel--;
Expand Down Expand Up @@ -205,10 +204,11 @@ void DoFilters(ref Rect rect)
if (m_FilterFoldout.boolValue)
{
EditorGUI.indentLevel++;
//Render queue filter
EditorGUI.BeginProperty(rect, Styles.renderQueueFilter, m_RenderQueue);
// There is still a bug with SerializedReference and PropertyField so we can't use it yet
// EditorGUI.PropertyField(rect, m_RenderQueue, Styles.renderQueueFilter);
// TODO: remove all this code when the fix for SerializedReference lands
m_RenderQueue.intValue = (int)(CustomPass.RenderQueueType)EditorGUI.EnumPopup(rect, Styles.renderQueueFilter, (CustomPass.RenderQueueType)m_RenderQueue.intValue);
EditorGUI.EndProperty();
rect.y += Styles.defaultLineSpace;
if (ShowOpaqueObjectWarning())
{
Expand All @@ -229,9 +229,7 @@ void DoMaterialOverride(ref Rect rect)
{
//Override material
EditorGUI.BeginChangeCheck();
// TODO: remove all this code when the fix for SerializedReference lands
m_OverrideMaterial.objectReferenceValue = EditorGUI.ObjectField(rect, Styles.overrideMaterial, m_OverrideMaterial.objectReferenceValue, typeof(Material), false);
// EditorGUI.PropertyField(rect, m_OverrideMaterial, Styles.overrideMaterial);
EditorGUI.PropertyField(rect, m_OverrideMaterial, Styles.overrideMaterial);
if (EditorGUI.EndChangeCheck())
{
var mat = m_OverrideMaterial.objectReferenceValue as Material;
Expand All @@ -244,37 +242,49 @@ void DoMaterialOverride(ref Rect rect)
EditorGUI.indentLevel++;
if (m_OverrideMaterial.objectReferenceValue)
{
var mat = m_OverrideMaterial.objectReferenceValue as Material;
EditorGUI.BeginChangeCheck();
int index = mat.FindPass(m_OverrideMaterialPassName.stringValue);
index = EditorGUI.IntPopup(rect, Styles.overrideMaterialPass, index, GetMaterialPassNames(mat), Enumerable.Range(0, mat.passCount).ToArray());
if (EditorGUI.EndChangeCheck())
m_OverrideMaterialPassName.stringValue = mat.GetPassName(index);
EditorGUI.BeginProperty(rect, Styles.overrideMaterialPass, m_OverrideMaterialPassName);
{
var mat = m_OverrideMaterial.objectReferenceValue as Material;
EditorGUI.BeginChangeCheck();
int index = mat.FindPass(m_OverrideMaterialPassName.stringValue);
index = EditorGUI.IntPopup(rect, Styles.overrideMaterialPass, index, GetMaterialPassNames(mat), Enumerable.Range(0, mat.passCount).ToArray());
if (EditorGUI.EndChangeCheck())
m_OverrideMaterialPassName.stringValue = mat.GetPassName(index);
}
EditorGUI.EndProperty();
}
else
{
EditorGUI.BeginProperty(rect, Styles.renderQueueFilter, m_RenderQueue);
// There is still a bug with SerializedReference and PropertyField so we can't use it yet
// EditorGUI.PropertyField(rect, m_ShaderPass, Styles.shaderPass);
m_ShaderPass.intValue = (int)(DrawRenderersCustomPass.ShaderPass)EditorGUI.EnumPopup(rect, Styles.shaderPass, (DrawRenderersCustomPass.ShaderPass)m_ShaderPass.intValue);
EditorGUI.EndProperty();
}
EditorGUI.indentLevel--;

rect.y += Styles.defaultLineSpace;
if (customDepthIsNone)
{
using (new EditorGUI.DisabledScope(true))
EditorGUI.Toggle(rect, Styles.overrideDepth, false);
}
else
EditorGUI.BeginProperty(rect, Styles.overrideDepth, m_OverrideDepthState);
{
m_OverrideDepthState.boolValue = EditorGUI.Toggle(rect, Styles.overrideDepth, m_OverrideDepthState.boolValue);
if (customDepthIsNone)
{
using (new EditorGUI.DisabledScope(true))
EditorGUI.Toggle(rect, Styles.overrideDepth, false);
}
else
{
EditorGUI.PropertyField(rect, m_OverrideDepthState, Styles.overrideDepth);
}
}
EditorGUI.EndProperty();

if (m_OverrideDepthState.boolValue && !customDepthIsNone)
{
EditorGUI.indentLevel++;
rect.y += Styles.defaultLineSpace;
m_DepthCompareFunction.intValue = (int)(CompareFunction)EditorGUI.EnumPopup(rect, Styles.depthCompareFunction, (CompareFunction)m_DepthCompareFunction.intValue);
EditorGUI.PropertyField(rect, m_DepthCompareFunction, Styles.depthCompareFunction);
rect.y += Styles.defaultLineSpace;
m_DepthWrite.boolValue = EditorGUI.Toggle(rect, Styles.depthWrite, m_DepthWrite.boolValue);
EditorGUI.PropertyField(rect, m_DepthWrite, Styles.depthWrite);
EditorGUI.indentLevel--;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,21 @@ protected override void DoPassGUI(SerializedProperty customPass, Rect rect)
rect.y += Styles.defaultLineSpace;
}

// TODO: remove all this code when the fix for SerializedReference lands
m_FullScreenPassMaterial.objectReferenceValue = EditorGUI.ObjectField(rect, Styles.fullScreenPassMaterial, m_FullScreenPassMaterial.objectReferenceValue, typeof(Material), false);
// EditorGUI.PropertyField(rect, m_FullScreenPassMaterial, Styles.fullScreenPassMaterial);
EditorGUI.PropertyField(rect, m_FullScreenPassMaterial, Styles.fullScreenPassMaterial);
rect.y += Styles.defaultLineSpace;
if (m_FullScreenPassMaterial.objectReferenceValue is Material mat)
{
using (new EditorGUI.IndentLevelScope())
{
EditorGUI.BeginChangeCheck();
int index = mat.FindPass(m_MaterialPassName.stringValue);
index = EditorGUI.IntPopup(rect, Styles.materialPassName, index, GetMaterialPassNames(mat), Enumerable.Range(0, mat.passCount).ToArray());
if (EditorGUI.EndChangeCheck())
m_MaterialPassName.stringValue = mat.GetPassName(index);
EditorGUI.BeginProperty(rect, Styles.materialPassName, m_MaterialPassName);
{
EditorGUI.BeginChangeCheck();
int index = mat.FindPass(m_MaterialPassName.stringValue);
index = EditorGUI.IntPopup(rect, Styles.materialPassName, index, GetMaterialPassNames(mat), Enumerable.Range(0, mat.passCount).ToArray());
if (EditorGUI.EndChangeCheck())
m_MaterialPassName.stringValue = mat.GetPassName(index);
}
EditorGUI.EndProperty();
}
}
}
Expand Down