Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用Direct3D Alpha混合_C#_Direct3d_Alphablending_Blending - Fatal编程技术网

C# 如何使用Direct3D Alpha混合

C# 如何使用Direct3D Alpha混合,c#,direct3d,alphablending,blending,C#,Direct3d,Alphablending,Blending,我试图在混合平行六面体容器中显示所有三维对象。 所得结果不令人满意 第一个数字似乎是正确的 第二个是错误的 我将托管directx与c一起使用 初始化: DxDeviceArea.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, 1.0f, 1.0f, MaxSizeArea * 2); DxDeviceArea.Transform.View = Matrix.LookAtLH(new Vector3(0,

我试图在混合平行六面体容器中显示所有三维对象。 所得结果不令人满意

第一个数字似乎是正确的

第二个是错误的

我将托管directx与c一起使用

初始化:

DxDeviceArea.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, 1.0f, 1.0f, MaxSizeArea * 2);
DxDeviceArea.Transform.View = Matrix.LookAtLH(new Vector3(0, 0, MaxSizeArea / 2f), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
DxDeviceArea.RenderState.Lighting = true;
DxDeviceArea.RenderState.CullMode = Cull.CounterClockwise;
DxDeviceArea.RenderState.SourceBlend = Blend.SourceAlpha;
DxDeviceArea.RenderState.DestinationBlend = Blend.InvSourceAlpha;
DxDeviceArea.RenderState.AlphaBlendEnable = true;
DxDeviceArea.RenderState.BlendOperation = BlendOperation.Add;
DxDeviceArea.RenderState.AlphaTestEnable = true;
//Set light
DxDeviceArea.Lights[0].Type = LightType.Directional;
DxDeviceArea.Lights[0].Diffuse = Color.White;
DxDeviceArea.Lights[0].Direction = new Vector3(0, 0, -1);
DxDeviceArea.Lights[0].Enabled = true;
在渲染函数中,第一步是在对象内部绘制 第二个是绘制混合边界

在绘制第二个图形之前,我将cullmode从逆时针方向切换到无

DxDeviceArea.RenderState.CullMode = Cull.None;
轮换

//rotation
DxDeviceArea.Transform.World *= Matrix.RotationY((-PosX / 300F)) * Matrix.RotationX(PosY / 300F);

如何解决此问题?

为了正确绘制透明曲面,必须按深度对其排序,并从后向前渲染。渲染透明对象时还必须禁用z缓冲区测试。

半透明框中包含的对象也是半透明的吗?哦,渲染混合对象比我想象的要困难得多。。。所以我在容器渲染之前使用了您的建议并禁用了Z缓冲区。我得到了只渲染边界多边形的容器,这对我来说是enouth。以下是图片: