Light vs Sound.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Jun 08, 2012 at 21:55

This may be a stupid question but, I’m working on real sounds in my game, and I was wondering if the sound from a distance is attenuated the same as light 1/(dist*dist) or is there a special formula for sound? I know that sound in space in nil since there are no air particles, and sound is not as loud in very high altitude due to much less air density. So I’m talking strictly sea level sound propagation. Any idea?

10 Replies

Please log in or register to post a reply.

B20d81438814b6ba7da7ff8eb502d039
0
Vilem_Otte 117 Jun 09, 2012 at 12:31

Maybe try looking at this - Stokes law for sound attenuation (you can google also some physics books ofc) - http://en.wikipedia.org/wiki/Stokes’_law_(sound_attenuation)

Anyway I’m sure you can go with some ‘constant / (dist * dist)’ as well (maybe with some fine tuning) … OpenAL afaik does something similar to hack the propagation.

For complete sound propagation you’d need sound reflection, correct rabbit-hole propagation, etc. etc. - e.g. doing path tracing for sound (that would be :ph34r:-like and it would really need looking deep into physics books) … but imo total overkill and maybe less visible than focusing the resources on graphics :D - especially if you know that most people just don’t have enough quality speakers for this stuff.

Though I don’t say it wouldn’t be worth of trying - if I’d have the time, i’d definitely try it B)

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Jun 09, 2012 at 15:05

ha! doing a path tracer for sound! wow, I’ve never thought of that one, and I got to try it, that should be fun!

Thanks Vilem.

B20d81438814b6ba7da7ff8eb502d039
0
Vilem_Otte 117 Jun 09, 2012 at 17:06

Actually, thinking about it (for few minutes)…

That algorithm could be quite easily done to actually be real time w/o some heavy effort. It even could be optimized to actually do the whole stuff on single core of CPU (which means that it could be game applicable).

So basically you’d have scene geometry (lets say just static, no dynamic now - though extending it would be quite easy with dynamiccaly re-building acceleration structure for ray tracing), sound sources (with info like position, volume, etc.) and listener.

I’d basically do it in very simple way - using bi-directional path-tracing to compute sound propagation. The algorithm would be 2-pass one:

/*
1st Pass
1.) Generate ray directions at sound source position (generated in directions with probability function that would describe F.e. direction of sound source)
2.) Path trace these, storing hit points as "Virtual sound sources" (with all parameters, also with "time-offset" effect - e.g. rays would have time parameter - you'd get "sound motion blur").

2nd Pass
1.) Generate random ray directions from listener position
2.) Path trace these, plus every step (even the first one which starts at listener) calculate "sound visiblity" to "every" sound source position (every means every reachable from hitpoint - optimization).
3.) Mix the sounds together - getting correct result (don't forget to compute with Stokes equation for sound propagation)
*/

It could be extended also with sound propagation through solid materials (in the Pass 2 2. phase - with quite simple code extension - getting all hits along ray and material parameters (of course until it hits the source)).

Totally you’d need a lot lower number than I get for realtime ray tracing per single core - so actually making it realtime would be possible on single core of CPU.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 168 Jun 09, 2012 at 21:56

For path tracing sound I’d expect you’d want to keep track of the phase of the waves as well, since audible sound wavelengths long enough (anywhere from \~2 cm to \~20 meters) that phase differences and interference/diffraction effects would be important. Fortunately sound waves are longitudinal so there is no polarization to worry about. :) Also, note that since the Stokes’ law depends on frequency, to realistically attenuate the sounds you’ll have to incorporate an equalizer or similar pass that can independently apply attenuation to different frequency bands.

6eaf0e08fe36b2c23ca096562dd7a8b7
0
__________Smile_ 101 Jun 09, 2012 at 22:54

Also keep in mind that every surface is like mirror for sound, not diffuse, so general path tracers works incorrectly. I think it’s better to solve wave equation directly on some sparse grid (about 1m cells).

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Jun 10, 2012 at 02:27

WOW, it works incredibly well and sounds much better than commercial games!

Each characters have a sound and a loudness, as in light color and power. It also have a normal which define the direction of the sound it emit, but it’s 180 degree feathered.

Each material have an acoustic absorption value, and of course, the reminder is reflected. Like dark colors absorbs more and reflect less. No diffuse tho.

For each audio channel (speakers)…

  1. get the global position in the scene, and, the normal of each one which define the direction it is listening.

  2. shot random rays out into the scene, and for each rays…
    a. if nothing hit, do next.
    b. cast ray to each audible source
    c. if it hit, get the sound * constant/(dist*dist) * (1-material_absorb)
    d. next

The above produces stunning results. I have modified it to do more depth like a path tracer, and I’ve included real time propagation of sound, then wow, it is absolutely amazing. When you move the character, the sound is so 3D, it feels so real, you know exactly where the monsters are!

Does this already exist? Or did I simply made a money maker thing public domain? Because none of the commercial games we play have real 3D sound.

5f8d1e15c62932fa37f8a383b8567e52
0
macnihilist 101 Jun 10, 2012 at 07:50

@Alienizer

Does this already exist? Or did I simply made a money maker thing public domain? Because none of the commercial games we play have real 3D sound.

I don’t know about games, but in research ray tracing and other ‘graphics’ algorithms have been used for quite a while to do sound rendering.
My former employer, for example, had a group working on this stuff, google for ‘sound tracing’ and ‘phonon tracing’.
There are also real-time approaches.
So the idea is certainly not new, but packaged in a cool library it could be a nice thing.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Jun 10, 2012 at 14:47

So I did not invent anything then. [img]http://static.rcgroups.net/forums/attachments/1/7/6/0/7/2/a3863053-114-male19-male-crying-tears-smiley-emoticon-000061-large.gif?d=1300008028[/img]

B20d81438814b6ba7da7ff8eb502d039
0
Vilem_Otte 117 Jun 10, 2012 at 23:41

That smiley is just EPIC! :D … almost as epic as chibi Zaraki Kenpachi:

100px-Zaraki\_Chibi.jpg

I actually never seen *solid* library doing this-like stuff and I’m sure lots of people would definitely like to use it (incl. me for example).

Of course it might need lots of work to do (because users will put insanely large meshes into it, etc. - so you won’t get far without fast KD-Trees or (Q)BVHs for example … of course one can use F.e. Luxrender as a library for this to solve the problems … or create own solution).

2f202c9f415522f43d07a9f6b77f0527
0
vdf22 101 Jun 15, 2012 at 16:49

FMOD does this:

Custom geometry engine to add polygon scenes (FMOD Ex will factor in obstruction/occlusion)

Basically you give it a scene and it will perform calculations for you.