Jump to content
  • Advertisement
Sign in to follow this  
jon723

Projection shadows

This topic is 4768 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 everyone, if you have a triangle mesh (like a height map) and you're trying to project a shadow onto it do you have to calculate the projected vertex for every plane produced by a triangle in the mesh? Would a solution to this problem be to draw a plane under the mesh, render the shadow onto the plane with depth testing off and then finally render the mesh?? From the many articles I've read on the subject they only mention a single plane (which has a trivial solution) but I'm baffled when you have a large amount of planes (derived from the triangles).

Share this post


Link to post
Share on other sites
Advertisement
Easiest would be to re-render the terrain (or better, just the chunk that has the shadow) with the shadow correctly positioned on it. You can project the texture correctly with a suitably set up texture matrix (google + projective textures should do it). This way your shadow correctly lies on a complex surface but you don't have to do any complex per-vertex math on the CPU.

Share this post


Link to post
Share on other sites
Common methods are as mentioned:
1) projected texture, I believe Halo did this for at least their flying ship.
2) shadow map(might be able to do this in conjunction with a simple projected texture layer)
3) that method you'd mentioned, trying to create a shadow mesh *over* the mesh or
3b) calculate (for each vertex) whether an area of vertices is in shadow, darken these vertices, or
4) stencil shadow (rather fill rate expensive) gives crisp shadows... works with shadow *volumes* where you extrude the silloutte of the object (or just the back-facing polys)

I belive this sort of stuff is actually mentioned in the Graphics forum faq. It's not the FAQ link, but the "view Forum FAQ" link (below all those links.)


-Michael g.

Share this post


Link to post
Share on other sites
I'd generally avoid projecting objects to get shadows like the plague. I can't remember a game I've seen it done in that's actually done it perfectly. (I think Neverwinter Nights is the best try I've ever seen and it's still got one or two glitches). Stick with stencil shadows or shadow mapping (or the projected texture method which works perfectly well provided you've got enough texture images to approximate all angles reasonably).

That having been said if you really want to do this you'd have to try and estimate all triangles that could be affected by the shadow and then yes, you'd have to project all points onto all triangles and clip the produced shadow triangles to each triangle (so you'd only have shadow actually on the ground). And once you've done all that you have to project the shadows upward slightly to avoid Z fighting issues. And if you really want to do it well you'd somehow have to try and stitch the shadow edges together to avoid cracks appearing due to numerical precision errors caused by projecting onto different planes (okay that might not be necessary but I'm trying to make a point ;-)

All in all I'd say it's never going to be worth it. Your suggestion of rendering onto a flat plane with depth testing disabled will work provided the entire area the shadow falls on is close to that plane - how close (i.e. amount of visual deficiency) is up to you, but I'd say you'll need a pretty flat landscape if you want it to look good. For that method it would help a lot if your viewpoint was close to top down because that will hide the odd angle the shadows will appear at.

Share this post


Link to post
Share on other sites
Projected shadows worked well for my project for quite a while.
What I did was to generate a frustum from a character's bounding sphere, and projected it away from the light.

This frustum was used to gather trianges to receive the shadow. Now, I already had static shadows in a lightmap, so I didn't need to solve the double-darkening problem, so all I had to do was to render the character in black into a white texture from the light's point of view, then just use the frustum's near plane as the texture coordiantes for each of the terrain triangles.

Worked great for characters, and artifacts were rare - mainly on stairs, etc. I have since switched to 8-bit depth shadow maps, so I no longer have the artifacts.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!