Now we can do that in the new graphics 2.0 engine?
You could certainly code something like this, but there is no generic function for it, if that is what you mean.
Your demo does remind me though that I wanted to look into using the composite ‘filters’ and snapshots to try out lighting effects
If you wanted to do something like in the demo, for every light you’d need to calculate the edge points of each object from the light source - when you find the boundary (IE the left most and right most points blocking the light) you’d create a polygon from those points extending away from the light source to the edge of the screen.
For a single light source this would be simple enough, but for multiple ones it could get tricky fairly quickly (and is why I mention snapshots - you’d need a way of accumulating each set of shadows from each lightsource, so you’d end up with 1 snapshot per light, then combining them all).
The code is fairly trivial (I’ve done something similar in the past) but it is long-winded, so I would not expect corona to natively support something like this any time soon.
One thing that *might* get you something similar would be playing with the lighting filters, where your height / normal / bump map is completely flat except for where you have objects. I don’t think it casts shadows however, which is clearly the main thing that is showing in that demo above.
Made a start on this earlier during the alpha. You can see where I got here:
http://www.screencast.com/t/9aRPZktxfPN
It actually looks much smoother, Jing is capturing a really low frame rate. But, when I tested it on the device it’s way way too slow. Haven’t had time to figure out if it’s the snapshots or the shadow generating code. None of it is optimized anyhow.
What I was attempting to do next was composite the shadows over bg/objects with normal-mapped lighting, which would be self-shadowing. No luck getting that all working together so far.
Can you put your code solution here?
Best regards
Looks nice, what was your basic strategy for this?
gtarkin- the code is a huge mess at the moment, and I’m still looking for solutions to certain things, so I’d hate to show it just now.
Rakoonic- very similar to what you described above, with a few problems.
- Haven’t yet figured out how to put the vertices of n-gons where I want them in screen space (because of auto re-centering).
My hackish solution for now was to use rects: create it at 0,0 on the screen, then move two of its vertices to the two points on the casting geo-edge, and two off screen. A new rect has to be created for each shadow-casting edge. Would be much better if I could just create a poly of X vertices, and place those vertices directly in screen space.
- The penumbra is wasteful at the moment, and I’d like to try to do them as a distorted texture pinned to the outer 2 edges of the umbra. The texture would be a fading diagonal across the rect. Then I’d calculate the spread based on the size of the light and whatnot.
The way I’m doing it right now is creating a spiral of light sources around the center light, running the shadow function for each"light sample", and setting a low alpha for each of the ‘penumbra’ passes. The umbra I’m keeping 100% opaque until compositing over the background simply to avoid double shadows from multiple geo in the light’s path. Doing it this way doesn’t actually seem particularly slow as it’s not wasting time raycasting 360deg or anything… just shooting vectors from the light sample to the vertices, which are a known, extending that off screen, then creating a simple rect and moving its points. The biggest problem is that for a really soft fade off I’d need *lots* of samples.
#2 isn’t a problem with Corona of course- just haven’t got to it yet.
-
I"m not sure yet, actually, how to handle rotating shadow casting geo if I’m not doing the rotating myself, as I don’t think we can yet query the location of a polygon’s vertices in 2.0 as we can currently for rects. So unless I create the ngons programmatically, and do the rotations myself so I can keep track of the vertices- not sure what can be done. Maybe I’ve missed the method for getting the vertices, but I’m guessing if it’s not possible now, it will be in future. The other alternative is to create all shadow casting geo from rects only- but that’s a bit of a pain. And if you use physics, well… Ideally we could use the physics collision geo as the shadow casters, and just create really tight collision geo around the artwork.
-
Right now, I’m taking a snapshot of the light, a snapshot of the shadow, setting the shadow.effect to subtract, then taking a snapshot of the result of this composite, and compositing that over the background. It *seems*, though I haven’t fully looked into it, that these 3 snapshots per loop are too much for an iPhone 4. I’ve tested the shadows themselves with no snapshots/compositing and it seems ok.
Anyhow- that’s the gist. I’m just an artist dabbling in coding. I’m guessing someone with a lot more experience with programming (like rakoonic) will be able to put together a coherent soft-shadow casting library pretty quickly now that Corona has all the pieces
You could certainly code something like this, but there is no generic function for it, if that is what you mean.
Your demo does remind me though that I wanted to look into using the composite ‘filters’ and snapshots to try out lighting effects
If you wanted to do something like in the demo, for every light you’d need to calculate the edge points of each object from the light source - when you find the boundary (IE the left most and right most points blocking the light) you’d create a polygon from those points extending away from the light source to the edge of the screen.
For a single light source this would be simple enough, but for multiple ones it could get tricky fairly quickly (and is why I mention snapshots - you’d need a way of accumulating each set of shadows from each lightsource, so you’d end up with 1 snapshot per light, then combining them all).
The code is fairly trivial (I’ve done something similar in the past) but it is long-winded, so I would not expect corona to natively support something like this any time soon.
One thing that *might* get you something similar would be playing with the lighting filters, where your height / normal / bump map is completely flat except for where you have objects. I don’t think it casts shadows however, which is clearly the main thing that is showing in that demo above.
Made a start on this earlier during the alpha. You can see where I got here:
http://www.screencast.com/t/9aRPZktxfPN
It actually looks much smoother, Jing is capturing a really low frame rate. But, when I tested it on the device it’s way way too slow. Haven’t had time to figure out if it’s the snapshots or the shadow generating code. None of it is optimized anyhow.
What I was attempting to do next was composite the shadows over bg/objects with normal-mapped lighting, which would be self-shadowing. No luck getting that all working together so far.
Can you put your code solution here?
Best regards
Looks nice, what was your basic strategy for this?
gtarkin- the code is a huge mess at the moment, and I’m still looking for solutions to certain things, so I’d hate to show it just now.
Rakoonic- very similar to what you described above, with a few problems.
- Haven’t yet figured out how to put the vertices of n-gons where I want them in screen space (because of auto re-centering).
My hackish solution for now was to use rects: create it at 0,0 on the screen, then move two of its vertices to the two points on the casting geo-edge, and two off screen. A new rect has to be created for each shadow-casting edge. Would be much better if I could just create a poly of X vertices, and place those vertices directly in screen space.
- The penumbra is wasteful at the moment, and I’d like to try to do them as a distorted texture pinned to the outer 2 edges of the umbra. The texture would be a fading diagonal across the rect. Then I’d calculate the spread based on the size of the light and whatnot.
The way I’m doing it right now is creating a spiral of light sources around the center light, running the shadow function for each"light sample", and setting a low alpha for each of the ‘penumbra’ passes. The umbra I’m keeping 100% opaque until compositing over the background simply to avoid double shadows from multiple geo in the light’s path. Doing it this way doesn’t actually seem particularly slow as it’s not wasting time raycasting 360deg or anything… just shooting vectors from the light sample to the vertices, which are a known, extending that off screen, then creating a simple rect and moving its points. The biggest problem is that for a really soft fade off I’d need *lots* of samples.
#2 isn’t a problem with Corona of course- just haven’t got to it yet.
-
I"m not sure yet, actually, how to handle rotating shadow casting geo if I’m not doing the rotating myself, as I don’t think we can yet query the location of a polygon’s vertices in 2.0 as we can currently for rects. So unless I create the ngons programmatically, and do the rotations myself so I can keep track of the vertices- not sure what can be done. Maybe I’ve missed the method for getting the vertices, but I’m guessing if it’s not possible now, it will be in future. The other alternative is to create all shadow casting geo from rects only- but that’s a bit of a pain. And if you use physics, well… Ideally we could use the physics collision geo as the shadow casters, and just create really tight collision geo around the artwork.
-
Right now, I’m taking a snapshot of the light, a snapshot of the shadow, setting the shadow.effect to subtract, then taking a snapshot of the result of this composite, and compositing that over the background. It *seems*, though I haven’t fully looked into it, that these 3 snapshots per loop are too much for an iPhone 4. I’ve tested the shadows themselves with no snapshots/compositing and it seems ok.
Anyhow- that’s the gist. I’m just an artist dabbling in coding. I’m guessing someone with a lot more experience with programming (like rakoonic) will be able to put together a coherent soft-shadow casting library pretty quickly now that Corona has all the pieces