Cast shadows but not render?

I’m trying to combine static light maps (my own system, not Beast + dual light maps) with dynamic lighting and shadows.

One thing I’m trying to figure out is how the shadows cast by my light mapped (static) geometry will fall on the characters. I want my static geometry to act as a shadow caster, but I don’t want it to receive shadows from itself, because they’re in the light map already. However, when I’m rendering the characters, I do want them to cast shadows on the environment.

What’s the best way to get it so that my environment (casts shadows && !receives shadows) when I’m rendering characters, and (receives shadows && !casts shadows) when I’m rendering the environment? Can/does the shadow mapping even work in this way?

1 Answer

1

Hi Superpig,

First, to be clear, even if you get this working it won’t ever be physically accurate since the light maps are static and shadow maps are dynamic. So let’s say you get shadows working; the bounce lighting that is baked into the light maps won’t look right when characters cast shadows on objects that have reflected light into the light maps. One would need a realtime global illumination system in place for that degree of realism.

Back to your scene. I don’t know your visual target or what your camera perspective is, if it’s zoomed out (like Diablo) then you might be able to just draw characters into the shadow maps, so that they cast shadows on objects. Objects wouldn’t cast shadows on characters, but if the light maps are quality and the camera stays far away this might work.

Another option is to somehow get the shadow maps and light maps to play together. This is tricky since the light maps already have shadows baked into them by virtue of their nature. You could remove some key objects from the scene before baking the light maps, then tag them as dynamic shadow casters. Experiment with this.

Last suggestion: make two shadow maps, one for characters and one for the scene. The scene then gets dynamic shadows from characters, and characters from the scene (or scene + characters). This satisfies your conditions, and it only costs extra memory for the second RT and a second shadow pass. You could even optimize this by making a static shadow map for the scene and then combining that into the character shadow map (provided that the scene isn’t destructable / no lights move)

Good luck,
-Peter

p.s. Saw your altdevblogaday post on music. Awesome :slight_smile:

The last suggestion is pretty much what I'm trying to do - two separate passes of the shadow pipeline, one for dynamic objects (receiving shadows from the scene) and one for the scene (receiving shadows from dynamic objects). The problem is figuring out how to rig this in Unity - the only solution I can think of is something that involves turning on/off the shadow flags for hundreds of objects every frame, but I'm suspicious that there might be a better approach involving light culling flags or something.

–