gl4es icon indicating copy to clipboard operation
gl4es copied to clipboard

OpenMW's gamma correction

Open AbduSharif opened this issue 4 years ago • 12 comments

I got these warnings when playing with OpenMW in openmw.log, I was using an Android-specific patch from the openwm-android repo with v1.1.4 and I don't see those warnings: [12:16:29.683 W] Warning: detected OpenGL error 'invalid enumerant' after applying attribute GammaCorrection 0x76d6ede800 [12:16:29.705 W] Warning: detected OpenGL error 'invalid enumerant' after applying attribute GammaCorrection 0x76ed065900

The Android patch from the openmw-android repo. I don't know if this is viable to use with gl4es in general and haven't tried it with the latest nightly of gl4es, but it works with stable gl4es and OpenMW android (nightly or stable): https://github.com/xyzz/openmw-android/blob/master/buildscripts/patches/gl4es/gamma.patch

AbduSharif avatar Jan 28 '21 17:01 AbduSharif

The gamma patch changes does work with gl4es nightly and OpenMW nightly, and I no longer get the gamma correction warning.

AbduSharif avatar Jan 28 '21 23:01 AbduSharif

I seem to have miss clicked and closed the issue.

AbduSharif avatar Jan 28 '21 23:01 AbduSharif

The gamma patch changes does work with gl4es nightly and OpenMW nightly, and I no longer get the gamma correction warning.

Is the issue fixed then?

akortunov avatar Jan 29 '21 07:01 akortunov

Yeah if I use the gamma patch changes.

AbduSharif avatar Jan 29 '21 09:01 AbduSharif

If I remembered correcly, gamma patch consists of two parts - for gl4es and for OpenMW.

If you apply only an OpenMW part, it will try to set a custom attribute (0x4242), but gl4es is not aware of its existance because relevant patch for gl4es is not applied.

If so, it is an Android fork packaging issue, not gl4es one.

akortunov avatar Jan 29 '21 09:01 akortunov

Oh, wow, that gl4es gamma patch! Nice, not standard, but nice :)

I can probably make it official if needed: but I don't like the 0x4242 value used, I would prefer to use one 0x1xxxx value that I used for other gl4es value? But 0x4242 doens't seems to be used, so we can go with it anyway.

ptitSeb avatar Jan 29 '21 09:01 ptitSeb

It is not really a gamma patch, and in theory this patch can be implemented in better ways.

OpenMW uses SDL_SetWindowGammaRamp because without gamma correction Morrowind scenes are too dark. Unfortunately, Android does not support gamma correction, so fork authors introduced a hack to workaround this issue.

The point of workaround is to adjust fragments colors in fragment shaders:

fColor.rgb = pow(fColor.rgb, vec3(1.0 / gamma));

It should be possible to use an alternative implementation - add an option (via an environmental variable?) to the gl4es itself. When enabled, modify fragment shaders to use value above (but be aware of possible division by zero). In this case Android port developers will just need to init an environmetal variable in the launcher, without need to manually patch anything. Also in this case there is no need to add any magic numbers to gl4es.

Unfortunately, I can not tell if gamma correction should be applied to whole scene or only for some its parts, so it will need testing.

akortunov avatar Jan 29 '21 10:01 akortunov

I see, so this was an invalid report, apologizes.

Feel free to close this if you're done.

AbduSharif avatar Jan 29 '21 10:01 AbduSharif

Having gamma correction handled by gl4es only and controlled by env var would be extremely usefull for half life 2 port too. Sorry for OT :)

Sisah2 avatar Feb 06 '21 08:02 Sisah2

I'll add the diff, and route the current "LIBGL_GAMMA" env. var. to it.

ptitSeb avatar Feb 06 '21 08:02 ptitSeb

Then one more problem, its custom shaders, this method work fine for gl4es generated shaders that emulate ffp, but it dont affect custom shaders. Can it be done in shaderconv too? I once tried it, but without succes, so i edited custom shaders manually, which is not possible in case of half life 2.

Sisah2 avatar Feb 06 '21 09:02 Sisah2

this may be really usefull for HL2 (if it handle custom shaders too) but is really not a issue for openmw (its introduced and also fixed by patches of openmw-android)

Sisah2 avatar Mar 08 '21 12:03 Sisah2