Depth buffer texture

Started by Thomas., June 30, 2012, 01:58:21 AM

Previous topic - Next topic

EgonOlsen

Why not just render into a larger texture and let the gpu scale it down?

Thomas.

I tried the texture enlarged by 50, but result seems be same... It's not high priority for me

EgonOlsen

I can't find anything for Android that shows how this can be enabled. I found some extenstions, but the mentioned calls are not present in the SDK. You can do something like FXAA in your shader though.

Thomas.

Now, I need depth buffer from previous rendering. I render scene to texture and I have to use this depth buffer to next "normal" rendering. FOB has its depth buffer, I need it for normal rendering. Is it possible?

EgonOlsen

The depth buffer will be rendered into a render buffer, the color buffer into a FBO. You can write, just like it happens when you set a texture as shadow map, the depth values into the color buffer, but you can't access the actual render buffer (by design of a render buffer). However, i'm not sure if i really get what you want to do...

Thomas.

#50
I have two worlds, in both are objects. I render first world into texture and second world normal. I need to use depth buffer from first world while is rendering second world.

EgonOlsen

I don't see how this should work that way. Like you can't access the color buffer in the fragment shader, you can't access the depth buffer either...especially not if it's not even a part of the current render setup but of some past rendering. The only way i see is to use a texture that contains this buffer, but even then i'm unsure how to map it onto the scene so that it matches the actual depth buffer.

Why not render both worlds into the same texture without clearing. That way, the depth buffer would be evaluated automatically by the rendering process.

Thomas.

Quote from: EgonOlsen on July 11, 2012, 07:10:34 AM
Why not render both worlds into the same texture without clearing. That way, the depth buffer would be evaluated automatically by the rendering process.

Yes, this is what I talking about, but I need render one to texture and second to screen, when I just skip fb.clear(), nothing happened (because FBO has its depthbuffer and normal rendering has another). I want to know if I can somehow mix it, use depthbuffer (internal, no texture) from first render while is rendered second. I hope that we already understand.

EgonOlsen

Yes, i did get that. But i don't see a way how to accomplish that... ???

EgonOlsen

Maybe this will work: I can add a method to FrameBuffer to create a render buffer for the depth buffer. I then can make the render target logic reuse this buffer if the render target has the same size as the frame buffer instead of creating its own.
You then have to clear the frame buffer first, then assign the render target and clear it again. Then render into your texture. The depth should be written into the render buffer. Then remove the render target and render directly into the frame buffer. This rendering should use the same render buffer as a depth buffer. However, you still won't be able to access the data directly (just like with the color buffer). Would that help?

Thomas.

Yes, this is exactly what I need :)

EgonOlsen

I'll try it and see if it actually works...

Thomas.

#57
Has this solution any performance loss? I can also set the render target > render > somehow clear image buffer only (could you add method for this, please?)> render with effect > remove render target > render/blit texture... but this need one extra rendering

EgonOlsen

I've updated the jpct_ae.jar. It includes two new methods in FrameBuffer, createRenderBuffer() and clearColorBufferOnly(RGBColor); The latter one is self-explanatory. The former one does more complicated stuff:


  • A new render buffer with the size of the framebuffer will be created and used as a depth buffer.
  • This can't be undone. Once created, all depth rendering will go into this buffer.
  • If you assign a new render target to the framebuffer with the exact same size, this buffer will be reused by this render target as a depth buffer.
  • You can set the Logger to debug to see if this actually happens. If it says "Using frame buffer's render buffer!", everything worked fine. If it says "Creating render buffer in depth mode!", the buffers' sizes don't match and a new one will be created.

Hope this helps. I've tested the basic functionality but i haven't tested if the depth values rely persist between renderings. I'm not doing anything to prevent them from doing so, but you never know what the driver thinks of this...

Thomas.

It seems, that depth buffer is not used in second rendering. Texture has same resolution as framebuffer and LogCat says "Using frame buffer's render buffer!". This is my code...

in constructor fb.createRenderBuffer();

fb.clear();
fb.setRenderTarget(imageBufferID);
fb.clear();
world.renderScene(fb);
world.draw(fb);
fb.display();
fb.removeRenderTarget();

fb.clearColorBufferOnly(RGBColor.BLACK);
ifWorld.renderScene(fb);
ifWorld.draw(fb);
                // blit
                fb.display();