Sign in to follow this  
SuperVGA

Both reading and writing depth through shaders

Recommended Posts

Hey everybody, Some time ago, I posted the problem of a fragment shader I was working on; i could either read from an FBO-attached texture resembling the depth, or write to gl_FragColor with values indirectly received from sampling another FBO-attached texture. Doing both things in one go didn't seem possible (ex. Multiplying the depth value with the other values, then writing them to the fragment.) I managed to convert the depth into a nice 0.0 - 1.0 scale, for test/eyecandy reasons, so that part's probably ok. If you have any experience with this, please let me know. It's been bothering me for weeks, and i haven't been able to figure out a solution. Also, I would like to know how, if it's possible, to write to a depth buffer, and for the next primitive, be able to access the new depth values from a texture. I don't know if a texture attached to an FBO will just update to the actual depth buffer values that fast. Hope you can and will help, -thanks in advance!

Share this post


Link to post
Share on other sites
You can't bind a texture to read into a shader and have the same texture bound as part of an FBO that you're using for output. You can write to a depth buffer just by writing to gl_Depth in your fragment shader.

It sounds like what you need to do is set up two depth buffers and use them in a ping-pong fashion using one as input and the other as output and then swapping.

Share this post


Link to post
Share on other sites
Hey coordz, that sounds like a good idea.

Yeah, i thought i was doing something stupid, but i gave it a shot anyhow.
I guess the ping-pong method is the one to go with for now.

Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this