Hello!
I have been trying to get 3d Reverbs to work in my project. I have a script that creates the reverb3D, sets its 3d attributes and properties. I also modified RuntimeManager to set the reverb level for index 0 to 100% for all 3d instances. From the reading I’ve done on the docs, I was expecting to notice reverb attenuation as my character with the listener moved closer to the reverb zones. Does the RuntimeManager.CoreSystem.set3DListenerAttributes have to be called manually for all listeners? I thought the StudioListener kept track of its own position. Is the CoreSystem not included? Is there something I’m missing? Any help would be greatly appreciated. Thanks!
-Mitch
here is my code for the reverb zones
using UnityEngine;
using FMODUnity;
using FMOD;
namespace DarkData.Gameplay.Audio
{
public class DynamicReverbArea : MonoBehaviour
{
public enum ReverbType
{
CAVE,
UNDERWATER,
SEWER_PIPE,
VENT,
ARENA,
BATHROOM,
ROOM
}
[SerializeField] ReverbType reverbPreset;
[SerializeField] Reverb3D reverb;
protected Reverb3D GetReverb() { return reverb; }
[SerializeField] REVERB_PROPERTIES propertiersOne;
[SerializeField] [Range(1, 100)] float minDistance;
protected float GetMinDistance() { return minDistance; }
[SerializeField] [Range(1, 100)] float maxDistance;
protected float GetMaxDistance() { return maxDistance; }
protected FMOD.VECTOR positionReference;
private Color minDistanceColor = new Color(0.488f, 0, 0.488f, 0.6f);
private Color maxDistanceColor = new Color(0.3f, 0.2f, 0.7f, 0.4f);
protected virtual void Start()
{
Init();
}
protected void Init()
{
positionReference = RuntimeUtils.ToFMODVector(transform.position);
SetReverbProperties(out propertiersOne);
RuntimeManager.CoreSystem.createReverb3D(out reverb);
reverb.set3DAttributes(ref positionReference, minDistance, maxDistance);
reverb.setProperties(ref propertiersOne);
reverb.setActive(true);
}
private void Update()
{
//hack testing, remove this if it works and move to audio manager
for (int i = 0; i < RuntimeManager.Listeners.Count; i++)
{
if (RuntimeManager.Listeners[i] == null)
continue;
if (RuntimeManager.Listeners[i].transform == null)
continue;
VECTOR pos = RuntimeUtils.ToFMODVector(RuntimeManager.Listeners[i].transform.position);
VECTOR vel = RuntimeUtils.ToFMODVector(Vector3.zero);
VECTOR forward = RuntimeUtils.ToFMODVector(RuntimeManager.Listeners[i].transform.forward);
VECTOR up = RuntimeUtils.ToFMODVector(RuntimeManager.Listeners[i].transform.up);
//RuntimeManager.CoreSystem.set3DListenerAttributes(i, ref pos, ref pos, ref pos, ref pos);
RuntimeManager.CoreSystem.set3DListenerAttributes(i, ref pos, ref vel, ref forward, ref up);
}
UnityEngine.Debug.LogWarning("Reverb Instance stats = " + reverb.getProperties(ref propertiersOne).ToString() + " " + reverb.hasHandle().ToString());
}
private void SetReverbProperties(out REVERB_PROPERTIES prop)
{
switch (reverbPreset)
{
case ReverbType.CAVE:
prop = PRESET.CAVE();
break;
case ReverbType.UNDERWATER:
prop = PRESET.UNDERWATER();
break;
case ReverbType.SEWER_PIPE:
prop = PRESET.SEWERPIPE();
break;
case ReverbType.VENT:
prop = PRESET.STONECORRIDOR();
break;
case ReverbType.ARENA:
prop = PRESET.ARENA();
break;
case ReverbType.BATHROOM:
prop = PRESET.BATHROOM();
break;
case ReverbType.ROOM:
default:
prop = PRESET.ROOM();
break;
}
}
private void OnDestroy()
{
reverb.release();
reverb.setActive(false);
}
private void OnDrawGizmos()
{
Gizmos.color = minDistanceColor;
Gizmos.DrawSphere(transform.position, minDistance);
Gizmos.color = maxDistanceColor;
Gizmos.DrawSphere(transform.position, maxDistance);
}
}
}
and here is the modification I made to RuntimeManager
public static FMOD.Studio.EventInstance CreateInstance(FMOD.GUID guid)
{
FMOD.Studio.EventDescription eventDesc = GetEventDescription(guid);
FMOD.Studio.EventInstance newInstance;
eventDesc.createInstance(out newInstance);
bool is3D = false;
eventDesc.is3D(out is3D);
#if UNITY_EDITOR
if (is3D)
{
// Set position to 1e+18F, set3DAttributes should be called by the dev after this.
newInstance.set3DAttributes(RuntimeUtils.To3DAttributes(new Vector3(1e+18F, 1e+18F, 1e+18F)));
instance.eventPositionWarnings.Add(newInstance);
}
#endif
if (is3D)
{
newInstance.setReverbLevel(0, 1);
}
return newInstance;
}