Jump to content

  • Log In with Google      Sign In   
  • Create Account


Partial Alpha / Blend problems


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 MaloW   Members   -  Reputation: 100

Like
0Likes
Like

Posted 12 April 2012 - 09:34 AM

Hi. Me and a few friends are making a game and we're having some problem with the alpha / blending.
What we're getting:
Posted Image

As you can see the glow-effect looks like shit. Here's the image for the glow-effect:
Posted Image
As you can see the alpha isnt correctly blending the parts where the alpha is pretty low in the image. The images are drawn back-to-front (there's 3 of them, the base texture, the text, and the glow), and they are drawn by expanding a quad in the GS.

Shader-code:
Texture2D tex2D;
SamplerState linearSampler
{
	Filter = MIN_MAG_MIP_LINEAR;
	AddressU = Wrap;
	AddressV = Wrap;
};

BlendState SrcAlphaBlendingAdd
{
	 BlendEnable[0] = TRUE;
	 SrcBlend = SRC_ALPHA;
	 DestBlend = INV_SRC_ALPHA;
	 BlendOp = ADD;
	 SrcBlendAlpha = ZERO;
	 DestBlendAlpha = ZERO;
	 BlendOpAlpha = ADD;
	 RenderTargetWriteMask[0] = 0x0F;
};

DepthStencilState DisableDepthWrite
{
	DepthEnable = FALSE;
	DepthWriteMask = ZERO;
};

cbuffer EveryFrame
{
	float posx;
	float posy;
	float dimx;
	float dimy;
}

RasterizerState NoCulling
{
	 CullMode = NONE;
};

VSIn VSScene(VSIn input)
{
	 return input;
}

[maxvertexcount(4)]
void GS( point VSIn input[1], inout TriangleStream<PSSceneIn> triStream )
{
	 PSSceneIn output;
	 output.opacity = 1.0f;

	 //create sprite quad
	 float4 basepos = float4(posx, posy, 0, 1);
	 //bottom left
	 output.Pos = basepos + float4(0, dimy, 0, 0);
	 output.tex = float2(0,1);
	 triStream.Append(output);

	 //bottom right
	 output.Pos = basepos + float4(dimx, dimy, 0, 0);
	 output.tex = float2(1,1);
	 triStream.Append(output);
	 //top left
	 output.Pos = basepos;
	 output.tex = float2(0,0);
	 triStream.Append(output);
	 //top right
	 output.Pos = basepos + float4(dimx, 0, 0, 0);
	 output.tex = float2(1,0);
	 triStream.Append(output);
}

float4 PSScene(PSSceneIn input) : SV_Target
{
	 float4 tex = tex2D.Sample(linearSampler, input.tex);
	 return tex;
}

technique11 BasicTech
{
	pass p0
	{
	   // Set VS, GS, and PS
	 	 SetVertexShader( CompileShader( vs_4_0, VSScene() ) );
	 	 SetGeometryShader( CompileShader( gs_4_0, GS() ) );
	 	 SetPixelShader( CompileShader( ps_4_0, PSScene() ) );
	
	 	 SetDepthStencilState( DisableDepthWrite, 0 );
	 	 SetRasterizerState( NoCulling );
	 	 SetBlendState( SrcAlphaBlendingAdd, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
	}
}


Sponsor:

#2 Geoffrey   Members   -  Reputation: 534

Like
1Likes
Like

Posted 12 April 2012 - 05:06 PM

What texture format is the glow effect stored in?
The Trouble With Robots - www.digitalchestnut.com/trouble

#3 MaloW   Members   -  Reputation: 100

Like
0Likes
Like

Posted 13 April 2012 - 03:53 AM

What texture format is the glow effect stored in?

Ah! I was using DXGI_FORMAT_BC1_UNORM, I changed it to DXGI_FORMAT_R32G32B32A32_FLOAT and now it works great, Thanks! :D

#4 Geoffrey   Members   -  Reputation: 534

Like
1Likes
Like

Posted 13 April 2012 - 05:32 AM

Glad I could help.

By the way, R32G32B32A32_FLOAT is a huge format and probably isn't widely supported - I suggest you use something a bit lighter like A8R8G8B8.
The Trouble With Robots - www.digitalchestnut.com/trouble

#5 MaloW   Members   -  Reputation: 100

Like
0Likes
Like

Posted 13 April 2012 - 06:38 AM

Glad I could help.

By the way, R32G32B32A32_FLOAT is a huge format and probably isn't widely supported - I suggest you use something a bit lighter like A8R8G8B8.


hmm ok, will R8G8B8A8 be able to hold all information that a normal .png image has without any loss in quality?

#6 Geoffrey   Members   -  Reputation: 534

Like
1Likes
Like

Posted 13 April 2012 - 10:03 AM

Yes, I believe that is exactly what you get in a PNG file.
The Trouble With Robots - www.digitalchestnut.com/trouble

#7 MJP   Moderators   -  Reputation: 10845

Like
2Likes
Like

Posted 13 April 2012 - 02:57 PM

BC1 only provides you with 1 bit of alpha, which is why you get that weird "stenciled out" look with that format. BC2 and BC3 both allow for a full range of alpha values, so you should get much better results with either of them. Otherwise if you don't want to use compression R8G8B8A8_UNORM will give you sufficient precision for a .PNG file.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS