Time & Pulsating Lights

From Shader Forge Wiki
Jump to: navigation, search
Animation showing the graphing process of y = sin x (where x is the angle in radians) using a unit circle. The blue arc around the unit circle (in green) and the blue line at right have the same length, equal to the angle in radians.

Time

To modify a shader over time, we need to take some external input as a variable in to our calculation. One of the simplest forms of external input is Time.

The time node increments upwards as time increases. To make a pulsing effect we need a way of translating this increment over time in to a value that moves between 0 and 1 over time (for more information on how colour and maths relate to shaders please see Color Mathematics).

Converting from the external input of time to a fluctuating value can be achieved using the Sin Node. A quick refresher from Wikipedia on Sine is worthwhile if the previous sentence isn't obvious (See Wikipedia - Sine) - particularly the animation on this page.


Time to Sin

Key to this is that as the value of X is increased the value of Y moves between 1 to -1. To adjust the speed of this transition simply include a multiplication node to increase or decrease the input to the Sin node.

This is great, however, what we really need is the value to be between 0 and 1 (rather than -1 and 1). For the values to be translated into the required range we can use a remap node. As this is a straightforward range remap we can use the 'Remap (Simple)' node.


Lerp

For the colours to change between two values, we need to use a Lerp node. The Lerp node can use colours as inputs in much the same way that you would use Lerp for floats in your game. Putting the complete sequence together we get the following:

All together now