controling the direction of player shadows

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

inio

many fauceted scarlet emerald
Feb 8, 2002
105
0
0
CA, USA
www.inio.org
is it possible to control what direction player shadows are cast in and maybe even their opacity? I'm working on a map that has a few dark areas with just a general glow, and would like to be able to either make the shadows show up directly below the player, or make them much less contrasty. I also have a few areas with a bright light in the center of the room and it looks weird when the shadow of a player falls towards that light.

edit: Here's a screenshot to let new people know what this is about right off the bat. Scroll down for details.
liveshadows.jpg
 
Last edited:

X

Soul on Ice
Apr 24, 2000
368
0
0
ON,CA
What you want isn't possible, the shadows for the player model are completly static, so unless you want to do some coding you'll just have to concider the shadows the same way most of us do, and that's useless and only there for show.
 

Dr. Nick

New Member
Oct 5, 2002
169
0
0
37
GA
Visit site
There are variables that control the light source position that determine the projection of the shadow. Unfortunately I do not remember them, but I do know they exist because someone posted the variables and a picture of it being done in game. I think it had something to do with the shadow script itself. Have a look around at it.

(edit)
Well a quick search of the source found the file. ShadowProjector.uc under engine\classes. Here are the variables:

var() Actor ShadowActor;
var() vector LightDirection;
var() float LightDistance;
var() bool RootMotion;
var() bool bBlobShadow;
var() bool bShadowActive;
 
Last edited:

inio

many fauceted scarlet emerald
Feb 8, 2002
105
0
0
CA, USA
www.inio.org
Thanks. I was incorrectly assuming it was mostly done in the game engine, so I didn't look for extra classes. I've already got something working, but it has several issues I wanna resolve before I publish it.
 

inio

many fauceted scarlet emerald
Feb 8, 2002
105
0
0
CA, USA
www.inio.org
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.
 
Last edited:

inio

many fauceted scarlet emerald
Feb 8, 2002
105
0
0
CA, USA
www.inio.org
Yeah, I was kinda struck by how cool it looks, even in the silly little testing environment. Btw, it definitely is going up on the wiki when I have time. (I already mention it in my dev journal). How does "Dynamic Shadows" sound for a title? Right now I need to sleep.
 

[SAS]Solid Snake

New Member
Jun 7, 2002
2,633
0
0
40
New Zealand
www.digitalconfectioners.com
I did this a while back, in the early stages of my Stairs Dismount code. Anyways, I just used a vector before hand to simply place the location of the source. To get the shadow caster to move, because it extends the light class, it has bStatic and bNoDelete set so that the light doesn't delete and it doesn't move I believe. Since all your using the light for is to set certain values (the defs) and the location of it, you could just change it to a standard actor. I noticed that you also used some values from the light, one way to associate the shadow caster to the light is to get the mapper to set the tag.

Only other real problems with moving lights is that if the light casts raytraced shadows, they won't be affected since it is just a light map in the end... but for dynamic shadows it should work like a treat.

Good work!!! I like it ... I figured out how to get the light to be sourced, but I couldn't figure out how to change some values like the FOV and the Darkness properly. Would it be alright if I made changes to my own light code [Credits of course to you]
 
Last edited:

MythOpus

You Have Witnessed The MythMaster @ Work
Jul 22, 2003
19
0
0
34
Canada
www.freewebs.com
inio said:
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!

........

Hey Inio. This thing does look cool and when all the bugs are squished out of it, it'll give us mappers a whole new depth of realism to work with ;) :D :lol: Oh and BTW thx for making me want to reply so badly to make me want to get an account on BuF :D
 

inio

many fauceted scarlet emerald
Feb 8, 2002
105
0
0
CA, USA
www.inio.org
[SAS]Solid Snake said:
BTW, I found out that if you use this for all the objects in the map, it runs super slow...
Yeah. You don't want to be doing more than probably a dozen or so projections per frame, especially if they're onto high-poly static meshes. I was also planning on using blob shadows for anything besides players, as the difference between a blob shadow of a grenade and a bitmap shadow of a grenade would be barely noticeable in-game. Looking at screenshots you could tell the difference, but that isn't what counts.

One other thing that would be possible is to make explosions cast shadows. I specifically made the actual shadow logic separate from the DynamicShadowVolume stuff, so it's possible to cast shadows without a volume involved. Is there anything like SpawnNotify in UT2003? I was thinking I could watch for the explosion effect to be created and add a shadow caster for them and appropriate shadow projectors for visible actors? what's the "right way" to do this?
 
Last edited:

inio

many fauceted scarlet emerald
Feb 8, 2002
105
0
0
CA, USA
www.inio.org
Dark[NSF] said:
Wait, I don't fully understand the features... Could you explain inio? Or add a screenshot showing it? Thanks.
Just posted to the top of the thread, might as well post it to the bottom to:

liveshadows.jpg


Right now I'm working on a playable map (simple DM map) that will show it off in a more accessible way.
 

inio

many fauceted scarlet emerald
Feb 8, 2002
105
0
0
CA, USA
www.inio.org
Here's another one:
liveshadows2.jpg

I know the shadow on the wall should be darker. I've got some ideas of how to get it darker (mostly turning off bGradient and tracking the MaxTraceDistance to match the first wall hit). Another slightly higher cpu- and gpu- load solution is to split it into two projectors, one that's bGradient=false for the first bit of distance, and another that's bGradient=true for the rest of it. There might be a visible seam between them though...

Before I play with that though, I'm going to get multiple shadows per DSV working.