2D Dynamic Shadows

I never chimed in before the show, but this is very cool stuff!

Soft shadows seem to be a fun (but difficult!) problem, so I had to know. :) Somebody always seems to have a new-and-improved demo, in the latest graphics text, or being presented at a conference.

@Rene,

It was great to have you on the hangout and I want to say, “This library is looking really great!”  I’m out of the office today (writing on my laptop right now), but when I get a chance, I’ll download the latest version from the repository, re-create the ‘benchmark’ test I made and give an example of avoiding ‘lucky luke’.

I’ll post all that here or e-mail it to you via Charles.

Cheers!

I downloaded the repo yesterday and it appears to be missing a “util” folder and the files within it (Vector2d, Log). Build fails without those files.

@roamiggamer Thank you Ed, I’m looking forward for your example/benchmark.

@tartarsauce Thank you for the info, I will check that immediately.

Ok, the utils folder is my personal collection of Corona/Lua helpers. Since this is a BitBucket repository on its own it has not been pushed to the repo (it just gets ignored). Now I found out that you can create special nested subrepositories (very cool!) for this special case. So I added the util repo as a subrepo to the shadow system project. Now it gets properly pushed to the BitBucket server.

BUT : if you use the download button on the BitBucket website, nested repos do not get resolved. It is still missing. You have two possibilities.

  1. Do a real clone of the shadow repo with console or with a GUI tool (I’m using SourceTree). When using clone the nested repo is resolved correct.
  2. Or if you want to donwload manually, you have to go to the utils repo. Download this as well and copy it’s content into a util folder inside the 2dshadows folder.

I recommend to use the first way. It is just two or three clicks and if theres in update, you can just pull it. If you have still problems please let me know. Especially if you never used repos like BitBucket/GitHub this might be confusing at first.

For convenience (and the ones that do not want to hassle with version control) I added an alternative download link in the first post.

Added a new Version 1.31 and a new video in the first post to introduce the current feature set.

This is really impressive. Well done and thank you.

Very cool!

Regarding the Lucky Luke problem, drawing your shapes using the nearest cube corner point “in the middle” of your contact shadow instead of the farthest will help a little already, I think. Are the boxes controlled by a player, or automatically? If the latter, why not move the boxes within the same enterFrame event? Everything in this code block will be drawn together before the frame is updated I believe, so things 'll move more or less in unison.

The big crate gets moved by a transition.to. The vertices at the four corners to calculate the shadow from are child objects of this crate that gets moved with the transition.to method. It seems that the child objects gets updated a bit later after the parent object.

Moving the tranistion.to directly into the shadow update method does not change the Lucky Luke effect :frowning:

I think I will clean up the code a bit and put it to GitHub. Maybe someone else interested in shadows is able to optimize.

Looks great.  I’m looking forward to seeing this on gitHub.

Ok I cleaned up most of the code, added some documentation.

I’ve created a repository on BitBucket. You can download it here:

https://bitbucket.org/reneaye/corona-2d-shadow-system/

Thanks for sharing this.  It works well in the simulator and on hardware (even an older gen1 Nexus 7).

I did have to make some small adjustments however.  Lua is case-sensitive and some of your require statements used the wrong cases for file names.  I merely updated all directory and file names to camel-case and then modified the code to use the same case.

After that… bingo.  No prob.

Again, thanks for sharing this.  If I find any optimizations or a solution to the ‘Lucky Luke’ issue I’ll post back.  

Ah, did not test it on hardware yet. I will add the changes to the repository. Thank you for the hint!

Yes, please, if you have any ideas about the lagging shadow polygons, let me know.

Ok, I updated the repo. Should be running on devices out of the box.

Really, really cool.

  • Caleb

Would increasing the frame rate fix it?

The example on BitBucket is already set to 60 fps. So, unfortunately not :frowning:

The Lucky Luke effect does only appear if I use transition.to() to move/rotate the object. I.e. if I drag the object (the crates and lights in the example are draggable) or if I rotate a crate with 

crate1.rotation = crate1.rotation + 5

in an update timer then the shadows are fine.

It seems the transition.to() let the objects updates somehow different which leads to the Lucky Luke effect.

This is a fantastic library. Well done and thank you.

I was thinking that perhaps the Lucky Luke (why that name, in particular?) problem is due to the enterFrame executing before the code executed by the transition library, yet before the screen is actually updated. Have you tried using a timer which executes at 120 times a second? (transition.to does not have a per-frame event listener, unfortunately.)