Jump to content
  • Advertisement
Sign in to follow this  
shukapi

OpenGL Pixel Shader: Framebuffer / Depthbuffer access.

This topic is 4092 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I code in OpenGL so I'm not familiar with Direct3D. I want to know if, in Direct3D, you can write a pixel shader that uses the current frame-buffer pixel color / depth-buffer pixel value, as inputs. For example, could you write a pixel shader that swaps the Red and Green values from the current frame-buffer pixel? Could you write a shader that sets the R, G, and B to some function of the difference between the previous pixel depth and the new pixel depth. And lastly, would you have any idea whether this functionality is supported by an OpenGL extension, or will be any time soon? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
There's no way for you to directly access the depth buffer in DX. The most generally-used solution is to output the depth to a floating-point texture using MRT's or a second pass, and then read from that texture in all your shaders that need it.

You also can't directly access the back-buffer, either. It's possible to copy the contents of the back-buffer to a texture and use that texture in your shader, but for most full-screen post-processing its more common to simply render your entire scene to a texture, and use that texture as the source for post-processing shaders.

If you want to see an example of what I'm talking about, check out the PostProcess sample in the DX SDK. The DepthOfField technique in particular uses a depth texture and a full-screen color texture.

Share this post


Link to post
Share on other sites
MJP's is a good answer. Regarding OpenGL, I can't tell you, but I can speculate. Reading the frame buffer is a problem. You can't read the same surface you're writing to because this results in inconsistencies. Therefore it's unlikely that this functionality is supported in OpenGL, either. As for depth buffer access, I think I've heard it's supported. In Direct3D ATI provides depth buffer formats which can be used for textures.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!