discosultan / penumbra

2D lighting with soft shadows for MonoGame
MIT License
321 stars 32 forks source link

[feature?] realistic shadows from topdown viewed shapes #7

Open InfiniteProductions opened 8 years ago

InfiniteProductions commented 8 years ago

I just wonder if you have already something to create "realistic" shadows from shapes which hide some part of themselves due to the view angle like trees, light pole, fence, gate or grid ?

For now and AFAIK, using Penumbra makes shadow looks resp. from a circle (if we consider trees displayed as a disk of leaves) and a full/opaque square. Not really what we would expect to see.

As I thought of this, I also come with a possible solution to this: for each assets we want to manage under Penumbra, we would have to provide a kind of front-view (or horizontal view) of it, and Penumbra would use this texture as base to generate better shadow by shearing/stretching the texture like the base shadow does. It would also allow to add vertical location of the light source (I don't think this is managed now, isn't it ?) as texture could be more and more stretched when light goes low and vice versa.

Example: fr-shadow1

One point here is to know how much time it takes to shear a texture, the right way, at run-time, probably not that's much.

discosultan commented 8 years ago

The library is currently strictly 2D only - there is no notion of light's height (or depth, depending on the perspective).

I have fiddled around with some 3D properties for features such as normal-mapped lighting, but for simplicity decided not to go down that route. Such texture shearing (shadow mapping) seems to fall into the same category. I don't have enough experience to know how other 2D lighting systems solve such problems. I would probably use a 3D system instead - even if dealing with a 2D game.

InfiniteProductions commented 8 years ago

I see. For other 2D lighting system, there are not so much (one I know about is Krypton) and if it comes to migrate to a 3D system, it would be silly as it is very complicated (deferred rendering and shadow mapping stuff, HLSL limitations in instructions count, platforms compatibility, etc.)

I just thought shearing a given texture wouldn't be too hard but add a little more realism in quite common cases.