# How to use sRGB texture encoding with ShaderMaterial / glsl?

**URL:** <https://discourse.threejs.org/t/how-to-use-srgb-texture-encoding-with-shadermaterial-glsl/13793>\
**Category:** Questions\
**Tags:** textures, materials, shaders\
**Created:** [March 24, 2020, 11:26pm UTC](https://discourse.threejs.org/t/how-to-use-srgb-texture-encoding-with-shadermaterial-glsl/13793 "2020-03-24T23:26:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![polarathene](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/polarathene/32/10160_2.png) [@polarathene](https://discourse.threejs.org/u/polarathene)\
**Post date:** [March 24, 2020, 11:26pm UTC](https://discourse.threejs.org/t/how-to-use-srgb-texture-encoding-with-shadermaterial-glsl/13793/1 "2020-03-24T23:26:07Z")

</div>

I am trying to port a shader effect where the texture is expected to be sRGB, it is a threshold effect and I have noticed that the filtered pixels are what I would get if the texture was encoded as Linear(default).

I have tried to update encoding via JS to `THREE.sRGBEncoding`, like the docs describe, but this doesn’t seem to have an effect on `ShaderMaterial`/`glsl`?

---

<div class="post-metadata">

**Author:** ![makc3d](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/makc3d/32/10452_2.png) [@makc3d](https://discourse.threejs.org/u/makc3d)\
**Post date:** [March 24, 2020, 11:53pm UTC](https://discourse.threejs.org/t/how-to-use-srgb-texture-encoding-with-shadermaterial-glsl/13793/2 "2020-03-24T23:53:29Z")

</div>

maybe if you do `mapTexelToLinear (texture2D (imageTexture, coordinates))` you will get the conversion you want?

---

<div class="post-metadata">

**Author:** ![polarathene](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/polarathene/32/10160_2.png) [@polarathene](https://discourse.threejs.org/u/polarathene)\
**Post date:** [March 25, 2020, 12:32am UTC](https://discourse.threejs.org/t/how-to-use-srgb-texture-encoding-with-shadermaterial-glsl/13793/3 "2020-03-25T00:32:21Z")

</div>

> [@makc3d](#):
>
> mapTexelToLinear

That does not appear to do anything. I will try put together a small reproduction of the issue to share and better demonstration the problem.

---

<div class="post-metadata">

**Author:** ![polarathene](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/polarathene/32/10160_2.png) [@polarathene](https://discourse.threejs.org/u/polarathene)\
**Post date:** [March 25, 2020, 7:05am UTC](https://discourse.threejs.org/t/how-to-use-srgb-texture-encoding-with-shadermaterial-glsl/13793/4 "2020-03-25T07:05:57Z")

</div>

Using `LinearTosRGB()` appears to solve the issue for me. Are these listed/documented somewhere, or must source code for ShaderChunks be inspected for them?

I had heard we were meant to `#include` these but that doesn’t seem to work, at least for ShaderMaterial, methods like this and the one you mention are available by default.

---

<div class="post-metadata">

**Author:** ![dubois](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dubois](https://discourse.threejs.org/u/dubois)\
**Post date:** [March 26, 2020, 1:10am UTC](https://discourse.threejs.org/t/how-to-use-srgb-texture-encoding-with-shadermaterial-glsl/13793/5 "2020-03-26T01:10:13Z")

</div>

Unfortunately no, the shaders have a lot of convenience functions that only live in the chunks. Another caveat is that the shader code is not always enough to inspect, as somelogic is created dynamically based on how encoding is set on various textures.

---

<div class="post-metadata">

**Author:** ![polarathene](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/polarathene/32/10160_2.png) [@polarathene](https://discourse.threejs.org/u/polarathene)\
**Post date:** [March 26, 2020, 5:20am UTC](https://discourse.threejs.org/t/how-to-use-srgb-texture-encoding-with-shadermaterial-glsl/13793/6 "2020-03-26T05:20:35Z")

</div>

> [@dubois](#):
>
> as somelogic is created dynamically based on how encoding is set on various textures.

But not with ShaderMaterial? Texture encoding parameter seems to have no effect, instead you need to know about this beforehand and stumble across those undocumented shader chunks.
