Visual Effect Breakdown – Lasers
Lasers are an important part of our game, so since they’ve got a big visual overhaul, I thought it’d be interesting to break it down and see how all the elements work together.
This week has been a bit of an ‘everything’ week where I’ve been fixing all sorts of miscellaneous bugs and minor improvements across the whole of the core of the game. In particular handling some of the tricker edge cases for portalling when the player has eyes either side of a portal and looks through a series of other portals at the same time. More interestingly I’ve also been working on our new laser visuals and making them feel exciting and dangerous.
Lasers go all the way back to the Hatton Garden Heist, where they were just simple (barely) textured cylinders. They didn’t even move or damage you, they were really just to make things a bit more colourful.
Lasers in Hatton Garden Heist – not our most visually impressive work
Unseen Diplomacy 1 lasers – more threatening but not visually dangerous
New UD2 laser effect – feel them crackle and avoid getting yourself burnt!
Breaking it down the new laser is a mix of layered geometry, custom shaders and particle systems. The core is a tube of geometry with a laser shader to get the right kind of soft fade on the edges but still keep a strong core of light in the center. Separate scorch and burn decals are spawned at the collision, aligned with the collision surface to provide an impact cue.
An important bit of polish is a trick we’ve lifted from Smash Hit Plunder – the shader will fade the laser out over a few centimeters close to the camera, so you don’t get an ugly line clipping through your view when you stick your head in it, again another thing that tends to break immersion. It’s technically more efficient to do this in clip-space, but here I calculate it in world space so that the input values (as seen in the inspector) are all in world units, which is much easier to make them super accurate to how we want it to behave. Want to implement it in your own VR game? Steal this shader code:
float CalcCameraFade(float3 worldPos)
{
// Depth offset pushes the fade away from the camera (so we can push it past the near plane)
// Depth scale affects the overall range of the fade (but still a linear fade)
// Do the calculations in world space so shader inputs are in world units
float dist = length(worldPos - _WorldSpaceCameraPos);
float normDist = (dist - _DepthOffset) / _DepthScale;
return saturate(normDist);
}
Sparks use unity’s particle system in full physics-collision mode. This is expensive compared to normal particles but the numbers are low and this means they’ll bounce off actual geometry and feel reactive. A good trick is to split this particle system in two and have a fully simulated one with low particle count, and a cheaper one with non-simulated particles as filler. However I haven’t done this here as too many spark particles became distracting and overpowered the whole effect.
Smoke is another particle system, this time using a soft-particle shader. Soft particles are great for particles that will probably clip through nearby surfaces – this can look ugly in a flat game but it’s even worse in vr.
This requires a depth pass to be rendered before normal rendering, so it has some overhead, but we’ll be sharing it between lots of effects so it’s an important step we have to optimise for.
Finally some dust motes spawned along the actual laser beam provide a subtle trail. Here the laser component has to update the emission shape (a line emitter) in realtime so the particles spawn in the correct place as the laser moves.
Put it all together and you get this:
We’re still figuring out what new environmental hazards we want you to be avoiding in UD2 – pop into our Discord and let us know what you want to dodge and sneak your way past!