0
\$\begingroup\$

hi i am currently implementing UI screen that shows Depth Complexity of scene, so that we can figure out how many time each pixels work for same pixels.

for this i need to render stencil ref value. i successed to READ stencil ref value of each pixels using staging texture. but i couldn't figure out how to pass this data to pixel shader, so that i can render 'Depth complexity'.

brief code that i have tried now.

//initializing Depth Stencil buffer-----------------------------------

D3D11_TEXTURE2D_DESC ds_desc;
    ds_desc.Width = SCREEN_WIDTH;
    ds_desc.Height = SCREEN_HEIGHT;
    ds_desc.MipLevels = 1;
    ds_desc.ArraySize = 1;
    ds_desc.Format = DXGI_FORMAT_R24G8_TYPELESS;
    ds_desc.SampleDesc.Count = 1;
    ds_desc.SampleDesc.Quality = 0;
    ds_desc.Usage = D3D11_USAGE_DEFAULT;
    ds_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
    ds_desc.CPUAccessFlags = 0;
    ds_desc.MiscFlags = 0;
    Create DepthStencil Texture ...

    D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
    dsv_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
    dsv_desc.Flags = 0;
    dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
    dsv_desc.Texture2D.MipSlice = 0;
    Create DepthStencilView

    DX_DContext->OMSetRenderTargets(1, rtv.GetAddressOf(), dsView.Get());

// process to create SRV--------------------------------------------------------
D3D11_TEXTURE2D_DESC desc;
    desc.ArraySize = 1;
    desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
    desc.CPUAccessFlags = 0;
    desc.Format = DXGI_FORMAT_X24_TYPELESS_G8_UINT;
    desc.Width = SCREEN_WIDTH;
    desc.Height = SCREEN_HEIGHT;
    desc.MipLevels = 1;
    desc.MiscFlags = 0;
    desc.SampleDesc.Count = 1;
    desc.SampleDesc.Quality = 0;
    desc.Usage = D3D11_USAGE_DEFAULT;
    Create StagingTexture2D...

DX_DContext->CopyResource(copyTex->Get(), graphic->DepthStencilBuffer());

    D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
    srvDesc.Format = DXGI_FORMAT_X24_TYPELESS_G8_UINT;
    srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
    srvDesc.Texture2D.MipLevels = 1;
    srvDesc.Texture2D.MostDetailedMip = 0;
    Create SRV for binding to pixel shader...

//

and i bind this srv into this pixel shader and just always showing BLACK


Texture2D<float4> uiTexture : register(t0);

float4 main(PS_INPUT input) : SV_Target
{
    int2 idx = int2(0, 0);
    return uiTexture[idx];

}

any advice or alternative would be really appreciated.

| improve this question | | | | |
\$\endgroup\$
0
\$\begingroup\$

Texture2D<uint2> uiTexture : register(t0);

Texture2D should be defined like this. and then uiTexture[idx].y will be stencil ref value.

and probably another value(uiTexture[idx].x) will be depth. cheers

| improve this answer | | | | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.