Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertex shader version OpenGL 300 ES should probably be highp #4463

Closed
nicolasnoble opened this issue Aug 22, 2021 · 1 comment
Closed

Vertex shader version OpenGL 300 ES should probably be highp #4463

nicolasnoble opened this issue Aug 22, 2021 · 1 comment

Comments

@nicolasnoble
Copy link
Contributor

TL;DR

When using OpenGL ES, the default Vertex Shader precision causes wobbly / skewed rendering on large displays.

This happens on master and docking branches, with the base example and a single change:

This line here:

const char* glsl_version = "#version 130";

changed to:

    const char* glsl_version = "#version 300 es";

This now leads the backend to select a vertex shader that has mediump precision:

"precision mediump float;\n"

With a highp precision instead, the problem goes away. I don't believe having highp on the vertex shader should cause significant problems. It's okay to keep the pixel shader in mediump.

Example of the demo window in this state:

image

Screenshots / explanation

On a 4k display, the absolute position values can grow quite large. When the drawing happens closer to (0, 0), the Vertex Shader's medium precision works fine, but the more the rendering goes towards the opposite end of the screen, the more the shader's vectors will lose precision, resulting in bad skewing of the sprites positions.

These screenshots / videos are taking with a simple demo code that draws a simple window with the coordinates, and a higher font, for readability. My setup is 3 monitors, one in 4k, and 2 in 1080p, so mixed DPI mode (which explains the resolution change in the screenshots / video). My graphics card is an RTX 3090.

    if (ImGui::Begin("Skewing demo")) {
        auto w = ImGui::GetCurrentWindow();
        ImGui::Text("Location: (%.3f, %.3f)", w->Pos.x, w->Pos.y);
    }
    ImGui::End();

Here are various screenshots of this window in various locations:

Close to (0, 0), it looks fairly normal:
image

A bit further away, you can already see the i in the title being squeezed, compared with the i in the Location:
image

And when farther away enough, the window is totally skewed:
image

Here's a video of me moving the window horizontally across my monitors (you can notice the monitor change during the resizing):

imgui-skew.mp4

Resolution / proposed solution

Obviously, selecting a different shader version passed to ImGui_ImplOpenGL3_Init solves the issue. Passing nullptr isn't really an option for software that have their own shaders for other non-imgui rendering, as some GPU OpenGL drivers don't like mixing multiple shader versions within the same context. This has the unfortunate consequence of forcing software using 300 es as their shader version for portability to rework their code.

Changing the vertex shader to highp in the ImGui OpenGL3 backend however seems like the better solution. I don't believe it'd have any huge performance impact to only change the vertex shader this way.

ocornut pushed a commit that referenced this issue Aug 23, 2021
@ocornut
Copy link
Owner

ocornut commented Aug 23, 2021

Thank you Nicolas. I have confirmed and pushed a fix for this (gave you the commit attribution).

@ocornut ocornut closed this as completed Aug 23, 2021
AnClark pushed a commit to AnClark/imgui-vst-mod that referenced this issue Aug 30, 2021
AnClark pushed a commit to AnClark/imgui-vst-mod that referenced this issue Aug 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants