Hello,
I try to make a realtime depth of field for Processing and for this I need to get the depthinformation into a texture to use ist in a textureShader. I'm rendering the scene in an GLGraphicsOffScreen. I can easy get the colortexture with .getTexture();, but now I need the depth information in a texture for my shader.
Like it was mentioned in another thread I made an CustomOffScreen to get the buffer ID:
- class CustomOffScreen extends GLGraphicsOffScreen {
- public CustomOffScreen(PApplet parent, int iwidth, int iheight, boolean multi, int level) {
- super(parent, iwidth, iheight, multi, level);
- }
- public CustomOffScreen(PApplet parent, int iwidth, int iheight) {
- super(parent, iwidth, iheight);
- }
- int getDepthBuffer() {
- return depthStencilBuffer;
- }
- }
But here I am lost. How can I acces the information?
Here is what I tried.
- public GLTexture getDepthTexture() {
- PGraphicsOpenGL pogl = (PGraphicsOpenGL) g;
- java.nio.FloatBuffer zbuff = java.nio.ByteBuffer.allocateDirect(width*height*4).order(java.nio.ByteOrder.nativeOrder()).asFloatBuffer();
- pogl.gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, getDepthBuffer());
- pogl.gl.glReadPixels( 0, 0, width, height, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, zbuff);
- pogl.gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
- depthTex = new GLTexture(parent, width, height);
- depthTex.loadPixels();
- for(int i = 0; i<width; i++){
- for(int j = 0; j<height; j++){
- depthTex.pixels[j*width+i] = color((zbuff.get(((height-j-1)*width)+i))*255);
- }
- }
- depthTex.updatePixels();
- return depthTex;
- }
Thanks, Michi
2