top of page

Waveforms in Shaders

The Pulsing Shader

 

The most simple application of the sine wave in a shader is to make a shader which pulses colour. It could pulse from black to coloured, or from coloured to emitting it's colour as light. All depending on the values you use.
If we plug the basic sine node setup directly into the emissive slot of a shader, we will get a shader which looks like it pulses white. What we don't see there (but we CAN see in the graph from earlier) is that the value we are sending to our emissive slot is actually going all the way down to -1, not just from 0 to 1. This isn't generally a good thing when you're combining the sine wave with colour because (if you're using a 'multiply' node) when the sine goes to -1 it will invert your colours.
In order to change what value we get out of this, we attach a few extra nodes to modify things. This first node we attach is a multiply node. This will simply be scaling the outputs of our sine node up or down. If you imagine the curve from before, the multiply node will be stretching/squashing the curve in the vertical direction. To start with we will multiply by 0.5.
Next we attach an add node. The add node will simply add a value to every single output. Again imagining the curve from before, the add node just shifts the whole curve up (or down). We will add 0.5.

We can multiply this by a texture and it will pulse the texture in and out. If you want the texture to show, but for it to pulse into emitting light then all you need to do is increase the number in your add node to be the number in your multiply node plus 1. This system shown below is using   mult = 1,   add = 2:

This is a basic 0 to 1 pulse setup.

Also, numerically, this wave is expressed as:     y = sin(t) + 2

This is the curve:

You can see that it never falls below 1. Multiplying your texture by 1 does nothing to it so that's why that is the baseline if you want it to pulse in and out. You can play with the values in your multiply and add nodes to try to achieve whichever simple pulse effect you like.

This is what the standard pulse setup from above looks like in real-time.

bottom of page