I've been through PIX, and when set to Greater I can see that the depth buffer is being filled as expected, farther objects become darker. When it's set to Less the buffer stays all white.
I can't see that anything is being drawn into the stencil buffer in either case.
My projection matrix has a near plane of 1.0f and a far plane of 50.0f. The devices viewport has a minZ of 0.0f and a maxZ of 1.0f. I've ensured that both are properly set onto the device at render.
I'm also setting the RasterizerState and DepthStencilState at the beginning of every frame. I've disabled culling deliberately, and it has no effect either way.
Here are the states I'm setting:
_defaultRasterizerState = SlimDX.Direct3D10.RasterizerState.FromDescription(context10.Device, new RasterizerStateDescription()
{
CullMode = CullMode.None,
FillMode = FillMode.Solid,
DepthBias = 0,
DepthBiasClamp = 0,
SlopeScaledDepthBias = 0.0f,
IsFrontCounterclockwise = false,
IsDepthClipEnabled = true,
IsScissorEnabled = false,
IsMultisampleEnabled = false,
IsAntialiasedLineEnabled = false
});
_defaultDepthStencilState = DepthStencilState.FromDescription(context10.Device,
new DepthStencilStateDescription()
{
// Depth test parameters
IsDepthEnabled = true,
DepthWriteMask = SlimDX.Direct3D10.DepthWriteMask.All,
DepthComparison = Comparison.Less,
// Stencil test parameters
IsStencilEnabled = true,
StencilReadMask = 0xFF,
StencilWriteMask = 0xFF,
// Stencil operations if pixel is front-facing
FrontFace = new DepthStencilOperationDescription()
{
FailOperation = StencilOperation.Keep,
DepthFailOperation = StencilOperation.Increment,
PassOperation = StencilOperation.Keep,
Comparison = SlimDX.Direct3D10.Comparison.Always
},
// Stencil operations if pixel if back-facing
BackFace = new DepthStencilOperationDescription()
{
FailOperation = StencilOperation.Keep,
DepthFailOperation = StencilOperation.Increment,
PassOperation = StencilOperation.Keep,
Comparison = SlimDX.Direct3D10.Comparison.Always
}
});
And here's where I create my RenderTargetView and DepthStencilView
using (var backBuffer = Texture2D.FromSwapChain<Texture2D>(Context10.SwapChain, 0))
{
var depthStencilDesc = new Texture2DDescription()
{
Width = backBuffer.Description.Width,
Height = backBuffer.Description.Height,
MipLevels = 1,
ArraySize = 1,
Format = SlimDX.DXGI.Format.D24_UNorm_S8_UInt,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = SlimDX.Direct3D10.BindFlags.DepthStencil,
CpuAccessFlags = SlimDX.Direct3D10.CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
};
using (var depthStencilBuffer = new Texture2D(Context10.Device, depthStencilDesc))
DepthView = new DepthStencilView(Context10.Device, depthStencilBuffer,
new DepthStencilViewDescription()
{
Format = SlimDX.DXGI.Format.D24_UNorm_S8_UInt,
FirstArraySlice = 0,
ArraySize = 1,
MipSlice = 0,
Dimension = DepthStencilViewDimension.Texture2D
});
RenderView = new RenderTargetView(Context10.Device, backBuffer);
}
Context10.Device.OutputMerger.SetTargets(DepthView, RenderView);
Would greatly appreciate any suggestions at all, admittedly still learning Direct3d10, but I'm about out of ideas, and I've been through pages of google search results without much help.