1
$\begingroup$

I'm kind of stuck on this one. When following a conventional, high-level shading tutorial, you'll come across these images that are like ambient + diffuse + specular = result, but I can tell that it's not straight addition (otherwise the picture would seem overexposed).

enter image description here

What's the "formula" for mixing two rgb colors?

$\endgroup$
5
$\begingroup$

With an old-style Phong shader (as in your example), they really are just added together. Each of those things is a contribution to the overall amount of light, so they're just added together, the same way you add together the contribution from each light source.

Your intuition is right that you often end up with overexposed specular highlights with this style of shading. In a modern, physically-based pipeline, it's common to instead use an energy-conserving shader. The contributions of each layer (specular, clear-coat/lacquer, diffuse, subsurface) are still added together, but the amount of light in each layer reduces the input amount of light for the next layer. That is, if the surface is giving a strong specular reflection, it's reflecting most of the light, so less light is available for the diffuse layer. In the same way, any light that's reflected by the diffuse layer reduces the amount of light available for subsurface scattering.

$\endgroup$
  • 1
    $\begingroup$ You're conflating energy conservation, with light additivity, with the film's sensitivity function. You can have an energy conserving bsdf and still get "overexposed" images. The second paragraph of your answer is simply confusing in the context of the question and the "problem" of overexposure mentioned. $\endgroup$ – lightxbulb May 31 at 17:09
2
$\begingroup$

You are somewhat right: the rightmost image is not the sum of the three images to the left of it. It's easiest to see that the rightmost image doesn't even have the ambient contribution on the left-hand side of the central spheroid.

I've done an experiment with two modes of addition of the three images. In the resulting images below, on the LHS, with the label "Addition", is my result, on the RHS is the rightmost image from the OP.

  1. Simple, naive addition — as if the images were in linear RGB space (and retaining the result in this space). Here's the result:

simple addition comparison

  1. sRGB addition, i.e. the addition where we consider the images being in sRGB space (the default assumption on the web when no color profile is present), and so undo the sRGB gamma before actually adding color values, and apply it back afterwards. This will give the following result:

sRGB addition comparison

So, you can see that both ways of adding colors result in a sharp border from the ambient lighting contribution — the leftmost image in the OP, while the rightmost supposed result doesn't have such a border on some sides.

I'm not really sure how the rightmost "Phong Reflection" image was created. It may have been manipulated, e.g. some gamma adjustment or something like that. But in any case, in both ways of addition above the image didn't get overexposed as you supposed it would.

$\endgroup$
  • $\begingroup$ I thought about it a bit, maybe they multiplied the diffuse, added the rest, averaged it out. $\endgroup$ – AnnoyinC May 31 at 21:08
  • $\begingroup$ @AnnoyinC well, in that case the product would be much darker. $\endgroup$ – Ruslan May 31 at 21:12
  • $\begingroup$ Since the lit areas look identical in your result with addition vs. the reference image, but the shadow areas are darker in the latter, my guess is that they forgot to clamp the diffuse component to nonnegative values before performing the addition. $\endgroup$ – Rahul Jun 1 at 11:16
  • $\begingroup$ @Rahul that might be indeed. But why would they get negative values in the first place? From some dot product? $\endgroup$ – Ruslan Jun 1 at 12:49
  • $\begingroup$ Yes, the diffuse component of illumination is $\max(n\cdot l,0)$ where $n$ is the surface normal and $l$ is the unit vector towards the light source. If you forget to do the $\max$, you get negative illumination on surfaces facing away from the light. $\endgroup$ – Rahul Jun 1 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.