Skip to content
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

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,62 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#if GT_USE_URP
using UnityEditor;
using UnityEngine;

namespace Microsoft.MixedReality.GraphicsTools.Editor
{
/// <summary>
/// Custom inspector that helps with magnifier configuration.
/// </summary>
[CustomEditor(typeof(MagnifierManager))]
public class MagnifierManagerInspector : UnityEditor.Editor
{
private SerializedProperty m_Script;
private SerializedProperty renderObjectsSettings;

private bool showRenderObjects = false;

private void OnEnable()
{
m_Script = serializedObject.FindProperty(nameof(m_Script));
renderObjectsSettings = serializedObject.FindProperty(nameof(renderObjectsSettings));
}

/// <summary>
/// Renders a custom inspector GUI.
/// </summary>
public override void OnInspectorGUI()
{
using (var check = new EditorGUI.ChangeCheckScope())
{
InspectorUtilities.DrawReadonlyPropertyField(m_Script);

DrawPropertiesExcluding(serializedObject, nameof(m_Script), nameof(renderObjectsSettings));

showRenderObjects = EditorGUILayout.Foldout(showRenderObjects, "Render Objects Settings");

if (showRenderObjects)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(renderObjectsSettings);
EditorGUI.indentLevel--;
}

if (check.changed)
{
MagnifierManager magnifier = target as MagnifierManager;

if (magnifier != null)
{
magnifier.ApplyMagnification();
}

serializedObject.ApplyModifiedProperties();
}
}
}
}
}
#endif // GT_USE_URP

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 @@ -108,7 +108,7 @@ private void OnEnable()
/// <inheritdoc />
public override void OnInspectorGUI()
{
DrawReadonlyPropertyField(m_Script);
InspectorUtilities.DrawReadonlyPropertyField(m_Script);

EditorGUI.BeginChangeCheck();

Expand Down Expand Up @@ -305,12 +305,5 @@ private static bool IsCorrectMaterial(Material material, MaterialSettings materi

return true;
}

private static void DrawReadonlyPropertyField(SerializedProperty property, params GUILayoutOption[] options)
{
GUI.enabled = false;
EditorGUILayout.PropertyField(property, options);
GUI.enabled = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public override void OnInspectorGUI()

using (var check = new EditorGUI.ChangeCheckScope())
{
DrawReadonlyPropertyField(m_Script);
InspectorUtilities.DrawReadonlyPropertyField(m_Script);

if (HasNoRenderers(previousRenderers))
{
EditorGUILayout.PropertyField(applyToSharedMaterial);
}
else
{
DrawReadonlyPropertyField(applyToSharedMaterial);
InspectorUtilities.DrawReadonlyPropertyField(applyToSharedMaterial);
}

DrawPropertiesExcluding(serializedObject, nameof(m_Script), nameof(applyToSharedMaterial));
Expand Down Expand Up @@ -99,13 +99,6 @@ public override void OnInspectorGUI()
}
}

private static void DrawReadonlyPropertyField(SerializedProperty property, params GUILayoutOption[] options)
{
GUI.enabled = false;
EditorGUILayout.PropertyField(property, options);
GUI.enabled = true;
}

private static bool HasNoRenderers(IEnumerable<Renderer> renderers)
{
foreach (var renderer in renderers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Microsoft.MixedReality.GraphicsTools.Editor
{
/// <summary>
/// General utility methods to help with shader inspector development.
/// General utility methods to help with inspector development.
/// </summary>
public static class InspectorUtilities
{
Expand All @@ -28,5 +28,15 @@ public static GameObject CreateGameObjectFromMenu<T>(MenuCommand menuCommand) wh

return gameObject;
}

/// <summary>
/// Draws a property that is greyed out and non-interactible.
/// </summary>
public static void DrawReadonlyPropertyField(SerializedProperty property, params GUILayoutOption[] options)
{
GUI.enabled = false;
EditorGUILayout.PropertyField(property, options);
GUI.enabled = true;
}
}
}

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 @@ -7,7 +7,7 @@ Material:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: BlitMaterial
m_Name: Blit
m_Shader: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Material:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: MagnifierMaterial
m_Name: Magnifier
m_Shader: {fileID: 4800000, guid: 708bca655443cdd41b94ee29b5572b6e, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,44 @@

namespace Microsoft.MixedReality.GraphicsTools
{
/// <summary>
/// Manages creating and updating render features necessary for the magnification effect on the scriptable render pipeline that in use .
/// </summary>
/// <summary>
/// Manages creating and updating render features necessary for the magnification effect on the scriptable render pipeline.
/// </summary>
public class MagnifierManager : MonoBehaviour
{
[Tooltip("Scaler of the magnification.")]
[SerializeField, Range(0.0f, 1.0f)]
private float magnification = 0.7f;

// Scaler of the magnification.
public float Magnification
{
get => magnification;
set
{
magnification = Mathf.Clamp01(value);
ApplyMagnification();
}
}

[Tooltip("The name of the global shader property that drives the magnification ammount.")]
[SerializeField]
private string magnificationPropertyName = "MagnifierMagnification";

public string MagnificationPropertyName
{
get => magnificationPropertyName;
set
{
magnificationPropertyName = value;
ApplyMagnification();
}
}

[Tooltip("Which renderer to use in the UniversalRenderPipelineAsset.")]
[SerializeField]
private int rendererIndex = 0;

[SerializeField]
private DrawFullscreenFeature.Settings drawFullscreenSettings = new DrawFullscreenFeature.Settings()
{
Expand All @@ -25,7 +58,7 @@ public class MagnifierManager : MonoBehaviour
DestinationTextureId = "MagnifierTexture",
};

[SerializeField, Header("Render Objects Settings")]
[SerializeField]
private RenderObjects.RenderObjectsSettings renderObjectsSettings = new RenderObjects.RenderObjectsSettings()
{
Event = RenderPassEvent.AfterRenderingTransparents,
Expand All @@ -35,9 +68,8 @@ public class MagnifierManager : MonoBehaviour
}
};

[Tooltip("Which renderer to use in the UniversalRenderPipelineAsset.")]
[SerializeField]
private int rendererIndex = 0;
[SerializeField, HideInInspector]
private Material defaultBlitMaterial;

private DrawFullscreenFeature magnifierFeature;
private ScriptableRendererFeature renderTransparent;
Expand All @@ -51,6 +83,14 @@ public class MagnifierManager : MonoBehaviour
private LayerMask previousOpaqueLayerMask;
private LayerMask previousTransparentLayerMask;

private void Reset()
{
if (drawFullscreenSettings.BlitMaterial == null)
{
drawFullscreenSettings.BlitMaterial = defaultBlitMaterial;
}
}

private void OnEnable()
{
if (!initialized)
Expand All @@ -62,6 +102,8 @@ private void OnEnable()
CreateRendererFeatures();
initialized = true;
}

ApplyMagnification();
}
}

Expand Down Expand Up @@ -89,9 +131,11 @@ private void OnDisable()
}
}

/// <summary>
/// Method <c>InitializeRendererData</c> gets the selected scriptable render pipeline thats currently in use.
/// </summary>
public void ApplyMagnification()
{
Shader.SetGlobalFloat(MagnificationPropertyName, 1.0f - Magnification);
}

private void InitializeRendererData()
{
var pipeline = ((UniversalRenderPipelineAsset)GraphicsSettings.currentRenderPipeline);
Expand All @@ -111,9 +155,6 @@ private void InitializeRendererData()
}
}

/// <summary>
/// Method <c>CreateRendererFeatures</c> creates renderer features and adds them to a list of features to be deployed on the scriptable render pipeline.
/// </summary>
private void CreateRendererFeatures()
{
magnifierFeature = CreateMagnifierFullsreenFeature("Magnifier Draw Fullscreen Feature", drawFullscreenSettings);
Expand All @@ -130,9 +171,6 @@ private void CreateRendererFeatures()
rendererData.SetDirty();
}

/// <summary>
/// Method <c>CreateMagnifierFullsreenFeature</c> creates an instance of the draw fullscreen renderer feature.
/// </summary>
private DrawFullscreenFeature CreateMagnifierFullsreenFeature(string name, DrawFullscreenFeature.Settings settings)
{
DrawFullscreenFeature feature = ScriptableObject.CreateInstance<DrawFullscreenFeature>();
Expand All @@ -142,9 +180,6 @@ private DrawFullscreenFeature CreateMagnifierFullsreenFeature(string name, DrawF
return feature;
}

/// <summary>
/// Method <c>CreateRenderObjectsFeature</c> creates an instance of the render objects renderer feature.
/// </summary>
private ScriptableRendererFeature CreateMagnifierRenderObjectsFeature(string name, RenderObjects.RenderObjectsSettings settings)
{
RenderObjects feature = ScriptableObject.CreateInstance<RenderObjects>();
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
Expand Up @@ -5,7 +5,6 @@ Shader "Graphics Tools/Magnifier"
{
Properties
{
Magnification("Magnification", Float) = 0.5
[ShowAsVector2] Center("Center", Vector) = (0.5,0.5,0,0)
}
SubShader
Expand Down Expand Up @@ -47,7 +46,7 @@ Shader "Graphics Tools/Magnifier"
UNITY_VERTEX_OUTPUT_STEREO
};

half Magnification;
half MagnifierMagnification;
float2 Center;

TEXTURE2D_X(MagnifierTexture);
Expand Down Expand Up @@ -75,7 +74,7 @@ Shader "Graphics Tools/Magnifier"

float2 normalizedScreenSpaceUVStereo = UnityStereoTransformScreenSpaceTex(normalizedScreenSpaceUV);

float2 zoomedUv = zoomIn(normalizedScreenSpaceUVStereo, Magnification, Center);
float2 zoomedUv = zoomIn(normalizedScreenSpaceUVStereo, MagnifierMagnification, Center);

float4 output = SAMPLE_TEXTURE2D_X(MagnifierTexture, samplerMagnifierTexture, zoomedUv);

Expand Down
Loading