ValveSoftware / steam-audio

Steam Audio
https://valvesoftware.github.io/steam-audio/
Apache License 2.0
2.2k stars 152 forks source link

Curve driven reflection attenuation incorrect for logarithmic fall off #343

Closed Roceh closed 2 months ago

Roceh commented 2 months ago

System Information

Issue Description Incorrect falloff for realtime reflections for SteamAudioSource when using curve logarithmic falloff

Steps To Reproduce Steps to reproduce the behavior:

  1. Add audio source with logarithmic fall off
  2. Add steam audio source with Curve driven attenuation, enable Reflections & enable Use Distance Curve For Reflections.
  3. Odd behaviour of audio reflections in scene, especially near end bounds of audio fall off (you briefly hear the reflection audio increase in volume as you cross the bounds)

The cause I believe is that the EvaluateDistanceCurve has the follwing code for Logarithmic curve

                  case AudioRolloffMode.Logarithmic:
                    if (distance < rMin)
                        return 1.0f;
                    else if (distance < rMax)
                        return 0.0f;
                    else
                        return rMin / distance;

I think at the very least it should be like the linear mapping maybe?

                  case AudioRolloffMode.Logarithmic:
                    if (distance < rMin)
                        return 1.0f;
                    else if (distance > rMax)
                        return 0.0f;
                    else
                        return (rMax - distance) / (rMax - rMin);

or perhaps mapping the actual log curve.

The linear and custom falloff seems ok.

Roceh commented 2 months ago

I do note that both the linear and the custom curves with realtime reflections (and logarithimic if you apply the above change) are MUCH louder (i assume as the full reflections lengths are being taken into account unlike the values below rMin) so much so that I have to reduce the recflection mix to 0.1 otherwise i get distortion.

The amount of distortion is proportional to the number of bounces set in the steam audio settings.

The generated reflection audio can also be heard beyond the max fall off point, which given its bounced its way to the audiolistener does not make sense as the total bounced path should be longer than direct line and therefore no reflected sound should be generated (with Use Distance Curve For Reflections).

My suspicion is that each calculated bounce is adding to the generated reflection audio rather than the total length of the bounced path.