jMonkeyEngine / jmonkeyengine

A complete 3-D game development suite written in Java.
http://jmonkeyengine.org
BSD 3-Clause "New" or "Revised" License
3.82k stars 1.12k forks source link

Updating the frustum does not work as expected #357

Open slyh80 opened 9 years ago

slyh80 commented 9 years ago

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 commented 9 years ago

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?

stephengold commented 7 years ago

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.

grizeldi commented 7 years ago

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

empirephoenix commented 7 years ago

fixed on master

stephengold commented 5 years ago

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 commented 4 years ago

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

stephengold commented 3 years ago

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

Markil3 commented 3 years ago

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.

stephengold commented 3 years ago

Still failing in v3.4.0-beta4