Shadows in a Foggy Room

I know some of you visit the Cg Shaders forum (Hi davepermen) but just in case…
http://www.baddoggames.com/shadvolback.jpg http://www.baddoggames.com/shadvolfront.jpg http://www.baddoggames.com/shadvolleft.jpg

It’s Cg/NV30 but I think it should be achievable in less.

I’m using shadow volumes and back-to-front depth peeling to calculate and accumulate the in-scatter along illuminated segments of the line between the solid surface and the eye. The Cg demo does everything in a pbuffer, including the ‘stencil’ shadow volume in/out counting and the in-scatter accumulation. As each shadow volume layer is peeled, if the previous sample was illuminated then it adds in-scatter proportional the the length of the segment and the distance to the light.

I need the shadow in/out count in the pbuffer so I can update it as I depth-peel the volumes forward. I then know at each point whether it moving into, or out of, a shadow volume. I guess in vanilla OGL I can’t copytex the stencil buffer and would have to do a pixel read and rebind it on each pass ?

pocketmoon

[Edit]
Most of us have done it - thought up a new rendering technique only to discover that it was first described in some siggraph paper in 1988. But… I can’t find any references to using shadow volumes for volumetric fog?

Anyone seen anything similar in the past ?

[This message has been edited by pocketmoon (edited 11-06-2002).]

Look for a paper by Radomir Mech.

I think it was Eurographics.

Originally posted by dorbie:
[b]Look for a paper by Radomir Mech.

I think it was Eurographics.[/b]

Hi Dorbie,

I’ve googled but can only find a paper on Layered Depth images (which bizarrely enough is the only other cg contest entry that’s so far been made public on the cg forum).

The other papers are about plant rendering ?? I’ll take a look at those…

Rob

It looks similar to the algorithm I implemented in Performer.
I used the color buffer (r, or alpha) to accumulate the distance
each ray travels through the fog defined by polygonal boundaries, converted that into attenuation factor and blended the pixel color with the fog color. There are also some extensions of this basic idea. Check Journal of Graphics Tools 2001, number 3.

Ah Yes, rendering of ‘bodies of fog’ where you just treat the fog like a translucent object. I read the excellent article on gamasutra (http://www.gamasutra.com/features/20011003/boyd_01.htm) by Baker & Boyd.

But as far as I can tell, you can’t get shadows cast within the fog itself by rendering fog volumes. Like this:
http://www.baddoggames.com/shadcross.jpg

[This message has been edited by pocketmoon (edited 11-06-2002).]

WAAAAAAAAAAAAAAAAAAHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
****ING
CROSS
POSTER!!!

hehe hy pocketmoon i like your pics.

somehow i have a big dislike against depth peeling, but for the rest, it looks cool…

explain exactly how you do it and we can explain you if it can be done with less… at least, my 9700 should be able to handle it, /me thinks

Originally posted by davepermen:
explain exactly how you do it and we can explain you if it can be done with less… at least, my 9700 should be able to handle it, /me thinks

I’ll explain roughly how I would do it now rather than how I did it in Cg with which was a bit ‘rushed’!

You’ll be able to grab the mess that I call code when the Cg Contest results are published next week. Although I should have a much slimmer version by then.

You need to understand depth peeling first, i.e copying back and binding the depth buffer to do a depthcompare etc.

First render the scene.

Then do a ‘Carmacks Reverse’ shadow volume buffer pass (or passes) to set the shadow count.

Apply your shadows (via full screen quad or whatever).

Copy and bind the depth buffer.

Now comes the cool bit.

Set DepthTest to GL_GREATER and DepthCompare to GL_LESS. Depth peel the shadow volumes from back to front adding in-scatter and maintaining the shadow count:

LOOP depth peel through all layers
if the shadow count is zero
accumulate inscatter (SRC+DEST))
update depth buffer
else
update depth buffer
end if

Update the shadow (stencil) count.

Copy and bind the depth buffer.

END LOOP

N.B. you can use an occlusion query to test when to stop rendering layers

The amount of inscatter accumulated depends on a couple of things - the length of the inter-volume segment (current depth - previous depth) and the distance from the light. You could use alpha to hold a computed depth, or a floating point pbuffer for greater accuracy. Ideally you want to integrate across the segment to get a proper in-scatter value.

A movie:
www.flexcomputers.co.uk/mistyroom.wmv

[This message has been edited by pocketmoon (edited 11-07-2002).]

Hey that’s pretty sweet stuff. That’s the effect I was describing to someone a long time ago but using a simplier method (not involving the depth).

Congrats!

V-man

Originally posted by V-man:
Hey that’s pretty sweet stuff. That’s the effect I was describing to someone a long time ago but using a simplier method (not involving the depth).

Thanks V-man. I’d be interested in exploring any similar techniques - how do you avoid using depth (I use it for peeling and for in-scatter calculation)?

All the volumetric fog ideas I’ve come across while researching are based on rendering either the fog body itself (dorbie, humus - hi!) or talk about light cones or light volumes. I dont think either of these techniques can be extended to give volumetric shadows.

Some breaking news: A clever chap over on the flipcode forum has integrated the Extinction+Mie Scattering equation for me. That should stress the fragment shader

pocketmoon

[This message has been edited by pocketmoon (edited 11-08-2002).]

Originally posted by pocketmoon:
All the volumetric fog ideas I’ve come across while researching are based on rendering either the fog body itself (dorbie, humus - hi!) or talk about light cones or light volumes. I dont think either of these techniques can be extended to give volumetric shadows.

I think the technique I use could be extended to allow shadows in fog. (The demo is here btw. (OT: Released another demo today, check it out ))
You could render scene radial distance into a texture and fog volume getting an final distance-through-fog value, as in the demo. Then render the shadow volume into another texture in the way. Then you can combine the two getting something like
color = fogD * texture + (fogD - shadowD) * fogColor
I haven’t tested this, but I think it should work.

hey humus, nice demo. now i need the actual drivers… i have registered myself as developer yet, but no reply so far… where can i get them else?

btw, this is the first time perpixellighting is implemented the way it was always ment to be. mathematical, not with lookuptables aka textures… i remember at the release of the gf2 nvidia stated that now perpixellighting is possible… hehe took some time till we got something real working now

Originally posted by Humus:
I think the technique I use could be extended to allow shadows in fog.
<SNIP>
I haven’t tested this, but I think it should work.

Sounds like you have challenged yourself

The weekend approaches - you weren’t planning a social life were you ?

Originally posted by davepermen:
[b]hey humus, nice demo. now i need the actual drivers… i have registered myself as developer yet, but no reply so far… where can i get them else?

btw, this is the first time perpixellighting is implemented the way it was always ment to be. mathematical, not with lookuptables aka textures… i remember at the release of the gf2 nvidia stated that now perpixellighting is possible… hehe took some time till we got something real working now [/b]

Check Rage3D is usually a good tip. One of the mirrors: http://gamefiles.blueyonder.co.uk/blueyondergames/drivers/ati/radeon_7.79b2_9x_xp.rar

Originally posted by pocketmoon:
[b] Sounds like you have challenged yourself

The weekend approaches - you weren’t planning a social life were you ?
[/b]

Heh, alright, I’ll attack the problem at least. Unfortunately, the current drivers have problems with rendering to texture, so I’ll either have to resort to an older driver or figure out another way.

>>>All the volumetric fog ideas I’ve come across while researching are based on rendering either the fog body itself (dorbie, humus - hi!) or talk about light cones or light volumes. I dont think either of these techniques can be extended to give volumetric shadows. <<<<

Light volumes was the method.
It went somthing like

render with fog - render shadow back wih fog + render shadow front with fog

and this gives a volumetric effect with no scaterring.

Without scattering, it looks as cheap as plain stencil shadows, but it;s a first step.

V-man

Alright, so I sacrificed the social life …

I have a new demo showing off shadows in fog now. It’s not that complete or general, but I suppose one could complete it given better tools like floating point framebuffers etc.
http://humus2.campus.luth.se/~humus/

Pocketmoon, you can get shadows, as you have using Radomir’s approach (you found the right paper). You need to draw the spotlight volume but you also draw the volume of the projected shadow caster. Radomir gave an example of a spotlight shining through fog in his paper, although it did not have any shadow subtracted from it, I don’t think the rendering algorithm would change fundamentally, only the geometry used. Other parts of the paper described the handling of complex fog volumes for a range of applications.