예제 #1
0
        public override void Initialize(ComponentCache componentCache, GameEngineState gameEngineState, string[] sofaFileNames)
        {
            foreach (var sofaFileName in sofaFileNames)
            {
                PhononFmod.iplFmodAddSOFAFileName(sofaFileName);
            }
            PhononFmod.iplFmodSetCurrentSOFAFile(0);

            PhononFmod.iplFmodSetEnvironment(gameEngineState.SimulationSettings(),
                                             gameEngineState.Environment().GetEnvironment(), gameEngineState.ConvolutionType());
        }
예제 #2
0
        public void Initialize(AudioEngine engine, ComponentCache componentCache, GameEngineState gameEngineState)
        {
            audioEngine = engine;

            switch (audioEngine)
            {
            case AudioEngine.UnityNative:
                PhononUnityNative.iplUnitySetEnvironment(gameEngineState.SimulationSettings(),
                                                         gameEngineState.Environment().GetEnvironment());
                break;

            default:
                Debug.LogError("Unsupported audio engine: " + audioEngine.ToString());
                break;
            }
        }
예제 #3
0
        public void Initialize(SimulationSettingsValue settings, ComponentCache componentCache,
                               GameEngineStateInitReason reason)
        {
            PhononCore.iplCreateContext(LogMessage, IntPtr.Zero, IntPtr.Zero, ref context);

            var customSettings = componentCache.SteamAudioCustomSettings();

            var useOpenCL         = false;
            var computeDeviceType = ComputeDeviceType.Any;
            var numComputeUnits   = 0;

            if (customSettings)
            {
                convolutionType = customSettings.convolutionOption;

                if (customSettings.convolutionOption == ConvolutionOption.TrueAudioNext)
                {
                    useOpenCL         = true;
                    computeDeviceType = ComputeDeviceType.GPU;
                    numComputeUnits   = customSettings.numComputeUnits;
                }
                else if (customSettings.rayTracerOption == SceneType.RadeonRays)
                {
                    useOpenCL = true;
                }
            }

            try
            {
                computeDevice.Create(context, useOpenCL, computeDeviceType, numComputeUnits);
            }
            catch (Exception e)
            {
                throw e;
            }

            var inEditor = !SteamAudioManager.IsAudioEngineInitializing();

            simulationSettings = new SimulationSettings
            {
                sceneType             = (customSettings) ? customSettings.rayTracerOption : SceneType.Phonon,
                rays                  = (inEditor) ? settings.BakeRays : settings.RealtimeRays,
                secondaryRays         = (inEditor) ? settings.BakeSecondaryRays : settings.RealtimeSecondaryRays,
                bounces               = (inEditor) ? settings.BakeBounces : settings.RealtimeBounces,
                irDuration            = settings.Duration,
                ambisonicsOrder       = settings.AmbisonicsOrder,
                maxConvolutionSources = settings.MaxSources
            };

            if (reason != GameEngineStateInitReason.ExportingScene)
            {
                scene.Create(computeDevice, simulationSettings, context);
            }

            if (reason == GameEngineStateInitReason.Playing)
            {
                probeManager.Create(context);
            }

            if (reason != GameEngineStateInitReason.ExportingScene &&
                reason != GameEngineStateInitReason.GeneratingProbes)
            {
                try
                {
                    environment.Create(computeDevice, simulationSettings, scene, probeManager, context);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }
예제 #4
0
        public void Initialize(SimulationSettingsValue settings, ComponentCache componentCache,
                               GameEngineStateInitReason reason)
        {
            PhononCore.iplCreateContext(LogMessage, IntPtr.Zero, IntPtr.Zero, ref context);

            if (reason != GameEngineStateInitReason.EditingProbes)
            {
                var customSettings = componentCache.SteamAudioCustomSettings();

                var useOpenCL         = false;
                var computeDeviceType = ComputeDeviceType.Any;
                var requiresTan       = false;
                var minReservableCUs  = 0;
                var maxCUsToReserve   = 0;

                if (customSettings)
                {
                    convolutionType = customSettings.ConvolutionType();

                    if (convolutionType == ConvolutionOption.TrueAudioNext)
                    {
                        useOpenCL         = true;
                        requiresTan       = true;
                        computeDeviceType = ComputeDeviceType.GPU;
                        minReservableCUs  = customSettings.minComputeUnitsToReserve;
                        maxCUsToReserve   = customSettings.maxComputeUnitsToReserve;
                    }
                    else if (customSettings.RayTracerType() == SceneType.RadeonRays)
                    {
                        useOpenCL = true;
                    }
                }

                try
                {
                    var deviceFilter = new ComputeDeviceFilter
                    {
                        type = computeDeviceType,
                        requiresTrueAudioNext = (requiresTan) ? Bool.True : Bool.False,
                        minReservableCUs      = minReservableCUs,
                        maxCUsToReserve       = maxCUsToReserve
                    };

                    computeDevice.Create(context, useOpenCL, deviceFilter);
                }
                catch (Exception e)
                {
                    Debug.LogWarning(String.Format("Unable to initialize TrueAudio Next: {0}. Using Phonon convolution.",
                                                   e.Message));

                    convolutionType = ConvolutionOption.Phonon;
                }

                var inEditor = !SteamAudioManager.IsAudioEngineInitializing();

                var maxSources = settings.MaxSources;
                if (customSettings && convolutionType == ConvolutionOption.TrueAudioNext)
                {
                    maxSources = customSettings.MaxSources;
                }
                if (customSettings && customSettings.RayTracerType() == SceneType.RadeonRays && reason == GameEngineStateInitReason.Baking)
                {
                    maxSources = customSettings.BakingBatchSize;
                }

                var rayTracer = SceneType.Phonon;
                if (customSettings)
                {
                    if (customSettings.RayTracerType() != SceneType.RadeonRays ||
                        reason != GameEngineStateInitReason.Playing)
                    {
                        rayTracer = customSettings.RayTracerType();
                    }
                }

                simulationSettings = new SimulationSettings
                {
                    sceneType             = rayTracer,
                    occlusionSamples      = settings.OcclusionSamples,
                    rays                  = (inEditor) ? settings.BakeRays : settings.RealtimeRays,
                    secondaryRays         = (inEditor) ? settings.BakeSecondaryRays : settings.RealtimeSecondaryRays,
                    bounces               = (inEditor) ? settings.BakeBounces : settings.RealtimeBounces,
                    threads               = (inEditor) ? (int)Mathf.Max(1, (settings.BakeThreadsPercentage * SystemInfo.processorCount) / 100.0f) : (int)Mathf.Max(1, (settings.RealtimeThreadsPercentage * SystemInfo.processorCount) / 100.0f),
                    irDuration            = (customSettings && convolutionType == ConvolutionOption.TrueAudioNext) ? customSettings.Duration : settings.Duration,
                    ambisonicsOrder       = (customSettings && convolutionType == ConvolutionOption.TrueAudioNext) ? customSettings.AmbisonicsOrder : settings.AmbisonicsOrder,
                    maxConvolutionSources = maxSources,
                    bakingBatchSize       = (customSettings && customSettings.RayTracerType() == SceneType.RadeonRays) ? customSettings.BakingBatchSize : 1
                };

#if UNITY_EDITOR
                if (customSettings)
                {
                    if (customSettings.RayTracerType() == SceneType.Embree)
                    {
                        if (!File.Exists(Directory.GetCurrentDirectory() + "/Assets/Plugins/x86_64/embree.dll"))
                        {
                            throw new Exception(
                                      "Steam Audio configured to use Embree, but Embree support package not installed. " +
                                      "Please import SteamAudio_Embree.unitypackage in order to use Embree support for " +
                                      "Steam Audio.");
                        }
                    }
                    else if (customSettings.RayTracerType() == SceneType.RadeonRays)
                    {
                        if (!File.Exists(Directory.GetCurrentDirectory() + "/Assets/Plugins/x86_64/RadeonRays.dll"))
                        {
                            throw new Exception(
                                      "Steam Audio configured to use Radeon Rays, but Radeon Rays support package not " +
                                      "installed. Please import SteamAudio_RadeonRays.unitypackage in order to use Radeon " +
                                      "Rays support for Steam Audio.");
                        }
                    }

                    if (customSettings.ConvolutionType() == ConvolutionOption.TrueAudioNext)
                    {
                        if (!File.Exists(Directory.GetCurrentDirectory() + "/Assets/Plugins/x86_64/tanrt64.dll"))
                        {
                            throw new Exception(
                                      "Steam Audio configured to use TrueAudio Next, but TrueAudio Next support package " +
                                      "not installed. Please import SteamAudio_TrueAudioNext.unitypackage in order to use " +
                                      "TrueAudio Next support for Steam Audio.");
                        }
                    }
                }
#endif

                if (reason != GameEngineStateInitReason.ExportingScene)
                {
                    scene.Create(computeDevice, simulationSettings, context);
                }

                if (reason == GameEngineStateInitReason.Playing)
                {
                    probeManager.Create(context);
                }

                if (reason != GameEngineStateInitReason.ExportingScene &&
                    reason != GameEngineStateInitReason.GeneratingProbes)
                {
                    try
                    {
                        environment.Create(computeDevice, simulationSettings, scene, probeManager, context);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }
        }
예제 #5
0
        public void Initialize(SimulationSettingsValue settings, ComponentCache componentCache,
            GameEngineStateInitReason reason)
        {
            PhononCore.iplCreateContext(LogMessage, IntPtr.Zero, IntPtr.Zero, ref context);

            if (reason != GameEngineStateInitReason.EditingProbes)
            {
                var customSettings = componentCache.SteamAudioCustomSettings();

                var useOpenCL = false;
                var computeDeviceType = ComputeDeviceType.Any;
                var requiresTan = false;
                var minReservableCUs = 0;
                var maxCUsToReserve = 0;

                if (customSettings)
                {
                    convolutionType = customSettings.convolutionOption;

                    if (customSettings.convolutionOption == ConvolutionOption.TrueAudioNext)
                    {
                        useOpenCL = true;
                        requiresTan = true;
                        computeDeviceType = ComputeDeviceType.GPU;
                        minReservableCUs = customSettings.minComputeUnitsToReserve;
                        maxCUsToReserve = customSettings.maxComputeUnitsToReserve;
                    }
                    else if (customSettings.rayTracerOption == SceneType.RadeonRays)
                    {
                        useOpenCL = true;
                    }
                }

                try
				{
                    var deviceFilter = new ComputeDeviceFilter
                    {
                        type = computeDeviceType,
                        requiresTrueAudioNext = (requiresTan) ? Bool.True : Bool.False,
                        minReservableCUs = minReservableCUs,
                        maxCUsToReserve = maxCUsToReserve
                    };

                    computeDevice.Create(context, useOpenCL, deviceFilter);
				}
                catch (Exception e)
                {
                    Debug.LogWarning(String.Format("Unable to initialize TrueAudio Next: {0}. Using Phonon convolution.",
                        e.Message));

                    customSettings.convolutionOption = ConvolutionOption.Phonon;
                }

                var inEditor = !SteamAudioManager.IsAudioEngineInitializing();

                simulationSettings = new SimulationSettings
                {
                    sceneType               = (customSettings) ? customSettings.rayTracerOption : SceneType.Phonon,
                    rays                    = (inEditor) ? settings.BakeRays : settings.RealtimeRays,
                    secondaryRays           = (inEditor) ? settings.BakeSecondaryRays : settings.RealtimeSecondaryRays,
                    bounces                 = (inEditor) ? settings.BakeBounces : settings.RealtimeBounces,
                    irDuration              = (customSettings && customSettings.convolutionOption == ConvolutionOption.TrueAudioNext) ? customSettings.Duration : settings.Duration,
                    ambisonicsOrder         = (customSettings && customSettings.convolutionOption == ConvolutionOption.TrueAudioNext) ? customSettings.AmbisonicsOrder : settings.AmbisonicsOrder,
                    maxConvolutionSources   = (customSettings && customSettings.convolutionOption == ConvolutionOption.TrueAudioNext) ? customSettings.MaxSources : settings.MaxSources
                };

                if (reason != GameEngineStateInitReason.ExportingScene)
                    scene.Create(computeDevice, simulationSettings, context);

                if (reason == GameEngineStateInitReason.Playing)
                    probeManager.Create(context);

                if (reason != GameEngineStateInitReason.ExportingScene &&
                    reason != GameEngineStateInitReason.GeneratingProbes)
                {
                    try
                    {
                        environment.Create(computeDevice, simulationSettings, scene, probeManager, context);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }
        }
예제 #6
0
        public void Initialize(SimulationSettingsValue settings, ComponentCache componentCache,
                               GameEngineStateInitReason reason)
        {
            PhononCore.iplCreateContext(LogMessage, IntPtr.Zero, IntPtr.Zero, ref context);

            if (reason != GameEngineStateInitReason.EditingProbes)
            {
                var customSettings = componentCache.SteamAudioCustomSettings();

                var useOpenCL              = false;
                var computeDeviceType      = ComputeDeviceType.Any;
                var maxCUsToReserve        = 0;
                var fractionCUsForIRUpdate = .0f;

                convolutionType = ConvolutionOption.Phonon;
                var rayTracer = SceneType.Phonon;

                // TAN is enabled for realtime.
                if (customSettings && customSettings.ConvolutionType() == ConvolutionOption.TrueAudioNext &&
                    reason == GameEngineStateInitReason.Playing)
                {
                    convolutionType = customSettings.ConvolutionType();

                    useOpenCL              = true;
                    computeDeviceType      = ComputeDeviceType.GPU;
                    maxCUsToReserve        = customSettings.maxComputeUnitsToReserve;
                    fractionCUsForIRUpdate = customSettings.fractionComputeUnitsForIRUpdate;
                }

                // Enable some settings which are commong whether Radeon Rays is enabled for baking or realtime.
                if (customSettings &&
                    (reason == GameEngineStateInitReason.Baking ||
                     reason == GameEngineStateInitReason.GeneratingProbes ||
                     reason == GameEngineStateInitReason.Playing))
                {
                    if (customSettings.RayTracerType() != SceneType.RadeonRays)
                    {
                        rayTracer = customSettings.RayTracerType();
                    }
                    else
                    {
                        useOpenCL         = true;
                        rayTracer         = SceneType.RadeonRays;
                        computeDeviceType = ComputeDeviceType.GPU;
                    }
                }

                // Enable additional settings when Radeon Rays is enabled for realtime but TAN is not.
                if (customSettings && customSettings.RayTracerType() == SceneType.RadeonRays &&
                    customSettings.ConvolutionType() != ConvolutionOption.TrueAudioNext &&
                    reason == GameEngineStateInitReason.Playing)
                {
                    maxCUsToReserve        = customSettings.maxComputeUnitsToReserve;
                    fractionCUsForIRUpdate = 1.0f;
                }

                try
                {
                    var deviceFilter = new ComputeDeviceFilter
                    {
                        type                   = computeDeviceType,
                        maxCUsToReserve        = maxCUsToReserve,
                        fractionCUsForIRUpdate = fractionCUsForIRUpdate
                    };

                    computeDevice.Create(context, useOpenCL, deviceFilter);
                }
                catch (Exception e)
                {
                    if (customSettings && convolutionType == ConvolutionOption.TrueAudioNext)
                    {
                        var eInEditor = !SteamAudioManager.IsAudioEngineInitializing();
                        if (eInEditor && (!File.Exists(Directory.GetCurrentDirectory() + "/Assets/Plugins/x86_64/tanrt64.dll")))
                        {
                            throw new Exception(
                                      "Steam Audio configured to use TrueAudio Next, but TrueAudio Next support package " +
                                      "not installed. Please import SteamAudio_TrueAudioNext.unitypackage in order to use " +
                                      "TrueAudio Next support for Steam Audio.");
                        }
                        else
                        {
                            Debug.LogWarning(String.Format("Unable to create compute device: {0}. Using Phonon convolution and raytracer.",
                                                           e.Message));
                        }
                    }
                    else
                    {
                        Debug.LogWarning(String.Format("Unable to create compute device: {0}. Using Phonon convolution and raytracer.",
                                                       e.Message));
                    }

                    convolutionType = ConvolutionOption.Phonon;
                    rayTracer       = SceneType.Phonon;
                }

                var inEditor = !SteamAudioManager.IsAudioEngineInitializing();

                var maxSources = settings.MaxSources;
                if (customSettings && convolutionType == ConvolutionOption.TrueAudioNext)
                {
                    maxSources = customSettings.MaxSources;
                }
                if (rayTracer == SceneType.RadeonRays && reason == GameEngineStateInitReason.Baking)
                {
                    maxSources = customSettings.BakingBatchSize;
                }

                simulationSettings = new SimulationSettings
                {
                    sceneType           = rayTracer,
                    maxOcclusionSamples = settings.MaxOcclusionSamples,
                    rays                  = (inEditor) ? settings.BakeRays : settings.RealtimeRays,
                    secondaryRays         = (inEditor) ? settings.BakeSecondaryRays : settings.RealtimeSecondaryRays,
                    bounces               = (inEditor) ? settings.BakeBounces : settings.RealtimeBounces,
                    threads               = (inEditor) ? (int)Mathf.Max(1, (settings.BakeThreadsPercentage * SystemInfo.processorCount) / 100.0f) : (int)Mathf.Max(1, (settings.RealtimeThreadsPercentage * SystemInfo.processorCount) / 100.0f),
                    irDuration            = (customSettings && convolutionType == ConvolutionOption.TrueAudioNext) ? customSettings.Duration : settings.Duration,
                    ambisonicsOrder       = (customSettings && convolutionType == ConvolutionOption.TrueAudioNext) ? customSettings.AmbisonicsOrder : settings.AmbisonicsOrder,
                    maxConvolutionSources = maxSources,
                    bakingBatchSize       = (rayTracer == SceneType.RadeonRays) ? customSettings.BakingBatchSize : 1,
                    irradianceMinDistance = settings.IrradianceMinDistance
                };

#if UNITY_EDITOR
                if (customSettings)
                {
                    if (rayTracer == SceneType.RadeonRays)
                    {
                        if (!File.Exists(Directory.GetCurrentDirectory() + "/Assets/Plugins/x86_64/RadeonRays.dll"))
                        {
                            throw new Exception(
                                      "Steam Audio configured to use Radeon Rays, but Radeon Rays support package not " +
                                      "installed. Please import SteamAudio_RadeonRays.unitypackage in order to use Radeon " +
                                      "Rays support for Steam Audio.");
                        }
                    }

                    if (convolutionType == ConvolutionOption.TrueAudioNext)
                    {
                        if (!File.Exists(Directory.GetCurrentDirectory() + "/Assets/Plugins/x86_64/tanrt64.dll"))
                        {
                            throw new Exception(
                                      "Editor: Steam Audio configured to use TrueAudio Next, but TrueAudio Next support package " +
                                      "not installed. Please import SteamAudio_TrueAudioNext.unitypackage in order to use " +
                                      "TrueAudio Next support for Steam Audio.");
                        }
                    }
                }
#endif

                if (reason != GameEngineStateInitReason.ExportingScene)
                {
                    scene.Create(computeDevice, simulationSettings, context);
                }

                // Add other scenes in the hierarchy
                if (scene.GetScene() != IntPtr.Zero &&
                    (reason == GameEngineStateInitReason.GeneratingProbes || reason == GameEngineStateInitReason.Baking))
                {
                    for (int i = 0; i < SceneManager.sceneCount; ++i)
                    {
                        var unityScene = SceneManager.GetSceneAt(i);
                        if (!unityScene.isLoaded)
                        {
                            continue;
                        }

                        if (unityScene == SceneManager.GetActiveScene())
                        {
                            continue;
                        }

                        IntPtr additiveScene, additiveMesh;
                        var    error = scene.AddAdditiveScene(unityScene, scene.GetScene(),
                                                              computeDevice, simulationSettings, context, out additiveScene, out additiveMesh);

                        if (error != Error.None)
                        {
                            continue;
                        }

                        if (additiveScenes == null)
                        {
                            editorAdditiveScenes = new List <IntPtr>();
                        }
                        editorAdditiveScenes.Add(additiveScene);

                        if (editorAdditiveSceneMeshes == null)
                        {
                            editorAdditiveSceneMeshes = new List <IntPtr>();
                        }
                        editorAdditiveSceneMeshes.Add(additiveMesh);
                    }

                    PhononCore.iplCommitScene(scene.GetScene());
                }

                if (reason == GameEngineStateInitReason.Playing)
                {
                    probeManager.Create(context);
                }

                if (reason != GameEngineStateInitReason.ExportingScene &&
                    reason != GameEngineStateInitReason.GeneratingProbes)
                {
                    try
                    {
                        environment.Create(computeDevice, simulationSettings, scene, probeManager, context);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }
        }