Ejemplo n.º 1
0
    // Updates room properties with the given |reverbProbe|. For a reverb probe, the room properties
    // are used only in computing the distance attenuation.
    private static void UpdateRoomProperties(ResonanceAudioReverbProbe reverbProbe)
    {
        Vector3 scale = Vector3.zero;

        if (reverbProbe.runtimeApplicationRegionShape ==
            ResonanceAudioReverbProbe.ApplicationRegionShape.Sphere)
        {
            // Use the minimum enclosing cube of the sphere for distance attenuation.
            var diameter = 2.0f * reverbProbe.GetScaledSphericalApplicationRegionRadius();
            scale = diameter * Vector3.one;
        }
        else
        {
            scale = reverbProbe.GetScaledBoxApplicationRegionSize();
        }
        FillGeometryOfRoomProperties(reverbProbe.transform.position, reverbProbe.transform.rotation,
                                     scale);
        // Surface materials are not needed for reverb probes.
        var surfaceMaterial = ResonanceAudioRoomManager.SurfaceMaterial.Transparent;

        FillWallMaterialsOfRoomProperties(surfaceMaterial, surfaceMaterial, surfaceMaterial,
                                          surfaceMaterial, surfaceMaterial, surfaceMaterial);
        // Reflectivity is not a responsibility of reverb probes.
        float reflectivity = 0.0f;

        FillModifiersOfRoomProperties(reverbProbe.reverbGainDb, reverbProbe.reverbTime,
                                      reverbProbe.reverbBrightness, reflectivity);
    }
    // Returns room properties of the given |reverbProbe|. For a reverb probe, the room properties
    // are used only in computing the distance attenuation.
    private static RoomProperties GetRoomProperties(ResonanceAudioReverbProbe reverbProbe)
    {
        RoomProperties roomProperties = new RoomProperties();

        Vector3 scale;

        if (reverbProbe.runtimeApplicationRegionShape ==
            ResonanceAudioReverbProbe.ApplicationRegionShape.Sphere)
        {
            // Use the minimum enclosing cube of the sphere for distance attenuation.
            var diameter = 2.0f * reverbProbe.GetScaledSphericalApplicationRegionRadius();
            scale = new Vector3(diameter, diameter, diameter);
        }
        else
        {
            scale = reverbProbe.GetScaledBoxApplicationRegionSize();
        }

        FillGeometryOfRoomProperties(reverbProbe.transform.position, reverbProbe.transform.rotation,
                                     scale, ref roomProperties);

        float reflectivity = 0.0f; // Reflectivity is not a responsibility of reverb probes.

        FillModifiersOfRoomProperties(reverbProbe.reverbGainDb, reverbProbe.reverbTime,
                                      reverbProbe.reverbBrightness, reflectivity, ref roomProperties);
        return(roomProperties);
    }
    /// Returns whether the listener is currently inside the application region of the given
    /// |reverb_probe|, subject to the visibility test if |reverbProbe.onlyWhenVisible| is true.
    private static bool IsListenerInsideVisibleReverbProbe(ResonanceAudioReverbProbe reverbProbe)
    {
        Transform listenerTransform = ResonanceAudio.ListenerTransform;

        if (listenerTransform != null)
        {
            Vector3 relativePosition = listenerTransform.position - reverbProbe.transform.position;

            // First the containing test.
            if (reverbProbe.runtimeApplicationRegionShape ==
                ResonanceAudioReverbProbe.ApplicationRegionShape.Sphere)
            {
                if (relativePosition.magnitude > reverbProbe.GetScaledSphericalApplicationRegionRadius())
                {
                    return(false);
                }
            }
            else
            {
                Quaternion rotationInverse = Quaternion.Inverse(reverbProbe.transform.rotation);
                bounds.size = reverbProbe.GetScaledBoxApplicationRegionSize();
                if (!bounds.Contains(rotationInverse * relativePosition))
                {
                    return(false);
                }
            }

            // Then the visibility test.
            if (reverbProbe.onlyApplyWhenVisible)
            {
                if (ResonanceAudio.ComputeOcclusion(reverbProbe.transform) > 0.0f)
                {
                    return(false);
                }
            }
            return(true);
        }
        return(false);
    }