diff options
| -rw-r--r-- | shaders/cook_torrance.frag | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/shaders/cook_torrance.frag b/shaders/cook_torrance.frag index 1975491..1a4faf8 100644 --- a/shaders/cook_torrance.frag +++ b/shaders/cook_torrance.frag | |||
| @@ -121,7 +121,11 @@ vec3 cook_torrance( | |||
| 121 | vec3 F = fresnel_schlick(F0, HdotV); | 121 | vec3 F = fresnel_schlick(F0, HdotV); |
| 122 | float G = geometry_smith(roughness, NdotL, NdotV); | 122 | float G = geometry_smith(roughness, NdotL, NdotV); |
| 123 | vec3 Kd = mix(vec3(1.0) - F, vec3(0.0), metallic); | 123 | vec3 Kd = mix(vec3(1.0) - F, vec3(0.0), metallic); |
| 124 | vec3 diffuse = Kd*albedo*INV_PI; | 124 | // A non-HDR environment map essentially has the 1/pi baked in as it does not |
| 125 | // use physical units. See: | ||
| 126 | // https://seblagarde.wordpress.com/2012/01/08/pi-or-not-to-pi-in-game-lighting-equation/ | ||
| 127 | // vec3 diffuse = Kd * albedo * INV_PI; | ||
| 128 | vec3 diffuse = Kd * albedo * INV_PI; | ||
| 125 | // Take a max to prevent division by 0 when either dot product is 0. | 129 | // Take a max to prevent division by 0 when either dot product is 0. |
| 126 | vec3 specular = (D*F*G) / max(4.0 * NdotV * NdotL, 0.0001); | 130 | vec3 specular = (D*F*G) / max(4.0 * NdotV * NdotL, 0.0001); |
| 127 | return diffuse + specular; | 131 | return diffuse + specular; |
| @@ -135,7 +139,11 @@ vec3 cook_torrance_IBL( | |||
| 135 | vec3 F0 = mix(vec3(0.04), albedo, metallic); | 139 | vec3 F0 = mix(vec3(0.04), albedo, metallic); |
| 136 | vec3 F = fresnel_schlick_roughness(F0, NdotV, roughness); | 140 | vec3 F = fresnel_schlick_roughness(F0, NdotV, roughness); |
| 137 | vec3 Kd = mix(vec3(1.0) - F, vec3(0.0), metallic); | 141 | vec3 Kd = mix(vec3(1.0) - F, vec3(0.0), metallic); |
| 138 | vec3 diffuse = Kd * albedo * INV_PI * irradiance; | 142 | // A non-HDR environment map essentially has the 1/pi baked in as it does not |
| 143 | // use physical units. See: | ||
| 144 | // https://seblagarde.wordpress.com/2012/01/08/pi-or-not-to-pi-in-game-lighting-equation/ | ||
| 145 | // vec3 diffuse = Kd * albedo * INV_PI * irradiance; | ||
| 146 | vec3 diffuse = Kd * albedo * irradiance; | ||
| 139 | vec3 specular = prefiltered_env * (F * BRDF_env.x + BRDF_env.y); | 147 | vec3 specular = prefiltered_env * (F * BRDF_env.x + BRDF_env.y); |
| 140 | return occlusion * (diffuse + specular); | 148 | return occlusion * (diffuse + specular); |
| 141 | } | 149 | } |
