Skip to content

Add a workaround for poor NPOT mipmap implementations#3080

Merged
10110111 merged 1 commit into
Stellarium:masterfrom
10110111:texture-average-npot
Mar 5, 2023
Merged

Add a workaround for poor NPOT mipmap implementations#3080
10110111 merged 1 commit into
Stellarium:masterfrom
10110111:texture-average-npot

Conversation

@10110111
Copy link
Copy Markdown
Contributor

@10110111 10110111 commented Mar 4, 2023

Description

We use the deepest mipmap level as the average of texture data in order to compute brightness of the scene in AtmosphereShowMySky. Some OpenGL implementations, however, appear to handle non-power-of-two textures poorly when computing mipmap levels. The result is that, when a texture dimension is close to a power of two but not exactly it, the whole mip map displays ugly aliasing, and the deepest 1×1 level is very far from the average of the texels of level 0.

The effect can be seen when resizing the window on e.g. Mesa-based drivers on Linux (and, IIRC, Intel on Windows). As you resize the window, the daytime atmosphere will change its brightness erratically, which shouldn't really happen.

To work around such implementations, we resize the base level texture to the closest smaller power-of-two texture, and compute the mip map from it instead of the initial texture. The resize introduces a small inaccuracy, but the result is still much higher quality than if we used glGenerateMipmap() on the initial NPOT texture.

On good implementations such as NVIDIA GPU drivers, the workaround is disabled.

The functionality of such averaging is implemented in a class TextureAverageComputer that's only available on desktop OpenGL. On OpenGL ES 2 it's #ifdefed out.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • This change requires a documentation update

How Has This Been Tested?

Test Configuration:

  • Operating system: Ubuntu 20.04
  • Graphics Card: Intel UHD Graphics 620

Checklist:

  • My code follows the code style of this project.
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (header file)
  • I have updated the respective chapter in the Stellarium User Guide
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 4, 2023

Great PR! Please pay attention to the following items before merging:

Files matching src/**/*.cpp:

  • Are possibly unused includes removed?

This is an automatically generated QA checklist based on modified files.

@alex-w alex-w added this to the 23.1 milestone Mar 4, 2023
Comment thread src/CMakeLists.txt Outdated
core/StelOpenGLArray.cpp
core/StelHips.hpp
core/StelHips.cpp
core/TextureAverageComputer.hpp
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix indentation

We use the deepest mipmap level as the average of texture data in order
to compute brightness of the scene in AtmosphereShowMySky. Some OpenGL
implementations, however, appear to handle non-power-of-two textures
poorly when computing mipmap levels. The result is that, when a texture
dimension is close to a power of two but not exactly it, the whole mip
map displays ugly aliasing, and the deepest 1×1 level is very far from
the average of the texels of level 0.

The effect can be seen when resizing the window on e.g. Mesa-based
drivers on Linux (and, IIRC, Intel on Windows). As you resize the
window, the daytime atmosphere will change its brightness erratically,
which shouldn't really happen.

To work around such implementations, we resize the base level texture to
the closest smaller power-of-two texture, and compute the mip map from
it instead of the initial texture. The resize introduces a small
inaccuracy, but the result is still much higher quality than if we used
glGenerateMipmap() on the initial NPOT texture.

On good implementations such as NVIDIA GPU drivers, the workaround is
disabled.

The functionality of such averaging is implemented in a class
TextureAverageComputer that's only made available on desktop OpenGL. On
OpenGL ES 2 it's #ifdefed out.
@10110111 10110111 force-pushed the texture-average-npot branch from 04bcd86 to 84f7d16 Compare March 4, 2023 19:36
Copy link
Copy Markdown
Member

@gzotti gzotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on my Intel Core i5-4570. I never saw the brightness issue during windows resize before, but on this slow system I usually have the old sky model. Yes, I confirm this works here!

@10110111 10110111 merged commit 35e4081 into Stellarium:master Mar 5, 2023
@10110111 10110111 deleted the texture-average-npot branch March 5, 2023 06:14
@github-actions
Copy link
Copy Markdown

Hello @10110111!

The enhancement or feature has been merged into source code and you may test it via building Stellarium from source code or wait the weekly development snapshot...

@github-actions
Copy link
Copy Markdown

Hello @10110111!

The fix has been merged into source code and you may test it via building Stellarium from source code or wait the weekly development snapshot...

@alex-w alex-w added state: published The fix has been published for testing in weekly binary package and removed state: fixed labels Mar 13, 2023
@github-actions
Copy link
Copy Markdown

Hello @10110111!

Please check the fresh version (development snapshot) of Stellarium:
https://github.com/Stellarium/stellarium-data/releases/tag/weekly-snapshot

@alex-w alex-w removed the state: published The fix has been published for testing in weekly binary package label Mar 27, 2023
@github-actions
Copy link
Copy Markdown

Hello @10110111!

Please check the latest stable version of Stellarium:
https://github.com/Stellarium/stellarium/releases/latest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants