2d Shadows

Monkey Archive Forums/Monkey Projects/2d Shadows

Raph(Posted 2014) [#1]


That's one colored spot and one parallel light.

What I'm doing:

- I ported this: http://www.blitzbasic.com/codearcs/codearcs.php?code=1833

- Added in some of the logic from http://greweb.me/2012/05/illuminated-js-2d-lights-and-shadows-rendering-engine-for-html5-applications/#underthehood Multiple samples is in there, but I am not using it; it gets crazy expensive real fast.

- also added in edge culling using http://forums.tigsource.com/index.php?topic=8803.0

- I grabbed Warpy's convex hull code from here: http://www.monkey-x.com/Community/posts.php?topic=709

- converted all the above to use keef.vectors. Thanks for posting it, Tibit!

- I made my AnimImage library (the one here: http://www.monkey-x.com/Community/posts.php?topic=8582) generate a hull for every frame of every AnimImage. (It'll be something you can turn off, eventually).

- I added a new Light class, with the two types (so far).

- I modified the shadow code to use the hulls as the polygons

- I added in a bunch of stuff to transform the hull polygons to match the AnimImage's rotations etc.

- added in a lightmap texture for the spots and a shadowmap image for the shadows.

- Made the shadows have colors (crudely inverted from the light color, right now)

- added intensity; spots attenuate it based on distance. And falloff, which is basically shadow size, is per light.

Lots of stuff to do yet. I want to tackle the penumbra issue to do hard shadows. I want to move to a concave hull algorithm instead of a convex one -- anyone got one in Monkey? I have found two that seem suitable, but one's a messy port and the other is a math paper. I want to add better Z handling so that you can set an object's height and it could sort everything properly, and shadow better based on the light position (basically, start to fake a Z using sprite height, light draw order, and the falloff for the shadow).

This will have to all get wrapped into an object system, of course, so that draw orders can be handled cleanly. But right now I am just drawing AnimSprites manually.

The HTML5 & Flash versions aren't drawing the shadow texturemap correctly. I suspect a UV issue -- I probably have the poly facing away. :P That's why no live demo right now.

I'll post code once it is cleaner. I wish it didn't entangle with dependencies so much as it makes it harder to share.


Raph(Posted 2014) [#2]
Oh, stuff I am NOT doing: a dark mask, or any GL at all. Eyeing nDrawExts though. :)


slenkar(Posted 2014) [#3]
looks good, but needs a better example,

Like a scene that really takes advantage of the shadow system,

Instead of doing concave you could just put 2 convex hulls together


Raph(Posted 2014) [#4]
I have a concave algo working now (had to come up with one myself). Currently working on optimizing the hull it generates.

Seems like figuring out how to combine two convex hulls (and get them to sort properly with shadows) is a tricky problem in itself? Maybe it's just the 2am talking here....