Пример #1
0
        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);

            SteamAudioManager.ShutDown();
            DestroyImmediate(SteamAudioManager.Singleton.gameObject);

            RemoveLayer(identifier);
        }
Пример #2
0
        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
        }
Пример #3
0
        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;
        }