Tuesday, March 9, 2021

ThreeJS Gamma Correction since r112


What is the correct way to get gamma corrected output from a Three.js scene with no textures? For example a scene with geometries of various solid coloured Basic, Lambert and Standard materials, lights and shadows and I want to correct for gamma 2.2.


This should be used for new ones

renderer.outputEncoding = THREE.sRGBEncoding;


Normally, JPEG textures are sRGB encoded. So if you want to retain the original color as good as possible, you should define the texture’s encoding if you load it manually like so:

texture.encoding = THREE.sRGBEncoding;


The renderer can then decode the texels into linear space for lighting equations in the shader. Notice, that this only happens for built-in materials. When implementing custom materials, you have to perform the decode by yourself.


Custom shader materials are not automatically part of the renderer’s output encoding process. This only happens if you include the encodings_fragment shader chunk into your fragment shader code.


References:

https://discourse.threejs.org/t/canonical-gamma-correction-since-r112/11756 



No comments:

Post a Comment