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.

I'd like to apply a simple few masks to few images.

The first mask I'd like to implement is mask like:

XXXOOO

I mean, that on the right everything is masked (to black), and on the left everything is stayed without changes.

The second mask I'd like to implement is glow mask. I mean something like this:

    O
  O***O
 O**X**O
  O***O
    O

What I mean, is a circle mask, which in the center everything is saved without changes, and going outside the circle everything is starting to be black

The last mask is irregular mask. For example like this:

  OOO*
 O**X**O
  OO**OO**O
    OO*X*O
      O*O
       O

Where:
O - to black
* - to gray
X - without changes

I've read, how to apply distortion pixel shader in XNA: msdn

Could you explain me how to apply mute mask on an image? (mask will be grayscale)

share|improve this question

1 Answer 1

How about, after you finished drawing everything else, you draw a sprite that covers the entire viewport (can be a rectangle spanning from (-1,-1) to (1,1), and without a perspective matrix), with z-buffer disabled, alpha blending enabled, and a simple texturing shader, and you set your mask to the alpha value of your texture?

That's what I do to implement fade in/fade out effects in my games.

share|improve this answer
    
Could you add some code for shaders? I'm new to shaders. A code that uses bitmap mask (gray-scale), where black will be alpha=0, and white alpha=1. Gray-scale color will be alpha=gray-scale-value –  Michał Bożydar Pawłowski Apr 4 '13 at 10:53
    
If you already have a shader that can do basic texture mapping, that's the shader you want to use. What I'm trying to say is that instead of thinking about masks, think about an overlay, like putting one layer above another in photoshop. –  Panda Pajama Apr 4 '13 at 15:48
    
This question encouraged me to view it by having an accurate and interesting title. Your answer that suggests a workaround may be correct for the poster's specific case, but I hope an answer appears for the general case of using a mask effectively. The spirit of SO is to provide authoritative technical answers to problems, not to troubleshoot and fix (avoid?) one particular use case. (Although we do see a lot of that on gamedev.) –  Seth Battin Apr 5 '13 at 5:35
    
@SethBattin: what is the general case then? if the purpose is to prevent some pixels from showing, this works for all cases I can think of. –  Panda Pajama Apr 5 '13 at 9:22
    
@PandaPajama I must have been looking at it too late at night. I recall a complete different answer than the one I'm seeing right now, but obviously you haven't edited it because I can't change my vote. I apologize for the mistake. –  Seth Battin Apr 5 '13 at 12:36

Your Answer

 
discard

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.