6
$\begingroup$

I need to create a scene with fog, i.e. distant elements faded out towards gray. I can't afford volumetric fog, because the renders would be way too slow. I'd like to just use a simple camera-to-object distance shader to interp the color toward mid-gray. I know that's not physically accurate but I think it'll be good enough for my needs.

I've seen how to do it with a depth pass and use that in the compositor, but I'm wondering if it can be done with a "global shader" right in the renderer? I'm using Cycles in Blender 2.93, recent nightly.

$\endgroup$
3
  • $\begingroup$ Does this answer your question? How to make fog in Blender $\endgroup$ Mar 30, 2021 at 19:25
  • $\begingroup$ That shows how to do it in the compositor, as I mentioned. Maybe that's the only way? $\endgroup$
    – GaryO
    Mar 30, 2021 at 21:17
  • $\begingroup$ You may want to try branched path tracing method in Cycles. Simply set the render samples to a lower value for volumetrics, and whatever you want for the others. $\endgroup$ Mar 31, 2021 at 0:08

2 Answers 2

6
$\begingroup$

You can use Ray Length (as suggested by @PGmath) to mix in a 'Fog Shader'.

  1. Use Light Path > Ray Length and Math > Divide to control the spread
  2. Use the result to mix your object's material with a 'Fog Shader'
  3. Add a background plane with the same 'Fog Shader' (so they nicely blend together)

For the 'Fog Shader' set Specular = 0 (to have zero reflectivity)

enter image description here

enter image description here

$\endgroup$
4
  • 2
    $\begingroup$ Since you'd have to apply this shader to all meterials creating a node group out of that might be nice. $\endgroup$
    – brockmann
    Mar 31, 2021 at 10:50
  • $\begingroup$ Yes, a bit of a pain to add this to all materials (I guess there's no shader that runs on everything, that's what compositing is for) but this is what I was looking for. Thanks! $\endgroup$
    – GaryO
    Mar 31, 2021 at 13:27
  • 1
    $\begingroup$ Note that this will look a little bit weird in reflections. The ray length should really be what gets used instead of distance to the camera. $\endgroup$
    – PGmath
    Mar 31, 2021 at 13:28
  • $\begingroup$ @PGmath Thanks, that does indeed work better and is also more flexible :). I'll edit it into the answer. $\endgroup$ Mar 31, 2021 at 14:03
0
$\begingroup$

Not sure if this is what you need but you could add the mist pass and then in rendered view in the viewport you could switch the view to mist rather than combined.

$\endgroup$
1
  • 1
    $\begingroup$ Sure, you can add the mist pass and then mix to a constant color in the compositor. I'm asking if there's a way to do it with a shader during rendering. $\endgroup$
    – GaryO
    Mar 30, 2021 at 21:17

You must log in to answer this question.

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