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
Thatβs pretty cool! Do you mind sharing a breakdown?
Sure.
Overview
2 Textures used:
Effect consist of 3 parts:
- simple LineRenderer for tracer using 1 texture
- glow horizontal line, using 2 texture
- 3-Slice Line glow, using 2 texture
https://imgur.com/gallery/1tNeD01
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.
https://simonschreibt.de/gat/doom-3-volumetric-glow/
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.
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
β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!