Skip to main content
GameDev.net gamedev.net
🔒 Locked

Read depth in shader

Started by Prune Nov 18, 2009 at 3:39 PM 3 replies 700+ views
Original Post
Prune
Prune
I want to splat points such that a pixel would have increasing transparency if there is an object behind it closer than a threshold; so I basically need to read the current depth value and calculate alpha based on that. I'd like to know the most efficient way to do this, without FBOs if possible. (If it matters, depth test is on and depth mask off; the depth buffer has data in it already from drawing the scene beforehand. I'm using OpenGL 3.0 or 3.1 and avoid deprecated features.)
"But who prays for Satan? Who, in eighteen centuries, has had the common humanity to pray for the one sinner that needed it most?" --Mark Twain

~~~~~~~~~~~~~~~Looking for a high-performance, easy to use, and lightweight math library? http://www.cmldev.net/ (note: I'm not associated with that project; just a user)
HuntsMan
HuntsMan
The only way is writing depth to a texture using a FBO, and reading that texture inside your fragment shader.

So, what's your reason to not use FBOs? They are core since GL 3.0.
Prune
Prune
Can I render only the depth to an FBO, and colors still directly to the display's framebuffer (since I'm doing direct rendering and no post-process)? And what texture format should I use?
"But who prays for Satan? Who, in eighteen centuries, has had the common humanity to pray for the one sinner that needed it most?" --Mark Twain

~~~~~~~~~~~~~~~Looking for a high-performance, easy to use, and lightweight math library? http://www.cmldev.net/ (note: I'm not associated with that project; just a user)
HuntsMan
HuntsMan
You can do a depth-only render, with a FBO with a depth attachment and no color buffer, and then read that buffer in the next render operation.

But you can't use the default framebuffer with a FBO.
V-man
V-man
Quote:
Original post by Prune
Can I render only the depth to an FBO, and colors still directly to the display's framebuffer (since I'm doing direct rendering and no post-process)? And what texture format should I use?


No.
You would have to render to a RTT with no color attachment. Explanation is here http://www.opengl.org/wiki/GL_EXT_framebuffer_object#Depth_only

just strip away the _EXT for your GL 3.0 code.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.