Skip to content

Commit

Permalink
[Shaders/Cook-Torrance] Made use of Brian Karis' Fresnel optimization
Browse files Browse the repository at this point in the history
- In regards to the removed artifacts, it has been deemed better than the current calculation
  - This may still need further investigation as to why the artifacts appeared

- Related to issue #16
  • Loading branch information
Razakhel committed Sep 29, 2020
1 parent bd0cd14 commit 5188f04
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 2 additions & 4 deletions shaders/cook-torrance.frag
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ float computeNormalDistrib(vec3 normal, vec3 halfVec, float roughness) {

// Fresnel: Shlick
vec3 computeFresnel(float cosTheta, vec3 baseReflectivity) {
// Seemingly optimized version:
// pow(2.0, (-5.55473 * cosTheta - 6.98316) * cosTheta)
// From: http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
return baseReflectivity + (1.0 - baseReflectivity) * pow(1.0 - cosTheta, 5.0);
// Optimized exponent version, from: http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
return baseReflectivity + (1.0 - baseReflectivity) * pow(2.0, (-5.55473 * cosTheta - 6.98316) * cosTheta);
}

// Shlick-Beckmann for Geometry part
Expand Down
6 changes: 2 additions & 4 deletions shaders/opengles3/cook-torrance.frag
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ float computeNormalDistrib(vec3 normal, vec3 halfVec, float roughness) {

// Fresnel: Shlick
vec3 computeFresnel(float cosTheta, vec3 baseReflectivity) {
// Seemingly optimized version:
// pow(2.0, (-5.55473 * cosTheta - 6.98316) * cosTheta)
// From: http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
return baseReflectivity + (1.0 - baseReflectivity) * pow(1.0 - cosTheta, 5.0);
// Optimized exponent version, from: http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
return baseReflectivity + (1.0 - baseReflectivity) * pow(2.0, (-5.55473 * cosTheta - 6.98316) * cosTheta);
}

// Shlick-Beckmann for Geometry part
Expand Down

0 comments on commit 5188f04

Please sign in to comment.