Jump to content


Light vs Sound.


10 replies to this topic

#1 Alienizer

    Member

  • Members
  • PipPipPipPip
  • 435 posts

Posted 08 June 2012 - 09:55 PM

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?

#2 Vilem Otte

    Valued Member

  • Members
  • PipPipPipPip
  • 345 posts

Posted 09 June 2012 - 12:31 PM

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)
My blog about game development (and not just game development) - http://gameprogramme...y.blogspot.com/

If you don't know how to speed up application, go "roarrrrrr!", hit the compiler with the club and use -O3 :D

#3 Alienizer

    Member

  • Members
  • PipPipPipPip
  • 435 posts

Posted 09 June 2012 - 03:05 PM

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.

#4 Vilem Otte

    Valued Member

  • Members
  • PipPipPipPip
  • 345 posts

Posted 09 June 2012 - 05:06 PM

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.
My blog about game development (and not just game development) - http://gameprogramme...y.blogspot.com/

If you don't know how to speed up application, go "roarrrrrr!", hit the compiler with the club and use -O3 :D

#5 Reedbeta

    DevMaster Staff

  • Administrators
  • 5309 posts
  • LocationSanta Clara, CA

Posted 09 June 2012 - 09:56 PM

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.
reedbeta.com - developer blog, OpenGL demos, and other projects

#6 }:+()___ (Smile)

    Member

  • Members
  • PipPipPip
  • 169 posts

Posted 09 June 2012 - 10:54 PM

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).
Sorry my broken english!

#7 Alienizer

    Member

  • Members
  • PipPipPipPip
  • 435 posts

Posted 10 June 2012 - 02:27 AM

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.

#8 macnihilist

    New Member

  • Members
  • PipPip
  • 19 posts

Posted 10 June 2012 - 07:50 AM

View PostAlienizer, on 10 June 2012 - 02:27 AM, said:

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.

#9 Alienizer

    Member

  • Members
  • PipPipPipPip
  • 435 posts

Posted 10 June 2012 - 02:47 PM

So I did not invent anything then. Posted Image

#10 Vilem Otte

    Valued Member

  • Members
  • PipPipPipPip
  • 345 posts

Posted 10 June 2012 - 11:41 PM

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

Posted Image


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).
My blog about game development (and not just game development) - http://gameprogramme...y.blogspot.com/

If you don't know how to speed up application, go "roarrrrrr!", hit the compiler with the club and use -O3 :D

#11 vdf22

    New Member

  • Members
  • PipPip
  • 30 posts

Posted 15 June 2012 - 04:49 PM

FMOD does this:

Quote

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users