Dynamic shadows for a portal engine

I have been working on a portal engine, and I decided rather than using a breed of lightmap/dynshadow to do the shadows for the whole world, I would just use dynamic shadows. When seeing the difficulty in Zpass shadowing, I decided to use Carmack’s reverse.

I came to realize that Carmack’s reverse on meshes coupled with using Zpass shadowing on portals just doesn’t work, so I decided I’d try creating some type of portal shadow based on the reverse, or more to the point, something that won’t conflict with my mesh’s shadows, which are using CR.

We must first consider the environment. There are two sectors connected by portals. Sector A has a portal to B, and it’s not necessary that B have one to A, although usually it will. There’s a light in A, which should shine into B.

First thing I did was to cast the sector walls of B as I would a normal mesh shadow. Since the walls mesh is “inside out”, and I cast my shadow volumes from the “facing away from the light” side, the shadow for the sector walls will pass completely through the sector.
Second thing I did was I cast the portal as a mesh, except I reversed things, so instead of getting a “shadow” I get an “antishadow” which lights the appropriate regions of the sector (which is totally shadowed). I suffered a problem though. It turns out that the sector walls mesh glows where it faces away from the light (all faces that should be completely shadowed). So, I doctored it up by adding Zpass to the “upper” cap of the sector walls shadow.

Now the question: Should I write a tutorial on this?

Sure, please write a tutorial, I’d be interested in reading…

I’m using a similar approach, but with
a little bit of cheating…

Lights only cast lights and shadows on object
within it’s sector. This works well in most
cases (indoor and outdoor (outdorr is one sector)

You can arrange the lights to hide possible
artifacts, you can also let the dynamic things, like characters get light and cast
shadows on currentSector + neightbour within
shadow BB, type thing…

This makes it possible to save some shadow
fillrate on things like walls, roof, ceilings.

However, I’ve thought about a problem case,
which goes a bit like this:

If you make a town area, it would be great to
separate streets and town-squares into sectors. However, this case would be very
artifact prone… So I’m still thinking about
the best solution for this (may still end up
cheating, but as long as it looks good and
saves fillrate, I’m happy =)

I second that! Tutorials are always good! Help the community grow!

im not sure i understand the purpose for your method. i have implemented stencil shadows with portals. i use infinite shadows with carmacks reverse. what i dont quite understand is why are you treating portals as a special case. if you are projecting shadows from the world geometry then the meshes that are around that portal will project that shadow you’re looking for. seems like yours is redundent. i had a discussion on here a while ago about a problem related to this with i believe knackered but i dont remember. the problem is the seems between meshes will get drawn and canceled out. what he said that was apsolutely correct is that you have to keep track of the connections between the meshes and check these when you are checking for edges to project. if you do this it should all be generic and you wont need and special shadowing for portals. in fact the portal may not even need a shadow volume at all because it may be shadowed itself. with your method you would render it anyways. if i got what you were saying wrong than by all means write an artical and teach me a thing or two.

Hi 147-2

If you do not mind me asking, then what are you using to create your scenes? I am about to start a project very similar to yours, so I would be interested in knowing. My little engine should also simulate indoor environments and use portals for culling. Are you using your own editor or are you loading an already existing scene file format (e.g. Quake BSPs)?