0
$\begingroup$

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);
$\endgroup$
  • $\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 Apr 21 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 Apr 22 at 15:56
0
$\begingroup$

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.

| improve this answer | |
$\endgroup$
  • $\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 Apr 28 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$ – Max Tarpini Apr 28 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 Apr 28 at 21:04

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.