-
Notifications
You must be signed in to change notification settings - Fork 62
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
Dynamic lights in linear colorspace #1544
Comments
To add to the topic, using linear attenuation for real time lights is the usually accepted workaround for blending a light in a non-linear colorspace, it is wrong but using this trick makes possible to keep the same light value in both linear and non-linear colorspace, by using a wrong linear attenuation in non-linear colorspace, and a correct quadratic attenuation in linear colorspace. Some games used such workaround with the non-linear colorspace, like Wolfenstein: Enemy Territory. It used the
|
So it looks like our engine was doing the same workaround as wolf:et for dynamic lights, now we are doing as bad as quake3 q3map2 profile. |
I guess the linear 1/r thing kind of makes sense since supposing srgb2linear(x) = x2.2, then srgb2linear(1/r) = 1/r2.2 which is approximately 1/r2. Maybe 1/r0.9 would be even closer. Assuming we go with the route of using one of 2 possible global color spaces, determined by the map, it seems like going back to overbright clamping being on by default would help solve some problems. Then we could use 1/r light attenuation in non-sRGB mode (per Reaper's code comment quoted in the OP that full overbright worked poorly with 1/r lights), and we could enable bloom without issues. Since the only sRGB maps that exist will be newly built ones, we can have those specify full-range overbright in the worldspawn. |
We just need to add HDR->LDR tonemapper, since we already have the HDR buffers, but currently we're just clamping the values to [0.0, 1.0]:
Which effectively nullifies this advantage of using HDR buffers. I have a branch with a Lottes tonemapper + adaptive lighting, I'll rebase it on master and add a pr for it a bit later. Just need to clean it up and add a macro or uniform to check for HDR buffer usage. |
The current advantage of using HDR buffers is to not lose precision when blending multiple stages. Using HDR buffers may have other advantages that may be nullified by such clamping, but this blending advantage is not nullified by clamping the output. Here with a slider: https://imgsli.com/MzQ3ODg4 |
Overbright clamping never was a feature, and the implementation we had was a bug and a regression. |
Yeah, I'm talking about the HDR->LDR conversion for displaying. |
There is now an HDR->LDR tonemapper implementation in #1550. It fixes the dynamic lights being clamped as well:
The code is actually still wrong, but for different reasons: the
If the All of those other ones still look wrong. |
Also note that #1425 NUKES the random dynamic light scaling, so any changes made to dynamic lights should take that into account. |
I'm not sure why those random multipliers and additions in shaders were even there in the first place, maybe we should just NUKE those while making sure that dynamic lights we have in assets work correctly. |
In
computeLight_fp.glsl
incomputeDynamicLight()
function we have this code:The comments suggest the code was modified from using a linear attenuation function to a quadratic attenuation once the complete overbright had been unlocked.
That may be wrong because if the light was not properly displayed with a not-clamped overbright, it means that maybe the values were wrong to begin with and that clamping was hiding the bug.
But my main concern isn't that. On this page we can read:
So, if I understand it correctly, the light attenuation function should be currently linear, it should be linear when loading all our Tremulous and current Unvanquished maps, and it should be quadratic only when loading the future maps that will be processed in linear space.
That code already using the quadratic function means we can't convert it from linear to quadratic…
The text was updated successfully, but these errors were encountered: