• Create Account

### #Actualphil_t

Posted 02 October 2012 - 11:02 AM

You can supply an AlphaTestEffect in the SpriteBatch.Begin method. But you need to set it up with a special Projection matrix:

			// Set up an AlphaTestEffect with a Projection that allows it to be used with SpriteBatch.
Matrix projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight, 0, 0, 1);
Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);
alphaTestEffect = new AlphaTestEffect(GraphicsDevice);
alphaTestEffect.VertexColorEnabled = false;
alphaTestEffect.AlphaFunction = CompareFunction.Greater;
alphaTestEffect.ReferenceAlpha = 0;
alphaTestEffect.World = Matrix.Identity;
alphaTestEffect.View = Matrix.Identity;
alphaTestEffect.Projection = halfPixelOffset * projection;


I put a little project here that shows how to use this to make a "clock" effect.

The only downside is that since you're using alpha to control the "angle" at which the "clock" is visible, you can't really use alpha blending. That's fine if you're ok with an opaque background.

Otherwise, you'd need to use a second "alpha texture" to control the angle; that would require writing a custom shader.

### #1phil_t

Posted 02 October 2012 - 10:59 AM

You can supply an AlphaTestEffect in the SpriteBatch.Begin method. But you need to set it up with a special Projection matrix:

		    // Set up an AlphaTestEffect with a Projection that allows it to be used with SpriteBatch.
Matrix projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight, 0, 0, 1);
Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);
alphaTestEffect = new AlphaTestEffect(GraphicsDevice);
alphaTestEffect.VertexColorEnabled = false;
alphaTestEffect.AlphaFunction = CompareFunction.Greater;
alphaTestEffect.ReferenceAlpha = 0;
alphaTestEffect.World = Matrix.Identity;
alphaTestEffect.View = Matrix.Identity;
alphaTestEffect.Projection = halfPixelOffset * projection;


I put a little project here that shows how to use this to make a "clock" effect.

PARTNERS