• Advertisement
Sign in to follow this  

Partial Alpha / Blend problems

This topic is 2108 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:
[img]http://i.imgur.com/U8RvS.png[/img]

As you can see the glow-effect looks like shit. Here's the image for the glow-effect:
[img]http://i.imgur.com/bL5Ke.png[/img]
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:
[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 );
}
}[/code]

Share this post


Link to post
Share on other sites
Advertisement
[quote name='Geoffrey' timestamp='1334271973' post='4930742'] What texture format is the glow effect stored in? [/quote]
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
[quote name='Geoffrey' timestamp='1334316776' post='4930922']
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.
[/quote]

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