Guide for implementing depth sensing and occlusion in IWSDK projects. Use when adding depth-based occlusion to hide virtual objects behind real-world surfaces, configuring DepthSensingSystem, choosing occlusion modes, or troubleshooting objects that disappear or fail to occlude.
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "iwsdk-depth-occlusion" 技能: 1. 下载 https://raw.githubusercontent.com/facebook/immersive-web-sdk/main/packages/starter-assets/claude-injections/skills/iwsdk-depth-occlusion/SKILL.md 2. 保存为 ~/.claude/skills/iwsdk-depth-occlusion/SKILL.md 3. 装好后重载技能,告诉我可以用了
Hide virtual objects behind real-world surfaces using WebXR depth sensing. The system samples a per-pixel depth texture from the XR device and compares it against each virtual fragment's depth — if the real surface is closer, the fragment is faded out.
Three things are required: XR session depth config, the system, and the component.
World.create(container, {
xr: {
sessionMode: SessionMode.ImmersiveAR,
referenceSpace: ReferenceSpaceType.Unbounded,
features: {
depthSensing: {
required: true,
usage: 'gpu-optimized', // or 'cpu-optimized'
format: 'float32',
},
hitTest: { required: true },
anchors: { required: true },
unbounded: { required: true },
},
},
});
DepthSensingSystem and DepthOccludableimport { DepthSensingSystem, DepthOccludable } from '@iwsdk/core';
world
.registerSystem(DepthSensingSystem, {
configData: {
enableDepthTexture: true,
enableOcclusion: true,
useFloat32: true,
blurRadius: 20.0,
},
})
.registerComponent(DepthOccludable);
DepthOccludable to entitiesimport { DepthOccludable, OcclusionShadersMode } from '@iwsdk/core';
// Soft occlusion (default) — smooth edges via 13-tap blur
entity.addComponent(DepthOccludable);
// Hard occlusion — sharp edges, single depth sample
entity.addComponent(DepthOccludable, {
mode: OcclusionShadersMode.HardOcclusion,
});
// MinMax occlusion — best quality, extra preprocessing pass
entity.addComponent(DepthOccludable, {
mode: OcclusionShadersMode.MinMaxSoftOcclusion,
});
The material must have transparent: true. The system sets this automatically, but verify it on custom materials.
| Mode | Quality | Cost | Best For |
|---|---|---|---|
SoftOcclusion | Good | Low | Most objects — smooth edges, hides depth aliasing |
HardOcclusion | Basic | Lowest | Small objects or when sharp edges are acceptable |
MinMaxSoftOcclusion | Best | Medium | Large objects with complex silhouettes against varied backgrounds |
| Property | Type | Default | Description |
|---|---|---|---|
enableOcclusion | Boolean | true | Master switch for all occlusion |
enableDepthTexture | Boolean | true | Create GPU textures from depth data |
useFloat32 | Boolean | true | Float32 depth textures (higher precision) |
blurRadius | Float32 | 20.0 | Blur radius for soft occlusion (pixels) |
| Mode | When to use |
|---|---|
cpu-optimized | Simpler, works everywhere. Depth as linear meters in a DataArrayTexture. |
gpu-optimized | Recommended. Matches Quest hardware format. Depth as reverse-Z inverse depth in an ExternalTexture. Required for production parity with on-device behavior. Note that Quest devices only support this mode. |
Depth occlusion only works in AR mode. The scene background must be null for passthrough:
scene.background = null;
Objects never occlude (always visible on top)
DepthOccludable componentDepthSensingSystem is registered with enableOcclusion: truedepthSensing is in the XR features configObjects always invisible in IWER
Flickering or noisy occlusion edges
blurRadius (try 30-40)HardOcclusion to SoftOcclusionMinMaxSoftOcclusion for best edge qualitySessionMode.ImmersiveAR with depthSensing in features.…
Test grab system (distance grab, one-hand grab, two-hand grab) against the grab example using the iwsdk CLI.
Test XR interactions (ray, poke/touch, dual-mode, audio, UI panel) against the poke example using the iwsdk CLI.
Find and click a target object in XR. Use when testing UI interactions, clicking buttons, or verifying interactable elements work correctly.
IWSDK project planning and best practices guide. Use when planning new IWSDK features, designing systems/components, reviewing IWSDK code architecture, or when the user asks about IWSDK patterns, ECS design, signals, or reactive programming in this codebase.
Develop and iterate on IWSDK UI panels efficiently. Use when working on PanelUI components, debugging UI layout, or improving UI design in IWSDK applications.
Test level system (LevelRoot, LevelTag, default lighting, scene hierarchy) against the poke example using the iwsdk CLI.