|
I've seen the source code of the Lightning Procedural Example, as posted below, but I can't understand it well and was wondering if someone could explain how the Perlin code scrambles the beam and if there was a way to simulate lightning simpler than this as an alternative?
(comments are locked)
|
|
I can shed some light on how this script works, but I'm trying to look for a more effecient way of doing this myself. The beauty of the Perlin function is that it emulates patterns in nature, so it looks good when used with things like lightning. The down side is it's really slow. I'd appreciate anyone offering any alternatives they may have... Anyway - to the code...
/* *The start function simply makes the particle emitter put out as many particles as you *specify in the "zigs" variable. It also grabs the percentage each particle makes up of *the whole bolt, and saves a reference to each particle for use in the update function. */
/* * * * */
// loop through every particle, because we're manually setting every particle's position
// this line basically lines the particles up in a straight line between the beginning point and the end point of the lightning bolt
// now every particle is going to be offset by whatever value perlin returns // this is why perlin is so expensive, because it's getting called 3 times for each and every particle in your lightning bolt //each time it gets called, it's providing a number to offset this individual particle by, based on it's basic straight-line position, using the timex value in the mix to make sure it's not just a crazy random number, but that it makes a somewhat smooth line over time
// now the position gets updated from the straight-line position to the perlin position
// this just places lights at the start and end of the lightning bolt
Hope that helps. As I said, I'm looking for a more efficient method myself, so I'll let you know if I make any progress.
(comments are locked)
|
