-
Notifications
You must be signed in to change notification settings - Fork 47
Experimental Feature: Area Lights #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Cameron-Micka
merged 49 commits into
microsoft:main
from
Cameron-Micka:user/cameron-micka/area-lights
Mar 26, 2025
Merged
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
79f01d7
Improved 2023 support.
Cameron-Micka 659cb08
Version bump.
Cameron-Micka 76df246
Merge branch 'main' of https://github.com/microsoft/MixedReality-Grap…
Cameron-Micka 5ec9853
Merge branch 'main' of https://github.com/microsoft/MixedReality-Grap…
Cameron-Micka 376d2aa
UNITY_6000_0_OR_NEWER support.
Cameron-Micka 301277c
Convert tabs to spaces.
Cameron-Micka 531a303
Bump package version.
Cameron-Micka 2f979b2
Merge branch 'main' of https://github.com/Cameron-Micka/MixedReality-…
Cameron-Micka 9e4b4a0
Merge branch 'main' of https://github.com/microsoft/MixedReality-Grap…
Cameron-Micka e7443e5
Merge branch 'main' of https://github.com/microsoft/MixedReality-Grap…
Cameron-Micka bc4489a
Project update and remove unneeded deps.
Cameron-Micka 62afd9d
Extra comments.
Cameron-Micka a06e99b
Package update.
Cameron-Micka 25d58bf
Merge branch 'main' of https://github.com/microsoft/MixedReality-Grap…
Cameron-Micka 04ee6d0
WIP real time area lights.
Cameron-Micka 2cfd203
LUTs
Cameron-Micka 4d53168
Pass in shader data.
Cameron-Micka 0b581fd
Working real time area light in forward renderer.
Cameron-Micka d54cc80
Cleanup.
Cameron-Micka 62f42b2
Remove angle.
Cameron-Micka 6a5cfa5
Multi-light support.
Cameron-Micka 946c206
Move to experimental.
Cameron-Micka 30d5626
Add base color.
Cameron-Micka 584e1c1
Light source visualization.
Cameron-Micka e549bba
Animation test.
Cameron-Micka a321dfc
WIP texture based diffuse.
Cameron-Micka 9e54c41
Cleanup.
Cameron-Micka 0cfbf9a
Movie area lights.
Cameron-Micka 674a1c0
Common area light shader include.
Cameron-Micka 7a943ee
Add shader graph example.
Cameron-Micka 468ed7e
Merge branch 'main' of https://github.com/microsoft/MixedReality-Grap…
Cameron-Micka fcc312f
Cleanup wip.
Cameron-Micka 7b3b287
Fixing artifact in area light.
Cameron-Micka ade9aa6
WIP abstarct filtering logic from area light.
Cameron-Micka 20b9b5e
Improved bluring.
Cameron-Micka 80ceb04
Optimize filter.
Cameron-Micka 40fa98a
Remove old video.
Cameron-Micka 0de40fd
WIP light sorting.
Cameron-Micka 9b8e857
Better area light culling.
Cameron-Micka 9f75ef3
Bug fixes.
Cameron-Micka 33f5782
Turns off area light shader calculations when no lights are present.
Cameron-Micka 34c72e0
Keyword optimizations and samples.
Cameron-Micka 550822d
Sample improvements and bug fixes.
Cameron-Micka 1c22264
Fix precision issues.
Cameron-Micka e641fb9
Make shaders a bit easier to use.
Cameron-Micka 4884814
Spacing fixes.
Cameron-Micka 9b497c9
Better handles.
Cameron-Micka cd7cb67
PR feedback.
Cameron-Micka 68c6731
Fix typo.
Cameron-Micka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
com.microsoft.mrtk.graphicstools.unity/Editor/Experimental/AreaLight.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
148 changes: 148 additions & 0 deletions
148
com.microsoft.mrtk.graphicstools.unity/Editor/Experimental/AreaLight/AreaLightInspector.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using UnityEditor; | ||
| using UnityEngine; | ||
|
|
||
| namespace Microsoft.MixedReality.GraphicsTools.Editor | ||
| { | ||
| /// <summary> | ||
| /// Improves object selection and adds a shortcut to create a configured game object and component from the game object context menu. | ||
| /// </summary> | ||
| [CustomEditor(typeof(AreaLight))] | ||
| public class AreaLightInspector : UnityEditor.Editor | ||
| { | ||
| private void OnSceneGUI() | ||
| { | ||
| AreaLight light = target as AreaLight; | ||
|
|
||
| if (light == null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (light.enabled) | ||
| { | ||
| Handles.color = light.Color; | ||
| } | ||
| else | ||
| { | ||
| Handles.color = Color.gray; | ||
| } | ||
|
|
||
| EditorGUI.BeginChangeCheck(); | ||
| Vector2 size = DrawRectHandles(light.transform.rotation, light.transform.position, light.Size); | ||
| if (EditorGUI.EndChangeCheck()) | ||
| { | ||
| Undo.RecordObject(light, "Adjust Area Light Size"); | ||
| light.Size = size; | ||
| } | ||
|
|
||
| // 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); | ||
| } | ||
|
|
||
| Handles.color = new Color(255.0f / 255.0f, 165.0f / 255.0f, 0.0f / 255.0f); // Orange. | ||
|
|
||
| // Different visual representation for runtime and edit mode because runtime using CullingGroup to cull lights. | ||
| if (Application.isPlaying) | ||
| { | ||
| var bounds = light.SphereBoundsWorldSpace; | ||
| Handles.RadiusHandle(Quaternion.identity, bounds.position, bounds.radius); | ||
| } | ||
| else | ||
| { | ||
| var bounds = light.BoundsWorldSpace; | ||
| Handles.DrawWireCube(bounds.center, bounds.size); | ||
| } | ||
|
|
||
| if (light.CullingActive) | ||
| { | ||
| Handles.Label(light.transform.position, $"Visible: {light.IsVisible}\nDist: {light.Distance.ToString("n1")}"); | ||
| } | ||
| } | ||
|
|
||
| private bool HasFrameBounds() { return true; } | ||
|
|
||
| private Bounds OnGetFrameBounds() | ||
| { | ||
| var light = target as AreaLight; | ||
| Debug.Assert(light != null); | ||
| return light.BoundsWorldSpace; | ||
| } | ||
|
|
||
| [MenuItem("GameObject/Light/Graphics Tools/Area Light")] | ||
| private static void CreateAreaLight(MenuCommand menuCommand) | ||
| { | ||
| GameObject gameObject = InspectorUtilities.CreateGameObjectFromMenu<AreaLight>(menuCommand); | ||
|
|
||
| if (gameObject != null) | ||
| { | ||
| gameObject.transform.position = new Vector3(0.0f, 1.0f, 0.0f); | ||
| gameObject.transform.rotation = Quaternion.Euler(0.0f, 180.0f, 0.0f); | ||
| } | ||
| } | ||
|
|
||
| private static float SizeSlider(Vector3 p, Vector3 d, float r) | ||
| { | ||
| Vector3 position = p + d * r; | ||
| float size = HandleUtility.GetHandleSize(position); | ||
| bool temp = GUI.changed; | ||
| GUI.changed = false; | ||
| position = Handles.Slider(position, d, size * 0.03f, Handles.DotHandleCap, 0.0f); | ||
|
|
||
| if (GUI.changed) | ||
| { | ||
| r = Vector3.Dot(position - p, d); | ||
| } | ||
|
|
||
| GUI.changed |= temp; | ||
| return r; | ||
| } | ||
| private static Color ToActiveColorSpace(Color color) | ||
| { | ||
| return (QualitySettings.activeColorSpace == ColorSpace.Linear) ? color.linear : color; | ||
| } | ||
|
|
||
| private static Vector2 DrawRectHandles(Quaternion rotation, Vector3 position, Vector2 size) | ||
| { | ||
| Vector3 up = rotation * Vector3.up; | ||
| Vector3 right = rotation * Vector3.right; | ||
|
|
||
| float halfWidth = 0.5f * size.x; | ||
| float halfHeight = 0.5f * size.y; | ||
|
|
||
| Vector3 topRight = position + up * halfHeight + right * halfWidth; | ||
| Vector3 bottomRight = position - up * halfHeight + right * halfWidth; | ||
| Vector3 bottomLeft = position - up * halfHeight - right * halfWidth; | ||
| Vector3 topLeft = position + up * halfHeight - right * halfWidth; | ||
|
|
||
| // Draw the rectangle. | ||
| Handles.DrawLine(topRight, bottomRight); | ||
| Handles.DrawLine(bottomRight, bottomLeft); | ||
| Handles.DrawLine(bottomLeft, topLeft); | ||
| Handles.DrawLine(topLeft, topRight); | ||
|
|
||
| // Give handles twice the alpha of the lines. | ||
| Color originalColor = Handles.color; | ||
| Color color = Handles.color; | ||
| color.a = Mathf.Clamp01(Handles.color.a * 2); | ||
| Handles.color = ToActiveColorSpace(color); | ||
|
|
||
| // Draw the handles. | ||
| halfHeight = SizeSlider(position, up, halfHeight); | ||
| halfHeight = SizeSlider(position, -up, halfHeight); | ||
| halfWidth = SizeSlider(position, right, halfWidth); | ||
| halfWidth = SizeSlider(position, -right, halfWidth); | ||
|
|
||
| size.x = Mathf.Max(0.0f, 2.0f * halfWidth); | ||
| size.y = Mathf.Max(0.0f, 2.0f * halfHeight); | ||
|
|
||
| Handles.color = originalColor; | ||
|
|
||
| return size; | ||
| } | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
...crosoft.mrtk.graphicstools.unity/Editor/Experimental/AreaLight/AreaLightInspector.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/AreaLight.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.