Jump to content
  • Advertisement
Sign in to follow this  
MaloW

Partial Alpha / Blend problems

This topic is 2288 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

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

As you can see the glow-effect looks like shit. Here's the image for the glow-effect:
bL5Ke.png
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 );
}
}

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

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?

Share this post


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

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!