Question

I'm making something with XNA 3.1, and I'm attempting to create 2D Ribbon trails using DrawUserPrimitives. My algorithm simply adds new vertices each frame (provided some movement occurs), and also iterates through the vertices and fades them out as it goes, removing unneeded ones. This works quite well, except that I'm using a SpriteBatch for a lot of the other graphics. Now, I'm drawing this entire screen to a RenderTarget2D (for various reasons, and I cannot avoid it), and I'm getting this odd alpha issue.

The issue I'm having looks like this:

Trail is clearly not behaving correctly

This should be a white trail that fades out as it goes. Clearly this isn't happening. Instead it's fading to the clear colour of the graphics device. When drawing this trail, I suspend the SpriteBatch (by calling End(), followed by Begin() once the drawing is done), so that I can get the depth correct. The effect I'm using to draw the primitive is just a BasicEffect with nothing special in it, and the code to initialise the SpriteBatch is here:

        spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);
        graphics.GraphicsDevice.RenderState.SeparateAlphaBlendEnabled = true;
        graphics.GraphicsDevice.RenderState.AlphaDestinationBlend = Blend.One;
        graphics.GraphicsDevice.RenderState.AlphaSourceBlend = Blend.SourceAlpha;
        graphics.GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha;
        graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha;

The settings after initialising the SpriteBatch ensure correct colouring for semi-transparency in the RenderTarget texture. My guess would be that something here is causing the issue, but I'm not sure what. If anyone could help me with this, I'd be very grateful.

Cheers.

Was it helpful?

Solution

Oh... I fixed it. Needed to swap out SaveStateMode.SaveState with SaveStateMode.None.

Still wondering why I can't get antialiasing on it, though...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top