# Is this a gamma color space problem?

**URL:** <https://forum.babylonjs.com/t/is-this-a-gamma-color-space-problem/57125>\
**Category:** Questions\
**Tags:** material\
**Created:** [March 14, 2025, 10:10am UTC](https://forum.babylonjs.com/t/is-this-a-gamma-color-space-problem/57125 "2025-03-14T10:10:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![superTigery](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/supertigery/32/37903_2.png) [@superTigery](https://forum.babylonjs.com/u/superTigery)\
**Post date:** [March 14, 2025, 10:10am UTC](https://forum.babylonjs.com/t/is-this-a-gamma-color-space-problem/57125/1 "2025-03-14T10:10:22Z")

</div>

I used PBRCustomMaterial and customized surfaceAlbedo in the Fragment\_Custom\_Albedo function, but the sampled color ended up being the equivalent of a lighter map color

```auto
  customMaterial.Fragment_Custom_Albedo(`
        vec3 dayColor = texture2D(dayTex, vUV).rgb;
        vec3 nightColor = texture2D(nightTex, vUV).rgb;
        vec3 mixColor = pow(mix(dayColor,nightColor,dissolve).rgb,vec3(2.2));
        // vec3 mixColor = mix(dayColor,nightColor,dissolve);
        surfaceAlbedo.rgb = mixColor;
    `)

```

chatGPT gave me the answer and let me do this

```auto
 vec3 mixColor = pow(mix(dayColor,nightColor,dissolve).rgb,vec3(2.2));

```

After this,it works very well, the color and texture after sampling are almost the same

**Is this the right solution?**

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [March 14, 2025, 2:24pm UTC](https://forum.babylonjs.com/t/is-this-a-gamma-color-space-problem/57125/2 "2025-03-14T14:24:09Z")

</div>

Yes, `pow(x,2.2)` will convert a gamma space color to linear space, which is the space expected by the PBR code. However, you can avoid doing a costly exponential operation for each pixel by modifying the day/night textures to store linear data instead of gamma space data.

Another possibility is to keep the day/night textures in gamma space but create the texture in Babylon with a sRGB format (the `Texture` constructor has a `useSRGBBuffer` option parameter). In this case, the GPU will take care of converting the gamma space value to linear space when you sample the texture.

---

<div class="post-metadata">

**Author:** ![superTigery](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/supertigery/32/37903_2.png) [@superTigery](https://forum.babylonjs.com/u/superTigery)\
**Post date:** [March 14, 2025, 2:45pm UTC](https://forum.babylonjs.com/t/is-this-a-gamma-color-space-problem/57125/3 "2025-03-14T14:45:28Z")

</div>

thank u very much , I will try latter!
