0
0

Hi everyone,

I’m new to Unity and I already use FMOD ex for a little C++ apps. But someone ask me to create a plugin for Unity that enable the occlusion engine.

I create FMOD_occlusion.cs, to get the information of the object ( pos, vertices, triangles, etc) to be able to create the geometry in FMOD.

And I modify FMOD_StudioEventEmitter to compute the raycast between the emitter (source) and the camera (listener). I’m using the function getGeometryOcclusion like this :

[code:18a8il18]
void UpdateSoundOcclusion()
{
if (evt != null && evt.isValid ())
{
GameObject cameraObj;
cameraObj = GameObject.Find ("Main Camera");

        if (cameraObj) {
            FMOD.VECTOR source = FMOD.Studio.UnityUtil.toFMODVector (this.transform.position);
            FMOD.VECTOR listener = FMOD.Studio.UnityUtil.toFMODVector (cameraObj.transform.position);

            //Debug.Log ("Sound pos : " + source.x.ToString () + ", " + source.y + ", " + source.z.ToString ());
            //Debug.Log ("Camera pos : " + listener.x.ToString () + ", " + listener.y + ", " + listener.z.ToString ());

            FMOD.RESULT result = FMOD.RESULT.OK;
            FMOD.System GlobalSystem;

            result = FMOD_StudioSystem.instance.System.getLowLevelSystem (out GlobalSystem);

            ERRCHECK (result);

            if (result == FMOD.RESULT.OK) {
                float direct = 0.0f;
                float reverbed = 0.0f;
                GlobalSystem.getGeometryOcclusion (ref listener, ref source, out direct, out reverbed);

                //Debug.Log ("The current source : " + source.x.ToString () + ", " + source.y + ", " + source.z.ToString () + ". Have a direct occlusion of : " + direct.ToString() + " and a reverb occlusion of : " + reverbed.ToString());

                FMOD.ChannelGroup group = null;
                ERRCHECK (evt.getChannelGroup (out group));

                if(group != null)
                {
                    group.set3DOcclusion (direct, reverbed);
                }

                //GlobalSystem.update ();

                //Debug.Log ("Channel direct = " + direct + " and reverb = " + reverbed);               
            }
        }
    }
}

[/code:18a8il18]

I don’t know if their something else to do. But by using the example sound from FMOD studio. My occlusion working only on "Music" and it’s not working well. Because by moving camera occlud or not occlud it taking few second to catch it (But the console call the log that tell it occlud or not every frame).

I was wondering if the sound was the trouble and not my code and by using a scattered sound, this occlusion code works pretty well. But with a single sound in loop, the occlusion don’t work at all.

Is there something special to do in my C# code to be sure it work with everything or need to create a specific kind of sound to be able to use it with occlusion geometry. Or maybe the problem is with the group.set3DOcclusion function ?

Anyone have a idea of what happen ?

Here the full code of FMOD_occlusion to create the object and the modified FMOD_StudioEventEmitter

[attachment=0:18a8il18]FMOD_occl.zip[/attachment:18a8il18]

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.