Sign in to follow this  
matthughson

What Shadow Tutorial Did It For You?

Recommended Posts

Hey Guys, I'm starting to do a little bit of research on implementing real-time shadows, and there are a ton of resources, but I'm wondering what tutorial or article explained a technique that just clicked for you. I'd prefer something as simple as posible (shadow quality isn't a high priority), and something I can do in one lump pass, rather than on each mesh induvidually (if that's posible). I'm using DirectX 9, so anything D3D specific is a major plus. I'd prefer to be able to just drop a function into my engine and just call it right before I flip the buffers (I'm not so much interested in learning how/why it works at the moment, just getting it to work is the goal). Thanks! Matt

Share this post


Link to post
Share on other sites
<shameless-plug>
I wrote an article for this very site that is fairly simple Z-Pass shadow volumes: An Example of Shadow Rendering in Direct3D 9. I'd recommend it as a starting point - it's not quite complete enough to be "generally".
</shameless-plug>

I highly recommend The Theory of Stencil Shadow Volumes if you're interested in SV's - that article was really useful to me when I first started messing with them [smile]

hth
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by dawidjoubert
I Second this Request... Mine is specific to a RTS game so once again im going 2 have +30 units on-screen so i need fast shadows

Any suggestions

From all the discussions (and my own thoughts on the matter) it really depends on the characteristics of your game.

  • What types of lights (point, spot, directional?)
    - Directional lights are easy for shadow maps, point lights can be tricky
  • How many of these lights
    - Can impact greatly on the number of passes required, hence multiplying any per-pass performance problems
  • How geometrically complex are your objects?
    - Lots of complex units can make for a heavy load on a SV implementation
  • Fill rate characteristics?
    - If you're using lots of fancy pixel shader effects then you probably want to pick the least fill-rate intensive shadowing algorithm
  • CPU usage characteristics?
    - If it's mostly GPU work then you could compute shadow volumes on the CPU and make the most of parallelism. Conversely, high CPU loads might make it better to look at shadow implementations that run entirely on the GPU.


    When I first looked into shadowing, it was all about SV's - but SM's have really matured now, and I personally think that I'll be using them in my current/future work.

    hth
    Jack

    Share this post


    Link to post
    Share on other sites
    I achieved some respectable results using D3DXMatrixShadow Function. You send the function a light direction vector and a plane position, and it produces a matrix.

    When applied to your mesh, it flattens it out.

    By setting your texture to 50% alpha blended grey before rendering the shadow helps, then you just render the object as normal over the top!

    Simon

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by sipickles
    I achieved some respectable results using D3DXMatrixShadow Function. You send the function a light direction vector and a plane position, and it produces a matrix.

    When applied to your mesh, it flattens it out.

    By setting your texture to 50% alpha blended grey before rendering the shadow helps, then you just render the object as normal over the top!

    Simon


    That work on non-flat surfaces?

    Matt

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by jollyjeffers
    When I first looked into shadowing, it was all about SV's - but SM's have really matured now, and I personally think that I'll be using them in my current/future work.


    Exactly what type of shadow maps do you think of?

    It's just my personal opinion, but after reading through perspective shadow maps, light space perspective shadow maps, trapezoidal shadow maps, etc, I still have the feeling that they're still trying to hack around something that is not really suitable for the purpose.
    If they can manage to use the shadow map efficiently (to not have huge shadow texels in large scenes), then another problem arises: shadow edges will change when the light or camera changes. In the result sections, the best thing authors usually say is that the algorithm is way better than the original shadow map algo, and that is does not produce that many artifatcs as the predecessors.

    Maybe I think like this because I'm a shadow volume fan (although I feel it is very painful sometimes)... I really hope there will be another (a third) way to do it :)

    kp

    Share this post


    Link to post
    Share on other sites
    Of all the implementations you can use Shadow Maps for, I think an RTS game is one of the simplest. Usually, theres a very small range of z values your shadow casters can be in, unless you're doing something fancy. This would greatly ease on shadow mapping.

    On the other hand, an RTS would probably mean any shadow you have is quite small in pixel size. This would also make Shadow Volumes run faster, especially on Fill-Rate limited cards (usually the lower end cards). Also, I think soft shadows are less of an issue if the shadow isn't too big.

    Guess it's pretty much up to what you feel more comfortable with doing.

    Share this post


    Link to post
    Share on other sites
    The book shader3 talks about possion disk shadow blur, which has to be the easiest to implement.

    Basically you render the object to a render texture (in solid black with white background), then apply possion disk filter (using a shader) to the texture, then project back to the scene.

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by kovacsp
    Quote:
    Original post by jollyjeffers
    When I first looked into shadowing, it was all about SV's - but SM's have really matured now, and I personally think that I'll be using them in my current/future work.


    Exactly what type of shadow maps do you think of?

    Hadn't really gotten that far - as much because they're fairly usage-dependent, and I don't know quite what I'll be using them for yet [smile]

    Quote:
    Original post by kovacsp
    It's just my personal opinion, but after reading through perspective shadow maps, light space perspective shadow maps, trapezoidal shadow maps, etc, I still have the feeling that they're still trying to hack around something that is not really suitable for the purpose.

    Yup, I get exactly the same feeling. Shadow Volumes might be a bit "old school" now, but they do come across as being a more general-purpose one-size-fits-all approach.

    Then again, they do seem to look much nicer when done properly...

    Quote:
    The book shader3 talks about possion disk shadow blur, which has to be the easiest to implement.

    Basically you render the object to a render texture (in solid black with white background), then apply possion disk filter (using a shader) to the texture, then project back to the scene.

    That sounds quite a lot like this article...

    I was wondering if that approach could be applied to stencil volumes actually. Not 100% sure you can do it easily though due to the whole stencil buffer part [smile]

    Share this post


    Link to post
    Share on other sites
    Well, it clicked for me with a CPU-based shadow volume tutorial on Code Sampler. It may not be very efficient and you'll need to generate a shadow volume for each shadow-casting mesh, but it's fairly simple to implement. The code itself is well documented and a bit optimized, so it's at least a good start into shadow rendering.

    Here's the link: http://www.codesampler.com/dx9src/dx9src_7.htm (at the bottom of the page)

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by jollyjeffers
    That sounds quite a lot like this article...

    I was wondering if that approach could be applied to stencil volumes actually. Not 100% sure you can do it easily though due to the whole stencil buffer part [smile]


    Hey, I'm glad you asked. It is possible, and I did it already! [smile]
    Have a look at my publication on this topic: Soft Edged Stentil Shadow in CAD Applications

    kp

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by kovacsp
    Quote:
    Original post by jollyjeffers
    That sounds quite a lot like this article...

    I was wondering if that approach could be applied to stencil volumes actually. Not 100% sure you can do it easily though due to the whole stencil buffer part [smile]


    Hey, I'm glad you asked. It is possible, and I did it already! [smile]
    Have a look at my publication on this topic: Soft Edged Stentil Shadow in CAD Applications

    kp

    That's an interesting paper. Thanks for pointing it out! I've bookmarked it for proper-reading later on [smile]

    Although, seems like the performance hit was heavy... 274fps -> 68fps [oh]

    Jack

    Share this post


    Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

    Sign in to follow this