jmonkeyengine icon indicating copy to clipboard operation
jmonkeyengine copied to clipboard

Updating the frustum does not work as expected

Open slyh80 opened this issue 9 years ago • 9 comments

There seems to be a problem when updating the frustum, camera and/or viewport.

Steps to reproduce:

  1. Resize a viewport so it has another aspect ratio as before
  2. Update camera aspect ratio
  3. Notice that the resulting rendering is stretched

Please see this discussion for details, including code sample: http://hub.jmonkeyengine.org/t/aspect-ratio-not-updated-when-resizing-viewport/33936/

slyh80 avatar Sep 29 '15 12:09 slyh80

I suspect class RenderManager (line 334) as part of the problem.

        for (ViewPort vp : viewPorts) {
            if (vp.getOutputFrameBuffer() == null) {
                Camera cam = vp.getCamera();
                cam.resize(w, h, true);
            }
            notifyReshape(vp, w, h);
        }

Note: I'm a layman regarding jME's internals. But resizing all viewports to the window's(!) width and height does not make too much sense for me. Right?

slyh80 avatar Sep 29 '15 12:09 slyh80

As I noted on the Forum today:

https://hub.jmonkeyengine.org/t/solved-aspect-ratios-of-cameras-in-a-split-screen-render/38922

Camera.resize() with fixAspect=true doesn't take the camera's viewport dimensions into account when calculating what the frustum's aspect ratio is. Since the renderer frequently invokes resize(w, h, true) on user cameras, the resulting renders appear squashed unless

viewPortTop - viewPortBottom == viewPortRight - viewPortLeft

This turns out to be the root cause of issue #357. I ran the test code (submitted by slyh on Sep 28, 2015) with jME 3.1.0-stable. I reproduced the reported issue, then patched Camera.resize() and verified that the patch resolved the issue.

stephengold avatar Jul 07 '17 04:07 stephengold

Interesting. I managed to make this work not too long ago on 3.1 stable without patching the engine, can't remeber how though.

grizeldi avatar Jul 07 '17 06:07 grizeldi

fixed on master

empirephoenix avatar Jul 13 '17 10:07 empirephoenix

TestAspectRatio is failing on jMonkeyEngine 3.2.3-v3.2-6660 on Linux, with the blue cube rendering as a rectangle instead of a square, even though that build includes the fix to Camera.resize(). That same test works on jMonkeyEngine 3.2.3-v3.2-6660 on Windows.

stephengold avatar Jul 12 '19 17:07 stephengold

Still failing on Linux as of Git hash 4b62b70 in the v3.3 branch.

stephengold avatar Apr 23 '20 13:04 stephengold

Some analysis here: https://hub.jmonkeyengine.org/t/betterlensflare/42779/4

stephengold avatar Nov 12 '20 17:11 stephengold

Some notes: While the test works by default on Windows, building jme3-examples with jme3-lwjgl3 causes the same issue as on Linux. Speaking of Linux, the library used doesn't actually matter. This is...interesting. Also, while the test by default sets the viewport to cover the upper half of the window, the bugged version has the viewport cover the third out of 4 parts of the window or something Screenshot from 2021-04-14 22-20-13 Oddly enough, skipping the camera adjustments and just setting the viewport and seems to work just as well on Windows LWJGL2, and gets the viewport in the right place in the bugged versions. The stretched ratio is still present, though. Some more digging seems to point towards Renderer.setViewport(), which pretty much just calls LWJGL itself. I'm guessing that this isn't an issue with jmonkey as it is with LWJGL itself.

Markil3 avatar Apr 15 '21 04:04 Markil3

Still failing in v3.4.0-beta4

stephengold avatar May 13 '21 21:05 stephengold