jMonkeyEngine / jmonkeyengine

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

fullscreen mode disables gamma correction #1226

Open stephengold opened 4 years ago

stephengold commented 4 years ago

I've noticed visually that applications with gamma correction enabled look very different in windowed display modes than they do in fullscreen. Visual comparisons suggest this is because gamma correction isn't actually enabled in fullscreen mode.

Seen in both v3.2.4 and v3.3.0-alpha5 of jMonkeyEngine with both v2 and v3 of LWJGL.

riccardobl commented 3 years ago

I can't reproduce this. Maybe there was something wrong in the code you were testing.

stephengold commented 3 years ago

I'll check again.

stephengold commented 3 years ago

I wasn't able to test on Linux due to issue #947. On Windows 7, a simple test with JME 3.3.2-stable and LWJGL 2.9.3 shows noticeable contrast between the viewport background and the stats background:

  1. in a 16bpp 640x480 window with isGamma=true
  2. in a 16bpp 640x480 fullscreen with isGamma=true
  3. in a 16bpp 640x480 fullscreen with isGamma=false

but no contrast (black-and-black) in a 16bpp 640x480 window with isGamma=false.

Here is the test app:

import com.jme3.app.SimpleApplication;
import com.jme3.font.BitmapText;
import com.jme3.math.ColorRGBA;

public class Main extends SimpleApplication {

    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        flyCam.setEnabled(false);

        ColorRGBA backgroundColor = new ColorRGBA(0.04f, 0.04f, 0.04f, 1f);
        viewPort.setBackgroundColor(backgroundColor);

        BitmapText statusText = new BitmapText(guiFont, false);
        statusText.setLocalTranslation(0f, cam.getHeight(), 0f);

        String message = 
                "   bpp=" + settings.getBitsPerPixel()
                + "   fullScreen=" + settings.isFullscreen() 
                + "   isGamma=" + settings.isGammaCorrection();
        statusText.setText(message);
        guiNode.attachChild(statusText);
    }
}
riccardobl commented 3 years ago

That's the normal behavior. Writing to an sRGB framebuffer causes the color to be gamma corrected, they will look different unless they are linearized beforehand

        ColorRGBA backgroundColor = new ColorRGBA().setAsSrgb(0.04f, 0.04f, 0.04f, 1f);

Textures are linearized automatically

stephengold commented 3 years ago

I agree that colors should look different between isGamma=true and isGamma=false, but that's not what this issue is about. The issue is that they don't look different in fullscreen, even between isGamma=true and isGamma=false.

riccardobl commented 3 years ago

I can't reproduce...could it be driver specific? Do you get the same issue even with 24bpp color depth?

stephengold commented 3 years ago

I suppose it could be a driver-specific issue.

I'm not finding any fullscreen modes with 24bpp color depth. However, I reproduced the issue with 32bpp 640x480 fullscreen.

riccardobl commented 3 years ago

Can you try to use native resolution fullscreen with lwjgl3? Also, what drivers are you using, on which gpu?

stephengold commented 3 years ago
LWJGL 2.9.3 context running on thread jME3 Main
 * Graphics Adapter: nvd3dumx,nvwgf2umx,nvwgf2umx
 * Driver Version: 23.21.13.8873
 * Scaling Factor: 1
OpenGL Renderer Information
 * Vendor: NVIDIA Corporation
 * Renderer: GeForce GT 545/PCIe/SSE2
 * OpenGL Version: 4.6.0 NVIDIA 388.73
 * GLSL Version: 4.60 NVIDIA
 * Profile: Compatibility

I tested with LWJGL3 at the highest available resolutions and found good contrast:

but poor contrast (black-and-black):

In other words, the issue went away with high resolution and LWJGL3. Okay, that's interesting. Do you have a hypothesis that might explain all this?

yaRnMcDonuts commented 3 years ago

I can confirm I am also experiencing the same issue when trying to run full screen.

Since @riccardobl was unable to reproduce the issue, I should note that my device's GPU is a NvidiaGeForce GTX 1080. I still need to test this on my older device with an AMD but will report back with the results when I do.

stephengold commented 3 years ago

@yaRnMcDonuts any news on this issue?

Ali-RS commented 1 year ago

I can not reproduce this issue. I am testing with Linux and JME 3.6.0-beta1.

Tested with these GPUs:

INFO: OpenGL Renderer Information
 * Vendor: Intel Open Source Technology Center
 * Renderer: Mesa DRI Intel(R) HD Graphics 3000 (SNB GT2)
 * OpenGL Version: 3.3 (Core Profile) Mesa 20.0.8
 * GLSL Version: 3.30
 * Profile: Core

and

INFO: OpenGL Renderer Information
 * Vendor: X.Org
 * Renderer: AMD CEDAR (DRM 2.50.0 / 5.4.0-58-generic, LLVM 10.0.0)
 * OpenGL Version: 3.3 (Core Profile) Mesa 20.0.8
 * GLSL Version: 3.30
 * Profile: Core

LWJGL 2

fullscreen mode

lwjgl2-fullscreen-mode

window mode lwjgl2-window-mode

LWJGL 3

fullscreen mode lwjgl3-fullscreen-mode

window mode lwjgl3-window-mode

Ali-RS commented 1 year ago

And this is how it looks with gamma off:

no-gamma

riccardobl commented 1 year ago

I've tested again on an RTX 2060s with 3.6.0-beta2 and i still can't reproduce :thinking:

stephengold commented 1 year ago

I reproduced the issue today, but it wasn't easy: I failed to repro it on Linux, nor could I repro it on my WIndows 11 laptop with an RTX 2070.

Here's what worked for me:

  1. Boot the Windows 7 Professional SP 1 partition on my desktop (the machine with the NVIDIA GeForce GT 545).
  2. Check "Fullscreen?" in the display settings.
  3. Visually compare the display, both with "Gamma correction" checked and unchecked.

After reproducing the issue (no visible difference between the displays) on 3.2.4-stable with LWJGL v2, I rebuilt the test app with 3.6.0-stable and jme3-awt-dialogs and ran it in the same environment. I was still able to repro the issue.

I was also able to reproduce the issue with LWJGL v3 instead of v2.

However, switching from fullscreen to windowed mode with LWJGL v2 made the issue go away: gamma correction had a visible effect.

My best guess would be it's a driver issue, but I can't prove it. The NVIDIA control panel displays the driver version as "388.73"

I'm leaving this issue open for now.