PostProcessing with multiple SMALLER views.. possible bug?

Hello everyone!
I’m still a beginner with this so I might be doing something wrong.
I’m writing an application for research and I want to render a simple scene made up of boxes, then I want to render a bunch of mini views at the bottom of the screen (different aspect ratios from the original large view) with different post processors. The post processing filter is supposed to render masks of visible parts of each box, similar to a stencil buffer which I never figured out how to use correctly in jMonkey.

I had the scene setup and it’s working fine until I add the post processors to the mini views, at this point all the views collapse to the lower left corner. I thought this could be a bug in the custom MaskFilter I wrote, but I tried other filters like Bloom and other stuff and they all had the same problem. The mini views all stack at the lower left corner.

I checked jMonkey code and there is a line in FilterPostProcessor.java reshape method, cam.setViewPort(0,1,0,1). I think it could be the source of the problem but I’m not sure about it. I tried commenting it but it didn’t resolve the problem.

Here is the piece of code to setup the mini views:
[java]
int subWinWidth = settings.getWidth() / likelihoods.size();
String[] keyset = likelihoods.keySet().toArray(new String[0]);
for(int i = 0; i < keyset.length; i++) {
FilterPostProcessor tempP = new FilterPostProcessor(assetManager);
String key = keyset[i];
tempP.addFilter(new MaskFilter(key));

        Camera cam2 = new Camera(subWinWidth,subWinWidth);
        cam2.copyFrom(cam);
        cam2.setName(key+&quot;Camera&quot;);
        cam2.resize(subWinWidth, subWinWidth, true);
        cam2.setViewPort(i, i+1f, 0, 1f);
        cam2.getRotation().set(cam.getRotation());
        cam2.getLocation().set(cam.getLocation());
        ViewPort miniView = renderManager.createPostView(key+&quot;View&quot;, cam2);
        miniView.setBackgroundColor(ColorRGBA.Black);
        miniView.setClearFlags(true, true, true);
        miniView.attachScene(rootNode);
        //miniView.addProcessor(tempP);
    }

[/java]

And here are the screenshots:
with the processor added (line 19 uncommented):

without the processor added (line 19 commented):

Are the miniviews different viewports? It should work. The Filter processor wasn’t initially designed to work with multiple viewports, but some time ago I did make some changes so it work.
I think @madjack use them extensively, so I’m surprised there are still issues with this.
Could you wrap up a test case?

Also, looking at the resolution of your screenshots, I’m wondering if you are planning to use this on android?
Filter post processing is not supported on android at the moment so you may have other issues.

yes the miniviews are different viewports with different cameras. The cameras are copied from the original camera in the main view (I actually copied the supplied code from my program). The intention is to render parts of the scene as white silhouettes like the one that appears in the first screenshot. I think that should be possible with stencils but I don’t know how to use them.

And this is not for android… it just happens to look like that in this particular example… Good observation though!

I made a quick test and it’s working fine.

How do you create your viewports?
look at this testcase http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/test/jme3test/post/TestMultiViewsFilters.java

1 Like

hmm… that’s weird…
I’m creating them using the piece of code I put in the first post.

Since the viewports are of a different resolution and aspect ratio than the original view, I need to recreate the cameras instead of cloning them (that’s what the documentation said)… Could that be the reason?

EDIT:
it turns out the reason IS actually using cameras with different resolutions than the original.
I changed them so they are cloned from the original camera and now they are working.
My custom filter is not working properly, though. It is rendering at the size of the original view even though it’s attached to the small ones. I think I need to research more about custom filters…

Thanks for the help!

mhh wait
this looks wrong
[java]
cam2.setViewPort(i, i+1f, 0, 1f);
[/java]
the values must be from 0 to 1
Actually I can’t see how it works without filters :stuck_out_tongue:

i guess your cams should have something like this
[java]
float width = 1f/ (float)keyset.length;
cam2.setViewPort(i * width , width, 0, 0.1f);
[/java]
the last 0.1 is an example, if you want the height to be one tenth of the window height

1 Like

You’re right. It requires the values to be between 0 and 1. However, since I was using smaller views with actual smaller resolutions, the [0,1] range mapped into the dimensions of the smaller view. So if I wanted to shift it to the right, I actually needed to position it using values more than 1.

I guess your cams should have something like this ...
yes that's what I did to fix the problem in my previous post. However, it requires that I use miniviews with the same resolution as the original one (even though they are scaled down). That way, the [0,1] range maps into the actual positions of the original large view.

I think I’m going to start another thread to ask about how to develop the mask filter or replace it with stencil somehow. However, I don’t have time to do this now as the paper deadline is in two days (talk about last minute! )

Thank you very much for the help! Your post was really helpful :amused:

1 Like