Skip to content

Commit 6610ad2

Browse files
alelievrsebastienlagarde
authored andcommitted
Fix custom pass prefabs #419
1 parent e433ac2 commit 6610ad2

File tree

5 files changed

+98
-60
lines changed

5 files changed

+98
-60
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4747
- Fix conflicts with Handles manipulation when performing a Reset in DecalComponent (case 1238833)
4848
- Fix error when removing DecalProjector from component contextual menu (case 1243960)
4949
- Fixed issue when switching back to custom sensor type in physical camera settings (case 1244350).
50+
- Fixed the prefab integration of custom passes (Prefab Override Highlight not working as expected).
5051

5152
### Changed
5253
- Shadowmask and realtime reflection probe property are hide in Quality settings

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/CustomPass/CustomPassDrawer.cs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -158,36 +158,33 @@ void DoCommonSettingsGUI(ref Rect rect)
158158
rect.y += Styles.defaultLineSpace;
159159
}
160160

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

168171
if ((commonPassUIFlags & PassUIFlag.TargetDepthBuffer) != 0)
169172
{
170-
m_TargetDepthBuffer.intValue = (int)(CustomPass.TargetBuffer)EditorGUI.EnumPopup(rect, Styles.targetDepthBuffer, (CustomPass.TargetBuffer)m_TargetDepthBuffer.intValue);
173+
EditorGUI.BeginProperty(rect, Styles.targetColorBuffer, m_TargetDepthBuffer);
174+
// EditorGUI.PropertyField(rect, m_TargetDepthBuffer, Styles.targetDepthBuffer);
175+
m_TargetDepthBuffer.intValue = (int)(CustomPass.TargetBuffer)EditorGUI.EnumPopup(rect, Styles.targetDepthBuffer, (CustomPass.TargetBuffer)m_TargetDepthBuffer.intValue);
176+
EditorGUI.EndProperty();
171177
rect.y += Styles.defaultLineSpace;
172178
}
173179

174180
if ((commonPassUIFlags & PassUIFlag.ClearFlags) != 0)
175181
{
176-
m_ClearFlags.intValue = (int)(ClearFlag)EditorGUI.EnumPopup(rect, Styles.clearFlags, (ClearFlag)m_ClearFlags.intValue);
182+
EditorGUI.BeginProperty(rect, Styles.clearFlags, m_ClearFlags);
183+
// EditorGUI.PropertyField(rect, m_ClearFlags, Styles.clearFlags);
184+
m_ClearFlags.intValue = (int)(ClearFlag)EditorGUI.EnumPopup(rect, Styles.clearFlags, (ClearFlag)m_ClearFlags.intValue);
185+
EditorGUI.EndProperty();
177186
rect.y += Styles.defaultLineSpace;
178187
}
179-
180-
#else // TODO: remove all this code when the fix for SerializedReference lands
181-
182-
EditorGUI.PropertyField(rect, m_TargetColorBuffer, Styles.targetColorBuffer);
183-
rect.y += Styles.defaultLineSpace;
184-
185-
EditorGUI.PropertyField(rect, m_TargetDepthBuffer, Styles.targetDepthBuffer);
186-
rect.y += Styles.defaultLineSpace;
187-
188-
EditorGUI.PropertyField(rect, m_ClearFlags, Styles.clearFlags);
189-
rect.y += Styles.defaultLineSpace;
190-
#endif
191188
}
192189

193190
/// <summary>
@@ -216,10 +213,18 @@ void DoHeaderGUI(ref Rect rect)
216213
enabledRect.x = rect.xMax - enabledSize.x;
217214
enabledRect.width = enabledSize.x;
218215

219-
m_PassFoldout.boolValue = EditorGUI.Foldout(headerRect, m_PassFoldout.boolValue, $"{m_Name.stringValue} ({m_PassType.Name})", true, EditorStyles.boldLabel);
220-
EditorGUIUtility.labelWidth = enabledRect.width - 14;
221-
m_Enabled.boolValue = EditorGUI.Toggle(enabledRect, Styles.enabled, m_Enabled.boolValue);
222-
EditorGUIUtility.labelWidth = 0;
216+
EditorGUI.BeginProperty(headerRect, GUIContent.none, m_PassFoldout);
217+
{
218+
m_PassFoldout.boolValue = EditorGUI.Foldout(headerRect, m_PassFoldout.boolValue, $"{m_Name.stringValue} ({m_PassType.Name})", true, EditorStyles.boldLabel);
219+
}
220+
EditorGUI.EndProperty();
221+
EditorGUI.BeginProperty(enabledRect, Styles.enabled, m_Enabled);
222+
{
223+
EditorGUIUtility.labelWidth = enabledRect.width - 14;
224+
m_Enabled.boolValue = EditorGUI.Toggle(enabledRect, Styles.enabled, m_Enabled.boolValue);
225+
EditorGUIUtility.labelWidth = 0;
226+
}
227+
EditorGUI.EndProperty();
223228
}
224229

225230
/// <summary>

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/CustomPass/CustomPassVolumeEditor.cs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public override void OnInspectorGUI()
7171
}
7272

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

7676
void UpdateMaterialEditors()
7777
{
@@ -113,6 +113,9 @@ CustomPassDrawer GetCustomPassDrawer(SerializedProperty pass, int listIndex)
113113

114114
var customPass = m_Volume.customPasses[listIndex];
115115

116+
if (customPass == null)
117+
return null;
118+
116119
foreach (var drawerType in TypeCache.GetTypesWithAttribute(typeof(CustomPassDrawerAttribute)))
117120
{
118121
var attr = drawerType.GetCustomAttributes(typeof(CustomPassDrawerAttribute), true)[0] as CustomPassDrawerAttribute;
@@ -140,7 +143,12 @@ void DrawSettingsGUI()
140143

141144
EditorGUI.BeginChangeCheck();
142145
{
143-
m_SerializedPassVolume.isGlobal.boolValue = EditorGUILayout.Popup(Styles.isGlobal, m_SerializedPassVolume.isGlobal.boolValue ? 0 : 1, Styles.modes) == 0;
146+
Rect isGlobalRect = EditorGUILayout.GetControlRect();
147+
EditorGUI.BeginProperty(isGlobalRect, Styles.isGlobal, m_SerializedPassVolume.isGlobal);
148+
{
149+
m_SerializedPassVolume.isGlobal.boolValue = EditorGUI.Popup(isGlobalRect, Styles.isGlobal, m_SerializedPassVolume.isGlobal.boolValue ? 0 : 1, Styles.modes) == 0;
150+
}
151+
EditorGUI.EndProperty();
144152
EditorGUILayout.PropertyField(m_SerializedPassVolume.injectionPoint, Styles.injectionPoint);
145153
EditorGUILayout.PropertyField(m_SerializedPassVolume.priority, Styles.priority);
146154
if (!m_SerializedPassVolume.isGlobal.boolValue)
@@ -163,9 +171,15 @@ void DrawCustomPassReorderableList()
163171
}
164172
}
165173

166-
EditorGUILayout.BeginVertical();
167-
m_CustomPassList.DoLayoutList();
168-
EditorGUILayout.EndVertical();
174+
float customPassListHeight = m_CustomPassList.GetHeight();
175+
var customPassRect = EditorGUILayout.GetControlRect(false, customPassListHeight);
176+
EditorGUI.BeginProperty(customPassRect, GUIContent.none, m_SerializedPassVolume.customPasses);
177+
{
178+
EditorGUILayout.BeginVertical();
179+
m_CustomPassList.DoList(customPassRect);
180+
EditorGUILayout.EndVertical();
181+
}
182+
EditorGUI.EndProperty();
169183
}
170184

171185
void CreateReorderableList(SerializedProperty passList)
@@ -200,28 +214,34 @@ void CreateReorderableList(SerializedProperty passList)
200214
};
201215

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

205219
var menu = new GenericMenu();
206220
foreach (var customPassType in TypeCache.GetTypesDerivedFrom<CustomPass>())
207221
{
208222
if (customPassType.IsAbstract)
209223
continue;
210-
224+
211225
menu.AddItem(new GUIContent(customPassType.Name), false, () => {
212-
m_Volume.AddPassOfType(customPassType);
213226
passList.serializedObject.Update();
227+
m_Volume.AddPassOfType(customPassType);
214228
UpdateMaterialEditors();
215-
});
229+
passList.serializedObject.ApplyModifiedProperties();
230+
// Notify the prefab that something have changed:
231+
PrefabUtility.RecordPrefabInstancePropertyModifications(target);
232+
});
216233
}
217234
menu.ShowAsContext();
218235
};
219236

220237
m_CustomPassList.onRemoveCallback = (list) => {
238+
passList.serializedObject.Update();
221239
Undo.RegisterCompleteObjectUndo(target, "Remove custom pass");
222240
m_Volume.customPasses.RemoveAt(list.index);
223-
passList.serializedObject.Update();
224241
UpdateMaterialEditors();
242+
passList.serializedObject.ApplyModifiedProperties();
243+
// Notify the prefab that something have changed:
244+
PrefabUtility.RecordPrefabInstancePropertyModifications(target);
225245
};
226246
}
227247

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/CustomPass/DrawRenderersCustomPassDrawer.cs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ protected override void DoPassGUI(SerializedProperty customPass, Rect rect)
161161
#endif
162162

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

168167
EditorGUI.indentLevel--;
@@ -205,10 +204,11 @@ void DoFilters(ref Rect rect)
205204
if (m_FilterFoldout.boolValue)
206205
{
207206
EditorGUI.indentLevel++;
208-
//Render queue filter
207+
EditorGUI.BeginProperty(rect, Styles.renderQueueFilter, m_RenderQueue);
208+
// There is still a bug with SerializedReference and PropertyField so we can't use it yet
209209
// EditorGUI.PropertyField(rect, m_RenderQueue, Styles.renderQueueFilter);
210-
// TODO: remove all this code when the fix for SerializedReference lands
211210
m_RenderQueue.intValue = (int)(CustomPass.RenderQueueType)EditorGUI.EnumPopup(rect, Styles.renderQueueFilter, (CustomPass.RenderQueueType)m_RenderQueue.intValue);
211+
EditorGUI.EndProperty();
212212
rect.y += Styles.defaultLineSpace;
213213
if (ShowOpaqueObjectWarning())
214214
{
@@ -229,9 +229,7 @@ void DoMaterialOverride(ref Rect rect)
229229
{
230230
//Override material
231231
EditorGUI.BeginChangeCheck();
232-
// TODO: remove all this code when the fix for SerializedReference lands
233-
m_OverrideMaterial.objectReferenceValue = EditorGUI.ObjectField(rect, Styles.overrideMaterial, m_OverrideMaterial.objectReferenceValue, typeof(Material), false);
234-
// EditorGUI.PropertyField(rect, m_OverrideMaterial, Styles.overrideMaterial);
232+
EditorGUI.PropertyField(rect, m_OverrideMaterial, Styles.overrideMaterial);
235233
if (EditorGUI.EndChangeCheck())
236234
{
237235
var mat = m_OverrideMaterial.objectReferenceValue as Material;
@@ -244,37 +242,49 @@ void DoMaterialOverride(ref Rect rect)
244242
EditorGUI.indentLevel++;
245243
if (m_OverrideMaterial.objectReferenceValue)
246244
{
247-
var mat = m_OverrideMaterial.objectReferenceValue as Material;
248-
EditorGUI.BeginChangeCheck();
249-
int index = mat.FindPass(m_OverrideMaterialPassName.stringValue);
250-
index = EditorGUI.IntPopup(rect, Styles.overrideMaterialPass, index, GetMaterialPassNames(mat), Enumerable.Range(0, mat.passCount).ToArray());
251-
if (EditorGUI.EndChangeCheck())
252-
m_OverrideMaterialPassName.stringValue = mat.GetPassName(index);
245+
EditorGUI.BeginProperty(rect, Styles.overrideMaterialPass, m_OverrideMaterialPassName);
246+
{
247+
var mat = m_OverrideMaterial.objectReferenceValue as Material;
248+
EditorGUI.BeginChangeCheck();
249+
int index = mat.FindPass(m_OverrideMaterialPassName.stringValue);
250+
index = EditorGUI.IntPopup(rect, Styles.overrideMaterialPass, index, GetMaterialPassNames(mat), Enumerable.Range(0, mat.passCount).ToArray());
251+
if (EditorGUI.EndChangeCheck())
252+
m_OverrideMaterialPassName.stringValue = mat.GetPassName(index);
253+
}
254+
EditorGUI.EndProperty();
253255
}
254256
else
255257
{
258+
EditorGUI.BeginProperty(rect, Styles.renderQueueFilter, m_RenderQueue);
259+
// There is still a bug with SerializedReference and PropertyField so we can't use it yet
260+
// EditorGUI.PropertyField(rect, m_ShaderPass, Styles.shaderPass);
256261
m_ShaderPass.intValue = (int)(DrawRenderersCustomPass.ShaderPass)EditorGUI.EnumPopup(rect, Styles.shaderPass, (DrawRenderersCustomPass.ShaderPass)m_ShaderPass.intValue);
262+
EditorGUI.EndProperty();
257263
}
258264
EditorGUI.indentLevel--;
259265

260266
rect.y += Styles.defaultLineSpace;
261-
if (customDepthIsNone)
262-
{
263-
using (new EditorGUI.DisabledScope(true))
264-
EditorGUI.Toggle(rect, Styles.overrideDepth, false);
265-
}
266-
else
267+
EditorGUI.BeginProperty(rect, Styles.overrideDepth, m_OverrideDepthState);
267268
{
268-
m_OverrideDepthState.boolValue = EditorGUI.Toggle(rect, Styles.overrideDepth, m_OverrideDepthState.boolValue);
269+
if (customDepthIsNone)
270+
{
271+
using (new EditorGUI.DisabledScope(true))
272+
EditorGUI.Toggle(rect, Styles.overrideDepth, false);
273+
}
274+
else
275+
{
276+
EditorGUI.PropertyField(rect, m_OverrideDepthState, Styles.overrideDepth);
277+
}
269278
}
279+
EditorGUI.EndProperty();
270280

271281
if (m_OverrideDepthState.boolValue && !customDepthIsNone)
272282
{
273283
EditorGUI.indentLevel++;
274284
rect.y += Styles.defaultLineSpace;
275-
m_DepthCompareFunction.intValue = (int)(CompareFunction)EditorGUI.EnumPopup(rect, Styles.depthCompareFunction, (CompareFunction)m_DepthCompareFunction.intValue);
285+
EditorGUI.PropertyField(rect, m_DepthCompareFunction, Styles.depthCompareFunction);
276286
rect.y += Styles.defaultLineSpace;
277-
m_DepthWrite.boolValue = EditorGUI.Toggle(rect, Styles.depthWrite, m_DepthWrite.boolValue);
287+
EditorGUI.PropertyField(rect, m_DepthWrite, Styles.depthWrite);
278288
EditorGUI.indentLevel--;
279289
}
280290
}

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/CustomPass/FullScreenCustomPassDrawer.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,21 @@ protected override void DoPassGUI(SerializedProperty customPass, Rect rect)
5454
rect.y += Styles.defaultLineSpace;
5555
}
5656

57-
// TODO: remove all this code when the fix for SerializedReference lands
58-
m_FullScreenPassMaterial.objectReferenceValue = EditorGUI.ObjectField(rect, Styles.fullScreenPassMaterial, m_FullScreenPassMaterial.objectReferenceValue, typeof(Material), false);
59-
// EditorGUI.PropertyField(rect, m_FullScreenPassMaterial, Styles.fullScreenPassMaterial);
57+
EditorGUI.PropertyField(rect, m_FullScreenPassMaterial, Styles.fullScreenPassMaterial);
6058
rect.y += Styles.defaultLineSpace;
6159
if (m_FullScreenPassMaterial.objectReferenceValue is Material mat)
6260
{
6361
using (new EditorGUI.IndentLevelScope())
6462
{
65-
EditorGUI.BeginChangeCheck();
66-
int index = mat.FindPass(m_MaterialPassName.stringValue);
67-
index = EditorGUI.IntPopup(rect, Styles.materialPassName, index, GetMaterialPassNames(mat), Enumerable.Range(0, mat.passCount).ToArray());
68-
if (EditorGUI.EndChangeCheck())
69-
m_MaterialPassName.stringValue = mat.GetPassName(index);
63+
EditorGUI.BeginProperty(rect, Styles.materialPassName, m_MaterialPassName);
64+
{
65+
EditorGUI.BeginChangeCheck();
66+
int index = mat.FindPass(m_MaterialPassName.stringValue);
67+
index = EditorGUI.IntPopup(rect, Styles.materialPassName, index, GetMaterialPassNames(mat), Enumerable.Range(0, mat.passCount).ToArray());
68+
if (EditorGUI.EndChangeCheck())
69+
m_MaterialPassName.stringValue = mat.GetPassName(index);
70+
}
71+
EditorGUI.EndProperty();
7072
}
7173
}
7274
}

0 commit comments

Comments
 (0)