Problem with alpha blending in XNA
Hi i have a background and two png sprites I want to make this effect using the provided background and sprites using XNA 3.1
I'm doing something wrong because i only get this As you noticed its not the effect i wanna do It is possible d开发者_开发知识库o this effect with a few lines of code using alpha blending in XNA 3.1? A practical example would be really great!First, render textures that contain the shapes that you want to be transparent to texture A. The textures containing the shapes should contain black shapes, on a transparent background -- easily constructed with image editing software like Photoshop.
Then take texture A and draw it over top of your scene using an effect (an HLSL shader) that does:
output = float4(0, 0, 0, A.r);
Effectively making the output image's alpha lower where A is darker.
The image will have clear portions where you drew your shapes on A, and will be black everywhere else.
Here are the details of the shader code:
sampler TextureSampler : register(s0);
float4 PS(float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
float4 Color = tex2D(TextureSampler, texCoord);
Color = float4(0, 0, 0, Color.r);
return Color;
}
technique Vicky
{
pass P0
{
PixelShader = compile ps_2_0 PS();
}
}
If you want a solution without shader.
You first need your fog of war textures to be black with the transparent parts as White.
- Render your map and entity normally, to a RenderTarget2D
- Clear your background to black
- Start sprite batch with Additive blend
- Render you fog of war textures
- Start a new sprite batch with Multiply blend
- Render your map RenderTarget2D on top of the whole screen
精彩评论