Adding shadows, exception in FrameBuffer

Hi!

I have a wierd problem with adding a shadow filter. My application is running and already has a FilterPostProcessor.
I try to add a shadow by:

[java]PointLightShadowFilter = new PointLightShadowFilter(shadowMapSize);
shadowFilter).setLight(light);
filterPostProcessor.addFilter(shadowFilter);[/java]

Simple :slight_smile:

However I get the follwoing exception:

java.lang.UnsupportedOperationException : FrameBuffer already initialized.
  1. com.jme3.texture.FrameBuffer.setDepthTexture(FrameBuffer.java:400)
  2. com.jme3.post.FilterPostProcessor.initFilter(FilterPostProcessor.java:162)
  3. com.jme3.post.FilterPostProcessor.addFilter(FilterPostProcessor.java:109)

(…)

Looking at the code in FilterPostProcessor:

[java] private void initFilter(Filter filter, ViewPort vp) {
filter.setProcessor(this);
if (filter.isRequiresDepthTexture()) {
if (!computeDepth && renderFrameBuffer != null) {
depthTexture = new Texture2D(width, height, Format.Depth24);
renderFrameBuffer.setDepthTexture(depthTexture);
}
computeDepth = true;
filter.init(assetManager, renderManager, vp, width, height);
filter.setDepthTexture(depthTexture);
} else {
filter.init(assetManager, renderManager, vp, width, height);
}
}[/java]

Suggests that if I could create a depth texture for the postprocessor just after init everything would work out fine. Is this correct?
And if yes, is there a way to do that?

Thanks :slight_smile:

that’s strange, it looks like computeDepth is false yet the depth texture has already been initialized
can you post how and where you initialize the filters and the FilterPostProcessor?

Thanks for the reply :slight_smile: What I’m doing is rather simple.

post processor init:
[java]FilterPostProcessor filterPostProcessor = new FilterPostProcessor(assetManager);
viewPort.addProcessor(filterPostProcessor);

BloomFilter filter = new BloomFilter(glowMode);

filter.setBloomIntensity(bloomIntensity);
filter.setBlurScale(blurScale);
filter.setDownSamplingFactor(downSampling);
filter.setExposureCutOff(exposureCutOff);
filter.setExposurePower(exposurePower);

filterPostProcessor.addFilter(filter);[/java]

I add more filters but everything in the same way.

However in FrameBuffer I noticed:
[java] public void setDepthTexture(Texture2D tex){
if (id != -1)
throw new UnsupportedOperationException(“FrameBuffer already initialized.”);

    Image img = tex.getImage();
    checkSetTexture(tex, true);
    
    depthBuf = new RenderBuffer();
    depthBuf.slot = -100; // indicates GL_DEPTH_ATTACHMENT
    depthBuf.tex = tex;
    depthBuf.format = img.getFormat();
}[/java]

For me it looks as if when the framebuffer is already initialized, you can’t add a depth texture to it. Which seems kind of weird…

What filters do you use? I mean all of them