I've read a lot of tutorials, but it just doesn't seem to work. Here's the code as suggested by a tutorial, using the built-in AlphaTestEffect class:
Matrix projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, 1); Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0); alphaTest = new AlphaTestEffect(GraphicsDevice); alphaTest.VertexColorEnabled = true; alphaTest.DiffuseColor = Color.White.ToVector3(); alphaTest.AlphaFunction = CompareFunction.Greater; alphaTest.ReferenceAlpha = 128; alphaTest.World = Matrix.Identity; alphaTest.View = Matrix.Identity; alphaTest.Projection = halfPixelOffset * projection;
Then this object is just passed in to the SpriteBatch.Begin method. The result: Nothing appears on the screen, whereas the exact same code that doesn't pass in the alphaTest object renders correctly.
Note that this is the case even with CompareFunction.Always! (I tried CompareFunction.Never too in case I misunderstand the comparison order).
I am following this tutorial, but I've also seen that same code elsewhere. The tutorial has a downloadable file for XNA 4.0 to demonstrate it. I downloaded and tried it, and - It doesn't work. No craters show up. So what the heck is going on?