Skip to main content
GameDev.net gamedev.net
🔒 Locked

Drawing shadow projections on a plane

Started by mr_malee Jan 31, 2010 at 7:30 PM 2 replies 1k views
Original Post
mr_malee
mr_malee
Hello again. It seems my quest for shadows and light is still underway, and I have come to another snag. take a look at this: lights WASD to move camera, click+drag to rotate, CTRL to pause/resume box rotation, SHIFT to toggle view between light and camera, SPACE to toggle light movement as you can see the shadow projected onto the plane are a little funny looking. The projections are fine, its the drawing of the shadow that isn't. My problem is finding a way to draw projected points so that it always forms a convex polygon. Some initial ideas have been testing every point to every other point to see if a line between them intersects any line between another, if so don't link those points together. However, that seems very very greedy. I've also heard about some algorithms that determine maximum polygon boundaries given a set of points. But in a way, that's what I already have. Unless these algorithms return points in order its not much use to me. any ideas? Thanks. [Edited by - mr_malee on January 31, 2010 7:46:52 PM]
Alrecenk
Alrecenk
The convex hull algorithm is what you need. The problems are that some of the points you've projected aren't in the shadow polygon edge, and that your points need to be in clockwise or counterclockwise order, and a convex hull algorithm will solve both of these problems. Wikipedia has an overview of some common algorithms:

http://en.wikipedia.org/wiki/Convex_hull_algorithms

I typically use the divide and conquer approach also sometimes referred to as quickhull(lots of relevant results on google for that). I have also written shadow casting algorithms where each triangle produced it's own shadow. When you start casting shadows from non-convex meshes you'll stop getting convex shadows, and finding the optimal shadow polygon becomes much more difficult.
mr_malee
mr_malee
Thanks for the advice. I realized soon after I posted that my edge determination was wrong, so I fixed that.

I'm using a convex hull algorithm now and its all working very nicely.

Thanks for the help :)

lights

on a side note, during my lengthly research on shadows I've never come across people needing a convex hull algorithm in their shadow projections. Is this because certain API's like OpenGL and DirectX do this automatically?

Thanks again for the help.
szecs
szecs
What happens, if the caster isn't convex?
Its shadow won't be complex either. I don't understand how you do this: Do you cast rays from the vertices to intersect the scene?

Look into "planar shadows", "volume shadows".

If you use the ray-casting stuff, I guess you calculate the silhouette edges, that simply connect the the shadow points with those edges (virtually), I mean you will always know, which points should be connected, then you can triangulate the stuff. But this works only with planar shadows (and a huuuge overkill), otherwise you have to deal with the corners of the scene.

So the so-called "planar shadows" is a better idea (with clipping/stenciling/whatever), or even "shadow mapping".

Volume shadows. Look into these.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.