Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This question already has an answer here:

I have game situation as shown in picture:

enter image description here

  • Red dot: player
  • Brown dot: obstacle ( rock, tree, etc)
  • Grey: non visible area ( under fog of war)

My question is: how can I draw that kind of shape, changed dynamically, with XNA 4.0. I can calculate each point of this shadow polygon. I would avoid drawing it pixel by pixel due to performance reasons, maybe particles? But i won't have sharp edges with this technique. Any tips?

share|improve this question
    
The technique is the same as rendering shadows (many resources online). The difference is that instead of rendering the gray area as a shadow, you're using it as a mask to hide parts of the green area. –  MattDavey Jun 14 '11 at 13:50
    
I don't know if it also exists under XNA, but with DirectX (and OpenGL I guess) you can use the stencil buffer to achieve exactly that effect. –  Heandel Jun 14 '11 at 13:55
    
@Anko this duplicate close vote leads to a chain of duplicate links, and it ends up in a closed question with no answers. That doesn't seem right. –  Seth Battin Mar 11 at 5:50
    
@Seth You're right. I meant to close them all as a duplicate of this one, which I think has the clearest phrasing and a clear (if somewhat incomplete) answer. Byte seems to have closed it as a duplicate of a much vaguer question for some reason. (I've voted to reopen it and added my reasons in the comments there.) –  Anko Mar 11 at 14:43
add comment

migrated from stackoverflow.com Jun 15 '11 at 0:36

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Anko, Byte56 Mar 11 at 23:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

See here for an in-depth tutorial/example of doing it in HLSL (shader) code.:

http://www.catalinzima.com/2010/07/my-technique-for-the-shader-based-dynamic-2d-shadows/

If you want sharp edges remove the final blur step.

share|improve this answer
    
+1 Thats right 2D shadow maps are the coolest solution :) –  Notabene Jun 15 '11 at 1:31
add comment