<p>When applying various types of attenuation you are just multiplying by some number smaller than 1.  This is akin to every atom of your material having some probability of absorbing the light that hits it.</p>

<p>Something to note is that these calculations should be performed ( in the context of <a href="https://en.m.wikipedia.org/wiki/Gamma_correction" rel="nofollow noreferrer">gamma correction</a> and colour spaces ) in a linear space.</p>

<p>If you don't perform the calculations in linear space you might end up with overly bright, overly dark, overly saturated or under saturated colours.</p>

CC BY-SA 3.0
2018-02-13T18:16:20.457Z
2018-02-13T18:16:20.457Z
Sebastián Mestre
<p>I'm trying to implement a simple Phong shader that supports non-physically-based materials and textures. Even though the material has a texture for each light component I still want the respective material coefficient to have some effect. My doubt is how to handle both of them. Should I mix, multiply or sum them?
Right now I've multiplied them:</p>

<pre><code>ambient  = material.ambient_color  * light.ambient  * texture_ambient;
diffuse  = material.diffuse_color  * light.diffuse  * diffuse_strength  * texture_diffuse;
specular = material.specular_color * light.specular * specular_strength * texture_specular;
</code></pre>

<p>It seems kinda dark, is this the correct way to combine material coefficients and textures?</p>

CC BY-SA 3.0
2018-01-28T20:42:45.743Z
that is the correct way. maybe darkness comes from not doing calculations in linear space?
Sebastián Mestre
CC BY-SA 3.0
2018-01-28T21:24:31.973Z
Have you tried increasing the light amounts?
user1118321
CC BY-SA 3.0
2018-01-28T23:42:09.827Z
@SebastiánMestre What do you mean by linear space? I'm sorry, I'm new to this.
Daniel Marques
CC BY-SA 3.0
2018-01-28T23:43:13.327Z
@user1118321 No, I've been using only one light, a directional light. In my mind it should be enough and it shouldn't be as dark as it is.
Daniel Marques
CC BY-SA 3.0
2018-01-29T00:18:30.707Z
i mean linear colour space. images are usually gamma compressed and can give wrong results when using them in shading. they should first be gamma corrected. you can search what that means online.
Sebastián Mestre
<opengl><texture><glsl><shading><material>
Combine material coefficients and textures in Phong Shading
Daniel Marques
# Combine material coefficients and textures in Phong Shading

(Asked by: username_0 on 2018-01-28)

I'm trying to implement a simple Phong shader that supports non-physically-based materials and textures. Even though the material has a texture for each light component I still want the respective material coefficient to have some effect. My doubt is how to handle both of them. Should I mix, multiply or sum them?
Right now I've multiplied them:

```
ambient  = material.ambient_color  * light.ambient  * texture_ambient;
diffuse  = material.diffuse_color  * light.diffuse  * diffuse_strength  * texture_diffuse;
specular = material.specular_color * light.specular * specular_strength * texture_specular;

```

It seems kinda dark, is this the correct way to combine material coefficients and textures?

**Tags:** opengl, texture, glsl, shading, material

> **Comments:**
> **username_1**: that is the correct way. maybe darkness comes from not doing calculations in linear space?  
> **username_2**: Have you tried increasing the light amounts?  
> **username_0**: @username_1 What do you mean by linear space? I'm sorry, I'm new to this.  
> **username_0**: @username_2 No, I've been using only one light, a directional light. In my mind it should be enough and it shouldn't be as dark as it is.  
> **username_1**: i mean linear colour space. images are usually gamma compressed and can give wrong results when using them in shading. they should first be gamma corrected. you can search what that means online.  

---

## 1 answers

### Answer by username_1 on 2018-02-13. Score: 1

When applying various types of attenuation you are just multiplying by some number smaller than 1. This is akin to every atom of your material having some probability of absorbing the light that hits it.

Something to note is that these calculations should be performed ( in the context of [gamma correction](https://en.m.wikipedia.org/wiki/Gamma_correction) and colour spaces ) in a linear space.

If you don't perform the calculations in linear space you might end up with overly bright, overly dark, overly saturated or under saturated colours.


---

