Skip to content

Commit

Permalink
Merge pull request #7966 from Unity-Technologies/internal/master
Browse files Browse the repository at this point in the history
Internal/master
  • Loading branch information
UnityAljosha authored Sep 27, 2023
2 parents 55775fd + 64026fe commit 0153969
Show file tree
Hide file tree
Showing 1,438 changed files with 466,278 additions and 52,916 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections.Generic;
using UnityEngine;

namespace UnityEditor.Rendering
{
/// <summary> Set of helpers for AssetDatabase operations. </summary>
public static class AssetDatabaseHelper
{
/// <summary>
/// Finds all assets of type T in the project.
/// </summary>
/// <param name="extension">Asset type extension i.e ".mat" for materials</param>
/// <typeparam name="T">The type of material you are looking for</typeparam>
/// <returns></returns>
public static IEnumerable<T> FindAssets<T>(string extension = null)
{
string typeName = typeof(T).ToString();
int i = typeName.LastIndexOf('.');
if (i != -1)
{
typeName = typeName.Substring(i+1, typeName.Length - i-1);
}

string query = !string.IsNullOrEmpty(extension) ? $"t:{typeName} glob:\"**/*{extension}\"" : $"t:{typeName}";

foreach (var guid in AssetDatabase.FindAssets(query))
{
var asset = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(guid));
if (asset is T castAsset)
yield return castAsset;
}
}
}
}

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 @@ -40,7 +40,7 @@ public static bool TryGetRenderPipelineAssets<T>([DisallowNull] this BuildTarget
srpAssets.Add(srpAsset);
}

return true;
return srpAssets.Count != 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public static void DrawSplitter(Rect rect, bool isBoxed = false)

/// <summary>Draw a splitter separator which is used after drawing a fouldout header.</summary>
/// <param name="isBoxed">[Optional] add margin if the splitter is boxed</param>
internal static void DrawFoldoutEndSplitter(bool isBoxed = false)
public static void DrawFoldoutEndSplitter(bool isBoxed = false)
{
var rect = GUILayoutUtility.GetRect(1f, 1f);

Expand Down

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,33 @@
using System.IO;
using UnityEngine;
using UnityEngine.Rendering;

namespace UnityEditor.Rendering
{
internal class GPUResidentDrawerEditorUtils
{
class DoCreateNewAssetGPUResidentDrawerResources : ProjectWindowCallback.EndNameEditAction
{
public override void Action(int instanceId, string pathName, string resourceFile)
{
var newAsset = CreateInstance<GPUResidentDrawerResources>();
newAsset.name = Path.GetFileName(pathName);

ResourceReloader.ReloadAllNullIn(newAsset, "Packages/com.unity.render-pipelines.core/");

AssetDatabase.CreateAsset(newAsset, pathName);
ProjectWindowUtil.ShowCreatedAsset(newAsset);
}
}

// Hide: User aren't suppose to have to create it.
//[MenuItem("Assets/Create/Rendering/GPU Resident Drawer Resources", priority = CoreUtils.Sections.section7 + CoreUtils.Priorities.assetsCreateRenderingMenuPriority + 2)]
static void CreateGPUResidentDrawerResources()
{
var icon = EditorGUIUtility.FindTexture("ScriptableObject Icon");
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0,
ScriptableObject.CreateInstance<DoCreateNewAssetGPUResidentDrawerResources>(),
"New GPUResidentDrawerResources.asset", icon, null);
}
}
}

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 @@ -1095,12 +1095,10 @@ static public void ApplyPostBakeOperations(NativeArray<SphericalHarmonicsL2> sh,
s_CustomDilationThresh[(cell.index, i)] = thresh;
}

intensityScale = touchupVolume.intensityScale;

if (touchupVolume.mode == ProbeTouchupVolume.Mode.IntensityScale)
intensityScale = touchupVolume.intensityScale;
if (intensityScale != 1.0f)
{
cell.touchupVolumeInteraction[i] = 2.0f + intensityScale;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEditor;
using UnityEditor.Rendering;
using UnityEngine.Rendering;
using UnityEditorInternal;
using System;

using RuntimeSRPPreferences = UnityEngine.Rendering.CoreRenderPipelinePreferences;

namespace UnityEditor.Rendering
Expand Down Expand Up @@ -33,7 +34,11 @@ internal static class Styles
internal static readonly GUIContent s_VolumeHeader = EditorGUIUtility.TrTextContent("Influence Volume");
internal static readonly GUIContent s_TouchupHeader = EditorGUIUtility.TrTextContent("Probe Volume Overrides");

internal static readonly GUIContent s_Mode = new GUIContent("Mode", "Choose which type of adjustment to apply to probes covered by this volume.");
internal static readonly GUIContent s_DilationThreshold = new GUIContent("Dilation Validity Threshold", "Override the Dilation Validity Threshold for probes covered by this Probe Adjustment Volume. Higher values increase the chance of probes being considered invalid.");
internal static readonly GUIContent s_UpdateValidity = new GUIContent("Update Probe Validity", "Invalidate probes covered by this Probe Adjustment Volume.");
internal static readonly GUIContent s_VODirection = new GUIContent("Direction", "Rotate the axis along which probes will be pushed when applying Virtual Offset.");
internal static readonly GUIContent s_VODistance = new GUIContent("Distance", "Determines how far probes are pushed in the direction of the Virtual Offset.");

internal static readonly EditMode.SceneViewEditMode VirtualOffsetEditMode = (EditMode.SceneViewEditMode)110;

Expand All @@ -50,6 +55,15 @@ internal static class Styles
};
}

static internal bool Button(GUIContent content)
{
GUILayout.BeginHorizontal();
EditorGUILayout.Space(15 * EditorGUI.indentLevel, false);
bool value = GUILayout.Button(content, EditorStyles.miniButton);
GUILayout.EndHorizontal();
return value;
}

static class ProbeTouchupVolumeUI
{
public static readonly CED.IDrawer Inspector = null;
Expand Down Expand Up @@ -93,14 +107,41 @@ public static void DrawVolumeContent(SerializedProbeTouchupVolume serialized, Ed

}

static T[] RemoveAt<T>(T[] values, int index)
{
var list = new List<T>(values);
list.RemoveAt(index);
return list.ToArray();
}
static GUIContent[] CastArray(string[] values)
{
var result = new GUIContent[values.Length];
for (int i = 0; i < values.Length; i++)
result[i] = new GUIContent(ObjectNames.NicifyVariableName(values[i]));
return result;
}

public static void DrawTouchupContent(SerializedProbeTouchupVolume serialized, Editor owner)
{
ProbeTouchupVolume ptv = (serialized.serializedObject.targetObject as ProbeTouchupVolume);

var bakingSet = ProbeReferenceVolume.instance.sceneData.GetBakingSetForScene(ptv.gameObject.scene);
bool useVirtualOffset = bakingSet != null ? bakingSet.settings.virtualOffsetSettings.useVirtualOffset : false;

EditorGUILayout.PropertyField(serialized.mode);
var hiddenMode = (int)ProbeTouchupVolume.Mode.IntensityScale;
var availableValues = (int[])Enum.GetValues(typeof(ProbeTouchupVolume.Mode));
var availableModes = CastArray(Enum.GetNames(typeof(ProbeTouchupVolume.Mode)));
if (!k_AdditionalPropertiesState[AdditionalProperties.Touchup] && serialized.mode.intValue != hiddenMode)
{
int idx = Array.IndexOf(availableValues, hiddenMode);
availableValues = RemoveAt(availableValues, idx);
availableModes = RemoveAt(availableModes, idx);
}

EditorGUI.BeginChangeCheck();
int newValue = EditorGUILayout.IntPopup(Styles.s_Mode, serialized.mode.intValue, availableModes, availableValues);
if (EditorGUI.EndChangeCheck())
serialized.mode.intValue = newValue;

if (serialized.mode.intValue == (int)ProbeTouchupVolume.Mode.OverrideValidityThreshold)
{
Expand All @@ -111,7 +152,7 @@ public static void DrawTouchupContent(SerializedProbeTouchupVolume serialized, E
EditorGUI.BeginDisabledGroup(!useVirtualOffset);
EditorGUILayout.BeginHorizontal();

EditorGUILayout.PropertyField(serialized.virtualOffsetRotation);
EditorGUILayout.PropertyField(serialized.virtualOffsetRotation, Styles.s_VODirection);

var editMode = Styles.VirtualOffsetEditMode;
EditorGUI.BeginChangeCheck();
Expand All @@ -123,12 +164,15 @@ public static void DrawTouchupContent(SerializedProbeTouchupVolume serialized, E
}
EditorGUILayout.EndHorizontal();

EditorGUILayout.PropertyField(serialized.virtualOffsetDistance);
EditorGUILayout.PropertyField(serialized.virtualOffsetDistance, Styles.s_VODistance);
EditorGUI.EndDisabledGroup();

if (!useVirtualOffset)
{
EditorGUILayout.HelpBox("Apply Virtual Offset can be used only if Virtual Offset is enabled for the Baking Set.", MessageType.Warning);
CoreEditorUtils.DrawFixMeBox("Apply Virtual Offset can be used only if Virtual Offset is enabled for the Baking Set.", MessageType.Warning, "Open", () =>
{
ProbeVolumeLightingTab.OpenBakingSet(bakingSet);
});
}
}
else if (serialized.mode.intValue == (int)ProbeTouchupVolume.Mode.OverrideVirtualOffsetSettings)
Expand All @@ -146,11 +190,16 @@ public static void DrawTouchupContent(SerializedProbeTouchupVolume serialized, E
}
else if (serialized.mode.intValue == (int)ProbeTouchupVolume.Mode.InvalidateProbes)
{
if (GUILayout.Button(EditorGUIUtility.TrTextContent("Update Probe Validity", "Update the validity of probes falling within probe adjustment volumes."), EditorStyles.miniButton))
if (Button(Styles.s_UpdateValidity))
{
ProbeGIBaking.RecomputeValidityAfterBake();
}
}
else if (serialized.mode.intValue == (int)ProbeTouchupVolume.Mode.IntensityScale)
{
EditorGUILayout.HelpBox("Overriding the intensity of probes can break the physical plausibility of lighting. This may result in unwanted visual inconsistencies.", MessageType.Info, wide: true);
EditorGUILayout.PropertyField(serialized.intensityScale);
}
}

internal static Bounds GetBounds(SerializedProbeTouchupVolume serialized, Editor owner)
Expand All @@ -165,11 +214,6 @@ internal static Bounds GetBounds(SerializedProbeTouchupVolume serialized, Editor

public static void DrawTouchupAdditionalContent(SerializedProbeTouchupVolume serialized, Editor owner)
{
if (serialized.mode.intValue == (int)ProbeTouchupVolume.Mode.InvalidateProbes)
{
EditorGUILayout.HelpBox("Changing the intensity of probe data is a delicate operation that can lead to inconsistencies in the lighting, hence the feature is to be used sparingly.", MessageType.Info, wide: true);
EditorGUILayout.PropertyField(serialized.intensityScale);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ static class Styles

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

public static GUIStyle voButtonStyle = new GUIStyle(EditorStyles.miniButton);
}

// PropertyDrawer are not made to use GUILayout, so it will try to reserve a rect before calling OnGUI
Expand Down Expand Up @@ -71,14 +69,11 @@ void DrawDilationSettings(SerializedProperty dilationSettings)

if (Unsupported.IsDeveloperMode())
{
GUILayout.BeginHorizontal();
EditorGUILayout.Space(15 * EditorGUI.indentLevel, false);
if (GUILayout.Button(EditorGUIUtility.TrTextContent("Refresh Dilation"), EditorStyles.miniButton))
if (ProbeTouchupVolumeEditor.Button(EditorGUIUtility.TrTextContent("Refresh Dilation")))
{
ProbeGIBaking.RevertDilation();
ProbeGIBaking.PerformDilation();
}
GUILayout.EndHorizontal();
}
}
}
Expand All @@ -100,13 +95,10 @@ void DrawVirtualOffsetSettings(SerializedProperty virtualOffsetSettings)
EditorGUILayout.PropertyField(virtualOffsetRayOriginBias, Styles.virtualOffsetRayOriginBias);
EditorGUILayout.PropertyField(virtualOffsetCollisionMask, Styles.virtualOffsetCollisionMask);

GUILayout.BeginHorizontal();
EditorGUILayout.Space(15 * EditorGUI.indentLevel, false);
if (GUILayout.Button(EditorGUIUtility.TrTextContent("Refresh Virtual Offset Debug", "Re-run the virtual offset simulation; it will be applied only for debug visualization sake and not affect baked data."), Styles.voButtonStyle))
if (ProbeTouchupVolumeEditor.Button(EditorGUIUtility.TrTextContent("Refresh Virtual Offset Debug", "Re-run the virtual offset simulation; it will be applied only for debug visualization sake and not affect baked data.")))
{
ProbeGIBaking.RecomputeVOForDebugOnly();
}
GUILayout.EndHorizontal();
}
}
}
Expand Down
Loading

0 comments on commit 0153969

Please sign in to comment.