PBRFresnel.glsl 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //! Functions to calculate fresnel coefficient and approximate zero fresnel value.
  2. vec3 occPBRFresnel (in vec3 theBaseColor,
  3. in float theMetallic,
  4. in float theIOR)
  5. {
  6. theIOR = (1.0 - theIOR) / (1.0 + theIOR);
  7. theIOR *= theIOR;
  8. vec3 f0 = vec3(theIOR);
  9. f0 = mix (f0, theBaseColor.rgb, theMetallic);
  10. return f0;
  11. }
  12. vec3 occPBRFresnel (in vec3 theBaseColor,
  13. in float theMetallic,
  14. in float theIOR,
  15. in float theCosVH)
  16. {
  17. vec3 f0 = occPBRFresnel (theBaseColor, theMetallic, theIOR);
  18. theCosVH = 1.0 - theCosVH;
  19. theCosVH *= theCosVH;
  20. theCosVH *= theCosVH * theCosVH * theCosVH * theCosVH;
  21. return f0 + (vec3 (1.0) - f0) * theCosVH;
  22. }
  23. vec3 occPBRFresnel (in vec3 theBaseColor,
  24. in float theMetallic,
  25. in float theRoughness,
  26. in float theIOR,
  27. in float theCosV)
  28. {
  29. vec3 f0 = occPBRFresnel (theBaseColor, theMetallic, theIOR);
  30. theCosV = 1.0 - theCosV;
  31. theCosV *= theCosV;
  32. theCosV *= theCosV * theCosV * theCosV * theCosV;
  33. return f0 + (max(vec3(1.0 - theRoughness), f0) - f0) * theCosV;
  34. }