Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.