From 0f78bb69aedb4bdb5c92c730eda01302c9c98b48 Mon Sep 17 00:00:00 2001 From: Joey de Vries Date: Sun, 18 Dec 2016 11:28:01 +0100 Subject: [PATCH] Prevent double multiplication of Fresnel. --- src/6.pbr/1.1.lighting/lighting.cpp | 8 ++++---- src/6.pbr/1.1.lighting/pbr.frag | 4 ++-- src/6.pbr/1.2.lighting_textured/pbr.frag | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/6.pbr/1.1.lighting/lighting.cpp b/src/6.pbr/1.1.lighting/lighting.cpp index 7f4db9b..375d264 100644 --- a/src/6.pbr/1.1.lighting/lighting.cpp +++ b/src/6.pbr/1.1.lighting/lighting.cpp @@ -95,10 +95,10 @@ int main() glm::vec3( 10.0f, -10.0f, 10.0f), }; glm::vec3 lightColors[] = { - glm::vec3(5.0f, 5.0f, 5.0f), - glm::vec3(5.0f, 5.0f, 5.0f), - glm::vec3(5.0f, 5.0f, 5.0f), - glm::vec3(5.0f, 5.0f, 5.0f) + glm::vec3(2.0f, 2.0f, 2.0f), + glm::vec3(2.0f, 2.0f, 2.0f), + glm::vec3(2.0f, 2.0f, 2.0f), + glm::vec3(2.0f, 2.0f, 2.0f) }; int nrRows = 7; int nrColumns = 7; diff --git a/src/6.pbr/1.1.lighting/pbr.frag b/src/6.pbr/1.1.lighting/pbr.frag index 3d97c4e..6945762 100644 --- a/src/6.pbr/1.1.lighting/pbr.frag +++ b/src/6.pbr/1.1.lighting/pbr.frag @@ -103,7 +103,7 @@ void main() float NDF = DistributionGGX(N, H, roughness); float G = GeometrySmith(N, V, L, roughness); - vec3 nominator = NDF * G * F; + vec3 nominator = NDF * G * F; float denominator = 4 * max(dot(V, N), 0.0) * max(dot(L, N), 0.0) + 0.001; // 0.001 to prevent divide by zero. vec3 brdf = nominator / denominator; @@ -111,7 +111,7 @@ void main() float NdotL = max(dot(N, L), 0.0); // add to outgoing radiance Lo - Lo += (kD * albedo / PI + kS * brdf) * radiance * NdotL; + Lo += (kD * albedo / PI + brdf) * radiance * NdotL; // note that we already multiplied the BRDF by the Fresnel (kS) so we won't multiply by kS again } // ambient lighting (note that the next IBL tutorial will replace diff --git a/src/6.pbr/1.2.lighting_textured/pbr.frag b/src/6.pbr/1.2.lighting_textured/pbr.frag index 98a0785..ee4b0f7 100644 --- a/src/6.pbr/1.2.lighting_textured/pbr.frag +++ b/src/6.pbr/1.2.lighting_textured/pbr.frag @@ -138,7 +138,7 @@ void main() float NdotL = max(dot(N, L), 0.0); // add to outgoing radiance Lo - Lo += (kD * albedo / PI + kS * brdf) * radiance * NdotL; + Lo += (kD * albedo / PI + brdf) * radiance * NdotL; // note that we already multiplied the BRDF by the Fresnel (kS) so we won't multiply by kS again } // ambient lighting (note that the next IBL tutorial will replace