Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7128329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:07:38+00:00 2026-05-28T11:07:38+00:00

I am rendering a scene to a texture, then using that texture and its

  • 0

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…).

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

I have suspected the call to device->clear to affect the wrong surface, but even when disabling them, it doesn’t fix anything.

Here is the actual code :

HRESULT hr = S_FALSE;

VCND3D* renderer = static_cast<VCND3D*>( VCNRenderCore::GetInstance() );
LPDIRECT3DDEVICE9 device = renderer->GetD3DDevice();

//device->EndScene();

VCNDXShaderCore* shaderCore = static_cast<VCNDXShaderCore*>( VCNDXShaderCore::GetInstance() );

VCNNode* rootNode = VCNNodeCore::GetInstance()->GetRootNode();

LPDIRECT3DSURFACE9 currentSurface;
device->GetRenderTarget(0, &currentSurface);

LPDIRECT3DSURFACE9 currentDepthBuffer;
device->GetDepthStencilSurface( &currentDepthBuffer );

///// INITIAL HDR RENDER : //////////////////////////////////////

hr = device->SetRenderTarget( 0, mInitialHDRSurface );
VCN_ASSERT( SUCCEEDED(hr) );

hr = device->SetDepthStencilSurface( mDepthSurface );
VCN_ASSERT( SUCCEEDED(hr) );

device->Clear(  0,
                NULL,
                D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
                D3DCOLOR_XRGB(100,100,100),
                1.0f,
                0 );

//device->BeginScene();
rootNode->Render();
//device->EndScene();

//hr = device->UpdateSurface( currentDepthBuffer, NULL, mDepthSurface, NULL );
//VCN_ASSERT( SUCCEEDED(hr) );

//////////// DOF EFFECT : /////////////////////////////////////////////////

hr = device->SetRenderTarget( 0, currentSurface );
VCN_ASSERT( SUCCEEDED(hr) );

device->SetRenderState(D3DRS_COLORWRITEENABLE, 
D3DCOLORWRITEENABLE_ALPHA | D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE);

device->Clear(  0,
                NULL,
                D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
                D3DCOLOR_XRGB(100,100,100),
                1.0f,
                0 );

//device->BeginScene();

// Set DOF shader
VCNDXShader* dofShader = shaderCore->GetShader( sidDof );

// Field of view to cover full screen :
hr = device->SetFVF(D3DFVF_SCREEN);
VCN_ASSERT( SUCCEEDED(hr) );

// select the vertex buffer to display
hr = device->SetStreamSource(0, mScreenVertexBuffer, 0, sizeof(SCREENVERTEX));
VCN_ASSERT( SUCCEEDED(hr) );

// Draw the Dof result
hr = dofShader->GetEffect()->SetTechnique( "BaseTechnique" );
VCN_ASSERT( SUCCEEDED(hr) );
hr = dofShader->GetEffect()->SetTexture( "gInputImageTexture", mInitialHDRTexture );
VCN_ASSERT( SUCCEEDED(hr) );
hr = dofShader->GetEffect()->SetTexture( "gDepthTexture", mDepthTexture );
VCN_ASSERT( SUCCEEDED(hr) );
hr = dofShader->GetEffect()->SetFloat( "gMinDepth", 3.0f );
VCN_ASSERT( SUCCEEDED(hr) );
hr = dofShader->GetEffect()->SetFloat( "gMaxDepth", 7.0f );
VCN_ASSERT( SUCCEEDED(hr) );

dofShader->RenderPrimitive( 2, D3DPT_TRIANGLESTRIP );

hr = device->SetDepthStencilSurface( currentDepthBuffer );
VCN_ASSERT( SUCCEEDED(hr) );

And here are the init of the texture and surfaces, because the error could be there :

// Texture for the initial HDR Render (Before effects)
hr = device->CreateTexture(res.x, res.y, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A32B32G32R32F, D3DPOOL_DEFAULT, &mInitialHDRTexture, 0);
VCN_ASSERT_MSG( SUCCEEDED(hr), _T("Unable to create initial HDR Render Texture") );

// Extract the associated surface for rendering
hr = mInitialHDRTexture->GetSurfaceLevel(0, &mInitialHDRSurface);
VCN_ASSERT( SUCCEEDED(hr) );

// Texture with depth of the scene
hr = device->CreateTexture(res.x, res.y, 1, D3DUSAGE_DEPTHSTENCIL, D3DFMT_D32F_LOCKABLE, D3DPOOL_DEFAULT, &mDepthTexture, 0);
VCN_ASSERT_MSG( SUCCEEDED(hr), _T("Unable to create depth texture") );

// Extract the associated surface for rendering
hr = mDepthTexture->GetSurfaceLevel(0, &mDepthSurface);
VCN_ASSERT( SUCCEEDED(hr) );

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)

Nic

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T11:07:39+00:00Added an answer on May 28, 2026 at 11:07 am

    If I read your code correctly you clear mDepthSurface twice: first in INITIAL HDR RENDER section, then in DOF EFFECT. You either need to do a SetDepthStencilSurface before second clear, or not setting D3DCLEAR_ZBUFFER in that call. Otherwise second clear discards whatever is rendered by rootNode->Render() and at effect start you have all clear z-buffer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm rendering my scene to a texture. This works fine except that depth testing
I am rendering an OpenGL scene that include some bitmap text. It is my
I have an opengl scene rendering on an EAGLView layer and some other elements
I'm using Java OpenGL (JOGL 2.x, built from Git source). I'm rendering my scene
I'm using Qt (Mac, version 4.7) to rendering a rather large scene (map data
I am rendering a scene in which I have two spheres. I am revolving
While rendering the view page, based on some condition in the controller action I
I'm rendering some HTML in a QT QLabel. The HTML looks like this: <pre>foo\tbar</pre>
I am looking at some sample code in a book that creates a jittered
I have an NSTimer that runs at 60hz. With an OpenGL scene loaded and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.