OK, here's what I have so far.
Not all the exposed variables do anything, and it probably still has some bugs, but at least it works:
http://www.inio.org/~inio/dynamicshadows.zip
That includes a map thats little demo, and source scripts. For some reason I didn't include the myLevel.u package to make it easy to include in your own maps, but I've got a workaround for that in a bit.
If you're just in it for the tech demo, load up the map single player no bots and type "behindview 1" at the console. Now walk around and watch the shadows change to reflect the local lighting. Weeee!
If you're thinking of using this tech in your own map, the most important thing to know is that each DynamicShadowVolume creates a shadow for each player within it, source at the most important ShadowCaster (typ. ShadowLight) with the same Tag. Each DynamicShadowVolume will create only one shadow for each player within it. As a side effect if you have multiple intersecting DynamicShadowVolumes, players within them will have multiple shadows. ShadowCaster exists to be subclassed. I didn't create a ShadowSpotLight yet, but it wouldn't be hard.
To use this in your own map, first load the sample map into UnrealEd, then load your map. Now place a DynamicShadowVolume and a ShadowLight somewhere in your map. Always make sure before saving that there is at least one DynamicShadowVolume and one ShadowLight in the map. Loading the sample map as a script package is not advised, as I've had very odd behavior when I've done that in the past.
Features:
- Should be pretty easy for mappers to pick up and use.
- Shadows fade out after leaving a zone.
- Mapper can control shadow casting distance, whether shadows should fade as they approach parallel with the surface, and whether to draw the shadow using blob shadow mode.
Ideas:
- Add shadows to all actors with DrawType=DT_Mesh. This should be possible, but making it work reliably and not shadow the wrong things could be hard.
- Add shadows for first-person. This would be harder from what I can tell, and would cause the odd effect of shadows from your nonexistent legs when you look down.
- figure out a nice way of attaching a Light to a mover, as the code right now doesn't care if it's the light or the player that's moving.
-
(WiP) Make it so a single DynamicShadowVolume can create multiple shadows for an object up to some fixed maximum. This would reduce the number of volumes required but complicate the DSVShadowProjector script a bit and provide means for quality dropping.
- colored shadows for colored lights. (maybe with some silly Material stuff?)
- to reduce load in situations where you have 2 or more shadow sources close together to create shadows appropriate for a non-point light: share the shadow texture between them so it only gets rendered once.
Known Issues:
- If a player gets too close to a light the shadow doesn't behave quite right. This is due to a limit on the projector FOV. Without this there would be potential for enormous cpu load when an actor got too close to a light and the FOV of the shadow projector aproached 180, resulting in a slice of the level between the plane of the shadow projector and the plane at the trace distance being considered for shadow casting. Right now the FOV is limited to about 100 (not sure of the exact number).
-
(fixed) Shadows pop up when you enter a DynamicShadowVolume that has a light to close to it's edge. Same thing for the default shadow disappearing and reappearing when you enter and exit DynamicShadowVolumes (not visible in the sample map).
- Right now there's still a few DefaultValues that need to be set to make mappers' lives easier.
- (untested but I assume this is the case) If a player is occluded and therefore not drawn, their shadows will also not be drawn. While it would be really cool to use a ground light shining up at a wall to give a hint of player's locations without directly showing them, this could be a PITA to get working reliably.
- Blob shadows don't fade
Not possible?
- shadows for particles (even if it were possible, it would be an enormous CPU hog).
- blurry shadows for non-point light sources. (again, maybe a Material trick to get this working without being a CPU hog?). Maybe by setting a over-large FOV on the BitmapShadowTexture and using a raw material to scale that up to fill the shadow appropriate area?
Questions
- This shouldn't add any bandwidth overhead in net games as it happens entirely on the client side, but I'd like someone with more experience with replication to validate that.