Rendertarget alpha is always 0?

I’m trying to cache some item renders for my game during initialization for UI purposes. I’ve got the models rendering fine, but they seem to be extremely white and semi transparent.

See top left and hotbar.

Im not sure whether this is important or not, but I’m drawing everything to a RenderTarget2D every frame for post processing purposes.

This is my block preview renderer. The code is designed such that it returns a Texture2D containing the rendered item preview

static BasicEffect effect = null;

public static Texture2D Render(BlockModel itemModel, Matrix View, Matrix World)
{
	if (effect == null)
	{
		effect = new BasicEffect(GameClient.Instance.GraphicsDevice);
	}
	//Create the projectionMatrix
	Matrix projection = Matrix.CreateOrthographic(64, 64, 0.1f, 1024f);
			
	//Initialise the render target
	RenderTarget2D targetTexture = new RenderTarget2D(GameClient.Instance.GraphicsDevice, 64, 64, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.DiscardContents);

	VoxelClient.Graphics.GraphicsDevice.BlendState = BlendState.Opaque;
	VoxelClient.Graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;

	GameClient.Instance.GraphicsDevice.SetRenderTarget(targetTexture);
	GameClient.Instance.GraphicsDevice.Clear(Color.Transparent);

	if (itemModel.voxels.Length > 0)
	{

		#region Mesh Construction
		List<VertexPositionColorTexture> vertices = new List<VertexPositionColorTexture>();
		//Construct vertices here. Not putting the code here because its not the issue
		#endregion

		//Prepare the effect
		//rotation
		effect.World = World;
		//Camera
		effect.View = View;
		effect.Projection = projection;
		//Texturing
		effect.VertexColorEnabled = true;
		effect.TextureEnabled = true;
		effect.Texture = TextureManager.terrain;

		//Double sided rendering
		RasterizerState stat = new RasterizerState();
		//stat.CullMode = CullMode.None;
		VoxelClient.Graphics.GraphicsDevice.RasterizerState = stat;

		//Point scaling
		VoxelClient.Graphics.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;

		//Draw the tris
		foreach (var pass in effect.CurrentTechnique.Passes)
		{
			pass.Apply();
			VoxelClient.Graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices.ToArray(), 0, vertices.Count / 3);
		}
	}

	GameClient.Instance.GraphicsDevice.SetRenderTarget(null);

	//Make texture opaque
	Texture2D opaqueTexture = new Texture2D(GameClient.Instance.GraphicsDevice, targetTexture.Width, targetTexture.Height);

	Color[] pixelData = new Color[targetTexture.Width * targetTexture.Height];
	targetTexture.GetData(pixelData);

	//Make the texture opaque
	for (int i = 0; i < pixelData.Length; i++)
	{
		Color col = pixelData[i];
		//Console.WriteLine("A at (" + (i % opaqueTexture.Width) + ", " + (i / opaqueTexture.Width) + "): " + col.A);
		if (col.A == 0)
		{
			//col.A = 255;
		}
		pixelData[i] = col;
	}

	opaqueTexture.SetData(pixelData);

	return opaqueTexture;
}

When the Render is called - I’m assuming there aren’t any other device state changes and drawing it normally with this basic-effect setup works fine on the regular backbuffer?
May also look at color format - like whether using premultiplied-alpha or alpha-blending and also check that status in the properties in content for the model texture being used?
Just some ideas.

Does the spritebatch initialisation have anything to do with this? I disabled textures and forced it to opaque but that doesn’t fix anything…

_spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise);

I think the spritebatch is using Additive blending, but I’m not sure if it is.

I tried fixing it, and managed but the solution is far from elegant. I added more code upon initialisation to take the terrain texture, and set its rgba to white opaque if the alpha is anything but 0. Now when rendering the block i define a second rendertarget, same properties as the first one, disable vertex colors and change the texture to this white terrain texture. When rendering the block previews, I clear the color to black and render the block with the white terrain texture (using a white texture to account for any transparent parts in the texture). Once I render that, i check if the new render target’s pixel color at the current position is white, and if it is, i make the pixel fully opaque, otherwise i make it completely transparent.

I know its not the best solution (eg semi transparent blocks will have a black background), but its good enough for now. I’m still going to try to fix the way this renders, as I’d love to support semi transparent textures in the hotbar.