Skip to content

Commit

Permalink
UX pass on APV settings window (#7158)
Browse files Browse the repository at this point in the history
* rename and UX

* Fix mispelling in file name

* review

* forgot the hdrp asset options

* update tests & improve foldouts
  • Loading branch information
adrien-de-tocqueville authored Feb 18, 2022
1 parent c29748e commit c60de46
Show file tree
Hide file tree
Showing 19 changed files with 424 additions and 311 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ MonoBehaviour:
outOfGeoOffset: 0.01
searchMultiplier: 0.2
profile: {fileID: 11400000, guid: c5b7fcbfc6aa87e458cb1c1893973b7c, type: 2}
lightingScenarios:
- Default
- name: Test
sceneGUIDs:
- 5028fc98db6fe304c90852113dca5b00
Expand All @@ -163,4 +165,6 @@ MonoBehaviour:
outOfGeoOffset: 0.01
searchMultiplier: 0.2
profile: {fileID: 11400000, guid: c70ba2f8270ecc54fa63963d2f32413d, type: 2}
lightingScenarios:
- Default
m_Version: 3
10 changes: 5 additions & 5 deletions TestProjects/HDRP_RuntimeTests/Assets/Scenes/007-BasicAPV.unity
Original file line number Diff line number Diff line change
Expand Up @@ -2077,7 +2077,7 @@ Transform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1943135964
GameObject:
m_ObjectHideFlags: 1
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
Expand All @@ -2094,7 +2094,7 @@ GameObject:
m_IsActive: 1
--- !u!114 &1943135965
MonoBehaviour:
m_ObjectHideFlags: 1
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
Expand All @@ -2108,16 +2108,16 @@ MonoBehaviour:
cellSharedDataAsset: {fileID: 4900000, guid: 4262df70f9af54e479b53da2b0b6f384, type: 3}
cellSupportDataAsset: {fileID: 4900000, guid: acb4ae6ad947b73478110ec6f398e997,
type: 3}
serializedStates:
- state: Default
serializedScenarios:
- scenario: Default
data:
sceneHash: 1784705805
cellDataAsset: {fileID: 4900000, guid: 33ad5211599350941aaefb40a027a52f, type: 3}
cellOptionalDataAsset: {fileID: 4900000, guid: 777185668354240419006bd3f247492e,
type: 3}
--- !u!4 &1943135966
Transform:
m_ObjectHideFlags: 1
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1151,8 +1151,8 @@ MonoBehaviour:
asset: {fileID: 0}
cellSharedDataAsset: {fileID: 0}
cellSupportDataAsset: {fileID: 0}
serializedStates:
- state: Default
serializedScenarios:
- scenario: Default
data:
sceneHash: -739037272
cellDataAsset: {fileID: 0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ MonoBehaviour:
outOfGeoOffset: 0.01
searchMultiplier: 0.2
profile: {fileID: 11400000, guid: 503bf6d995e8a4043ba60c02a674d0d3, type: 2}
bakingStates:
lightingScenarios:
- Default
m_BakingState: Default
m_LightingScenario: Default
m_Version: 3
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public DataForDilation(ProbeReferenceVolume.Cell cell, float defaultThreshold)

for (int i = 0; i < probeCount; ++i)
{
dilatedProbes[i].FromSphericalHarmonicsShaderConstants(cell.shBands, cell.bakingState.shL0L1Data, cell.bakingState.shL2Data, i);
dilatedProbes[i].FromSphericalHarmonicsShaderConstants(cell.shBands, cell.bakingScenario.shL0L1Data, cell.bakingScenario.shL2Data, i);
needDilating[i] = s_CustomDilationThresh.ContainsKey(i) ?
(cell.GetValidity(i) > s_CustomDilationThresh[i] ? 1 : 0) : (cell.GetValidity(i) > defaultThreshold ? 1 : 0);
}
Expand All @@ -129,7 +129,7 @@ public void ExtractDilatedProbes()
int probeCount = cell.probePositions.Length;
for (int i = 0; i < probeCount; ++i)
{
dilatedProbes[i].ToSphericalHarmonicsShaderConstants(cell.shBands, cell.bakingState.shL0L1Data, cell.bakingState.shL2Data, i);
dilatedProbes[i].ToSphericalHarmonicsShaderConstants(cell.shBands, cell.bakingScenario.shL0L1Data, cell.bakingScenario.shL2Data, i);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,10 @@ internal static void RevertDilation()
{
if (dilationSettings.enableDilation && dilationSettings.dilationDistance > 0.0f && cell.validity[i] > dilationSettings.dilationValidityThreshold)
{
WriteToShaderCoeffsL0L1(ref blackProbe, cell.bakingState.shL0L1Data, i * ProbeVolumeAsset.kL0L1ScalarCoefficientsCount);
WriteToShaderCoeffsL0L1(ref blackProbe, cell.bakingScenario.shL0L1Data, i * ProbeVolumeAsset.kL0L1ScalarCoefficientsCount);

if (cell.shBands == ProbeVolumeSHBands.SphericalHarmonicsL2)
WriteToShaderCoeffsL2(ref blackProbe, cell.bakingState.shL2Data, i * ProbeVolumeAsset.kL2ScalarCoefficientsCount);
WriteToShaderCoeffsL2(ref blackProbe, cell.bakingScenario.shL2Data, i * ProbeVolumeAsset.kL2ScalarCoefficientsCount);
}
}
}
Expand Down Expand Up @@ -754,7 +754,7 @@ static void OnAdditionalProbesBakeCompleted()
if (ProbeReferenceVolume.instance.sceneData.SceneHasProbeVolumes(data.gameObject.scene))
{
data.asset = ProbeVolumeAsset.CreateAsset(data);
data.states.TryAdd(ProbeReferenceVolume.instance.bakingState, default);
data.scenarios.TryAdd(ProbeReferenceVolume.instance.lightingScenario, default);
scene2Data[data.gameObject.scene] = data;
}
}
Expand Down Expand Up @@ -831,7 +831,7 @@ static void OnAdditionalProbesBakeCompleted()
if (EditorWindow.HasOpenInstances<ProbeVolumeBakingWindow>())
{
var window = (ProbeVolumeBakingWindow)EditorWindow.GetWindow(typeof(ProbeVolumeBakingWindow));
window.UpdateBakingStatesStatuses(ProbeReferenceVolume.instance.bakingState);
window.UpdateScenariosStatuses(ProbeReferenceVolume.instance.lightingScenario);
}

// We are done with baking so we reset whether we need to bake only the active or not.
Expand Down Expand Up @@ -902,7 +902,7 @@ static BakingCell ConvertCellToBakingCell(ProbeReferenceVolume.Cell cell)
bc.sh = new SphericalHarmonicsL2[numberOfProbes];
for (int probe = 0; probe < numberOfProbes; ++probe)
{
ReadFullFromShaderCoeffsL0L1L2(ref bc.sh[probe], cell.bakingState.shL0L1Data, cell.bakingState.shL2Data, probe);
ReadFullFromShaderCoeffsL0L1L2(ref bc.sh[probe], cell.bakingScenario.shL0L1Data, cell.bakingScenario.shL2Data, probe);
}

return bc;
Expand Down Expand Up @@ -1161,7 +1161,7 @@ static void WriteBakingCells(ProbeVolumePerSceneData data, List<BakingCell> baki
AssetDatabase.ImportAsset(cellSharedDataFilename);
AssetDatabase.ImportAsset(cellSupportDataFilename);

data.states[ProbeReferenceVolume.instance.bakingState] = new ProbeVolumePerSceneData.PerStateData
data.scenarios[ProbeReferenceVolume.instance.lightingScenario] = new ProbeVolumePerSceneData.PerScenarioData
{
sceneHash = sceneStateHash,
cellDataAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(cellDataFilename),
Expand All @@ -1175,7 +1175,7 @@ static void WriteBakingCells(ProbeVolumePerSceneData data, List<BakingCell> baki
static void WritebackModifiedCellsData(ProbeVolumePerSceneData data)
{
var asset = data.asset;
var stateData = data.states[ProbeReferenceVolume.instance.bakingState];
var stateData = data.scenarios[ProbeReferenceVolume.instance.lightingScenario];
data.GetBlobFileNames(out var cellDataFilename, out var cellOptionalDataFilename, out var cellSharedDataFilename, out var cellSupportDataFilename);

unsafe
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using UnityEngine;
using UnityEngine.Rendering;

namespace UnityEditor.Rendering
{
[CanEditMultipleObjects]
[CustomEditor(typeof(ProbeReferenceVolumeProfile))]
internal class ProbeReferenceVolumeProfileEditor : Editor
{
SerializedProperty m_MinDistanceBetweenProbes;
SerializedProperty m_SimplificationLevels;
SerializedProperty m_MinRendererVolumeSize;
SerializedProperty m_RenderersLayerMask;
ProbeReferenceVolumeProfile profile => target as ProbeReferenceVolumeProfile;

static class Styles
{
// TODO: Better tooltip are needed here.
public static readonly GUIContent simplificationLevels = new GUIContent("Simplification levels", "Determine how many bricks are in a streamable unit. Each simplification step adds a brick level above the minimum one.");
public static readonly string simplificationLevelsHighWarning = "High simplification levels have a big memory overhead, they are not recommended except for testing purposes.";
public static readonly GUIContent minDistanceBetweenProbes = new GUIContent("Min Distance Between Probes", "The minimal distance between two probes in meters.");
public static readonly GUIContent indexDimensions = new GUIContent("Index Dimensions", "The dimensions of the index buffer.");
public static readonly GUIContent minRendererVolumeSize = new GUIContent("Min Renderer Volume Size", "Specifies the minimum bounding box volume of renderers to consider placing probes around.");
public static readonly GUIContent renderersLayerMask = new GUIContent("Layer Mask", "Specifies the layer mask for renderers when placing probes.");
public static readonly GUIContent rendererFilterSettings = new GUIContent("Renderers Filter Settings");
}

void OnEnable()
{
m_MinDistanceBetweenProbes = serializedObject.FindProperty(nameof(ProbeReferenceVolumeProfile.minDistanceBetweenProbes));
m_SimplificationLevels = serializedObject.FindProperty(nameof(ProbeReferenceVolumeProfile.simplificationLevels));
m_MinRendererVolumeSize = serializedObject.FindProperty(nameof(ProbeReferenceVolumeProfile.minRendererVolumeSize));
m_RenderersLayerMask = serializedObject.FindProperty(nameof(ProbeReferenceVolumeProfile.renderersLayerMask));
}

public override void OnInspectorGUI()
{
EditorGUI.BeginChangeCheck();
serializedObject.Update();

EditorGUILayout.PropertyField(m_SimplificationLevels, Styles.simplificationLevels);
if (m_SimplificationLevels.intValue == 5)
{
EditorGUILayout.HelpBox(Styles.simplificationLevelsHighWarning, MessageType.Warning);
}
EditorGUILayout.PropertyField(m_MinDistanceBetweenProbes, Styles.minDistanceBetweenProbes);
EditorGUILayout.HelpBox($"The distance between probes will fluctuate between: {profile.minDistanceBetweenProbes}m and {profile.cellSizeInMeters / 3.0f}m", MessageType.Info);

EditorGUILayout.Space();
if (ProbeVolumeBakingWindow.Foldout(Styles.rendererFilterSettings, ProbeVolumeBakingWindow.Expandable.RendererFilterSettings))
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_RenderersLayerMask, Styles.renderersLayerMask);
EditorGUILayout.PropertyField(m_MinRendererVolumeSize, Styles.minRendererVolumeSize);
EditorGUI.indentLevel--;
}

if (EditorGUI.EndChangeCheck())
serializedObject.ApplyModifiedProperties();
}
}
}

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
@@ -1,4 +1,5 @@
using UnityEditor;
using UnityEditor.Rendering;

namespace UnityEngine.Rendering
{
Expand All @@ -21,11 +22,13 @@ static class Styles

public static readonly GUIContent advanced = EditorGUIUtility.TrTextContent("Advanced");

public static readonly string dilationSettingsTitle = "Dilation Settings";
public static readonly string virtualOffsetSettingsTitle = "Virtual Offset Settings";
public static readonly GUIContent dilationSettingsTitle = EditorGUIUtility.TrTextContent("Dilation Settings");
public static readonly GUIContent virtualOffsetSettingsTitle = EditorGUIUtility.TrTextContent("Virtual Offset Settings");
}

bool m_VirtualOffsetShowAdvanced;
// PropertyDrawer are not made to use GUILayout, so it will try to reserve a rect before calling OnGUI
// Tell we have a height of 0 so it doesn't interfere with our usage of GUILayout
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) => 0;

// Draw the property inside the given rect
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
Expand All @@ -39,10 +42,13 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten

property.serializedObject.Update();

DrawDilationSettings(dilationSettings);
EditorGUILayout.Space();
EditorGUI.FloatField(position, 100f);

if (ProbeVolumeBakingWindow.Foldout(Styles.dilationSettingsTitle, ProbeVolumeBakingWindow.Expandable.Dilation))
DrawDilationSettings(dilationSettings);
EditorGUILayout.Space();
DrawVirtualOffsetSettings(virtualOffsetSettings);
if (ProbeVolumeBakingWindow.Foldout(Styles.virtualOffsetSettingsTitle, ProbeVolumeBakingWindow.Expandable.VirtualOffset))
DrawVirtualOffsetSettings(virtualOffsetSettings);
EditorGUI.EndProperty();

property.serializedObject.ApplyModifiedProperties();
Expand All @@ -57,7 +63,6 @@ void DrawDilationSettings(SerializedProperty dilationSettings)
var dilationIterations = dilationSettings.FindPropertyRelative("dilationIterations");
var dilationInvSquaredWeight = dilationSettings.FindPropertyRelative("squaredDistWeighting");

EditorGUILayout.LabelField(Styles.dilationSettingsTitle, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
enableDilation.boolValue = EditorGUILayout.Toggle(Styles.enableDilation, enableDilation.boolValue);
EditorGUI.BeginDisabledGroup(!enableDilation.boolValue);
Expand All @@ -66,8 +71,8 @@ void DrawDilationSettings(SerializedProperty dilationSettings)
dilationValidityThreshold.floatValue = Mathf.Max(0.05f, 1.0f - dilationValidityThresholdInverted);
dilationIterations.intValue = EditorGUILayout.IntSlider(Styles.dilationIterationCount, dilationIterations.intValue, 1, 5);
dilationInvSquaredWeight.boolValue = EditorGUILayout.Toggle(Styles.dilationSquaredDistanceWeighting, dilationInvSquaredWeight.boolValue);
EditorGUI.indentLevel--;
EditorGUI.EndDisabledGroup();
EditorGUI.indentLevel--;

if (Unsupported.IsDeveloperMode())
{
Expand All @@ -81,15 +86,14 @@ void DrawDilationSettings(SerializedProperty dilationSettings)

void DrawVirtualOffsetSettings(SerializedProperty virtualOffsetSettings)
{
EditorGUILayout.LabelField(Styles.virtualOffsetSettingsTitle, EditorStyles.boldLabel);
using (new EditorGUI.IndentLevelScope())
{
var enableVirtualOffset = virtualOffsetSettings.FindPropertyRelative("useVirtualOffset");
EditorGUILayout.PropertyField(enableVirtualOffset, Styles.useVirtualOffset);

using (new EditorGUI.DisabledScope(!enableVirtualOffset.boolValue))
{
if (m_VirtualOffsetShowAdvanced = EditorGUILayout.Foldout(m_VirtualOffsetShowAdvanced, Styles.advanced))
EditorGUILayout.LabelField(Styles.advanced);
{
using (new EditorGUI.IndentLevelScope())
{
Expand Down
Loading

0 comments on commit c60de46

Please sign in to comment.