Sign in to follow this  
agahpt

Z-Buffer Transparency/Alpha Blending and PixelShader

Recommended Posts

agahpt    122
Hi guys, this is my first post, but ive been reading the foruns for a while now. Now straight to my problem (wich has been frustrating me for the past week). I'm making a space RTS (hw2 inspired) and ive been having some wierd graphics issues with my ship's engine trails hiding behind my selection circle, if you can see the picture you can notice the trail over the arrow hides behind transparent pixels of my celection circle. I draw the cicle using a simple pixel shader, and the trails are also pixel shaded. image -> http://img235.imageshack.us/img235/2496/bugf.jpg Currently i have two theories: 1. My pixel shadding is just wrong. 2. My approach to drawing the transparent parts is wrong Here are bits of the code that i think are important: Trail PS:
PS_Output PS(PS_Input input) {
    PS_Output output = (PS_Output)0;
	
	output.Color = tex2D(TrailTextureSampler, input.TextureCoords) * input.Color;
	
	return output;
}

technique Base {
	pass Pass0 {
		ZEnable = true;
		
		AlphaBlendEnable = true;
		SrcBlend = SrcAlpha;
		DestBlend = InvSrcAlpha;
		
		CullMode = None;
		
		VertexShader = compile vs_3_0 VS();
		PixelShader = compile ps_3_0 PS();
	}
}
Selection circle PS:
PS_Output mainPS(PS_Input input) {
	PS_Output output = (PS_Output)0;
	
	float val = pow(input.TextureCoords.x - .5, 2) + pow(input.TextureCoords.y - .5, 2);
	
	if (.25 - Width * 0.01 * (1/Size) < val && val < .25) {
		output.Color = float4(Color);
	} else {
		output.Color = float4(0,0, 0, 0);
	} 

	return output;
}

technique Base {
	pass Pass0 {
		ZEnable = true;
		
		AlphaBlendEnable = true;
        SrcBlend = SrcAlpha;
        DestBlend = InvSrcAlpha;

		CullMode = None;
		
		VertexShader = compile vs_3_0 mainVS();
		PixelShader = compile ps_3_0 mainPS();
	}
}
Hopping for an answer to my nightmare. Thanks for reading anyway :)

Share this post


Link to post
Share on other sites
Evil Steve    2017
I assume the selection object is actually a solid circle with a transparent texture applied?

You usually disable Z-writes when rendering transparent geometry; otherwise the pixels will be written to the Z buffer even if the pixel is completely transparent - that'll cause the effect you're seeing.

Share this post


Link to post
Share on other sites
agahpt    122
Quote:
Original post by Evil Steve
I assume the selection object is actually a solid circle with a transparent texture applied?

You usually disable Z-writes when rendering transparent geometry; otherwise the pixels will be written to the Z buffer even if the pixel is completely transparent - that'll cause the effect you're seeing.


Worked like a charm :) Ithought about that solution too but it seemed too simple. Shame on me.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this