# Applying Phong illumination to a colored surface

The formula for Phong illumination as given on Wikipedia (see there for the variable definitions) is:

$$I_\text{p} = k_\text{a} i_\text{a} + \sum_{m\;\in\;\text{lights}} (k_\text{d} (\hat{L}_m \cdot \hat{N}) i_{m,\text{d}} + k_\text{s} (\hat{R}_m \cdot \hat{V})^{\alpha}i_{m,\text{s}})$$

This gives the "illumination" of a point on a surface. However, once I've calculated that, how do I take the color of the surface into account to find the final value of, say, a raytraced pixel? Do I just multiply the illumination by the surface color's RGB components? Are the RGB components expected to have already been taken into account in the $$k_a, k_d, k_s$$ terms? None of the raytracing tutorials I've found online come out and give a straight answer to this question, aside from this, which multiplies the diffuse term but not the specular term by the surface color (and omits the ambient term entirely), something which this page implies should only be done for dielectrics.

• $k_d$ is the diffuse albedo, which the surface "color" represented in RGB. Jul 28, 2022 at 19:03
• @Hubble: Are you saying that $k_d$ equals the color or that it equals the color multiplied by a material-specific constant? Either way, that sounds like an answer, moreso if you link to some comprehensive reference on this. Jul 28, 2022 at 19:26
• The expression you wrote is "valid" only if you consider directional lights, you ignore shadows, and also the ambient term is a hack. If you're doing path tracing then you phong brdf is made up of two parts: the diffuse part is just a standard Lambertian, while the specular part is $C(R\cdot V)^{\alpha}/(N\cdot L)$, where $C$ is a suitable constant. Look up the Global Illumination Compendium from Dutre. Jul 29, 2022 at 7:14
• The answer to this depends on what your definition of a color is. If you think rgb is the epitome of color then sure multiply light color by surface color. But if you think color is a spectrum then you need to multiply by spectrum slices and then repuild it as rgb Jul 30, 2022 at 21:50
• Diffuse reflection is influenced by the color of the material (light is absorbed then reemitted); specular reflection is not.
– user1703
Apr 30 at 13:06

This question is conflating different lighting models, Phong lighting has no concept of dielectrics and the referenced website is clearly just comparing the Phong models to more physically based models. All the websites listed are consistent in their presentation of the Phong model which is fundamentally and intentionally simple as it reflects the capabilities of the hardware it was designed to run on. ( I agree that the flip code site is confusing and the formula's don't even display correctly in my browser)

$$I_p$$ reads as intensity sub point this is what the entire goal of computing the lighting is. Once intensity is computed for the lighting it is multiplied by the point color and its done. Again, this is for the Phong lighting model. $$k_a$$, $$k_d$$ and $$k_s$$ are constants used to compute $$I_p$$ that is why they are on the right hand side of the equation. Once $$I_p$$ is computed $$k_a$$, $$k_d$$ and $$k_s$$ are no longer needed and do not participate in lighting calculations further.

To talk it through... The term $$k_ai_a$$ represents the ambient contribution of the light. Think of a room painted bright red with a white light in it. The "ambient" light in the room is going to pick up a red color as it bounces off all those red walls. $$k_a$$ is most often used to represent that red color while $$i_a$$ represents the intensity of that light. When multiplied they represent the ambient term for the lighting calculation. $$i_a$$ is usually just a floating point value and is very small relative to diffuse and specular. Some models will drop the ambient term all together. (but then they are no longer a true Phong lighting model). In real code this term is almost always a pre-multiplied constant and is not actually computed.

$$k_d(\hat{L}_m⋅N)i_{m,d}$$ here $$k_d$$ is a constant and again is almost always used as the color of the light, in this example it would be white. $$(\hat{L}_m⋅N)$$ is the cosine of the angle between the light the surface normal, and $$I_{m,d}$$ is the intensity of the diffuse light. When multiplied out this term represents the "diffuse" component of the light. In real code the terms $$k_d$$ and $$I_{m,d}$$ are almost always a pre-multiplied constant and are not actually computed.

Finally, $$k_s(\hat{R}_m⋅\hat{V})^αi_{m,s}$$ here again $$k_s$$ is a constant, and again almost always a color representing the light and $$k_s$$ almost always is equal to $$k_d$$. Next $$i_{m,s}$$ is the specular intensity and it is almost always equal to diffuse intensity, and again is pre-multiplied with $$k_s$$, is very frequently the same value used for diffuse and is usually constant for a given light. The value $$(\hat{R}_m⋅\hat{V})^α$$ is the cosine of the angle between view vector and the reflection vector raised to the specular power $$\alpha$$. Once computed this term represents specular intensity. So in this case the specular $$k_s$$ is white and the intensity is equal to $$i_d$$. (so we end up with the same constant used to compute the diffuse term)

Now add them up... A little bit of red light from the ambient plus the diffuse light which is a bright white plus very bright white highlights from the specular. This is $$I_p$$, call it "light_intensity" now figure out the color of the point, and compute the final color...

// lets make the color a constant blue-green...
vec4 point_color = vec4(0.0,0.2,0.8, 1.0);
final_color = light_intensity * point_color;

• So you're saying that $k_d$ and $k_s$ are properties of the light rather than of the material being illuminated? That conflicts with what I've seen in most other sources. Aug 3, 2022 at 13:13
• It doesn't matter where these constants come from. They can be constants in the shader, they can be stored in a material, they can come from a texture, it doesn't matter. Aug 3, 2022 at 16:14
• But are $k_d$ and $k_s$ associated with the light source — and thus have different values for different lights — or are they associated with the materials being illuminated — and thus have different values when considering a different material under the same light? Aug 3, 2022 at 19:16
• Unfortunately the answer to that is all of the above as it depends on the situation. This is one of the several reasons that Phong lighting models tend to use fixed lighting. The desire would be to fix them based on the material, and this can work in simple scenes, but in more complex scene's the colors can interact with lights in unexpected ways. This leads to artists "tweaking" values to get the scene to "look its best". Move a light, change a value, and ugly artifacts emerge. This can lead to scene specific materials where the only value that is different is the constant color. Aug 3, 2022 at 21:52
• $k_d, k_s$ are not related to the light, those are material/brdf parameters. Aug 4, 2022 at 7:15

According to chapter 6 of The Ray Tracer Challenge by Jamis Buck, in order to get the final color, the color of the material is multiplied by the ambient term and the diffuse term but not by the specular term. $$k_a$$, $$k_d$$, and $$k_s$$, meanwhile, are simply material properties in the range $$[0,1]$$.

• The original question should be edited if adding to the questions, this doesn't answer the question at all. Aug 3, 2022 at 9:28
• @pmw1234: This was intended to be an answer to the question, as the referenced work was the first source I found that comprehensively addressed the question of combining Phong illumination with a colored material. You may think the answer is wrong, but that doesn't make it not an answer. Aug 3, 2022 at 13:12
• These models are all approximations. Feel free to take your favorite approximation and run with it. The internet has thousands of versions (for better or worse) of "Phong" lighting. The "correct" solution is the one that fits best with the situation. Aug 3, 2022 at 16:23