简体   繁体   中英

How to Direct3D Alpha Blending

I am trying to display seleveral 3D objects inside a blend parallelepiped container. Obtained result is unsatisfactory.

First figure seems to be correct https://picasaweb.google.com/lh/photo/QabTkrf2zyIMP0UEuZvmTdMTjNZETYmyPJy0liipFm0?feat=directlink

And the second is wrong https://picasaweb.google.com/lh/photo/JqnZqeTuomNLqDR5vhizadMTjNZETYmyPJy0liipFm0?feat=directlink

I use managed directx with c#

Initialization:

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;

In render function first step is drawing inside objects And the second is drawing blend border.

Before drawing second i switch cullmode from CounterClockwise to None

DxDeviceArea.RenderState.CullMode = Cull.None;

Rotation

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

How can i beat showed issue?

In order to draw transparent surfaces correctly, you have to sort them by depth and render them from back to front. You also have to disable z-buffer testing while rendering transparent objects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM