Animated Candle Flame write-up

If you haven't yet watched the video detailing the creation of this shader, you can view it here: Animated Candle Flame Shader in Unity.

To have control over the colours of the candle flame, we split a texture up into separate RGBA channels, using Channel Mixer Adjustment layers in Photoshop. This is a great way to pack a lot into a single texture and it's a technique we'll be using for lots of different effects.

Each Channel Mixer needs to have its unwanted colours set to zero, so for the Red channel, go to the Output Channel dropdown, and in turn make sure that the Blue and Green contributions are set to zero, while leaving the Red output set to 100%. Having a Channel Mixer at the top of each group, and making sure that the groups Blending Mode is set to Screen, will mean that anything painted inside that group will only ever contribute to that channel.

We only really need 3 channels to pull off the colour variation in a flame. Perhaps even 2 channels would be enough for this effect. But since we have 4, we might as well use them. I like to pop a circular gradient in the alpha whenever I'm splitting up a texture and have a spare channel. It can always come in handy to mask any movement and stop it clipping at the edge of the quad.

Back in Unity and Amplify Shader Editor, we use those separate channels as masks to multiply against adjustable colours, which we can then add back together. Multiplying this by a brightness modifier will let the bloom kick in on any post process image effects we have on the camera. Or if you want to do your glow directly in the shader, you can use the circular gradient from the alpha channel. Or both!

To make the flame flicker, we can add a panning noise to the UVs of the flame texture. You want to lower this effect nearer to the bottom of the flame, such as by multiplying it by the V channel of the UVs, you could also use vertex colours or a spare RGBA channel if you wanted, but using the UVs is by far the easiest. You'll also want to add the world position, scaled appropriately, to the noise offset, just to add some variation between flames using the same shader.

For a more optimised shader, it would be better to use a simple pre-painted flame texture and forgo the ability to adjust the colours. The SSS shader on the candle itself can also be massively optimised if you want to use this in a game with many candles that are only seen at a distance - it would be preferable to not actually use a point light and Subsurface Scattering at all, and simply bake the light into the candle via a texture, vertex colours, or UV coordinates.