8
$\begingroup$

An easy way to get fire in your scene without simulating - no matter if it's for still images or animation - is using stock footage/photos of fire, often with a black background and just as JPG or PNG. And the background is okay, if you want to add it over a rendered image in the Compositor.

But for use in a material with the black background being transparent, a common way shown in tutorials is to mix the fire image plugged into an Emission shader with a Transparent BSDF, using the image as the mix factor either directly or plugged into a Color Ramp to have some control over the contrast etc. Adjusting the Strength on the Emission then helps brightening up the flames.

However, the result without boosting the strength looks quite flat compared to the original image and misses detail in the darker flame areas. Even with the help of a Color Ramp and increasing the Strength, it is not easy to bring back the darker parts without increasing the contrast and then maybe losing detail in the bright areas:

basic setup for transparent fire

So the question is: Is there a better setup to maintain all the brightness information of the image without losing the detail?

$\endgroup$
3
  • $\begingroup$ Do you see something special about 'fire stock images' or will the same techniques apply to any other flickering image, as for example, human hair or tree branches? $\endgroup$ Commented Apr 5, 2023 at 18:30
  • $\begingroup$ In that case why would you try this in Blender, rather than somewhere like Photoshop? $\endgroup$ Commented Apr 10, 2023 at 21:18
  • $\begingroup$ Hi, Gordon and @RobbieGoodwin .. this commentary seems to have got a little out of hand.. it's become more about itself than the question or answer. I've taken the liberty of removing those parts. If you still have have points to make on the central issues that can be stated clearly, independently of other comments, please go ahead. $\endgroup$
    – Robin Betts
    Commented Apr 13, 2023 at 8:36

1 Answer 1

17
$\begingroup$

The problem with the above setup is, using the image as mix factor directly or with the help of a Color Ramp converts the colored image into a greyscale image which gives a combined brightness value of the overall color, although separating the image with a Separate Color or Separate XYZ node you can see, the RGB channels might be very different in brightness like shown in the following comparison:

greyscale values

As to be expected with yellow/orange flames, the red channel has the most bright pixels overall, the green is still quite bright while the blue channel is mostly dark.

So the secret to keeping the brightness and detail of the original image lies in separating the channels and using them for Emission shaders with different colors and adding them to a transparent material.

To achieve this, you first of all need three Add Shader nodes. Plug a Transparent BSDF into the first Add Shader. The Image Texture will be plugged into a Separate Color node (or Separate XYZ, it does not matter since the RGB channels are a 3-dimensional vector as well).

Now you need three Emission nodes: the first one set to pure red (RGB: 1/0/0), the second to green (RGB: 0/1/0) and the third to blue (RGB: 0/0/1). In the Strength inputs you plug the Separate Color outputs of the according color channels: Red into the red Emission shader, Green into the green one and Blue into Strength of the blue Emission node of course.

Now plug the red Emission into the Add Shader with the Transparent BSDF already plugged in, the output of the addition into the next Add Shader together with the green Emission and that output in the third Add Shader together with the blue Emission. The order does not matter though, since addition is commutative.

Now the result without improving anything like e.g. boosting the brightness already looks a lot better than the basic transparency setup in the question, the colors are more vivid and there is more detail in the flames:

improved setup

For tweaking the look there are now different options, basically depending on what you want to do and which method you prefer. Just for a general increase of the emission strength overall like in the question you can use a Vector Math node set to Scale and plug it between the image and the Separate Color node:

scaling the strength

But if you are maybe not happy with the color of the flames, let's say they are to yellow and you want them a little more red, and maybe going towards white in the bright areas - in this case, instead of scaling the channels uniformly, you can set the Vector Math node to Multiply and use different factors per channel. So for a little more red than yellow, multiply red/X with a slightly higher value than green/Y. For making the bright areas turning more white, multiply blue/Z with a higher value than red and green:

tweaking colors

Another way to change the strength of the emission with also having control other the individual colors would be to not scale the image before separating the colors, but multiplying the separate channels after splitting them up with normal Math nodes set to Multiply after the Red, Green and Blue outputs.

If you want to increase the contrast you could either do this with a Bright/Contrast node plugged between image and Separate Color node or for each channel separately by using Math nodes set to Power. Plug the color channel into the Base input and set an Exponent. Exponents > 1 will increase contrast, values between 0 and 1 will decrease contrast.

exponential values

In the above example I scaled the strength before separating colors, however you have to keep one thing in mind: Let's say you want to increase the strength by 5 and do this with a Scale node. Then you want to increase the contrast by an exponent of 2 maybe, but: it makes a big difference if you first scale by a factor of 5 and then use the Power node on separate channels or if you do not scale before separation, then use the Power node and afterwards a Multiply node with a factor of 5. In the first case your maximum strength suddenly jumps to 25, in the second case you keep the maximum strength at 5 as it was before changing the contrast.

The mathematical reason is simple, in the first case the strength per channel $y$ is calculated as $$y=(5x)^2$$ and since $x\in[0,1]$ this results in $y\in[0,25]$, while the second case is calculated as $$y=5x^2 =5\cdot x^2$$ and so for the strength you get the range $y\in[0,5]$.

Here you see the first case:

scale and power

And this is the result of the second case:

power and multiply

$\endgroup$
2
  • 3
    $\begingroup$ Wow, we need more of these. Great answer, and the effect looks great too. $\endgroup$ Commented Mar 27, 2023 at 14:41
  • 3
    $\begingroup$ @DuarteFarrajotaRamos I can only agree! Gordon, keep it up, this is a great post! ...and shaders are apparently also more popular than Geometry Nodes :D $\endgroup$
    – quellenform
    Commented Mar 30, 2023 at 19:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .