Vixen
02b45cc4
csharp
public sealed class PhysicsOcclusionProvider

Answers the mixer's occlusion question by casting rays at the level.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

The layer mask is the whole feature. A raycast against everything solid finds the chain-link fence, the handrail and the crate the player is standing behind, and muffles a conversation happening through a doorway because a lamp post is nominally in the way. Occlusion belongs on the geometry a level designer decided blocks sound — usually the same layer as the walls and nothing else — and Layers is where that is said. Leaving it at everything is the setting most likely to make this sound wrong.

It is also the answer to a sound occluding itself. An engine emitter sits inside the vehicle's collider, so a ray cast at it hits the vehicle and reports the sound as blocked by the thing making it. Nothing here can fix that on its own — this is handed two points and knows nothing about which body either belongs to — so the fix is to put occluding geometry on its own layer and leave dynamic bodies off it, which is what a level wants anyway.

Several rays, because one is a coin toss. A single centre-to-centre cast makes occlusion binary and makes it flicker: a source a few centimetres to one side of a door frame is either fully blocked or fully clear, and walking past the opening switches between them. Casting to a few offsets around the source and counting how many got through gives partial values — a doorway reads about half — which is what AudioOcclusion's smoothing then has something useful to smooth.

The offsets are on a fixed cross and not random. Random offsets would make the answer differ between two frames that ought to agree, which is jitter dressed up as detail; and between two machines, which is worse for anything recorded or replayed. A fixed pattern is reproducible, and the smoothing takes care of the rest.

Called on the game thread, a handful of times a frame. AudioOcclusion rations how many voices are asked about, so the real cost is Rays × its budget — five by eight is forty casts a frame, which is nothing.

Fields and properties (5)

  • public const int MaxRays

    The most rays one query may cast.

  • public PhysicsLayerMask Layers

    Which layers block sound.

  • public int Rays

    How many rays are cast per query, from 1 to MaxRays.

  • public float Spread

    How wide the ray fan is around the source, in world units.

  • public long Casts

    How many rays have been cast, for a profiler.

Methods (2)

  • public PhysicsOcclusionProvider(PhysicsWorld world)

    A provider over a physics world.

  • public float Occlusion(in Vector3 source, in Vector3 listener)

    How blocked the path is.

Used by (1)

  • PhysicsOcclusionTestsVixen.Audio.Physics.Tests