Ejemplo n.º 1
0
    // Computes reverb using already extracted scene geometry. Calls various native functions.
    // Returns false if failed.
    private static bool ComputeReverbForSceneGeometry()
    {
        // Initializes the reverb computation engine: creates the scene, sets up the surface materials,
        // and prepares the ray tracer.
        ResonanceAudio.InitializeReverbComputer(vertices, triangles, materials, scatteringCoefficient);

        // Iterate through the selected reverb probes.
        for (int i = 0; i < selectedReverbProbes.Count; ++i)
        {
            var    reverbProbe = selectedReverbProbes[i];
            string probeName   = "Probe[" + i + "] " + reverbProbe.gameObject.name;
            Undo.RecordObject(reverbProbe, "Bake Reverb To Reverb Probes");

            // Compute the RT60s and estimate the proxy room.
            var probePosition = reverbProbe.gameObject.transform.position;
            var outputRt60s   = reverbProbe.rt60s;
            ResonanceAudio.RoomProperties outputProxyRoomProperties = new ResonanceAudio.RoomProperties();
            if (!ResonanceAudio.ComputeRt60sAndProxyRoom(totalNumPaths, numPathsPerBatch, maxDepth,
                                                         energyThreshold, probePosition,
                                                         listenerSphereRadius, ref outputRt60s,
                                                         ref outputProxyRoomProperties))
            {
                Debug.LogError("FAILED c++ ComputeRT60sAndProxyRoom for " + probeName);
                return(false);
            }

            // Validate the computed RT60s for all frequency bands to the reverb probe.
            for (int band = 0; band < outputRt60s.Length; ++band)
            {
                float outputRt60Value = outputRt60s[band];
                if (Single.IsNaN(outputRt60Value) || Single.IsInfinity(outputRt60Value))
                {
                    Debug.Log("Invalid RT60 for " + probeName + ": " + outputRt60Value + "; set to zero");
                    outputRt60Value = 0.0f;
                }
                else if (outputRt60Value > ResonanceAudio.maxReverbTime || outputRt60Value < 0.0f)
                {
                    outputRt60Value = Mathf.Clamp(outputRt60Value, 0.0f, ResonanceAudio.maxReverbTime);
                }
                outputRt60s[band] = outputRt60Value;
            }

            // Copy the estimated proxy room properties to the reverb probe.
            reverbProbe.SetProxyRoomProperties(outputProxyRoomProperties);
        }
        return(true);
    }
Ejemplo n.º 2
0
 /// Set proxy room properties. Proxy rooms are estimated by the ray-tracing engine and passed
 /// back to be used in real-time early reflections.
 public void SetProxyRoomProperties(ResonanceAudio.RoomProperties proxyRoomProperties)
 {
     proxyRoomPosition = new Vector3(proxyRoomProperties.positionX,
                                     proxyRoomProperties.positionY,
                                     proxyRoomProperties.positionZ);
     proxyRoomRotation = new Quaternion(proxyRoomProperties.rotationX,
                                        proxyRoomProperties.rotationY,
                                        proxyRoomProperties.rotationZ,
                                        proxyRoomProperties.rotationW);
     proxyRoomSize = new Vector3(proxyRoomProperties.dimensionsX,
                                 proxyRoomProperties.dimensionsY,
                                 proxyRoomProperties.dimensionsZ);
     proxyRoomLeftWall  = proxyRoomProperties.materialLeft;
     proxyRoomRightWall = proxyRoomProperties.materialRight;
     proxyRoomFloor     = proxyRoomProperties.materialBottom;
     proxyRoomCeiling   = proxyRoomProperties.materialTop;
     proxyRoomBackWall  = proxyRoomProperties.materialBack;
     proxyRoomFrontWall = proxyRoomProperties.materialFront;
 }