# How to get linear data from R, G, B & Alpha channels of a file?

**URL:** https://discourse.threejs.org/t/how-to-get-linear-data-from-r-g-b-alpha-channels-of-a-file/27425
**Category:** Questions
**Tags:** materials, textures, shaders
**Created:** [June 22, 2021, 9:46am UTC](https://discourse.threejs.org/t/how-to-get-linear-data-from-r-g-b-alpha-channels-of-a-file/27425 "2021-06-22T09:46:01Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Aleksei](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aleksei/32/7927_2.png) [@Aleksei](https://discourse.threejs.org/u/Aleksei)
#### Post date: [June 22, 2021, 9:46am UTC](https://discourse.threejs.org/t/how-to-get-linear-data-from-r-g-b-alpha-channels-of-a-file/27425/1 "2021-06-22T09:46:01Z")

</div>

Hi!  
As long as we usually create Roughness, Metallic and some other channels as grayscale images with float/Linear profiles then I have the next question: is it possible to read different color channels separately from a file and use them as texture maps?

For exmaple, in Unreal Engine they do it like this: **Red (1)** channel is used for the Ambient Occlusion map, **Green (2)** — for the Roughness and **Blue (3)** — for the Metallic:

 ![rgb](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/7/6/76a28b82bc53ba9da0d9209285aa488e43b4c903.jpeg)

Thank you in advance!

---

<div class="post-metadata">

### Author: ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)
#### Post date: [June 22, 2021, 10:00am UTC](https://discourse.threejs.org/t/how-to-get-linear-data-from-r-g-b-alpha-channels-of-a-file/27425/2 "2021-06-22T10:00:49Z")

</div>

Hi!  
You can see in the docs of `MeshStandardMaterial` that `aoMap` reads red channel, `roughnessMap` reads green channel, `metalnessMap` reads blue channel of a texture. So you can write them in one texture.

---

<div class="post-metadata">

### Author: ![Aleksei](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aleksei/32/7927_2.png) [@Aleksei](https://discourse.threejs.org/u/Aleksei)
#### Post date: [June 22, 2021, 10:09am UTC](https://discourse.threejs.org/t/how-to-get-linear-data-from-r-g-b-alpha-channels-of-a-file/27425/3 "2021-06-22T10:09:42Z")

</div>

Does this mean that I don’t have to do anything special for this to work and this is done by default?

---

<div class="post-metadata">

### Author: ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)
#### Post date: [June 22, 2021, 10:16am UTC](https://discourse.threejs.org/t/how-to-get-linear-data-from-r-g-b-alpha-channels-of-a-file/27425/4 "2021-06-22T10:16:31Z")

</div>

Reading the docs on `MeshStandardMaterial`, pay attention to this sentence in the `aoMap` section`: _The aoMap requires a second set of UVs._

---

<div class="post-metadata">

### Author: ![Aleksei](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aleksei/32/7927_2.png) [@Aleksei](https://discourse.threejs.org/u/Aleksei)
#### Post date: [June 22, 2021, 10:40am UTC](https://discourse.threejs.org/t/how-to-get-linear-data-from-r-g-b-alpha-channels-of-a-file/27425/5 "2021-06-22T10:40:57Z")

</div>

And what does it mean in the context of Three.JS and gltf? I know how to make several UVs for one mesh in 3D editor. Is it what should be done?

---

<div class="post-metadata">

### Author: ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)
#### Post date: [June 22, 2021, 10:48am UTC](https://discourse.threejs.org/t/how-to-get-linear-data-from-r-g-b-alpha-channels-of-a-file/27425/6 "2021-06-22T10:48:01Z")

</div>

Maybe this topic will be helpful: [Help with aoMap of GLTF/GLB model - #3 by donmccurdy](https://discourse.threejs.org/t/help-with-aomap-of-gltf-glb-model/14265/3)

PS Feel free to use “Search” on the forum 🙂

---

<div class="post-metadata">

### Author: ![Aleksei](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aleksei/32/7927_2.png) [@Aleksei](https://discourse.threejs.org/u/Aleksei)
#### Post date: [June 22, 2021, 11:05am UTC](https://discourse.threejs.org/t/how-to-get-linear-data-from-r-g-b-alpha-channels-of-a-file/27425/7 "2021-06-22T11:05:54Z")

</div>

Thanks, @prisoner849 this helped with understanding.  
Unfortunatelly, all this is not so obvious when I read those short descriptions in the docs. Even for me who is familiar both with 3D graphics and JS.

---

<div class="post-metadata">

### Author: ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)
#### Post date: [June 22, 2021, 7:03pm UTC](https://discourse.threejs.org/t/how-to-get-linear-data-from-r-g-b-alpha-channels-of-a-file/27425/8 "2021-06-22T19:03:52Z")

</div>

GLTFLoader will automatically create a second set of UVs (by copying the first) if the model has an AO map and needs it.

---

<div class="post-metadata">

### Author: ![Aleksei](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aleksei/32/7927_2.png) [@Aleksei](https://discourse.threejs.org/u/Aleksei)
#### Post date: [June 23, 2021, 12:11pm UTC](https://discourse.threejs.org/t/how-to-get-linear-data-from-r-g-b-alpha-channels-of-a-file/27425/9 "2021-06-23T12:11:37Z")

</div>

> [@prisoner849](#):
>
> You can see in the docs of `MeshStandardMaterial` that `aoMap` reads red channel, `roughnessMap` reads green channel, `metalnessMap` reads blue channel of a texture. So you can write them in one texture.

Couldn’t find any examples of extracting data from the channels. I thought that if **aoMap** , **roughnessMap** and **metalnessMap** read color channels automatically, then something like this will work:

```javascript
const carMaterial = new THREE.MeshStandardMaterial({
    map: textureLoader.load(`'car_color.png`),
    roughnessMap: textureLoader.load(`car_AO-RG-ML.png`),
    metalnessMap: textureLoader.load(`car_AO-RG-ML.png`),
    aoMap: textureLoader.load(`car_AO-RG-ML.png`),
    envMap: hdriTexture
});
carMaterial.side = THREE.DoubleSide;
carMaterial.metalness = 1;
carMaterial.map.encoding = THREE.sRGBEncoding;

```

…but it doesn’t work — the mesh is black.  
In the example above in the **car\_AO-RG-ML.png** file I have R, G & B channels containing information about AO, roughness & metalness respectively (exported from Substance Painter).

Could you please, show a code example of how you do this properly?

---

<div class="post-metadata">

### Author: ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)
#### Post date: [June 23, 2021, 12:19pm UTC](https://discourse.threejs.org/t/how-to-get-linear-data-from-r-g-b-alpha-channels-of-a-file/27425/10 "2021-06-23T12:19:38Z")

</div>

> [@Aleksei](#):
>
> 'car\_color.png

Is it a typo with `'` in the beginning of the file name?

Could you provide an editable working live code example, that demonstrates the issue?

---

<div class="post-metadata">

### Author: ![Aleksei](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aleksei/32/7927_2.png) [@Aleksei](https://discourse.threejs.org/u/Aleksei)
#### Post date: [June 23, 2021, 1:27pm UTC](https://discourse.threejs.org/t/how-to-get-linear-data-from-r-g-b-alpha-channels-of-a-file/27425/11 "2021-06-23T13:27:07Z")

</div>

Yeah, that was a typo. It isn’t in the actual code.  
The live code example will take some time — will post in a while.

---

<div class="post-metadata">

### Author: ![Aleksei](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aleksei/32/7927_2.png) [@Aleksei](https://discourse.threejs.org/u/Aleksei)
#### Post date: [June 24, 2021, 11:50am UTC](https://discourse.threejs.org/t/how-to-get-linear-data-from-r-g-b-alpha-channels-of-a-file/27425/12 "2021-06-24T11:50:07Z")

</div>

Here is the repository: [nordskill/cartest (github.com)](https://github.com/nordskill/cartest)

While working on it I noticed that the textures render as expected if set without the AO map. And with AO the model is black:

```javascript
matCar = new THREE.MeshStandardMaterial({
    map: textureLoader.load(color),
    envMap: obj.hdri,
    roughnessMap: textureLoader.load(roughness),
    aoMap: textureLoader.load(ao), // this line creates an issue
    metalnessMap: textureLoader.load(metalness)
});

```

P.S. In the repository the textures are loaded in `loadCar()` function.

---

<div class="post-metadata">

### Author: ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)
#### Post date: [June 25, 2021, 6:49pm UTC](https://discourse.threejs.org/t/how-to-get-linear-data-from-r-g-b-alpha-channels-of-a-file/27425/13 "2021-06-25T18:49:53Z")

</div>

You can load that texture once and use it in three parameters of material.  
Also, I used two directional lights in the scene. [https://jsfiddle.net/prisoner849/81Lr0jyx/](https://jsfiddle.net/prisoner849/81Lr0jyx/)
