Viewport "resets" when adding a FilterPostProcessor (BloomFilter)

I need help with that please.



I’ve got several viewports that renders the object selected by the user. If I don’t use a filter, it displays the rendered object, but, as soon as I attach a PostProcessor to the viewport, all the viewport’s settings disapper. It’s moved elsewhere on the screen, background color is reset and there’s nothing in there, ie: the object is either invisible or the entire viewport is empty.



I noticed that in RenderManager → renderViewPort(…) it doesn’t seem to think the SceneProcessor has been initialized.

[java]

if (processors != null) {

for (SceneProcessor proc : processors) {

if (!proc.isInitialized()) { // <


Right here.
proc.initialize(this, vp); // so the viewport is "reinitialized"
}
proc.preFrame(tpf);
}
}
[/java]

I'm probably doing something wrong. Here's how I do it:
[java]
/*
* setViewPort
* @param previewName String, name of the preview
* @param nodeToAttach GameNode that is attached to the viewport
*/
private void setViewPort(String viewportName) {
panelViewPort = gProc.getRenderManager().createMainView(viewportName, panelCam);
panelViewPort.setBackgroundColor(ColorRGBA.DarkGray);
panelViewPort.setClearEnabled(true);
panelViewPort.attachScene(panelNode);
}

/*
* attachNewSceneToViewport
* @param noteToAttach
* new node to attach to viewport
*/
public void attachNewSceneToViewport(GameNode nodeToAttach) {
panelViewPort.clearScenes();
panelViewPort.attachScene(nodeToAttach);
setPostProcess();
}

private void setPostProcess() {
FilterPostProcessor fpp = new FilterPostProcessor(gProc.getAssetManager());

BloomFilter bf = new BloomFilter(BloomFilter.GlowMode.Objects);

fpp.addFilter(bf);
panelViewPort.addProcessor(fpp);
}
[/java]

mhhh actually filters does not work well with multiple viewports…

i’ll look into it

I’m currently doing some heavy cleanup and I noticed something right before I started…



There’s a “selector” image I put on the star when a selection is made and that selector was attached to a node called galaxyNode. That galaxyNode was attached to the rootNode (so it would be easier to switch views by simply removing the galaxyNode from the rootNode). Long story short, if instead of attaching that selector to the galaxyNode I attach it to the rootNode, I get the same thing as noted above: ALL preview screens (up to 2) are blank and do not retain the initial values. The main view remain unaffected.



This whole thing (and light inside a preview lighting objects in the main view) tell me think there’s something wrong with my code. I have fixed many things as of now, but since I’m not done yet I can’t run the game. Anyway, you might not want to spend too much time on this until I have had some more testing done with better code.



Just saying.

alright, just give me the heads up when you’ve made your clean up. :wink:

With the current system it is possible to apply the filter post processor to the entire screen even if you use multiple viewports, but it needs a little bit of hacking… It would be best if any sceneprocessors we have right now automatically constrained themselves to the viewport.

true!

Alright. I’ve done a lot of code clean-up and now I’m certain (as certain as I can get anyhow) that those viewports are not the cause of the filter problem.



So, first thing is to forget any code pasted before this post and the conclusions therein.



I’ve tried following the code by step-debugging but I haven’t been successful in finding the exact cause of the viewport relocation.

Checking the camera object tells me that “viewPortLeft, viewPortRight, viewPortTop and viewPortBottom” remain unchanged (as they should not be changed anyway), but somehow, the viewport gets relocated at “0, 0, 200, 200”. 200x200 is the viewport’s real size. But afaik, or afaiu, the original viewport’s coordinates on the screen are not used to compute the viewport’s location.



Does that make sense?



Here’s what it does:

This is the normal view without any post-processing. The “rightPreview” is at the right location.

http://www.danyrioux.com/files/nopp_viewport.png

This is the screen WITH post-processing. The “rightPreview” is relocated in the bottom left.

http://www.danyrioux.com/files/pp_viewport.png

The way I set up the filter is simple.

[java]

/*

  • setViewPort
  • @param previewName String, name of the preview
  • Sets basic viewport properties.

    */

    private void setViewPort(String viewportName) {

    if (viewportName.equals("listPreview")) {

    setListPreviewSceneParams();

    } else if (viewportName.equals("rightPreview")) {

    setRightPreviewSceneParams();

    }

    panelViewPort = gMgrs.getRenderManager().createMainView(viewportName, panelCam);

    panelViewPort.setBackgroundColor(ColorRGBA.DarkGray);

    panelViewPort.setClearEnabled(true);

    setPostProcess();

    }

    private void setPostProcess() {

    FilterPostProcessor fpp1 = new FilterPostProcessor(globalAssetManager);

    FogFilter ff = new FogFilter(ColorRGBA.Magenta, .5f, .75f);

    fpp1.addFilter(ff);

    panelViewPort.addProcessor(fpp1);

    System.out.println("…PostProcess set on: " + panelViewPort);

    }

    [/java]

Yeah that’s what we were talking about with Kirill, the filterProcessor does not restrain itself to the viewport it’s applied on.

I’m gonna look how i can fix that

Yup. But I wanted to make sure that it wasn’t something I was doing. Which wouldn’t have surprised me to be honest. But it isn’t.

Hey, this should be fixed in last SVN, could you give it a try and report back please?

thanks

1 Like

Did some changes to the game and for now it can’t really render. It shouldn’t be a long process to get it to work again, but while I do this, could you please remove the spam please? :wink:



In RenderManager, on line 622

[java] System.out.println(orthoMatrix);[/java]



I’ll get back to you ASAP.

k, I was able to run the game and have something to click on in the screen (making some changes and I can’t control anything on the screen except clicking on stars when the view show me some). Anyway.



The good news is, the viewport isn’t relocated anymore. The bad news is, the Filter doesn’t seem to work. It’s looks exactly the same as without a Filter.



To be sure I removed the Filter I had setup on the main viewport but it’s still the same.



Hmmm… Let me rebuild jME3… No change.



Maybe the Filters have some problem?



With a BloomFilter on the preview viewport, I get no result. The object displayed there is the same.

With a FogFilter, the preview is completely black. The FogFilter used is:



[java]FogFilter ff = new FogFilter(ColorRGBA.Magenta, .5f, .75f);[/java]

Just checked last modification made by @Momoko_Fan and it seems to be, umm, somehow, I think, working.



The thing is, the object isn’t in the viewport, or the camera isn’t placed at the right position when a Filter is attached to the viewport.



If I enable the BloomFilter, I won’t see the object at all because it’s not covering the entire viewport (it’s a sphere), but if I enable the FogFilter, I can see a little part of the fogged area in the viewport (since fog is calculated and displayed in the entire viewport). There’s maybe an inch wide by a 1/4 of an inch high in the upper right corner of the viewport where I can see the magenta colored fog.



The viewport’s background color is the same as defined when set (dark gray in my case).



As before, if I disable the Filters, it works. Except for that, the viewport is there and at its proper location.

madjack said:
Just checked last modification made by @Momoko_Fan and it seems to be, umm, somehow, I think, working.

Well that's strange because it broke TestMultiViews and TestFilterMultiViews

madjack said:
The thing is, the object isn't in the viewport, or the camera isn't placed at the right position when a Filter is attached to the viewport.

If I enable the BloomFilter, I won't see the object at all because it's not covering the entire viewport (it's a sphere), but if I enable the FogFilter, I can see a little part of the fogged area in the viewport (since fog is calculated and displayed in the entire viewport). There's maybe an inch wide by a 1/4 of an inch high in the upper right corner of the viewport where I can see the magenta colored fog.

The viewport's background color is the same as defined when set (dark gray in my case).

As before, if I disable the Filters, it works. Except for that, the viewport is there and at its proper location.

So...? working or not working?

Could you show me, how you create and initialize you view ports, please?
1 Like

Here’s the result with FogFilter enabled.



http://www.danyrioux.com/files/viewport_err.png



A tiny “fogged” area.



As for how, here it is.



There are two ways that I set it depending on which viewport it is, either the one on the right side or the one on the popup. As I said, if I remove the Filters, the previews work flawlessly.



[java]

/*

  • makePreviewScene
  • @param viewportName Name of the ViewPort
  • @param pickedObject Object selected to make a preview of

    *
  • makePreviewScene will setup the PreviewScene with the main selected object
  • and all subobjects if applicable (moons for a planet).

    /

    final public void makePreviewScene(String viewportName, Object pickedObject) {

    System.out.println("…Making viewport named: " + viewportName);

    this.objectInView = pickedObject;

    this.viewportName = viewportName;



    setPanelCamera(viewportName);

    panelNode = objectPreviewScene.getScene(objectInView);

    if (objectInView instanceof Star) {

    panelCam.setLocation(new Vector3f(10, 0, 0));

    panelCam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);

    isRotatable = true;

    } else if (objectInView instanceof Galaxy) {

    isRotatable = false;

    } else if (objectInView instanceof SolarSystem) {

    isRotatable = false;

    }



    setViewPort(viewportName);

    attachNewSceneToViewport(panelNode);

    setViewPortEnabled(true);

    setPostProcess();

    }



    /

  • setViewPort
  • @param previewName String, name of the preview
  • Sets basic viewport properties.

    */

    private void setViewPort(String viewportName) {

    if (viewportName.equals("listPreview")) {

    setListPreviewSceneParams();

    } else if (viewportName.equals("rightPreview")) {

    setRightPreviewSceneParams();

    }



    panelViewPort = gMgrs.getRenderManager().createMainView(viewportName, panelCam);

    panelViewPort.setBackgroundColor(ColorRGBA.DarkGray);

    }



    private void setListPreviewSceneParams() {

    // set viewport params

    this.setViewPortAreas(2.46f, 3.46f, 2.76f, 3.76f);

    this.setViewPortCamSize(165, 165);

    this.setCameraLocation(new Vector3f(10, 0, 0));

    this.setCameraLookAt(Vector3f.ZERO);

    }



    private void setRightPreviewSceneParams() {

    this.setViewPortAreas(5.23f, 6.33f, 0.56f, 1.66f);

    this.setViewPortCamSize(200, 200);

    this.setCameraLocation(new Vector3f(10, 0, 0));

    this.setCameraLookAt(Vector3f.ZERO);

    }

    [/java]



    If you need more info just ask.

thanks i’m gonna look a bit more into this :wink:

It seems @Momoko_Fan fixed the relocation problem with the last commit.



The previews are working and at their right place.



Although I have to admit I was only able to make the fog filter work. I’m wondering what are the basic ingredients I need to have the Glow Filter working.



PointLight? AmbientLight? DirectionalLight? Will any of those work or is there a specific kind of light the filter expects? Or am I simply missing something?



I’ll dig up and try to find some info on the subject.



Thanks guys for fixing that. It’s appreciated. :slight_smile:

Just noted something. The preview viewport background color is by default set to light gray but it’s black with the glow filter (even if the scene is or looks) empty.



EDIT: As explained above, because of the changes I can’t rotate the camera and what I thought was a black background was in fact the background of the main view. So, the preview viewports are actually transparent.



Here’s an image to show it.

Yeah, I’m currently re-thinking the filters/viewport thing.

I have something functional in my local copy, but there are issue when you stack several filters on the same viewport or when you disable all the filters in the stack (if you have more than one viewport).



It’s a bit tricky and need to be thoroughly tested so it could take some time.



I already noticed that the glow filter changes the back ground of the viewport, this is due to the method used to compute bloom/glow, I look into it, but i’m afraid there is no simple solution.



BTW, the actual version works, but the filter is computed in full size, and not viewport size. So it’s slow. That’s why 'im re thinking the whole thing

Ok, well I hope this time it’s gonna work.

Filters should now support multiviews…you tell me :stuck_out_tongue: