繁体   English   中英

DirectX11深度值仅0和1

[英]DirectX11 Depth values only 0 and 1

我正在将OpenGL渲染器移植到DirectX。 几乎一切都可以正常工作,但是我对深度有疑问。 3D中的所有内容都呈现为平面。 我已经检查了Visual Studio图形分析器和深度缓冲区和状态绑定。 如果我检查“深度/模板纹理资源”,则只有值0.f(屏幕上显示某些内容)和1.f(未渲​​染任何内容)。 用gDEBugger检查的OpenGL渲染器显示的值从0.f到1.f,并且OpenGL正在工作。 我还检查了错误代码。 一切都返回S_OK。 我该怎么办?

这是我的DepthStencilState创建的:

                D3D11_DEPTH_STENCIL_DESC dsDescEn;
                ZeroMemory(&dsDescEn, sizeof(D3D11_DEPTH_STENCIL_DESC));

                dsDescEn.DepthEnable = TRUE;
                dsDescEn.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
                dsDescEn.DepthFunc = D3D11_COMPARISON_LESS;

                dsDescEn.StencilEnable = TRUE;
                dsDescEn.StencilReadMask = 0xFF;
                dsDescEn.StencilWriteMask = 0xFF;

                dsDescEn.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
                dsDescEn.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
                dsDescEn.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
                dsDescEn.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

                dsDescEn.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
                dsDescEn.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
                dsDescEn.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
                dsDescEn.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

                DirectX11Device::getDevice().getDevicePtr()->CreateDepthStencilState(&dsDescEn, &m_dSStateEn);

我通过OMSetDepthStencilState绑定状态。

D3D11_TEXTURE2D_DESC depthStencilDesc;

                    depthStencilDesc.Width = width;
                    depthStencilDesc.Height = height;
                    depthStencilDesc.MipLevels = 1;
                    depthStencilDesc.ArraySize = 1;
                    depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
                    depthStencilDesc.SampleDesc.Count = 1;
                    depthStencilDesc.SampleDesc.Quality = 0;
                    depthStencilDesc.Usage = D3D11_USAGE_DEFAULT;
                    depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
                    depthStencilDesc.CPUAccessFlags = 0;
                    depthStencilDesc.MiscFlags = 0;

                    D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
                    ZeroMemory(&depthStencilViewDesc, sizeof(D3D11_DEPTH_STENCIL_VIEW_DESC));

                    depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
                    depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
                    depthStencilViewDesc.Texture2D.MipSlice = 0;

                    DirectX11Device::getDevice().getDevicePtr()->CreateTexture2D(&depthStencilDesc, NULL, &m_stencilDepthBuff);
                    DirectX11Device::getDevice().getDevicePtr()->CreateDepthStencilView(m_stencilDepthBuff, &depthStencilViewDesc, &m_stencilDepthView);

我找到了解决方案。 问题是矩阵乘法。 我将其从C ++移到了着色器,现在它可以正常工作了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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