3

I'm implementing a simple lightning effect for my 3D game, something like this:

http://www.krazydad.com/bestiary/bestiary_lightning.html

I'm using opengl ES 2.0. I'm pondering what the best looking and most performance efficient way to render this in a 3D environment is though, as the lines making up the electric bolt needs to be looking "solid" when viewed from any angle.

I was thinking to generate two planes for each line segment, in an X cross to create an effect of line thickness. Rendering by disabling depth buffer writes, using some kind off additive blending mode. Texturing each line segment using an electric looking texture with an alpha channel.

I'm a bit worried about the performance hit from generating the necessary triangle lists using this method though, as my game will potentially have a lot of lightning bolts generated at the same time. But as the length and thickness of the lightning bolts will vary a lot, I doubt it would look good to simply use an animated 3D object of an lightning bolt, stretched and pointing to the right location, which was my initial idea.

I was thinking of an alternative approach where I render the lightning bolts using 2D lines between projected end points in a post processing pass. That should work well since the perspective effect in my case is negligible, except then it would be tricky to have the lines appear behind occluding objects.

Any good ideas on the best approach here?

Edit: I found this white paper from nVidia:

http://developer.download.nvidia.com/SDK/10/direct3d/Source/Lightning/doc/lightning_doc.pdf

Which uses an approach with having billboards for each line segment, then apply some filtering to smooth the resulting gaps and overlaps from each billboard.

Seems to yield pretty good visual results, however I am not too happy about the additional filtering pass as the game is for mobile phones where such a step is quite costly. And, as it turns out, billboarding is quite CPU expensive too, due to the additional matrix calculation overhead, which is slow on mobile devices.

sinsro
  • 905
  • 7
  • 25
  • Why are you creating this in 3D? The bolts should be bright enough that you could get away with a 2D plane that constantly faces the viewer but is restricted to rotate about the two points. – Blender Dec 27 '11 at 03:47
  • Then the bolts would need to be stretched depending on the distance, which is not visually optimal since the distance can vary quite a lot in my case. This problem is the same in "3D" though, which is why I am considering building a custom triangle list for each lightning bolt. – sinsro Dec 27 '11 at 04:39

2 Answers2

2

I ended up doing something like the nVidia paper suggested, but to prevent the need for a postprocessing step I used different kind of textures for different kind of branching angles, to avoid gaps and overlaps of the segment corners, which turned out quite well. And to avoid the expensive billboard matrix calculation I instead drew the line segments using a more 2D approach, but calculating the depth value manually for each vertex in the segments. This yields both acceptable performance and visuals.

sinsro
  • 905
  • 7
  • 25
0

An animated texture, possibly powered by a shader, is likely the fastest way to handle this.

Any geometry generation and rendering will limit the quality of the effect, and may take significantly more CPU time, memory bandwidth and draw calls.

Using a single animated texture on a quad, or a shader creating procedural lightning, will give constant speed and make the effect much simpler to implement. For that, this question may be of interest.

Community
  • 1
  • 1
ssube
  • 47,010
  • 7
  • 103
  • 140
  • As mentioned in the comment above, static animated textures would need to be stretched, which would not be visually pleasing. This is why I am looking into generating a triangle list customized for each bolt, depending on its distance to the target. This appears to be how they did it in Skyrim when you fire off a lightning bolt, and looks pretty much how I want to. As for a shader approach, which I assume you think should be applied to a billboarded plane, is probably a good idea, but implementing it well to make it look realistic at all angles and distances is truly not a trivial task. – sinsro Dec 27 '11 at 04:55