Atmosphere Replaced

Dealing with the change...


So POV-Ray 3.1 is out, and it offers many new features over 3.02. The one thing that it seems more people are having trouble with is media. It doesn't behave like halos and is even more mysterious to learn. Let's go back a little and try to make sense of it by adapting an old lesson on atmosphere:

#include "colors.inc"

 camera {
 location <-10, 8, -19>
 look_at <0, 5, 0>
 angle 75
}
background { color rgb <0.2, 0.4, 0.8> }


light_source { <0, 19, 0> color rgb 0.5 media_interaction off }


light_source {
<40, 25, 0> color rgb <1, 1, 1>
spotlight
point_at <0, 5, 0>
radius 20
falloff 20
media_attenuation on
}


union {
difference {
box { <-21, -1, -21>, <21, 21, 21> }
box { <-20, 0, -20>, <20, 20, 20> }
box { <19.9, 5, -3>, <21.1, 15, 3> }
}
box { <20, 5, -0.25>, <21, 15, 0.25> }
box { <20, 9.775, -3>, <21, 10.25, 3> }
pigment { color red 1 green 1 blue 1 }
finish { ambient 0.2 diffuse 0.5 }
} 

That's pretty much the atmosphere scene from the POV-Ray 3.02 docs with two exceptions:

1)The atmosphere keyword has been replaced with media_interaction. This turns light with scattering media on or off.

2)Atmospheric_attenuation has been replaced by media_interaction. This controls whether or not the light is diminished as it passes through the media.

OK, here's the scene:

The empty room...ooooh


Now let's try some media similiar to the atmosphere in the docs:

media {

scattering {1, .2 extinction 1}

samples 5, 10
intervals 3
confidence .999
variance 1/2
}

I'm not even going to bother with showing a picture of this, since the room is completely black! Clearly this is no good. The problem is in the extinction value. If the scattering is lowered to .02, then we are able to see the room, but the light beam isn't bright enough. This can be overcome by increasing the lightsource brightness by a factor of ten, such as rgb 10*<1, 1, 1>:

This seems like a reasonable fix, but that light is a little too bright on the floor. Back to extinction...the new docs tell us that it controls how the light is attenuated as the scattering is increased. The higher the extinction, the greater the attenuation, so let's lower the value to .1 from 1. Change the spotlight back to rgb <1, 1, 1> and the scattering back to .2 as we'll, as it seems that it was the extinction messing things up:

Now it looks like atmosphere. So one question remains...in the new docs it says that the default extinction of 1 is the accurate model of light attenuation, yet we had to reduce it to .1 to get the same effect of atmosphere. Personally I think someone misplaced a decimal point. I don't know which version it right, but at least we learned how to deal with it. If you want atmospheric attentuation, use extinction .1. Next, let's try to smooth things out. It's clear that what we have is pretty ragged. Compared to atmosphere it seems much less smooth because of the spotted appearence. Technically there's not much different in the accuracy, it's just that the banded look of atmosphere is a lot less visually distracting than the grainy look of the random sampling of media. There's a few things that can be done to get smoother results. First we'll reduce the scattering to .1, then go about changing some other parameters. The most obvious is to increase the samples. The old docs use 50, so let's try 30, 50:

Not only was that painfully long to render, there is still quite a bit of graininess to the image. Now we get to learn all about the nitty-gritty new keywords!

First, we need to know that to render this scene, we needed a minimum of 3 intervals. Any less and we get an error and POV-Ray won't render the scene. Intervals are the number of segments that the media sampling ray is split into at it passes through the media, which in the case of atmospheric media is the whole scene until it hits an object. In object media it is divided between the entry and exit points of the object. Think of it as a line that is split into segments. In this scene that means there is one interval from the camera to the spotlight, one through the spotlight, and finally one from the spotlight to the wall. For each light you need an interval, and the number of unlit intervals must be greater than the number of lit intervals.

From this, it's not hard to understand that the more intervals we have, the smoother the media will be, since we will have more samples. How many more samples? Well, for each interval we get the number of samples specified. If we have 10, 10 samples and 3 intervals, there will be 30 total media samples. That means that doubling the intervals is like doubling the samples.

The keyword ratio defines how samples get distributed between lit and unlit intervals. The default is .9, which gives lit intervals more samples than unlit ones. This can help our scene a little by increasing the intervals to .95 or even 1, though it only makes things only slightly better. The default of .9 is pretty high. If you find when using more complex densities that graininess starts showing up in unlit areas, it could be useful to lower the ratio to increase samples in unlit intervals. Don't use a ratio greater than 1 or you'll crash!

So far this hasn't helped much. What about variance and confidence? If the variance is below a threshold value, then no further samples are needed. That's the docs description, which doesn't help much. I take it to mean the maximum color difference allowed. I could be wrong, but it seems to make sense. Regardless, variance doesn't improve things much if there's a small gap between min and max samples. Using samples 5, 50 there will begin to be a difference seen with different variance and confidence values. Using variance 1/10000 and confidence .999, we see that in certain areas the media is getting very smooth, all without a big hit on the render time:

No AA used on this one. Pretty good.

Now if we can just get everything smooth without taking forever. We learned that if we need more samples in lit intervals, we can simply increase the ratio in that area without taking more samples. We also learned that lower variance and higher confidence can help improve where samples are taken provided the difference in min and max samples is made high enough for them to do their work. And finally, we know that the number of samples used can be doubled by doubling the number of intervals. The only question remaining is whether or not it's better to increase the number of samples or the number of intervals?

The answer for this scene is a little of both, since with a high ratio, more intervals means more samples in lit portions of the scene, and therefore more samples in those areas. The optimimum situation would be to have a min samples of 1, since that would limit one sample to the unlit intervals. Unfortunately variance and confidence don't do a good enough job of figuring out where the samples are needed, so at least 10 or 20 min samples are needed, and combined with the higher max samples needed for them to smooth things in areas that need them, they really end up slowing things down. The lesson here is that there's really no way to get good results across the whole image without taking a lot of samples and a lot of time. We're better off using more samples since that way we're gauranteed samples will be taken where they are needed. So here's what we're left with:

media {
scattering {1, .1 extinction .1}
samples 20, 100
intervals 10
ratio .999
confidence .9
variance 1/1000
}

This took about 18 minutes to render with AA .03 at 320x240. The different options honestly didn't help much, and as you can see, it was pretty much sampling that determined the quality of the render. Intervals, variance, and confidence are mainly useful for when you want to render media quickly, but for this scattering example, they really didn't help speed up the image while retaining quality. So is media better than atmosphere? Well, here's the scene rendered with atmosphere:

If you see any artifacts it's from the jpeg compression, not the atmosphere. This image took 3 minutes to render using AA .03 at 320x240. Clearly atmosphere is a LOT faster and cleaner than media. This doesn't mean that media is a step backwards...well in this case it kinda' is. For other things media is an improvement, particularly emission and absorption, since they work much more accurately and predictable than halo's features. There's also the added advantage of media being able to cast shadows on the environment. It's too bad atmospheric media is so difficult to deal with.

Here's the messy scene file if you want it.


© Michael Hough 1998

Not responsible for typoographical errors (this stuff takes long enough as it is).