2
$\begingroup$

I need to do a fog that's dense at the bottom and gradually disappears to the top of the box. I adjusted a gradient texture with mapping, but is there a more straighforward way?

$\endgroup$
4
  • $\begingroup$ for me that is straight forward ;) i would have done it the same way $\endgroup$
    – Chris
    Jul 9, 2021 at 7:46
  • $\begingroup$ you can also use the Converter > Separate XYZ and its Z output socket $\endgroup$
    – moonboots
    Jul 9, 2021 at 7:53
  • $\begingroup$ Does the Z output go from 0 to 1 relative to the bottom and top of the mesh? $\endgroup$ Jul 9, 2021 at 8:01
  • $\begingroup$ @francoisgibon it does in generated texture coordinate. $\endgroup$ Jul 9, 2021 at 8:42

1 Answer 1

4
$\begingroup$

As moonbots pointed out, you can use Z coordinate to get a gradient. You can also raise it to some power for nonlinear falloff (normalized 0..1 range raised to some power is still normalized, which is pleasant), then multiply to change the maximum value:

$\endgroup$
6
  • 1
    $\begingroup$ This question has made me curious. I wonder whether there's a way of combining some kind of World Z pass with a Mist pass to approximate this in compositing, without using volumetrics? Somebody must have done this. $\endgroup$
    – Robin Betts
    Jul 9, 2021 at 9:06
  • 2
    $\begingroup$ @RobinBetts You can do a worldpos AOC, but there are a number of reasons why a mist pass is not going to give the same results as renderered fog (volumetric lighting, variable density, scattering, many more.) You can get the integral of a very simple height-based mist pass function, which is even better than volumetric sampling, at least for raw, rasterizer absorption, but it's easy to get mist functions that can only be sampled iteratively; it's possible to sample in composting, but tedious and slow and not what compositing is good at. $\endgroup$
    – Nathan
    Jul 9, 2021 at 12:54
  • $\begingroup$ Thank you @Nathan! I think that nails it. My comment should have been a question :) $\endgroup$
    – Robin Betts
    Jul 9, 2021 at 12:58
  • $\begingroup$ How do you change where the volume begins? By default, this starts at the top, I want it to start from the bottom up. $\endgroup$
    – no_name
    Dec 17, 2022 at 17:28
  • $\begingroup$ @no_name you can use Map Range node to map from 0..1 to 1..0 for example. Or use a color ramp, or just do Math: subtract: $1-x$. $\endgroup$ Dec 18, 2022 at 9:54

You must log in to answer this question.

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