Help with Fog: if you place a fog object inside another, they cancel out, why?

(By Ian Smith)

I was looking over an older list of bugs that were still not fixed when I came across the fog canceling out other fog objects. Remembering previous messages about transparent objects I wondered if it would work for fog. It does, sorta.

Imagine only renders flat, one sided triangles. To make a solid object, Imagine keeps track of if it is inside or outside of an imaginary solid. When a ray hits a face with fog or transparency, the ray is considered 'inside' until it hits another edge. That is why if you place a fog object inside another, they cancel out. When the ray hits the second fog object, Imagine considers the ray having exited the fog object. This is actually a good thing, albet tricky at times.

The solution to both problems as noted before on the list, is to make sure all objects are solid entities with no common or open edges. Picture trying to make a yellow sphere of fog with a second red fog sphere inside. If you try this, what happens is you get a sphere of yellow fog, but it has a hole in it where the red should have been. This is the canceling effect. What you do now is to set the inner sphere to the same attributes as the outer one. You now have created a true hollow fog object. The trick is to now use a third sphere, make it a red fog, and put it inside the hole. You have to be careful to make sure it is just a little smaller than the hole. Try to make it about 0.001 units smaller. An easy way is to duplicate the inner surface of the sphere and then scale it down slightly.

I included a uuencoded object you can test render (please refer to IMLarc61.lha at IML landfill for these uuencode objs). It contains 8 CSG spheres...

 RIGHT.LARGE       - Large yellow fog.
 RIGHT.UPPER       - Small yellow fog inside.
 RIGHT.LOWER       - Small red fog inside.

 LEFT.LARGE        - Large yellow fog.
 LEFT.UPPER        - Small yellow fog inside.
 LEFT.LOWER        - Small red fog inside.
 LEFT.UPPER.OUTER  - Inner surface of LEFT.LARGE surrounding LEFT.UPPER
 LEFT.LOWER.OUTER  - Inner surface of LEFT.LARGE surrounding LEFT.LOWER

Whe n rendered, the object on the left renders correctly, showing a yellow fog sphere with a red splotch of fog in the bottom corner. The top yellow fog does not show up because it is the same color and density as the larger sphere.

The right sphere however, renders incorrectly. It shows a solid, shaded red sphere in the bottom, and at the top is a hole where the smaller yellow sphere should be.

Now Imagine is still not doing for quite correct. For one, this trick does not work for global fog! I tried surrounding a fog object with a shell that was the same density and color as the global fog, but it simply caused the fog object to vanish completely! I was hoping this would allow the use of fog objects with global fog, but no luck. Secondly, and more important, the above example with red fog inside is still not what shoudl happen. The object on the right SHOULD render correctly. In reality, you do not chop holes in fog and stick other peices of fog inside. The two fogs should add their fog properties together. I have no idea what goes on inside Imagine, but I can take a guess that each ray has a fog/transparency flag that gets toggled when a ray hits a surface. What they need is not a flag, but an array of flags to keep track of how many layers of fog they have penetrated. Perhaps link this to the reflection resolve paramater in preferences. Then we could have true additive fog. You can fake it by manually adding the attributes together and settign the inner fog object to that.

BTW, I tried a negative fog length and it resulted in a totally invisible object. I wasn't sure WHAT I expected, but figured it was worth a try. :-) I also ran these tests in Imagine 2.0 and 3.2 to test for diffrences. Other than 3.2 being about 25% slower to render than 2.0 they worked the same.

Last Update: July 13, 1995
Back to Ian's HomePage. -- Up to FAQ #8 Index