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

How would I apply a mask for pixel shading effect to restrict it only to some part of image? For example I have a height tile:

enter image description here

Now I want to apply the effect only on the tile-shape of this height-tile with some sort of masking:

enter image description here

Therefore, how would I restrict the pixel shading function boundary using masking?

share|improve this question
up vote 2 down vote accepted

You could achieve this through (at least) two different methods. One is to use the stencil buffer, this way you could draw arbitrary shapes in pictures and use those as masks. The other option is to make the mask in a vertex buffer and thus draw only the wanted part directly in the first call.

Both would work fine, in this case the second type would probably be simplest and quickest to setup, but the first one allows a bit more artistic freedom at the cost of some complexity. Here is a pretty good example for stencil buffering and what it can do.

share|improve this answer
I have always wonder what's stencil buffer is for, how it is all clarified.. Thanks! – user1542 May 18 '12 at 12:59

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.