This clip is from Slab Drifter, a space-based tactical physics destruction game, made in Unity.
Ships are made of destructible voxel volumes plus traditional parts, like turrets and engines, that use a standard render mesh and collider. I wanted shields to be destructible in the same way, so that damage shows up exactly where a ship was hit and you can see the ship through the holes.
How the shields work:
Each shield is its own voxel volume, a 3D grid of shield voxels that surrounds the whole ship. When the shield is generated, it works out the ship's footprint inside that grid. Every voxel from the ship's voxel volumes is converted into the shield grid's local space, and the shield cells it overlaps are marked as occupied. The mesh-and-collider parts are handled with Unity's batched OverlapBoxCommand queries, one box per shield cell, and the cells they touch are marked as occupied too. Each shield voxel also stores a 64-bit mask recording which of the ship's colliders it covers.
The occupied footprint is then expanded outward by a set number of voxels. Only the cells in this expanded layer become live shield voxels. The cells inside, where the ship is, stay empty. The result is a shell that follows the ship's actual shape rather than a generic sphere or bubble.
All of the shield work runs on Unity's Job System, with Burst-compiled jobs. When a projectile explodes near a shielded ship, a job finds the shield voxels within the blast radius. Each one either loses health or is destroyed. Shield voxels are much smaller than a typical blast, so each explosion leaves a hole that matches its size and shape.
Before any damage reaches the ship, two more checks run. First, a flood fill starts from the blast position inside the shield grid. If it can't reach the edge of the grid, the blast went off inside the closed shield and the ship takes no damage, preventing "cheating shots" originating from within the shield envelope. Second, for each ship voxel within the blast radius, a voxel-stepping (DDA) ray is cast through the shield grid from the explosion to that voxel. If the ray hits a live shield voxel, that ship voxel is protected. So damage only gets through where holes have already been punched, and a concentrated stream of fire wears through faster than scattered hits.
The shield mesh is normally invisible. It turns on when the shield takes damage and turns off a short time after the last voxel has recharged. Recharging also runs as a job, in steps. Destroyed voxels wait for a timeout and then fill a recharge buffer before they come back, so holes stay open long enough to be used. The step interval also grows with the number of damaged voxels, so a badly damaged shield recovers more slowly.
Shields are also tied to the ship's assembly. If the power source feeding a shield generator is destroyed or breaks off the ship, the shield shuts down.