-1
\$\begingroup\$

OpengGL 4.5 with LWJGL

For my particle system, I have billboards that are rendered to an off screen texture. This FBO contains texture information, multiple render targets, a depth texture and a depth buffer. What I'd like to happen is for me to be able to render all my particles to the FBO, add some stuff to them, then render them to my scene with depth testing. I've tried manually depth testing, but I couldn't get that to work (It created large chunks of pixels that would appear and disappear, probably a precision error, but I'm using RGBA16 so I would assume that would be enough).

What I did for manual depth testing : if(gl_FragCoord.w < sceneDepth.x) then discard pixel.

One idea I have in mind is to manually replace the depth buffer of my FBO with the depth buffer of the scene, but I have no idea how I could do this.

I was able to get the clipping effect when it wasn't rendered to an FBO, for obvious reasons, but I have no idea how I could recreate this while using an FBO. How can I recreate this?

What I want (Clipping) enter image description here

What I get (No clipping because no depth information)

enter image description here

Any help would be much appreciated.

\$\endgroup\$
  • \$\begingroup\$ Just curious, what did the image look like with strange artifacts? \$\endgroup\$ – leetNightshade Jun 21 '17 at 2:10
  • \$\begingroup\$ @leetNightshade I'll try to find a picture, but I basically was just the shape but pixelated, as large square chunks of pixels kept appearing and disappearing. I'm assuming it was caused by a precision error, but I have my depth buffer using RGBA16, which should be plenty. \$\endgroup\$ – Jason Jun 21 '17 at 13:08
  • \$\begingroup\$ But why do you do the depth testing yourself? FBOs can do that. \$\endgroup\$ – Bálint Jun 21 '17 at 17:23
  • \$\begingroup\$ @Bálint The problem is I want to combine two FBOs that each have depth in them. The first one has my scene, and the second has particles on it. So my plan to combine them was to do depth testing by myself, but it didn't work. \$\endgroup\$ – Jason Jun 21 '17 at 17:29
  • 1
    \$\begingroup\$ @Jason let the scene be the default buffer, render it, then render the particles, then by using the particle output as a texture, render it on a quad, that covers the screen and set the depth value of the fragments to the one in the depth buffer. \$\endgroup\$ – Bálint Jun 21 '17 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.