Viewport is not resized if any filter is applied on it

Hi!

I think I found an issue in the engine. If you resize a camera by running cam.setViewPort(left,right,bottom,top) and you have any filter applied to it, the viewport is not resized. I’m using jme3.3.2

Here’s a simple test case for the issue. It creates a simple scene and animates the viewport size. If you run it, the viewport size is not changed but if you comment the line “fpp.addFilter(ssao);” the viewport is resized as expected:

package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.post.FilterPostProcessor;
import com.jme3.post.ssao.SSAOFilter;
import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;

public class Main extends SimpleApplication {

    private float viewSize=0f;
    private boolean viewChangeDir=true;
    
    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        
        // Create an empty pre view to clear the whole screen with a different background color 
        Camera preCam=cam.clone();
        Node preRoot=new Node("pre");
        preRoot.updateGeometricState();
        ViewPort preView=renderManager.createPreView("Upgrade", preCam);
        preView.setClearFlags(true, true, true);
        preView.setBackgroundColor(ColorRGBA.DarkGray);
        preView.attachScene(preRoot);
        
        // Simple default blue box scene
        Box b = new Box(1, 1, 1);
        Geometry geom = new Geometry("Box", b);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Blue);
        geom.setMaterial(mat);
        rootNode.attachChild(geom);

        // Filters
        FilterPostProcessor fpp=new FilterPostProcessor(assetManager);
        SSAOFilter ssao=new SSAOFilter();
        // If filter is added, the viewport is never resized
        fpp.addFilter(ssao);
        viewPort.addProcessor(fpp);
    }

    @Override
    public void simpleUpdate(float tpf) {
        
        // make it smaller
        if(viewChangeDir)
        {
            viewSize+=tpf/5.0f;
            if(viewSize>0.4f)
            {
                viewSize=0.4f;
                viewChangeDir=!viewChangeDir;
            }
        }
        // make it bigger
        else
        {
            viewSize-=tpf/5.0f;
            if(viewSize<0f)
            {
                viewSize=0f;
                viewChangeDir=!viewChangeDir;
            }
        }
        cam.setViewPort(viewSize, 1-viewSize, viewSize, 1-viewSize);
    }

}

The test is done using ssao but any filter will lock the viewport size.

I’ve not investigated this deeply but I think the filters are not re-initialized if the camera view port size is changed so they use the same framebuffer size always

Probably this is not the typical use case as most users may just use the default main and gui viewport of in some special cases create new viewports with the size they want and never change them…

Thanks

2 Likes