I'm working on a software and I'd to move the rendering API from SlimDX to SharpDX. I've done that but I noticed that the solid polygon are not drawn correctly i.e., even if the polygon is at the back side of another polygon, part of it is visible, also part of the polygon lie inside terrain that is also visible. Below are the images from SlimDX implementation and SharpDX implementation for reference:
I tried to set the Stencil & ZBuffer but there are not working as expected. I've already applied DepthBias to it which worked fine with SlimDX but not with SharpDX.
Please let me know if, I'm missing something or I'm doing something wrong.
Update 1 (Polygon rendering):
// set the render state to device
device.SetRenderState(RenderState.AlphaTestEnable,
true);
device.SetRenderState(RenderState.AlphaBlendEnable,
true);
device.SetRenderState(RenderState.SourceBlend,
Blend.SourceAlpha);
device.SetRenderState(RenderState.SeparateAlphaBlendEnable,
true);
device.SetRenderState(RenderState.DestinationBlendAlpha,
Blend.One);
device.SetRenderState(RenderState.SourceBlendAlpha,
Blend.InverseDestinationAlpha);
// set the render state to the device
device.SetRenderState(RenderState.DepthBias,
-1E-06f);
this.effectVectoring.Begin(FX.None);
// binds the vertex buffer to device data stream
device.SetStreamSource(0,
this.vertexBuffer,
dataGeometry.FillVertexOffset,
stride);
// pass 1 to shader as a pass if it is 3D mode else 0
this.effectVectoring.BeginPass(is3D ? 1 : 0);
// renders the non-index geometric primitives using the data from current input stream
device.DrawPrimitives(SharpDX.Direct3D9.PrimitiveType.TriangleList,
0,
primitiveCount);
// end the pass
this.effectVectoring.EndPass();
this.effectVectoring.End();
device.SetRenderState(RenderState.AlphaBlendEnable,
false);
device.SetRenderState(RenderState.AlphaTestEnable,
false);
device.SetRenderState(RenderState.DepthBias,
0);
device.SetRenderState(RenderState.FillMode,
FillMode.Solid);
device.SetRenderState(RenderState.SeparateAlphaBlendEnable,
false);
Update 2 (Terrain rendering):
device.SetRenderState(RenderState.AlphaBlendEnable,
false);
device.SetRenderState(RenderState.AlphaTestEnable,
false);
device.SetRenderState(RenderState.CullMode,
Cull.Counterclockwise);
device.Indices = this.terrainIB;
device.SetStreamSource(0,
this.terrainVB,
0,
12);
device.VertexFormat = VertexFormat.Position;
// Set texture in effect...
effect.Begin(FX.None);
effect.BeginPass(pass);
device.DrawIndexedPrimitive(PrimitiveType.TriangleStrip,
baseVertexIndex,
0,
vertexCount,
startIndex,
primitiveCount);
effect.EndPass();
effect.End();
device.SetRenderState(RenderState.FillMode,
FillMode.Solid);
device.SetRenderState(RenderState.CullMode,
Cull.None);