rust
An Editor You Can Stand Inside: Pulsar's VR Level Editor
How Pulsar edits a level from inside it: the real editor panels copied into GPU textures, one pointer whose line depends only on where it aims, a dock on the off hand, a radial quick menu, an overlay pass that never trails the head, a headset thread that shares one GPU with the desktop editor, and a preview that runs it all with a mouse.
Most level editors that "support VR" mean you can look at your level in a headset and then take the headset off to change anything. We wanted the other thing: stand in the level, point at an object, read its properties, change a number, move the thing with your hand, and undo it, without touching the desk.
The awkward part of that sentence is "read its properties". An editor is mostly panels. A hierarchy, a properties list with sixty-odd fields on a light, a content browser, popovers, search boxes, drag handles. Rebuilding all of that as a second, in-headset UI would mean writing the editor twice and then keeping both copies honest forever. So Pulsar does not. The panels you see in VR are the editor's own panels, pixel for pixel, and clicking one is clicking the real thing.
We build on OpenXR, the Khronos standard that lets one program talk to many headset runtimes, and on wgpu underneath. Our thanks to the people who maintain both, and to the openxr crate's authors. The scene in the pictures is the 2022 remaster of Sponza, commissioned from Frank Meinl and sponsored by Anton Kaplanyan, with its curtains from the add-on package by Katica Putica, Cristiano Siqueira, Timothy Heath, Justin Prazen, Sebastian Herholz, Bruce Cherniak and Anton Kaplanyan, from the Intel Sample Library.
Every picture in this post comes from the editor's desktop preview, which stands in for a headset on a monitor: the editor camera is your head and the mouse is your pointing hand. It runs the same pointer rules, the same panel textures and the same overlay pass as the headset. Section 9 covers how it holds up with a headset on, and what is not built yet.
Introduction: Two Hands and One Level
The idea fits in a paragraph. Your dominant hand points: at panels to use them, at objects to select and move them. Your other hand carries things: a small dock of panel previews above it, and above that one panel at working size. Thumbsticks fly and turn. A ring of common actions opens under your pointing hand when you ask for it. Left-handed people get all of it mirrored.
Here is the whole preview in the full editor window. On the left of the viewport, the Hierarchy panel is in the off hand. The row of three little pictures under it is the dock. The two white rings at the bottom are the hands, and the dashed amber line is the right hand aiming at the point light. In the top right corner is the preview's card, where you choose your dominant hand and where each panel goes.
This post goes from the idea outward: how a docked panel ends up in your hand, how one pointer decides what you mean, what the dock and the quick menu do, how all of it is drawn so it stays glued to your hand, and how a headset thread and a desktop editor share one GPU without breaking it.
1. Where VR Lives in the Engine
Pulsar keeps most features in plugins. VR is deliberately not one of them. It is part of the engine and editor, so that every editor, including one a plugin ships, can build on it. It still lives in crates of its own, and the rest of the engine only gains a few small connections to them.
| Crate | What it holds |
|---|---|
pulsar_vr | The rules: poses, handedness, panels, the hand dock, hit tests, the pointer, grabbing, the radial menu, the desktop camera maths. It depends on glam and nothing else |
pulsar_vr_overlay | What is drawn in the scene: panel quads, lines, rings, and the render pass that draws them |
pulsar_vr_runtime | The headset: making the GPU through OpenXR, the session thread, both eyes, controllers, the room's place in the level. No UI dependency |
ui_vr | What editor UI needs: panels as VR panels, where each one is, forwarding clicks, the quick menu, the toolbar, the desktop preview |
The split matters mostly for the first row. Everything that decides how VR feels, such as what a trigger pull does or how big a dock preview is, is plain geometry in a crate with no GPU and no UI. It can be unit tested with a few vectors: put a panel a metre away, aim a hand at it, pull the trigger, check the events.
2. A Panel in Your Hand Is Still a Panel
Look at these two crops from one frame. The first is the Properties panel hanging in the scene, tilted, in your off hand. The second is the Properties panel docked on the right of the editor window. They are not two panels. The first is a picture of the second.
2.1 Texture export
The editor's UI framework is our fork of GPUI, drawing through wgpu. We gave it one new tool: gpui::TextureExport. You wrap an element in it, and after every frame the window draws, the renderer copies that element's rectangle out of the composed frame into a texture of the export's own, on the same device the level is rendered on.
Copying finished pixels is the whole trick, and it is why this is so cheap and so faithful:
- It holds everything on screen in that rectangle: nested layers, cached views, text, embedded GPU surfaces, even a menu opened over the panel.
- The element renders exactly as it otherwise would. There is no second window, no second UI renderer and no extra layout pass.
- It costs one texture-to-texture copy per exported panel per drawn frame, and nothing while the window is idle.
The copy happens in the same command stream as the frame, and the texture is only published once that work has been submitted, so a consumer never samples a texture whose copy is not on the queue yet. The view handed out samples as linear colour, which is what a shader drawing it into a 3D scene wants. A resize makes a new texture. A lost device throws the old one away.
GPUI's layer cache can also retain textures, and it looks like the natural tool, but it holds one layer's own primitives and refuses a layer with layers inside it. Any real panel has them.
2.2 Input comes for free
Because the pixels sit at a known rectangle in a known window, input needs almost no work. The pointer produces a hit as a uv coordinate on the panel. Pulsar turns that back into a window position and dispatches an ordinary mouse event there:
The panel cannot tell the difference. Hover states, clicks, drags, scrolling and double-clicks work because they are the same code that runs for a mouse. In the next picture, the right hand rests on the Hierarchy panel in the left hand. A trigger pull on the "Point Light" row selects the light, in the hierarchy, in the viewport and in the Properties panel, as one ordinary selection.
2.3 What copying pixels asks in return
The same property that makes it faithful sets its limits. A panel has to be on screen in the editor to be shown. One sitting behind another tab keeps whatever it last showed and takes no input until its tab is in front. In the pictures here the third dock preview, World Settings, is blank for exactly that reason: its tab has not been in front. A menu that opens beyond the panel's rectangle is cut off at the edge. And texture resolution is the panel's size on screen, so a tiny docked panel is a blurry one in your hand.
2.4 Offering your own panel
Any editor, a plugin's included, offers a panel to VR by passing its content through one function when it renders:
The panel stays docked where it was. A panel nobody asks for is not even wrapped. The list of offered panels is a global of the UI framework's App rather than a Rust static, because a plugin loaded as a library has statics of its own, and its panels have to reach the same list as the editor's.
3. One Pointer, No Modes
VR tools love modes: a button for the laser, a button for selection, a menu to switch between them. Pulsar's dominant hand has none. What the line looks like depends only on where it points. Whatever the ray meets first wins:
| The ray meets first | You see | A trigger pull |
|---|---|---|
| A panel | A solid blue line and a cursor on the panel | Uses the panel |
| A selectable object | A dashed amber line and a ring on the surface | Selects it |
| Nothing | Just a hand | Clears the selection |
Colour and dash pattern both differ, so the two read apart at a glance and do not rely on colour alone. A hand that is holding or touching something shows no line at all, because at that moment it is not asking a question.
The rules have a few details that only show up when a real hand does the pointing, and all of them are in the Pointer type:
- A press keeps its panel. Once the trigger goes down on a panel, that panel owns the pointer until it comes up, even if your ray slides off the edge or across an object. Sliders and scrollbars would be unusable otherwise.
- A held trigger does not click what it sweeps onto. Only the moment of pulling counts.
- Edges are sticky. A panel the pointer is already on holds it for 2.5 cm past its edge, so aiming at a border does not flicker. A neighbour you are really on still beats that margin, which is what lets you tell the tiny dock previews apart.
- Nearer wins. An object in front of a panel hides it from the pointer. Panels farther than 6 m are not pointed at.
- You cannot point at what you are holding. The dominant hand ignores panels attached to itself.
3.1 Asking the scene a question
"Is there an object under the ray?" is answered by a CPU ray against the scene's triangles, asked of the viewport's renderer, and that renderer cannot draw while it is answering. In a small level nobody would notice. In a heavy one, asking on every mouse move would eat the frame rate.
So the question is only asked when its answer could have changed (the mouse, the eye or the view moved), never sooner than 33 ms after the last one, and never so often that answering takes more than a twentieth of the renderer's time, however slow the answer is. When nothing moves it is repeated twice a second, because a level can change under a still pointer.
In the preview, there is one more piece of honesty. The pointer is solved along the mouse's own ray from the eye, so what is under the cursor is exactly what is pointed at. Only the drawn line starts at the right hand, down and to the side, which is where your hand would be.
3.2 Selecting is editing
Selecting through the pointer is selecting, full stop. The gizmo appears, the hierarchy highlights, the Properties panel fills in. Here the pointer where I picked one of Sponza's arches (and missed horribly selecting the wall behind it): the outline is the ordinary editor selection, and the panel in the off hand shows its mesh and material slots.
Moving with the grip goes through the same queue the mouse uses, so a carry across the room is one undo step like any drag.
4. The Dock on Your Other Hand
A headset has no screen edges to dock things to, but it has something better: a hand that is always where you left it (It is, after all, attached to you). The off hand carries a row of small previews, one per panel, directly above it, and above the row a main display showing one panel at working size.
The previews are boxes of 6.8 by 5.6 cm, fitted to each panel's shape, and the row sits 4.5 cm above the hand. The whole dock turns about 13 degrees toward the middle of your body, so it faces you instead of facing straight ahead from out at your side.
You switch panels two ways: click the off hand's stick to step to the next one, or point at a preview with the dominant hand and pull the trigger. The shown preview is framed in blue and a pointed-at one in white. On the desktop, ] and [ step through them while the mouse is over the viewport (and only then, so the keys stay yours while you type elsewhere).
A panel does not have to live in the dock. Each one can be:
- Off,
- In hand, in the dock,
- Floating, standing in the world on the dominant hand's side, away from the dock,
- In view, held low in the middle of your vision wherever your head turns, sliding up from below when it first appears.
The content drawer gets special handling. It is not normally on screen, and a panel that is not on screen cannot be copied. So while VR asks for it, the editor window draws it docked under the editor area at 1100 by 440 logical pixels, where nothing overlaps it or the other exported panels, replacing the desktop drawer for that time and leaving your saved layout alone. In the headset, two trigger pulls in one place within half a second are a double-click, so opening an asset folder works the way your fingers expect.
5. The Quick Menu
Some actions you want without crossing the room to a panel. Hold the dominant hand's A or X and grip together, in either order, and a ring 32 cm across opens 55 cm along your hand's ray, facing your head. It stays put while you aim into it.
Point into a slice, or push the thumbstick toward one, and let go of either button to do it. The middle is a 4.5 cm dead zone, so letting go there does nothing, and B or Y cancels. While the ring is up the other controls are quiet, so opening it never also selects or drags something behind it.
The level editor fills it like this, clockwise from the top, with opposites mirrored:
| Slice | Action |
|---|---|
| Top | Duplicate |
| Upper right | Turn right 45° |
| Right | Bigger (1.25×) |
| Lower right | Delete |
| Bottom | Content drawer, rising into view |
| Lower left | Undo |
| Left | Smaller |
| Upper left | Turn left 45° |
Every one of these is the level editor's ordinary command, so every one is undoable. Turns and sizes apply about each selected object's own origin. Another editor passes its own list to the VR toolbar button, and an editor with no list gets no menu. The ring is painted with the editor's own font, once per highlighted slice, and shown as a translucent panel in the same overlay as everything else.
5.1 The rest of the controls
The table is written for roles rather than sides, so left-handed mode mirrors it. The names are for Quest controllers.
| Control | Action |
|---|---|
| Dominant trigger | Use a panel; select; over empty space, clear the selection |
| Dominant A / X, on release | Add or remove the pointed-at object from the selection |
| Dominant A / X + grip | The quick menu |
| Dominant B / Y | Close the menu, else cancel a move, else clear the selection |
| Dominant grip | Move the selection, carried and turned with your hand |
| Dominant stick | Up and down scroll; left and right snap-turn 30 degrees |
| Off hand stick | Fly where you look, 4 m/s |
| Off hand grip + stick | Fly up and down |
| Off hand stick click | Next panel in the dock |
| Off hand X / A | Undo |
| Off hand Y / B | Redo |
One choice in there is about stomachs more than software: the room only ever turns about the vertical. The level's floor stays your floor, and nothing tilts the world to match your head.
6. Drawing Things That Stay Stuck to You
Everything VR adds to the picture is one small data structure, an OverlayFrame: textured quads for panels, camera-facing lines, and flat rings. The editor publishes it to a viewport, and a render pass, registered as the engine's own pulsar.vr_overlay feature, draws it. The pass is in the render graph only while something is published, and only in the editor.
6.1 After the final image
The pass draws over the finished frame, after tone mapping and the temporal resolve. Text on a panel is small and sharp, and the last thing it needs is to be tone mapped like a surface in the world or smeared by temporal anti-aliasing. The projection the pass reads still carries the temporal jitter the 3D renderer uses, so the vertex shader subtracts it back out:
The flip side of "over everything" is that panels and lines are not occluded by the scene. A panel in your hand stays readable when your hand is inside a wall.
6.2 What each point follows
The editor's UI publishes overlay frames at UI rates. A head moves faster than that. If the overlay were a list of world positions, a panel in your hand would swim behind your hand by however old the last publish was.
So every point says what it keeps its place against:
World is for floating panels and cursors on objects. View points are placed by the vertex shader with the camera of the very frame being drawn, which is what the desktop preview uses for its hands and dock: fly the camera around and nothing needs republishing. Hand points are stored relative to a hand, and the headset thread places them with that headset frame's tracked pose, which is far fresher than anything the UI thread saw. Head is for the in-view panel: one real place for both eyes, so it keeps its depth.
A line can follow different things at each end. The pointer is exactly that: its start rides your hand and its tip stays on the object.
Publishing is also lazy. A new frame goes to the renderer only when something changed, and a change that is only a panel's contents, like typing in a search box with everything else still, wakes the renderer at most ten times a second.
7. In the Headset
7.1 The GPU has to be born in VR
OpenXR does not accept a Vulkan device you made yourself. The runtime wants to create it, through XR_KHR_vulkan_enable2, so it can add the extensions it needs and pick the adapter the headset is plugged into. And a UI framework, a viewport and an asset pipeline all hang off one device. You cannot swap that out under a running editor.
So the decision is made at startup. GPUI gained a hook, a GPU factory, that the host can offer: given the features the window system needs, return a whole instance, adapter, device and queue, or nothing. If a VR runtime is already running with a headset, Pulsar makes the engine's one device through OpenXR, described exactly as the engine would have described its own. Otherwise, or on any error, the usual device is made. Starting the editor never launches a VR runtime, and setting PULSAR_NO_VR skips the whole thing.
That is why the toolbar tells you what stands between you and the headset, and shows nothing at all until a runtime is running:
| The toolbar shows | Meaning |
|---|---|
| VR: switch to Vulkan | Another graphics backend is selected. Click to choose Vulkan, then restart |
| Enter VR | Ready. You appear at the viewport camera, facing its way, on your room's floor |
| Exit VR | A session is up |
| VR: restart | The runtime started after the editor, or startup failed; the tooltip says why |
The editor in the pictures was not running on Vulkan, which is why its toolbar reads "VR: switch to Vulkan".
The Vulkan instance created through OpenXR must be version 1.3, matching wgpu's own. wgpu uses what 1.3 made core without enabling the matching extensions, judging by the device's version. Ask the runtime for a 1.2 instance and wgpu believes image robustness is on when it is not, leaves shader texture reads unchecked, and one read out of range faults the GPU.
If you want the details of how the Vulkan handles cross between OpenXR and wgpu, the post on Helio's OpenXR support goes through them.
7.2 A thread paced by the headset
A headset has its own clock and no patience. Pulsar gives the session a thread of its own, listed as "VR headset" in the editor's Tasks window. Each headset frame it:
- waits for the runtime to say it is time,
- locates both eyes and reads the controllers,
- moves the room rig (flying, snap turns),
- places the overlay's hand and head points with those fresh poses,
- draws each eye into its layer of the runtime's image, and submits.
Each eye is its own engine renderer of the same level, so each keeps its own temporal history. Sharing one would reproject each eye's frame from the other's. That means the level is drawn twice per headset frame, at the headset's resolution, which on a Quest 3S through Meta's runtime is 1616 by 1648 per eye. Helio has a single-pass stereo path, but the editor's pipeline does not use it: it does not take graphs that trace rays.
The UI thread does the thinking at its own pace: once per window frame it reads the same tracking, runs the pointer, the dock and the menu, and sends selections and moves to the viewport renderer's pointer queue.
7.3 Taking turns
Two threads and a runtime now want one GPU queue, and two rules the single-threaded editor never had to think about come into force:
- Renderers of one level share its GPU copy, so they draw one at a time. The eyes take the same turn as the viewports.
- OpenXR uses the Vulkan queue inside its own frame calls, and Vulkan requires that nobody else touches the queue meanwhile. Those calls take the window's submit lock exclusively, the same lock the UI renderer holds while it submits and presents.
The order is fixed: the drawing turn first, then the submit lock. Without either, the GPU can fault and take the device with it.
7.4 The desktop keeps a window into it
While you are in VR, drawing the level a third time for a monitor nobody is looking at would be waste. The viewport you entered from instead shows a half-size copy of the left eye, about thirty times a second, cropped to fill it, and still accepts clicks. Every other renderer in the editor waits, holding its last frame. Take the headset off for a second and they draw again.
7.5 When things go wrong
GPUs get lost. When that happens during a VR session, the replacement device is made through OpenXR again (closing the old OpenXR instance first, since the loader allows one at a time), and once the level's viewport is rebuilt and has stayed healthy for a few seconds, the editor puts you back in VR where you were. Both recoveries are rationed: after three replacements in ten minutes you get an ordinary device and a message to restart, and re-entry gives up after three tries unless a session lasted two minutes in between. A crash that repeats should stop, not loop.
8. Seeing Where the Time Goes
VR performance problems are timing problems, and an average frame rate hides them. While the headset is worn, the engine log gets a line every two seconds: frames drawn against the headset's refresh rate, refreshes missed, and how the headset thread's time split between waiting for the runtime, waiting for the editor's GPU locks, OpenXR calls and recording the eyes, plus each eye's GPU time and its most expensive passes.
For anything deeper there is the editor's profiler. The pictures in this section are a real recording of a headset session in the editor: 10.2 seconds, 776,431 events.
8.1 Frames the headset asked for
The strip along the top is every headset frame, judged against the budget of a 120 Hz display, 8.3 ms. Dragging across it summarises a range. Here are 300 frames in a row:
The news is not flattering, and it is exactly the news a profiler is for. The average frame is 15.2 ms, the median 14.5 ms, the 95th percentile 21.0 ms and the worst 24.9 ms. All 300 are over budget. Those 300 frames span 5.1 seconds, so the headset got a new picture about 58 times a second on a display that refreshes 120 times.
8.2 One bad frame
A frame here has a CPU part and a GPU part, and the longer one is what counts. Frame 220 is the worst of that range:
Read it from top to bottom:
- VR headset spends about 10 ms of each loop waiting in
xrWaitFrame, then about 5.7 ms recording the two eyes, one after the other. The CPU part of frame 220 is 6.27 ms, inside the budget. - helio-encoder-finish threads are the renderer finishing its command buffers in parallel while each eye is recorded.
- GPU · Left eye and GPU · Right eye are where the time goes: 13.2 ms for the left eye of this frame and then 11.7 ms for the right. They run in turn, and the GPU part comes to 24.9 ms. These lanes use GPU timestamps calibrated to the CPU clock, so a GPU pass sits where it really happened next to the thread that asked for it.
- Display refresh is the headset runtime's side: one 8.33 ms slot per refresh, marked predicted or missed.
The passes name the culprit. In each eye, nearly half of this frame is Shadow, about 6.1 ms on the left and 5.4 ms on the right, and almost all of that is redrawing the static shadow layer. How long that takes varies a lot: the previous right eye spent 2.7 ms in Shadow. In the 300 frames above, the left eye alone redrew its static layer 184 times, at up to 6.8 ms a go.
8.3 Asking one span
Selecting a span opens everything known about it:
The span knows what it waited on (the renderer's submit) and what it let go (drawn as arrows, with a wake-up that had to be inferred drawn dashed and labelled as such). It also knows how it compares with itself: over 611 calls the left eye's GPU frame has a median of about 7.9 ms, a 95th percentile of about 11.5 ms and a worst of about 13.6 ms, so this one is 1.7 times the median. A median near 7.9 ms per eye, with two eyes to draw inside 8.3 ms, says plainly where the work has to happen next: shadows first, and drawing the level twice after that.
9. Where It Stands
The pictures here are the desktop preview, but the editor has been used with the headset on, on a Quest 3S. Both eyes show and head and hand tracking feel right. The dock, the pointer, clicking panels, flying, snap turns and the toolbar work. So do selecting, moving things with the grip, undo, the quick menu and the content drawer, and it is comfortable to use. It is not yet keeping up with a 120 Hz display, though, as the recording in Section 8 shows. Underneath, a test draws both eyes into a two-layer image without any headset, and the rules in pulsar_vr and the overlay have unit tests.
And here is what is not built:
- Grab gestures for panels (the rules exist in
pulsar_vr; nothing triggers them yet). - Rotating objects by hand, and grabbing the world to move around.
- Occlusion of panels by the scene, and controller models.
- Text entry, file dialogs, and menus larger than their panel.
- Haptics, and a way for plugins to react to controllers.
- Dragging an asset from the content drawer into the level.
The editor window also still has to draw for the UI side to run, so do not minimise it while you are inside.
One question stays open on purpose. With floors and walls selectable, the amber line is on almost all the time. Whether to limit its reach, or to let objects opt out of selection, is not decided.
Why It Is Built This Way
If there is one idea to take from all of this, it is that the VR editor should not be a second editor. The panels are the real panels, so they can never drift from the desktop ones, and a new panel, or a plugin's, joins VR with one function call. Input is real input, so nothing needs a VR version of "click". Edits go through the same commands, so undo just works. What is actually new is small and contained: rules about hands in a crate you can test without a GPU, one overlay pass, and one thread that knows how to share.
To try it without any headset at all: open a level, then in the viewport's Overlays menu choose VR Panel Preview. Your mouse is now your right hand.
Credits
Scene: Sponza (2022) by Frank Meinl and Anton Kaplanyan, with the add-on curtains by the Sponza Addon Package Crew named above, from the Intel Sample Library:
Frank Meinl and Anton Kaplanyan. Intel Sample Library, 2022. intel.com
OpenXR is a standard of the Khronos Group. The level, the editor and the panels in these pictures are Pulsar, rendered by Helio.