Author Topic: Depth buffer texture  (Read 49764 times)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #45 on: July 06, 2012, 10:56:37 pm »
Why not just render into a larger texture and let the gpu scale it down?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #46 on: July 06, 2012, 11:42:29 pm »
I tried the texture enlarged by 50, but result seems be same... It's not high priority for me

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #47 on: July 06, 2012, 11:55:06 pm »
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.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #48 on: July 10, 2012, 10:55:23 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #49 on: July 10, 2012, 11:37:16 pm »
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...

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #50 on: July 10, 2012, 11:47:03 pm »
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.
« Last Edit: July 11, 2012, 01:15:35 am by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #51 on: July 11, 2012, 07:10:34 am »
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.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #52 on: July 11, 2012, 09:56:14 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #53 on: July 11, 2012, 10:14:20 am »
Yes, i did get that. But i don't see a way how to accomplish that... ???

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #54 on: July 11, 2012, 01:53:09 pm »
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?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #55 on: July 11, 2012, 04:12:38 pm »
Yes, this is exactly what I need :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #56 on: July 11, 2012, 04:20:54 pm »
I'll try it and see if it actually works...

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #57 on: July 11, 2012, 04:42:10 pm »
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
« Last Edit: July 11, 2012, 04:44:52 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #58 on: July 11, 2012, 05:50:04 pm »
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...

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #59 on: July 11, 2012, 07:09:56 pm »
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();

Code: [Select]
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();