Course contentsShow
← Unity Game Development
Lesson 680 of 82810. VFX and Post-ProcessingFree lesson

Simulating Particle Collisions with Signed Distance Fields

Utilize Signed Distance Fields to create accurate, performant particle collisions against complex game world geometry and character meshes.

In this lesson, you will learn how to leverage Signed Distance Fields (SDFs) to achieve high-performance, pixel-perfect particle collisions against complex scene geometry.

The Problem with Physics Colliders

Traditional collision detection in the VFX Graph relies on Physics Colliders, which are computationally expensive for thousands of particles and often fail to handle concave meshes or complex character geometries smoothly. Instead of checking for physical intersections, we represent our scene as an SDF—a texture containing the distance from any point in space to the nearest surface.

How SDFs Power Collisions

An SDF stores a scalar value: zero represents the surface, negative values indicate being "inside" an object, and positive values indicate being "outside." To simulate a collision, we pass the particle's current position (in world or local space) into the SDF texture.

If the sampled distance value is less than the particle's radius, we know a collision has occurred. Because the SDF also provides the gradient of the distance field, we can calculate the surface normal at the point of impact. This allows us to reflect the particle’s velocity vector with simple vector math:

// Conceptual reflection logic for a collision node
float3 GetCollisionResponse(float3 velocity, float3 normal, float bounciness) {
    return reflect(velocity, normal) * bounciness;
}

Implementation in VFX Graph

In the VFX Graph, you utilize the Collision (SDF) node. You must first ensure your scene is baked into an SDF volume via the SDFBaker or by using the global distance field generated by the URP/HDRP renderer.

When a particle hits the surface, you retrieve the Distance value from the texture. By setting the Collision node to "Reflect," the GPU automatically uses the normal data derived from the SDF gradient to bounce the particle off the mesh. This is significantly faster than standard physics because it is a simple texture lookup in a single compute shader pass, allowing you to simulate tens of thousands of particles interacting with intricate character meshes without hitting the CPU bottleneck.

Key Takeaway: Signed Distance Fields transform collision detection into a high-speed texture sampling operation, enabling complex particle interactions that remain performant even with high-density meshes.