1
\$\begingroup\$

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)

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

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.

\$\endgroup\$
5
  • \$\begingroup\$ 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 \$\endgroup\$ Commented Apr 4, 2013 at 10:53
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Apr 4, 2013 at 15:48
  • \$\begingroup\$ 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.) \$\endgroup\$ Commented Apr 5, 2013 at 5:35
  • \$\begingroup\$ @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. \$\endgroup\$ Commented Apr 5, 2013 at 9:22
  • \$\begingroup\$ @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. \$\endgroup\$ Commented Apr 5, 2013 at 12:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .