# Gamma Correction and Tone Mapping

**URL:** <https://forum.castle-engine.io/t/gamma-correction-and-tone-mapping/171>\
**Category:** News\
**Created:** [June 20, 2020, 12:17pm UTC](https://forum.castle-engine.io/t/gamma-correction-and-tone-mapping/171 "2020-06-20T12:17:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)\
**Post date:** [June 20, 2020, 12:17pm UTC](https://forum.castle-engine.io/t/gamma-correction-and-tone-mapping/171/1 "2020-06-20T12:17:04Z")

</div>

| [![Helmet: Gamma Correct / Gamma Correct + Tone Mapping / No Gamma or Tone Mapping](https://castle-engine.io/wp/wp-content/uploads/2020/06/gamma_gammatone_nogamma-200x86.png)](https://castle-engine.io/wp/wp-content/uploads/2020/06/gamma_gammatone_nogamma.png "Helmet: Gamma Correct / Gamma Correct + Tone Mapping / No Gamma or Tone Mapping") |
| [![Damaged Helmet: Gamma Corrected / Not Corrected](https://castle-engine.io/wp/wp-content/uploads/2020/06/gamma_nogamma-200x103.png)](https://castle-engine.io/wp/wp-content/uploads/2020/06/gamma_nogamma.png "Damaged Helmet: Gamma Corrected / Not Corrected") |
| [![Specular Highlight: Gamma Corrected / Not Corrected](https://castle-engine.io/wp/wp-content/uploads/2020/06/gamma_nogamma_specular-200x86.png)](https://castle-engine.io/wp/wp-content/uploads/2020/06/gamma_nogamma_specular.png "Specular Highlight: Gamma Corrected / Not Corrected") |
| [![Teapot: Gamma Corrected / Not Corrected](https://castle-engine.io/wp/wp-content/uploads/2020/06/gamma_nogamma_teapot-200x86.png)](https://castle-engine.io/wp/wp-content/uploads/2020/06/gamma_nogamma_teapot.png "Teapot: Gamma Corrected / Not Corrected") |

[Gamma Correction and Tone Mapping](https://castle-engine.io/manual_gamma_correction.php) are now implemented in _Castle Game Engine_. They can be trivially controlled by global variables [GammaCorrection](https://castle-engine.io/apidoc-unstable/html/CastleRendererBaseTypes.html#GammaCorrection) (by default it is _on_ for PBR materials) and [ToneMapping](https://castle-engine.io/apidoc-unstable/html/CastleRendererBaseTypes.html#ToneMapping).

_Gamma Correction_ is a way of making lighting calculations more correct (see e.g. [here](https://blog.molecular-matters.com/2011/11/21/gamma-correct-rendering/) and [here](https://www.vfxwizard.com/tutorials/gamma-correction-for-linear-workflow.html) for explanation; [my analysis of various implementation is here](https://github.com/michaliskambi/x3d-tests/wiki/Gamma-correction-in-X3D-and-glTF)).

_Tone Mapping_ is just a fancy name for _nice-looking color processing_, that makes the final look more visually pleasing. It is independent from the gamma correction (technically), although they both “change the scene colors” so are often considered together. We now implement 3 tone mapping operators (based on [glTF sample viewer](https://github.khronos.org/glTF-Sample-Viewer/)): [see TToneMapping](https://castle-engine.io/apidoc-unstable/html/CastleRendererBaseTypes.html#TToneMapping). Note that you can easily do your own color processing (thus providing functionality equivalent to these tone-mapping operators) by using Effect node like in this example: [tone\_mapping.x3dv](https://github.com/castle-engine/demo-models/blob/master/compositing_shaders/tone_mapping.x3dv) from [demo models](https://github.com/castle-engine/demo-models).

I wrote a new [manual chapter about Gamma Correction](https://castle-engine.io/manual_gamma_correction.php) documenting all of this, and [my description of gamma correction in various engines was also extended](https://github.com/michaliskambi/x3d-tests/wiki/Gamma-correction-in-X3D-and-glTF).
