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;
        }
Exemple #2
0
 public static extern void iplReflectionsBakerBake(IntPtr context, ref ReflectionsBakeParams bakeParams, ProgressCallback progressCallback, IntPtr userData);