[SOLVED] How to not render the masking texture when masking with the stencil buffer

I’ve implemented alpha masking after following this tutorial - https://medium.com/@sfranks/i-originally-wrote-this-for-the-best-way-to-mask-2d-sprites-in-xna-game-development-stack-949cf7bd7421

However it doesn’t quite work how I need. This must be a fairly common use case for masking so I wonder if there is an easy fix.

Screenshot

This image shows the loading bar from the beginning of the game. It’s working nicely to reveal the fill texture, but its also rendering the mask itself. Currently the stencil states are setup as per the tutorial, and works as expected really.

Is there a way to not render the white of the masking texture?

Ahh damn, as usual, I spent ages trying to get this working and the second I make a post, I work it out :slight_smile:

Found this snippet on stackoverflow

//Disable writing to screen BlendState disableColorBufferState = new BlendState(); disableColorBufferState.ColorWriteChannels = ColorWriteChannels.None; _mask.Material.blendState = disableColorBufferState;

At least I know how to do custom blend states now.