<p>Comment: if you make references to book, then it would be good if you could provide references.</p>

<p>To answer your questions:</p>

<ol>
<li><p>First, it is quite unusual these days to see people representing colors using a computer byte that is integer values within the range [0:255]. Most people these days use floats, and you will understand why in a moment. When you look at a material in general you can see a shiny part and a diffuse part. Shininess and diffuse appearance are computed using two different types of equation. Let's call the functions that compute the diffuse part <code>diffuse()</code> and the function that compute the specular component <code>specular()</code>. So now you can write:</p>

<p>ObjectColor = Ks * specular() + Kd * diffuse();</p></li>
</ol>

<p><code>Ks</code> and <code>Kd</code> control how shiny or/and diffuse your object is. </p>

<p>About conservation of energy. In short an object can not reflect more light that it receives. So that means that technically if the specular() and diffuse() function do the right thing <code>Ks + Kd</code> ought to be <code>1</code>. If that wasn't true you would violate the principle of conservation of energy. In practice, it is generally good to follow this rule though most of the basic shading models are based on simple diffuse and specular models (for example the Phong model) and are not themselves energy conserving, so trying to be purely energy conserving at this level, is like trying to say you can paint a miniature with a paint roller. Forget about it, just try to be more or less in the right range.</p>

<p><code>ks</code> and <code>kd</code> generally stand for the specular and diffuse coefficients.</p>

<ol start="2">
<li><p>if you don't do path tracing (aka don't simulate global illumination) the object won't reflect light from other objects in the scene, just light from direct light sources. So in the old time, in order to compensate for that, they would add an ambient term. In these days in age, this is considered as 'heresy'. Though if you account for the ambient term still then Ka + Kd + Ks should be again equal to 1 (same principle).</p></li>
<li><p>Not sure to understand what you say here but all these components are additive. You compute the diffuse multiplied by Kd and then you multiply the specular multiplied by Ks and then you add the two resulting numbers together. And that's your object color at the intersection point.</p></li>
</ol>

<p>For an introduction to these topics I recommend you read:</p>

<p><a href="https://www.scratchapixel.com/lessons/3d-basic-rendering/introduction-to-ray-tracing" rel="nofollow noreferrer">Introduction Ray-Tracing</a></p>

<p><a href="https://www.scratchapixel.com/lessons/3d-basic-rendering/introduction-to-shading" rel="nofollow noreferrer">Introduction to Shading</a></p>

<p><a href="https://www.scratchapixel.com/lessons/3d-basic-rendering/phong-shader-BRDF" rel="nofollow noreferrer">The Phong Model</a></p>

<p>In order for you to progress, I personally recommend you proceed by step and don't try to understand everything at once. The problem of rendering and shading is very complex. You need to first understand the principle of light-matter interactions, what is diffuse what is specular and how are objects illuminated (direct and indirect lighting). Once you have these notions you can jump onto shading and understand or learn about the concept of shading model, and what the flaws and strengths of existing shading models (many of them exist).</p>

CC BY-SA 3.0
2017-02-12T09:05:45.763Z
Dude i've read all of those. And maybe i forgot to mention but i am working with floats. What do you expect when i say everything is in range [0,1] surely it can't be 0 and 1. 

Again i think you failed to understand my questions 1) and 3). I've read books and i know Ks and Kd are blah blah blah coefficients. But what exactly are those when it comes to putting numbers? Are those the diffuse and specular color or something else? Let me update my question with books references.
gallickgunner
CC BY-SA 3.0
2017-02-12T09:10:37.233Z
@wandering-warrior: your commend is border line polite. I am not a dude to start with. Please stay within the limits of correctness. Second I spent a share amount of time answer your question so I would appreciate some appreciation of that. If you feel I don't answer your problem, maybe you start questioning whether your questions are properly formulated.
user18490
CC BY-SA 3.0
2017-02-12T09:18:03.270Z
Well sorry i can't tell your gender sitting in front of my LED. My native language isn't english so didn't know people get pissed off on the net if called a 'dude'. Yes i feel you don't answer the question because you didn't read it carefully. I clearly wrote "If Ks and Kd are the surface color or the reflectance ratio and if they are the ratio what their value should be?" You failed to answer what their value should be?
gallickgunner
CC BY-SA 3.0
2017-02-12T10:19:32.433Z
Sorry, cant help it but I'm *considering* downvoating based on op's attitude and not on the questions merit. Dude, loose the attitude and have a little courtesy. We're all here to help.@user18490 made a more than decent effort to answer your question.
Erik
CC BY-SA 3.0
2017-02-12T12:08:02.057Z
@wandering-warrior: I answered your question very precisely. But you need to get outside of the context of the code that you are using. I said that Kd and Ks are coefficients (they are not colors) and that should take values between 0 and 1 and that their sum should be ideally equal to 1. I also mentioned that you need to multiply these coefficients by the functions diffuse() and specular() which return the diffuse and specular responses of the surface. These functions are defined by shading model you use. If you are not familiar with these concepts you need to study them first.
user18490
CC BY-SA 3.0
2017-02-12T12:47:49.320Z
*ahem* Ok you answered half.  "For example if i have a color rgb(66, 170, 244) which is somewhat light blue. What should the Ks and Kd be for the above color?" If these aren't the color where can i get their values? Any reference?
gallickgunner
CC BY-SA 3.0
2017-02-12T14:48:42.383Z
@wandering-warrior please be respectful to the people who are giving their time to help you. Whether you intended so or not, the repeated use of the phrase "you failed" comes across as aggressive and ungrateful. As for the confusion over the term "dude", it's worth noting that it is a [**slang term with a long history**](https://en.wikipedia.org/wiki/Dude) and a wide range of meanings, from complimentary to insulting. It's safest to avoid slang terms here as the intended meaning will not always match the understood meaning.
trichoplax is on Codidact now
CC BY-SA 3.0
2017-02-12T15:51:04.800Z
@Erik Thanks for speaking out about this. Hopefully I've made it clear that disrespectful behaviour is not acceptable here. Note that you can flag any question, answer or comment for moderator attention, and we will appreciate the chance to step in and calm things down.
trichoplax is on Codidact now
CC BY-SA 3.0
2017-02-12T08:42:13.213Z
2017-02-12T08:42:13.213Z
user18490
<p>In <a href="https://github.com/mmp/pbrt-v3" rel="nofollow noreferrer">Physically Based Rendering</a> Kd is the diffuse albedo (diffuse color) and Ks the specular albedo (specular color).</p>

CC BY-SA 4.0
2021-02-20T08:22:06.700Z
2021-02-21T12:19:39.613Z
2021-02-21T12:19:39.613Z
wolfand11
<p>I am currently making a Ray-tracer as a personal project. My lighting equation looks like this</p>

<pre><code>Pixel_color[i] = 255 * (Ma*Ig*Ca + Md*I*Cd * diffuse  + Ms*I*Cs * glossy)
// M = material color (ambient, diffuse and specular)
// I = intensity of light (Ig is the global ambient intensity)
// C = color of the light (ambient , diffuse and specular)
</code></pre>

<p>Here <code>diffuse</code> and <code>glossy</code> contains all the necessary dot products and the normalization factors ( PI for diffuse and n+8/8*PI for Blinn Phong). Also everything is in range 0-1. I've read from some books and it says to make sure that <code>"Ks + Kd" &lt;= 1</code> And now I am confused. </p>

<p>1) What exactly is Ks and Kd? Is it just my surface diffuse color and specular color divided by 255 to make it in the range 0-1? Or is it the reflectance ratio that I have to multiply with my color? If it's something else then what should I set them to? For example if I have a color <code>rgb(66, 170, 244)</code> which is somewhat light blue. What should the Ks and Kd be for the above color?</p>

<p>2) These books don't include the ambient component when talking about this conservation so should it be  Ka+Kd+Ks &lt;= 1? Again if that's the case what will Ka be?</p>

<p>3) If I consider Ks = Ms and Kd = Md. It doesn't fit out. for example if I want a surface with the above color <code>rgb(66, 170, 244)</code> to be shiny and the specular highlight should be white. Then my Ms would be (255-66, 255-170, 255-244) which won't be white. Another way I could do is subtract the maximum from every component Ms(255-244, 255-244, 255-244). But this means the specular color would be very low. What if I wanted a very shiny surface?</p>

<p>UPDATE:-</p>

<p>So according to the book Computer Graphics Principles and Practice, Chapter 6 "Fixed Function and Hierarchial Modeling in WPF" </p>

<pre><code>Cd Innate color of “diffuse layer” (Cd,R,Cd,G,Cd,B)
Cs Innate color of “specular layer” (Cs,R,Cs,G,Cs,B)
ka Efficiency of diffuse layer at reflecting ambient light (ka,R, ka,G, ka,B)
kd Efficiency of diffuse layer at reflecting light (kd,R, kd,G, kd,B)
ks Efficiency of specular layer at reflecting light (ks,R, ks,G, ks,B)
</code></pre>

<p>After that it writes, </p>

<blockquote>
  <p>Note that for solid-color materials, the distinction between the two terms Cd
  and kd is unnecessary, as far as the math is concerned; you can think of them as
  a single term. That is, you can fix kd,R at 1. 0 and use Cd,R to achieve any effect,
  and conversely you could fix Cd,R and specify only kd,R. However, the distinction
  between the two terms is meaningful when the innate color Cd is being provided
  via texture mapping; in that case, there is a need for a kd,R factor affecting the
  reflection of the varying color Cd specified by the texture.</p>
</blockquote>

<p>After that in Chapter 14.9 it removes Kd/Ks and Cd/Cs and replaces both with K_L and K_G</p>

<blockquote>
  <p>These k parameters are no longer potentially ambiguous RGB triples (each 0 . . . 1), but constants representing the net probability over all directions of
  that term contributing to scattering.</p>
</blockquote>

<p>Which led me to think they are just a single constant like "0.5" However in the next example they are telling the same thing to ensure that K_L + K_G &lt;= 1 across all channel which implies that k_L and k_G are infact RGB triples.</p>

CC BY-SA 3.0
2017-02-12T14:18:49.130Z
CGPP is dated regarding PBR and statements like Kd+Ks<=1 isn't correct, assuming they stand for diffuse & specular albedo. It's rather that integral of BRDF over hemisphere <= 1 for energy conservation
JarkkoL
CC BY-SA 3.0
2017-02-12T15:18:05.287Z
@JarkkoL - does that mean when i normalize blinn phong, there is no need for Kd+Ks <= 1?
gallickgunner
<raytracing><lighting><shading>
Energy Conservation in Lighting Equation
gallickgunner
# Energy Conservation in Lighting Equation

(Asked by: username_0 on 2017-02-11)

I am currently making a Ray-tracer as a personal project. My lighting equation looks like this

```
Pixel_color[i] = 255 * (Ma*Ig*Ca + Md*I*Cd * diffuse  + Ms*I*Cs * glossy)
// M = material color (ambient, diffuse and specular)
// I = intensity of light (Ig is the global ambient intensity)
// C = color of the light (ambient , diffuse and specular)

```

Here `diffuse` and `glossy` contains all the necessary dot products and the normalization factors ( PI for diffuse and n+8/8\*PI for Blinn Phong). Also everything is in range 0-1. I've read from some books and it says to make sure that `"Ks + Kd" <= 1` And now I am confused.

1) What exactly is Ks and Kd? Is it just my surface diffuse color and specular color divided by 255 to make it in the range 0-1? Or is it the reflectance ratio that I have to multiply with my color? If it's something else then what should I set them to? For example if I have a color `rgb(66, 170, 244)` which is somewhat light blue. What should the Ks and Kd be for the above color?

2) These books don't include the ambient component when talking about this conservation so should it be Ka+Kd+Ks <= 1? Again if that's the case what will Ka be?

3) If I consider Ks = Ms and Kd = Md. It doesn't fit out. for example if I want a surface with the above color `rgb(66, 170, 244)` to be shiny and the specular highlight should be white. Then my Ms would be (255-66, 255-170, 255-244) which won't be white. Another way I could do is subtract the maximum from every component Ms(255-244, 255-244, 255-244). But this means the specular color would be very low. What if I wanted a very shiny surface?

UPDATE:-

So according to the book Computer Graphics Principles and Practice, Chapter 6 "Fixed Function and Hierarchial Modeling in WPF"

```
Cd Innate color of “diffuse layer” (Cd,R,Cd,G,Cd,B)
Cs Innate color of “specular layer” (Cs,R,Cs,G,Cs,B)
ka Efficiency of diffuse layer at reflecting ambient light (ka,R, ka,G, ka,B)
kd Efficiency of diffuse layer at reflecting light (kd,R, kd,G, kd,B)
ks Efficiency of specular layer at reflecting light (ks,R, ks,G, ks,B)

```

After that it writes,

> Note that for solid-color materials, the distinction between the two terms Cd
> and kd is unnecessary, as far as the math is concerned; you can think of them as
> a single term. That is, you can fix kd,R at 1. 0 and use Cd,R to achieve any effect,
> and conversely you could fix Cd,R and specify only kd,R. However, the distinction
> between the two terms is meaningful when the innate color Cd is being provided
> via texture mapping; in that case, there is a need for a kd,R factor affecting the
> reflection of the varying color Cd specified by the texture.

After that in Chapter 14.9 it removes Kd/Ks and Cd/Cs and replaces both with K\_L and K\_G

> These k parameters are no longer potentially ambiguous RGB triples (each 0 . . . 1), but constants representing the net probability over all directions of
> that term contributing to scattering.

Which led me to think they are just a single constant like "0.5" However in the next example they are telling the same thing to ensure that K\_L + K\_G <= 1 across all channel which implies that k\_L and k\_G are infact RGB triples.

**Tags:** raytracing, lighting, shading

> **Comments:**
> **username_1**: CGPP is dated regarding PBR and statements like Kd+Ks<=1 isn't correct, assuming they stand for diffuse & specular albedo. It's rather that integral of BRDF over hemisphere <= 1 for energy conservation  
> **username_0**: @username_1 - does that mean when i normalize blinn phong, there is no need for Kd+Ks <= 1?  

---

## 2 answers

### Answer by username_2 on 2017-02-12. Score: 3

Comment: if you make references to book, then it would be good if you could provide references.

To answer your questions:

1. First, it is quite unusual these days to see people representing colors using a computer byte that is integer values within the range [0:255]. Most people these days use floats, and you will understand why in a moment. When you look at a material in general you can see a shiny part and a diffuse part. Shininess and diffuse appearance are computed using two different types of equation. Let's call the functions that compute the diffuse part `diffuse()` and the function that compute the specular component `specular()`. So now you can write:

   ObjectColor = Ks \* specular() + Kd \* diffuse();

`Ks` and `Kd` control how shiny or/and diffuse your object is.

About conservation of energy. In short an object can not reflect more light that it receives. So that means that technically if the specular() and diffuse() function do the right thing `Ks + Kd` ought to be `1`. If that wasn't true you would violate the principle of conservation of energy. In practice, it is generally good to follow this rule though most of the basic shading models are based on simple diffuse and specular models (for example the Phong model) and are not themselves energy conserving, so trying to be purely energy conserving at this level, is like trying to say you can paint a miniature with a paint roller. Forget about it, just try to be more or less in the right range.

`ks` and `kd` generally stand for the specular and diffuse coefficients.

2. if you don't do path tracing (aka don't simulate global illumination) the object won't reflect light from other objects in the scene, just light from direct light sources. So in the old time, in order to compensate for that, they would add an ambient term. In these days in age, this is considered as 'heresy'. Though if you account for the ambient term still then Ka + Kd + Ks should be again equal to 1 (same principle).
3. Not sure to understand what you say here but all these components are additive. You compute the diffuse multiplied by Kd and then you multiply the specular multiplied by Ks and then you add the two resulting numbers together. And that's your object color at the intersection point.

For an introduction to these topics I recommend you read:

[Introduction Ray-Tracing](https://www.scratchapixel.com/lessons/3d-basic-rendering/introduction-to-ray-tracing)

[Introduction to Shading](https://www.scratchapixel.com/lessons/3d-basic-rendering/introduction-to-shading)

[The Phong Model](https://www.scratchapixel.com/lessons/3d-basic-rendering/phong-shader-BRDF)

In order for you to progress, I personally recommend you proceed by step and don't try to understand everything at once. The problem of rendering and shading is very complex. You need to first understand the principle of light-matter interactions, what is diffuse what is specular and how are objects illuminated (direct and indirect lighting). Once you have these notions you can jump onto shading and understand or learn about the concept of shading model, and what the flaws and strengths of existing shading models (many of them exist).

> **Comments:**
> **username_0**: Dude i've read all of those. And maybe i forgot to mention but i am working with floats. What do you expect when i say everything is in range [0,1] surely it can't be 0 and 1.   Again i think you failed to understand my questions 1) and 3). I've read books and i know Ks and Kd are blah blah blah coefficients. But what exactly are those when it comes to putting numbers? Are those the diffuse and specular color or something else? Let me update my question with books references.  
> **username_2**: @wandering-warrior: your commend is border line polite. I am not a dude to start with. Please stay within the limits of correctness. Second I spent a share amount of time answer your question so I would appreciate some appreciation of that. If you feel I don't answer your problem, maybe you start questioning whether your questions are properly formulated.  
> **username_0**: Well sorry i can't tell your gender sitting in front of my LED. My native language isn't english so didn't know people get pissed off on the net if called a 'dude'. Yes i feel you don't answer the question because you didn't read it carefully. I clearly wrote "If Ks and Kd are the surface color or the reflectance ratio and if they are the ratio what their value should be?" You failed to answer what their value should be?  
> **username_3**: Sorry, cant help it but I'm *considering* downvoating based on op's attitude and not on the questions merit. Dude, loose the attitude and have a little courtesy. We're all here to help.@username_2 made a more than decent effort to answer your question.  
> **username_2**: @wandering-warrior: I answered your question very precisely. But you need to get outside of the context of the code that you are using. I said that Kd and Ks are coefficients (they are not colors) and that should take values between 0 and 1 and that their sum should be ideally equal to 1. I also mentioned that you need to multiply these coefficients by the functions diffuse() and specular() which return the diffuse and specular responses of the surface. These functions are defined by shading model you use. If you are not familiar with these concepts you need to study them first.  
> **username_0**: *ahem* Ok you answered half.  "For example if i have a color rgb(66, 170, 244) which is somewhat light blue. What should the Ks and Kd be for the above color?" If these aren't the color where can i get their values? Any reference?  
> **username_4**: @wandering-warrior please be respectful to the people who are giving their time to help you. Whether you intended so or not, the repeated use of the phrase "you failed" comes across as aggressive and ungrateful. As for the confusion over the term "dude", it's worth noting that it is a [**slang term with a long history**](https://en.wikipedia.org/wiki/Dude) and a wide range of meanings, from complimentary to insulting. It's safest to avoid slang terms here as the intended meaning will not always match the understood meaning.  
> **username_4**: @username_3 Thanks for speaking out about this. Hopefully I've made it clear that disrespectful behaviour is not acceptable here. Note that you can flag any question, answer or comment for moderator attention, and we will appreciate the chance to step in and calm things down.  

---

### Answer by username_5 on 2021-02-20. Score: 0

In [Physically Based Rendering](https://github.com/mmp/pbrt-v3) Kd is the diffuse albedo (diffuse color) and Ks the specular albedo (specular color).


---

