Raytraced Audio now understands the difference between indoors and outdoors, as well as small vs large rooms.
Vercdad and I took everything out of the garage so it could be cleaned, and I noticed it had an echo it didn't have before. This made me realise I was doing audio raytracing wrong this whole time.
I realised the garage now had an echo because every surface of the garage was reflecting sound back to me, i.e. no sound waves were getting lost behind the car, fridge or boxes that were there before.
The problem with the old raytraced audio system was that it only used two reverb presets:
small wooden room, modified to have a longer decay time
outdoor plains
It would then interpolate between the two based on the size of the room around the player.
This meant the smaller the room around the player, the longer and stronger the reverb was. I then left the garage, walked into the kitchen, and there was no echo, even though the kitchen is smaller than the garage. I had it all wrong!
The kitchen didn't echo because sound was able to leave the room and disperse into other rooms. This means I had to control reverb based on how much sound came back to the player, and how far it travelled before it came back.
Each time an audio ray bounces, it checks for line of sight back to the player. The first bounce always has line of sight as it originated from the player, then the subsequent 7 bounces perform a raycast back to the player.
Each time it bounces and reaches the player, the total distance from that surface to the player is accumulated. If the ray reaches the edge of the map, it is marked as an 'outdoor' ray and treated as lost energy. The 'Room Size' and 'Outdoor %' variables at the bottom of the screen reflect this.
The average distance that every 'indoor' ray travelled is used to interpolate between two reverb presets:
small wooden room
large factory hall
Finally, this is interpolated with the outdoor plains preset based on the percentage of rays that are 'outdoor' rays.
All raytracing is continuously performed on a background CPU thread as the player moves around and/or the environment gets destroyed.
You can try it out on our beta branch by entering the code betabetabeta on Steam: https://sectorsedge.com/s/iua6