ZDoom / gzdoom

GZDoom is a feature centric port for all Doom engine games, based on ZDoom, adding an OpenGL renderer and powerful scripting capabilities
http://zdoom.org
GNU General Public License v3.0
2.56k stars 552 forks source link

[Feature] Gamma correction of albedo and output. #2091

Closed nullfrctl closed 1 year ago

nullfrctl commented 1 year ago

GZDoom version

g4.10.0-m, Flatpak

Which game are you running with GZDoom?

Doom 2

What Operating System are you using?

Linux x86_64

If Other OS, please describe

uBlue Bluefin, Fedora Silverblue spin.

Relevant hardware info

AMD Ryzen 5 1600X, NVIDIA RTX 3070

Is your feature request related to a problem? Please describe.

I was experimenting with the full settings menu when I noticed the tone mapping options didn't seem to really "work": all of them were looking like you were applying it on SDR, which I suspected being the answer as DOOM II is pretty old and doesn't have any HDR rendering. I imagine this is here to support mods, but even then, the tone mapping shader applies gamma on the already lit image as it is post processing. This makes the input exponential and not linear. It normally wouldn't be an issue as DOOM maps probably don't have HDR rendering in the first place, but something to consider.

Describe the solution you'd like

Restructure the shaders to apply a 2.2 gamma on albedo textures before lighting to get native linear, then apply the tone mapping operator, after which, 1/2.2 gamma should be applied to get a closer match to the IEC 61966:1996 sRGB specification (not perfect, but better than sqrt(c)).

Describe alternatives you've considered

Simply removing the tone mappers for now. I think it'd be fine as I don't feel that DOOM mods really use HDR in the first place, but I might be totally wrong.

Add any other context or screenshots about the feature request here.

This is what's currently being done to get back "linear" values, x being the albedo color, and l being a lighting applied on that albedo color. The actual values are exponential.

image

What I propose should be done. Apply a 2.2 gamma curve on only the albedo and leave lighting to do its job with linear.

image

nullfrctl commented 1 year ago

Sorry for adding a few things after the issue uploaded. I hit enter accidentally too early and submitted it early.

dpjudas commented 1 year ago

You are quite right that the tonemaps for GZDoom are pretty pointless. The only useful tonemap is the one that attempts to simulate palette visuals.

While what you are suggesting technically would create more accurate light, the problem is that the sector light level in Doom was never linear to begin with. Thus you would probably have to apply the gamma to the light level as well, which would leave only dynamic lights left doing anything in linear. Even then the radius and colors chosen by mappers have been selected based on non-linear visuals.

nullfrctl commented 1 year ago

Is it possible to reverse the sector light curve though to get back linear values of any kind? It would be a good addition to get a bit more accurate visuals, although your point that mappers with user's configurations have been selected based on these wrong calculations is true--maybe it's possible to make it a UI option for those seeking it?

Honestly, it's not such a huge deal, but I think it would enhance the visuals if HDR could be properly implemented in DOOM mods or maps, along with making nerds like me a bit happier lmao.

dpjudas commented 1 year ago

I used to think like you do too. That's why I added the tonemap shaders to begin with. And also why I added HDR monitor support (vk_hdr 1) and bloom.

However over the years I've also come to realize that you can't really take old assets and maps carefully designed for SDR+sRGB and then with a few cheap tricks in the shaders suddenly turn it into something more modern. It would only really work for new games designed in GZDoom and explicitly for this new light mode.

The issue with that is most indie game devs using GZDoom for their titles aren't really into this kind of thing. If they were, they wouldn't be using GZDoom as the base for their game. I don't really think this is solvable problem and therefore is no longer trying. :)

coelckers commented 1 year ago

This is the kind of stuff that will cost a lot of work and research but ultimately won't do the engine any good at all. dpJudas is correct by saying that all existing content was made for the current light model.