David Grzesik

Visual Effects Artist

David Grzesik

Car Commercial – 4 – Lightning Solver

I wrote this cool little solver for creating prims with some awesome attributes such as varying animation length. Realistically though, any other attributes that can be varied and are varied down the tree when making the lightning can be set here specifically for a seemingly endless combination of attributes and parameters.

The main idea for how we will use this lightning system is surrounding the base of the car connecting to the surrounding ground. My initial idea was to use the nearpoints function in Houdini to compare scattered points from the car to the surrounding car. This idea definitely works, however its extremely erratic as it connects to the nearest point every single frame, so there it very little consistency, especially with moving points. Instead a much more complicated technique would have to be implemented.

I tend to write a lot of notes and psuedo code in my notebook as I develop my ideas, I find its so much easier to put the code in more loose terms to block in what exactly I’m trying to accomplish. It’s great because it makes the code much easier to figure out and it lays the groundwork, I”l constantly come back to it while I’m actually coding and the majority of ideas are eventually implemented.

The main idea of my Solver comes from the first set of notes, an initial set of connections and attributes are provided, this is then compared to the start points (sourced from the car) and the position of the start points is updated to follow, and then compared to the end points (sourced from the ground) to determine connections between points and if the connections need to be remade or not. This was quite a bit of work and took a ton of time to figure out but it was a ton of fun. Check out the code here.

This first loop iterates based on the total amount of points being inputted. Initialize_Conditions sets some base attributes and initializes connections. Each start point gets a certain amount of points around it and randomly selects one of them. A random life is then set for each prim so that they aren’t all synced up with one another. The code can be seen in more detail here.

Inside of the solver took me a while to figure out. We loop the previous frame to get the past info and update the position of the start points. Set_Anim_And_Reset_Connection is where all the magic happens. Basically it checks the age of each prim, if that age is too high then it re-initializes its connection and resets its age and some other attributes. In this wrangle we get a slider for the animation length. We can slide this to how ever many frames we want the prim to be animated along before re-initializing. If the age is somewhere int he middle make sure the animControl is 1 so that the bolt actually makes a full and direct connection, otherwise reference a custom sin function that maps its intermediate ranges correctly.

Sounds somewhat straight forward.

It wasn’t nearly so.

The biggest problem was how I would organize this data. When a prim gets reinitialized a point and prim are deleted and new ones are made in their place. In doing so their point and prim values are changed. Id attributes were the only way to solve this and structuring my code to function with this style of organization was an interesting task that I have never tried before. I highly suggest checking out the code for it, I think its really cool and there are some awesome functions implemented that are going to be incredibly useful in systems in the future.

There are so many parameters that are waiting to be procedurally varied for more crazy and interesting effects, cant wait to make it even better!

The next on my to do list is possibly some pyro sims in tandem with the lightning effects and moving the points on the car so that they glide across the surface of the car a bit rather than staying completely static.

Leave a Reply

Your email address will not be published. Required fields are marked *