Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieving depthBuffer of a render for another render pass. (D3DX9)
    primarykey
    data
    text
    <p>I am rendering a scene to a texture, then using that texture and its depthBuffer in subsequent renderings to apply some effects (Depth Of Field, Bloom, etc...).</p> <p>Here is the problem: I manage to set the DepthStencilBuffer to a custom surface and render my scene to a texture. The scene is rendered perfectly, and there is no depth problems. This being said, when using the texture (to which the custom surface is bound), all depth values are exactly 1.0</p> <p>I have suspected the call to device->clear to affect the wrong surface, but even when disabling them, it doesn't fix anything.</p> <p>Here is the actual code :</p> <pre><code>HRESULT hr = S_FALSE; VCND3D* renderer = static_cast&lt;VCND3D*&gt;( VCNRenderCore::GetInstance() ); LPDIRECT3DDEVICE9 device = renderer-&gt;GetD3DDevice(); //device-&gt;EndScene(); VCNDXShaderCore* shaderCore = static_cast&lt;VCNDXShaderCore*&gt;( VCNDXShaderCore::GetInstance() ); VCNNode* rootNode = VCNNodeCore::GetInstance()-&gt;GetRootNode(); LPDIRECT3DSURFACE9 currentSurface; device-&gt;GetRenderTarget(0, &amp;currentSurface); LPDIRECT3DSURFACE9 currentDepthBuffer; device-&gt;GetDepthStencilSurface( &amp;currentDepthBuffer ); ///// INITIAL HDR RENDER : ////////////////////////////////////// hr = device-&gt;SetRenderTarget( 0, mInitialHDRSurface ); VCN_ASSERT( SUCCEEDED(hr) ); hr = device-&gt;SetDepthStencilSurface( mDepthSurface ); VCN_ASSERT( SUCCEEDED(hr) ); device-&gt;Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(100,100,100), 1.0f, 0 ); //device-&gt;BeginScene(); rootNode-&gt;Render(); //device-&gt;EndScene(); //hr = device-&gt;UpdateSurface( currentDepthBuffer, NULL, mDepthSurface, NULL ); //VCN_ASSERT( SUCCEEDED(hr) ); //////////// DOF EFFECT : ///////////////////////////////////////////////// hr = device-&gt;SetRenderTarget( 0, currentSurface ); VCN_ASSERT( SUCCEEDED(hr) ); device-&gt;SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA | D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE); device-&gt;Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(100,100,100), 1.0f, 0 ); //device-&gt;BeginScene(); // Set DOF shader VCNDXShader* dofShader = shaderCore-&gt;GetShader( sidDof ); // Field of view to cover full screen : hr = device-&gt;SetFVF(D3DFVF_SCREEN); VCN_ASSERT( SUCCEEDED(hr) ); // select the vertex buffer to display hr = device-&gt;SetStreamSource(0, mScreenVertexBuffer, 0, sizeof(SCREENVERTEX)); VCN_ASSERT( SUCCEEDED(hr) ); // Draw the Dof result hr = dofShader-&gt;GetEffect()-&gt;SetTechnique( "BaseTechnique" ); VCN_ASSERT( SUCCEEDED(hr) ); hr = dofShader-&gt;GetEffect()-&gt;SetTexture( "gInputImageTexture", mInitialHDRTexture ); VCN_ASSERT( SUCCEEDED(hr) ); hr = dofShader-&gt;GetEffect()-&gt;SetTexture( "gDepthTexture", mDepthTexture ); VCN_ASSERT( SUCCEEDED(hr) ); hr = dofShader-&gt;GetEffect()-&gt;SetFloat( "gMinDepth", 3.0f ); VCN_ASSERT( SUCCEEDED(hr) ); hr = dofShader-&gt;GetEffect()-&gt;SetFloat( "gMaxDepth", 7.0f ); VCN_ASSERT( SUCCEEDED(hr) ); dofShader-&gt;RenderPrimitive( 2, D3DPT_TRIANGLESTRIP ); hr = device-&gt;SetDepthStencilSurface( currentDepthBuffer ); VCN_ASSERT( SUCCEEDED(hr) ); </code></pre> <p>And here are the init of the texture and surfaces, because the error could be there :</p> <pre><code>// Texture for the initial HDR Render (Before effects) hr = device-&gt;CreateTexture(res.x, res.y, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A32B32G32R32F, D3DPOOL_DEFAULT, &amp;mInitialHDRTexture, 0); VCN_ASSERT_MSG( SUCCEEDED(hr), _T("Unable to create initial HDR Render Texture") ); // Extract the associated surface for rendering hr = mInitialHDRTexture-&gt;GetSurfaceLevel(0, &amp;mInitialHDRSurface); VCN_ASSERT( SUCCEEDED(hr) ); // Texture with depth of the scene hr = device-&gt;CreateTexture(res.x, res.y, 1, D3DUSAGE_DEPTHSTENCIL, D3DFMT_D32F_LOCKABLE, D3DPOOL_DEFAULT, &amp;mDepthTexture, 0); VCN_ASSERT_MSG( SUCCEEDED(hr), _T("Unable to create depth texture") ); // Extract the associated surface for rendering hr = mDepthTexture-&gt;GetSurfaceLevel(0, &amp;mDepthSurface); VCN_ASSERT( SUCCEEDED(hr) ); </code></pre> <p>Note that no ASSERT is getting triggered (which is exactly what is pissing me off, I would like some errors as an indication of where to look)</p> <p>Nic</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload