Skip to content
pblucPublic

About

Research project from Columbia's CGUI Lab. Magic Leap 2 app that measures how bright the real world is behind virtual objects and dims just those areas so they stay visible.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

Repository files navigation

SegDimmer

Selectively (de)emphasizing physical-world content in AR

SegDimmer is an augmented reality (AR) tool that selectively (de)emphasizes physical-world content for task guidance. Using the camera stream and Segmented Dimming capabilities of the Magic Leap 2 headset, it analyzes the luminance of the incoming environment and adjusts how much real-world light is blocked behind virtual content, so that content stays visible in bright surroundings. It is built in Unity with the Magic Leap Unity SDK's MLCamera and Segmented Dimming features.

Demo video: https://www.youtube.com/watch?v=ntrazod3MHA

Authors: Daniel Hu and Patricia Luc
Advisor: Bettina Schlager
Built for COMS E6998 (Topics in VR and AR) at Columbia University.


The problem

AR headsets render virtual content by adding light to what you already see. That works until the real environment is too bright: a sunny window or a bright lamp can wash out virtual objects. Making the content darker doesn't help, because an additive display can't remove light that's already reaching your eyes.

For AR task guidance, this is a practical problem. A guidance system that works in a controlled lab also has to handle changing real-world conditions, and lighting is one of the most common.

Segmented dimming on Magic Leap 2

The Magic Leap 2 adds a low-resolution dimmer panel that can block environmental light before it reaches the display. It offers two modes:

  • Global Dimming applies a single tint across the whole display, dimming the entire real-world view.
  • Segmented Dimming dims only specific parts of the display, so selected virtual content appears more opaque without tinting everything else.

SegDimmer uses Segmented Dimming. It dims only where a virtual object is, and only as much as the lighting behind that object requires.

How it works

SegDimmer runs a five-stage pipeline:

 ┌─────────────────┐   ┌──────────────────┐   ┌───────────────────┐   ┌──────────────────┐   ┌──────────────────┐
 │ 1. Camera stream│──▶│ 2. Grab RGB frame│──▶│ 3. 2D bounding box│──▶│ 4. Avg. luminance│──▶│ 5. Apply dimming │
 │  (ML2 camera)   │   │  every 100 ms    │   │  of virtual object│   │  of that region  │   │  mask opacity    │
 └─────────────────┘   └──────────────────┘   └───────────────────┘   └──────────────────┘   └──────────────────┘
  1. Retrieve the camera stream. The app waits until the Magic Leap 2 Main camera is available, then connects to it with MLCamera. The Main camera is used instead of the CV camera because the pixel work here is light. The stream is configured for RGBA_8888 video at 30 fps, using the supported resolution closest to 1280×720.

  2. Grab the RGB frame. A raw-frame callback flips each frame vertically, strips any row padding, and loads it into a Texture2D. Every 100 ms, the latest frame is copied for processing. The interval started at 2 seconds but was shortened so the dimming reacts almost immediately.

  3. Find the object's 2D bounding box. The eight corners of the target object's BoxCollider are projected from world space to screen space with Unity's virtual camera (Camera.WorldToScreenPoint). The min/max of those points gives the bounding rectangle. Processing only runs while the object is in front of the camera.

  4. Analyze luminance. For each pixel in the bounding box, relative luminance is computed from its linear RGB components:

    $$Y = 0.2126,R + 0.7152,G + 0.0722,B$$

    The result is averaged across the region into a single value from 0 (dark) to 1 (bright), and written to an in-scene debug log.

  5. Apply Segmented Dimming. The average luminance is written to the _DimmingValue property of the object's segmented dimming mask material. Brighter surroundings produce a more opaque mask, which keeps the object readable.

Segmented dimming masks

Segmented Dimming works through mask objects. Each virtual object that should be dimmed has a matching mask with the same position and orientation. SegDimmer was tested on three objects:

Object Mask shape
Cube Sphere
Sign with text ("Happy Holidays!") Rectangular box
Christmas tree model Same mesh as the tree

The mask's scale changes the look: a slightly smaller mask gives the object translucent edges, and a larger mask adds an opaque halo around it.

Requirements

  • Hardware: Magic Leap 2 headset, with Segmented Dimming enabled in the device settings
  • Unity: 2022.2.0f1
  • Packages (declared in Packages/manifest.json):
    • Magic Leap Unity SDK com.magicleap.unitysdk 1.12.1 (from the Magic Leap scoped registry)
    • Universal Render Pipeline 14.0.4
    • TextMeshPro 3.0.6
    • XR Interaction Toolkit 2.1.1, pulled in by the Magic Leap SDK and used for the XR rig and grab interactions
  • Build target: Android (Magic Leap 2)
  • Permissions: android.permission.CAMERA, already declared in Assets/Plugins/Android/AndroidManifest.xml

Getting started

  1. Clone the repository:
    git clone https://github.com/pbluc/SegDimmer.git
  2. Open the project in Unity Hub with Unity 2022.2.0f1. The Magic Leap SDK and other packages resolve on first open.
  3. If prompted, run the Magic Leap Setup Tool (com.magicleap.setuptool, included in Packages/). It checks the build target, graphics API, color space and other project settings for Magic Leap 2.
  4. Open File → Build Settings, make sure Assets/Scenes/DimCube.unity is enabled, and set the platform to Android.
  5. On the headset, turn on Segmented Dimming in the device settings.
  6. Connect the Magic Leap 2 and choose Build And Run.
  7. Grant camera permission when the app asks. The script assumes the permission has already been granted before it starts capturing.

Using the app

The DimCube scene contains the cube, the holiday sign and the Christmas tree, each with its own segmented dimming mask, plus a UI panel.

  • Tracked object: The luminance analysis follows one target object at a time. In the committed scene, this is the Cube.
  • Luminance log: A scrolling debug panel shows the bounding box, the average luminance of that region (0–1, where values closer to 1 mean a brighter area), and the opacity currently applied to the dimming material.
  • Toggle Dimmer: Turns segmented dimming on or off, so you can compare the dimmed and undimmed views.
  • Moving objects: Objects are grab interactables, so you can reposition them in the room with the controller.

Configuration

The core logic is in Assets/Scripts/Dimming.cs. It is attached to the XR rig in DimCube and exposes these fields in the Inspector:

Field Description
_debugText TextMeshPro text used for the in-scene log
_target The virtual object to track. It must have a BoxCollider.
_dimmingRenderer Renderer of the segmented dimming mask whose _DimmingValue is set
_plane Optional plane that can display the raw camera texture while debugging
_captureWidth / _captureHeight Requested capture resolution (default 1280×720)

Other values you can change in code:

  • _waitTime: frame-processing interval (default 0.1f s)
  • PIXEL_PROCESSING_STRIDE_X / PIXEL_PROCESSING_STRIDE_Y: pixel sampling stride for the luminance loop (default 1). Raise these to trade accuracy for speed.

Project structure

Assets/
├── Scripts/
│   └── Dimming.cs                       # Camera capture, bounding box, luminance analysis, dimming
├── Scenes/
│   ├── DimCube.unity                    # Main SegDimmer scene (enabled in build settings)
│   ├── HelloCube.unity                  # Magic Leap starter scene
│   └── SampleScene.unity                # URP template scene
├── Resources/
│   ├── Canvas.prefab                    # Debug log + Toggle Dimmer UI
│   ├── Cube.prefab
│   ├── Sign.prefab
│   └── Segmented Dimmer.prefab          # Segmented dimming mask
├── Christmas Tree - POLYCRAFT Series/   # Third-party tree model
├── Materials/
├── Plugins/Android/AndroidManifest.xml  # Camera permission
├── XR/, XRI/                            # XR plug-in and Interaction Toolkit settings
└── ...
Packages/
├── manifest.json
└── com.magicleap.setuptool/             # Magic Leap project setup tool
ProjectSettings/

Limitations and future work

  • Use the physical camera for projection. Bounding boxes are currently projected with Unity's virtual camera instead of the Magic Leap 2's physical RGB camera. The offset between the two is small, but projecting with the physical camera's pose and intrinsics would match the captured frame more accurately. Dimming.cs includes an unused helper, WorldToScreenPoint, as a starting point.
  • Match screen points to the capture resolution. Virtual screen coordinates should be rescaled to the captured image's resolution and aspect ratio.
  • Track multiple objects. Only one target object is analyzed at a time. The next step is to track and dim several virtual objects independently.
  • Improve brightness analysis. Replace the plain average with an analysis that accounts for skewed distributions and for thresholds tied to the user or the environment.

Credits

  • Christmas tree model: POLYCRAFT Christmas Tree (Unity Asset Store)
  • Camera capture code is adapted from the Magic Leap developer guide's camera capture walkthrough.

References

  1. Magic Leap, "Camera Capture Walkthrough," Magic Leap Developer Docs. https://developer-docs.magicleap.cloud/docs/guides/unity/camera/camera-capture-walkthrough/
  2. Magic Leap, "MLCamera," Magic Leap Developer Docs. https://developer-docs.magicleap.cloud/docs/guides/features/ml-camera/
  3. "Relative luminance," Wikipedia. https://en.wikipedia.org/wiki/Relative_luminance
  4. Magic Leap, "Segmented Dimming," Magic Leap Developer Docs. https://developer-docs.magicleap.cloud/docs/guides/unity/display/unity-segmented-dimming/

About

Research project from Columbia's CGUI Lab. Magic Leap 2 app that measures how bright the real world is behind virtual objects and dims just those areas so they stay visible.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages