2d dynamic shadows and lighting

Started by
4 comments, last by ArKano22 14 years, 5 months ago
Hi I've read the article abou 2d dynamic soft shadows, and its pretty much exactly what I need. The main difference is that my shadow casters are not primitives, but some random shapes made out of pixels. I have no way of knowing where the shape's corners are and thus to find the area that's actually lit by the light, I need to perform a lot of ray castings. Is there any cheaper way to achieve the same effect? The light might move around so prerendering is out of question, also the shapes might change. If this is the best way, then what would be the fastest ray casting algorithm (given that the process will take place on GPU fragment shader). How fast would this approach be on older GPU-s, starting from, lets say, Nvidia's FX5xxx series?' Here is picture for clarification: (The random shapes are black, shadows are gray and the point in the centre is the light)
Advertisement
I´ve never done 2d shadows before but i´m pretty sure the algorithm can be generalized to 2d convex polygons.

Then just represent your random-shaped shadow casters with groups of convex polygons and you´re done.

Of course this only works if you can use convex polygons instead of just squares and such.
Hmm, the scene must be represented as a texture (object must be made out of pixels), but I could try to convert the pixel data into polygon data. I would have to do this quite accurately and every frame, so in the end, I'm not sure which is faster:

Find the accurate convex hull of a random shape and cast the rays to its points (there would still be a lot of raycasting for jagged shapes)

OR

I could simply cast rays from the light, with certain angles (If one ray hits an object and the next one does not, I should cast more rays between them, just to make accurate shadow edge) and then maybe blur the shadow, so it would give me softer look and hide some accuracy mistakes.

Would like to hear your suggestions
Where is that article? I'd be interested in reading it. I'm experimenting with almost realtime raytracing in my 2D game (with multiple Z levels) at the time.
Quote:Original post by Beyond_Repair
Where is that article? I'd be interested in reading it. I'm experimenting with almost realtime raytracing in my 2D game (with multiple Z levels) at the time.


Here it is [smile]

If you absolutely need to have pixels and the environment may change during time (making a "worms" clone? :D) then your best bet (i think) is to use raycasting, jsut like you said.

good luck!

EDIT: Off the top of my head, you could render all your shadow casters in a render target, then use a directional blur to fade them away from the light center, and modulate the resulting buffer on top of your scene...that would also work, i think, but the resulting shadows would fade away in the distance...

[Edited by - ArKano22 on October 28, 2009 4:16:04 AM]

This topic is closed to new replies.

Advertisement