I feel like my light conservation math isn't correct, but I am not sure which part is wrong.

Is reflected light supposed to influence the diffuse light?

Does metalness only affect the reflected light or does it also affect ambient and diffuse light?

vec4 falbedo; // surface color
vec3 fnormal; // surface normal

vec3 ambientLight;

vec3 directionToCamera; // Camera normal
vec3 directionToLight; // Directional light normal
vec3 lightColor; // Directional light color

float metalness; // 0-1
float shininess; // 1-256
float subsurface; // 0-1

// Diffuse light
float lightNormalDot = dot(fnormal, directionToLight);
float lightIntensity = max(.0, lightNormalDot);

// Blinn–Phong reflection
vec3 halfway = normalize(directionToCamera + directionToLight);
float reflectionFactor = max(.0, dot(halfway, fnormal));

float reflection = pow(reflectionFactor, shininess);

vec3 res = falbedo.rgb * ambientLight;
res += subsurface * lightIntensity * lightColor * falbedo.rgb;
res += (1. - subsurface) * reflection * mix(lightColor, lightColor * falbedo.rgb, metalness);

gl_FragColor = vec4(res, falbedo.a);
  • $\begingroup$ i'm not sure what you mean by "reflected light". however, ambient light is just a simple approximation for global illumination. it should be a simple value added without anny effect of reflection or viewer position taken into account. therefore, metalness does not affect the ambient light (unless your metalness affects your albedo, which i can't see int he code) $\endgroup$
    – Tare
    Commented Apr 21, 2020 at 12:23
  • $\begingroup$ @Tare I should edit the question so it's clear that I'm talking about directional light. The ambient light is complementary $\endgroup$
    – zoran404
    Commented Apr 22, 2020 at 15:56

1 Answer 1


What is wrong ? Almost everything. It is not a PBR material at all. PBR metallic materials do not use ambient term and do use generally microfacet BRDFs and ComplexFresnel.

  • $\begingroup$ I have apparently misunderstood the point of PBR and have since dumped my shader in favor of the one I found at learnopengl.com/PBR/Lighting But I just don't get why do you claim that "PBR metallic materials do not use ambient term"? $\endgroup$
    – zoran404
    Commented Apr 28, 2020 at 11:04
  • $\begingroup$ @zoran404 because first 'ambient' in a PBR is global illumination. Second, in a pure metallic material there isn't any diffuse part so no global illumination nor ambient term. $\endgroup$ Commented Apr 28, 2020 at 20:15
  • $\begingroup$ If ambient light is light coming from all directions, and metals reflect light, then why is it wrong to just multiply the ambient light and albedo? I don't see why this wouldn't work for both metals and non-metals. $\endgroup$
    – zoran404
    Commented Apr 28, 2020 at 21:04
  • $\begingroup$ Ambient term in this old OpenGL shading model is an approximation of diffuse inter-reflection, Metals don't consider that as they reflect all their incoming light via specular reflection. $\endgroup$
    – PaulHK
    Commented Jan 19, 2021 at 5:52
  • $\begingroup$ I highly recommend chapters 8,9,10,11 from Real Time Rendering (RTR) 4. They do a good job explaining the concepts behind PBR. Discuss how various game engines use it. And give a lot of references to papers and books. If you are serious about PBR then this is an excellent primer on the subject. $\endgroup$
    – pmw1234
    Commented Jan 22, 2021 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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