top of page
13 RONIN banner

There will be lightning!

When scanning the net for examples on different weather effects I came across an amazing tutorial written by Michael Hoffman on how to make realistic looking light effects. This inspired me to write a very similar lightning engine.

The main difference between the solutions is that Michael's uses a pre-drawn image rendering the lightning bolts while mine uses the line strip drawing primitive. Michael's lightnings are more realistic looking than mine but since I'm going for more of a pixel-art looking aesthetic the line strip is a better choice for me.

Example of a lightning branch.

Lightning branch

I began creating a single lightning bolt and then added feature after feature until I had a full blown lightning engine sending randomized bolts and branches through the sky. As with the rain engine this engine also has a lot of settings, some of these are:

  • Lightning length

  • Lightning angle

  • Interval between lightning strikes

  • Lightning duration

  • Animation

  • Fade

  • Min and max number of branches

This was quite fun to code and I'm quite pleased with the result. Things left to add is sound for thunder and maybe a flashing background.

Check out my lightning strikes at YouTube and why not download the source code from by BitBucket account.

Working with the lightning engine I also spent a few hours tinkering with HLSL and including shaders. It was really interesting and fun, but for now it will be a type of coding I will save for the polishing phase.

For anyone getting started with MonoGame and HSLS I highly recommend the article My First Pixel Shader(s).

I'd be very happy for recommendations on other good HSLS pages.

Happy coding!



bottom of page