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 6550677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:14:41+00:00 2026-05-25T12:14:41+00:00

Is it possible to access depth buffer via pixel shader 2.0 in DX 9.0c?

  • 0

Is it possible to access depth buffer via pixel shader 2.0 in DX 9.0c? I’ve google’d a bit and the only solution I’ve found describe GPU hack that works only on GeForce 6 & 7.

What I am trying to achieve is to write depth of field shader effect. I can’t simple grab Z coords of vertices, because I am doing render to texture trick too, used for other post processing.

Edit:

I’ve tried this:

D3DXCreateTexture(lpD3Dev9, width, height, 1, D3DUSAGE_DEPTHSTENCIL, D3DFMT_D24S8, D3DPOOL_DEFAULT, &lpD3DepthBuffer);
lpD3DepthBuffer->GetSurfaceLevel(0,&lpNewDepthBuffer);

lpD3Dev9->GetDepthStencilSurface(&lpPrevDepthBuffer);
lpD3Dev9->SetDepthStencilSurface(lpNewDepthBuffer);
lpD3Dev9->BeginScene();
// Rendering...
lpD3Dev9->EndScene();
lpD3Dev9->SetDepthStencilSurface(lpPrevDepthBuffer);

// this function fails:
D3DXSaveTextureToFile("C:\backBuffer.png", D3DXIFF_PNG, lpD3DepthBuffer, NULL);

lpD3Dev9->BeginScene(); 
UINT passes;
D3DXHANDLE tech;
lpD3DXfxScreen->FindNextValidTechnique(0, &tech);
lpD3DXfxScreen->SetTechnique(tech);
lpD3DXfxScreen->Begin(&passes,0);
lpD3DXfxScreen->SetTexture("texDepth", lpD3DepthBuffer);
// render shader...

SaveTextureToFile fails, and shader gets texture that is pure white RGB(1, 1, 1)

  • 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-25T12:14:42+00:00Added an answer on May 25, 2026 at 12:14 pm

    To my knowledge there is no standardised way of doing it as you are trying to do it.
    You are better off just creating a D3FMT_R32F (or whatever) texture as a D3DUSAGE_RENDERTARGET and then write depths to it as if its a normal texture (ie writing the depth in the r component from the pixel shader). You can then use that texture for whatever purpose you like purely by binding it to a sampler and reading the r value straight out of it to use in whatever pixel shader you are messing about with.

    That said try going into the DirectX control panel and setting yourself to debug runtime. You’ll see a tonne of useful error message spewed out in to the debug output stream by the DirectX runtime. There really is no reason not to be doing this as it would save you a lot of bother on problems like this.

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

Sidebar

Related Questions

Is it possible to access Google Chrome's cache from within an extension? I'd like
Is it possible to access the SQL Server by-product messages via ADO.NET? Due to
Is it possible to access files beyond WEB-INF folder in Google App Engine's development
Is it possible to access movies which were purchased via iTunes in an app?
Is it possible to access an element on a Master page from the page
Is it possible to access the Abstract Syntax Tree(AST) inside the javac.exe programmatically? Could
Is it possible to access a constant value (i.e. a public static final variable
Is it possible to access a USB drive or Flash card without using the
Is it possible to access hardware devices (web-cams, magnetic card readers, etc.) from within
Is it possible to access the data belonging to the apps that ship with

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.