Jump to content
  • Advertisement
Sign in to follow this  
gq3

2d dynamic shadows and lighting

This topic is 3158 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!