"Spatial audio for VR: a practical guide to 3D sound"
By the Turbl team · · 10 min read
Spatial audio in VR makes each sound seem to come from a point in the scene, and keeps it there when you turn your head. The software filters the sound separately for each ear, based on where the source is relative to your head. On the web you get this from the Web Audio API's PannerNode, which three.js wraps as PositionalAudio.
Why sound matters more in VR
A headset shows only the part of the world in front of you. Sound covers all of it. A noise behind you is often the only way to know something is there.
Sound also replaces touch. Microsoft notes that immersive apps need sound more than flat apps do, because there is no tactile interface. A virtual button gives your finger nothing to feel. A click tells you the press worked.
Does spatial sound raise presence, the feeling of being in the place? The research is less tidy than marketing suggests. A 2025 study in Frontiers in Virtual Reality tested an audio enhancement tool on 68 people in two VR experiences. People rated involvement higher with the enhanced audio in both. They rated localization higher where it was measured. The single presence rating did not differ in one of the two experiences. The study was partly funded by the company that makes the tool. Treat spatial audio as information the player needs. Do not expect it to create presence by itself.
How spatial audio works
Spatialization means processing a sound so it seems to come from one direction and distance. It rests on four things.
Direction: the HRTF
Your brain finds a sound's direction from small differences between your two ears. Meta's audio guide names the main ones:
- Time difference. A sound on your left reaches your left ear first. This is the main cue for low sounds, below roughly 500 to 800 Hz.
- Level difference. Your head blocks part of the sound on its way to the far ear. This matters most above about 1,500 Hz.
- Filtering by your body. The outer ear, head and torso change the tone of a sound depending on where it comes from. This is how you tell front from back and up from down.
A head-related transfer function (HRTF) is a set of filters that captures all three effects for each direction. The engine picks the filter for the direction of the source and applies it to the sound. The result is two channels, one per ear. This is called binaural audio.
Everyone's ears differ, so engines ship a generic set. Meta's guide says a generic set is adequate for most situations, especially with head tracking.
Head tracking is what makes it hold together. A generic HRTF often leaves a sound ambiguous between front and back. When you turn your head a little, the cues change, and the brain resolves the question. So the audio must follow your head without noticeable delay.
HRTF audio needs a separate signal for each ear. Meta's guide recommends headphones for this.
Distance: attenuation
Distance attenuation means a sound gets quieter as it moves away. It is the cheapest distance cue. Meta's guide calls it the most obvious cue and also a misleading one. You judge distance by loudness only when you know how loud the source should be. A voice is easy to judge. A synthetic beep is not.
Two more cues help. Far sounds lose some high frequencies in air. A low-pass filter imitates this: it cuts high frequencies and makes a sound duller. A far sound also carries more echo relative to its direct sound.
Occlusion
Occlusion is what happens when something solid sits between you and the source. The sound gets quieter and duller. A radio behind a closed door is the standard example.
Reverb
Reverb is the sum of reflections from walls, floor and ceiling. It tells you how big the room is and what it is made of. It also carries distance. Microsoft's guide puts it bluntly: without acoustics, spatialized sounds lack perceived distance. Meta's SDK documentation says HRTFs alone often sound dry and lifeless.
Spatial audio for VR on the web
The browser has what you need built in. The Web Audio API is the browser's standard audio engine. Its PannerNode places one sound in 3D space relative to a listener.
These are the settings that matter. Defaults are from the Web Audio specification.
| Setting | What it does | Default |
|---|---|---|
panningModel | equalpower only balances left and right. HRTF uses filters measured on people. | equalpower |
distanceModel | The curve for distance attenuation: linear, inverse or exponential | inverse |
refDistance | Closer than this, the sound plays at full volume | 1 |
rolloffFactor | How fast the volume falls beyond refDistance | 1 |
maxDistance | Where the linear model stops reducing the volume | 10000 |
coneInnerAngle, coneOuterAngle | Make a source directional, like a loudspeaker | 360 |
For VR, set panningModel to HRTF. The default only pans left and right, so it cannot place a sound above or behind you.
With the default inverse model and default values, the gain is 1 divided by the distance. In a scene measured in meters, a sound is at half volume at 2 m and at a tenth at 10 m. It never reaches zero. Use linear when a sound must be silent beyond a known distance.
Here is a plain Web Audio source. buffer is a decoded audio file.
const ctx = new AudioContext();
const panner = new PannerNode(ctx, {
panningModel: 'HRTF',
distanceModel: 'inverse',
refDistance: 1,
rolloffFactor: 1,
positionX: 2,
positionY: 1.5,
positionZ: -3,
});
const source = new AudioBufferSourceNode(ctx, { buffer, loop: true });
source.connect(panner).connect(ctx.destination);
source.start();
This is only half the job. You must also copy the headset's position and orientation to ctx.listener on every frame. Otherwise the sound turns with the player's head. A library does this for you.
three.js PositionalAudio
In three.js, PositionalAudio wraps a PannerNode. It sets the panning model to HRTF in its constructor, as of November 2026. You add an AudioListener to the camera and add each sound to the object that makes it. three.js then updates both positions every frame. In a WebXR session the camera follows the headset, so the listener does too.
import * as THREE from 'three';
// camera, generator (a mesh) and enterVrButton already exist
const listener = new THREE.AudioListener();
camera.add(listener);
const hum = new THREE.PositionalAudio(listener);
hum.setRefDistance(1);
hum.setRolloffFactor(2);
hum.setLoop(true);
generator.add(hum);
const buffer = await new THREE.AudioLoader().loadAsync('sounds/hum.mp3');
hum.setBuffer(buffer);
enterVrButton.addEventListener('click', async () => {
await listener.context.resume();
hum.play();
});
The click handler matters. Browsers block audio until the user interacts with the page. Chrome creates an AudioContext in the suspended state if no gesture came first, and you must call resume() after one. Starting a VR session already needs a click, so start the audio from the same button.
For music that should not come from a place, use THREE.Audio with the same listener. It skips the panner.
If you use React Three Fiber, the drei library has a PositionalAudio component that wraps the same class. The React Three Fiber VR tutorial covers the setup around it.
What the web does not give you
The Web Audio API has no occlusion and no automatic room acoustics. You build both from parts:
- Occlusion. Cast a ray from the listener to the source. If it hits a wall, lower the gain and route the sound through a
BiquadFilterNodeset tolowpass. - Reverb. A
ConvolverNodeapplies a recorded impulse response, which is a recording of how a real room answers a short sharp sound. One shared reverb per room is enough for most scenes.
HRTF filtering costs processor time for every source. Microsoft notes the cost is negligible for one or two sounds at once. On a standalone headset, spatialize the sounds that carry information and keep the count low. The guide to WebXR performance on Meta Quest covers the frame budget this competes for.
Native options in brief
Native engines add the acoustics the browser lacks. Status as of November 2026:
| Tool | What it adds | Works with |
|---|---|---|
| Unity built-in panner | Left and right gain only, on the horizontal plane | Unity |
| Meta XR Audio SDK | HRTF, first-order ambisonics, room acoustics, near-field rendering | Unity, Unreal, FMOD, Wwise |
| Steam Audio | HRTF, occlusion and reflections from scene geometry, baked or real-time propagation | Unity, Unreal, FMOD Studio, Wwise, C API |
Ambisonics is a format that stores a whole sphere of sound around one point. It suits background ambience and music better than single objects.
Unity's default panner does not use an HRTF, so a spatializer plugin is the first thing to add. Meta strongly recommends its own SDK for all in-game sources on its headsets. Steam Audio is open source under the Apache 2.0 license.
Picking an engine is a bigger decision than audio. See Unity vs Unreal vs Godot for VR for that.
Design rules for VR sound
Attach every sound to its source. Microsoft's rule is simple: spatialize a sound when its event has a location. A humming machine hums from the machine. Moving objects should carry a sound so the player can follow them out of view.
Do not spatialize what has no place. Music, a narrator and ambient wind have no position. Microsoft warns that a spatialized sound with nothing visible at its location sends users looking for an object that is not there. Play these sounds without a panner.
Keep head-locked music modest. Head-locked means the sound stays fixed to your head and ignores the scene. Music played this way sits on top of everything. Meta's guidance says overlapping sounds are hard to separate and tiring. Keep music quieter than the world, lower it when an important sound plays, and offer a volume control.
Confirm every interaction. A press, a grab and a release each need a short sound. Microsoft recommends a short tactile click for a button press and a similar click at a higher pitch for the release. Grabs need sound most, because the hand often hides the object. The guide to VR interaction design covers the visual and haptic side.
Do not fade interface sounds with distance. Microsoft advises against distance attenuation on button sounds. The confirmation matters more than the distance. More on buttons in the VR UI design guide.
Fit the falloff to the room. Microsoft notes that an engine's default curve is often meant for spaces up to half a kilometer across. Adjust the curve of each source to the size of your scene. In a small room, raise the rolloff or switch to a linear curve.
Never rely on sound alone. Some players are hard of hearing, and some play muted. Every sound cue needs a visual one.
Avoid sudden loud sounds. Meta warns that loud or jarring sounds can cause discomfort or even pain.
Where Turbl fits
Turbl builds VR projects from a text description, and they run as standard WebXR apps in the headset browser. That means the same browser audio engine described above. You ask for sound in plain words, for example "make the generator hum and get louder as I walk toward it". You do not edit the audio code yourself. If you need baked acoustics or occlusion from scene geometry, a native engine with Steam Audio or the Meta SDK is the better tool.
FAQ
What is spatial audio in VR?
Spatial audio makes a sound seem to come from a specific point in the virtual world. The software filters the sound separately for each ear based on the direction and distance of the source. Head tracking keeps the sound in place when you turn.
What is an HRTF?
A head-related transfer function is a set of filters that describes how your head, ears and torso change a sound from each direction. Applying the filter for one direction makes a sound appear to come from there. Most engines use a generic set, not one measured on you.
Do I need headphones for spatial audio in VR?
HRTF audio needs a separate signal for each ear. Headphones give the cleanest result, and Meta's design guide recommends them. Room speakers mix the two signals and weaken the effect.
Does WebXR support spatial audio?
Yes. WebXR itself only handles the headset and controllers. Sound comes from the Web Audio API, which has HRTF panning built in through PannerNode. three.js wraps it as PositionalAudio.
Should music be spatialized in VR?
Only if it comes from something in the scene, such as a radio. Background music has no location, so play it without spatialization and keep it quieter than the world's sounds.
What is the difference between binaural audio and ambisonics?
Binaural audio is the two-channel result you hear in headphones, with one signal per ear. Ambisonics is a format that stores sound from all directions around one point. An ambisonic recording is converted to binaural for playback.
Sources
- Spatial audio design guide, Meta Horizon developers
- Audio design overview, Meta Horizon developers
- Meta XR Audio SDK features, Meta Horizon developers
- Meta XR Audio SDK overview, Meta Horizon developers
- Spatial sound overview, Microsoft Learn
- Spatial audio best practices, Microsoft Learn
- Web Audio API specification, W3C Audio Working Group
- PannerNode, MDN
- PannerNode: panningModel, MDN
- Web audio spatialization basics, MDN
- ConvolverNode, MDN
- BiquadFilterNode, MDN
- Autoplay policy in Chrome, Chrome for Developers
- PositionalAudio, three.js docs
- AudioListener, three.js docs
- PositionalAudio.js source, three.js on GitHub
- PositionalAudio component, drei docs
- Spatializer SDK, Unity 6.6 manual, Unity
- Steam Audio, Valve
- Steam Audio repository, Valve on GitHub
- "Did you hear that?": Software-based spatial audio enhancements in virtual reality, Frontiers in Virtual Reality, July 2025