Game Development Community

Dynamic Shadows, Callback for if player is currently in shadows

by Jan Max Friedrich · in Torque Game Engine Advanced · 11/09/2008 (11:35 pm) · 10 replies

The topic makes it likely sound more complex than it is. I'm working on a game project and considering TGEA
for a variety of reasons there is however one thing it needs to be able to do:

Can it send a callback concerning the player characters shadowed status.
I.e.: If the character is currently in the shadows?

One of the main things our game dynamic needs is to be able to tell that and the initial prototype would be
built around the old game of "going home jumping only on the shadows".
Marking shadow zones is really not an option since we need it to work for dynamic shadows.

Would appreciate some input into how complex this would be to achieve with TGEA
I apologize if this has been covered in another thread, the topic doesn't lend itself well to search terms.

Thanks for any and all input,
~Jan

#1
11/10/2008 (12:23 am)
What you can do is check the interior or terrain below the player to see how shadowed it is. Since it's pretty blurry - literally) what you can already call a shadow, it is best to check for how dark stuff is below the player.

The method getColorFromRayInfo is responsible for getting shadow color from terrains and interiors in this manner. This information is then used in the light manager in the method getLightingAmbientColor. It casts a ray from the player's bounding box top center down (100 units long) when the object moves, and checks if there's a lighting interface available for the collided object. If it finds one, it calls its getColorFromRayInfo, and takes the resulting color.

This might help. To decide if you are standing in shade, you can set up a threshold and check for that.
#2
11/10/2008 (12:54 am)
Sounds like it would only work in moderate to high contrast scenarios or if I would cap all shadows to be black or very close to black, but it sounds a lot easier to implement than I initially expected. Thanks a ton for the fast feedback by the way it really helps. This puts a bit of a constraint on our artistic direction, but I'll run it past the team and see what they think.

So I assume what I would do would be to check if the player is on the ground(since it only needs to be checked then) and then add a callback to the getColorFromRayInfo on the condition that the RGB value is under a certain threshhold. Is this passed as RGB, ARGB or other? Just out of curiosity.
#3
11/10/2008 (2:37 am)
Jan, yes, there's a separate lighting interface for terrain and atlas - so depending on which one you want to use, you'd want to look for the interface's getColorFromRayInfo method - in which you can set up a callback passing the color value to it that's been picked up by the ray cast. This is an RGBA value (a ColorF to be precise), through the alpha is always 1.0f afaik.
#4
11/10/2008 (2:50 am)
Would this only work with terrain types or also objects? We'd be working with indoors for at least a good part of the game. Also thanks for your fast responses, It's really helpful.
#5
11/10/2008 (2:55 am)
If you want it to be working indoors, I presume your indoors will be interior .dif models. If so, that also works, there's a separate lighting interface for interiors (.dif files), and everything works just the same for these.

You're welcome. This is a topic I'm poking at myself, so it's helpful for me too.
#6
11/10/2008 (3:40 am)
I'm pretty sure the above mentioned methods won't work for dynamic shadows.
#7
11/10/2008 (3:49 am)
Dynamic shadows would be really important to both feel and gameplay. Would hope we don't have to implement our own shadowcasting system... do you think there's a way to achieve this with dynamic shadows in TGEA without major engine modifications?
#8
11/10/2008 (3:56 am)
Stefan is right, this works only for static shadows on the legacy or atlas terrain and interiors. As for dynamic shadows, I'm not sure what the right approach would be.
#9
11/10/2008 (4:51 am)
You could cast a ray towards the sun from your position, and see if you're obstructed. That would get you a simple "shadowing" test on dynamic objects, but it depends on a number of factors, one of them being how detailed your collisions geometry is, and of course - a shadow gets stretched depending on sun elevation, so that wouldn't be very accurate either.

And then all the other light sources..

Quote:
Would hope we don't have to implement our own shadowcasting system...

This feature is rather game-specific, so I see no reason why you wouldn't have to.
There are obviously ways to get this rolling, but you'd have to know your way around.
If you're feeling adventurous, take a look at BlobShadow. It should be totally in software (and thus, suitable for this feature because we need to run this on the server as well - which shouldn't have to care about shaders.)

That would give you a 'good enough' smooth shadow that conforms to object length/width/height (ie, it's not just a simple circle). Take that and for each light, make your check.
#10
05/13/2009 (8:23 pm)
Thanks for all your detailed responses. I've been looking into it with the help of a very advanced programmer and if something interesting and TGE(A) related comes of it I'll be sure to keep you posted.