Blending textures

I’m working on something that requires a sprite to smoothly blend from one texture to another.

The textures are the same size, rotation, scale etc. I can slowly ramp down all the color values on one and ramp up the values of another and the blend is lovely. However, these textures are now being drawn with opacity throughout the transition so everything behind shows through.

I’ve tried drawing a black mask under the transitional objects,(on top of the background objects) but this doesn’t seem to have much affect, if any. Do I need to mix these textures into a 3rd texture and then display that result with full alpha?

And the draw layer… I’ve read somewhere you can assign any draw layer value between 0 and 1 as a single, so .0001, .001, .01 are all valid. So with the command SpriteBatch.Begin(sortmode:=SpriteSortMode.FrontToBack) why do layers .3 and .3001 swap draw order randomly? It seems to happen more when the code draws objects on a lesser layer than something else already sent, ie:
Draw on layer .301
Draw on layer .302
Draw on layer .3 < This layer randomly get’s drawn on top of .302. If doesn’t flicker madly, it’ll swap back and forth a couple of times a second.

Thanks folks.

tell us more about the blending sprite - does it have an alpha cutout? What blending mode have you used?

You could try this way possibly

tex a -> base
tex b -> target

a -> blend percent

tex a ( rgb * (1-a), 1)
tex b ( rgb, a)

I’m using all the channels. I ramp one down from 255,255,255,255 to 0,0,0,0 on all channels while the other is coming up from 0,0,0,0 to 255,255,255,255. To calculate I use 10*DeltaTime (Frame time) for each frame, then multiply this by an arbitrary value depending on the game state.

I have to use all channels else there is a brightness problem which gives a huge ‘pop’ when I stop drawing the fading texture. This gives a beautifully smooth fade from one to the other.

I’ve managed to fix the problem but I’m really not sure why. I added a blank value between each layer so the layer values are now .3 .3002 .3004 .3006 etc. Why this has worked I honestly don’t know. It’s possible I had a rogue value somewhere drawing 2 items the same layer, but if that was the case I’d still have the same problem as no layer is decided in hard code.

Anyway, it works now. Thanks for getting back to me. :slight_smile: