Unity 3-SliceLine Glow, Volumetric Lines

Hi, my first post on forum (: Made script, that generate geometry to render line-glowing, billboarded to camera. Center segment is from 1 pixel, so texture can be any simple particle. Same technic was used in KOTOR to render lightsabers. Script pretty optimized, no batching, but as is - pretty fast. No postprocessing and no custom shaders. That allow use any shader you want

here is demo built for android and web


That’s pretty cool! Do you mind sharing a breakdown?


2 Textures used:

Effect consist of 3 parts:

Script uses sub-transform for Renderer, to simpify billboarding math.
Everything in mesh (uvs, triangle Indexes) stays not changed, except vertices.
Mesh.colors used to recolor glow same way, as particles.

Default shader is Two-Sided and not use lighting, that allow skip normal calculation.

Caching not changing mesh-arrays in static reduce memory footprint of multiply effects, and reduce lag on Instantiate.
Cached uvs and triangles:

Vertices calculation steps:

  • ‘FacingRotation’ Rotate renderer transform same, as projected line would be, with up, facing same as perpendicular to camera.forward and our line
  • ‘UpdateValues’ Calculates _start and _end points, in plane, facing camera, depth is get from transform.position, uses Camera.WorldToScreenPoint and Camera.ScreenToWorldPoint.
  • ‘UpdateVertecies’ calculates two vectors, halfUp and halfRight, representing aligned to our Line and _start to _end line, representing directions, to move vertices, using ‘_width * 0.5’ as length. And apply this offsets to vertices. Math abuses caching, to reduce Vector3-operations, even some final vertex-values used as variables. array is cached, with fixed size of course.
  • ‘UpdateMesh’ just assign vertices array

Awesome! Thanks for sharing : )

This is a great old-school effect.

Though I should point out the effect is already available as an asset for Unity for free on GitHub and on the Unity Asset store:

That does use custom shaders rather than purely script based. Script based is useful for OpenGLES 2.0 projects, but after than the shader based approach is significantly preferred for performance reasons. It also more correctly handles z depth which your approach does not appear to do which will cause problems when trying to put your effect into a 3D scene. That alone makes it a non-starter for me if I was someone who was looking at using the asset for anything.

There is a similar effect that I’ve not seen as a Unity asset anywhere though. Having both your lines (with it properly projecting back in 3d space) and this glow effect might make it a more interesting asset. Or if you’re just looking for something else fun to implement.

In the past I’ve spent time trying to do this in a purely shader based approach, and I got close, but I never found a clean way to handle the corners I was happy with, so a script based approach is still useful.


Hello thanks for answer!

  • Yea, later I’ve found Volumetric Lines too
  • Shader obviosly faster, by when I submitted asset, i haven’t check out Volumetric Lines, and it’s part of my asset-philosophy - allow user to choose shader
  • Yes, there is problem with depth, will try fix it soon
  • Doom 3 volumetric glow is looks awesome, will try replicate it

Good luck!

Correction of z depth problem the way it done with VolumetricLines create problem, when you look along line with perspective camera. That leads to unacceptable popping when line rotates.
Left is my script, right is VolumetricLines.


Because Volumetric Lines doesn’t really do it quite right either. As you get close to viewing it edge on you want to smoothly bring the further away end up to the closer end. At what point you do that is somewhat arbitrary, and when it looks best to do so depends on the texture being used.

I wish I could find the paper where I first saw the technique you’re doing written about, because it had a bunch of tricks like this in it, plus a final example that just straight up raytraced a volumetric pill shape to get it perfect.

1 Like

Had in-house solution on volumeLines by collapsing length but cost complexity. Nice accomplishment on your end

I’ve fixed zdepth by way, that you described, check ti out!

3 - slice line , fixed zdepth
1 Like

Tron, Volumetric Lines, and Meshless Tubes” by Philip Rideout discusses similar methods. I wonder if that’s what you’re thinking of?

That wasn’t it, but the article it linked to at the beginning was!

1 Like