From 79f01d73d8c7f5719ded53140cb836a153bb0278 Mon Sep 17 00:00:00 2001 From: Cameron Micka Date: Tue, 7 May 2024 14:49:11 -0700 Subject: [PATCH 01/13] Improved 2023 support. --- .../Editor/Utilities/ScreenshotUtilities.cs | 4 ++++ .../Experimental/Acrylic/Scripts/AcrylicBlurRenderPass.cs | 8 ++++---- .../Runtime/Utilities/FlyCameraController.cs | 4 ++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/com.microsoft.mrtk.graphicstools.unity/Editor/Utilities/ScreenshotUtilities.cs b/com.microsoft.mrtk.graphicstools.unity/Editor/Utilities/ScreenshotUtilities.cs index bcfa8cbe..b72810ec 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Editor/Utilities/ScreenshotUtilities.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Editor/Utilities/ScreenshotUtilities.cs @@ -86,7 +86,11 @@ public static bool CaptureScreenshot(string path, int superSize = 1, bool transp if (camera == null) { +#if UNITY_2023_1_OR_NEWER + camera = GameObject.FindFirstObjectByType(); +#else camera = GameObject.FindObjectOfType(); +#endif if (camera == null) { diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Acrylic/Scripts/AcrylicBlurRenderPass.cs b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Acrylic/Scripts/AcrylicBlurRenderPass.cs index 80dda26c..436b1e03 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Acrylic/Scripts/AcrylicBlurRenderPass.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Acrylic/Scripts/AcrylicBlurRenderPass.cs @@ -19,7 +19,7 @@ class AcrylicBlurRenderPass : ScriptableRenderPass { public bool setMaterialTexture = false; private string profilerLabel; -#if UNITY_6000_0_OR_NEWER +#if UNITY_2022_1_OR_NEWER private RTHandle target1; private RTHandle target2; #else @@ -96,7 +96,7 @@ public override void Configure(CommandBuffer cmd, RenderTextureDescriptor camera } } -#if UNITY_6000_0_OR_NEWER +#if UNITY_2022_1_OR_NEWER private static RenderTargetIdentifier GetIdentifier(RTHandle target) { return Shader.PropertyToID(target.name); @@ -117,7 +117,7 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData var handle = providedTexture==null ? GetIdentifier(target1) : providedTexture; var renderer = renderingData.cameraData.renderer; -#if UNITY_6000_0_OR_NEWER +#if UNITY_2022_1_OR_NEWER var colorTargetHandle = renderer.cameraColorTargetHandle; #else var colorTargetHandle = renderer.cameraColorTarget; @@ -198,7 +198,7 @@ private void SwapTempTargets() target2 = rttmp; } -#if UNITY_6000_0_OR_NEWER +#if UNITY_2022_1_OR_NEWER private void ConfigureTempRenderTarget(ref RTHandle target, string id, int width, int height, int slices, CommandBuffer cmd) { target = RTHandles.Alloc(id, name: id); diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/FlyCameraController.cs b/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/FlyCameraController.cs index f58c390e..5281b4b8 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/FlyCameraController.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/FlyCameraController.cs @@ -95,7 +95,11 @@ private void OnEnable() /// private void Start() { +#if UNITY_2023_1_OR_NEWER + SubsystemManager.GetSubsystems(xrDisplaySubsystems); +#else SubsystemManager.GetInstances(xrDisplaySubsystems); +#endif } /// From 659cb08cd3e6aab0082ad84178b038c14a1fd653 Mon Sep 17 00:00:00 2001 From: Cameron Micka Date: Tue, 7 May 2024 14:50:36 -0700 Subject: [PATCH 02/13] Version bump. --- .../package.json | 4 ++-- com.microsoft.mrtk.graphicstools.unity/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/com.microsoft.mrtk.graphicstools.shadergraph.unity/package.json b/com.microsoft.mrtk.graphicstools.shadergraph.unity/package.json index 1fb199a3..26df481e 100644 --- a/com.microsoft.mrtk.graphicstools.shadergraph.unity/package.json +++ b/com.microsoft.mrtk.graphicstools.shadergraph.unity/package.json @@ -1,8 +1,8 @@ { "name": "com.microsoft.mrtk.graphicstools.shadergraph.unity", - "version": "0.6.5", + "version": "0.7.0", "displayName": "MRTK Graphics Tools Shader Graph", - "description": "Graphics tools and components for developing Mixed Reality applications in Unity Shader Graph.", + "description": "Graphics tools and components for developing Mixed Reality applications in Unity Shader Graph.", "documentationUrl": "https://aka.ms/mrtk3graphics", "msftFeatureCategory": "MRTK3", "unity": "2021.3", diff --git a/com.microsoft.mrtk.graphicstools.unity/package.json b/com.microsoft.mrtk.graphicstools.unity/package.json index 60ac32f7..e683415c 100644 --- a/com.microsoft.mrtk.graphicstools.unity/package.json +++ b/com.microsoft.mrtk.graphicstools.unity/package.json @@ -1,6 +1,6 @@ { "name": "com.microsoft.mrtk.graphicstools.unity", - "version": "0.6.9", + "version": "0.7.0", "displayName": "MRTK Graphics Tools", "description": "Graphics tools and components for developing Mixed Reality applications in Unity.", "documentationUrl": "https://aka.ms/mrtk3graphics", From 376d2aa43dbbcced29263f04d46461f02d07a758 Mon Sep 17 00:00:00 2001 From: Cameron Micka Date: Wed, 2 Oct 2024 16:56:49 -0700 Subject: [PATCH 03/13] UNITY_6000_0_OR_NEWER support. --- .../Editor/Utilities/ScreenshotUtilities.cs | 4 ++-- .../Acrylic/Scripts/AcrylicBlurRenderPass.cs | 10 ++++++++-- .../Acrylic/Scripts/AcrylicLayer.cs | 2 ++ .../Magnifier/Scripts/MagnifierManager.cs | 2 ++ .../Utilities/ClearRenderTargetPass.cs | 11 +++++++---- .../Runtime/Utilities/DrawFullscreenPass.cs | 14 ++++++++++---- .../Runtime/Utilities/FlyCameraController.cs | 4 ++-- .../MaterialGallery/Scripts/MaterialMatrix.cs | 19 +++++++++++++------ 8 files changed, 46 insertions(+), 20 deletions(-) diff --git a/com.microsoft.mrtk.graphicstools.unity/Editor/Utilities/ScreenshotUtilities.cs b/com.microsoft.mrtk.graphicstools.unity/Editor/Utilities/ScreenshotUtilities.cs index b72810ec..9e2788ee 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Editor/Utilities/ScreenshotUtilities.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Editor/Utilities/ScreenshotUtilities.cs @@ -86,8 +86,8 @@ public static bool CaptureScreenshot(string path, int superSize = 1, bool transp if (camera == null) { -#if UNITY_2023_1_OR_NEWER - camera = GameObject.FindFirstObjectByType(); +#if UNITY_6000_0_OR_NEWER + camera = GameObject.FindFirstObjectByType(); #else camera = GameObject.FindObjectOfType(); #endif diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Acrylic/Scripts/AcrylicBlurRenderPass.cs b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Acrylic/Scripts/AcrylicBlurRenderPass.cs index 436b1e03..6af7825d 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Acrylic/Scripts/AcrylicBlurRenderPass.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Acrylic/Scripts/AcrylicBlurRenderPass.cs @@ -56,7 +56,10 @@ public AcrylicBlurRenderPass(string _profilerLabel, int _downSamplePasses, int _ private Vector4 info = Vector4.zero; - public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor) +#if UNITY_6000_0_OR_NEWER + [System.Obsolete] +#endif + public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor) { int width = cameraTextureDescriptor.width / downSample; int height = cameraTextureDescriptor.height / downSample; @@ -110,7 +113,10 @@ private static RenderTargetIdentifier GetIdentifier(RenderTargetHandle target) #endif - public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) +#if UNITY_6000_0_OR_NEWER + [System.Obsolete] +#endif + public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(profilerLabel); cmd.Clear(); diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Acrylic/Scripts/AcrylicLayer.cs b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Acrylic/Scripts/AcrylicLayer.cs index 82336a76..712c8e4a 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Acrylic/Scripts/AcrylicLayer.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Acrylic/Scripts/AcrylicLayer.cs @@ -4,7 +4,9 @@ #if GT_USE_URP using System; using UnityEngine; +#if !UNITY_6000_0_OR_NEWER using UnityEngine.Experimental.Rendering.Universal; +#endif using UnityEngine.Profiling; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Magnifier/Scripts/MagnifierManager.cs b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Magnifier/Scripts/MagnifierManager.cs index 8a87cffc..b378d9ef 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Magnifier/Scripts/MagnifierManager.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Magnifier/Scripts/MagnifierManager.cs @@ -4,7 +4,9 @@ #if GT_USE_URP using System.Collections.Generic; using UnityEngine; +#if !UNITY_6000_0_OR_NEWER using UnityEngine.Experimental.Rendering.Universal; +#endif using UnityEngine.Rendering.Universal; namespace Microsoft.MixedReality.GraphicsTools diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/ClearRenderTargetPass.cs b/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/ClearRenderTargetPass.cs index 339255d5..f2c9e8f4 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/ClearRenderTargetPass.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/ClearRenderTargetPass.cs @@ -20,10 +20,13 @@ public ClearRenderTargetPass(ClearRenderTarget.PassSettings passSettings) renderPassEvent = settings.RenderPassEvent; } - /// - /// Queues a ClearRenderTarget command based on the pass settings. - /// - public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) + /// + /// Queues a ClearRenderTarget command based on the pass settings. + /// +#if UNITY_6000_0_OR_NEWER + [System.Obsolete] +#endif + public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(); diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/DrawFullscreenPass.cs b/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/DrawFullscreenPass.cs index c9581e07..d0f80914 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/DrawFullscreenPass.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/DrawFullscreenPass.cs @@ -34,8 +34,11 @@ public DrawFullscreenPass(string tag) profilerTag = tag; } - /// - public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData) + /// +#if UNITY_6000_0_OR_NEWER + [System.Obsolete] +#endif + public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData) { RenderTextureDescriptor blitTargetDescriptor = renderingData.cameraData.cameraTargetDescriptor; blitTargetDescriptor.depthBufferBits = 0; @@ -69,8 +72,11 @@ public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderin } } - /// - public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) + /// +#if UNITY_6000_0_OR_NEWER + [System.Obsolete] +#endif + public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(profilerTag); diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/FlyCameraController.cs b/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/FlyCameraController.cs index 5281b4b8..bd2aba8d 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/FlyCameraController.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/FlyCameraController.cs @@ -95,8 +95,8 @@ private void OnEnable() /// private void Start() { -#if UNITY_2023_1_OR_NEWER - SubsystemManager.GetSubsystems(xrDisplaySubsystems); +#if UNITY_6000_0_OR_NEWER + SubsystemManager.GetSubsystems(xrDisplaySubsystems); #else SubsystemManager.GetInstances(xrDisplaySubsystems); #endif diff --git a/com.microsoft.mrtk.graphicstools.unity/Samples~/MaterialGallery/Scripts/MaterialMatrix.cs b/com.microsoft.mrtk.graphicstools.unity/Samples~/MaterialGallery/Scripts/MaterialMatrix.cs index cbbf8f4d..bbfb7a74 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Samples~/MaterialGallery/Scripts/MaterialMatrix.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Samples~/MaterialGallery/Scripts/MaterialMatrix.cs @@ -52,9 +52,13 @@ private void Update() // Poll for when the render pipeline changes. if (useDefaultMaterial) { - if (lastRenderPipelineAsset != GraphicsSettings.renderPipelineAsset) - { - BuildMatrix(); +#if UNITY_6000_0_OR_NEWER + if (lastRenderPipelineAsset != GraphicsSettings.defaultRenderPipeline) +#else + if (lastRenderPipelineAsset != GraphicsSettings.renderPipelineAsset) +#endif + { + BuildMatrix(); } } } @@ -83,9 +87,12 @@ private void BuildMatrix() if (useDefaultMaterial) { - lastRenderPipelineAsset = GraphicsSettings.renderPipelineAsset; - - if (lastRenderPipelineAsset != null) +#if UNITY_6000_0_OR_NEWER + lastRenderPipelineAsset = GraphicsSettings.defaultRenderPipeline; +#else + lastRenderPipelineAsset = GraphicsSettings.renderPipelineAsset; +#endif + if (lastRenderPipelineAsset != null) { currentMaterial = lastRenderPipelineAsset.defaultMaterial; } From 301277c055055e4341a7739510ec23653ab05bf8 Mon Sep 17 00:00:00 2001 From: Cameron Micka Date: Wed, 2 Oct 2024 17:07:44 -0700 Subject: [PATCH 04/13] Convert tabs to spaces. --- .../Editor/Utilities/ScreenshotUtilities.cs | 2 +- .../Acrylic/Scripts/AcrylicBlurRenderPass.cs | 8 ++++---- .../Runtime/Utilities/ClearRenderTargetPass.cs | 10 +++++----- .../Runtime/Utilities/DrawFullscreenPass.cs | 12 ++++++------ .../Runtime/Utilities/FlyCameraController.cs | 2 +- .../MaterialGallery/Scripts/MaterialMatrix.cs | 14 +++++++------- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/com.microsoft.mrtk.graphicstools.unity/Editor/Utilities/ScreenshotUtilities.cs b/com.microsoft.mrtk.graphicstools.unity/Editor/Utilities/ScreenshotUtilities.cs index 9e2788ee..e329b7bc 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Editor/Utilities/ScreenshotUtilities.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Editor/Utilities/ScreenshotUtilities.cs @@ -87,7 +87,7 @@ public static bool CaptureScreenshot(string path, int superSize = 1, bool transp if (camera == null) { #if UNITY_6000_0_OR_NEWER - camera = GameObject.FindFirstObjectByType(); + camera = GameObject.FindFirstObjectByType(); #else camera = GameObject.FindObjectOfType(); #endif diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Acrylic/Scripts/AcrylicBlurRenderPass.cs b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Acrylic/Scripts/AcrylicBlurRenderPass.cs index 6af7825d..2af683cd 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Acrylic/Scripts/AcrylicBlurRenderPass.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Acrylic/Scripts/AcrylicBlurRenderPass.cs @@ -57,9 +57,9 @@ public AcrylicBlurRenderPass(string _profilerLabel, int _downSamplePasses, int _ private Vector4 info = Vector4.zero; #if UNITY_6000_0_OR_NEWER - [System.Obsolete] + [System.Obsolete] #endif - public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor) + public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor) { int width = cameraTextureDescriptor.width / downSample; int height = cameraTextureDescriptor.height / downSample; @@ -114,9 +114,9 @@ private static RenderTargetIdentifier GetIdentifier(RenderTargetHandle target) #endif #if UNITY_6000_0_OR_NEWER - [System.Obsolete] + [System.Obsolete] #endif - public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) + public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(profilerLabel); cmd.Clear(); diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/ClearRenderTargetPass.cs b/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/ClearRenderTargetPass.cs index f2c9e8f4..a38eba11 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/ClearRenderTargetPass.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/ClearRenderTargetPass.cs @@ -20,13 +20,13 @@ public ClearRenderTargetPass(ClearRenderTarget.PassSettings passSettings) renderPassEvent = settings.RenderPassEvent; } - /// - /// Queues a ClearRenderTarget command based on the pass settings. - /// + /// + /// Queues a ClearRenderTarget command based on the pass settings. + /// #if UNITY_6000_0_OR_NEWER - [System.Obsolete] + [System.Obsolete] #endif - public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) + public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(); diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/DrawFullscreenPass.cs b/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/DrawFullscreenPass.cs index d0f80914..647eb8a1 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/DrawFullscreenPass.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/DrawFullscreenPass.cs @@ -34,11 +34,11 @@ public DrawFullscreenPass(string tag) profilerTag = tag; } - /// + /// #if UNITY_6000_0_OR_NEWER - [System.Obsolete] + [System.Obsolete] #endif - public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData) + public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData) { RenderTextureDescriptor blitTargetDescriptor = renderingData.cameraData.cameraTargetDescriptor; blitTargetDescriptor.depthBufferBits = 0; @@ -72,11 +72,11 @@ public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderin } } - /// + /// #if UNITY_6000_0_OR_NEWER - [System.Obsolete] + [System.Obsolete] #endif - public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) + public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(profilerTag); diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/FlyCameraController.cs b/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/FlyCameraController.cs index bd2aba8d..fdeff153 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/FlyCameraController.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Utilities/FlyCameraController.cs @@ -96,7 +96,7 @@ private void OnEnable() private void Start() { #if UNITY_6000_0_OR_NEWER - SubsystemManager.GetSubsystems(xrDisplaySubsystems); + SubsystemManager.GetSubsystems(xrDisplaySubsystems); #else SubsystemManager.GetInstances(xrDisplaySubsystems); #endif diff --git a/com.microsoft.mrtk.graphicstools.unity/Samples~/MaterialGallery/Scripts/MaterialMatrix.cs b/com.microsoft.mrtk.graphicstools.unity/Samples~/MaterialGallery/Scripts/MaterialMatrix.cs index bbfb7a74..faff3282 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Samples~/MaterialGallery/Scripts/MaterialMatrix.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Samples~/MaterialGallery/Scripts/MaterialMatrix.cs @@ -53,12 +53,12 @@ private void Update() if (useDefaultMaterial) { #if UNITY_6000_0_OR_NEWER - if (lastRenderPipelineAsset != GraphicsSettings.defaultRenderPipeline) + if (lastRenderPipelineAsset != GraphicsSettings.defaultRenderPipeline) #else - if (lastRenderPipelineAsset != GraphicsSettings.renderPipelineAsset) + if (lastRenderPipelineAsset != GraphicsSettings.renderPipelineAsset) #endif - { - BuildMatrix(); + { + BuildMatrix(); } } } @@ -88,11 +88,11 @@ private void BuildMatrix() if (useDefaultMaterial) { #if UNITY_6000_0_OR_NEWER - lastRenderPipelineAsset = GraphicsSettings.defaultRenderPipeline; + lastRenderPipelineAsset = GraphicsSettings.defaultRenderPipeline; #else - lastRenderPipelineAsset = GraphicsSettings.renderPipelineAsset; + lastRenderPipelineAsset = GraphicsSettings.renderPipelineAsset; #endif - if (lastRenderPipelineAsset != null) + if (lastRenderPipelineAsset != null) { currentMaterial = lastRenderPipelineAsset.defaultMaterial; } From 531a303b11ee4c758f435fb0418440ca77035848 Mon Sep 17 00:00:00 2001 From: Cameron Micka Date: Wed, 2 Oct 2024 17:13:22 -0700 Subject: [PATCH 05/13] Bump package version. --- com.microsoft.mrtk.graphicstools.shadergraph.unity/package.json | 2 +- com.microsoft.mrtk.graphicstools.unity/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/com.microsoft.mrtk.graphicstools.shadergraph.unity/package.json b/com.microsoft.mrtk.graphicstools.shadergraph.unity/package.json index 8e6ec4d5..69517934 100644 --- a/com.microsoft.mrtk.graphicstools.shadergraph.unity/package.json +++ b/com.microsoft.mrtk.graphicstools.shadergraph.unity/package.json @@ -1,6 +1,6 @@ { "name": "com.microsoft.mrtk.graphicstools.shadergraph.unity", - "version": "0.7.2", + "version": "0.7.3", "displayName": "MRTK Graphics Tools Shader Graph", "description": "Graphics tools and components for developing Mixed Reality applications in Unity Shader Graph.", "documentationUrl": "https://aka.ms/mrtk3graphics", diff --git a/com.microsoft.mrtk.graphicstools.unity/package.json b/com.microsoft.mrtk.graphicstools.unity/package.json index 006ebf76..3f36a05d 100644 --- a/com.microsoft.mrtk.graphicstools.unity/package.json +++ b/com.microsoft.mrtk.graphicstools.unity/package.json @@ -1,6 +1,6 @@ { "name": "com.microsoft.mrtk.graphicstools.unity", - "version": "0.7.2", + "version": "0.7.3", "displayName": "MRTK Graphics Tools", "description": "Graphics tools and components for developing Mixed Reality applications in Unity.", "documentationUrl": "https://aka.ms/mrtk3graphics", From bc4489abe0f44d3f2920ba5e68268b36a0b4cbfb Mon Sep 17 00:00:00 2001 From: Cameron Micka Date: Mon, 2 Dec 2024 14:04:32 -0800 Subject: [PATCH 06/13] Project update and remove unneeded deps. --- .../Packages/manifest.json | 14 ++-- .../Packages/packages-lock.json | 74 ++++++------------- .../ProjectSettings/ProjectVersion.txt | 4 +- 3 files changed, 32 insertions(+), 60 deletions(-) diff --git a/GraphicsToolsUnityProject/Packages/manifest.json b/GraphicsToolsUnityProject/Packages/manifest.json index 434e33e3..a5c553d0 100644 --- a/GraphicsToolsUnityProject/Packages/manifest.json +++ b/GraphicsToolsUnityProject/Packages/manifest.json @@ -2,16 +2,14 @@ "dependencies": { "com.microsoft.mrtk.graphicstools.shadergraph.unity": "file:../../com.microsoft.mrtk.graphicstools.shadergraph.unity", "com.microsoft.mrtk.graphicstools.unity": "file:../../com.microsoft.mrtk.graphicstools.unity", - "com.unity.asset-store-validation": "0.5.1", - "com.unity.ide.visualstudio": "2.0.17", + "com.unity.asset-store-validation": "0.6.0", + "com.unity.ide.visualstudio": "2.0.22", "com.unity.ide.vscode": "1.2.5", - "com.unity.inputsystem": "1.4.4", - "com.unity.memoryprofiler": "0.7.1-preview.1", - "com.unity.render-pipelines.universal": "12.1.8", - "com.unity.textmeshpro": "3.0.6", + "com.unity.inputsystem": "1.7.0", + "com.unity.textmeshpro": "3.0.9", "com.unity.ugui": "1.0.0", - "com.unity.xr.management": "4.2.1", - "com.unity.xr.oculus": "3.2.2", + "com.unity.xr.management": "4.4.1", + "com.unity.xr.oculus": "3.3.0", "com.unity.modules.ai": "1.0.0", "com.unity.modules.androidjni": "1.0.0", "com.unity.modules.animation": "1.0.0", diff --git a/GraphicsToolsUnityProject/Packages/packages-lock.json b/GraphicsToolsUnityProject/Packages/packages-lock.json index 5e53d566..9599ca80 100644 --- a/GraphicsToolsUnityProject/Packages/packages-lock.json +++ b/GraphicsToolsUnityProject/Packages/packages-lock.json @@ -15,7 +15,7 @@ "dependencies": {} }, "com.unity.asset-store-validation": { - "version": "0.5.1", + "version": "0.6.0", "depth": 0, "source": "registry", "dependencies": { @@ -24,21 +24,14 @@ "url": "https://packages.unity.com" }, "com.unity.burst": { - "version": "1.8.2", - "depth": 1, + "version": "1.8.11", + "depth": 2, "source": "registry", "dependencies": { "com.unity.mathematics": "1.2.1" }, "url": "https://packages.unity.com" }, - "com.unity.editorcoroutines": { - "version": "1.0.0", - "depth": 1, - "source": "registry", - "dependencies": {}, - "url": "https://packages.unity.com" - }, "com.unity.ext.nunit": { "version": "1.0.6", "depth": 2, @@ -47,7 +40,7 @@ "url": "https://packages.unity.com" }, "com.unity.ide.visualstudio": { - "version": "2.0.17", + "version": "2.0.22", "depth": 0, "source": "registry", "dependencies": { @@ -63,7 +56,7 @@ "url": "https://packages.unity.com" }, "com.unity.inputsystem": { - "version": "1.4.4", + "version": "1.7.0", "depth": 0, "source": "registry", "dependencies": { @@ -73,30 +66,21 @@ }, "com.unity.mathematics": { "version": "1.2.6", - "depth": 1, + "depth": 2, "source": "registry", "dependencies": {}, "url": "https://packages.unity.com" }, - "com.unity.memoryprofiler": { - "version": "0.7.1-preview.1", - "depth": 0, - "source": "registry", - "dependencies": { - "com.unity.editorcoroutines": "1.0.0" - }, - "url": "https://packages.unity.com" - }, "com.unity.nuget.newtonsoft-json": { - "version": "3.0.2", + "version": "3.2.1", "depth": 1, "source": "registry", "dependencies": {}, "url": "https://packages.unity.com" }, "com.unity.render-pipelines.core": { - "version": "12.1.8", - "depth": 1, + "version": "12.1.14", + "depth": 2, "source": "builtin", "dependencies": { "com.unity.ugui": "1.0.0", @@ -105,43 +89,34 @@ } }, "com.unity.render-pipelines.universal": { - "version": "12.1.8", - "depth": 0, + "version": "12.1.14", + "depth": 1, "source": "builtin", "dependencies": { "com.unity.mathematics": "1.2.1", - "com.unity.burst": "1.8.2", - "com.unity.render-pipelines.core": "12.1.8", - "com.unity.shadergraph": "12.1.8" + "com.unity.burst": "1.8.9", + "com.unity.render-pipelines.core": "12.1.14", + "com.unity.shadergraph": "12.1.14" } }, "com.unity.searcher": { "version": "4.9.1", - "depth": 2, + "depth": 3, "source": "registry", "dependencies": {}, "url": "https://packages.unity.com" }, "com.unity.shadergraph": { - "version": "12.1.8", - "depth": 1, + "version": "12.1.14", + "depth": 2, "source": "builtin", "dependencies": { - "com.unity.render-pipelines.core": "12.1.8", + "com.unity.render-pipelines.core": "12.1.14", "com.unity.searcher": "4.9.1" } }, - "com.unity.subsystemregistration": { - "version": "1.1.0", - "depth": 1, - "source": "registry", - "dependencies": { - "com.unity.modules.subsystems": "1.0.0" - }, - "url": "https://packages.unity.com" - }, "com.unity.test-framework": { - "version": "1.1.31", + "version": "1.1.33", "depth": 1, "source": "registry", "dependencies": { @@ -152,7 +127,7 @@ "url": "https://packages.unity.com" }, "com.unity.textmeshpro": { - "version": "3.0.6", + "version": "3.0.9", "depth": 0, "source": "registry", "dependencies": { @@ -180,20 +155,19 @@ "url": "https://packages.unity.com" }, "com.unity.xr.management": { - "version": "4.2.1", + "version": "4.4.1", "depth": 0, "source": "registry", "dependencies": { - "com.unity.modules.subsystems": "1.0.0", "com.unity.modules.vr": "1.0.0", "com.unity.modules.xr": "1.0.0", - "com.unity.xr.legacyinputhelpers": "2.1.7", - "com.unity.subsystemregistration": "1.0.6" + "com.unity.modules.subsystems": "1.0.0", + "com.unity.xr.legacyinputhelpers": "2.1.7" }, "url": "https://packages.unity.com" }, "com.unity.xr.oculus": { - "version": "3.2.2", + "version": "3.3.0", "depth": 0, "source": "registry", "dependencies": { diff --git a/GraphicsToolsUnityProject/ProjectSettings/ProjectVersion.txt b/GraphicsToolsUnityProject/ProjectSettings/ProjectVersion.txt index 3643b022..39a629e9 100644 --- a/GraphicsToolsUnityProject/ProjectSettings/ProjectVersion.txt +++ b/GraphicsToolsUnityProject/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2021.3.16f1 -m_EditorVersionWithRevision: 2021.3.16f1 (4016570cf34f) +m_EditorVersion: 2021.3.35f1 +m_EditorVersionWithRevision: 2021.3.35f1 (157b46ce122a) From 62afd9db76c2a22c55a2d85df21c92d970cdc7c6 Mon Sep 17 00:00:00 2001 From: Cameron Micka Date: Mon, 2 Dec 2024 14:04:49 -0800 Subject: [PATCH 07/13] Extra comments. --- .../Runtime/Shaders/GraphicsToolsStandard.shader | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Shaders/GraphicsToolsStandard.shader b/com.microsoft.mrtk.graphicstools.unity/Runtime/Shaders/GraphicsToolsStandard.shader index 76cc3af4..9109d71a 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Shaders/GraphicsToolsStandard.shader +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Shaders/GraphicsToolsStandard.shader @@ -191,6 +191,7 @@ Shader "Graphics Tools/Standard" ENDHLSL } + // Shadow casting pass. Pass { Name "ShadowCaster" @@ -231,6 +232,7 @@ Shader "Graphics Tools/Standard" ENDHLSL } + // Depth pass. // From Packages/com.unity.render-pipelines.universal/Shader/Lit.hlsl Pass { @@ -286,8 +288,8 @@ Shader "Graphics Tools/Standard" ENDHLSL } + // This pass is used when drawing to a _CameraNormalsTexture texture. // From Packages/com.unity.render-pipelines.universal/Shader/Lit.hlsl - // This pass is used when drawing to a _CameraNormalsTexture texture Pass { Name "DepthNormals" From a06e99b9d92656b0c791b0bf87d7526c5cb36fd0 Mon Sep 17 00:00:00 2001 From: Cameron Micka Date: Mon, 2 Dec 2024 14:20:09 -0800 Subject: [PATCH 08/13] Package update. --- .../package.json | 4 ++-- com.microsoft.mrtk.graphicstools.unity/CHANGELOG.md | 6 ++++++ com.microsoft.mrtk.graphicstools.unity/package.json | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/com.microsoft.mrtk.graphicstools.shadergraph.unity/package.json b/com.microsoft.mrtk.graphicstools.shadergraph.unity/package.json index 9238eef2..7f9c836d 100644 --- a/com.microsoft.mrtk.graphicstools.shadergraph.unity/package.json +++ b/com.microsoft.mrtk.graphicstools.shadergraph.unity/package.json @@ -1,12 +1,12 @@ { "name": "com.microsoft.mrtk.graphicstools.shadergraph.unity", - "version": "0.8.0", + "version": "0.8.1", "displayName": "MRTK Graphics Tools Shader Graph", "description": "Graphics tools and components for developing Mixed Reality applications in Unity Shader Graph.", "documentationUrl": "https://aka.ms/mrtk3graphics", "msftFeatureCategory": "MRTK3", "unity": "2021.3", - "unityRelease": "26f1", + "unityRelease": "35f1", "author": "Microsoft", "license": "MIT", "repository": { diff --git a/com.microsoft.mrtk.graphicstools.unity/CHANGELOG.md b/com.microsoft.mrtk.graphicstools.unity/CHANGELOG.md index 0c7e494a..39a1015b 100644 --- a/com.microsoft.mrtk.graphicstools.unity/CHANGELOG.md +++ b/com.microsoft.mrtk.graphicstools.unity/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). +## [0.8.1] - 2024-12-02 + +### Changed + +- Added support for Unity URP SSAO's "Depth normal" mode. + ## [0.8.0] - 2024-11-21 ### Changed diff --git a/com.microsoft.mrtk.graphicstools.unity/package.json b/com.microsoft.mrtk.graphicstools.unity/package.json index 8058af02..e751cd48 100644 --- a/com.microsoft.mrtk.graphicstools.unity/package.json +++ b/com.microsoft.mrtk.graphicstools.unity/package.json @@ -1,12 +1,12 @@ { "name": "com.microsoft.mrtk.graphicstools.unity", - "version": "0.8.0", + "version": "0.8.1", "displayName": "MRTK Graphics Tools", "description": "Graphics tools and components for developing Mixed Reality applications in Unity.", "documentationUrl": "https://aka.ms/mrtk3graphics", "msftFeatureCategory": "MRTK3", "unity": "2021.3", - "unityRelease": "26f1", + "unityRelease": "35f1", "author": "Microsoft", "license": "MIT", "repository": { From 7f213c37b1ee243db2e5568d9343f1fa6866787c Mon Sep 17 00:00:00 2001 From: Cameron Micka Date: Thu, 3 Apr 2025 11:45:51 -0700 Subject: [PATCH 09/13] Adding facing option. --- .../AreaLight/AreaLightInspector.cs | 3 +- .../Experimental/AreaLight/AreaLight.cs | 33 +++++++++++++++++-- .../Shaders/AreaLightVisualize.shader | 2 ++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/com.microsoft.mrtk.graphicstools.unity/Editor/Experimental/AreaLight/AreaLightInspector.cs b/com.microsoft.mrtk.graphicstools.unity/Editor/Experimental/AreaLight/AreaLightInspector.cs index 51f30afb..31a4a94a 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Editor/Experimental/AreaLight/AreaLightInspector.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Editor/Experimental/AreaLight/AreaLightInspector.cs @@ -41,7 +41,8 @@ private void OnSceneGUI() // Draw the area light's normal only if it will not overlap with the current tool. if (!((Tools.current == Tool.Move || Tools.current == Tool.Scale) && Tools.pivotRotation == PivotRotation.Local)) { - Handles.DrawLine(light.transform.position, light.transform.position + light.transform.forward); + var normal = light.transform.forward * ((light.Facing == AreaLight.ForwardFacing.PositiveZ) ? 1.0f : -1.0f); + Handles.DrawLine(light.transform.position, light.transform.position + normal); } Handles.color = new Color(255.0f / 255.0f, 165.0f / 255.0f, 0.0f / 255.0f); // Orange. diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs index 85e6d0e0..c7c61d44 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs @@ -21,6 +21,7 @@ public partial class AreaLight : BaseLight, IComparable private static readonly float[,] offsets = new float[4, 2] { { 1, 1 }, { 1, -1 }, { -1, -1 }, { -1, 1 } }; private const int lutResolution = 64; private const int lutMatrixDim = 3; + private static readonly Matrix4x4 rotation180Up = Matrix4x4.Rotate(Quaternion.AngleAxis(180.0f, Vector3.up)); private static Texture2D transformInvTextureSpecular; private static Texture2D transformInvTextureDiffuse; @@ -89,6 +90,25 @@ public Vector2 Size set => size = value; } + public enum ForwardFacing + { + PositiveZ, + NegativeZ, + } + + [Tooltip("The forward direction of the light.")] + [SerializeField] + private ForwardFacing facing = ForwardFacing.PositiveZ; + + /// + /// The forward direction of the light. + /// + public ForwardFacing Facing + { + get => facing; + set => facing = value; + } + [Tooltip("Optional texture to use instead of a solid color.")] [SerializeField] private Texture cookie; @@ -367,13 +387,21 @@ protected override void UpdateLights(bool forceUpdate = false) // A little bit of bias to prevent the light from lighting itself. const float z = 0.01f; - Matrix4x4 lightVerts = new Matrix4x4(); + var localToWorld = light.transform.localToWorldMatrix; + + if (light.facing == ForwardFacing.NegativeZ) + { + localToWorld *= rotation180Up; + } + + var lightVerts = new Matrix4x4(); + for (int v = 0; v < 4; ++v) { Vector3 vertex = new Vector3(light.size.x * offsets[v, 0], light.size.y * offsets[v, 1], z) * 0.5f; - lightVerts.SetRow(v, light.transform.TransformPoint(vertex)); + lightVerts.SetRow(v, localToWorld.MultiplyPoint(vertex)); } areaLightVerts[i] = lightVerts; @@ -506,6 +534,7 @@ private void UpdateLightSourceVisual() lightSourceVisual.sharedMaterial.color = Color; lightSourceVisual.sharedMaterial.mainTexture = drawLightSourceCookie ? drawLightSourceCookie : cookie; + lightSourceVisual.sharedMaterial.SetFloat("_facing", (float)facing); lightSourceVisual.transform.localScale = new Vector3(size.x, size.y, 1.0f); } else diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/Shaders/AreaLightVisualize.shader b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/Shaders/AreaLightVisualize.shader index 3eea9e10..de9b1d14 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/Shaders/AreaLightVisualize.shader +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/Shaders/AreaLightVisualize.shader @@ -41,6 +41,7 @@ Shader "Hidden/Graphics Tools/Experimental/Area Light Visualize" CBUFFER_START(UnityPerMaterial) fixed4 _Color; float4 _MainTex_ST; + float _facing; CBUFFER_END v2f vert (appdata_t input) @@ -55,6 +56,7 @@ Shader "Hidden/Graphics Tools/Experimental/Area Light Visualize" fixed4 frag (v2f input, bool facing : SV_IsFrontFace) : SV_Target { + facing = _facing ? !facing : facing; fixed4 output = facing ? tex2D(_MainTex, input.texcoord) : fixed4(0.05, 0.05, 0.05, 1.0); UNITY_OPAQUE_ALPHA(output.a); return output * _Color; From 69e338745fda2222f523af7f74f0f308dd5de20a Mon Sep 17 00:00:00 2001 From: Cameron Micka Date: Thu, 3 Apr 2025 12:10:12 -0700 Subject: [PATCH 10/13] Add logic to flip the cookie UV.y. --- .../CHANGELOG.md | 6 +++ .../Experimental/AreaLight/AreaLight.cs | 46 +++++++++++++------ .../AreaLight/Shaders/AreaLight.hlsl | 2 +- .../package.json | 2 +- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/com.microsoft.mrtk.graphicstools.unity/CHANGELOG.md b/com.microsoft.mrtk.graphicstools.unity/CHANGELOG.md index 0cbe4b47..d3d2d601 100644 --- a/com.microsoft.mrtk.graphicstools.unity/CHANGELOG.md +++ b/com.microsoft.mrtk.graphicstools.unity/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). +## [0.8.4] - 2025-04-03 + +### Changed + +- Added more properties to the experimental AreaLight component. + ## [0.8.3] - 2025-03-26 ### Changed diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs index c7c61d44..74bf162f 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs @@ -27,15 +27,16 @@ public partial class AreaLight : BaseLight, IComparable private static Texture2D transformInvTextureDiffuse; private static Texture2D ampDiffAmpSpecFresnel; + private static int lastAreaLightUpdate = -1; private static List activeAreaLights = new(maxAreaLights); private static List activeAreaLightsSorted = new(maxAreaLights); private static Vector4[] areaLightData = new Vector4[areaLightDataSize * areaLightCount]; private static Matrix4x4[] areaLightVerts = new Matrix4x4[areaLightCount]; private static Texture[] areaLightCookies = new Texture[areaLightCount]; - private static int _AreaLightDataID; - private static int _AreaLightVertsID; - private static int[] _AreaLightCookiesIDs = new int[areaLightCount]; - private static int lastAreaLightUpdate = -1; + private static int areaLightDataID; + private static int areaLightVertsID; + private static int[] areaLightCookiesIDs = new int[areaLightCount]; + private static int facingID; private static CullingGroup cullingGroup; private static BoundingSphere[] boundingSpheres = new BoundingSphere[maxAreaLights]; @@ -122,6 +123,19 @@ public Texture Cookie set => cookie = value; } + [Tooltip("Should the texture UV coordinate convention for this cookie have Y starting at the top of the image.")] + [SerializeField] + private bool cookieUVStartsAtTop = true; + + /// + /// Should the texture UV coordinate convention for this cookie have Y starting at the top of the image. + /// + public bool CookieUVStartsAtTop + { + get => cookieUVStartsAtTop; + set => cookieUVStartsAtTop = value; + } + [Tooltip("Should the area light have a visualization?")] [SerializeField] private bool drawLightSource = true; @@ -235,14 +249,16 @@ public Camera CullingGroupCamera /// protected override void Initialize() { - _AreaLightDataID = Shader.PropertyToID("_AreaLightData"); - _AreaLightVertsID = Shader.PropertyToID("_AreaLightVerts"); + areaLightDataID = Shader.PropertyToID("_AreaLightData"); + areaLightVertsID = Shader.PropertyToID("_AreaLightVerts"); - for (int i = 0; i < _AreaLightCookiesIDs.Length; ++i) + for (int i = 0; i < areaLightCookiesIDs.Length; ++i) { - _AreaLightCookiesIDs[i] = Shader.PropertyToID($"_AreaLightCookie{i}"); + areaLightCookiesIDs[i] = Shader.PropertyToID($"_AreaLightCookie{i}"); } + facingID = Shader.PropertyToID("_facing"); + CreateLUTs(); UpdateLightSourceVisual(); @@ -382,7 +398,11 @@ protected override void UpdateLights(bool forceUpdate = false) if (light) { - areaLightData[dataIndex] = light.Color; + var color = light.Color; + areaLightData[dataIndex] = new Vector4(color.r, + color.g, + color.b, + light.cookieUVStartsAtTop ? 1.0f : 0.0f); // A little bit of bias to prevent the light from lighting itself. const float z = 0.01f; @@ -425,13 +445,13 @@ protected override void UpdateLights(bool forceUpdate = false) } } - Shader.SetGlobalVectorArray(_AreaLightDataID, areaLightData); - Shader.SetGlobalMatrixArray(_AreaLightVertsID, areaLightVerts); + Shader.SetGlobalVectorArray(areaLightDataID, areaLightData); + Shader.SetGlobalMatrixArray(areaLightVertsID, areaLightVerts); // There is no SetGlobalTextureArray so pass in 1 by 1. for (int i = 0; i < areaLightCookies.Length; ++i) { - Shader.SetGlobalTexture(_AreaLightCookiesIDs[i], areaLightCookies[i]); + Shader.SetGlobalTexture(areaLightCookiesIDs[i], areaLightCookies[i]); } lastAreaLightUpdate = Time.frameCount; @@ -534,7 +554,7 @@ private void UpdateLightSourceVisual() lightSourceVisual.sharedMaterial.color = Color; lightSourceVisual.sharedMaterial.mainTexture = drawLightSourceCookie ? drawLightSourceCookie : cookie; - lightSourceVisual.sharedMaterial.SetFloat("_facing", (float)facing); + lightSourceVisual.sharedMaterial.SetFloat(facingID, (float)facing); lightSourceVisual.transform.localScale = new Vector3(size.x, size.y, 1.0f); } else diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/Shaders/AreaLight.hlsl b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/Shaders/AreaLight.hlsl index 6a954f05..0404df79 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/Shaders/AreaLight.hlsl +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/Shaders/AreaLight.hlsl @@ -257,7 +257,7 @@ half3 SampleDiffuseFilteredTexture(in int lightIndex, in float4x3 L) float3 V2_ = V2 - V1 * dot_V1_V2 * inv_dot_V1_V1; float2 Puv; Puv.x = dot(V2_, P) / dot(V2_, V2_); - Puv.y = 1 - (dot(V1, P) * inv_dot_V1_V1 - dot_V1_V2 * inv_dot_V1_V1 * Puv.x); + Puv.y = abs(_AreaLightData[lightIndex].a - (dot(V1, P) * inv_dot_V1_V1 - dot_V1_V2 * inv_dot_V1_V1 * Puv.x)); float2 uv = float2(0.125, 0.125) + 0.75 * Puv; // TODO - [Cameron-Micka] calculate mip level based on distance to area light if the texture has pre-filtered mip levels. diff --git a/com.microsoft.mrtk.graphicstools.unity/package.json b/com.microsoft.mrtk.graphicstools.unity/package.json index 6629e114..ef957935 100644 --- a/com.microsoft.mrtk.graphicstools.unity/package.json +++ b/com.microsoft.mrtk.graphicstools.unity/package.json @@ -1,6 +1,6 @@ { "name": "com.microsoft.mrtk.graphicstools.unity", - "version": "0.8.3", + "version": "0.8.4", "displayName": "MRTK Graphics Tools", "description": "Graphics tools and components for developing Mixed Reality applications in Unity.", "documentationUrl": "https://aka.ms/mrtk3graphics", From 3eff470605e704c5d7511d534da3d96758dae36d Mon Sep 17 00:00:00 2001 From: Cameron Micka Date: Thu, 3 Apr 2025 13:14:03 -0700 Subject: [PATCH 11/13] Adding top edge rotation bias. --- .../Experimental/AreaLight/AreaLight.cs | 53 +++++++++++++++---- .../Shaders/AreaLightVisualize.shader | 6 ++- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs index 74bf162f..491080be 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs @@ -37,6 +37,7 @@ public partial class AreaLight : BaseLight, IComparable private static int areaLightVertsID; private static int[] areaLightCookiesIDs = new int[areaLightCount]; private static int facingID; + private static int uvStartsAtTopID; private static CullingGroup cullingGroup; private static BoundingSphere[] boundingSpheres = new BoundingSphere[maxAreaLights]; @@ -110,6 +111,19 @@ public ForwardFacing Facing set => facing = value; } + [Tooltip("Artificially rotates the top edge of the area light to reflect \"better\" on perpendicular surfaces.")] + [SerializeField, Range(0.0f, 180.0f)] + private float topEdgeRotationBias = 0.0f; + + /// + /// Artificially rotates the top edge of the area light to reflect "better" on perpendicular surfaces. + /// + public float TopEdgeRotationBias + { + get => topEdgeRotationBias; + set => topEdgeRotationBias = Mathf.Clamp(value, 0.0f, 180.0f); + } + [Tooltip("Optional texture to use instead of a solid color.")] [SerializeField] private Texture cookie; @@ -258,6 +272,7 @@ protected override void Initialize() } facingID = Shader.PropertyToID("_facing"); + uvStartsAtTopID = Shader.PropertyToID("_uvStartsAtTop"); CreateLUTs(); UpdateLightSourceVisual(); @@ -404,9 +419,7 @@ protected override void UpdateLights(bool forceUpdate = false) color.b, light.cookieUVStartsAtTop ? 1.0f : 0.0f); - // A little bit of bias to prevent the light from lighting itself. - const float z = 0.01f; - + var lightVerts = new Matrix4x4(); var localToWorld = light.transform.localToWorldMatrix; if (light.facing == ForwardFacing.NegativeZ) @@ -414,14 +427,21 @@ protected override void UpdateLights(bool forceUpdate = false) localToWorld *= rotation180Up; } - var lightVerts = new Matrix4x4(); - - for (int v = 0; v < 4; ++v) + // Small optimization to calculate the rotation bias if we don't need to. + if (topEdgeRotationBias != 0.0f) { - Vector3 vertex = new Vector3(light.size.x * offsets[v, 0], - light.size.y * offsets[v, 1], - z) * 0.5f; - lightVerts.SetRow(v, localToWorld.MultiplyPoint(vertex)); + lightVerts.SetRow(0, TransformVertex(0, light.size, localToWorld)); + lightVerts.SetRow(1, TransformVertex(1, light.size, localToWorld)); + lightVerts.SetRow(2, TransformVertex(2, light.size, localToWorld)); + lightVerts.SetRow(3, TransformVertex(3, light.size, localToWorld)); + } + else + { + var localToWorldBias = localToWorld * Matrix4x4.Rotate(Quaternion.AngleAxis(light.topEdgeRotationBias, Vector3.right)); + lightVerts.SetRow(0, TransformVertex(0, light.size, localToWorldBias)); + lightVerts.SetRow(1, TransformVertex(1, light.size, localToWorld)); + lightVerts.SetRow(2, TransformVertex(2, light.size, localToWorld)); + lightVerts.SetRow(3, TransformVertex(3, light.size, localToWorldBias)); } areaLightVerts[i] = lightVerts; @@ -515,6 +535,18 @@ private void OnDrawGizmos() } #endif + private static Vector3 TransformVertex(int index, Vector2 size, Matrix4x4 localToWorld) + { + // A little bit of bias to prevent the light from lighting itself. + const float z = 0.01f; + + var vertex = new Vector3(size.x * offsets[index, 0], + size.y * offsets[index, 1], + z) * 0.5f; + + return localToWorld.MultiplyPoint(vertex); + } + private static void CreateLUTs() { if (transformInvTextureDiffuse == null) @@ -555,6 +587,7 @@ private void UpdateLightSourceVisual() lightSourceVisual.sharedMaterial.color = Color; lightSourceVisual.sharedMaterial.mainTexture = drawLightSourceCookie ? drawLightSourceCookie : cookie; lightSourceVisual.sharedMaterial.SetFloat(facingID, (float)facing); + lightSourceVisual.sharedMaterial.SetFloat(uvStartsAtTopID, cookieUVStartsAtTop ? 0.0f : 1.0f); lightSourceVisual.transform.localScale = new Vector3(size.x, size.y, 1.0f); } else diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/Shaders/AreaLightVisualize.shader b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/Shaders/AreaLightVisualize.shader index de9b1d14..2cab42b4 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/Shaders/AreaLightVisualize.shader +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/Shaders/AreaLightVisualize.shader @@ -42,6 +42,7 @@ Shader "Hidden/Graphics Tools/Experimental/Area Light Visualize" fixed4 _Color; float4 _MainTex_ST; float _facing; + float _uvStartsAtTop; CBUFFER_END v2f vert (appdata_t input) @@ -57,7 +58,10 @@ Shader "Hidden/Graphics Tools/Experimental/Area Light Visualize" fixed4 frag (v2f input, bool facing : SV_IsFrontFace) : SV_Target { facing = _facing ? !facing : facing; - fixed4 output = facing ? tex2D(_MainTex, input.texcoord) : fixed4(0.05, 0.05, 0.05, 1.0); + float2 texcoord = input.texcoord; + texcoord.x = abs(_facing - texcoord.x); + texcoord.y = abs(_uvStartsAtTop - texcoord.y); + fixed4 output = facing ? tex2D(_MainTex, texcoord) : fixed4(0.05, 0.05, 0.05, 1.0); UNITY_OPAQUE_ALPHA(output.a); return output * _Color; } From a048bf3cb93e0be0651afa6ad4de1b21d6f24a3f Mon Sep 17 00:00:00 2001 From: Cameron Micka Date: Thu, 3 Apr 2025 14:48:53 -0700 Subject: [PATCH 12/13] Fix optmization check. --- .../Runtime/Experimental/AreaLight/AreaLight.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs index 491080be..75c800da 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs @@ -428,7 +428,7 @@ protected override void UpdateLights(bool forceUpdate = false) } // Small optimization to calculate the rotation bias if we don't need to. - if (topEdgeRotationBias != 0.0f) + if (Mathf.Approximately(light.topEdgeRotationBias, 0.0f)) { lightVerts.SetRow(0, TransformVertex(0, light.size, localToWorld)); lightVerts.SetRow(1, TransformVertex(1, light.size, localToWorld)); From d8902c78a5cb74f596fb3187134bde5e974f6c40 Mon Sep 17 00:00:00 2001 From: Cameron Micka Date: Thu, 3 Apr 2025 17:26:28 -0700 Subject: [PATCH 13/13] Better cookie sampling. --- .../Experimental/AreaLight/AreaLight.cs | 29 +-- .../AreaLight/AreaLightCookieFilter.cs | 4 +- .../AreaLight/Shaders/AreaLight.hlsl | 182 +++++++++--------- 3 files changed, 100 insertions(+), 115 deletions(-) diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs index 75c800da..6f86168f 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLight.cs @@ -111,19 +111,6 @@ public ForwardFacing Facing set => facing = value; } - [Tooltip("Artificially rotates the top edge of the area light to reflect \"better\" on perpendicular surfaces.")] - [SerializeField, Range(0.0f, 180.0f)] - private float topEdgeRotationBias = 0.0f; - - /// - /// Artificially rotates the top edge of the area light to reflect "better" on perpendicular surfaces. - /// - public float TopEdgeRotationBias - { - get => topEdgeRotationBias; - set => topEdgeRotationBias = Mathf.Clamp(value, 0.0f, 180.0f); - } - [Tooltip("Optional texture to use instead of a solid color.")] [SerializeField] private Texture cookie; @@ -427,21 +414,9 @@ protected override void UpdateLights(bool forceUpdate = false) localToWorld *= rotation180Up; } - // Small optimization to calculate the rotation bias if we don't need to. - if (Mathf.Approximately(light.topEdgeRotationBias, 0.0f)) - { - lightVerts.SetRow(0, TransformVertex(0, light.size, localToWorld)); - lightVerts.SetRow(1, TransformVertex(1, light.size, localToWorld)); - lightVerts.SetRow(2, TransformVertex(2, light.size, localToWorld)); - lightVerts.SetRow(3, TransformVertex(3, light.size, localToWorld)); - } - else + for (int v = 0; v < 4; ++v) { - var localToWorldBias = localToWorld * Matrix4x4.Rotate(Quaternion.AngleAxis(light.topEdgeRotationBias, Vector3.right)); - lightVerts.SetRow(0, TransformVertex(0, light.size, localToWorldBias)); - lightVerts.SetRow(1, TransformVertex(1, light.size, localToWorld)); - lightVerts.SetRow(2, TransformVertex(2, light.size, localToWorld)); - lightVerts.SetRow(3, TransformVertex(3, light.size, localToWorldBias)); + lightVerts.SetRow(v, TransformVertex(v, light.size, localToWorld)); } areaLightVerts[i] = lightVerts; diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLightCookieFilter.cs b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLightCookieFilter.cs index c1532e48..063de233 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLightCookieFilter.cs +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/AreaLightCookieFilter.cs @@ -59,7 +59,7 @@ public Material CookieFilterMaterial [Tooltip("How many blur passes to perform during Dual blurring.")] [SerializeField] - [Range(2, 7)] + [Range(0, 7)] private int blurPasses = 3; /// @@ -68,7 +68,7 @@ public Material CookieFilterMaterial public int BlurPasses { get => blurPasses; - set => blurPasses = Mathf.Clamp(value, 2, 7); + set => blurPasses = Mathf.Clamp(value, 0, 7); } /// diff --git a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/Shaders/AreaLight.hlsl b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/Shaders/AreaLight.hlsl index 0404df79..d7baef2f 100644 --- a/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/Shaders/AreaLight.hlsl +++ b/com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight/Shaders/AreaLight.hlsl @@ -10,15 +10,15 @@ #define AREA_LIGHT_COUNT 2 #define AREA_LIGHT_DATA_SIZE 1 -#define AREA_LIGHT_ENABLE_DIFFUSE 0 +//#define AREA_LIGHT_ENABLE_DIFFUSE /// /// Global properties. /// -#if AREA_LIGHT_ENABLE_DIFFUSE +#if defined(AREA_LIGHT_ENABLE_DIFFUSE) sampler2D _TransformInvDiffuse; -#endif +#endif // AREA_LIGHT_ENABLE_DIFFUSE sampler2D _TransformInvSpecular; sampler2D _AmpDiffAmpSpecFresnel; @@ -33,19 +33,81 @@ float4x4 _AreaLightVerts[AREA_LIGHT_COUNT]; /// Lighting methods. /// -float IntegrateEdge(in float3 v1, in float3 v2) +bool RayPlaneIntersect(float3 direction, float3 origin, float4 plane, out float t) { - float cosTheta = dot(v1, v2); - float theta = acos(cosTheta); - float cross = (v1.x * v2.y - v1.y * v2.x); - return cross * ((theta > 0.001) ? theta / sin(theta) : 1.0); + t = -dot(plane, float4(origin, 1.0)) / dot(plane.xyz, direction); + return t > 0.0; } - -float PolygonRadiance(in float4x3 L) + +half4 SampleAreaLightCookie(in int lightIndex, in float2 uv) +{ +#if defined(_AREA_LIGHTS_ACTIVE) + [forcecase] + switch (lightIndex) + { + case 0: + return tex2D(_AreaLightCookie0, uv); + case 1: + return tex2D(_AreaLightCookie1, uv); + default: + return half4(1, 1, 1, 1); + } +#else + return tex2D(_AreaLightCookie0, uv); +#endif // _AREA_LIGHTS_ACTIVE +} + +half3 SampleDiffuseFilteredTexture(in int lightIndex, in float4x3 L, float3 direction) +{ + float3 p1 = L[0]; + float3 p2 = L[1]; + float3 p3 = L[2]; + float3 p4 = L[3]; + + // Area light plane basis. + float3 V1 = p2 - p1; + float3 V2 = p4 - p1; + float3 planeOrtho = cross(V1, V2); + float planeAreaSquared = dot(planeOrtho, planeOrtho); + + float4 plane = float4(planeOrtho, -dot(planeOrtho, p1)); + float planeDist; + RayPlaneIntersect(direction, 0, plane, planeDist); + + float3 P = planeDist * direction - p1; + + // Find tex coords of P. + float dot_V1_V2 = dot(V1, V2); + float inv_dot_V1_V1 = 1.0 / dot(V1, V1); + float3 V2_ = V2 - V1 * dot_V1_V2 * inv_dot_V1_V1; + float2 uv; + uv.x = dot(V2_, P) / dot(V2_, V2_); + uv.y = abs(_AreaLightData[lightIndex].a - (dot(V1, P) * inv_dot_V1_V1 - dot_V1_V2 * inv_dot_V1_V1 * uv.x)); + + return SampleAreaLightCookie(lightIndex, uv).rgb; +} + +float3 IntegrateEdge(in float3 v1, in float3 v2) +{ + float x = dot(v1, v2); + float y = abs(x); + + float a = 0.8543985 + (0.4965155 + 0.0145206 * y) * y; + float b = 3.4175940 + (4.1616724 + y) * y; + float v = a / b; + + float theta_sintheta = (x > 0.0) ? v : 0.5 * rsqrt(max(1.0 - x * x, 1e-7)) - v; + + return cross(v1, v2) * theta_sintheta; +} + +float4 PolygonRadiance(in int lightIndex, in float4x3 L) { // Baum's equation // Expects non-normalized vertex positions + float4x3 unclippedL = L; + // Detect clipping config. uint config = 0; if (L[0].z > 0) { config += 1; } @@ -180,9 +242,9 @@ float PolygonRadiance(in float4x3 L) L4 = normalize(L4); } } - + // Integrate. - float sum = 0; + float3 sum = 0; sum += IntegrateEdge(L[0], L[1]); sum += IntegrateEdge(L[1], L[2]); sum += IntegrateEdge(L[2], L[3]); @@ -196,13 +258,16 @@ float PolygonRadiance(in float4x3 L) { sum += IntegrateEdge(L4, L[0]); } - - sum *= 0.15915; // 1/2pi - - return max(0, sum); + + float3 direction = normalize(sum); + return float4(max(0, sum.z * 0.15915) * SampleDiffuseFilteredTexture(lightIndex, unclippedL, direction), direction.z); } - -float TransformedPolygonRadiance(in float4x3 L, in float2 uv, in sampler2D transformInv, in float amplitude) + +half4 TransformedPolygonRadiance(in int lightIndex, + in float4x3 L, + in float2 uv, + in sampler2D transformInv, + in float amplitude) { // Get the inverse LTC matrix M. float3x3 Minv = 0; @@ -213,59 +278,7 @@ float TransformedPolygonRadiance(in float4x3 L, in float2 uv, in sampler2D trans float4x3 LTransformed = mul(L, Minv); // Polygon radiance in transformed configuration - specular. - return PolygonRadiance(LTransformed) * amplitude; -} - -half4 SampleAreaLightCookie(in int lightIndex, in float2 uv) -{ -#if defined(_AREA_LIGHTS_ACTIVE) - [forcecase] - switch (lightIndex) - { - case 0: - return tex2D(_AreaLightCookie0, uv); - case 1: - return tex2D(_AreaLightCookie1, uv); - default: - return half4(1, 1, 1, 1); - } -#else - return tex2D(_AreaLightCookie0, uv); -#endif // _AREA_LIGHTS_ACTIVE -} - -half3 SampleDiffuseFilteredTexture(in int lightIndex, in float4x3 L) -{ - float3 p1_ = L[0]; - float3 p2_ = L[1]; - float3 p3_ = L[2]; - float3 p4_ = L[3]; - - // Area light plane basis. - float3 V1 = p2_ - p1_; - float3 V2 = p4_ - p1_; - float3 planeOrtho = (cross(V1, V2)); - float planeAreaSquared = dot(planeOrtho, planeOrtho); - float planeDistxPlaneArea = dot(planeOrtho, p1_); - - // Orthonormal projection of (0,0,0) in area light space. - float3 P = planeDistxPlaneArea * planeOrtho / planeAreaSquared - p1_; - - // Find tex coords of P. - float dot_V1_V2 = dot(V1, V2); - float inv_dot_V1_V1 = 1.0 / dot(V1, V1); - float3 V2_ = V2 - V1 * dot_V1_V2 * inv_dot_V1_V1; - float2 Puv; - Puv.x = dot(V2_, P) / dot(V2_, V2_); - Puv.y = abs(_AreaLightData[lightIndex].a - (dot(V1, P) * inv_dot_V1_V1 - dot_V1_V2 * inv_dot_V1_V1 * Puv.x)); - float2 uv = float2(0.125, 0.125) + 0.75 * Puv; - - // TODO - [Cameron-Micka] calculate mip level based on distance to area light if the texture has pre-filtered mip levels. - //float d = abs(planeDistxPlaneArea) / pow(planeAreaSquared, 0.75); - //float w = log(1024.0 * d) / log(6.0); // TODO get texture size. - //return tex2Dlod(texLightFiltered, float4(uv.x, uv.y, 0, w)).rgb; - - return SampleAreaLightCookie(lightIndex, uv).rgb; + return PolygonRadiance(lightIndex, LTransformed) * float4(amplitude.xxx, 1); } void CalculateAreaLight(in float3 worldPosition, @@ -292,9 +305,6 @@ void CalculateAreaLight(in float3 worldPosition, float4x3 L; L = (float4x3)_AreaLightVerts[lightIndex] - float4x3(worldPosition, worldPosition, worldPosition, worldPosition); L = mul(L, transpose(basis)); - - // TODO - [Cameron-Micka] disable if no texture? - half3 textureColor = SampleDiffuseFilteredTexture(lightIndex, L); // UVs for sampling the LUTs. float theta = acos(dot(V, worldNormal)); @@ -303,16 +313,16 @@ void CalculateAreaLight(in float3 worldPosition, half3 AmpDiffAmpSpecFresnel = tex2D(_AmpDiffAmpSpecFresnel, uv).rgb; half3 result = 0; -#if AREA_LIGHT_ENABLE_DIFFUSE - half diffuseTerm = TransformedPolygonRadiance(L, uv, _TransformInvDiffuse, AmpDiffAmpSpecFresnel.x); +#if defined(AREA_LIGHT_ENABLE_DIFFUSE) + half3 diffuseTerm = TransformedPolygonRadiance(lightIndex, L, uv, _TransformInvDiffuse, AmpDiffAmpSpecFresnel.x); result = diffuseTerm * baseColor; -#endif +#endif // AREA_LIGHT_ENABLE_DIFFUSE - half specularTerm = TransformedPolygonRadiance(L, uv, _TransformInvSpecular, AmpDiffAmpSpecFresnel.y); - half fresnelTerm = (half) (specularColor + (1.0 - specularColor) * AmpDiffAmpSpecFresnel.z); + half3 specularTerm = TransformedPolygonRadiance(lightIndex, L, uv, _TransformInvSpecular, AmpDiffAmpSpecFresnel.y); + half3 fresnelTerm = (half) (specularColor + (1.0 - specularColor) * AmpDiffAmpSpecFresnel.z); result += specularTerm * fresnelTerm * 3.14159265359; // Pi. - output = result * _AreaLightData[lightIndex].rgb * textureColor; + output = result * _AreaLightData[lightIndex].rgb; } /// @@ -360,12 +370,12 @@ void CalculateAreaLights(in float3 worldPosition, /// Entry point, call this from Shader Graph (half precision). /// void CalculateAreaLights_half(in float3 worldPosition, - in float3 worldCameraPosition, - in float3 worldNormal, - in half3 baseColor, - in half3 specularColor, - in half smoothness, - out half3 output) + in float3 worldCameraPosition, + in float3 worldNormal, + in half3 baseColor, + in half3 specularColor, + in half smoothness, + out half3 output) { CalculateAreaLights(worldPosition, worldCameraPosition,