X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=blobdiff_plain;f=src%2FShaders%2FPBRFresnel.glsl;h=53c3d705c861ddd060ebb45ccb4d63b6528ba91b;hb=67312b7991c945e66d4fa1d3a6f8e02dbabc9b5a;hpb=f4a7308f61af6cde23a6380eb8127695b75f4690 diff --git a/src/Shaders/PBRFresnel.glsl b/src/Shaders/PBRFresnel.glsl new file mode 100644 index 0000000000..53c3d705c8 --- /dev/null +++ b/src/Shaders/PBRFresnel.glsl @@ -0,0 +1,36 @@ +//! Functions to calculate fresnel coefficient and approximate zero fresnel value. +vec3 occPBRFresnel (in vec3 theBaseColor, + in float theMetallic, + in float theIOR) +{ + theIOR = (1.0 - theIOR) / (1.0 + theIOR); + theIOR *= theIOR; + vec3 f0 = vec3(theIOR); + f0 = mix (f0, theBaseColor.rgb, theMetallic); + return f0; +} + +vec3 occPBRFresnel (in vec3 theBaseColor, + in float theMetallic, + in float theIOR, + in float theCosVH) +{ + vec3 f0 = occPBRFresnel (theBaseColor, theMetallic, theIOR); + theCosVH = 1.0 - theCosVH; + theCosVH *= theCosVH; + theCosVH *= theCosVH * theCosVH * theCosVH * theCosVH; + return f0 + (vec3 (1.0) - f0) * theCosVH; +} + +vec3 occPBRFresnel (in vec3 theBaseColor, + in float theMetallic, + in float theRoughness, + in float theIOR, + in float theCosV) +{ + vec3 f0 = occPBRFresnel (theBaseColor, theMetallic, theIOR); + theCosV = 1.0 - theCosV; + theCosV *= theCosV; + theCosV *= theCosV * theCosV * theCosV * theCosV; + return f0 + (max(vec3(1.0 - theRoughness), f0) - f0) * theCosV; +}