GameCrew AIEarly access
Sign in
Unity 6vrRevision 1 · Compile-verified pattern

Passthrough Mixed Reality in the Player's Room in Unity 6 (WebXR immersive-ar)

A passthrough game in Unity 6 with CCGD.GameXR: hide the virtual setting when GameXR.Passthrough turns on, place the play area from the head, move it by pointing at the floor and pinching, ground things with contact shadows, keep every opaque pixel at alpha 1, and fall back to a virtual room everywhere else.

  • vr
  • xr
  • webxr
  • passthrough
  • mixed reality
  • mr
  • ar
  • immersive-ar
  • room
  • tabletop
  • placement
  • contact shadow
  • alpha
  • quest

No demo.

When to Use & Field Best Practices

A passthrough game (game.json "passthrough": true) plays in the player's own room on a headset whose browser can show it: the page starts an immersive-ar session, the kit's eyes clear to transparent, and the headset's cameras show the room wherever the game draws nothing. The same link plays as ordinary VR on a headset that can't, and flat on a computer or phone, so a passthrough game always keeps its virtual setting for those.

  1. One switch, read once per session: GameXR.Passthrough is true between GameXR.Entered and GameXR.Exited in a passthrough session. React there: hide the setting, turn fog off, place the play area. Give everything back on Exited.
  2. Hide the setting, keep the toys: put the sky dome, walls, floor, ceiling, windows and far scenery under one Environment root and SetActive(false) it. Keep what the player handles and anything that plausibly stands in a room (a table-top stage, a trunk, a lamp). Never draw a sky, a full-screen backdrop or a giant floor plane in passthrough: it covers the room.
  3. The real floor is y = 0: the session uses local-floor, so the rig's origin is on the real floor where the player stood. Nothing knows where the real furniture is: place the play area from the head at the start (a tabletop act at 0.85 of eye height, 0.45 m in front), and let the player move it.
  4. Move it by pointing: point a hand at the floor and pinch to put the play area there (facing the player), the gesture people know from headset home screens. An XrGrabbable handle on the play area is the other choice.
  5. No artificial locomotion: GameXR.Locomotion(move: "none", turn: "none") and GameXR.FollowGameCamera = false. The player walks round their room; never move the rig after placing it.
  6. Belong in the room: a soft round contact shadow under anything that rests or lands sells it more than any shader. Light evenly and warmly (one soft directional light plus ambient), avoid deep black shading and emissive sky colours, keep materials opaque.
  7. Alpha is the mask: the headset composites the layer by its alpha. Opaque URP shaders write alpha 1; a cleared pixel is alpha 0 (the room). Additive particles and alpha-0 glows let the room through, so in passthrough give effects an alpha (Universal Render Pipeline/Particles/Unlit, Blend Alpha) or keep them small.

Mathematical & Algorithmic Core

  • Placement from the head: with head position h, its forward f flattened to the floor f_xz = normalize(f_x, 0, f_z), and eye height e = h_y: $p = (h_x, 0, h_z) + d\,f_xz + (0,\; k e,\; 0), yaw = atan2( f_x, f_z)$ with $d \approx 0.45$ m and $k \approx 0.85$ for a tabletop at a standing player's hands (clamp $k e$ to 0.7-1.1 m so a seated player still reaches it).
  • Point-at-floor ray: aim origin o, direction a; the floor hit is t = -o_y / a_y for a_y < -0.15 (pointing down enough) and t ≤ 4 m, x = o + ta. The play area turns to face the player: yaw from x toward the head.
  • Contact shadow: a quad on the surface below the object, scale s = s_0(1 + 0.6\,clamp01(y / 1.5)) and alpha α = α_0(1 - clamp01(y / 1.5)) for height $y$ above it: it widens and fades as the object rises, so a thrown ball reads its height over the table.

Engine Implementation

Passthrough stage: hide the setting, place, point-and-pinch to move, contact shadows (Assets/Game/Runtime/VR/PassthroughStage.cs)

#if CCGD_VR
using CCGD;
using UnityEngine;

namespace MyGame
{
    /// <summary>
    /// The play area in the player's room. In a passthrough session (GameXR.Passthrough) the virtual setting
    /// (environment) is hidden and fog is off; the stage is placed in front of the player from their head and moved
    /// by pointing a hand at the floor and pinching. Everywhere else nothing changes.
    /// </summary>
    public class PassthroughStage : MonoBehaviour
    {
        public Transform environment;      // the sky, walls, floor and far scenery: hidden in passthrough
        public Transform stage;            // what the player plays with: placed in the room
        public float reach = 0.45f;        // metres in front of the head
        public float heightShare = 0.85f;  // of eye height (a tabletop at the hands)

        bool fogWas, placed;
        readonly bool[] wasPinching = new bool[2];

        void OnEnable() { GameXR.Entered += Entered; GameXR.Exited += Exited; }
        void OnDisable() { GameXR.Entered -= Entered; GameXR.Exited -= Exited; }

        void Entered()
        {
            if (!GameXR.Passthrough) return;
            if (environment != null) environment.gameObject.SetActive(false);
            fogWas = RenderSettings.fog;
            RenderSettings.fog = false;
            GameXR.FollowGameCamera = false;
            GameXR.Locomotion(move: "none", turn: "none");
            placed = false; // placed on the first frame the head is known
        }

        void Exited()
        {
            if (environment != null) environment.gameObject.SetActive(true);
            RenderSettings.fog = fogWas;
            placed = false;
        }

        void LateUpdate()
        {
            if (!GameXR.Passthrough || stage == null || GameXR.Head == null) return;
            var head = GameXR.Head;
            if (!placed)
            {
                var f = Vector3.ProjectOnPlane(head.forward, Vector3.up);
                if (f.sqrMagnitude < 1e-4f) f = Vector3.forward;
                f.Normalize();
                float rigFloor = GameXR.Rig.position.y;
                float eye = head.position.y - rigFloor;
                float y = rigFloor + Mathf.Clamp(eye * heightShare, 0.7f, 1.1f);
                var at = new Vector3(head.position.x, y, head.position.z) + f * reach;
                stage.SetPositionAndRotation(at, Quaternion.LookRotation(-f, Vector3.up) * Quaternion.Euler(0, 180f, 0));
                placed = true;
            }
            for (int i = 0; i < 2; i++)
            {
                var hand = GameXR.Hand(i == 0 ? "left" : "right");
                bool pinch = hand != null && hand.Tracked && hand.Pinching;
                if (pinch && !wasPinching[i]) TryPlace(hand, head);
                wasPinching[i] = pinch;
            }
        }

        /// <summary>A pinch while pointing down at the floor puts the stage there, facing the player.</summary>
        void TryPlace(XrHand hand, Transform head)
        {
            var o = hand.Aim.position;
            var a = hand.Aim.forward;
            float floor = GameXR.Rig.position.y;
            if (a.y > -0.15f) return;
            float t = (floor - o.y) / a.y;
            if (t <= 0f || t > 4f) return;
            var hit = o + a * t;
            var toPlayer = Vector3.ProjectOnPlane(head.position - hit, Vector3.up);
            if (toPlayer.sqrMagnitude < 1e-4f) return;
            float y = stage.position.y; // the stage keeps its height; it moves across the room
            stage.SetPositionAndRotation(new Vector3(hit.x, y, hit.z), Quaternion.LookRotation(-toPlayer.normalized, Vector3.up));
            hand.Pulse(0.4f, 0.03f);
        }
    }

    /// <summary>A soft round shadow on the surface below a thing: wider and fainter as it rises.</summary>
    public class ContactShadow : MonoBehaviour
    {
        public Transform target;
        public float surfaceY;          // world height of what it rests on (the stage's top)
        public float size = 0.12f, strength = 0.55f, fadeHeight = 1.5f;
        Material mat;

        void Start() { mat = GetComponent<Renderer>().material; }

        void LateUpdate()
        {
            if (target == null) return;
            float h = Mathf.Max(0f, target.position.y - surfaceY);
            float k = Mathf.Clamp01(h / fadeHeight);
            transform.position = new Vector3(target.position.x, surfaceY + 0.002f, target.position.z);
            transform.localScale = Vector3.one * size * (1f + 0.6f * k);
            var c = mat.color; c.a = strength * (1f - k); mat.color = c;
        }
    }
}
#endif

The shadow quad: a horizontal quad with a radial white-to-transparent texture made in code (a 64×64 Texture2D, alpha = (1 - r)^2), material Universal Render Pipeline/Unlit, Surface Type Transparent, colour black.

PlayMode test with the simulated passthrough session (Assets/Game/Tests/PlayMode/PassthroughTests.cs)

using System.Collections;
using CCGD;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;

public class PassthroughTests
{
    [TearDown] public void TearDown() { GameXR.Sim.Exit(); GameXR.Sim.Reset(); }

    [UnityTest]
    public IEnumerator PassthroughHidesTheSettingAndPlacesTheStageInFront()
    {
        yield return UnityEngine.SceneManagement.SceneManager.LoadSceneAsync("Main");
        var env = GameObject.Find("Environment");
        var stage = GameObject.Find("Stage").transform;
        GameXR.Sim.Head(new Vector3(0, 1.6f, 0), yaw: 0f);
        GameXR.Sim.Enter(passthrough: true);
        yield return null; yield return null;
        Assert.IsTrue(GameXR.Passthrough);
        Assert.IsFalse(env.activeInHierarchy, "the virtual setting is hidden in passthrough");
        Assert.IsFalse(RenderSettings.fog, "no fog over a real room");
        var toStage = stage.position - GameXR.Head.position;
        Assert.Greater(Vector3.Dot(toStage, GameXR.Head.forward), 0.2f, "the stage is in front of the player");
        Assert.That(stage.position.y - GameXR.Rig.position.y, Is.InRange(0.7f, 1.1f), "at hand height");
        GameXR.Sim.Exit();
        yield return null;
        Assert.IsTrue(env.activeInHierarchy, "the setting is back after the session");
    }
}

Pitfalls

  • A sky or backdrop in passthrough: the room never shows. The save's check samples the headset's layer and fails when nothing is transparent.
  • Fog left on: real furniture shows through a grey haze of fog-tinted geometry edges; turn it off in passthrough.
  • Assuming a table: the kit has no plane or furniture detection; a stage floating at hand height in front of the player is honest, a stage "on your table" is a guess.
  • Locomotion in a real room: snap turn and stick walking move the virtual things away from the real room; walking is the player's.
  • Alpha-0 glows and additive particles: they show the room through the effect. Give effects alpha, keep them small, or skip them in passthrough.
  • Forgetting the fallback: on a computer or a non-passthrough headset the game is the same game in its virtual setting; test both (GameXR.Sim.Enter() and GameXR.Sim.Enter(passthrough: true)).

Official references

  • Meta Mixed Reality Design Guidelines (Passthrough, Scene placement)
  • WebXR Device API environmentBlendMode
  • Meta Quest Browser immersive-ar

More Unity 6 games

Games made with GameCrew on the same engine. No game has been built with this guide yet: these show what Unity 6 games here look like.

Thin Air Errands — Three hundred metres up, with a storm on the way, you carry your own plank between rooftops, lay it across the gap, and walk it with your arms out.
Plays in VR

Thin Air Errands

Three hundred metres up, with a storm on the way, you carry your own plank between rooftops, lay it across the gap, and walk it with your arms out.

Kerbside — Every push, pop and scrape is earned: a grounded skateboarding game where your feet, not a button, do the trick, and a clean landing feels like the real thing.

Kerbside

Every push, pop and scrape is earned: a grounded skateboarding game where your feet, not a button, do the trick, and a clean landing feels like the real thing.

More Unity 6 techniques

physics

Active Ragdoll Falls & Bails on a Procedurally Posed Humanoid in Unity 6 →

Turn an animated or procedurally posed rigged humanoid into a muscled ragdoll at runtime (no Ragdoll Wizard) for falls and bails, with hinges that hold, no pop or one-step lag at the switch, PD muscle tone that decays, protective reflexes, and a clean hand-back to the animated rig.

lighting

Atmospheric Height Fog, Sun Shafts & Rim-Readable Lighting in Unity 6 URP →

Three-point outdoor/interior URP lighting recipe combining directional sun + warm/cool fill, exponential height/distance fog, ACES/Neutral post-processing, and anti-darkness floors so captures never read black or washed out.

shaders

Cel-Shading, Shadow Ramps & Width-Compensated Outlines in Unity 6 URP →

Two-pass URP stylized cel shader combining main-light shadow-attenuated diffuse ramps, crisp specular/rim accents, and clip-space distance-compensated inverted-hull outlines.

physics

CharacterController Slope Projection & Floor Snap in Unity 6 →

Deterministic Unity 6 CharacterController locomotion with SphereCast ground projection, ramp stickiness, steep-slope slide, and coyote jumps.

Use verified techniques inside a real game

Describe your game idea for free or connect an MCP assistant to search and contribute techniques.

Learn about collaboration