shadow volume question?

Started by
3 comments, last by Seiko 18 years, 4 months ago
I'm not sure if this is really a DX related question or not but if I have a scene viewed from over head what should the expected shadow casts look like? Basically the scene consists of a cube and 2 lights, 1 light either side. If the lights are of the same brightness and equal distince from the cube should shadows be rendered? I only ask as I'm trying to implement shadow volumes for a DX overhead scroller and wondered if I've understood shadow volumes correctly and whether the output would look odd? Finally if it would look odd how can I overcome this? Suspected image output using shadow volumes ____________**+++** Light1>______**+++**<-----Light2 ____________**+++** +Structure/*shadow Accurate image output, i.e. lights prevent shadows either side of structure? ____________+++ Light1>______+++<-----Light2 ____________+++ +Structure/*shadow Any thoughts or pointers would be a grerat help to this newbie to the world of D3D. Many thanks, [Edited by - Seiko on December 5, 2005 10:16:23 AM]
Advertisement
It depends on how you 'process' the results from the shadow volumes. Using shadow volumes you can basically determine whether or not a part of the scene is in shadow. If you have more than one light, it's up to you how to combine the results.

You could make the lights cancel eachother out (which should happen when you render multiple passes to the same stencil buffer, which is commonly the default approach). On the other hand, you could create seperate overlays for each light and add them together using alpha blending, which will give you 'half shadows'. The same effect might be achived more efficiently by tweaking your stencil test settings.

But for a top-down game, I doubt you'll want to go through the pain of getting shadow volumes to work. I'd recommend you try out the Matrix.Shadow approach first, from you other thread. If you've got a flat ground surface (which top-down games commonly have), it should work just fine and save you a lot of trouble.

I started out with volume textures too in my first week of game-coding-newbie-ness and you can trust me on this one that it's a big pain to implement. Working with the stencil buffer, screenspace quads and actually generating the shadow volumes aren't things you want to mess with at first. With a little bit more experience, they will be much easier to understand and implement.

But don't let me stop you if you really want to try. I'd just recommend you get yourself the tutorial on codesampler.com and work with that to get started.
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
Quote:Original post by remigius
It depends on how you 'process' the results from the shadow volumes. Using shadow volumes you can basically determine whether or not a part of the scene is in shadow. If you have more than one light, it's up to you how to combine the results.

You could make the lights cancel eachother out (which should happen when you render multiple passes to the same stencil buffer, which is commonly the default approach). On the other hand, you could create seperate overlays for each light and add them together using alpha blending, which will give you 'half shadows'. The same effect might be achived more efficiently by tweaking your stencil test settings.

But for a top-down game, I doubt you'll want to go through the pain of getting shadow volumes to work. I'd recommend you try out the Matrix.Shadow approach first, from you other thread. If you've got a flat ground surface (which top-down games commonly have), it should work just fine and save you a lot of trouble.

I started out with volume textures too in my first week of game-coding-newbie-ness and you can trust me on this one that it's a big pain to implement. Working with the stencil buffer, screenspace quads and actually generating the shadow volumes aren't things you want to mess with at first. With a little bit more experience, they will be much easier to understand and implement.

But don't let me stop you if you really want to try. I'd just recommend you get yourself the tutorial on codesampler.com and work with that to get started.



Well I've pretty much psyched myself up to take the plunge and try and use stencil volumnes. My plan was originally to use a projected cube matrix (via matrix.shadow) to populate my shadow volumes. Having read the Gamasutra shadow volumes demo however I'm now a little lost on the combining of the stencil buffer passes to allow shadows to be automatically cancelled out.

http://www.gamasutra.com/features/19991115/bestimt_freitag_01.htm

It appears their technique would create many shadows and would not allow for either half/blended shadows or completly cancelled shadows. Do you have any examples of using a shadow volume technique that either cancels shadows or blends to create half shadows?

Many thanks,
Well, if you're really determined to through with this, I can only applaud you for being a stubborn ass like me ;)

As I said, I'd go with the codesampler tutorial on shadow volumes to get the basics working with one light. This isn't the fastest, most robust example, but it's easy to understand and well documented. For a more robust approach and some more theoretical info, you might want to look into the articles here at gamedev.

Anyway, when you get that tutorial working, you'll basically have a screen overlay which darkens the parts of the scene that are in the shadow. Now you can use the same approach to render another overlay for another light, on top of the existing overlay. Since the overlays are semi- or fully transparent, they can be alphablended together for the 'half shadow' effect. Tweaking the color/alpha with which you render the overlay will allow you to get a decent result.

It can undoubtedly be done more efficiently and more elegantly, but this should work out just fine, be reasonably fast and most of all, be just about the easiest way to do it.

Good luck :)

Edited:

If you actually WANT to have the lights cancel eachother out, you should go with the approach described in one of the GameDev papers (can't recall which one, sorry), that 'renders' the shadow volumes of all lights into one and the same stencil buffer.....

I was thinking that they would cancel eachother out by default, but I see I was wrong on that. If I recall the technique correctly, the exisiting shadows may indeed be 'overwritten' in the buffer by lights that are rendered later, but the shadow of the final light will still be there. You might be able to get around this by tweaking the stencil function, but I can't tell you exactly how to do it from the top of my hat.
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
Quote:Original post by remigius
Well, if you're really determined to through with this, I can only applaud you for being a stubborn ass like me ;)

As I said, I'd go with the codesampler tutorial on shadow volumes to get the basics working with one light. This isn't the fastest, most robust example, but it's easy to understand and well documented. For a more robust approach and some more theoretical info, you might want to look into the articles here at gamedev.

Anyway, when you get that tutorial working, you'll basically have a screen overlay which darkens the parts of the scene that are in the shadow. Now you can use the same approach to render another overlay for another light, on top of the existing overlay. Since the overlays are semi- or fully transparent, they can be alphablended together for the 'half shadow' effect. Tweaking the color/alpha with which you render the overlay will allow you to get a decent result.

It can undoubtedly be done more efficiently and more elegantly, but this should work out just fine, be reasonably fast and most of all, be just about the easiest way to do it.

Good luck :)

Edited:

If you actually WANT to have the lights cancel eachother out, you should go with the approach described in one of the GameDev papers (can't recall which one, sorry), that 'renders' the shadow volumes of all lights into one and the same stencil buffer.....

I was thinking that they would cancel eachother out by default, but I see I was wrong on that. If I recall the technique correctly, the exisiting shadows may indeed be 'overwritten' in the buffer by lights that are rendered later, but the shadow of the final light will still be there. You might be able to get around this by tweaking the stencil function, but I can't tell you exactly how to do it from the top of my hat.


Remigius,
You've been a real gentleman and I thankyou for you're time and patience in relation to answering my newbie questions! I've got plenty to play with now at least and will hopefully have something running eventually. BTW, you're right about the stubborn ass but having skirted around the shadow ideas and concepts for months in relation to a tiling/2d approach I keep ending up back at the same conclusion. i.e. if you want anything that even remotely looks acceptable by todays standards you'll need a decent shadowing technique. I guess it's time to bite the bullet and start to render a genuine albeit simple scene that can generate my shadows. This simplified scene will hopefully still allow me to incorporate literally hundreds of sprites. BTW, I only use sprites as once you enter the world of 3d models you're really never going to get a game out of the door!

Once again, thanks.
:)

This topic is closed to new replies.

Advertisement