waddwa

I have problems with using alpha blending in a HLSL effect. Here is the technique I am using:

texture g_MeshTexture; // Color texture for mesh
float4x4 g_mWorldViewProjection; // World * View * Projection matrix
float4 Diffuse;
// Texture samplers
sampler MeshTextureSampler =
sampler_state
{
Texture = <g_MeshTexture>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;

};

struct VS_OUTPUT
{
float4 Position : POSITION; // vertex position
float2 TextureUV : TEXCOORD0; // vertex texture coords
float4 Diffuse : COLOR0; // vertex diffuse color
};
VS_OUTPUT RenderSceneVS( float4 vPos : POSITION,
float2 vTexCoord0 : TEXCOORD0,
float4 vColor : COLOR0

)
{
VS_OUTPUT Output;
Output.Position = mul(vPos, g_mWorldViewProjection);
Output.TextureUV = vTexCoord0;
Output.Diffuse = vColor;
return Output;
}
struct PS_OUTPUT
{
float4 RGBColor : COLOR0; // Pixel color
};

PS_OUTPUT RenderScenePS( VS_OUTPUT In
)
{
PS_OUTPUT Output;

Output.RGBColor = tex2D(MeshTextureSampler, In.TextureUV);
Output.RGBColor.a=0.4;

return Output;
}

technique RenderSceneWithTexture1Light
{

pass P0
{
AlphaBlendEnable = true;
SrcBlend = SrcAlpha;
DestBlend = InvSrcAlpha;


VertexShader = compile vs_1_1 RenderSceneVS();


}
}


I tried many combinations and it seems that when I set blending values to ONE, ONE there seems to be some actual aplha blending, but this isn't what I need. However, both SrcAlpha and InvSrcAlpha seem to have absolutely no effect. Anyone got an idea what's wrong Needless to say I'm new to this. Thx in advance.



Re: Game Technologies: Graphics Alpha Blending in HLSL- help

Asesh

Are you trying to render a texture with alpha channel If that specific image has alpha channel then it should render fine but seems like that's not what you are trying to do. Maybe you are you just trying to render other resources or meshes. If it's so then then you are doing it wrong




Re: Game Technologies: Graphics Alpha Blending in HLSL- help

inezdias

To Emphasize Asesh's post: One, One works when the source has no alpha, but black background.

SourceAlpha, InvSourceAlpha works _only_ when there's a real alpa channel in the source. (Check with the DX texture tool.)