<p>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.</p>

CC BY-SA 4.0
2020-04-28T11:04:17.840Z
I have apparently misunderstood the point of PBR and have since dumped my shader in favor of the one I found at https://learnopengl.com/PBR/Lighting But I just don't get why do you claim that "PBR metallic materials do not use ambient term"?
zoran404
CC BY-SA 4.0
2020-04-28T20:15:05.513Z
@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.
Max Tarpini
CC BY-SA 4.0
2020-04-28T21:04:25.407Z
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.
zoran404
CC BY-SA 4.0
2021-01-19T05:52:58.717Z
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.
PaulHK
CC BY-SA 4.0
2021-01-22T15:36:03.530Z
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.
pmw1234
CC BY-SA 4.0
2020-04-23T20:54:31.333Z
2020-04-23T20:54:31.333Z
Max Tarpini
<p>I feel like my light conservation math isn't correct, but I am not sure which part is wrong.</p>

<p>Is reflected light supposed to influence the diffuse light?</p>

<p>Does metalness only affect the reflected light or does it also affect ambient and diffuse light?</p>

<pre class="lang-c prettyprint-override"><code>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);
</code></pre>

CC BY-SA 4.0
2020-04-21T12:23:34.063Z
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)
Tare
CC BY-SA 4.0
2020-04-22T15:56:32.097Z
@Tare I should edit the question so it's clear that I'm talking about directional light. The ambient light is complementary
zoran404
<glsl><lighting><webgl><pbr>
What is wrong with my metallic PBR shader?
zoran404
# What is wrong with my metallic PBR shader?

(Asked by: username_0 on 2020-04-18)

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?

```c
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);

```

**Tags:** glsl, lighting, webgl, pbr

> **Comments:**
> **username_1**: 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)  
> **username_0**: @username_1 I should edit the question so it's clear that I'm talking about directional light. The ambient light is complementary  

---

## 1 answers

### Answer by username_2 on 2020-04-23. Score: 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.

> **Comments:**
> **username_0**: I have apparently misunderstood the point of PBR and have since dumped my shader in favor of the one I found at https://learnopengl.com/PBR/Lighting But I just don't get why do you claim that "PBR metallic materials do not use ambient term"?  
> **username_2**: @username_0 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.  
> **username_0**: 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.  
> **username_3**: 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.  
> **username_4**: 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.  

---

