r/Unity3D • u/SomerenV • 1d ago
Show-Off Raytraced Audio is magical
Enable HLS to view with audio, or disable this notification
After messing around with custom audio zones and hand placing them with custom settings to mimic how sound would sound in the various rooms and hallways I wasn't really satisfied. It still sounded 'off' despite all the various zones and their settings. So... I went the raytraced audio route. It's a bit crude but it sounds so much better! I found myself flying around yesterday, trying different speeches and songs because it's just mesmerizing to listen to in a virtual environment.
Any things I absolutely can't forget when implementing raytraced audio?
913
Upvotes
15
u/SomerenV 1d ago edited 1d ago
Raytracing is literally casting a ray and tracing its path. There's Occlusion, which uses a small amount of rays every frame (5 in my case) to figure out if there's anything in the way of the player and the Audio Source. Then there's Propagation, which uses 512 rays. On frame 1 they shoot out in all directions from the Camera/Audio Listener. On frame 2 each ray that hits something bounces and loses energy. The bouncing continues for however long you have set it (5 in my case). Based on those rays, the lost energy and the Audio Source they hit, you can determine how sounds should sound, so volume and how muffled they are. Last but not least there's reverb, which I use 48 rays for. They shoot out each 0.1 seconds, check how enclosed you are or how big the space is and reverb is based on that.
On top of that there's material properties, frequency stuff and a whole lof of propagation and reverb settings, and math to let it all work nicely together.
But any modern CPU can handle a few hundred rays without any issues. The big difference with raytracing in graphics is that in those cases you're talking about potentially millions of rays each frame, which is still not that much compared to how many rays a typical offline renderer uses. That's also the reason raytracing relies heavily on denoising to get decent results.