Sign in to follow this  
Fray Verdugo

[SlimDX] [SOLVED] Problems initializing DepthStencil

Recommended Posts

I'm trying to enable ZBuffering in Directx10, but I get a faulty rendering and I can't find what I am missing. I have been looking into the samples provided in the SlimDX SDK, even copying the code verbatim. No luck. Using PIX I can see that the ZBuffer is not being filled when drawing. It does get cleared though: So when I clear it to 1.0f, I get a black Depth image, all black; when I clear it to 0.0f, I get a full white Depth image, and nothing gets rendered. Anyway, I present you the code and the images I get. Hopefully someone has got around such problem and knows what I'm doing wrong. I am using SlimDX. Here is the initialization code: ('dispG' is the directX Device)
//Create renderTargetView
            using (Texture2D Tex2D_backbuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0)) {
                renderTargetView = new RenderTargetView(dispG, Tex2D_backbuffer);
            }

	    
	    //Create DepthStencil
            DepthStencilStateDescription dssd = new DepthStencilStateDescription {
                IsDepthEnabled = true,
                IsStencilEnabled = false,
                DepthWriteMask = DepthWriteMask.All,
                DepthComparison = Comparison.Less,
                //FrontFace = new DepthStencilOperationDescription() { Comparison = Comparison.Less, DepthFailOperation = StencilOperation.Keep }
                //BackFace= new DepthStencilOperationDescription()
            };
            depthStencilState = DepthStencilState.FromDescription(dispG, dssd);
                        
            Texture2DDescription Tex2DdepthStencil_desc = new Texture2DDescription() {
                Width = resolución.ancho,
                Height = resolución.alto,
                MipLevels = 1,
                ArraySize = 1,
                Format = Format.D32_Float,
                //Format = Format.D32_Float_S8X24_UInt,
                SampleDescription = _info.dscSwapChain.SampleDescription,
                Usage = ResourceUsage.Default,
                BindFlags = BindFlags.DepthStencil,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.None
            };
            /*
            using (Texture2D Tex2D_depthStencil = new Texture2D(dispG, Tex2DdepthStencil_desc)) {
                depthStencilView = new DepthStencilView(dispG, Tex2D_depthStencil);
            }*/
            //Create DepthStencilView
            
            DepthStencilViewDescription depthStencilView_Desc = new DepthStencilViewDescription() {
                Format = Tex2DdepthStencil_desc.Format,
                Dimension = Tex2DdepthStencil_desc.SampleDescription.Count > 1? DepthStencilViewDimension.Texture2DMultisampled: DepthStencilViewDimension.Texture2D,
                MipSlice = 0
            };
            using (Texture2D Tex2D_depthStencil = new Texture2D(dispG, Tex2DdepthStencil_desc)) {
                depthStencilView = new DepthStencilView(dispG, Tex2D_depthStencil, depthStencilView_Desc);
            }
            
            dispG.OutputMerger.SetTargets(depthStencilView, renderTargetView);
            //dispG.OutputMerger.SetTargets(renderTargetView);
            

            dispG.Rasterizer.SetViewports(new Viewport(0, 0, resolución.ancho, resolución.alto, 0.0f, 1.0f));
            
            Matrix.PerspectiveFovRH(ánguloDeVistaEnY, _info.resolución.ratio, 0, 1000, out M_Proye);

            dispG.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleList);

            RasterizerStateDescription rsd = new RasterizerStateDescription() {
                CullMode = CullMode.Back,
                FillMode = FillMode.Solid,
                IsAntialiasedLineEnabled = true,
                IsFrontCounterclockwise = true,
                IsMultisampleEnabled = true,
                //IsDepthClipEnabled = true
            };
            estadosRasterizador_Normal = RasterizerState.FromDescription(dispG, rsd);
            dispG.Rasterizer.State = estadosRasterizador_Normal;


And here is the rendering loop:
public void render() {
            
            dispG.ClearRenderTargetView(renderTargetView, Color.LightGray);
            dispG.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0);

            renderScene();
           
            swapChain.Present(0, PresentFlags.None);
        }


renderScene() ends up in a per object call to:
OADM_materialL[0].recurso.effect.GetVariableByName("M_mundoVistaProye").AsMatrix().SetMatrix(M_Mundo * _NG.M_VistaProye);

_NG.dispG.InputAssembler.SetIndexBuffer(OADM_malla.recurso.mallaGráfica.ib, Format.R16_UInt, 0);
            _NG.dispG.InputAssembler.SetVertexBuffers(0, OADM_malla.recurso.mallaGráfica.vbBinding);
            OADM_materialL[0].recurso.effect.GetTechniqueByIndex(0).GetPassByIndex(0).Apply();
            _NG.dispG.DrawIndexed(OADM_malla.recurso.mallaGráfica.i_numÍndices, 0, 0);


These are the images I get: 1st- Without ZBuffer: No ZBuffer 2nd- Zbuffer enabled (so I thought): ZBuffer enabled? Thanks! [Edited by - Fray Verdugo on March 8, 2010 11:58:21 AM]

Share this post


Link to post
Share on other sites
[embarrass]
God! 3 days stuck with this, and I find the answer right after crying for help.
I was positioning of the zNear clipping plane at 0.0; too near.

What bugs me is that i've been reading posts about DepthStencil for a while but my searches never returned the 'DirectX Forum FAQ' linked in the Sticky. I should have seen that...[embarrass]

I'll study what would be a good value to put in there.

Case closed!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this