#[SOLVED] Render target is blank if depth buffer is set

4 messages · Page 1 of 1 (latest)

lilac violet
#

For details, MSAA is disabled

    swapChainDesc.SampleDesc = { 1, 0 }; //count, quality

depth texture is created as

    D3D11_TEXTURE2D_DESC desc{};
    desc.Format = DXGI_FORMAT_R24G8_TYPELESS;
    desc.ArraySize = 1;
    desc.Width = x;
    desc.Height = y;
    desc.MipLevels = 1;
    desc.SampleDesc.Count = 1;
    desc.SampleDesc.Quality = 0;
    desc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;

with

    D3D11_DEPTH_STENCIL_VIEW_DESC viewDesc{};
    viewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT ;
    viewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;

and

    D3D11_SHADER_RESOURCE_VIEW_DESC sr_desc;
    sr_desc.Format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
    sr_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
    sr_desc.Texture2D.MostDetailedMip = 0;
    sr_desc.Texture2D.MipLevels = 1;

It isn't binded to any shader, just supposed to be drawn into.

Render target texture is created with this texture description (with bindRenderTarget = true, Format = R16G16B16A16 Float)

    D3D11_TEXTURE2D_DESC desc{};
    desc.Width = x;
    desc.Height = y;
    desc.ArraySize = 1;
    desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
    desc.Usage = D3D11_USAGE_DEFAULT;
    desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | (bindRenderTarget ? D3D11_BIND_RENDER_TARGET : 0);
    desc.MipLevels = 1;
    desc.SampleDesc.Count = 1;
    desc.SampleDesc.Quality = 0;
    desc.Format = _getTextureFormat(format);

As in the title, unbinding using OMSetRenderTargets will allow primitives to be drawn into my RT.

First attached picture has a render of my application, with the black square being the RT.
Second attached picture has the same render, but with the depth stencil buffer unbound (view is rotated, ignore that detail)

I've run out of ideas, so any other ideas from any of you is higly appreciated. Thanks.

quick stirrup
#

how do you clear the depth stencil and how do you set the viewport?

lilac violet
#

Viewport is set as topx 0, topy 0, same size as the backbuffer, with min-max Z range as (0, 1).

Depth stencil is cleared using:

_context->ClearDepthStencilView(_stencilBuffer->_depthView.Get(), D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0x00);
``` where `_stencilBuffer` is both the back buffer and RT (at different method calls)
lilac violet
#

Found the fix. I had an other clear depth function with wrong arguments.