Jump to content
  • Advertisement
Sign in to follow this  
Spa8nky

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

This topic is 3124 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
Those settings look correct to me.

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Awesome detective work you two!

The problem HLSL line now reads:

Output.Color.a *= xGUI_Transparency;

and everything works great! :D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!