Volume FX - Advanced Lightning Shader

By Adam Sale

The lightning effect is a versatile volume tool, that can be used to simulate many natural and man made effects. www.edharriss.com has an article that outlines the parameters of the tool, and how to get it up and running.

In this article we will utilize the knowledge from the latter mentioned tutorial and create a system to animate an electrified force field type of effect. I will also discuss other applications for the lightning shader. Download the sample scene by clicking here, or if you are using netview, drag and drop the link into any 3D viewport. The scene is ready for you to follow along with

The lightning shader uses a 3D volume to calculate the effect, so you'll want to create a bounding box for the lightning to operate within. The effect does not work with implicit objects, you'll need to use a real 3D object to contain the volume effect. A cube is a simple object that works well without consuming a lot of overhead. Scale it upso that it's larger than your entire scene and your camera fits inside of its volume.

The lightning shader can be applied in two ways:

Applying the volume shader

1) In an explorer, select the scene root, and then open up a render tree. Click 'update' to refresh the rendertree and display the scene material. From the nodes pull down, navigate to the volume folder, and choose the lightning node.

Make the connection between the scene material and the lightning node by clicking on the red output dot on the lightning shader and dragging towards the scene material node. As you do this, you'll pull a connection arrow out of the lightning node. When you've got your cursor over top of the scene material node, let go of your mouse button. A pop appears, allowing you to select an input that you wish to attach the lightning node to. The only option available to you is 'Volume'. Choose this option. The lightning shader is now hooked up to the scene root. Double click the lightning node to open its property editor.

You could also apply the shader in the following way:

2) Press your '3' hotkey to switch over to the Render module (F3 if you're using Soft3D hotkeys). XSI allows you to break your scene into passes, and comes equipped with numerous defaults such as specular, shadow, diffuse, and volumic. Passes save on valuable render time in production, and allow you to tweak each predefined level in post without affecting other passes. For example, I could render my volume shader in a pass separate from the rest of my scene. When I render out the two passes, I can make changes to the color of the volume effect, blurring, or changing the look of the effect completely. Chances are I'll only need to re-render the volume effect and won't have to re-render the rest of my scene, and waste valuable time.

Click on pass>edit>current pass (as there is currently only 1 pass in this tutorial) Start by giving the pass a name in the pop up that appears. You'll notice the pass property editor has 4 tabs near the top. Select the Volume shader tab by clicking on it once to reveal the volume shader stack.

Currently the stack is empty. Add the lightning shader to the stack by clicking the 'Add' button. XSI should then kick you into the softimage shader presets folder. My shader is located in the following directory:

C:\Softimage\XSI_1.5\Data\DSPresets\Shaders\Volume

Choose the Volume lightning shader, and then click OK.

In the lightning property editor, note that the volume_lightning shader has been applied to the shader stack. You are not limited to only one volume shader here. That's why it's called a 'stack'.

Define start and end points for the shader.

The lightning shader requires you to set two parameters before you'll see any results. It needs a starting position and an end position. To set this up, you'll need two scene objects. Any object will do. If you don't wish to see the objects at render time, you can simply disable their render visibility in the objects viewing properties.

You cannot use a null for your start end point objects.

To access the shaders parameters, highlight the shader in the volume stack, and then press inspect.

The volume stack is replaced with the lightning property editor. Set the start point by clicking on Add.

Select your starting object by choosing it from the pop up explorer. Click outside of the explorer when you're done. Select the ending point by clicking the Add button on the right. As before, choose your ending point object from the pop up explorer. Close the pop up by clicking anywhere outside of it.

Preview your work.

Press your 'Q' hotkey and drag a render region in your B viewport. Make sure it is set to your camera view. As with Ed's tutorial, you should see lightning.

Multiple lightning instances

Have you noticed how large the black boxes are in the area where you set your start and end points for the lightning shader.? You may have also noticed that the black box in the shader stack property editor is also quite large.

Did you know that you're not limited to one set of start and end points? The shader allows you to set as many as you'd like. All you need to do is tell the shader where the lightning should start and where it should end. You can create incredibly complex visual FX when you start to explore the possibilities.

You could have a single start point, and eight end points in a ring around the starting point, to create a spider web effect. As a matter of fact, you could create any sort of combination of start end points that you can imagine

In our example, we'll be making 4 different starting points and four different end points to create the illusion of electrified prison bars. We'll be doing this using a single volume shader in the stack. In the sample scene, you'll see 4 spheres on the left side of the doorway, and 4 spheres on the right side of the doorway. The spheres are appropriately named left_sphere 1 through 4 and right_sphere 1 through 4. In the Add the spheres on the left as starting points for the volume effect. Click the add button to the right of the starting point box. When selecting the objects in the pop up explorer, you can hold down your shift key and click on additional spheres to add them as multiple staring points. When you are done, repeat this process for the spheres on the right side of the door.

Preview your work using a render region.

There is one setback when adding numerous start and end points to a single shader in the Volume stack. Since the lightning spikes are essentially defined by the parameters of the single volume shader in the stack, a shader containing more than one set of start end points will yield lightning forks that all behave in the same manner.

The work around in this case, would be to add a second instance of the lightning shader to the volume stack, and then choose a set of start end point objects for the new copy of the shader. Adjusting the parameters of each shader to achieve your look will mean more work. You could however, simplify the property tweaking you'll have to perform in each shader by hooking up similar parameters from each shader to a custom parameter slider using the link with function.

When setting relative values for linked parameters you could have a custom parameter slider control the random seed of each shader, which introduces random behavior along the length of the lightning fork. When the custom parameter slider value is at 0, you could set it up so that each shader's seed value is set to a different value. When the custom parameter slider is dragged all the way up, the final seed values for each of the shaders would also be different here. The trick is to make sure that the relative values of each shader are different from each other at any given time.

Adjusting the look of the lightning system

The lightning default settings are nice, but hardly original. Let's refine the look of the animation a little more. Make sure you are inside the lightning property editor. The lightning at this stage is branching out in too many directions. The electric fence doesn't look convincing enough with the random forks of lightning branching off of the main spike. We can turn down the branching effect of the lightning shader by turning down the branching probability. Drag the value of this slider to 0, and look at the result in your render region.

You should be left with 4 spikes of electricity, a much cleaner, refined look. You can adjust the jaggedness of these spikes by clicking on the lightning shaders line segments tab, and adjusting the values for the shaders minimum and maximum line segment angle. I chose values of 16 min and 40 max. Do what feels right for yourself. The shaders jagged spikes are created by random lines, kind of like the step in a NURBS object. Setting Min and Max angles alter the orientation of each of these steps.

You can further enhance the look of your lightning spikes by adjusting the Min and Max Values for the line segment lengths. Higher values here, will create definitive straight line segments, giving your lightning a more linear, choppy look, while lowering your min, max values to around. .2 or less will create rounded spikes of energy. Again, use the analogy of the step value here. The lower min max values of around .2 would be like increasing the step count to 7 or 8 on a NURBS object. Increasing the min max line segment values would be the equivalent of lowering your NURBS step count to numbers like 2 or 1, creating more linear stepped type objects.

I chose to use the lower numbers around .2

Colors

I think the system is looking pretty good, lets adjust the overall color. I think I'll give the glow of the lighting a blue tint. Switch back to the lightning tab and adjust the glow color by dragging the RGB sliders in the glow section of the PPG. The higher you drag the slider values, the larger the glow width. You can offset the size of glow width, by altering the glow width sliders above.

My glow color was set at the following values: R: 0.020 G: 0.065 B:0.233

The glow width was set to 0.75

Click on the line segments tab once more to adjust the RGB attenuation values of the line itself. Think of this as controlling the amount of contrast or color mix between the line and the glow. Currently there is a considerable contrast, enough to make a clear distinction between line and glow. Hold down Ctrl and drag one of the RGB sliders to adjust the line / glow contrast. Lower values will yield a lower contrast while high RGB values upwards of .7 or higher will give a higher contrast. If you drag the RGB sliders individually, you will be able to create a nice color mix for your lightning spikes

Animating the effect

Drag your time slider back and forth and allow the render region to refresh. Notice how nothing happens. We haven't really animated anything yet. All we've done is set static parameters. As with the rest of XS, any parameter that has a green animation chip to the left of it can be animated, or controlled through linking or expressions. To put the finishing touches on this piece, we'll animate the seed of the lightning shader, as well as the glow color.

As mentioned before animating the seed will randomize the jaggedness of the lines, making it look like a lot of energy is passing from starting point to end point. Animating the glow width will make the effect feel like it is pulsing slightly, expanding and contracting, flickering if you will.

At this stage, you could simply set keys on these two parameters, changing their values over time and keying them at various frames. For the purposes of this article, we will use an expression to manually animate these parameters. The oscillation function should serve our needs nicely.

An oscillation function generates a sin wave function curve whose period and amplitude can vary over time. The period is the amount of time it takes between the peaks or troughs of a wave, while the amplitude is the height of the wave. From trough to peak. To make the oscillation function affect our seed and glow width properly without becoming too intense, we need to find a starting point value for each of these animatable parameters, and then determine how much standard deviation or offset the values need to have.
To start, right click on the seed green animation chip and choose the 'expression editor' option. The editor will pop up. Place your cursor in the white box. The Grey box tells you which parameter of the lightning you'll be affecting with this expression.
Assign the seed an oscillation function by choosing function>profiles>oscillation in the expression editors pull down menus at the top of the editor.

The following string will be inserted into the white text box: Ultimately, I want my seed to begin at a value of 100 and oscillate back and forth between a value of 40 and 160

oscil(<sf>, <ef>, <sp>, <ep>, <interp>, <sa>, <ea>, <interp>)

The following description for the Oscillation function was 'lifted' from the online docs

The Function > Profiles > Oscillation command in the expression editor inserts the token

oscil(<sf>, <ef>, <sp>, <ep>, <interp>, <sa>, <ea>, <interp>)

at the insertion point in the editing pane. This token generates a complex oscillating function. Replace the dummy arguments as follows:

<sf> Replace with an expression for the start frame of the oscillation. The value is 0 before this frame.

<ef> Replace with an expression for the end frame of the oscillation. The value is 0 after this frame.

<sp> Replace with an expression for the starting half-period (half-wavelength) of the oscillation in frames.

<ep> Replace with an expression for the first half-period of the final oscillation in frames.

<interp> Replace with LinearInterp for a linear interpolation between and, or with SplineInterp for a spline (curved) interpolation. You can use the Function > Constant submenu to insert these strings.

<sa> Replace with an expression for the starting amplitude (maximum height) of the oscillation in SOFTIMAGE units.

<ea> Replace with an expression for the end amplitude (maximum height) of the oscillation in SOFTIMAGE units.

<interp> Replace with LinearInterp for a linear interpolation between and, or with SplineInterp for a spline (curved) interpolation. You can use the Function > Constant submenu to insert these strings.

Example oscil(10,90,5,15,LinearInterp,1,20,SplineInterp)

Generates an oscillation that starts at frame 10 and ends at frame 90. The first half-period period lasts 5 frames and grows linearly with the second-to-last half-period lasting 15 frames. The amplitude is initially 1 SOFTIMAGE unit and grows with a spline interpolation to 20.

For our expression on the lightning seed, I entered the following string:

oscil(1,100,5,7,SplineInterp,40,60,SplineInterp) + 100

As mentioned before, I want my seed to begin at a value of 100 and oscillate back and forth between a value of 40 and 160. Since the oscillate function always assumes the default value of the expression is 0, I had to add 100 to the entire expression to offset the starting point of the oscillation function from 0 to 100.

When you are happy with the movement of your lightning, click on Validate, to make sure that you haven't missed any syntax, and if there are no error, click apply.

If you wish to look at the expression that the oscillation function generates on the lightning seed, click on view>show graph in the expression editors pull down menu. This is a handy tool hat helps you see what your animation will look like over time, rather than at a particular frame.

Repeat this same process for the lightning glow width. Use the same oscillation function to generate a random pulsing glow.

I used the following expression:

oscil( 1, 100, 10, 6, SplineInterp, 0.1, 0.15, SplineInterp ) + 0.7

As you can see, the lightning shader is good for creating more than just lightning. I've managed to create spider webs, wall crack texture maps, explosions, intricate electrical fields, science lab arc welders, heart monitors and much more. With a little experimentation, the possibilities are countless.

Advanced Lightning Shader was written by Adam Sale. Adam is a Technical Director at Joncrow Entertainment as well as a fully certified Softimage Instructor who teaches at various institutions throughout Vancouver, BC. He can be reached at adam@joncrow.com