Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

migrated from 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 '14 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.

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 '14 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 '14 at 14:43

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

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