I used three method to obtain depth buffer with no use
firstly I used manual method with this code:
int width = getContext().getSettings().getWidth();
int height = getContext().getSettings().getHeight();
Camera reflectionCam = new Camera(width, height);
reflectionCam.setFrustumPerspective(getCamera().getFov(), getCamera().getAspect(), 0.01f, 1000);
reflectionCam.setLocation(new Vector3f(0, 0, -6.f));
ViewPort reflectionView = renderManager.createPreView("reflectionView", getCamera());
reflectionView.setEnabled(true);
reflectionView.setClearFlags(true, true, true);
reflectionView.attachScene(getRootNode());
renderFrameBuffer = new FrameBuffer(width, height, 1);
//setup framebuffer to use texture
renderFrameBuffer.setMultiTarget(true);
reflectionView.setOutputFrameBuffer(renderFrameBuffer);
depthTexture = new Texture2D(width, height, Format.Depth);
renderedTexture = new Texture2D(width, height, Format.RGBA8);
renderFrameBuffer.setDepthTarget(FrameBufferTarget.newTarget(depthTexture));
renderFrameBuffer.addColorTarget(FrameBufferTarget.newTarget(renderedTexture));
reflectionView.setBackgroundColor(ColorRGBA.Cyan);
reflectionView.setOutputFrameBuffer(renderFrameBuffer);
As you can see the colored target worked successfully whereas the depth one wasn’t
the second method I was trying to get depthtexture by using filter like waterfilter and fogfilter:
FogFilter fogFilter = new FogFilter();
FilterPostProcessor filterPostProcessor = new FilterPostProcessor(assetManager);
filterPostProcessor.addFilter(fogFilter);
viewPort.addProcessor(filterPostProcessor);
depthTexture = filterPostProcessor.getDepthTexture();
Image img = renderedTexture.getImage();
but it return null
The third method by making custom filter and custom filterpostprocessor with no use
so please how to get depth texture in easy way possible?