Skip to content

Add VolumeComponentArchetype to handle VolumeStack specifically #6025

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

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
04f33e1
WIP SupportedOnAttribute
fredericv-unity3d Oct 8, 2021
1f39ef4
Improvement of type relation API
fredericv-unity3d Oct 8, 2021
e669fe1
Updated attribute SupportedOn
fredericv-unity3d Oct 11, 2021
e1afe89
Updated format
fredericv-unity3d Oct 11, 2021
972c427
Remove the subject argument
fredericv-unity3d Oct 12, 2021
ab2bb36
Filter based on supported components
fredericv-unity3d Oct 18, 2021
786ae3f
Adding new framework classes for volume components
fredericv-unity3d Oct 19, 2021
76dc11a
WIP Use the SupportedOn attribute to filter volumes
fredericv-unity3d Oct 19, 2021
b99d1e4
WIP updating stack with archetypes
fredericv-unity3d Oct 19, 2021
b86ba09
WIP using customized volume stacks
fredericv-unity3d Oct 19, 2021
453631d
WIP specialized volume stacks
fredericv-unity3d Oct 19, 2021
55ea29d
Fixed invalid call to volume stacks
fredericv-unity3d Oct 20, 2021
d762023
Updated all APIs
fredericv-unity3d Oct 20, 2021
4d5ebdd
Refactored files
fredericv-unity3d Oct 20, 2021
efd7908
Added API to update the displayed archetypes
fredericv-unity3d Oct 21, 2021
9c13773
Added FsCheck and tests
fredericv-unity3d Oct 25, 2021
f8f2b5e
Updated tests for volumes
fredericv-unity3d Oct 25, 2021
e52ddc4
Added tests
fredericv-unity3d Oct 27, 2021
6ccba7b
Updated test for volume framework
fredericv-unity3d Nov 9, 2021
b17322d
Updated test coverage for volume framework
fredericv-unity3d Nov 9, 2021
725ef8f
Update tests of volume framework
fredericv-unity3d Nov 10, 2021
b226ed5
Added a comment
fredericv-unity3d Nov 12, 2021
6a3173b
Update tests
fredericv-unity3d Dec 14, 2021
f6b8f85
Update test coverage
fredericv-unity3d Dec 14, 2021
8efc51b
Update test coverage
fredericv-unity3d Dec 14, 2021
2d88838
Update test coverage
fredericv-unity3d Dec 14, 2021
340045f
Update test coverage
fredericv-unity3d Dec 15, 2021
fb2c913
Update test coverage
fredericv-unity3d Dec 15, 2021
97079c5
Update test coverage
fredericv-unity3d Dec 16, 2021
4a5dc8b
Merge branch 'master' into rpw/supported-on
fredericv-unity3d Jan 31, 2022
2caaf97
Fixed default state for volume
fredericv-unity3d Jan 31, 2022
f1b80a2
Fixed path and type
fredericv-unity3d Jan 31, 2022
b6c5e7e
Added FsCheck consistent runs
fredericv-unity3d Jan 31, 2022
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
3 changes: 3 additions & 0 deletions com.unity.render-pipelines.core/Editor/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Unity.RenderPipelines.Core.Editor.Tests")]
3 changes: 3 additions & 0 deletions com.unity.render-pipelines.core/Editor/AssemblyInfo.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using UnityEngine.Rendering;

namespace UnityEditor.Rendering
{
/// <summary>
/// A context for volume components
/// </summary>
// Do not expose, context is a workaround to a bad UX, VolumeProfile should only accept a specific archetype
class VolumeComponentContext
{
// what archetype to use when displaying an Add Volume Override menu
[NotNull]
[ExcludeFromCodeCoverage] // trivial
public VolumeComponentArchetype contextualArchetype { get; private set; } = VolumeComponentArchetype.Empty;

HashSet<VolumeComponentArchetype> s_Includes = new HashSet<VolumeComponentArchetype>();
HashSet<VolumeComponentArchetype> s_Excludes = new HashSet<VolumeComponentArchetype>();

[ExcludeFromCodeCoverage] // trivial
public VolumeComponentContext()
{
AddExcludeArchetype(VolumeComponentArchetype.FromFilterCached(IsVisibleVolumeComponentFilter.FromIsVisible(false)));
}

[ExcludeFromCodeCoverage] // trivial wraps of `VolumeComponentArchetype.FromIncludeExclude`
public void AddIncludeArchetype([DisallowNull] VolumeComponentArchetype archetype)
{
s_Includes.Add(archetype);
contextualArchetype = VolumeComponentArchetype.FromIncludeExclude(s_Includes, s_Excludes);
}

[ExcludeFromCodeCoverage] // trivial wraps of `VolumeComponentArchetype.FromIncludeExclude`
public void RemoveIncludeArchetype([DisallowNull] VolumeComponentArchetype archetype)
{
s_Includes.Remove(archetype);
contextualArchetype = VolumeComponentArchetype.FromIncludeExclude(s_Includes, s_Excludes);
}

[ExcludeFromCodeCoverage] // trivial wraps of `VolumeComponentArchetype.FromIncludeExclude`
public void AddExcludeArchetype([DisallowNull] VolumeComponentArchetype archetype)
{
s_Excludes.Add(archetype);
contextualArchetype = VolumeComponentArchetype.FromIncludeExclude(s_Includes, s_Excludes);
}

[ExcludeFromCodeCoverage] // trivial wraps of `VolumeComponentArchetype.FromIncludeExclude`
public void RemoveExcludeArchetype([DisallowNull] VolumeComponentArchetype archetype)
{
s_Excludes.Remove(archetype);
contextualArchetype = VolumeComponentArchetype.FromIncludeExclude(s_Includes, s_Excludes);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,9 @@ public virtual GUIContent GetDisplayTitle()
{
var targetType = target.GetType();
string title = string.IsNullOrEmpty(volumeComponent.displayName) ? ObjectNames.NicifyVariableName(volumeComponent.GetType().Name) : volumeComponent.displayName;
string tooltip = targetType.GetCustomAttribute(typeof(VolumeComponentMenuForRenderPipeline), false) is VolumeComponentMenuForRenderPipeline supportedOn
? string.Join(", ", supportedOn.pipelineTypes.Select(t => ObjectNames.NicifyVariableName(t.Name)))
var supportedTypes = targetType.GetCustomAttributes<SupportedOnAttribute>().Select(attr => ObjectNames.NicifyVariableName(attr.target.Name)).ToArray();
string tooltip = supportedTypes.Length > 0
? string.Join(", ", supportedTypes)
: string.Empty;
return EditorGUIUtility.TrTextContent(title, tooltip);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void OnGUI()
{
var r = hscope.rect;
var pos = new Vector2(r.x + r.width / 2f, r.yMax + 18f);
FilterWindow.Show(pos, new VolumeComponentProvider(asset, this));
FilterWindow.Show(pos, new VolumeComponentTreeProvider(asset, this, null));
}
}
}
Expand Down Expand Up @@ -282,7 +282,7 @@ void OnContextClick(Vector2 position, VolumeComponentEditor targetEditor, int id
menu.AddItem(EditorGUIUtility.TrTextContent("Collapse All"), false, () => CollapseComponents());
menu.AddItem(EditorGUIUtility.TrTextContent("Expand All"), false, () => ExpandComponents());
menu.AddSeparator(string.Empty);
menu.AddItem(EditorGUIUtility.TrTextContent("Reset"), false, () => ResetComponent(targetComponent.GetType(), id));
menu.AddItem(EditorGUIUtility.TrTextContent("Reset"), false, () => ResetComponent(VolumeComponentType.FromTypeUnsafe(targetComponent.GetType()), id));
menu.AddItem(EditorGUIUtility.TrTextContent("Remove"), false, () => RemoveComponent(id));
menu.AddSeparator(string.Empty);
if (targetEditor.hasAdditionalProperties)
Expand All @@ -306,15 +306,15 @@ void OnContextClick(Vector2 position, VolumeComponentEditor targetEditor, int id
menu.DropDown(new Rect(position, Vector2.zero));
}

VolumeComponent CreateNewComponent(Type type)
static VolumeComponent CreateNewComponent(VolumeComponentType type)
{
var effect = (VolumeComponent)ScriptableObject.CreateInstance(type);
var effect = (VolumeComponent)ScriptableObject.CreateInstance(type.AsType());
effect.hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy;
effect.name = type.Name;
effect.name = type.AsType().Name;
return effect;
}

internal void AddComponent(Type type)
internal void AddComponent(VolumeComponentType type)
{
m_SerializedObject.Update();

Expand Down Expand Up @@ -388,7 +388,7 @@ internal void RemoveComponent(int id)

// Reset is done by deleting and removing the object from the list and adding a new one in
// the same spot as it was before
internal void ResetComponent(Type type, int id)
internal void ResetComponent(VolumeComponentType type, int id)
{
// Remove from the cached editors list
m_Editors[id].OnDisable();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

namespace UnityEditor.Rendering
{
using IProvider = FilterWindow.IProvider;
using Element = FilterWindow.Element;
using GroupElement = FilterWindow.GroupElement;

/// <summary>
/// Build a tree for the add volume override menu.
///
/// Don't show a volume if it is already in the stack
/// </summary>
class VolumeComponentTreeProvider : IProvider
{
internal class VolumeComponentElement : Element
{
public VolumeComponentType type;

public VolumeComponentElement(int level, string label, VolumeComponentType type)
{
this.level = level;
this.type = type;
// TODO: Add support for custom icons
content = new GUIContent(label);
}
}

[ExcludeFromCodeCoverage] // trivial
public Vector2 position { get; set; }

VolumeProfile m_Target;
VolumeComponentListEditor m_TargetEditor;
readonly VolumeComponentArchetype m_ArchetypeOverride;

/// <summary>
///
/// </summary>
/// <param name="target"></param>
/// <param name="targetEditor"></param>
/// <param name="archetypeOverride">
/// Use this value to override which archetype to use to create the tree.
/// By default it will use the <see cref="VolumeComponentUserExperience.displayedArchetype"/>
/// </param>
public VolumeComponentTreeProvider(
[DisallowNull] VolumeProfile target,
[DisallowNull] VolumeComponentListEditor targetEditor,
[AllowNull] VolumeComponentArchetype archetypeOverride)
{
m_Target = target;
m_TargetEditor = targetEditor;
m_ArchetypeOverride = archetypeOverride;
}

public void CreateComponentTree([DisallowNull] List<Element> tree)
{
tree.Add(new GroupElement(0, "Volume Overrides"));

var archetype = m_ArchetypeOverride ?? VolumeComponentUserExperience.displayedArchetype;
if (!archetype.GetOrAddTreeProvider(out var extension))
return;

// Recursively add all elements to the tree
Traverse(extension.root, 1, tree);
}

public bool GoToChild([DisallowNull] Element element, bool addIfComponent)
{
if (element is VolumeComponentElement volumeComponentElement)
{
m_TargetEditor.AddComponent(volumeComponentElement.type);
return true;
}

return false;
}

void Traverse(
[DisallowNull] VolumeComponentArchetypeTreeProvider.PathNode node,
int depth,
[DisallowNull] List<Element> tree
)
{
node.nodes.Sort();

foreach (var n in node.nodes)
{
if (n.nodes.Count > 0) // Group
{
tree.Add(new GroupElement(depth, n.name));
Traverse(n, depth + 1, tree);
}
else if (!m_Target.Has(n.type.AsType())) // Element
{
tree.Add(new VolumeComponentElement(depth, n.name, n.type));
}
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading