Ambient Gain Formula
This function converts raytracing energy values to ambient gain values.
The AmbientGainFormula is invoked twice per emitter:
- Once with low-frequency energy values
- Once with high-frequency energy values
The default formula specifies that 10% of occlusion energy, or 10% of permeation energy is required for ambient sounds to be at max volume:
emitter.AmbientGainFormula = (
bool lowFrequency,
int occlusionRayCount,
int permeationRayCount,
int permeationBounceCount,
float occlusionEnergy,
float permeationEnergy)
{
float gain = 0.0f;
if (occlusionRayCount > 0)
{
// 10% energy required to be at max volume
float rayThreshold = 0.1f * occlusionRayCount;
gain += occlusionEnergy / rayThreshold;
}
if (permeationRayCount > 0 && permeationBounceCount > 0)
{
// 10% energy required to be at max volume
float rayThreshold = 0.1f * (permeationRayCount * permeationBounceCount);
gain += permeationEnergy / rayThreshold;
}
return MathF.Min(1, gain);
}
Parameters:
lowFrequency- indicates whetherAmbientGainFormulais invoked with low-frequency energy values or high-frequency energy values (AmbientGainFormulais invoked twice)occlusionRayCountis the number of occlusion rays that were cast by the source emitterpermeationRayCountis the number of permeation rays that were cast by the source emitterpermeationBounceCountis the number of bounces per permeation rayocclusionEnergyis in the range 0.0 to 1.0, where 1.0 means all occlusion rays reached the world edge with maximum energy remaining (i.e. no occlusion)permeationEnergyis in the range 0.0 to 1.0, where 1.0 means all permeation rays reached the world edge with maximum energy remaining (i.e. all rays passed through air)
The results of these functions are stored on the emitter.AmbientFilter object, which is null until raytracing has completed for the first time:
if (emitter.AmbientFilter != null)
{
var gainLF = emitter.AmbientFilter.GainLF;
var gainHF = emitter.AmbientFilter.GainHF;
}