.dds sprite A8R8G8B8 draws with a black square surrounding it in game.

Started by
5 comments, last by Spa8nky 14 years, 5 months ago
I have a transparent sprite located here When I draw it in my GUI the sprite draws with a black background where the transparency should be. Have I set my alpha blending settings incorrectly or is something else wrong. Alpha Blend Settings:

		AlphaBlendEnable = true;	// Setup For Alpha Blending
		ZEnable = true;				// Setup For Alpha Blending
		ZWriteEnable = false;		// Setup For Alpha Blending
		
		SrcBlend = SrcAlpha;		// Normal Alpha Blending
		DestBlend = InvSrcAlpha;	// Normal Alpha Blending
		BlendOp = Add;				// Normal Alpha Blending
Thank you.
Advertisement
Those settings look correct to me.

Are you also drawing the alpha blended objects in far->near sorted order?
Because your image has alpha background, you could use alpha testing to only render the non-invisible part of the image

AlphaTestEnable = True;
AlphaFunc = GreaterEqual;
AlphaRef = 100;

That means anything with an alpha value less than or equal to 100 will not be rendered.

This can improve performance as it doesn't need to do the blend equation.
Quote:Original post by Adam_42
Those settings look correct to me.

Are you also drawing the alpha blended objects in far->near sorted order?


If I draw absolutely nothing else but the sprite then the problem still occurs.

My HLSL shader code is as follows:

//=============================================//----------- [XNA to HLSL Variables] ---------//=============================================float xGUI_Transparency;//=============================================//------------- [Texture Samplers] ------------//=============================================texture xTexture0;sampler textureSampler = sampler_state{	texture = <xTexture0>;		// Don't filter GUI sprites	magfilter = None;	minfilter = None;	mipfilter = None;		// No need for AddressU & AddressV};//=============================================//------------------ [Structs] ----------------//=============================================struct VertexToPixel{	float4 Position : POSITION;	float2 TexCoord	: TEXCOORD0;};struct PixelToFrame{    float4 Color 	: COLOR0;};//=============================================//------ Technique: Draw Transparent GUI ------//=============================================VertexToPixel PassThroughVertexShader(float4 inPos: POSITION0, float2 inTexCoord: TEXCOORD0){	VertexToPixel Output = (VertexToPixel)0;		Output.Position = inPos;	Output.TexCoord = inTexCoord;		return Output;}PixelToFrame TransparentGUI(VertexToPixel PSIn) : COLOR0{	PixelToFrame Output = (PixelToFrame)0;			    	float4 samplePos = tex2D(textureSampler, PSIn.TexCoord);    Output.Color = samplePos;    Output.Color.a = xGUI_Transparency;	return Output;}technique GUI_Transparent{	pass Pass0    {  					AlphaBlendEnable = true;	// Setup For Alpha Blending		ZEnable = true;				// Setup For Alpha Blending		ZWriteEnable = false;		// Setup For Alpha Blending				SrcBlend = SrcAlpha;		// Normal Alpha Blending		DestBlend = InvSrcAlpha;	// Normal Alpha Blending		BlendOp = Add;				// Normal Alpha Blending		      	VertexShader = compile vs_1_1 PassThroughVertexShader();        PixelShader  = compile ps_2_0 TransparentGUI();    }}


Maybe there is something in there that might shed some light on this problem?
In the pixel shader you have this line

Output.Color.a = xGUI_Transparency;


so the alpha value of every pixel you render will be xGUI_Transparency. You want the alpha value to be the alpha value of the image so this line is not needed.
As said above, you're overwriting the texture's alpha with your gui alpha value. You probably want to multiply the texture alpha and the GUI alpha, allowing for partial transparency of already partially transparent sprites.
Awesome detective work you two!

The problem HLSL line now reads:

Output.Color.a *= xGUI_Transparency;

and everything works great! :D

This topic is closed to new replies.

Advertisement