4.5.3
This commit is contained in:
46
Scripts/Runtime/AudioEngineAmbisonicSource.cs
Executable file
46
Scripts/Runtime/AudioEngineAmbisonicSource.cs
Executable file
@ -0,0 +1,46 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public abstract class AudioEngineAmbisonicSource
|
||||
{
|
||||
public virtual void Initialize(GameObject gameObject)
|
||||
{ }
|
||||
|
||||
public virtual void Destroy()
|
||||
{ }
|
||||
|
||||
public virtual void UpdateParameters(SteamAudioAmbisonicSource ambisonicSource)
|
||||
{ }
|
||||
|
||||
public virtual void GetParameters(SteamAudioAmbisonicSource ambisonicSource)
|
||||
{ }
|
||||
|
||||
public static AudioEngineAmbisonicSource Create(AudioEngineType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case AudioEngineType.Unity:
|
||||
return new UnityAudioEngineAmbisonicSource();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Scripts/Runtime/AudioEngineAmbisonicSource.cs.meta
Executable file
11
Scripts/Runtime/AudioEngineAmbisonicSource.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf3a8878920e660448a9f5dd6ff8589f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
59
Scripts/Runtime/AudioEngineSource.cs
Executable file
59
Scripts/Runtime/AudioEngineSource.cs
Executable file
@ -0,0 +1,59 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#if STEAMAUDIO_ENABLED
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public abstract class AudioEngineSource
|
||||
{
|
||||
public virtual void Initialize(GameObject gameObject)
|
||||
{ }
|
||||
|
||||
public virtual void Destroy()
|
||||
{ }
|
||||
|
||||
public virtual void UpdateParameters(SteamAudioSource source)
|
||||
{ }
|
||||
|
||||
public virtual void GetParameters(SteamAudioSource source)
|
||||
{ }
|
||||
|
||||
public static AudioEngineSource Create(AudioEngineType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case AudioEngineType.Unity:
|
||||
return new UnityAudioEngineSource();
|
||||
case AudioEngineType.FMODStudio:
|
||||
return CreateFMODStudioAudioEngineSource();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static AudioEngineSource CreateFMODStudioAudioEngineSource()
|
||||
{
|
||||
var type = Type.GetType("SteamAudio.FMODStudioAudioEngineSource,SteamAudioUnity");
|
||||
return (type != null) ? (AudioEngineSource) Activator.CreateInstance(type) : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
11
Scripts/Runtime/AudioEngineSource.cs.meta
Executable file
11
Scripts/Runtime/AudioEngineSource.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf1484b65484cc846b06a489d54195a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
89
Scripts/Runtime/AudioEngineState.cs
Executable file
89
Scripts/Runtime/AudioEngineState.cs
Executable file
@ -0,0 +1,89 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#if STEAMAUDIO_ENABLED
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using SteamAudio;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public abstract class AudioEngineState
|
||||
{
|
||||
public virtual void Initialize(IntPtr context, IntPtr defaultHRTF, SimulationSettings simulationSettings, PerspectiveCorrection correction)
|
||||
{ }
|
||||
|
||||
public virtual void Destroy()
|
||||
{ }
|
||||
|
||||
public virtual void SetHRTF(IntPtr hrtf)
|
||||
{ }
|
||||
|
||||
public virtual void SetPerspectiveCorrection(PerspectiveCorrection correction)
|
||||
{ }
|
||||
|
||||
public virtual void SetReverbSource(Source reverbSource)
|
||||
{ }
|
||||
|
||||
public static AudioEngineState Create(AudioEngineType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case AudioEngineType.Unity:
|
||||
return new UnityAudioEngineState();
|
||||
case AudioEngineType.FMODStudio:
|
||||
return CreateFMODStudioAudioEngineState();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static AudioEngineState CreateFMODStudioAudioEngineState()
|
||||
{
|
||||
var type = Type.GetType("SteamAudio.FMODStudioAudioEngineState,SteamAudioUnity");
|
||||
return (type != null) ? (AudioEngineState) Activator.CreateInstance(type) : null;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class AudioEngineStateHelpers
|
||||
{
|
||||
public abstract Transform GetListenerTransform();
|
||||
|
||||
public abstract SteamAudio.AudioSettings GetAudioSettings();
|
||||
|
||||
public static AudioEngineStateHelpers Create(AudioEngineType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case AudioEngineType.Unity:
|
||||
return new UnityAudioEngineStateHelpers();
|
||||
case AudioEngineType.FMODStudio:
|
||||
return CreateFMODStudioAudioEngineStateHelpers();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static AudioEngineStateHelpers CreateFMODStudioAudioEngineStateHelpers()
|
||||
{
|
||||
var type = Type.GetType("SteamAudio.FMODStudioAudioEngineStateHelpers,SteamAudioUnity");
|
||||
return (type != null) ? (AudioEngineStateHelpers) Activator.CreateInstance(type) : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
11
Scripts/Runtime/AudioEngineState.cs.meta
Executable file
11
Scripts/Runtime/AudioEngineState.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82bc9a6ff2f97254787d9f40d71ae2e0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
349
Scripts/Runtime/Baker.cs
Executable file
349
Scripts/Runtime/Baker.cs
Executable file
@ -0,0 +1,349 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#if STEAMAUDIO_ENABLED
|
||||
|
||||
using AOT;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
#endif
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public enum BakeStatus
|
||||
{
|
||||
Ready,
|
||||
InProgress,
|
||||
Complete
|
||||
}
|
||||
|
||||
public struct BakedDataTask
|
||||
{
|
||||
public GameObject gameObject;
|
||||
public MonoBehaviour component;
|
||||
public string name;
|
||||
public BakedDataIdentifier identifier;
|
||||
public SteamAudioProbeBatch[] probeBatches;
|
||||
public string[] probeBatchNames;
|
||||
public SerializedData[] probeBatchAssets;
|
||||
}
|
||||
|
||||
public static class Baker
|
||||
{
|
||||
static BakeStatus sStatus = BakeStatus.Ready;
|
||||
#if UNITY_EDITOR
|
||||
static float sProgress = 0.0f;
|
||||
#endif
|
||||
static ProgressCallback sProgressCallback = null;
|
||||
static IntPtr sProgressCallbackPointer = IntPtr.Zero;
|
||||
static GCHandle sProgressCallbackHandle;
|
||||
static Thread sThread;
|
||||
static int sCurrentObjectIndex = 0;
|
||||
static int sTotalObjects = 0;
|
||||
static string sCurrentObjectName = null;
|
||||
static int sCurrentProbeBatchIndex = 0;
|
||||
static int sTotalProbeBatches = 0;
|
||||
static bool sCancel = false;
|
||||
static BakedDataTask[] sTasks = null;
|
||||
|
||||
public static void BeginBake(BakedDataTask[] tasks)
|
||||
{
|
||||
SteamAudioManager.Initialize(ManagerInitReason.Baking);
|
||||
|
||||
if (SteamAudioManager.GetSceneType() == SceneType.Custom)
|
||||
{
|
||||
Debug.LogError("Baking is not supported when using Unity's built-in ray tracer. Click Steam Audio > Settings and switch to a different ray tracer.");
|
||||
return;
|
||||
}
|
||||
|
||||
SteamAudioManager.LoadScene(SceneManager.GetActiveScene(), SteamAudioManager.Context, false);
|
||||
|
||||
SteamAudioStaticMesh staticMeshComponent = null;
|
||||
var rootObjects = SceneManager.GetActiveScene().GetRootGameObjects();
|
||||
foreach (var rootObject in rootObjects)
|
||||
{
|
||||
staticMeshComponent = rootObject.GetComponentInChildren<SteamAudioStaticMesh>();
|
||||
if (staticMeshComponent)
|
||||
break;
|
||||
}
|
||||
|
||||
if (staticMeshComponent == null || staticMeshComponent.asset == null)
|
||||
{
|
||||
Debug.LogError(string.Format("Scene {0} has not been exported. Click Steam Audio > Export Active Scene to do so.", SceneManager.GetActiveScene().name));
|
||||
return;
|
||||
}
|
||||
|
||||
var staticMesh = new StaticMesh(SteamAudioManager.Context, SteamAudioManager.CurrentScene, staticMeshComponent.asset);
|
||||
staticMesh.AddToScene(SteamAudioManager.CurrentScene);
|
||||
|
||||
SteamAudioManager.CurrentScene.Commit();
|
||||
|
||||
staticMesh.Release();
|
||||
|
||||
sTasks = tasks;
|
||||
sStatus = BakeStatus.InProgress;
|
||||
|
||||
sProgressCallback = new ProgressCallback(AdvanceProgress);
|
||||
|
||||
#if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN)
|
||||
sProgressCallbackPointer = Marshal.GetFunctionPointerForDelegate(sProgressCallback);
|
||||
sProgressCallbackHandle = GCHandle.Alloc(sProgressCallbackPointer);
|
||||
GC.Collect();
|
||||
#endif
|
||||
|
||||
#if UNITY_EDITOR
|
||||
EditorApplication.update += InEditorUpdate;
|
||||
#endif
|
||||
|
||||
sThread = new Thread(BakeThread);
|
||||
sThread.Start();
|
||||
}
|
||||
|
||||
public static void EndBake()
|
||||
{
|
||||
if (sThread != null)
|
||||
{
|
||||
sThread.Join();
|
||||
}
|
||||
|
||||
SerializedObject.FlushAllWrites();
|
||||
|
||||
#if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN)
|
||||
if (sProgressCallbackHandle.IsAllocated)
|
||||
{
|
||||
sProgressCallbackHandle.Free();
|
||||
}
|
||||
#endif
|
||||
|
||||
SteamAudioManager.ShutDown();
|
||||
UnityEngine.Object.DestroyImmediate(SteamAudioManager.Singleton.gameObject);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
sProgress = 0.0f;
|
||||
#endif
|
||||
sCurrentObjectIndex = 0;
|
||||
sTotalObjects = 0;
|
||||
sCurrentObjectName = null;
|
||||
sCurrentProbeBatchIndex = 0;
|
||||
sTotalProbeBatches = 0;
|
||||
|
||||
sStatus = BakeStatus.Ready;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
EditorApplication.update -= InEditorUpdate;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool IsBakeActive()
|
||||
{
|
||||
return (sStatus != BakeStatus.Ready);
|
||||
}
|
||||
|
||||
public static bool DrawProgressBar()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (sStatus != BakeStatus.InProgress)
|
||||
return false;
|
||||
|
||||
var progress = sProgress + .01f; // Adding an offset because progress bar when it is exact 0 has some non-zero progress.
|
||||
var progressPercent = Mathf.FloorToInt(Mathf.Min(progress * 100.0f, 100.0f));
|
||||
var progressString = string.Format("Object {0} / {1} [{2}]: Baking {3} / {4} Probe Batch ({5}% complete)",
|
||||
sCurrentObjectIndex + 1, sTotalObjects, sCurrentObjectName, sCurrentProbeBatchIndex + 1, sTotalProbeBatches, progressPercent);
|
||||
|
||||
EditorGUI.ProgressBar(EditorGUILayout.GetControlRect(), progress, progressString);
|
||||
|
||||
if (GUILayout.Button("Cancel"))
|
||||
{
|
||||
CancelBake();
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void CancelBake()
|
||||
{
|
||||
// Ensures partial baked data is not serialized and that bake is properly canceled for multiple
|
||||
// probe boxes.
|
||||
sCancel = true;
|
||||
API.iplReflectionsBakerCancelBake(SteamAudioManager.Context.Get());
|
||||
EndBake();
|
||||
sCancel = false;
|
||||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(ProgressCallback))]
|
||||
static void AdvanceProgress(float progress, IntPtr userData)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
sProgress = progress;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void InEditorUpdate()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (sStatus == BakeStatus.Complete)
|
||||
{
|
||||
EndBake();
|
||||
EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void BakeThread()
|
||||
{
|
||||
sTotalObjects = sTasks.Length;
|
||||
|
||||
for (var i = 0; i < sTotalObjects; ++i)
|
||||
{
|
||||
sCurrentObjectIndex = i;
|
||||
|
||||
if (sTasks[i].identifier.type == BakedDataType.Pathing)
|
||||
{
|
||||
sCurrentObjectName = "pathing";
|
||||
}
|
||||
else if (sTasks[i].identifier.variation == BakedDataVariation.Reverb)
|
||||
{
|
||||
sCurrentObjectName = "reverb";
|
||||
}
|
||||
else
|
||||
{
|
||||
sCurrentObjectName = sTasks[i].name;
|
||||
}
|
||||
|
||||
Debug.Log(string.Format("START: Baking effect for {0}.", sCurrentObjectName));
|
||||
|
||||
var probeBatches = sTasks[i].probeBatches;
|
||||
sTotalProbeBatches = probeBatches.Length;
|
||||
|
||||
for (var j = 0; j < sTotalProbeBatches; ++j)
|
||||
{
|
||||
sCurrentProbeBatchIndex = j;
|
||||
|
||||
if (sCancel)
|
||||
return;
|
||||
|
||||
if (probeBatches[j] == null)
|
||||
{
|
||||
Debug.LogWarning(string.Format("{0}: Probe Batch at index {1} is null.", sCurrentObjectName, j));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (probeBatches[j].GetNumProbes() == 0)
|
||||
{
|
||||
Debug.LogWarning(string.Format("{0}: Probe Batch {1} has no probes, skipping.", sCurrentObjectName, sTasks[i].probeBatchNames[j]));
|
||||
continue;
|
||||
}
|
||||
|
||||
var probeBatch = new ProbeBatch(SteamAudioManager.Context, sTasks[i].probeBatchAssets[j]);
|
||||
|
||||
var simulationSettings = SteamAudioManager.GetSimulationSettings(true);
|
||||
|
||||
if (sTasks[i].identifier.type == BakedDataType.Reflections)
|
||||
{
|
||||
var bakeParams = new ReflectionsBakeParams { };
|
||||
bakeParams.scene = SteamAudioManager.CurrentScene.Get();
|
||||
bakeParams.probeBatch = probeBatch.Get();
|
||||
bakeParams.sceneType = simulationSettings.sceneType;
|
||||
bakeParams.identifier = sTasks[i].identifier;
|
||||
bakeParams.flags = 0;
|
||||
bakeParams.numRays = simulationSettings.maxNumRays;
|
||||
bakeParams.numDiffuseSamples = simulationSettings.numDiffuseSamples;
|
||||
bakeParams.numBounces = SteamAudioSettings.Singleton.bakingBounces;
|
||||
bakeParams.simulatedDuration = simulationSettings.maxDuration;
|
||||
bakeParams.savedDuration = simulationSettings.maxDuration;
|
||||
bakeParams.order = simulationSettings.maxOrder;
|
||||
bakeParams.numThreads = simulationSettings.numThreads;
|
||||
bakeParams.rayBatchSize = simulationSettings.rayBatchSize;
|
||||
bakeParams.irradianceMinDistance = SteamAudioSettings.Singleton.bakingIrradianceMinDistance;
|
||||
bakeParams.bakeBatchSize = 1;
|
||||
|
||||
if (SteamAudioSettings.Singleton.bakeConvolution)
|
||||
bakeParams.flags = bakeParams.flags | ReflectionsBakeFlags.BakeConvolution;
|
||||
|
||||
if (SteamAudioSettings.Singleton.bakeParametric)
|
||||
bakeParams.flags = bakeParams.flags | ReflectionsBakeFlags.BakeParametric;
|
||||
|
||||
if (simulationSettings.sceneType == SceneType.RadeonRays)
|
||||
{
|
||||
bakeParams.openCLDevice = SteamAudioManager.OpenCLDevice;
|
||||
bakeParams.radeonRaysDevice = SteamAudioManager.RadeonRaysDevice;
|
||||
bakeParams.bakeBatchSize = SteamAudioSettings.Singleton.bakingBatchSize;
|
||||
}
|
||||
|
||||
API.iplReflectionsBakerBake(SteamAudioManager.Context.Get(), ref bakeParams, sProgressCallback, IntPtr.Zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
var bakeParams = new PathBakeParams { };
|
||||
bakeParams.scene = SteamAudioManager.CurrentScene.Get();
|
||||
bakeParams.probeBatch = probeBatch.Get();
|
||||
bakeParams.identifier = sTasks[i].identifier;
|
||||
bakeParams.numSamples = SteamAudioSettings.Singleton.bakingVisibilitySamples;
|
||||
bakeParams.radius = SteamAudioSettings.Singleton.bakingVisibilityRadius;
|
||||
bakeParams.threshold = SteamAudioSettings.Singleton.bakingVisibilityThreshold;
|
||||
bakeParams.visRange = SteamAudioSettings.Singleton.bakingVisibilityRange;
|
||||
bakeParams.pathRange = SteamAudioSettings.Singleton.bakingPathRange;
|
||||
bakeParams.numThreads = SteamAudioManager.Singleton.NumThreadsForCPUCorePercentage(SteamAudioSettings.Singleton.bakedPathingCPUCoresPercentage);
|
||||
|
||||
API.iplPathBakerBake(SteamAudioManager.Context.Get(), ref bakeParams, sProgressCallback, IntPtr.Zero);
|
||||
}
|
||||
|
||||
if (sCancel)
|
||||
{
|
||||
Debug.Log("CANCELLED: Baking.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't flush the writes to disk just yet, because we can only do it from the main thread.
|
||||
probeBatches[j].probeDataSize = probeBatch.Save(sTasks[i].probeBatchAssets[j], false);
|
||||
|
||||
var dataSize = (int) probeBatch.GetDataSize(sTasks[i].identifier);
|
||||
probeBatches[j].AddOrUpdateLayer(sTasks[i].gameObject, sTasks[i].identifier, dataSize);
|
||||
|
||||
if (sTasks[i].identifier.type == BakedDataType.Reflections)
|
||||
{
|
||||
switch (sTasks[i].identifier.variation)
|
||||
{
|
||||
case BakedDataVariation.Reverb:
|
||||
(sTasks[i].component as SteamAudioListener).UpdateBakedDataStatistics();
|
||||
break;
|
||||
|
||||
case BakedDataVariation.StaticSource:
|
||||
(sTasks[i].component as SteamAudioBakedSource).UpdateBakedDataStatistics();
|
||||
break;
|
||||
|
||||
case BakedDataVariation.StaticListener:
|
||||
(sTasks[i].component as SteamAudioBakedListener).UpdateBakedDataStatistics();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log(string.Format("COMPLETED: Baking effect for {0}.", sCurrentObjectName));
|
||||
}
|
||||
|
||||
sStatus = BakeStatus.Complete;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
11
Scripts/Runtime/Baker.cs.meta
Executable file
11
Scripts/Runtime/Baker.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73a54b25ac58b5f499dae7062adb0e1f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
188
Scripts/Runtime/Common.cs
Executable file
188
Scripts/Runtime/Common.cs
Executable file
@ -0,0 +1,188 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public static class Common
|
||||
{
|
||||
public static Vector3 ConvertVector(UnityEngine.Vector3 point)
|
||||
{
|
||||
Vector3 convertedPoint;
|
||||
convertedPoint.x = point.x;
|
||||
convertedPoint.y = point.y;
|
||||
convertedPoint.z = -point.z;
|
||||
|
||||
return convertedPoint;
|
||||
}
|
||||
|
||||
public static UnityEngine.Vector3 ConvertVector(Vector3 point)
|
||||
{
|
||||
UnityEngine.Vector3 convertedPoint;
|
||||
convertedPoint.x = point.x;
|
||||
convertedPoint.y = point.y;
|
||||
convertedPoint.z = -point.z;
|
||||
|
||||
return convertedPoint;
|
||||
}
|
||||
|
||||
public static Matrix4x4 ConvertTransform(Transform transform)
|
||||
{
|
||||
UnityEngine.Matrix4x4 flipZ = UnityEngine.Matrix4x4.Scale(new UnityEngine.Vector3(1, 1, -1));
|
||||
UnityEngine.Matrix4x4 flippedMatrix = flipZ * transform.localToWorldMatrix * flipZ;
|
||||
|
||||
var matrix = new Matrix4x4();
|
||||
matrix.m00 = flippedMatrix.m00;
|
||||
matrix.m01 = flippedMatrix.m01;
|
||||
matrix.m02 = flippedMatrix.m02;
|
||||
matrix.m03 = flippedMatrix.m03;
|
||||
matrix.m10 = flippedMatrix.m10;
|
||||
matrix.m11 = flippedMatrix.m11;
|
||||
matrix.m12 = flippedMatrix.m12;
|
||||
matrix.m13 = flippedMatrix.m13;
|
||||
matrix.m20 = flippedMatrix.m20;
|
||||
matrix.m21 = flippedMatrix.m21;
|
||||
matrix.m22 = flippedMatrix.m22;
|
||||
matrix.m23 = flippedMatrix.m23;
|
||||
matrix.m30 = flippedMatrix.m30;
|
||||
matrix.m31 = flippedMatrix.m31;
|
||||
matrix.m32 = flippedMatrix.m32;
|
||||
matrix.m33 = flippedMatrix.m33;
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public static Matrix4x4 TransposeMatrix(Matrix4x4 inMatrix)
|
||||
{
|
||||
var outMatrix = new Matrix4x4();
|
||||
|
||||
outMatrix.m00 = inMatrix.m00;
|
||||
outMatrix.m01 = inMatrix.m10;
|
||||
outMatrix.m02 = inMatrix.m20;
|
||||
outMatrix.m03 = inMatrix.m30;
|
||||
outMatrix.m10 = inMatrix.m01;
|
||||
outMatrix.m11 = inMatrix.m11;
|
||||
outMatrix.m12 = inMatrix.m21;
|
||||
outMatrix.m13 = inMatrix.m31;
|
||||
outMatrix.m20 = inMatrix.m02;
|
||||
outMatrix.m21 = inMatrix.m12;
|
||||
outMatrix.m22 = inMatrix.m22;
|
||||
outMatrix.m23 = inMatrix.m32;
|
||||
outMatrix.m30 = inMatrix.m03;
|
||||
outMatrix.m31 = inMatrix.m13;
|
||||
outMatrix.m32 = inMatrix.m23;
|
||||
outMatrix.m33 = inMatrix.m33;
|
||||
|
||||
return outMatrix;
|
||||
}
|
||||
|
||||
public static Matrix4x4 TransformMatrix(UnityEngine.Matrix4x4 inMatrix)
|
||||
{
|
||||
var outMatrix = new Matrix4x4();
|
||||
|
||||
outMatrix.m00 = inMatrix.m00;
|
||||
outMatrix.m01 = inMatrix.m01;
|
||||
outMatrix.m02 = inMatrix.m02;
|
||||
outMatrix.m03 = inMatrix.m03;
|
||||
outMatrix.m10 = inMatrix.m10;
|
||||
outMatrix.m11 = inMatrix.m11;
|
||||
outMatrix.m12 = inMatrix.m12;
|
||||
outMatrix.m13 = inMatrix.m13;
|
||||
outMatrix.m20 = inMatrix.m20;
|
||||
outMatrix.m21 = inMatrix.m21;
|
||||
outMatrix.m22 = inMatrix.m22;
|
||||
outMatrix.m23 = inMatrix.m23;
|
||||
outMatrix.m30 = inMatrix.m30;
|
||||
outMatrix.m31 = inMatrix.m31;
|
||||
outMatrix.m32 = inMatrix.m32;
|
||||
outMatrix.m33 = inMatrix.m33;
|
||||
|
||||
return outMatrix;
|
||||
}
|
||||
|
||||
public static byte[] ConvertString(string s)
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(s + Char.MinValue);
|
||||
}
|
||||
|
||||
public static string GetStreamingAssetsFileName(string fileName)
|
||||
{
|
||||
var streamingAssetsFileName = Path.Combine(Application.streamingAssetsPath, fileName);
|
||||
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
var tempFileName = Path.Combine(Application.temporaryCachePath, fileName);
|
||||
|
||||
if (File.Exists(tempFileName))
|
||||
{
|
||||
File.Delete(tempFileName);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var streamingAssetLoader = new WWW(streamingAssetsFileName);
|
||||
while (!streamingAssetLoader.isDone)
|
||||
{
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(streamingAssetLoader.error))
|
||||
{
|
||||
using (var dataWriter = new BinaryWriter(new FileStream(tempFileName, FileMode.Create)))
|
||||
{
|
||||
dataWriter.Write(streamingAssetLoader.bytes);
|
||||
dataWriter.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError(streamingAssetLoader.error);
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Debug.LogError(exception.ToString());
|
||||
}
|
||||
|
||||
return tempFileName;
|
||||
#else
|
||||
return streamingAssetsFileName;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static string HumanReadableDataSize(int dataSize)
|
||||
{
|
||||
if (dataSize < 1e3)
|
||||
{
|
||||
return dataSize.ToString() + " bytes";
|
||||
}
|
||||
else if (dataSize < 1e6)
|
||||
{
|
||||
return (dataSize / 1e3f).ToString("0.0") + " kB";
|
||||
}
|
||||
else if (dataSize < 1e9)
|
||||
{
|
||||
return (dataSize / 1e6f).ToString("0.0") + " MB";
|
||||
}
|
||||
else
|
||||
{
|
||||
return (dataSize / 1e9f).ToString("0.0") + " GB";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Scripts/Runtime/Common.cs.meta
Executable file
11
Scripts/Runtime/Common.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7797e245e8512a547ab441d68268cc01
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
84
Scripts/Runtime/Context.cs
Executable file
84
Scripts/Runtime/Context.cs
Executable file
@ -0,0 +1,84 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using AOT;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public class Context
|
||||
{
|
||||
IntPtr mContext = IntPtr.Zero;
|
||||
|
||||
public Context()
|
||||
{
|
||||
var contextSettings = new ContextSettings { };
|
||||
contextSettings.version = Constants.kVersion;
|
||||
contextSettings.logCallback = LogMessage;
|
||||
contextSettings.simdLevel = SIMDLevel.AVX2;
|
||||
|
||||
if (SteamAudioSettings.Singleton.EnableValidation)
|
||||
{
|
||||
contextSettings.flags = contextSettings.flags | ContextFlags.Validation;
|
||||
}
|
||||
|
||||
var status = API.iplContextCreate(ref contextSettings, out mContext);
|
||||
if (status != Error.Success)
|
||||
throw new Exception(string.Format("Unable to create context. [{0}]", status));
|
||||
}
|
||||
|
||||
public Context(Context context)
|
||||
{
|
||||
mContext = API.iplContextRetain(context.Get());
|
||||
}
|
||||
|
||||
~Context()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
API.iplContextRelease(ref mContext);
|
||||
}
|
||||
|
||||
public IntPtr Get()
|
||||
{
|
||||
return mContext;
|
||||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(LogCallback))]
|
||||
public static void LogMessage(LogLevel level, string message)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case LogLevel.Info:
|
||||
case LogLevel.Debug:
|
||||
Debug.Log(message);
|
||||
break;
|
||||
case LogLevel.Warning:
|
||||
Debug.LogWarning(message);
|
||||
break;
|
||||
case LogLevel.Error:
|
||||
Debug.LogError(message);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Scripts/Runtime/Context.cs.meta
Executable file
11
Scripts/Runtime/Context.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19c99b97347775a4d901f873fee55e3d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
54
Scripts/Runtime/EmbreeDevice.cs
Executable file
54
Scripts/Runtime/EmbreeDevice.cs
Executable file
@ -0,0 +1,54 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public class EmbreeDevice
|
||||
{
|
||||
IntPtr mEmbreeDevice = IntPtr.Zero;
|
||||
|
||||
public EmbreeDevice(Context context)
|
||||
{
|
||||
var embreeDeviceSettings = new EmbreeDeviceSettings { };
|
||||
|
||||
var status = API.iplEmbreeDeviceCreate(context.Get(), ref embreeDeviceSettings, out mEmbreeDevice);
|
||||
if (status != Error.Success)
|
||||
throw new Exception(string.Format("Unable to create Embree device. [{0}]", status));
|
||||
}
|
||||
|
||||
public EmbreeDevice(EmbreeDevice embreeDevice)
|
||||
{
|
||||
mEmbreeDevice = API.iplEmbreeDeviceRetain(embreeDevice.mEmbreeDevice);
|
||||
}
|
||||
|
||||
~EmbreeDevice()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
API.iplEmbreeDeviceRelease(ref mEmbreeDevice);
|
||||
}
|
||||
|
||||
public IntPtr Get()
|
||||
{
|
||||
return mEmbreeDevice;
|
||||
}
|
||||
}
|
||||
}
|
11
Scripts/Runtime/EmbreeDevice.cs.meta
Executable file
11
Scripts/Runtime/EmbreeDevice.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b63c80d20765d8f49be4ad645532115f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
186
Scripts/Runtime/FMODStudioAudioEngineSource.cs
Executable file
186
Scripts/Runtime/FMODStudioAudioEngineSource.cs
Executable file
@ -0,0 +1,186 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#if STEAMAUDIO_ENABLED
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public sealed class FMODStudioAudioEngineSource : AudioEngineSource
|
||||
{
|
||||
bool mFoundDSP = false;
|
||||
object mEventEmitter = null;
|
||||
object mEventInstance = null;
|
||||
object mDSP = null;
|
||||
SteamAudioSource mSteamAudioSource = null;
|
||||
int mHandle = -1;
|
||||
|
||||
static Type FMOD_DSP;
|
||||
static Type FMOD_ChannelGroup;
|
||||
static Type FMOD_Studio_EventInstance;
|
||||
static Type FMODUnity_StudioEventEmitter;
|
||||
static PropertyInfo FMODUnity_StudioEventEmitter_EventInstance;
|
||||
static MethodInfo FMOD_Studio_EventInstance_getChannelGroup;
|
||||
static MethodInfo FMOD_Studio_EventInstance_isValid;
|
||||
static MethodInfo FMOD_ChannelGroup_getNumDSPs;
|
||||
static MethodInfo FMOD_ChannelGroup_getDSP;
|
||||
static MethodInfo FMOD_DSP_getInfo;
|
||||
static MethodInfo FMOD_DSP_setParameterInt;
|
||||
static bool mBoundToPlugin = false;
|
||||
|
||||
const int kSimulationOutputsParamIndex = 33;
|
||||
|
||||
public override void Initialize(GameObject gameObject)
|
||||
{
|
||||
FindDSP(gameObject);
|
||||
|
||||
mSteamAudioSource = gameObject.GetComponent<SteamAudioSource>();
|
||||
if (mSteamAudioSource)
|
||||
{
|
||||
mHandle = FMODStudioAPI.iplFMODAddSource(mSteamAudioSource.GetSource().Get());
|
||||
}
|
||||
}
|
||||
|
||||
public override void Destroy()
|
||||
{
|
||||
mFoundDSP = false;
|
||||
|
||||
if (mSteamAudioSource)
|
||||
{
|
||||
FMODStudioAPI.iplFMODRemoveSource(mHandle);
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateParameters(SteamAudioSource source)
|
||||
{
|
||||
CheckForChangedEventInstance();
|
||||
|
||||
FindDSP(source.gameObject);
|
||||
if (!mFoundDSP)
|
||||
return;
|
||||
|
||||
var index = kSimulationOutputsParamIndex;
|
||||
FMOD_DSP_setParameterInt.Invoke(mDSP, new object[] { index++, mHandle });
|
||||
}
|
||||
|
||||
void CheckForChangedEventInstance()
|
||||
{
|
||||
if (mEventEmitter != null)
|
||||
{
|
||||
var eventInstance = FMODUnity_StudioEventEmitter_EventInstance.GetValue(mEventEmitter, null);
|
||||
if (eventInstance != mEventInstance)
|
||||
{
|
||||
// The event instance is different from the one we last used, which most likely means the
|
||||
// event-related objects were destroyed and re-created. Make sure we look for the DSP instance
|
||||
// when FindDSP is called next.
|
||||
mFoundDSP = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We haven't yet seen a valid event emitter component, so make sure we look for one when
|
||||
// FindDSP is called.
|
||||
mFoundDSP = false;
|
||||
}
|
||||
}
|
||||
|
||||
void FindDSP(GameObject gameObject)
|
||||
{
|
||||
if (mFoundDSP)
|
||||
return;
|
||||
|
||||
BindToFMODStudioPlugin();
|
||||
|
||||
mEventEmitter = gameObject.GetComponent(FMODUnity_StudioEventEmitter) as object;
|
||||
if (mEventEmitter == null)
|
||||
return;
|
||||
|
||||
mEventInstance = FMODUnity_StudioEventEmitter_EventInstance.GetValue(mEventEmitter, null);
|
||||
if (!((bool)FMOD_Studio_EventInstance_isValid.Invoke(mEventInstance, null)))
|
||||
return;
|
||||
|
||||
var channelGroup = Activator.CreateInstance(FMOD_ChannelGroup);
|
||||
|
||||
var getChannelGroupArgs = new object[] { channelGroup };
|
||||
FMOD_Studio_EventInstance_getChannelGroup.Invoke(mEventInstance, getChannelGroupArgs);
|
||||
channelGroup = getChannelGroupArgs[0];
|
||||
|
||||
var getNumDSPsArgs = new object[] { 0 };
|
||||
FMOD_ChannelGroup_getNumDSPs.Invoke(channelGroup, getNumDSPsArgs);
|
||||
int numDSPs = (int)getNumDSPsArgs[0];
|
||||
|
||||
for (var i = 0; i < numDSPs; ++i)
|
||||
{
|
||||
var getDSPArgs = new object[] { i, mDSP };
|
||||
FMOD_ChannelGroup_getDSP.Invoke(channelGroup, getDSPArgs);
|
||||
mDSP = getDSPArgs[1];
|
||||
|
||||
var dspName = "";
|
||||
var dspVersion = 0u;
|
||||
var dspNumChannels = 0;
|
||||
var dspConfigWidth = 0;
|
||||
var dspConfigHeight = 0;
|
||||
|
||||
var getInfoArgs = new object[] { dspName, dspVersion, dspNumChannels, dspConfigWidth, dspConfigHeight };
|
||||
FMOD_DSP_getInfo.Invoke(mDSP, getInfoArgs);
|
||||
dspName = (string)getInfoArgs[0];
|
||||
|
||||
if (dspName == "Steam Audio Spatializer")
|
||||
{
|
||||
mFoundDSP = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void BindToFMODStudioPlugin()
|
||||
{
|
||||
if (mBoundToPlugin)
|
||||
return;
|
||||
|
||||
var assemblySuffix = ",FMODUnity";
|
||||
|
||||
FMOD_DSP = Type.GetType("FMOD.DSP" + assemblySuffix);
|
||||
FMOD_ChannelGroup = Type.GetType("FMOD.ChannelGroup" + assemblySuffix);
|
||||
FMOD_Studio_EventInstance = Type.GetType("FMOD.Studio.EventInstance" + assemblySuffix);
|
||||
FMODUnity_StudioEventEmitter = Type.GetType("FMODUnity.StudioEventEmitter" + assemblySuffix);
|
||||
|
||||
FMODUnity_StudioEventEmitter_EventInstance = FMODUnity_StudioEventEmitter.GetProperty("EventInstance");
|
||||
|
||||
FMOD_Studio_EventInstance_getChannelGroup = FMOD_Studio_EventInstance.GetMethod("getChannelGroup");
|
||||
FMOD_Studio_EventInstance_isValid = FMOD_Studio_EventInstance.GetMethod("isValid");
|
||||
FMOD_ChannelGroup_getNumDSPs = FMOD_ChannelGroup.GetMethod("getNumDSPs");
|
||||
FMOD_ChannelGroup_getDSP = FMOD_ChannelGroup.GetMethod("getDSP");
|
||||
FMOD_DSP_setParameterInt = FMOD_DSP.GetMethod("setParameterInt");
|
||||
|
||||
var candidates = FMOD_DSP.GetMethods();
|
||||
foreach (var candidate in candidates)
|
||||
{
|
||||
if (candidate.Name == "getInfo" && candidate.GetParameters().Length == 5)
|
||||
{
|
||||
FMOD_DSP_getInfo = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mBoundToPlugin = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
11
Scripts/Runtime/FMODStudioAudioEngineSource.cs.meta
Executable file
11
Scripts/Runtime/FMODStudioAudioEngineSource.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c36706fa5b924b94c8895e3051bdee14
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
109
Scripts/Runtime/FMODStudioAudioEngineState.cs
Executable file
109
Scripts/Runtime/FMODStudioAudioEngineState.cs
Executable file
@ -0,0 +1,109 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#if STEAMAUDIO_ENABLED
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public sealed class FMODStudioAudioEngineState : AudioEngineState
|
||||
{
|
||||
public override void Initialize(IntPtr context, IntPtr defaultHRTF, SimulationSettings simulationSettings, PerspectiveCorrection correction)
|
||||
{
|
||||
FMODStudioAPI.iplFMODInitialize(context);
|
||||
FMODStudioAPI.iplFMODSetHRTF(defaultHRTF);
|
||||
FMODStudioAPI.iplFMODSetSimulationSettings(simulationSettings);
|
||||
}
|
||||
|
||||
public override void Destroy()
|
||||
{
|
||||
FMODStudioAPI.iplFMODTerminate();
|
||||
}
|
||||
|
||||
public override void SetHRTF(IntPtr hrtf)
|
||||
{
|
||||
FMODStudioAPI.iplFMODSetHRTF(hrtf);
|
||||
}
|
||||
|
||||
public override void SetReverbSource(Source reverbSource)
|
||||
{
|
||||
FMODStudioAPI.iplFMODSetReverbSource(reverbSource.Get());
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class FMODStudioAudioEngineStateHelpers : AudioEngineStateHelpers
|
||||
{
|
||||
static bool mBoundToPlugin = false;
|
||||
|
||||
static Type FMOD_SPEAKERMODE;
|
||||
static Type FMOD_System;
|
||||
static Type FMODUnity_StudioListener;
|
||||
static Type FMODUnity_RuntimeManager;
|
||||
static PropertyInfo FMODUnity_RuntimeManager_CoreSystem;
|
||||
static MethodInfo FMOD_System_getSoftwareFormat;
|
||||
static MethodInfo FMOD_System_getDSPBufferSize;
|
||||
|
||||
public override Transform GetListenerTransform()
|
||||
{
|
||||
BindToFMODStudioPlugin();
|
||||
|
||||
var fmodStudioListener = (MonoBehaviour) GameObject.FindObjectOfType(FMODUnity_StudioListener);
|
||||
return (fmodStudioListener != null) ? fmodStudioListener.transform : null;
|
||||
}
|
||||
|
||||
public override AudioSettings GetAudioSettings()
|
||||
{
|
||||
BindToFMODStudioPlugin();
|
||||
|
||||
var audioSettings = new AudioSettings { };
|
||||
|
||||
var fmodSystem = FMODUnity_RuntimeManager_CoreSystem.GetValue(null, null);
|
||||
|
||||
var speakerMode = Activator.CreateInstance(FMOD_SPEAKERMODE);
|
||||
var getSoftwareFormatArgs = new object[] { 0, speakerMode, 0 };
|
||||
FMOD_System_getSoftwareFormat.Invoke(fmodSystem, getSoftwareFormatArgs);
|
||||
audioSettings.samplingRate = (int) getSoftwareFormatArgs[0];
|
||||
|
||||
var getDSPBufferSizeArgs = new object[] { 0u, 0 };
|
||||
FMOD_System_getDSPBufferSize.Invoke(fmodSystem, getDSPBufferSizeArgs);
|
||||
audioSettings.frameSize = (int) ((uint) getDSPBufferSizeArgs[0]);
|
||||
|
||||
return audioSettings;
|
||||
}
|
||||
|
||||
static void BindToFMODStudioPlugin()
|
||||
{
|
||||
if (mBoundToPlugin)
|
||||
return;
|
||||
|
||||
var assemblySuffix = ",FMODUnity";
|
||||
|
||||
FMOD_SPEAKERMODE = Type.GetType("FMOD.SPEAKERMODE" + assemblySuffix);
|
||||
FMOD_System = Type.GetType("FMOD.System" + assemblySuffix);
|
||||
FMODUnity_StudioListener = Type.GetType("FMODUnity.StudioListener" + assemblySuffix);
|
||||
FMODUnity_RuntimeManager = Type.GetType("FMODUnity.RuntimeManager" + assemblySuffix);
|
||||
|
||||
FMODUnity_RuntimeManager_CoreSystem = FMODUnity_RuntimeManager.GetProperty("CoreSystem");
|
||||
|
||||
FMOD_System_getSoftwareFormat = FMOD_System.GetMethod("getSoftwareFormat");
|
||||
FMOD_System_getDSPBufferSize = FMOD_System.GetMethod("getDSPBufferSize");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
11
Scripts/Runtime/FMODStudioAudioEngineState.cs.meta
Executable file
11
Scripts/Runtime/FMODStudioAudioEngineState.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8e2075eab110ad4b88d26e434723035
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
102
Scripts/Runtime/HRTF.cs
Executable file
102
Scripts/Runtime/HRTF.cs
Executable file
@ -0,0 +1,102 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public class HRTF
|
||||
{
|
||||
IntPtr mHRTF = IntPtr.Zero;
|
||||
|
||||
public HRTF(Context context, AudioSettings audioSettings, string sofaFileName, byte[] sofaFileData, float gaindB, HRTFNormType normType)
|
||||
{
|
||||
IntPtr sofaData = IntPtr.Zero;
|
||||
|
||||
var hrtfSettings = new HRTFSettings { };
|
||||
if (sofaFileData != null && sofaFileData.Length > 0)
|
||||
{
|
||||
hrtfSettings.type = HRTFType.SOFA;
|
||||
|
||||
sofaData = Marshal.AllocHGlobal(sofaFileData.Length);
|
||||
Marshal.Copy(sofaFileData, 0, sofaData, sofaFileData.Length);
|
||||
|
||||
hrtfSettings.sofaFileData = sofaData;
|
||||
hrtfSettings.sofaFileDataSize = sofaFileData.Length;
|
||||
}
|
||||
else if (sofaFileName != null)
|
||||
{
|
||||
hrtfSettings.type = HRTFType.SOFA;
|
||||
hrtfSettings.sofaFileName = sofaFileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
hrtfSettings.type = HRTFType.Default;
|
||||
}
|
||||
|
||||
hrtfSettings.volume = dBToGain(gaindB);
|
||||
hrtfSettings.normType = normType;
|
||||
|
||||
var status = API.iplHRTFCreate(context.Get(), ref audioSettings, ref hrtfSettings, out mHRTF);
|
||||
if (status != Error.Success)
|
||||
{
|
||||
Debug.LogError(string.Format("Unable to load HRTF: {0}. [{1}]", (sofaFileName != null) ? sofaFileName : "default", status));
|
||||
mHRTF = IntPtr.Zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log(string.Format("Loaded HRTF: {0}.", (sofaFileName != null) ? sofaFileName : "default"));
|
||||
}
|
||||
|
||||
if (sofaData != IntPtr.Zero)
|
||||
{
|
||||
Marshal.FreeHGlobal(sofaData);
|
||||
}
|
||||
}
|
||||
|
||||
public HRTF(HRTF hrtf)
|
||||
{
|
||||
mHRTF = API.iplHRTFRetain(hrtf.Get());
|
||||
}
|
||||
|
||||
~HRTF()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
API.iplHRTFRelease(ref mHRTF);
|
||||
}
|
||||
|
||||
public IntPtr Get()
|
||||
{
|
||||
return mHRTF;
|
||||
}
|
||||
|
||||
private float dBToGain(float gaindB)
|
||||
{
|
||||
const float kMinDBLevel = -90.0f;
|
||||
|
||||
if (gaindB <= kMinDBLevel)
|
||||
return 0.0f;
|
||||
|
||||
return (float) Math.Pow(10.0, (double) gaindB * (1.0 / 20.0));
|
||||
}
|
||||
}
|
||||
}
|
11
Scripts/Runtime/HRTF.cs.meta
Executable file
11
Scripts/Runtime/HRTF.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2676d545429ad5547a1ea3389903271e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
77
Scripts/Runtime/InstancedMesh.cs
Executable file
77
Scripts/Runtime/InstancedMesh.cs
Executable file
@ -0,0 +1,77 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#if STEAMAUDIO_ENABLED
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public class InstancedMesh
|
||||
{
|
||||
IntPtr mInstancedMesh = IntPtr.Zero;
|
||||
|
||||
public InstancedMesh(Scene scene, Scene subScene, Transform transform)
|
||||
{
|
||||
var instancedMeshSettings = new InstancedMeshSettings { };
|
||||
instancedMeshSettings.subScene = subScene.Get();
|
||||
instancedMeshSettings.transform = Common.ConvertTransform(transform);
|
||||
|
||||
var status = API.iplInstancedMeshCreate(scene.Get(), ref instancedMeshSettings, out mInstancedMesh);
|
||||
if (status != Error.Success)
|
||||
throw new Exception(string.Format("Unable to create instanced mesh ({0}). [{1}]", transform.gameObject.name, status));
|
||||
}
|
||||
|
||||
public InstancedMesh(InstancedMesh instancedMesh)
|
||||
{
|
||||
mInstancedMesh = API.iplInstancedMeshRetain(instancedMesh.mInstancedMesh);
|
||||
}
|
||||
|
||||
~InstancedMesh()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
API.iplInstancedMeshRelease(ref mInstancedMesh);
|
||||
}
|
||||
|
||||
public IntPtr Get()
|
||||
{
|
||||
return mInstancedMesh;
|
||||
}
|
||||
|
||||
public void AddToScene(Scene scene)
|
||||
{
|
||||
API.iplInstancedMeshAdd(mInstancedMesh, scene.Get());
|
||||
scene.NotifyAddObject();
|
||||
}
|
||||
|
||||
public void RemoveFromScene(Scene scene)
|
||||
{
|
||||
API.iplInstancedMeshRemove(mInstancedMesh, scene.Get());
|
||||
scene.NotifyRemoveObject();
|
||||
}
|
||||
|
||||
public void UpdateTransform(Scene scene, Transform transform)
|
||||
{
|
||||
API.iplInstancedMeshUpdateTransform(mInstancedMesh, scene.Get(), Common.ConvertTransform(transform));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
11
Scripts/Runtime/InstancedMesh.cs.meta
Executable file
11
Scripts/Runtime/InstancedMesh.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9b254356f848f34d976c386541ec68b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
94
Scripts/Runtime/OpenCLDevice.cs
Executable file
94
Scripts/Runtime/OpenCLDevice.cs
Executable file
@ -0,0 +1,94 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public class OpenCLDevice
|
||||
{
|
||||
IntPtr mOpenCLDevice = IntPtr.Zero;
|
||||
|
||||
public OpenCLDevice(Context context, OpenCLDeviceType deviceType, int numCUsToReserve, float fractionCUsForIRUpdate,
|
||||
bool requiresTAN)
|
||||
{
|
||||
var deviceSettings = new OpenCLDeviceSettings { };
|
||||
deviceSettings.type = deviceType;
|
||||
deviceSettings.numCUsToReserve = numCUsToReserve;
|
||||
deviceSettings.fractionCUsForIRUpdate = fractionCUsForIRUpdate;
|
||||
deviceSettings.requiresTAN = requiresTAN ? Bool.True : Bool.False;
|
||||
|
||||
var deviceList = IntPtr.Zero;
|
||||
var status = API.iplOpenCLDeviceListCreate(context.Get(), ref deviceSettings, out deviceList);
|
||||
if (status != Error.Success)
|
||||
throw new Exception(string.Format("Unable to enumerate OpenCL devices. [{0}]", status));
|
||||
|
||||
var numDevices = API.iplOpenCLDeviceListGetNumDevices(deviceList);
|
||||
if (numDevices <= 0)
|
||||
{
|
||||
API.iplOpenCLDeviceListRelease(ref deviceList);
|
||||
|
||||
// If we explicitly requested a device that supports TAN, or if we didn't ask for CU
|
||||
// reservation, but still didn't find any devices, stop.
|
||||
if (requiresTAN || numCUsToReserve == 0)
|
||||
throw new Exception(string.Format("No OpenCL devices found."));
|
||||
|
||||
Debug.LogWarning("No OpenCL devices found that match the provided parameters, attempting to " +
|
||||
"initialize without CU reservation.");
|
||||
|
||||
deviceSettings.numCUsToReserve = 0;
|
||||
deviceSettings.fractionCUsForIRUpdate = 0.0f;
|
||||
status = API.iplOpenCLDeviceListCreate(context.Get(), ref deviceSettings, out deviceList);
|
||||
if (status != Error.Success)
|
||||
throw new Exception(string.Format("Unable to enumerate OpenCL devices. [{0}]", status));
|
||||
|
||||
numDevices = API.iplOpenCLDeviceListGetNumDevices(deviceList);
|
||||
if (numDevices <= 0)
|
||||
throw new Exception(string.Format("No OpenCL devices found."));
|
||||
}
|
||||
|
||||
status = API.iplOpenCLDeviceCreate(context.Get(), deviceList, 0, out mOpenCLDevice);
|
||||
if (status != Error.Success)
|
||||
{
|
||||
API.iplOpenCLDeviceListRelease(ref deviceList);
|
||||
throw new Exception(string.Format("Unable to create OpenCL device. [{0}]", status));
|
||||
}
|
||||
|
||||
API.iplOpenCLDeviceListRelease(ref deviceList);
|
||||
}
|
||||
|
||||
public OpenCLDevice(OpenCLDevice device)
|
||||
{
|
||||
mOpenCLDevice = API.iplOpenCLDeviceRetain(device.mOpenCLDevice);
|
||||
}
|
||||
|
||||
~OpenCLDevice()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
API.iplOpenCLDeviceRelease(ref mOpenCLDevice);
|
||||
}
|
||||
|
||||
public IntPtr Get()
|
||||
{
|
||||
return mOpenCLDevice;
|
||||
}
|
||||
}
|
||||
}
|
11
Scripts/Runtime/OpenCLDevice.cs.meta
Executable file
11
Scripts/Runtime/OpenCLDevice.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 980da0934e6939d439f50baac22a5286
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
151
Scripts/Runtime/ProbeBatch.cs
Executable file
151
Scripts/Runtime/ProbeBatch.cs
Executable file
@ -0,0 +1,151 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#if STEAMAUDIO_ENABLED
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public class ProbeArray
|
||||
{
|
||||
IntPtr mProbeArray = IntPtr.Zero;
|
||||
|
||||
public ProbeArray(Context context)
|
||||
{
|
||||
API.iplProbeArrayCreate(context.Get(), out mProbeArray);
|
||||
}
|
||||
|
||||
public ProbeArray(ProbeArray probeArray)
|
||||
{
|
||||
mProbeArray = API.iplProbeArrayRetain(probeArray.mProbeArray);
|
||||
}
|
||||
|
||||
~ProbeArray()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
API.iplProbeArrayRelease(ref mProbeArray);
|
||||
}
|
||||
|
||||
public IntPtr Get()
|
||||
{
|
||||
return mProbeArray;
|
||||
}
|
||||
|
||||
public void GenerateProbes(Scene scene, ProbeGenerationParams probeGenerationParams)
|
||||
{
|
||||
API.iplProbeArrayGenerateProbes(mProbeArray, scene.Get(), ref probeGenerationParams);
|
||||
}
|
||||
|
||||
public int GetNumProbes()
|
||||
{
|
||||
return API.iplProbeArrayGetNumProbes(mProbeArray);
|
||||
}
|
||||
|
||||
public Sphere GetProbe(int index)
|
||||
{
|
||||
return API.iplProbeArrayGetProbe(mProbeArray, index);
|
||||
}
|
||||
}
|
||||
|
||||
public class ProbeBatch
|
||||
{
|
||||
Context mContext = null;
|
||||
IntPtr mProbeBatch = IntPtr.Zero;
|
||||
|
||||
public ProbeBatch(Context context)
|
||||
{
|
||||
mContext = context;
|
||||
|
||||
API.iplProbeBatchCreate(context.Get(), out mProbeBatch);
|
||||
}
|
||||
|
||||
public ProbeBatch(Context context, SerializedData dataAsset)
|
||||
{
|
||||
mContext = context;
|
||||
|
||||
var serializedObject = new SerializedObject(context, dataAsset);
|
||||
|
||||
var status = API.iplProbeBatchLoad(context.Get(), serializedObject.Get(), out mProbeBatch);
|
||||
if (status != Error.Success)
|
||||
{
|
||||
Debug.LogError(string.Format("Unable to load Probe Batch from {0}.", dataAsset.name));
|
||||
mProbeBatch = IntPtr.Zero;
|
||||
}
|
||||
|
||||
serializedObject.Release();
|
||||
}
|
||||
|
||||
public ProbeBatch(ProbeBatch probeBatch)
|
||||
{
|
||||
mContext = probeBatch.mContext;
|
||||
|
||||
mProbeBatch = API.iplProbeBatchRetain(probeBatch.mProbeBatch);
|
||||
}
|
||||
|
||||
~ProbeBatch()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
API.iplProbeBatchRelease(ref mProbeBatch);
|
||||
|
||||
mContext = null;
|
||||
}
|
||||
|
||||
public IntPtr Get()
|
||||
{
|
||||
return mProbeBatch;
|
||||
}
|
||||
|
||||
public int Save(SerializedData dataAsset, bool flush = true)
|
||||
{
|
||||
var serializedObject = new SerializedObject(mContext);
|
||||
API.iplProbeBatchSave(mProbeBatch, serializedObject.Get());
|
||||
var size = (int) serializedObject.GetSize();
|
||||
serializedObject.WriteToFile(dataAsset, flush);
|
||||
serializedObject.Release();
|
||||
return size;
|
||||
}
|
||||
|
||||
public void AddProbeArray(ProbeArray probeArray)
|
||||
{
|
||||
API.iplProbeBatchAddProbeArray(mProbeBatch, probeArray.Get());
|
||||
}
|
||||
|
||||
public void Commit()
|
||||
{
|
||||
API.iplProbeBatchCommit(mProbeBatch);
|
||||
}
|
||||
|
||||
public void RemoveData(BakedDataIdentifier identifier)
|
||||
{
|
||||
API.iplProbeBatchRemoveData(mProbeBatch, ref identifier);
|
||||
}
|
||||
|
||||
public UIntPtr GetDataSize(BakedDataIdentifier identifier)
|
||||
{
|
||||
return API.iplProbeBatchGetDataSize(mProbeBatch, ref identifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
11
Scripts/Runtime/ProbeBatch.cs.meta
Executable file
11
Scripts/Runtime/ProbeBatch.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63ee2a9f8d2a86043bb79036d010ee2a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
54
Scripts/Runtime/RadeonRaysDevice.cs
Executable file
54
Scripts/Runtime/RadeonRaysDevice.cs
Executable file
@ -0,0 +1,54 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public class RadeonRaysDevice
|
||||
{
|
||||
IntPtr mRadeonRaysDevice = IntPtr.Zero;
|
||||
|
||||
public RadeonRaysDevice(OpenCLDevice openCLDevice)
|
||||
{
|
||||
var deviceSettings = new RadeonRaysDeviceSettings { };
|
||||
|
||||
var status = API.iplRadeonRaysDeviceCreate(openCLDevice.Get(), ref deviceSettings, out mRadeonRaysDevice);
|
||||
if (status != Error.Success)
|
||||
throw new Exception(string.Format("Unable to create Radeon Rays device. [{0}]", status));
|
||||
}
|
||||
|
||||
public RadeonRaysDevice(RadeonRaysDevice device)
|
||||
{
|
||||
mRadeonRaysDevice = API.iplRadeonRaysDeviceRetain(device.mRadeonRaysDevice);
|
||||
}
|
||||
|
||||
~RadeonRaysDevice()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
API.iplRadeonRaysDeviceRelease(ref mRadeonRaysDevice);
|
||||
}
|
||||
|
||||
public IntPtr Get()
|
||||
{
|
||||
return mRadeonRaysDevice;
|
||||
}
|
||||
}
|
||||
}
|
11
Scripts/Runtime/RadeonRaysDevice.cs.meta
Executable file
11
Scripts/Runtime/RadeonRaysDevice.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab45c0e4ff6a2c445843d2133d90ce2e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
38
Scripts/Runtime/SOFAFile.cs
Executable file
38
Scripts/Runtime/SOFAFile.cs
Executable file
@ -0,0 +1,38 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
/*
|
||||
* Represents a serializable object that is created when importing a .sofa file as an asset.
|
||||
*/
|
||||
public class SOFAFile : ScriptableObject
|
||||
{
|
||||
// The name of the sofa file that was imported.
|
||||
public string sofaName = "";
|
||||
|
||||
// The imported data.
|
||||
public byte[] data = null;
|
||||
|
||||
// The volume correction factor in dB.
|
||||
public float volume = 0.0f;
|
||||
|
||||
// Volume normalization type.
|
||||
public HRTFNormType normType = HRTFNormType.None;
|
||||
}
|
||||
}
|
11
Scripts/Runtime/SOFAFile.cs.meta
Executable file
11
Scripts/Runtime/SOFAFile.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c07f8c30ab6b2bb4380f1a4429dd557a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
114
Scripts/Runtime/Scene.cs
Executable file
114
Scripts/Runtime/Scene.cs
Executable file
@ -0,0 +1,114 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#if STEAMAUDIO_ENABLED
|
||||
|
||||
using System;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public class Scene
|
||||
{
|
||||
Context mContext = null;
|
||||
IntPtr mScene = IntPtr.Zero;
|
||||
int mNumObjects = 0;
|
||||
|
||||
public Scene(Context context, SceneType type, EmbreeDevice embreeDevice, RadeonRaysDevice radeonRaysDevice, ClosestHitCallback closestHitCallback, AnyHitCallback anyHitCallback)
|
||||
{
|
||||
mContext = context;
|
||||
|
||||
var sceneSettings = new SceneSettings { };
|
||||
sceneSettings.type = type;
|
||||
sceneSettings.embreeDevice = (embreeDevice != null) ? embreeDevice.Get() : IntPtr.Zero;
|
||||
sceneSettings.radeonRaysDevice = (radeonRaysDevice != null) ? radeonRaysDevice.Get() : IntPtr.Zero;
|
||||
sceneSettings.closestHitCallback = closestHitCallback;
|
||||
sceneSettings.anyHitCallback = anyHitCallback;
|
||||
|
||||
var status = API.iplSceneCreate(context.Get(), ref sceneSettings, out mScene);
|
||||
if (status != Error.Success)
|
||||
throw new Exception(string.Format("Unable to create scene [{0}]", status.ToString()));
|
||||
}
|
||||
|
||||
public Scene(Context context, SceneSettings sceneSettings, SerializedData dataAsset)
|
||||
{
|
||||
mContext = context;
|
||||
|
||||
var serializedObject = new SerializedObject(context, dataAsset);
|
||||
var status = API.iplSceneLoad(context.Get(), ref sceneSettings, serializedObject.Get(), null, IntPtr.Zero, out mScene);
|
||||
if (status != Error.Success)
|
||||
throw new Exception(string.Format("Unable to load scene [{0}]", status.ToString()));
|
||||
|
||||
serializedObject.Release();
|
||||
}
|
||||
|
||||
public Scene(Scene scene)
|
||||
{
|
||||
mContext = scene.mContext;
|
||||
|
||||
mScene = API.iplSceneRetain(scene.mScene);
|
||||
}
|
||||
|
||||
~Scene()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
API.iplSceneRelease(ref mScene);
|
||||
|
||||
mContext = null;
|
||||
}
|
||||
|
||||
public IntPtr Get()
|
||||
{
|
||||
return mScene;
|
||||
}
|
||||
|
||||
public void Save(SerializedData dataAsset)
|
||||
{
|
||||
var serializedObject = new SerializedObject(mContext);
|
||||
API.iplSceneSave(mScene, serializedObject.Get());
|
||||
serializedObject.WriteToFile(dataAsset);
|
||||
serializedObject.Release();
|
||||
}
|
||||
|
||||
public void SaveOBJ(string fileBaseName)
|
||||
{
|
||||
API.iplSceneSaveOBJ(mScene, fileBaseName);
|
||||
}
|
||||
|
||||
public void NotifyAddObject()
|
||||
{
|
||||
++mNumObjects;
|
||||
}
|
||||
|
||||
public void NotifyRemoveObject()
|
||||
{
|
||||
--mNumObjects;
|
||||
}
|
||||
|
||||
public int GetNumObjects()
|
||||
{
|
||||
return mNumObjects;
|
||||
}
|
||||
|
||||
public void Commit()
|
||||
{
|
||||
API.iplSceneCommit(mScene);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
11
Scripts/Runtime/Scene.cs.meta
Executable file
11
Scripts/Runtime/Scene.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f36118f1552c924438a563f1eba9832d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
45
Scripts/Runtime/SerializedData.cs
Executable file
45
Scripts/Runtime/SerializedData.cs
Executable file
@ -0,0 +1,45 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public class SerializedData : ScriptableObject
|
||||
{
|
||||
[SerializeField]
|
||||
public byte[] data;
|
||||
|
||||
public static SerializedData PromptForNewAsset(string defaultFileName)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var fileName = EditorUtility.SaveFilePanelInProject("Export", defaultFileName, "asset",
|
||||
"Select a file to export data to.");
|
||||
|
||||
if (fileName != null && fileName.Length > 0)
|
||||
{
|
||||
var dataAsset = ScriptableObject.CreateInstance<SerializedData>();
|
||||
AssetDatabase.CreateAsset(dataAsset, fileName);
|
||||
return dataAsset;
|
||||
}
|
||||
#endif
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
11
Scripts/Runtime/SerializedData.cs.meta
Executable file
11
Scripts/Runtime/SerializedData.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a82078fb50fbcb46a7e4402721b1a31
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
141
Scripts/Runtime/SerializedObject.cs
Executable file
141
Scripts/Runtime/SerializedObject.cs
Executable file
@ -0,0 +1,141 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#if STEAMAUDIO_ENABLED
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public class SerializedObject
|
||||
{
|
||||
IntPtr mSerializedObject = IntPtr.Zero;
|
||||
IntPtr mDataBuffer = IntPtr.Zero;
|
||||
|
||||
static List<SerializedData> sAssetsToFlush = null;
|
||||
|
||||
public SerializedObject(Context context)
|
||||
{
|
||||
var serializedObjectSettings = new SerializedObjectSettings { };
|
||||
|
||||
API.iplSerializedObjectCreate(context.Get(), ref serializedObjectSettings, out mSerializedObject);
|
||||
}
|
||||
|
||||
public SerializedObject(Context context, SerializedData dataAsset)
|
||||
{
|
||||
var data = dataAsset.data;
|
||||
mDataBuffer = Marshal.AllocHGlobal(data.Length);
|
||||
|
||||
Marshal.Copy(data, 0, mDataBuffer, data.Length);
|
||||
|
||||
var serializedObjectSettings = new SerializedObjectSettings { };
|
||||
serializedObjectSettings.data = mDataBuffer;
|
||||
serializedObjectSettings.size = (UIntPtr) data.Length;
|
||||
|
||||
API.iplSerializedObjectCreate(context.Get(), ref serializedObjectSettings, out mSerializedObject);
|
||||
}
|
||||
|
||||
public SerializedObject(SerializedObject serializedObject)
|
||||
{
|
||||
mSerializedObject = API.iplSerializedObjectRetain(serializedObject.Get());
|
||||
}
|
||||
|
||||
~SerializedObject()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
if (mDataBuffer != IntPtr.Zero)
|
||||
{
|
||||
Marshal.FreeHGlobal(mDataBuffer);
|
||||
mDataBuffer = IntPtr.Zero;
|
||||
}
|
||||
|
||||
API.iplSerializedObjectRelease(ref mSerializedObject);
|
||||
}
|
||||
|
||||
public IntPtr Get()
|
||||
{
|
||||
return mSerializedObject;
|
||||
}
|
||||
|
||||
public UIntPtr GetSize()
|
||||
{
|
||||
return API.iplSerializedObjectGetSize(mSerializedObject);
|
||||
}
|
||||
|
||||
public IntPtr GetData()
|
||||
{
|
||||
return API.iplSerializedObjectGetData(mSerializedObject);
|
||||
}
|
||||
|
||||
public void WriteToFile(SerializedData dataAsset, bool flush = true)
|
||||
{
|
||||
var dataSize = GetSize();
|
||||
var dataBuffer = GetData();
|
||||
|
||||
dataAsset.data = new byte[(int) dataSize];
|
||||
Marshal.Copy(dataBuffer, dataAsset.data, 0, (int) dataSize);
|
||||
|
||||
if (flush)
|
||||
{
|
||||
FlushWrite(dataAsset);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sAssetsToFlush == null)
|
||||
{
|
||||
sAssetsToFlush = new List<SerializedData>();
|
||||
}
|
||||
|
||||
sAssetsToFlush.Add(dataAsset);
|
||||
}
|
||||
}
|
||||
|
||||
public static void FlushWrite(SerializedData dataAsset)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var assetPaths = new string[1];
|
||||
assetPaths[0] = AssetDatabase.GetAssetPath(dataAsset);
|
||||
|
||||
// TODO: Deprecate older versions of Unity.
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
AssetDatabase.ForceReserializeAssets(assetPaths);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void FlushAllWrites()
|
||||
{
|
||||
if (sAssetsToFlush == null)
|
||||
return;
|
||||
|
||||
foreach (var dataAsset in sAssetsToFlush)
|
||||
{
|
||||
FlushWrite(dataAsset);
|
||||
}
|
||||
|
||||
sAssetsToFlush.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
11
Scripts/Runtime/SerializedObject.cs.meta
Executable file
11
Scripts/Runtime/SerializedObject.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e71666981c49a64e98ee2cbd2726952
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
152
Scripts/Runtime/Simulator.cs
Executable file
152
Scripts/Runtime/Simulator.cs
Executable file
@ -0,0 +1,152 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#if STEAMAUDIO_ENABLED
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public class Simulator
|
||||
{
|
||||
IntPtr mSimulator = IntPtr.Zero;
|
||||
|
||||
public Simulator(Context context, SimulationSettings simulationSettings)
|
||||
{
|
||||
var status = API.iplSimulatorCreate(context.Get(), ref simulationSettings, out mSimulator);
|
||||
if (status != Error.Success)
|
||||
throw new Exception(string.Format("Unable to create simulator. [{0}]", status));
|
||||
}
|
||||
|
||||
public Simulator(Simulator simulator)
|
||||
{
|
||||
mSimulator = API.iplSimulatorRetain(simulator.mSimulator);
|
||||
}
|
||||
|
||||
~Simulator()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
API.iplSimulatorRelease(ref mSimulator);
|
||||
}
|
||||
|
||||
public IntPtr Get()
|
||||
{
|
||||
return mSimulator;
|
||||
}
|
||||
|
||||
public void SetScene(Scene scene)
|
||||
{
|
||||
API.iplSimulatorSetScene(mSimulator, scene.Get());
|
||||
}
|
||||
|
||||
public void AddProbeBatch(ProbeBatch probeBatch)
|
||||
{
|
||||
API.iplSimulatorAddProbeBatch(mSimulator, probeBatch.Get());
|
||||
}
|
||||
|
||||
public void RemoveProbeBatch(ProbeBatch probeBatch)
|
||||
{
|
||||
API.iplSimulatorRemoveProbeBatch(mSimulator, probeBatch.Get());
|
||||
}
|
||||
|
||||
public void SetSharedInputs(SimulationFlags flags, SimulationSharedInputs sharedInputs)
|
||||
{
|
||||
API.iplSimulatorSetSharedInputs(mSimulator, flags, ref sharedInputs);
|
||||
}
|
||||
|
||||
public void Commit()
|
||||
{
|
||||
API.iplSimulatorCommit(mSimulator);
|
||||
}
|
||||
|
||||
public void RunDirect()
|
||||
{
|
||||
API.iplSimulatorRunDirect(mSimulator);
|
||||
}
|
||||
|
||||
public void RunReflections()
|
||||
{
|
||||
API.iplSimulatorRunReflections(mSimulator);
|
||||
}
|
||||
|
||||
public void RunPathing()
|
||||
{
|
||||
API.iplSimulatorRunPathing(mSimulator);
|
||||
}
|
||||
}
|
||||
|
||||
public class Source
|
||||
{
|
||||
IntPtr mSource = IntPtr.Zero;
|
||||
|
||||
public Source(Simulator simulator, SimulationSettings simulationSettings)
|
||||
{
|
||||
var sourceSettings = new SourceSettings { };
|
||||
sourceSettings.flags = simulationSettings.flags;
|
||||
|
||||
var status = API.iplSourceCreate(simulator.Get(), ref sourceSettings, out mSource);
|
||||
if (status != Error.Success)
|
||||
throw new Exception(string.Format("Unable to create source for simulation. [{0}]", status));
|
||||
}
|
||||
|
||||
public Source(Source source)
|
||||
{
|
||||
mSource = API.iplSourceRetain(source.mSource);
|
||||
}
|
||||
|
||||
~Source()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
API.iplSourceRelease(ref mSource);
|
||||
}
|
||||
|
||||
public IntPtr Get()
|
||||
{
|
||||
return mSource;
|
||||
}
|
||||
|
||||
public void AddToSimulator(Simulator simulator)
|
||||
{
|
||||
API.iplSourceAdd(mSource, simulator.Get());
|
||||
}
|
||||
|
||||
public void RemoveFromSimulator(Simulator simulator)
|
||||
{
|
||||
API.iplSourceRemove(mSource, simulator.Get());
|
||||
}
|
||||
|
||||
public void SetInputs(SimulationFlags flags, SimulationInputs inputs)
|
||||
{
|
||||
API.iplSourceSetInputs(mSource, flags, ref inputs);
|
||||
}
|
||||
|
||||
public SimulationOutputs GetOutputs(SimulationFlags flags)
|
||||
{
|
||||
var outputs = new SimulationOutputs { };
|
||||
API.iplSourceGetOutputs(mSource, flags, ref outputs);
|
||||
return outputs;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
11
Scripts/Runtime/Simulator.cs.meta
Executable file
11
Scripts/Runtime/Simulator.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59c8ab9b6583fd541bae96e7d56ad808
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
136
Scripts/Runtime/StaticMesh.cs
Executable file
136
Scripts/Runtime/StaticMesh.cs
Executable file
@ -0,0 +1,136 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#if STEAMAUDIO_ENABLED
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public class StaticMesh
|
||||
{
|
||||
Context mContext = null;
|
||||
IntPtr mStaticMesh = IntPtr.Zero;
|
||||
|
||||
public StaticMesh(Context context, Scene scene, Vector3[] vertices, Triangle[] triangles, int[] materialIndices, Material[] materials)
|
||||
{
|
||||
mContext = context;
|
||||
|
||||
var verticesBuffer = Marshal.AllocHGlobal(vertices.Length * Marshal.SizeOf(typeof(Vector3)));
|
||||
var trianglesBuffer = Marshal.AllocHGlobal(triangles.Length * Marshal.SizeOf(typeof(Triangle)));
|
||||
var materialIndicesBuffer = Marshal.AllocHGlobal(materialIndices.Length * Marshal.SizeOf(typeof(int)));
|
||||
var materialsBuffer = Marshal.AllocHGlobal(materials.Length * Marshal.SizeOf(typeof(Material)));
|
||||
|
||||
for (var i = 0; i < vertices.Length; ++i)
|
||||
{
|
||||
Marshal.StructureToPtr(vertices[i], new IntPtr(verticesBuffer.ToInt64() + i * Marshal.SizeOf(typeof(Vector3))), false);
|
||||
}
|
||||
|
||||
for (var i = 0; i < triangles.Length; ++i)
|
||||
{
|
||||
Marshal.StructureToPtr(triangles[i], new IntPtr(trianglesBuffer.ToInt64() + i * Marshal.SizeOf(typeof(Triangle))), false);
|
||||
}
|
||||
|
||||
Marshal.Copy(materialIndices, 0, materialIndicesBuffer, triangles.Length);
|
||||
|
||||
for (var i = 0; i < materials.Length; ++i)
|
||||
{
|
||||
Marshal.StructureToPtr(materials[i], new IntPtr(materialsBuffer.ToInt64() + i * Marshal.SizeOf(typeof(Material))), false);
|
||||
}
|
||||
|
||||
var staticMeshSettings = new StaticMeshSettings { };
|
||||
staticMeshSettings.numVertices = vertices.Length;
|
||||
staticMeshSettings.numTriangles = triangles.Length;
|
||||
staticMeshSettings.numMaterials = materials.Length;
|
||||
staticMeshSettings.vertices = verticesBuffer;
|
||||
staticMeshSettings.triangles = trianglesBuffer;
|
||||
staticMeshSettings.materialIndices = materialIndicesBuffer;
|
||||
staticMeshSettings.materials = materialsBuffer;
|
||||
|
||||
var status = API.iplStaticMeshCreate(scene.Get(), ref staticMeshSettings, out mStaticMesh);
|
||||
if (status != Error.Success)
|
||||
{
|
||||
throw new Exception(string.Format("Unable to create static mesh for export ({0} vertices, {1} triangles, {2} materials): [{3}]",
|
||||
staticMeshSettings.numVertices.ToString(), staticMeshSettings.numTriangles.ToString(), staticMeshSettings.numMaterials.ToString(),
|
||||
status.ToString()));
|
||||
}
|
||||
|
||||
Marshal.FreeHGlobal(verticesBuffer);
|
||||
Marshal.FreeHGlobal(trianglesBuffer);
|
||||
Marshal.FreeHGlobal(materialIndicesBuffer);
|
||||
Marshal.FreeHGlobal(materialsBuffer);
|
||||
}
|
||||
|
||||
public StaticMesh(Context context, Scene scene, SerializedData dataAsset)
|
||||
{
|
||||
mContext = context;
|
||||
|
||||
var serializedObject = new SerializedObject(context, dataAsset);
|
||||
|
||||
var status = API.iplStaticMeshLoad(scene.Get(), serializedObject.Get(), null, IntPtr.Zero, out mStaticMesh);
|
||||
if (status != Error.Success)
|
||||
throw new Exception(string.Format("Unable to load static mesh ({0}). [{1}]", dataAsset.name, status));
|
||||
|
||||
serializedObject.Release();
|
||||
}
|
||||
|
||||
public StaticMesh(StaticMesh staticMesh)
|
||||
{
|
||||
mContext = staticMesh.mContext;
|
||||
|
||||
mStaticMesh = API.iplStaticMeshRetain(staticMesh.mStaticMesh);
|
||||
}
|
||||
|
||||
~StaticMesh()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
API.iplStaticMeshRelease(ref mStaticMesh);
|
||||
|
||||
mContext = null;
|
||||
}
|
||||
|
||||
public IntPtr Get()
|
||||
{
|
||||
return mStaticMesh;
|
||||
}
|
||||
|
||||
public void Save(SerializedData dataAsset)
|
||||
{
|
||||
var serializedObject = new SerializedObject(mContext);
|
||||
API.iplStaticMeshSave(mStaticMesh, serializedObject.Get());
|
||||
serializedObject.WriteToFile(dataAsset);
|
||||
serializedObject.Release();
|
||||
}
|
||||
|
||||
public void AddToScene(Scene scene)
|
||||
{
|
||||
API.iplStaticMeshAdd(mStaticMesh, scene.Get());
|
||||
scene.NotifyAddObject();
|
||||
}
|
||||
|
||||
public void RemoveFromScene(Scene scene)
|
||||
{
|
||||
API.iplStaticMeshRemove(mStaticMesh, scene.Get());
|
||||
scene.NotifyRemoveObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
11
Scripts/Runtime/StaticMesh.cs.meta
Executable file
11
Scripts/Runtime/StaticMesh.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 426a41fdb5d8b904fb4b688ed1b1db02
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
1372
Scripts/Runtime/SteamAudio.cs
Executable file
1372
Scripts/Runtime/SteamAudio.cs
Executable file
File diff suppressed because it is too large
Load Diff
11
Scripts/Runtime/SteamAudio.cs.meta
Executable file
11
Scripts/Runtime/SteamAudio.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: faab0996f33b3304faccb7f9f8c48dc9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
74
Scripts/Runtime/SteamAudioAmbisonicSource.cs
Executable file
74
Scripts/Runtime/SteamAudioAmbisonicSource.cs
Executable file
@ -0,0 +1,74 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
[AddComponentMenu("Steam Audio/Steam Audio Ambisonic Source")]
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
public class SteamAudioAmbisonicSource : MonoBehaviour
|
||||
{
|
||||
[Header("HRTF Settings")]
|
||||
public bool applyHRTF = true;
|
||||
|
||||
AudioEngineAmbisonicSource mAudioEngineAmbisonicSource = null;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
mAudioEngineAmbisonicSource = AudioEngineAmbisonicSource.Create(SteamAudioSettings.Singleton.audioEngine);
|
||||
if (mAudioEngineAmbisonicSource != null)
|
||||
{
|
||||
mAudioEngineAmbisonicSource.Initialize(gameObject);
|
||||
mAudioEngineAmbisonicSource.UpdateParameters(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (mAudioEngineAmbisonicSource != null)
|
||||
{
|
||||
mAudioEngineAmbisonicSource.UpdateParameters(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (mAudioEngineAmbisonicSource != null)
|
||||
{
|
||||
mAudioEngineAmbisonicSource.Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (mAudioEngineAmbisonicSource != null)
|
||||
{
|
||||
mAudioEngineAmbisonicSource.UpdateParameters(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (mAudioEngineAmbisonicSource != null)
|
||||
{
|
||||
mAudioEngineAmbisonicSource.UpdateParameters(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
Scripts/Runtime/SteamAudioAmbisonicSource.cs.meta
Executable file
11
Scripts/Runtime/SteamAudioAmbisonicSource.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe05866fd4e732246be6461a576ebcb0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
150
Scripts/Runtime/SteamAudioBakedListener.cs
Executable file
150
Scripts/Runtime/SteamAudioBakedListener.cs
Executable file
@ -0,0 +1,150 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
[AddComponentMenu("Steam Audio/Steam Audio Baked Listener")]
|
||||
public class SteamAudioBakedListener : MonoBehaviour
|
||||
{
|
||||
[Header("Baked Static Listener Settings")]
|
||||
[Range(0.0f, 1000.0f)]
|
||||
public float influenceRadius = 1000.0f;
|
||||
public bool useAllProbeBatches = false;
|
||||
public SteamAudioProbeBatch[] probeBatches = null;
|
||||
|
||||
[SerializeField]
|
||||
int mTotalDataSize = 0;
|
||||
[SerializeField]
|
||||
int[] mProbeDataSizes = null;
|
||||
[SerializeField]
|
||||
BakedDataIdentifier mIdentifier = new BakedDataIdentifier { };
|
||||
[SerializeField]
|
||||
SteamAudioProbeBatch[] mProbeBatchesUsed = null;
|
||||
|
||||
#if STEAMAUDIO_ENABLED
|
||||
public int GetTotalDataSize()
|
||||
{
|
||||
return mTotalDataSize;
|
||||
}
|
||||
|
||||
public int[] GetProbeDataSizes()
|
||||
{
|
||||
return mProbeDataSizes;
|
||||
}
|
||||
|
||||
public int GetSizeForProbeBatch(int index)
|
||||
{
|
||||
return mProbeDataSizes[index];
|
||||
}
|
||||
|
||||
public SteamAudioProbeBatch[] GetProbeBatchesUsed()
|
||||
{
|
||||
if (mProbeBatchesUsed == null)
|
||||
{
|
||||
CacheProbeBatchesUsed();
|
||||
}
|
||||
|
||||
return mProbeBatchesUsed;
|
||||
}
|
||||
|
||||
public BakedDataIdentifier GetBakedDataIdentifier()
|
||||
{
|
||||
var identifier = new BakedDataIdentifier { };
|
||||
identifier.type = BakedDataType.Reflections;
|
||||
identifier.variation = BakedDataVariation.StaticListener;
|
||||
identifier.endpointInfluence.center = Common.ConvertVector(transform.position);
|
||||
identifier.endpointInfluence.radius = influenceRadius;
|
||||
return identifier;
|
||||
}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
var oldColor = Gizmos.color;
|
||||
var oldMatrix = Gizmos.matrix;
|
||||
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawWireSphere(transform.position, influenceRadius);
|
||||
|
||||
Gizmos.color = Color.magenta;
|
||||
|
||||
if (mProbeBatchesUsed != null)
|
||||
{
|
||||
foreach (var probeBatch in mProbeBatchesUsed)
|
||||
{
|
||||
if (probeBatch == null)
|
||||
continue;
|
||||
|
||||
Gizmos.matrix = probeBatch.transform.localToWorldMatrix;
|
||||
Gizmos.DrawWireCube(new UnityEngine.Vector3(0, 0, 0), new UnityEngine.Vector3(1, 1, 1));
|
||||
}
|
||||
}
|
||||
|
||||
Gizmos.matrix = oldMatrix;
|
||||
Gizmos.color = oldColor;
|
||||
}
|
||||
|
||||
public void UpdateBakedDataStatistics()
|
||||
{
|
||||
if (mProbeBatchesUsed == null)
|
||||
return;
|
||||
|
||||
mProbeDataSizes = new int[mProbeBatchesUsed.Length];
|
||||
mTotalDataSize = 0;
|
||||
|
||||
for (var i = 0; i < mProbeBatchesUsed.Length; ++i)
|
||||
{
|
||||
mProbeDataSizes[i] = mProbeBatchesUsed[i].GetSizeForLayer(mIdentifier);
|
||||
mTotalDataSize += mProbeDataSizes[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void BeginBake()
|
||||
{
|
||||
CacheIdentifier();
|
||||
CacheProbeBatchesUsed();
|
||||
|
||||
var tasks = new BakedDataTask[1];
|
||||
tasks[0].gameObject = gameObject;
|
||||
tasks[0].component = this;
|
||||
tasks[0].name = gameObject.name;
|
||||
tasks[0].identifier = mIdentifier;
|
||||
tasks[0].probeBatches = (useAllProbeBatches) ? FindObjectsOfType<SteamAudioProbeBatch>() : probeBatches;
|
||||
tasks[0].probeBatchNames = new string[tasks[0].probeBatches.Length];
|
||||
tasks[0].probeBatchAssets = new SerializedData[tasks[0].probeBatches.Length];
|
||||
for (var i = 0; i < tasks[0].probeBatchNames.Length; ++i)
|
||||
{
|
||||
tasks[0].probeBatchNames[i] = tasks[0].probeBatches[i].gameObject.name;
|
||||
tasks[0].probeBatchAssets[i] = tasks[0].probeBatches[i].GetAsset();
|
||||
}
|
||||
|
||||
Baker.BeginBake(tasks);
|
||||
}
|
||||
|
||||
void CacheIdentifier()
|
||||
{
|
||||
mIdentifier = GetBakedDataIdentifier();
|
||||
}
|
||||
|
||||
void CacheProbeBatchesUsed()
|
||||
{
|
||||
mProbeBatchesUsed = (useAllProbeBatches) ? FindObjectsOfType<SteamAudioProbeBatch>() : probeBatches;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
11
Scripts/Runtime/SteamAudioBakedListener.cs.meta
Executable file
11
Scripts/Runtime/SteamAudioBakedListener.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d1a2bdfdee8e5b48a9949c674b73640
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
150
Scripts/Runtime/SteamAudioBakedSource.cs
Executable file
150
Scripts/Runtime/SteamAudioBakedSource.cs
Executable file
@ -0,0 +1,150 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
[AddComponentMenu("Steam Audio/Steam Audio Baked Source")]
|
||||
public class SteamAudioBakedSource : MonoBehaviour
|
||||
{
|
||||
[Header("Baked Static Source Settings")]
|
||||
[Range(0.0f, 1000.0f)]
|
||||
public float influenceRadius = 1000.0f;
|
||||
public bool useAllProbeBatches = false;
|
||||
public SteamAudioProbeBatch[] probeBatches = null;
|
||||
|
||||
[SerializeField]
|
||||
int mTotalDataSize = 0;
|
||||
[SerializeField]
|
||||
int[] mProbeDataSizes = null;
|
||||
[SerializeField]
|
||||
BakedDataIdentifier mIdentifier = new BakedDataIdentifier { };
|
||||
[SerializeField]
|
||||
SteamAudioProbeBatch[] mProbeBatchesUsed = null;
|
||||
|
||||
#if STEAMAUDIO_ENABLED
|
||||
public int GetTotalDataSize()
|
||||
{
|
||||
return mTotalDataSize;
|
||||
}
|
||||
|
||||
public int[] GetProbeDataSizes()
|
||||
{
|
||||
return mProbeDataSizes;
|
||||
}
|
||||
|
||||
public int GetSizeForProbeBatch(int index)
|
||||
{
|
||||
return mProbeDataSizes[index];
|
||||
}
|
||||
|
||||
public SteamAudioProbeBatch[] GetProbeBatchesUsed()
|
||||
{
|
||||
if (mProbeBatchesUsed == null)
|
||||
{
|
||||
CacheProbeBatchesUsed();
|
||||
}
|
||||
|
||||
return mProbeBatchesUsed;
|
||||
}
|
||||
|
||||
public BakedDataIdentifier GetBakedDataIdentifier()
|
||||
{
|
||||
var identifier = new BakedDataIdentifier { };
|
||||
identifier.type = BakedDataType.Reflections;
|
||||
identifier.variation = BakedDataVariation.StaticSource;
|
||||
identifier.endpointInfluence.center = Common.ConvertVector(transform.position);
|
||||
identifier.endpointInfluence.radius = influenceRadius;
|
||||
return identifier;
|
||||
}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
var oldColor = Gizmos.color;
|
||||
var oldMatrix = Gizmos.matrix;
|
||||
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawWireSphere(transform.position, influenceRadius);
|
||||
|
||||
Gizmos.color = Color.magenta;
|
||||
|
||||
if (mProbeBatchesUsed != null)
|
||||
{
|
||||
foreach (var probeBatch in mProbeBatchesUsed)
|
||||
{
|
||||
if (probeBatch == null)
|
||||
continue;
|
||||
|
||||
Gizmos.matrix = probeBatch.transform.localToWorldMatrix;
|
||||
Gizmos.DrawWireCube(new UnityEngine.Vector3(0, 0, 0), new UnityEngine.Vector3(1, 1, 1));
|
||||
}
|
||||
}
|
||||
|
||||
Gizmos.matrix = oldMatrix;
|
||||
Gizmos.color = oldColor;
|
||||
}
|
||||
|
||||
public void UpdateBakedDataStatistics()
|
||||
{
|
||||
if (mProbeBatchesUsed == null)
|
||||
return;
|
||||
|
||||
mProbeDataSizes = new int[mProbeBatchesUsed.Length];
|
||||
mTotalDataSize = 0;
|
||||
|
||||
for (var i = 0; i < mProbeBatchesUsed.Length; ++i)
|
||||
{
|
||||
mProbeDataSizes[i] = mProbeBatchesUsed[i].GetSizeForLayer(mIdentifier);
|
||||
mTotalDataSize += mProbeDataSizes[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void BeginBake()
|
||||
{
|
||||
CacheIdentifier();
|
||||
CacheProbeBatchesUsed();
|
||||
|
||||
var tasks = new BakedDataTask[1];
|
||||
tasks[0].gameObject = gameObject;
|
||||
tasks[0].component = this;
|
||||
tasks[0].name = gameObject.name;
|
||||
tasks[0].identifier = mIdentifier;
|
||||
tasks[0].probeBatches = (useAllProbeBatches) ? FindObjectsOfType<SteamAudioProbeBatch>() : probeBatches;
|
||||
tasks[0].probeBatchNames = new string[tasks[0].probeBatches.Length];
|
||||
tasks[0].probeBatchAssets = new SerializedData[tasks[0].probeBatches.Length];
|
||||
for (var i = 0; i < tasks[0].probeBatchNames.Length; ++i)
|
||||
{
|
||||
tasks[0].probeBatchNames[i] = tasks[0].probeBatches[i].gameObject.name;
|
||||
tasks[0].probeBatchAssets[i] = tasks[0].probeBatches[i].GetAsset();
|
||||
}
|
||||
|
||||
Baker.BeginBake(tasks);
|
||||
}
|
||||
|
||||
void CacheIdentifier()
|
||||
{
|
||||
mIdentifier = GetBakedDataIdentifier();
|
||||
}
|
||||
|
||||
void CacheProbeBatchesUsed()
|
||||
{
|
||||
mProbeBatchesUsed = (useAllProbeBatches) ? FindObjectsOfType<SteamAudioProbeBatch>() : probeBatches;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
11
Scripts/Runtime/SteamAudioBakedSource.cs.meta
Executable file
11
Scripts/Runtime/SteamAudioBakedSource.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ea378497d2d9e847898c57b9eb3fb94
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
82
Scripts/Runtime/SteamAudioDynamicObject.cs
Executable file
82
Scripts/Runtime/SteamAudioDynamicObject.cs
Executable file
@ -0,0 +1,82 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
[AddComponentMenu("Steam Audio/Steam Audio Dynamic Object")]
|
||||
public class SteamAudioDynamicObject : MonoBehaviour
|
||||
{
|
||||
[Header("Export Settings")]
|
||||
public SerializedData asset = null;
|
||||
|
||||
#if STEAMAUDIO_ENABLED
|
||||
InstancedMesh mInstancedMesh = null;
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
SteamAudioManager.UnloadDynamicObject(this);
|
||||
|
||||
if (mInstancedMesh != null)
|
||||
{
|
||||
mInstancedMesh.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (mInstancedMesh != null)
|
||||
{
|
||||
mInstancedMesh.AddToScene(SteamAudioManager.CurrentScene);
|
||||
SteamAudioManager.ScheduleCommitScene();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (mInstancedMesh != null && SteamAudioManager.CurrentScene != null)
|
||||
{
|
||||
mInstancedMesh.RemoveFromScene(SteamAudioManager.CurrentScene);
|
||||
SteamAudioManager.ScheduleCommitScene();
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (mInstancedMesh == null && asset != null)
|
||||
{
|
||||
mInstancedMesh = SteamAudioManager.LoadDynamicObject(this, SteamAudioManager.CurrentScene, SteamAudioManager.Context);
|
||||
|
||||
if (enabled)
|
||||
{
|
||||
mInstancedMesh.AddToScene(SteamAudioManager.CurrentScene);
|
||||
SteamAudioManager.ScheduleCommitScene();
|
||||
}
|
||||
}
|
||||
|
||||
// Only update the dynamic object if it has actually move this frame
|
||||
if (transform.hasChanged)
|
||||
{
|
||||
mInstancedMesh.UpdateTransform(SteamAudioManager.CurrentScene, transform);
|
||||
SteamAudioManager.ScheduleCommitScene();
|
||||
transform.hasChanged = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
11
Scripts/Runtime/SteamAudioDynamicObject.cs.meta
Executable file
11
Scripts/Runtime/SteamAudioDynamicObject.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2fb43d10a308b2f46ad4561774f97e52
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
76
Scripts/Runtime/SteamAudioFMODStudio.cs
Executable file
76
Scripts/Runtime/SteamAudioFMODStudio.cs
Executable file
@ -0,0 +1,76 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public static class FMODStudioAPI
|
||||
{
|
||||
// FMOD STUDIO PLUGIN
|
||||
|
||||
#if UNITY_IOS && !UNITY_EDITOR
|
||||
[DllImport("__Internal")]
|
||||
#else
|
||||
[DllImport("phonon_fmod")]
|
||||
#endif
|
||||
public static extern void iplFMODInitialize(IntPtr context);
|
||||
|
||||
#if UNITY_IOS && !UNITY_EDITOR
|
||||
[DllImport("__Internal")]
|
||||
#else
|
||||
[DllImport("phonon_fmod")]
|
||||
#endif
|
||||
public static extern void iplFMODSetHRTF(IntPtr hrtf);
|
||||
|
||||
#if UNITY_IOS && !UNITY_EDITOR
|
||||
[DllImport("__Internal")]
|
||||
#else
|
||||
[DllImport("phonon_fmod")]
|
||||
#endif
|
||||
public static extern void iplFMODSetSimulationSettings(SimulationSettings simulationSettings);
|
||||
|
||||
#if UNITY_IOS && !UNITY_EDITOR
|
||||
[DllImport("__Internal")]
|
||||
#else
|
||||
[DllImport("phonon_fmod")]
|
||||
#endif
|
||||
public static extern void iplFMODSetReverbSource(IntPtr reverbSource);
|
||||
|
||||
#if UNITY_IOS && !UNITY_EDITOR
|
||||
[DllImport("__Internal")]
|
||||
#else
|
||||
[DllImport("phonon_fmod")]
|
||||
#endif
|
||||
public static extern void iplFMODTerminate();
|
||||
|
||||
#if UNITY_IOS && !UNITY_EDITOR
|
||||
[DllImport("__Internal")]
|
||||
#else
|
||||
[DllImport("phonon_fmod")]
|
||||
#endif
|
||||
public static extern int iplFMODAddSource(IntPtr source);
|
||||
|
||||
#if UNITY_IOS && !UNITY_EDITOR
|
||||
[DllImport("__Internal")]
|
||||
#else
|
||||
[DllImport("phonon_fmod")]
|
||||
#endif
|
||||
public static extern void iplFMODRemoveSource(int handle);
|
||||
}
|
||||
}
|
11
Scripts/Runtime/SteamAudioFMODStudio.cs.meta
Executable file
11
Scripts/Runtime/SteamAudioFMODStudio.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 910b4010d4f5f4c388938e56f9715f37
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
74
Scripts/Runtime/SteamAudioGeometry.cs
Executable file
74
Scripts/Runtime/SteamAudioGeometry.cs
Executable file
@ -0,0 +1,74 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
[AddComponentMenu("Steam Audio/Steam Audio Geometry")]
|
||||
public class SteamAudioGeometry : MonoBehaviour
|
||||
{
|
||||
[Header("Material Settings")]
|
||||
public SteamAudioMaterial material = null;
|
||||
[Header("Export Settings")]
|
||||
public bool exportAllChildren = false;
|
||||
[Header("Terrain Settings")]
|
||||
[Range(0, 10)]
|
||||
public int terrainSimplificationLevel = 0;
|
||||
|
||||
#if STEAMAUDIO_ENABLED
|
||||
public int GetNumVertices()
|
||||
{
|
||||
if (exportAllChildren)
|
||||
{
|
||||
var objects = SteamAudioManager.GetGameObjectsForExport(gameObject);
|
||||
|
||||
var numVertices = 0;
|
||||
foreach (var obj in objects)
|
||||
{
|
||||
numVertices += SteamAudioManager.GetNumVertices(obj);
|
||||
}
|
||||
|
||||
return numVertices;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SteamAudioManager.GetNumVertices(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetNumTriangles()
|
||||
{
|
||||
if (exportAllChildren)
|
||||
{
|
||||
var objects = SteamAudioManager.GetGameObjectsForExport(gameObject);
|
||||
|
||||
var numTriangles = 0;
|
||||
foreach (var obj in objects)
|
||||
{
|
||||
numTriangles += SteamAudioManager.GetNumTriangles(obj);
|
||||
}
|
||||
|
||||
return numTriangles;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SteamAudioManager.GetNumTriangles(gameObject);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
12
Scripts/Runtime/SteamAudioGeometry.cs.meta
Executable file
12
Scripts/Runtime/SteamAudioGeometry.cs.meta
Executable file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e829c87dc2a2ed2419c5f67848317fe4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- material: {fileID: 11400000, guid: a086f686223eed942816c70be67841b0, type: 2}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
247
Scripts/Runtime/SteamAudioListener.cs
Executable file
247
Scripts/Runtime/SteamAudioListener.cs
Executable file
@ -0,0 +1,247 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public enum ReverbType
|
||||
{
|
||||
Realtime,
|
||||
Baked
|
||||
}
|
||||
|
||||
[AddComponentMenu("Steam Audio/Steam Audio Listener")]
|
||||
public class SteamAudioListener : MonoBehaviour
|
||||
{
|
||||
[Header("Baked Static Listener Settings")]
|
||||
public SteamAudioBakedListener currentBakedListener = null;
|
||||
|
||||
[Header("Reverb Settings")]
|
||||
public bool applyReverb = false;
|
||||
public ReverbType reverbType = ReverbType.Realtime;
|
||||
|
||||
[Header("Baked Reverb Settings")]
|
||||
public bool useAllProbeBatches = false;
|
||||
public SteamAudioProbeBatch[] probeBatches = null;
|
||||
|
||||
[SerializeField]
|
||||
int mTotalDataSize = 0;
|
||||
[SerializeField]
|
||||
int[] mProbeDataSizes = null;
|
||||
[SerializeField]
|
||||
BakedDataIdentifier mIdentifier = new BakedDataIdentifier { };
|
||||
[SerializeField]
|
||||
SteamAudioProbeBatch[] mProbeBatchesUsed = null;
|
||||
|
||||
#if STEAMAUDIO_ENABLED
|
||||
Simulator mSimulator = null;
|
||||
Source mSource = null;
|
||||
|
||||
public int GetTotalDataSize()
|
||||
{
|
||||
return mTotalDataSize;
|
||||
}
|
||||
|
||||
public int[] GetProbeDataSizes()
|
||||
{
|
||||
return mProbeDataSizes;
|
||||
}
|
||||
|
||||
public int GetSizeForProbeBatch(int index)
|
||||
{
|
||||
return mProbeDataSizes[index];
|
||||
}
|
||||
|
||||
public SteamAudioProbeBatch[] GetProbeBatchesUsed()
|
||||
{
|
||||
if (mProbeBatchesUsed == null)
|
||||
{
|
||||
CacheProbeBatchesUsed();
|
||||
}
|
||||
|
||||
return mProbeBatchesUsed;
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Reinitialize();
|
||||
}
|
||||
|
||||
public void Reinitialize()
|
||||
{
|
||||
mSimulator = SteamAudioManager.Simulator;
|
||||
|
||||
var settings = SteamAudioManager.GetSimulationSettings(false);
|
||||
mSource = new Source(SteamAudioManager.Simulator, settings);
|
||||
|
||||
SteamAudioManager.GetAudioEngineState().SetReverbSource(mSource);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (mSource != null)
|
||||
{
|
||||
mSource.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SteamAudioManager.GetAudioEngineState().SetReverbSource(mSource);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (applyReverb)
|
||||
{
|
||||
mSource.AddToSimulator(mSimulator);
|
||||
SteamAudioManager.AddListener(this);
|
||||
SteamAudioManager.GetAudioEngineState().SetReverbSource(mSource);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (applyReverb)
|
||||
{
|
||||
SteamAudioManager.RemoveListener(this);
|
||||
mSource.RemoveFromSimulator(mSimulator);
|
||||
SteamAudioManager.GetAudioEngineState().SetReverbSource(mSource);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
SteamAudioManager.GetAudioEngineState().SetReverbSource(mSource);
|
||||
}
|
||||
|
||||
public BakedDataIdentifier GetBakedDataIdentifier()
|
||||
{
|
||||
var identifier = new BakedDataIdentifier { };
|
||||
identifier.type = BakedDataType.Reflections;
|
||||
identifier.variation = BakedDataVariation.Reverb;
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public void SetInputs(SimulationFlags flags)
|
||||
{
|
||||
var inputs = new SimulationInputs { };
|
||||
inputs.source.origin = Common.ConvertVector(transform.position);
|
||||
inputs.source.ahead = Common.ConvertVector(transform.forward);
|
||||
inputs.source.up = Common.ConvertVector(transform.up);
|
||||
inputs.source.right = Common.ConvertVector(transform.right);
|
||||
inputs.distanceAttenuationModel.type = DistanceAttenuationModelType.Default;
|
||||
inputs.airAbsorptionModel.type = AirAbsorptionModelType.Default;
|
||||
inputs.reverbScaleLow = 1.0f;
|
||||
inputs.reverbScaleMid = 1.0f;
|
||||
inputs.reverbScaleHigh = 1.0f;
|
||||
inputs.hybridReverbTransitionTime = SteamAudioSettings.Singleton.hybridReverbTransitionTime;
|
||||
inputs.hybridReverbOverlapPercent = SteamAudioSettings.Singleton.hybridReverbOverlapPercent / 100.0f;
|
||||
inputs.baked = (reverbType != ReverbType.Realtime) ? Bool.True : Bool.False;
|
||||
if (reverbType == ReverbType.Baked)
|
||||
{
|
||||
inputs.bakedDataIdentifier = GetBakedDataIdentifier();
|
||||
}
|
||||
|
||||
inputs.flags = 0;
|
||||
if (applyReverb)
|
||||
{
|
||||
inputs.flags = inputs.flags | SimulationFlags.Reflections;
|
||||
}
|
||||
|
||||
inputs.directFlags = 0;
|
||||
|
||||
mSource.SetInputs(flags, inputs);
|
||||
}
|
||||
|
||||
public void UpdateOutputs(SimulationFlags flags)
|
||||
{}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
var oldColor = Gizmos.color;
|
||||
var oldMatrix = Gizmos.matrix;
|
||||
|
||||
Gizmos.color = Color.magenta;
|
||||
|
||||
if (mProbeBatchesUsed != null)
|
||||
{
|
||||
foreach (var probeBatch in mProbeBatchesUsed)
|
||||
{
|
||||
if (probeBatch == null)
|
||||
continue;
|
||||
|
||||
Gizmos.matrix = probeBatch.transform.localToWorldMatrix;
|
||||
Gizmos.DrawWireCube(new UnityEngine.Vector3(0, 0, 0), new UnityEngine.Vector3(1, 1, 1));
|
||||
}
|
||||
}
|
||||
|
||||
Gizmos.matrix = oldMatrix;
|
||||
Gizmos.color = oldColor;
|
||||
}
|
||||
|
||||
public void UpdateBakedDataStatistics()
|
||||
{
|
||||
if (mProbeBatchesUsed == null)
|
||||
return;
|
||||
|
||||
mProbeDataSizes = new int[mProbeBatchesUsed.Length];
|
||||
mTotalDataSize = 0;
|
||||
|
||||
for (var i = 0; i < mProbeBatchesUsed.Length; ++i)
|
||||
{
|
||||
mProbeDataSizes[i] = mProbeBatchesUsed[i].GetSizeForLayer(mIdentifier);
|
||||
mTotalDataSize += mProbeDataSizes[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void BeginBake()
|
||||
{
|
||||
CacheIdentifier();
|
||||
CacheProbeBatchesUsed();
|
||||
|
||||
var tasks = new BakedDataTask[1];
|
||||
tasks[0].gameObject = gameObject;
|
||||
tasks[0].component = this;
|
||||
tasks[0].name = "Reverb";
|
||||
tasks[0].identifier = mIdentifier;
|
||||
tasks[0].probeBatches = (useAllProbeBatches) ? FindObjectsOfType<SteamAudioProbeBatch>() : probeBatches;
|
||||
tasks[0].probeBatchNames = new string[tasks[0].probeBatches.Length];
|
||||
tasks[0].probeBatchAssets = new SerializedData[tasks[0].probeBatches.Length];
|
||||
for (var i = 0; i < tasks[0].probeBatchNames.Length; ++i)
|
||||
{
|
||||
tasks[0].probeBatchNames[i] = tasks[0].probeBatches[i].gameObject.name;
|
||||
tasks[0].probeBatchAssets[i] = tasks[0].probeBatches[i].GetAsset();
|
||||
}
|
||||
|
||||
Baker.BeginBake(tasks);
|
||||
}
|
||||
|
||||
void CacheIdentifier()
|
||||
{
|
||||
mIdentifier.type = BakedDataType.Reflections;
|
||||
mIdentifier.variation = BakedDataVariation.Reverb;
|
||||
}
|
||||
|
||||
void CacheProbeBatchesUsed()
|
||||
{
|
||||
mProbeBatchesUsed = (useAllProbeBatches) ? FindObjectsOfType<SteamAudioProbeBatch>() : probeBatches;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
11
Scripts/Runtime/SteamAudioListener.cs.meta
Executable file
11
Scripts/Runtime/SteamAudioListener.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6fd9ebf1401392e4bbd47fea32f47642
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
2059
Scripts/Runtime/SteamAudioManager.cs
Executable file
2059
Scripts/Runtime/SteamAudioManager.cs
Executable file
File diff suppressed because it is too large
Load Diff
11
Scripts/Runtime/SteamAudioManager.cs.meta
Executable file
11
Scripts/Runtime/SteamAudioManager.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b11066ff95bbf3344b868394742f7002
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
55
Scripts/Runtime/SteamAudioMaterial.cs
Executable file
55
Scripts/Runtime/SteamAudioMaterial.cs
Executable file
@ -0,0 +1,55 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
[CreateAssetMenu(menuName = "Steam Audio/Steam Audio Material")]
|
||||
public class SteamAudioMaterial : ScriptableObject
|
||||
{
|
||||
[Header("Absorption")]
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float lowFreqAbsorption = 0.1f;
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float midFreqAbsorption = 0.1f;
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float highFreqAbsorption = 0.1f;
|
||||
[Header("Scattering")]
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float scattering = 0.5f;
|
||||
[Header("Transmission")]
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float lowFreqTransmission = 0.1f;
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float midFreqTransmission = 0.1f;
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float highFreqTransmission = 0.1f;
|
||||
|
||||
public Material GetMaterial()
|
||||
{
|
||||
var material = new Material { };
|
||||
material.absorptionLow = lowFreqAbsorption;
|
||||
material.absorptionMid = midFreqAbsorption;
|
||||
material.absorptionHigh = highFreqAbsorption;
|
||||
material.scattering = scattering;
|
||||
material.transmissionLow = lowFreqTransmission;
|
||||
material.transmissionMid = midFreqTransmission;
|
||||
material.transmissionHigh = highFreqTransmission;
|
||||
return material;
|
||||
}
|
||||
}
|
||||
}
|
11
Scripts/Runtime/SteamAudioMaterial.cs.meta
Executable file
11
Scripts/Runtime/SteamAudioMaterial.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1cb82a87a4954a947923856a12b49b38
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
344
Scripts/Runtime/SteamAudioProbeBatch.cs
Executable file
344
Scripts/Runtime/SteamAudioProbeBatch.cs
Executable file
@ -0,0 +1,344 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
[Serializable]
|
||||
public struct BakedDataLayerInfo
|
||||
{
|
||||
public GameObject gameObject;
|
||||
public BakedDataIdentifier identifier;
|
||||
public int dataSize;
|
||||
}
|
||||
|
||||
[AddComponentMenu("Steam Audio/Steam Audio Probe Batch")]
|
||||
public class SteamAudioProbeBatch : MonoBehaviour
|
||||
{
|
||||
[Header("Placement Settings")]
|
||||
public ProbeGenerationType placementStrategy = ProbeGenerationType.UniformFloor;
|
||||
[Range(.1f, 50f)]
|
||||
public float horizontalSpacing = 5f;
|
||||
[Range(.1f, 20f)]
|
||||
public float heightAboveFloor = 1.5f;
|
||||
|
||||
[Header("Export Settings")]
|
||||
public SerializedData asset = null;
|
||||
|
||||
public int probeDataSize = 0;
|
||||
[SerializeField] Sphere[] mProbeSpheres = null;
|
||||
[SerializeField] List<BakedDataLayerInfo> mBakedDataLayerInfo = new List<BakedDataLayerInfo>();
|
||||
|
||||
#if STEAMAUDIO_ENABLED
|
||||
ProbeBatch mProbeBatch = null;
|
||||
|
||||
const float kProbeDrawSize = 0.1f;
|
||||
|
||||
public SerializedData GetAsset()
|
||||
{
|
||||
if (asset == null)
|
||||
{
|
||||
asset = SerializedData.PromptForNewAsset(gameObject.scene.name + "_" + name);
|
||||
}
|
||||
|
||||
return asset;
|
||||
}
|
||||
|
||||
public int GetNumProbes()
|
||||
{
|
||||
return (mProbeSpheres == null) ? 0 : mProbeSpheres.Length;
|
||||
}
|
||||
|
||||
public int GetNumLayers()
|
||||
{
|
||||
return mBakedDataLayerInfo.Count;
|
||||
}
|
||||
|
||||
public IntPtr GetProbeBatch()
|
||||
{
|
||||
return mProbeBatch.Get();
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (asset == null)
|
||||
return;
|
||||
|
||||
mProbeBatch = new ProbeBatch(SteamAudioManager.Context, asset);
|
||||
mProbeBatch.Commit();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (mProbeBatch != null)
|
||||
{
|
||||
mProbeBatch.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
SteamAudioManager.Simulator.AddProbeBatch(mProbeBatch);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (SteamAudioManager.Simulator != null)
|
||||
{
|
||||
SteamAudioManager.Simulator.RemoveProbeBatch(mProbeBatch);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected()
|
||||
{
|
||||
var oldColor = Gizmos.color;
|
||||
Gizmos.color = Color.magenta;
|
||||
|
||||
var oldMatrix = Gizmos.matrix;
|
||||
Gizmos.matrix = transform.localToWorldMatrix;
|
||||
Gizmos.DrawWireCube(new UnityEngine.Vector3(0, 0, 0), new UnityEngine.Vector3(1, 1, 1));
|
||||
Gizmos.matrix = oldMatrix;
|
||||
|
||||
Gizmos.color = Color.yellow;
|
||||
if (mProbeSpheres != null)
|
||||
{
|
||||
for (var i = 0; i < mProbeSpheres.Length; ++i)
|
||||
{
|
||||
var center = Common.ConvertVector(mProbeSpheres[i].center);
|
||||
Gizmos.DrawCube(center, new UnityEngine.Vector3(kProbeDrawSize, kProbeDrawSize, kProbeDrawSize));
|
||||
}
|
||||
}
|
||||
Gizmos.color = oldColor;
|
||||
}
|
||||
|
||||
public void GenerateProbes()
|
||||
{
|
||||
SteamAudioManager.Initialize(ManagerInitReason.GeneratingProbes);
|
||||
SteamAudioManager.LoadScene(SceneManager.GetActiveScene(), SteamAudioManager.Context, false);
|
||||
var scene = SteamAudioManager.CurrentScene;
|
||||
|
||||
SteamAudioStaticMesh staticMeshComponent = null;
|
||||
var rootObjects = SceneManager.GetActiveScene().GetRootGameObjects();
|
||||
foreach (var rootObject in rootObjects)
|
||||
{
|
||||
staticMeshComponent = rootObject.GetComponentInChildren<SteamAudioStaticMesh>();
|
||||
if (staticMeshComponent)
|
||||
break;
|
||||
}
|
||||
|
||||
if (staticMeshComponent == null || staticMeshComponent.asset == null)
|
||||
{
|
||||
Debug.LogError(string.Format("Scene {0} has not been exported. Click Steam Audio > Export Active Scene to do so.", SceneManager.GetActiveScene().name));
|
||||
return;
|
||||
}
|
||||
|
||||
var staticMesh = new StaticMesh(SteamAudioManager.Context, scene, staticMeshComponent.asset);
|
||||
staticMesh.AddToScene(scene);
|
||||
|
||||
scene.Commit();
|
||||
|
||||
var probeArray = new ProbeArray(SteamAudioManager.Context);
|
||||
|
||||
var probeGenerationParams = new ProbeGenerationParams { };
|
||||
probeGenerationParams.type = placementStrategy;
|
||||
probeGenerationParams.spacing = horizontalSpacing;
|
||||
probeGenerationParams.height = heightAboveFloor;
|
||||
probeGenerationParams.transform = Common.TransposeMatrix(Common.ConvertTransform(gameObject.transform)); // Probe generation requires a transposed matrix.
|
||||
|
||||
probeArray.GenerateProbes(scene, probeGenerationParams);
|
||||
|
||||
var numProbes = probeArray.GetNumProbes();
|
||||
mProbeSpheres = new Sphere[numProbes];
|
||||
for (var i = 0; i < numProbes; ++i)
|
||||
{
|
||||
mProbeSpheres[i] = probeArray.GetProbe(i);
|
||||
}
|
||||
|
||||
var probeBatch = new ProbeBatch(SteamAudioManager.Context);
|
||||
probeBatch.AddProbeArray(probeArray);
|
||||
|
||||
probeDataSize = probeBatch.Save(GetAsset());
|
||||
|
||||
probeBatch.Release();
|
||||
probeArray.Release();
|
||||
staticMesh.Release();
|
||||
|
||||
SteamAudioManager.ShutDown();
|
||||
DestroyImmediate(SteamAudioManager.Singleton.gameObject);
|
||||
|
||||
ResetLayers();
|
||||
|
||||
Debug.Log("Generated " + mProbeSpheres.Length + " probes for game object " + gameObject.name + ".");
|
||||
|
||||
// Redraw scene view for probes to show up instantly.
|
||||
#if UNITY_EDITOR
|
||||
SceneView.RepaintAll();
|
||||
#endif
|
||||
}
|
||||
|
||||
public void DeleteBakedDataForIdentifier(BakedDataIdentifier identifier)
|
||||
{
|
||||
if (asset == null)
|
||||
return;
|
||||
|
||||
SteamAudioManager.Initialize(ManagerInitReason.EditingProbes);
|
||||
|
||||
var probeBatch = new ProbeBatch(SteamAudioManager.Context, asset);
|
||||
probeBatch.RemoveData(identifier);
|
||||
probeDataSize = probeBatch.Save(asset);
|
||||
probeBatch.Release();
|
||||
|
||||
SteamAudioManager.ShutDown();
|
||||
DestroyImmediate(SteamAudioManager.Singleton.gameObject);
|
||||
|
||||
RemoveLayer(identifier);
|
||||
}
|
||||
|
||||
public int GetSizeForLayer(BakedDataIdentifier identifier)
|
||||
{
|
||||
var layerInfo = new BakedDataLayerInfo { };
|
||||
if (FindLayer(identifier, ref layerInfo))
|
||||
{
|
||||
return layerInfo.dataSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public BakedDataLayerInfo GetInfoForLayer(int index)
|
||||
{
|
||||
return mBakedDataLayerInfo[index];
|
||||
}
|
||||
|
||||
public void ResetLayers()
|
||||
{
|
||||
mBakedDataLayerInfo.Clear();
|
||||
}
|
||||
|
||||
public void AddLayer(GameObject gameObject, BakedDataIdentifier identifier, int dataSize)
|
||||
{
|
||||
var layerInfo = new BakedDataLayerInfo { };
|
||||
layerInfo.gameObject = gameObject;
|
||||
layerInfo.identifier = identifier;
|
||||
layerInfo.dataSize = dataSize;
|
||||
|
||||
mBakedDataLayerInfo.Add(layerInfo);
|
||||
}
|
||||
|
||||
public void UpdateLayer(BakedDataIdentifier identifier, int dataSize)
|
||||
{
|
||||
var layerInfo = new BakedDataLayerInfo { };
|
||||
if (FindLayer(identifier, ref layerInfo))
|
||||
{
|
||||
layerInfo.dataSize = dataSize;
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveLayer(BakedDataIdentifier identifier)
|
||||
{
|
||||
var layerInfo = new BakedDataLayerInfo { };
|
||||
if (FindLayer(identifier, ref layerInfo))
|
||||
{
|
||||
mBakedDataLayerInfo.Remove(layerInfo);
|
||||
UpdateGameObjectStatistics(layerInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddOrUpdateLayer(GameObject gameObject, BakedDataIdentifier identifier, int dataSize)
|
||||
{
|
||||
var layerInfo = new BakedDataLayerInfo { };
|
||||
if (FindLayer(identifier, ref layerInfo))
|
||||
{
|
||||
UpdateLayer(identifier, dataSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddLayer(gameObject, identifier, dataSize);
|
||||
}
|
||||
}
|
||||
|
||||
bool FindLayer(BakedDataIdentifier identifier, ref BakedDataLayerInfo result)
|
||||
{
|
||||
foreach (var layerInfo in mBakedDataLayerInfo)
|
||||
{
|
||||
if (layerInfo.identifier.Equals(identifier))
|
||||
{
|
||||
result = layerInfo;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void UpdateGameObjectStatistics(BakedDataLayerInfo layerInfo)
|
||||
{
|
||||
if (layerInfo.identifier.type == BakedDataType.Reflections)
|
||||
{
|
||||
switch (layerInfo.identifier.variation)
|
||||
{
|
||||
case BakedDataVariation.Reverb:
|
||||
layerInfo.gameObject.GetComponent<SteamAudioListener>().UpdateBakedDataStatistics();
|
||||
break;
|
||||
|
||||
case BakedDataVariation.StaticSource:
|
||||
layerInfo.gameObject.GetComponent<SteamAudioBakedSource>().UpdateBakedDataStatistics();
|
||||
break;
|
||||
|
||||
case BakedDataVariation.StaticListener:
|
||||
layerInfo.gameObject.GetComponent<SteamAudioBakedListener>().UpdateBakedDataStatistics();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BakedDataIdentifier GetBakedDataIdentifier()
|
||||
{
|
||||
var identifier = new BakedDataIdentifier { };
|
||||
identifier.type = BakedDataType.Pathing;
|
||||
identifier.variation = BakedDataVariation.Dynamic;
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public void BeginBake()
|
||||
{
|
||||
var tasks = new BakedDataTask[1];
|
||||
tasks[0].gameObject = gameObject;
|
||||
tasks[0].component = this;
|
||||
tasks[0].name = gameObject.name;
|
||||
tasks[0].identifier = GetBakedDataIdentifier();
|
||||
tasks[0].probeBatches = new SteamAudioProbeBatch[1];
|
||||
tasks[0].probeBatchNames = new string[1];
|
||||
tasks[0].probeBatchAssets = new SerializedData[1];
|
||||
|
||||
tasks[0].probeBatches[0] = this;
|
||||
tasks[0].probeBatchNames[0] = gameObject.name;
|
||||
tasks[0].probeBatchAssets[0] = GetAsset();
|
||||
|
||||
Baker.BeginBake(tasks);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
11
Scripts/Runtime/SteamAudioProbeBatch.cs.meta
Executable file
11
Scripts/Runtime/SteamAudioProbeBatch.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 286962cac82a4fa4e9ec38ab663c9578
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
163
Scripts/Runtime/SteamAudioSettings.cs
Executable file
163
Scripts/Runtime/SteamAudioSettings.cs
Executable file
@ -0,0 +1,163 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public enum AudioEngineType
|
||||
{
|
||||
Unity,
|
||||
FMODStudio
|
||||
}
|
||||
|
||||
[CreateAssetMenu(menuName = "Steam Audio/Steam Audio Settings")]
|
||||
public class SteamAudioSettings : ScriptableObject
|
||||
{
|
||||
[Header("Audio Engine Settings")]
|
||||
public AudioEngineType audioEngine = AudioEngineType.Unity;
|
||||
|
||||
[Header("HRTF Settings")]
|
||||
public bool perspectiveCorrection = false;
|
||||
[Range(.25f, 4.0f)]
|
||||
public float perspectiveCorrectionFactor = 1.0f;
|
||||
[Range(-12.0f, 12.0f)]
|
||||
public float hrtfVolumeGainDB = 0.0f;
|
||||
public HRTFNormType hrtfNormalizationType = HRTFNormType.None;
|
||||
public SOFAFile[] SOFAFiles = null;
|
||||
|
||||
[Header("Material Settings")]
|
||||
public SteamAudioMaterial defaultMaterial = null;
|
||||
|
||||
[Header("Ray Tracer Settings")]
|
||||
public SceneType sceneType = SceneType.Default;
|
||||
public LayerMask layerMask = new LayerMask();
|
||||
|
||||
[Header("Occlusion Settings")]
|
||||
[Range(1, 128)]
|
||||
public int maxOcclusionSamples = 16;
|
||||
|
||||
[Header("Real-time Reflections Settings")]
|
||||
[Range(1024, 65536)]
|
||||
public int realTimeRays = 4096;
|
||||
[Range(1, 64)]
|
||||
public int realTimeBounces = 4;
|
||||
[Range(0.1f, 10.0f)]
|
||||
public float realTimeDuration = 1.0f;
|
||||
[Range(0, 3)]
|
||||
public int realTimeAmbisonicOrder = 1;
|
||||
[Range(1, 128)]
|
||||
public int realTimeMaxSources = 32;
|
||||
[Range(0, 100)]
|
||||
public int realTimeCPUCoresPercentage = 5;
|
||||
[Range(0.1f, 10.0f)]
|
||||
public float realTimeIrradianceMinDistance = 1.0f;
|
||||
|
||||
[Header("Baked Reflections Settings")]
|
||||
public bool bakeConvolution = true;
|
||||
public bool bakeParametric = false;
|
||||
[Range(1024, 65536)]
|
||||
public int bakingRays = 16384;
|
||||
[Range(1, 64)]
|
||||
public int bakingBounces = 16;
|
||||
[Range(0.1f, 10.0f)]
|
||||
public float bakingDuration = 1.0f;
|
||||
[Range(0, 3)]
|
||||
public int bakingAmbisonicOrder = 1;
|
||||
[Range(0, 100)]
|
||||
public int bakingCPUCoresPercentage = 50;
|
||||
[Range(0.1f, 10.0f)]
|
||||
public float bakingIrradianceMinDistance = 1.0f;
|
||||
|
||||
[Header("Baked Pathing Settings")]
|
||||
[Range(1, 32)]
|
||||
public int bakingVisibilitySamples = 4;
|
||||
[Range(0.0f, 2.0f)]
|
||||
public float bakingVisibilityRadius = 1.0f;
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float bakingVisibilityThreshold = 0.1f;
|
||||
[Range(0.0f, 1000.0f)]
|
||||
public float bakingVisibilityRange = 1000.0f;
|
||||
[Range(0.0f, 1000.0f)]
|
||||
public float bakingPathRange = 1000.0f;
|
||||
[Range(0, 100)]
|
||||
public int bakedPathingCPUCoresPercentage = 50;
|
||||
|
||||
[Header("Simulation Update Settings")]
|
||||
[Range(0.1f, 1.0f)]
|
||||
public float simulationUpdateInterval = 0.1f;
|
||||
|
||||
[Header("Reflection Effect Settings")]
|
||||
public ReflectionEffectType reflectionEffectType = ReflectionEffectType.Convolution;
|
||||
|
||||
[Header("Hybrid Reverb Settings")]
|
||||
[Range(0.1f, 2.0f)]
|
||||
public float hybridReverbTransitionTime = 1.0f;
|
||||
[Range(0, 100)]
|
||||
public int hybridReverbOverlapPercent = 25;
|
||||
|
||||
[Header("OpenCL Settings")]
|
||||
public OpenCLDeviceType deviceType = OpenCLDeviceType.GPU;
|
||||
[Range(0, 16)]
|
||||
public int maxReservedComputeUnits = 8;
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float fractionComputeUnitsForIRUpdate = 0.5f;
|
||||
|
||||
[Header("Radeon Rays Settings")]
|
||||
[Range(1, 16)]
|
||||
public int bakingBatchSize = 8;
|
||||
|
||||
[Header("TrueAudio Next Settings")]
|
||||
[Range(0.1f, 10.0f)]
|
||||
public float TANDuration = 1.0f;
|
||||
[Range(0, 3)]
|
||||
public int TANAmbisonicOrder = 1;
|
||||
[Range(1, 128)]
|
||||
public int TANMaxSources = 32;
|
||||
|
||||
[Header("Advanced Settings")]
|
||||
public bool EnableValidation = false;
|
||||
|
||||
static SteamAudioSettings sSingleton = null;
|
||||
|
||||
public static SteamAudioSettings Singleton
|
||||
{
|
||||
get
|
||||
{
|
||||
if (sSingleton == null)
|
||||
{
|
||||
sSingleton = Resources.Load<SteamAudioSettings>("SteamAudioSettings");
|
||||
if (sSingleton == null)
|
||||
{
|
||||
sSingleton = CreateInstance<SteamAudioSettings>();
|
||||
sSingleton.name = "Steam Audio Settings";
|
||||
|
||||
#if UNITY_EDITOR
|
||||
sSingleton.defaultMaterial = (SteamAudioMaterial) AssetDatabase.LoadAssetAtPath("Assets/Plugins/SteamAudio/Resources/Materials/Default.asset", typeof(SteamAudioMaterial));
|
||||
|
||||
AssetDatabase.CreateAsset(sSingleton, "Assets/Plugins/SteamAudio/Resources/SteamAudioSettings.asset");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return sSingleton;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
12
Scripts/Runtime/SteamAudioSettings.cs.meta
Executable file
12
Scripts/Runtime/SteamAudioSettings.cs.meta
Executable file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3efcebd75ef2af49badc83215c91685
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- defaultMaterial: {fileID: 11400000, guid: a086f686223eed942816c70be67841b0, type: 2}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
544
Scripts/Runtime/SteamAudioSource.cs
Executable file
544
Scripts/Runtime/SteamAudioSource.cs
Executable file
@ -0,0 +1,544 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using AOT;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public enum DistanceAttenuationInput
|
||||
{
|
||||
CurveDriven,
|
||||
PhysicsBased
|
||||
}
|
||||
|
||||
public enum AirAbsorptionInput
|
||||
{
|
||||
SimulationDefined,
|
||||
UserDefined
|
||||
}
|
||||
|
||||
public enum DirectivityInput
|
||||
{
|
||||
SimulationDefined,
|
||||
UserDefined
|
||||
}
|
||||
|
||||
public enum OcclusionInput
|
||||
{
|
||||
SimulationDefined,
|
||||
UserDefined
|
||||
}
|
||||
|
||||
public enum TransmissionInput
|
||||
{
|
||||
SimulationDefined,
|
||||
UserDefined
|
||||
}
|
||||
|
||||
public enum ReflectionsType
|
||||
{
|
||||
Realtime,
|
||||
BakedStaticSource,
|
||||
BakedStaticListener
|
||||
}
|
||||
|
||||
public struct AudioSourceAttenuationData
|
||||
{
|
||||
public AudioRolloffMode rolloffMode;
|
||||
public float minDistance;
|
||||
public float maxDistance;
|
||||
public AnimationCurve curve;
|
||||
}
|
||||
|
||||
[AddComponentMenu("Steam Audio/Steam Audio Source")]
|
||||
public class SteamAudioSource : MonoBehaviour
|
||||
{
|
||||
[Header("HRTF Settings")]
|
||||
public bool directBinaural = true;
|
||||
public HRTFInterpolation interpolation = HRTFInterpolation.Nearest;
|
||||
public bool perspectiveCorrection = false;
|
||||
|
||||
[Header("Attenuation Settings")]
|
||||
public bool distanceAttenuation = false;
|
||||
public DistanceAttenuationInput distanceAttenuationInput = DistanceAttenuationInput.CurveDriven;
|
||||
public float distanceAttenuationValue = 1.0f;
|
||||
public bool airAbsorption = false;
|
||||
public AirAbsorptionInput airAbsorptionInput = AirAbsorptionInput.SimulationDefined;
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float airAbsorptionLow = 1.0f;
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float airAbsorptionMid = 1.0f;
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float airAbsorptionHigh = 1.0f;
|
||||
|
||||
[Header("Directivity Settings")]
|
||||
public bool directivity = false;
|
||||
public DirectivityInput directivityInput = DirectivityInput.SimulationDefined;
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float dipoleWeight = 0.0f;
|
||||
[Range(0.0f, 4.0f)]
|
||||
public float dipolePower = 0.0f;
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float directivityValue = 1.0f;
|
||||
|
||||
[Header("Occlusion Settings")]
|
||||
public bool occlusion = false;
|
||||
public OcclusionInput occlusionInput = OcclusionInput.SimulationDefined;
|
||||
public OcclusionType occlusionType = OcclusionType.Raycast;
|
||||
[Range(0.0f, 4.0f)]
|
||||
public float occlusionRadius = 1.0f;
|
||||
[Range(1, 128)]
|
||||
public int occlusionSamples = 16;
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float occlusionValue = 1.0f;
|
||||
public bool transmission = false;
|
||||
public TransmissionType transmissionType = TransmissionType.FrequencyIndependent;
|
||||
public TransmissionInput transmissionInput = TransmissionInput.SimulationDefined;
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float transmissionLow = 1.0f;
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float transmissionMid = 1.0f;
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float transmissionHigh = 1.0f;
|
||||
[Range(1, 8)]
|
||||
public int maxTransmissionSurfaces = 1;
|
||||
|
||||
[Header("Direct Mix Settings")]
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float directMixLevel = 1.0f;
|
||||
|
||||
[Header("Reflections Settings")]
|
||||
public bool reflections = false;
|
||||
public ReflectionsType reflectionsType = ReflectionsType.Realtime;
|
||||
public bool useDistanceCurveForReflections = false;
|
||||
public SteamAudioBakedSource currentBakedSource = null;
|
||||
public IntPtr reflectionsIR = IntPtr.Zero;
|
||||
public float reverbTimeLow = 0.0f;
|
||||
public float reverbTimeMid = 0.0f;
|
||||
public float reverbTimeHigh = 0.0f;
|
||||
public float hybridReverbEQLow = 1.0f;
|
||||
public float hybridReverbEQMid = 1.0f;
|
||||
public float hybridReverbEQHigh = 1.0f;
|
||||
public int hybridReverbDelay = 0;
|
||||
public bool applyHRTFToReflections = false;
|
||||
[Range(0.0f, 10.0f)]
|
||||
public float reflectionsMixLevel = 1.0f;
|
||||
|
||||
[Header("Pathing Settings")]
|
||||
public bool pathing = false;
|
||||
public SteamAudioProbeBatch pathingProbeBatch = null;
|
||||
public bool pathValidation = true;
|
||||
public bool findAlternatePaths = true;
|
||||
public float[] pathingEQ = new float[3] { 1.0f, 1.0f, 1.0f };
|
||||
public float[] pathingSH = new float[16];
|
||||
public bool applyHRTFToPathing = false;
|
||||
[Range(0.0f, 10.0f)]
|
||||
public float pathingMixLevel = 1.0f;
|
||||
|
||||
#if STEAMAUDIO_ENABLED
|
||||
Simulator mSimulator = null;
|
||||
Source mSource = null;
|
||||
AudioEngineSource mAudioEngineSource = null;
|
||||
UnityEngine.Vector3[] mSphereVertices = null;
|
||||
UnityEngine.Vector3[] mDeformedSphereVertices = null;
|
||||
Mesh mDeformedSphereMesh = null;
|
||||
|
||||
AudioSource mAudioSource = null;
|
||||
AudioSourceAttenuationData mAttenuationData = new AudioSourceAttenuationData { };
|
||||
DistanceAttenuationModel mCurveAttenuationModel = new DistanceAttenuationModel { };
|
||||
GCHandle mThis;
|
||||
SteamAudioSettings mSettings = null;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
mSimulator = SteamAudioManager.Simulator;
|
||||
|
||||
var settings = SteamAudioManager.GetSimulationSettings(false);
|
||||
mSource = new Source(SteamAudioManager.Simulator, settings);
|
||||
mSettings = SteamAudioSettings.Singleton;
|
||||
|
||||
mAudioEngineSource = AudioEngineSource.Create(mSettings.audioEngine);
|
||||
if (mAudioEngineSource != null)
|
||||
{
|
||||
mAudioEngineSource.Initialize(gameObject);
|
||||
mAudioEngineSource.UpdateParameters(this);
|
||||
}
|
||||
|
||||
mAudioSource = GetComponent<AudioSource>();
|
||||
|
||||
mThis = GCHandle.Alloc(this);
|
||||
|
||||
if (mSettings.audioEngine == AudioEngineType.Unity &&
|
||||
distanceAttenuation &&
|
||||
distanceAttenuationInput == DistanceAttenuationInput.CurveDriven &&
|
||||
reflections &&
|
||||
useDistanceCurveForReflections)
|
||||
{
|
||||
mAttenuationData.rolloffMode = mAudioSource.rolloffMode;
|
||||
mAttenuationData.minDistance = mAudioSource.minDistance;
|
||||
mAttenuationData.maxDistance = mAudioSource.maxDistance;
|
||||
mAttenuationData.curve = mAudioSource.GetCustomCurve(AudioSourceCurveType.CustomRolloff);
|
||||
|
||||
mCurveAttenuationModel.type = DistanceAttenuationModelType.Callback;
|
||||
mCurveAttenuationModel.callback = EvaluateDistanceCurve;
|
||||
mCurveAttenuationModel.userData = GCHandle.ToIntPtr(mThis);
|
||||
mCurveAttenuationModel.dirty = Bool.False;
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (mAudioEngineSource != null)
|
||||
{
|
||||
mAudioEngineSource.UpdateParameters(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (mAudioEngineSource != null)
|
||||
{
|
||||
mAudioEngineSource.Destroy();
|
||||
mAudioEngineSource = null;
|
||||
}
|
||||
|
||||
if (mSource != null)
|
||||
{
|
||||
mSource.Release();
|
||||
mSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
~SteamAudioSource()
|
||||
{
|
||||
mThis.Free();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
mSource.AddToSimulator(mSimulator);
|
||||
SteamAudioManager.AddSource(this);
|
||||
|
||||
if (mAudioEngineSource != null)
|
||||
{
|
||||
mAudioEngineSource.UpdateParameters(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
SteamAudioManager.RemoveSource(this);
|
||||
mSource.RemoveFromSimulator(mSimulator);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (mAudioEngineSource != null)
|
||||
{
|
||||
mAudioEngineSource.UpdateParameters(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
if (directivity && directivityInput == DirectivityInput.SimulationDefined && dipoleWeight > 0.0f)
|
||||
{
|
||||
if (mDeformedSphereMesh == null)
|
||||
{
|
||||
InitializeDeformedSphereMesh(32, 32);
|
||||
}
|
||||
|
||||
DeformSphereMesh();
|
||||
|
||||
var oldColor = Gizmos.color;
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireMesh(mDeformedSphereMesh, transform.position, transform.rotation);
|
||||
Gizmos.color = oldColor;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetInputs(SimulationFlags flags)
|
||||
{
|
||||
var listener = SteamAudioManager.GetSteamAudioListener();
|
||||
|
||||
var inputs = new SimulationInputs { };
|
||||
inputs.source.origin = Common.ConvertVector(transform.position);
|
||||
inputs.source.ahead = Common.ConvertVector(transform.forward);
|
||||
inputs.source.up = Common.ConvertVector(transform.up);
|
||||
inputs.source.right = Common.ConvertVector(transform.right);
|
||||
|
||||
if (mSettings.audioEngine == AudioEngineType.Unity &&
|
||||
distanceAttenuation &&
|
||||
distanceAttenuationInput == DistanceAttenuationInput.CurveDriven &&
|
||||
reflections &&
|
||||
useDistanceCurveForReflections)
|
||||
{
|
||||
inputs.distanceAttenuationModel = mCurveAttenuationModel;
|
||||
}
|
||||
else
|
||||
{
|
||||
inputs.distanceAttenuationModel.type = DistanceAttenuationModelType.Default;
|
||||
}
|
||||
|
||||
inputs.airAbsorptionModel.type = AirAbsorptionModelType.Default;
|
||||
inputs.directivity.dipoleWeight = dipoleWeight;
|
||||
inputs.directivity.dipolePower = dipolePower;
|
||||
inputs.occlusionType = occlusionType;
|
||||
inputs.occlusionRadius = occlusionRadius;
|
||||
inputs.numOcclusionSamples = occlusionSamples;
|
||||
inputs.numTransmissionRays = maxTransmissionSurfaces;
|
||||
inputs.reverbScaleLow = 1.0f;
|
||||
inputs.reverbScaleMid = 1.0f;
|
||||
inputs.reverbScaleHigh = 1.0f;
|
||||
inputs.hybridReverbTransitionTime = mSettings.hybridReverbTransitionTime;
|
||||
inputs.hybridReverbOverlapPercent = mSettings.hybridReverbOverlapPercent / 100.0f;
|
||||
inputs.baked = (reflectionsType != ReflectionsType.Realtime) ? Bool.True : Bool.False;
|
||||
inputs.pathingProbes = (pathingProbeBatch != null) ? pathingProbeBatch.GetProbeBatch() : IntPtr.Zero;
|
||||
inputs.visRadius = mSettings.bakingVisibilityRadius;
|
||||
inputs.visThreshold = mSettings.bakingVisibilityThreshold;
|
||||
inputs.visRange = mSettings.bakingVisibilityRange;
|
||||
inputs.pathingOrder = mSettings.bakingAmbisonicOrder;
|
||||
inputs.enableValidation = pathValidation ? Bool.True : Bool.False;
|
||||
inputs.findAlternatePaths = findAlternatePaths ? Bool.True : Bool.False;
|
||||
|
||||
if (reflectionsType == ReflectionsType.BakedStaticSource)
|
||||
{
|
||||
if (currentBakedSource != null)
|
||||
{
|
||||
inputs.bakedDataIdentifier = currentBakedSource.GetBakedDataIdentifier();
|
||||
}
|
||||
}
|
||||
else if (reflectionsType == ReflectionsType.BakedStaticListener)
|
||||
{
|
||||
if (listener != null && listener.currentBakedListener != null)
|
||||
{
|
||||
inputs.bakedDataIdentifier = listener.currentBakedListener.GetBakedDataIdentifier();
|
||||
}
|
||||
}
|
||||
|
||||
inputs.flags = SimulationFlags.Direct;
|
||||
if (reflections)
|
||||
{
|
||||
if ((reflectionsType == ReflectionsType.Realtime) ||
|
||||
(reflectionsType == ReflectionsType.BakedStaticSource && currentBakedSource != null) ||
|
||||
(reflectionsType == ReflectionsType.BakedStaticListener && listener != null && listener.currentBakedListener != null))
|
||||
{
|
||||
inputs.flags = inputs.flags | SimulationFlags.Reflections;
|
||||
}
|
||||
}
|
||||
if (pathing)
|
||||
{
|
||||
if (pathingProbeBatch == null)
|
||||
{
|
||||
pathing = false;
|
||||
Debug.LogWarningFormat("Pathing probe batch not set, disabling pathing for source {0}.", gameObject.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
inputs.flags = inputs.flags | SimulationFlags.Pathing;
|
||||
}
|
||||
}
|
||||
|
||||
inputs.directFlags = 0;
|
||||
if (distanceAttenuation)
|
||||
inputs.directFlags = inputs.directFlags | DirectSimulationFlags.DistanceAttenuation;
|
||||
if (airAbsorption)
|
||||
inputs.directFlags = inputs.directFlags | DirectSimulationFlags.AirAbsorption;
|
||||
if (directivity)
|
||||
inputs.directFlags = inputs.directFlags | DirectSimulationFlags.Directivity;
|
||||
if (occlusion)
|
||||
inputs.directFlags = inputs.directFlags | DirectSimulationFlags.Occlusion;
|
||||
if (transmission)
|
||||
inputs.directFlags = inputs.directFlags | DirectSimulationFlags.Transmission;
|
||||
|
||||
mSource.SetInputs(flags, inputs);
|
||||
}
|
||||
|
||||
public SimulationOutputs GetOutputs(SimulationFlags flags)
|
||||
{
|
||||
return mSource.GetOutputs(flags);
|
||||
}
|
||||
|
||||
public Source GetSource()
|
||||
{
|
||||
return mSource;
|
||||
}
|
||||
|
||||
public void UpdateOutputs(SimulationFlags flags)
|
||||
{
|
||||
var outputs = mSource.GetOutputs(flags);
|
||||
|
||||
if (SteamAudioSettings.Singleton.audioEngine == AudioEngineType.Unity &&
|
||||
((flags & SimulationFlags.Direct) != 0))
|
||||
{
|
||||
if (distanceAttenuation && distanceAttenuationInput == DistanceAttenuationInput.PhysicsBased)
|
||||
{
|
||||
distanceAttenuationValue = outputs.direct.distanceAttenuation;
|
||||
}
|
||||
|
||||
if (airAbsorption && airAbsorptionInput == AirAbsorptionInput.SimulationDefined)
|
||||
{
|
||||
airAbsorptionLow = outputs.direct.airAbsorptionLow;
|
||||
airAbsorptionMid = outputs.direct.airAbsorptionMid;
|
||||
airAbsorptionHigh = outputs.direct.airAbsorptionHigh;
|
||||
}
|
||||
|
||||
if (directivity && directivityInput == DirectivityInput.SimulationDefined)
|
||||
{
|
||||
directivityValue = outputs.direct.directivity;
|
||||
}
|
||||
|
||||
if (occlusion && occlusionInput == OcclusionInput.SimulationDefined)
|
||||
{
|
||||
occlusionValue = outputs.direct.occlusion;
|
||||
}
|
||||
|
||||
if (transmission && transmissionInput == TransmissionInput.SimulationDefined)
|
||||
{
|
||||
transmissionLow = outputs.direct.transmissionLow;
|
||||
transmissionMid = outputs.direct.transmissionMid;
|
||||
transmissionHigh = outputs.direct.transmissionHigh;
|
||||
}
|
||||
}
|
||||
|
||||
if (pathing && ((flags & SimulationFlags.Pathing) != 0))
|
||||
{
|
||||
outputs.pathing.eqCoeffsLow = Mathf.Max(0.1f, outputs.pathing.eqCoeffsLow);
|
||||
outputs.pathing.eqCoeffsMid = Mathf.Max(0.1f, outputs.pathing.eqCoeffsMid);
|
||||
outputs.pathing.eqCoeffsHigh = Mathf.Max(0.1f, outputs.pathing.eqCoeffsHigh);
|
||||
}
|
||||
}
|
||||
|
||||
void InitializeDeformedSphereMesh(int nPhi, int nTheta)
|
||||
{
|
||||
var dPhi = (2.0f * Mathf.PI) / nPhi;
|
||||
var dTheta = Mathf.PI / nTheta;
|
||||
|
||||
mSphereVertices = new UnityEngine.Vector3[nPhi * nTheta];
|
||||
var index = 0;
|
||||
for (var i = 0; i < nPhi; ++i)
|
||||
{
|
||||
var phi = i * dPhi;
|
||||
for (var j = 0; j < nTheta; ++j)
|
||||
{
|
||||
var theta = (j * dTheta) - (0.5f * Mathf.PI);
|
||||
|
||||
var x = Mathf.Cos(theta) * Mathf.Sin(phi);
|
||||
var y = Mathf.Sin(theta);
|
||||
var z = Mathf.Cos(theta) * -Mathf.Cos(phi);
|
||||
|
||||
var vertex = new UnityEngine.Vector3(x, y, z);
|
||||
|
||||
mSphereVertices[index++] = vertex;
|
||||
}
|
||||
}
|
||||
|
||||
mDeformedSphereVertices = new UnityEngine.Vector3[nPhi * nTheta];
|
||||
Array.Copy(mSphereVertices, mDeformedSphereVertices, mSphereVertices.Length);
|
||||
|
||||
var indices = new int[6 * nPhi * (nTheta - 1)];
|
||||
index = 0;
|
||||
for (var i = 0; i < nPhi; ++i)
|
||||
{
|
||||
for (var j = 0; j < nTheta - 1; ++j)
|
||||
{
|
||||
var i0 = i * nTheta + j;
|
||||
var i1 = i * nTheta + (j + 1);
|
||||
var i2 = ((i + 1) % nPhi) * nTheta + (j + 1);
|
||||
var i3 = ((i + 1) % nPhi) * nTheta + j;
|
||||
|
||||
indices[index++] = i0;
|
||||
indices[index++] = i1;
|
||||
indices[index++] = i2;
|
||||
indices[index++] = i0;
|
||||
indices[index++] = i2;
|
||||
indices[index++] = i3;
|
||||
}
|
||||
}
|
||||
|
||||
mDeformedSphereMesh = new Mesh();
|
||||
mDeformedSphereMesh.vertices = mDeformedSphereVertices;
|
||||
mDeformedSphereMesh.triangles = indices;
|
||||
mDeformedSphereMesh.RecalculateNormals();
|
||||
}
|
||||
|
||||
void DeformSphereMesh()
|
||||
{
|
||||
for (var i = 0; i < mSphereVertices.Length; ++i)
|
||||
{
|
||||
mDeformedSphereVertices[i] = DeformedVertex(mSphereVertices[i]);
|
||||
}
|
||||
|
||||
mDeformedSphereMesh.vertices = mDeformedSphereVertices;
|
||||
}
|
||||
|
||||
UnityEngine.Vector3 DeformedVertex(UnityEngine.Vector3 vertex)
|
||||
{
|
||||
var cosine = vertex.z;
|
||||
var r = Mathf.Pow(Mathf.Abs((1.0f - dipoleWeight) + dipoleWeight * cosine), dipolePower);
|
||||
var deformedVertex = vertex;
|
||||
deformedVertex.Scale(new UnityEngine.Vector3(r, r, r));
|
||||
return deformedVertex;
|
||||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(DistanceAttenuationCallback))]
|
||||
public static float EvaluateDistanceCurve(float distance, IntPtr userData)
|
||||
{
|
||||
var target = (SteamAudioSource) GCHandle.FromIntPtr(userData).Target;
|
||||
|
||||
var rMin = target.mAttenuationData.minDistance;
|
||||
var rMax = target.mAttenuationData.maxDistance;
|
||||
|
||||
switch (target.mAttenuationData.rolloffMode)
|
||||
{
|
||||
case AudioRolloffMode.Logarithmic:
|
||||
if (distance < rMin)
|
||||
return 1.0f;
|
||||
else if (distance < rMax)
|
||||
return 0.0f;
|
||||
else
|
||||
return rMin / distance;
|
||||
|
||||
case AudioRolloffMode.Linear:
|
||||
if (distance < rMin)
|
||||
return 1.0f;
|
||||
else if (distance > rMax)
|
||||
return 0.0f;
|
||||
else
|
||||
return (rMax - distance) / (rMax - rMin);
|
||||
|
||||
case AudioRolloffMode.Custom:
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
return target.mAttenuationData.curve.Evaluate(distance / rMax);
|
||||
#else
|
||||
if (distance < rMin)
|
||||
return 1.0f;
|
||||
else if (distance > rMax)
|
||||
return 0.0f;
|
||||
else
|
||||
return rMin / distance;
|
||||
#endif
|
||||
|
||||
default:
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
11
Scripts/Runtime/SteamAudioSource.cs.meta
Executable file
11
Scripts/Runtime/SteamAudioSource.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59c3684b22f00604a97bb68037fcf4cd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
80
Scripts/Runtime/SteamAudioStaticMesh.cs
Executable file
80
Scripts/Runtime/SteamAudioStaticMesh.cs
Executable file
@ -0,0 +1,80 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public class SteamAudioStaticMesh : MonoBehaviour
|
||||
{
|
||||
[Header("Export Settings")]
|
||||
public SerializedData asset = null;
|
||||
public string sceneNameWhenExported = "";
|
||||
|
||||
#if STEAMAUDIO_ENABLED
|
||||
StaticMesh mStaticMesh = null;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (asset == null)
|
||||
{
|
||||
Debug.LogWarningFormat("No asset set for Steam Audio Static Mesh in scene {0}. Export the scene before clicking Play.",
|
||||
gameObject.scene.name);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (mStaticMesh != null)
|
||||
{
|
||||
mStaticMesh.Release();
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (mStaticMesh != null)
|
||||
{
|
||||
mStaticMesh.AddToScene(SteamAudioManager.CurrentScene);
|
||||
SteamAudioManager.ScheduleCommitScene();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if (mStaticMesh != null && SteamAudioManager.CurrentScene != null)
|
||||
{
|
||||
mStaticMesh.RemoveFromScene(SteamAudioManager.CurrentScene);
|
||||
SteamAudioManager.ScheduleCommitScene();
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (mStaticMesh == null && asset != null)
|
||||
{
|
||||
mStaticMesh = new StaticMesh(SteamAudioManager.Context, SteamAudioManager.CurrentScene, asset);
|
||||
|
||||
if (enabled)
|
||||
{
|
||||
mStaticMesh.AddToScene(SteamAudioManager.CurrentScene);
|
||||
SteamAudioManager.ScheduleCommitScene();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
11
Scripts/Runtime/SteamAudioStaticMesh.cs.meta
Executable file
11
Scripts/Runtime/SteamAudioStaticMesh.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8173b2a8dbe2d2d48995bb2ba9a49ff1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
58
Scripts/Runtime/TrueAudioNextDevice.cs
Executable file
58
Scripts/Runtime/TrueAudioNextDevice.cs
Executable file
@ -0,0 +1,58 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public class TrueAudioNextDevice
|
||||
{
|
||||
IntPtr mTrueAudioNextDevice = IntPtr.Zero;
|
||||
|
||||
public TrueAudioNextDevice(OpenCLDevice openCLDevice, int frameSize, int irSize, int order, int maxSources)
|
||||
{
|
||||
var deviceSettings = new TrueAudioNextDeviceSettings { };
|
||||
deviceSettings.frameSize = frameSize;
|
||||
deviceSettings.irSize = irSize;
|
||||
deviceSettings.order = order;
|
||||
deviceSettings.maxSources = maxSources;
|
||||
|
||||
var status = API.iplTrueAudioNextDeviceCreate(openCLDevice.Get(), ref deviceSettings, out mTrueAudioNextDevice);
|
||||
if (status != Error.Success)
|
||||
throw new Exception(string.Format("Unable to create TrueAudio Next device. [{0}]", status));
|
||||
}
|
||||
|
||||
public TrueAudioNextDevice(TrueAudioNextDevice device)
|
||||
{
|
||||
mTrueAudioNextDevice = API.iplTrueAudioNextDeviceRetain(device.mTrueAudioNextDevice);
|
||||
}
|
||||
|
||||
~TrueAudioNextDevice()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
API.iplTrueAudioNextDeviceRelease(ref mTrueAudioNextDevice);
|
||||
}
|
||||
|
||||
public IntPtr Get()
|
||||
{
|
||||
return mTrueAudioNextDevice;
|
||||
}
|
||||
}
|
||||
}
|
11
Scripts/Runtime/TrueAudioNextDevice.cs.meta
Executable file
11
Scripts/Runtime/TrueAudioNextDevice.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdd785831c5dd8c43ab06d5c23bb56c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
40
Scripts/Runtime/UnityAudioEngineAmbisonicSource.cs
Executable file
40
Scripts/Runtime/UnityAudioEngineAmbisonicSource.cs
Executable file
@ -0,0 +1,40 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public sealed class UnityAudioEngineAmbisonicSource : AudioEngineAmbisonicSource
|
||||
{
|
||||
AudioSource mAudioSource = null;
|
||||
|
||||
public override void Initialize(GameObject gameObject)
|
||||
{
|
||||
mAudioSource = gameObject.GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
public override void UpdateParameters(SteamAudioAmbisonicSource ambisonicSource)
|
||||
{
|
||||
if (!mAudioSource)
|
||||
return;
|
||||
|
||||
var index = 0;
|
||||
mAudioSource.SetAmbisonicDecoderFloat(index++, (ambisonicSource.applyHRTF) ? 1.0f : 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
11
Scripts/Runtime/UnityAudioEngineAmbisonicSource.cs.meta
Executable file
11
Scripts/Runtime/UnityAudioEngineAmbisonicSource.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6e7b360f01d93347b477af15e75be7f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
94
Scripts/Runtime/UnityAudioEngineSource.cs
Executable file
94
Scripts/Runtime/UnityAudioEngineSource.cs
Executable file
@ -0,0 +1,94 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#if STEAMAUDIO_ENABLED
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public sealed class UnityAudioEngineSource : AudioEngineSource
|
||||
{
|
||||
AudioSource mAudioSource = null;
|
||||
SteamAudioSource mSteamAudioSource = null;
|
||||
int mHandle = -1;
|
||||
|
||||
public override void Initialize(GameObject gameObject)
|
||||
{
|
||||
mAudioSource = gameObject.GetComponent<AudioSource>();
|
||||
|
||||
mSteamAudioSource = gameObject.GetComponent<SteamAudioSource>();
|
||||
if (mSteamAudioSource)
|
||||
{
|
||||
mHandle = API.iplUnityAddSource(mSteamAudioSource.GetSource().Get());
|
||||
}
|
||||
}
|
||||
|
||||
public override void Destroy()
|
||||
{
|
||||
var index = 28;
|
||||
mAudioSource.SetSpatializerFloat(index, -1);
|
||||
|
||||
if (mSteamAudioSource)
|
||||
{
|
||||
API.iplUnityRemoveSource(mHandle);
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateParameters(SteamAudioSource source)
|
||||
{
|
||||
if (!mAudioSource)
|
||||
return;
|
||||
|
||||
var index = 0;
|
||||
mAudioSource.SetSpatializerFloat(index++, (source.distanceAttenuation) ? 1.0f : 0.0f);
|
||||
mAudioSource.SetSpatializerFloat(index++, (source.airAbsorption) ? 1.0f : 0.0f);
|
||||
mAudioSource.SetSpatializerFloat(index++, (source.directivity) ? 1.0f : 0.0f);
|
||||
mAudioSource.SetSpatializerFloat(index++, (source.occlusion) ? 1.0f : 0.0f);
|
||||
mAudioSource.SetSpatializerFloat(index++, (source.transmission) ? 1.0f : 0.0f);
|
||||
mAudioSource.SetSpatializerFloat(index++, (source.reflections) ? 1.0f : 0.0f);
|
||||
mAudioSource.SetSpatializerFloat(index++, (source.pathing) ? 1.0f : 0.0f);
|
||||
mAudioSource.SetSpatializerFloat(index++, (float) source.interpolation);
|
||||
mAudioSource.SetSpatializerFloat(index++, source.distanceAttenuationValue);
|
||||
mAudioSource.SetSpatializerFloat(index++, (source.distanceAttenuationInput == DistanceAttenuationInput.CurveDriven) ? 1.0f : 0.0f);
|
||||
mAudioSource.SetSpatializerFloat(index++, source.airAbsorptionLow);
|
||||
mAudioSource.SetSpatializerFloat(index++, source.airAbsorptionMid);
|
||||
mAudioSource.SetSpatializerFloat(index++, source.airAbsorptionHigh);
|
||||
mAudioSource.SetSpatializerFloat(index++, (source.airAbsorptionInput == AirAbsorptionInput.UserDefined) ? 1.0f : 0.0f);
|
||||
mAudioSource.SetSpatializerFloat(index++, source.directivityValue);
|
||||
mAudioSource.SetSpatializerFloat(index++, source.dipoleWeight);
|
||||
mAudioSource.SetSpatializerFloat(index++, source.dipolePower);
|
||||
mAudioSource.SetSpatializerFloat(index++, (source.directivityInput == DirectivityInput.UserDefined) ? 1.0f : 0.0f);
|
||||
mAudioSource.SetSpatializerFloat(index++, source.occlusionValue);
|
||||
mAudioSource.SetSpatializerFloat(index++, (float) source.transmissionType);
|
||||
mAudioSource.SetSpatializerFloat(index++, source.transmissionLow);
|
||||
mAudioSource.SetSpatializerFloat(index++, source.transmissionMid);
|
||||
mAudioSource.SetSpatializerFloat(index++, source.transmissionHigh);
|
||||
mAudioSource.SetSpatializerFloat(index++, source.directMixLevel);
|
||||
mAudioSource.SetSpatializerFloat(index++, (source.applyHRTFToReflections) ? 1.0f : 0.0f);
|
||||
mAudioSource.SetSpatializerFloat(index++, source.reflectionsMixLevel);
|
||||
mAudioSource.SetSpatializerFloat(index++, (source.applyHRTFToPathing) ? 1.0f : 0.0f);
|
||||
mAudioSource.SetSpatializerFloat(index++, source.pathingMixLevel);
|
||||
index++; // Skip 2 deprecated params.
|
||||
index++;
|
||||
mAudioSource.SetSpatializerFloat(index++, (source.directBinaural) ? 1.0f : 0.0f);
|
||||
mAudioSource.SetSpatializerFloat(index++, mHandle);
|
||||
mAudioSource.SetSpatializerFloat(index++, (source.perspectiveCorrection) ? 1.0f : 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
11
Scripts/Runtime/UnityAudioEngineSource.cs.meta
Executable file
11
Scripts/Runtime/UnityAudioEngineSource.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92cc150395b3d034aa2e8fc975634251
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
76
Scripts/Runtime/UnityAudioEngineState.cs
Executable file
76
Scripts/Runtime/UnityAudioEngineState.cs
Executable file
@ -0,0 +1,76 @@
|
||||
//
|
||||
// Copyright 2017-2023 Valve Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#if STEAMAUDIO_ENABLED
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SteamAudio
|
||||
{
|
||||
public sealed class UnityAudioEngineState : AudioEngineState
|
||||
{
|
||||
public override void Initialize(IntPtr context, IntPtr defaultHRTF, SimulationSettings simulationSettings, PerspectiveCorrection correction)
|
||||
{
|
||||
API.iplUnityInitialize(context);
|
||||
API.iplUnitySetHRTF(defaultHRTF);
|
||||
API.iplUnitySetSimulationSettings(simulationSettings);
|
||||
API.iplUnitySetPerspectiveCorrection(correction);
|
||||
}
|
||||
|
||||
public override void Destroy()
|
||||
{
|
||||
API.iplUnityTerminate();
|
||||
}
|
||||
|
||||
public override void SetHRTF(IntPtr hrtf)
|
||||
{
|
||||
API.iplUnitySetHRTF(hrtf);
|
||||
}
|
||||
|
||||
public override void SetPerspectiveCorrection(PerspectiveCorrection correction)
|
||||
{
|
||||
API.iplUnitySetPerspectiveCorrection(correction);
|
||||
}
|
||||
|
||||
public override void SetReverbSource(Source reverbSource)
|
||||
{
|
||||
API.iplUnitySetReverbSource(reverbSource.Get());
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class UnityAudioEngineStateHelpers : AudioEngineStateHelpers
|
||||
{
|
||||
public override Transform GetListenerTransform()
|
||||
{
|
||||
var audioListener = GameObject.FindObjectOfType<AudioListener>();
|
||||
return (audioListener != null) ? audioListener.transform : null;
|
||||
}
|
||||
|
||||
public override AudioSettings GetAudioSettings()
|
||||
{
|
||||
var audioSettings = new AudioSettings { };
|
||||
|
||||
audioSettings.samplingRate = UnityEngine.AudioSettings.outputSampleRate;
|
||||
|
||||
var numBuffers = 0;
|
||||
UnityEngine.AudioSettings.GetDSPBufferSize(out audioSettings.frameSize, out numBuffers);
|
||||
|
||||
return audioSettings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
11
Scripts/Runtime/UnityAudioEngineState.cs.meta
Executable file
11
Scripts/Runtime/UnityAudioEngineState.cs.meta
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1c6ea05d9a254e4eb65412b568878b5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user