Skip to content

Rework sRGB support#2483

Draft
levinli303 wants to merge 2 commits intomasterfrom
feature/srgb-support
Draft

Rework sRGB support#2483
levinli303 wants to merge 2 commits intomasterfrom
feature/srgb-support

Conversation

@levinli303
Copy link
Copy Markdown
Collaborator

Render in linear light with a final post-process sRGB conversion instead of relying on hardware GL_FRAMEBUFFER_SRGB.

  • Add SRGBViewportEffect as the final viewport effect for linear→sRGB conversion, with a GL_RGBA16F source FBO
  • Pre-linearize input colours (HUD, labels, stars, galaxies, atmospheres) for correct blending in linear space
  • Detect sRGB PNG/JPEG textures and use sRGB internal formats
  • On GLES, expand sRGB luminance formats to GL_SRGB8_ALPHA8 at upload time since GL_SLUMINANCE is unavailable (ANGLE/Metal)

@levinli303 levinli303 force-pushed the feature/srgb-support branch from 68053ac to f7b647f Compare April 9, 2026 06:56
@levinli303
Copy link
Copy Markdown
Collaborator Author

levinli303 commented Apr 9, 2026

to test:

download exe, dll, shaders, etc from and replace files in the 1.7.0 install (likely you'll use celestia-windows-x64-qt6gui)
https://github.com/CelestiaProject/Celestia/actions/runs/24272795050

@levinli303 levinli303 force-pushed the feature/srgb-support branch 14 times, most recently from 2e8ebdf to 90b44ae Compare April 11, 2026 02:02
@levinli303 levinli303 mentioned this pull request Apr 11, 2026
levinli303 added a commit that referenced this pull request Apr 13, 2026
Taken from #2483 no behavior change yet

Fix a bug that iOS ES2 has OES_depth24 extension and will try to call
this. GL_DEPTH_COMPONENT24 is not valid for ES2.
```
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr);
```

I've tested viewport effects with:
iOS (ES2, ES3) and macOS (desktop GL), with MSAA on/off (ES2 FBO's MSAA
is always off), with float or non-float storage.
@levinli303 levinli303 force-pushed the feature/srgb-support branch 2 times, most recently from 8adbeb9 to 9e98360 Compare April 14, 2026 17:13
Comment thread src/celimage/jpeg.cpp
PixelFormat format = PixelFormat::RGB;
// JPEG color images are always sRGB-encoded; grayscale channels are
// treated as linear (they're typically used as height/alpha data).
PixelFormat format = PixelFormat::sRGB;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some grayscale textures (like the asteroid maps in CelestiaContent) are intended to be used as sRGB, so if possible, this should be limited to bump maps and alpha channels.

@levinli303 levinli303 force-pushed the feature/srgb-support branch 7 times, most recently from 7b2a2a6 to 9ce194c Compare April 14, 2026 21:12
Render in linear light with a final post-process sRGB conversion
instead of relying on hardware GL_FRAMEBUFFER_SRGB.

- Add SRGBViewportEffect as the final viewport effect for
  linear→sRGB conversion, with a GL_RGBA16F source FBO
- Pre-linearize input colours (HUD, labels, stars, galaxies,
  atmospheres) for correct blending in linear space
- Detect sRGB PNG/JPEG textures and use sRGB internal formats
- On GLES, expand sRGB luminance formats to GL_SRGB8_ALPHA8 at
  upload time since GL_SLUMINANCE is unavailable (ANGLE/Metal)

Remove gamma tone-mapping hack from light source normalization

Now that the rendering pipeline uses float color textures with sRGB
output, the old gamma compensation (γ≈0.602) for making dim secondary
light sources visible in 8-bit framebuffers is no longer needed.
Light irradiance is now simply normalized linearly by the total.

Support sRGB on GLES2 too

Better support GLES
@levinli303 levinli303 force-pushed the feature/srgb-support branch from 9ce194c to b633caa Compare April 16, 2026 04:50
@levinli303 levinli303 force-pushed the feature/srgb-support branch 3 times, most recently from 9db6d9c to fee0584 Compare April 16, 2026 07:03
Add a config-file option (SRGBRendering, default false) that controls
whether the linear-light rendering pipeline is active.  When off, the
renderer behaves as before the sRGB branch: no color linearization, no
sRGB texture formats, no gamma-related code changes, and no sRGB
post-process viewport effect.

On GLES, enabling the setting requires GL_EXT_sRGB; if the extension
is missing the setting is silently forced off.

Also add sRGB-aware image loading:
- DDS: support DX10 extended header with DXGI sRGB format variants
- AVIF: detect sRGB vs linear from CICP transfer characteristics
@levinli303 levinli303 force-pushed the feature/srgb-support branch from fee0584 to b06e1f4 Compare April 16, 2026 19:56
@sonarqubecloud
Copy link
Copy Markdown

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.

2 participants