C# directx TransformedColor字段alpha值

C# directx TransformedColor字段alpha值,c#,colors,directx,alpha,C#,Colors,Directx,Alpha,我用的是C#。我需要使用DirectX绘制点,它们应该是半透明的。我将顶点声明为TransformedColor,并将颜色值设置为: vertices[i].Color = Color.FromArgb(20,0,0,255).ToArgb(); 这应该是非常透明的蓝色,但我得到的是不透明的蓝色。无论我对alpha值使用什么值,它总是完全不透明。 你知道为什么吗?我希望TransformedColor字段支持alpha值 提前谢谢 图纸代码为: device.Clear(ClearFlags

我用的是C#。我需要使用DirectX绘制点,它们应该是半透明的。我将顶点声明为TransformedColor,并将颜色值设置为:

 vertices[i].Color = Color.FromArgb(20,0,0,255).ToArgb();
这应该是非常透明的蓝色,但我得到的是不透明的蓝色。无论我对alpha值使用什么值,它总是完全不透明。 你知道为什么吗?我希望TransformedColor字段支持alpha值

提前谢谢

图纸代码为:

device.Clear(ClearFlags.Target, System.Drawing.Color.White, 1.0f, 0);

device.RenderState.AlphaBlendEnable = true;

device.RenderState.AlphaSourceBlend = Blend.SourceAlpha;

device.RenderState.AlphaDestinationBlend = Blend.InvSourceAlpha;

device.RenderState.BlendOperation = BlendOperation.Add;

CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[N];

for (int i = 0; i < N; i++)
{
   vertices[i].Position = new Vector4(2.5f + (g_embed[i, 0] - minx) * (width - 5.0f) / maxx, 2.5f + (g_embed[i, 1] - miny) * (height - 5.0f) / maxy, 0f, 1f);//g_embed, minx, width,maxx, miny,height, maxy are all predifined

   vertices[i].Color = Color.FromArgb(20, 0, 0, 255).ToArgb();
}

 device.BeginScene();

 device.VertexFormat = CustomVertex.TransformedColored.Format;

 device.DrawUserPrimitives(PrimitiveType.PointList, N, vertices);

 device.EndScene();

 device.Present();

 this.Invalidate();
device.Clear(ClearFlags.Target,System.Drawing.Color.White,1.0f,0);
device.RenderState.AlphaBlendEnable=true;
device.RenderState.AlphaSourceBlend=Blend.SourceAlpha;
device.RenderState.AlphaDestinationBlend=Blend.InvSourceAlpha;
device.RenderState.BlendOperation=BlendOperation.Add;
CustomVertex.TransformedColor[]顶点=新CustomVertex.TransformedColor[N];
对于(int i=0;i
渲染状态用于预乘alpha。使用真实alpha通道需要以下设置():


它按照公式创建,其中a是颜色的alpha:a*SourceColor+(1-a)*DestColor

是否激活了alphablending并调整了相关的渲染状态?我添加了以下内容:device.RenderState.AlphaBlendEnable=true;device.RenderState.AlphaSourceBlend=Blend.One;device.RenderState.AlphaDestinationBlend=Blend.One;device.RenderState.BlendOperation=BlendOperation.Add;您使用哪种框架?XNA 3?我正在使用C#Directx 11。嗯,你的着色器怎么样?非常感谢你的帮助,但它仍然不起作用。。我使用的设置与您发布的完全相同,然后对于顶点,我使用了顶点[I].Color=Color.FromArgb(20,0,0255).ToArgb();但我仍然得到完全不透明。我对目的地的颜色有点困惑,这是我需要设置的颜色吗?谢谢!嗯,真遗憾:)你能展示一下你的绘图代码吗?也许你的附加顶点+声明会很有趣。目标颜色是你渲染到的目标曲面的颜色。嘿,再次感谢你的回复。我在原始帖子中添加了我的绘图代码。我想我可能犯了一些愚蠢的错误。。
graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true;
graphics.GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha;
graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha;
graphics.GraphicsDevice.RenderState.BlendFunction = BlendFunction.Add;