2012-05-16 128 views
1

我想顯示混合平行六面體容器內部的多個3D對象。 獲得的結果不令人滿意。如何Direct3D Alpha混合

第一個數字似乎是正確的 https://picasaweb.google.com/lh/photo/QabTkrf2zyIMP0UEuZvmTdMTjNZETYmyPJy0liipFm0?feat=directlink

而且 https://picasaweb.google.com/lh/photo/JqnZqeTuomNLqDR5vhizadMTjNZETYmyPJy0liipFm0?feat=directlink

我使用託管的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; 

在渲染功能第一步驟是繪製對象 第二個是繪製混合邊框。

之前繪製第二i開關cullmode從逆時針無

DxDeviceArea.RenderState.CullMode = Cull.None; 

旋轉

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

我如何才能戰勝顯示問題?

+0

半透明盒子還包含半透明物體嗎? – Ani

回答

0

爲了正確繪製透明曲面,您必須按深度對它們進行排序並從後到前渲染它們。您還必須在渲染透明對象時禁用z緩衝區測試。

+0

哦,混合對象的渲染比我想象的要難得多...所以我使用了你的建議,並在容器渲染之前禁用Z緩衝區。我只有邊界多邊形渲染的容器,這對我來說是非常棒的。這裏是圖片:https://picasaweb.google.com/lh/photo/kwH_AZTQfrTjlKAYkviTj9MTjNZETYmyPJy0liipFm0?feat=directlink – gunboxer