Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17560

Sampling from Depth Buffer

$
0
0

HI All,

 

I think I have most of this working, but you guys might be able to pick out where I am going wrong.

 

I'm going through and creating a resourceview for my depth buffer. I've tested everything and its green in the code.  No error results or warnings (with debug etc all on).

              D3D11.DepthStencilViewDescription stencilBufferViewDesc = new D3D11.DepthStencilViewDescription()
                {
                    Dimension = D3D11.DepthStencilViewDimension.Texture2DMultisampled,
                    Format = DXGI.Format.D24_UNorm_S8_UInt,
                    Flags = D3D11.DepthStencilViewFlags.None,
                    Texture2DMS = new D3D11.DepthStencilViewDescription.Texture2DMultisampledResource(),                    
                };



                D3D11.Texture2DDescription desc = new D3D11.Texture2DDescription()
                {
                   Format = DXGI.Format.R24G8_Typeless,                    
                    ArraySize = 1,
                    MipLevels = 1,
                    Width = m_gameResolution.Width,
                    Height = m_gameResolution.Height,
                    Usage = D3D11.ResourceUsage.Default,
                    SampleDescription = new DXGI.SampleDescription(s_antiAliasSample, 0),
                    BindFlags = D3D11.BindFlags.DepthStencil | D3D11.BindFlags.ShaderResource,
                    CpuAccessFlags = D3D11.CpuAccessFlags.None,
                    OptionFlags = D3D11.ResourceOptionFlags.None
                };
                m_depthBuffer = new D3D11.Texture2D(m_device, desc);
                m_stencilView = new D3D11.DepthStencilView(m_device, m_depthBuffer, stencilBufferViewDesc);

                /*---------------------------------------------*/
                // Creating depth buffer as resource



                D3D11.ShaderResourceViewDescription shaderResourceView = new D3D11.ShaderResourceViewDescription()
                {

                    Dimension = ShaderResourceViewDimension.Texture2DMultisampled,
                    Format = DXGI.Format.R24_UNorm_X8_Typeless,

                    //Flags = D3D11.DepthStencilViewFlags.None,
                    Texture2DMS = new D3D11.ShaderResourceViewDescription.Texture2DMultisampledResource()
                };

                // this is used to sample the DEPTH buffer!
                m_depthShaderResource = new D3D11.ShaderResourceView(m_device, m_depthBuffer, shaderResourceView);                

                m_renderTargetView = new D3D11.RenderTargetView(m_device, m_swapChainBuffer);

I am using a Texture2dMS so I have to use load to sample the texture in my fx code. But. I'm getting an exception thrown in my HLSL code.

 

No real error, not even with debugging in.  Just says something external has thrown an exception.  

 

I've defined my texture as in the fx code.

 

Texture2DMS<float4, 4> depthTexture;

 

I sample using the middle of the screen.  My expectation is that the entire landscape should change to a darker colour as I zoom out.  proving that I am indeed reading from the zbuffer correctly.

 

    texCoord.x = 0.5f;
    texCoord.y = 0.5f;
 
    float4 color = depthTexture.Load(texCoord, 0);

 

I update this from my main loop using "SetResource" and passing the depthshaderresource in.  

 

I've spent a fair bit of time on this. with no success.  including:

 

- Defining another texture (multisample) and using copy resource.  This doesn't cause an exception but I dont seem to get any thing from the sample that changes the colour.  I use copyresource after all the landscape is rendered and zbuffer written to (assume this).  NO errors, but no results on screen.  its always fully white.

 

- tried to define a single sample texture and use ResolveSubresource to downsample, but I can't find any formats where it will allow me to resolve. spent hours on this to no avail.

 

I'm sure im doing something simply wrong here, but I just can't find it.

 

 

 

 

 

 

 

    texCoord.x = 0.5f;
    texCoord.y = 0.5f;
 
    float4 color = depthTexture.Load(texCoord, 0);

Viewing all articles
Browse latest Browse all 17560

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>