stackgl / shader-school

:mortar_board: A workshopper for GLSL shaders and graphics programming
Other
4.28k stars 252 forks source link

Bug in 19-light-3 (phong shader)? #129

Open dhcoder opened 9 years ago

dhcoder commented 9 years ago

TL;DR - Missing max check on lambertian weight?

18-light-2 introduces the following function for lambertian diffuse shading:

float lambertWeight(vec3 n, vec3 d) {
  return max(dot(n, d), 0.0);
}

I carried this forward into 19-light-3, and scratched my head for hours as I got the specular highlights correct but the expected solution's shadowed areas were darker than mine.

Then, on a whim, I removed the max check on the lambertWeight, e.g.

float lambertWeight(vec3 n, vec3 d) {
  return dot(n, d);
}

suddenly my solution passed.

Can you check the official solution and make sure there isn't a dropped max check that's supposed to be there?

dhcoder commented 9 years ago

If you want to compare with my solution, you can see it here (spoilers ahead!): https://github.com/dhcoder/shader-school-answers/tree/master/19-light-3

dhcoder commented 9 years ago

So I woke up this morning and realized that the answers needed to be on my computer somewhere (sort of a "oh, duh!" moment) and found them. I can verify the official solution is missing a max(..., 0.0) check (unless that's for some reason I'm unaware what you're supposed to do when adding phong specular to the equation?)