Skip to content

Instantly share code, notes, and snippets.

@8bitniksis
Last active March 27, 2024 21:07
Show Gist options
  • Save 8bitniksis/75ff3c0bbee1f790492df3d230b29251 to your computer and use it in GitHub Desktop.
Save 8bitniksis/75ff3c0bbee1f790492df3d230b29251 to your computer and use it in GitHub Desktop.
Function for calculate fresnel terms modified original lazanyi apprx
float Pow5(float x) { return x*x*x*x*x; }
float Pow6(float x) { return x*x*x*x*x*x; }
//Ref: https://diglib.eg.org/bitstream/handle/10.2312/mam20191305/007-011.pdf Eq(2;4)
float3 fresnel_lazanyi_2019(float cos_theta, float3 f0, float3 f82)
{
float3 a = 17.6513846 * (f0 - f82) + 8.16666667 * (1.0 - f0);
float m = Pow5(1.0 - cos_theta);
return clamp((f0 + (1.0 - f0) * m - a * cos_theta * (m - m * cos_theta)), 0, 1);
}
float fresnel_lazanyi_2019(float cos_theta, float f0, float f82)
{
float a = 17.6513846f * (f0 - f82) + 8.16666667f * (1.0 - f0);
float m = Pow5(1.0 - cos_theta);
return clamp((f0 + (1.0 - f0) * m - a * cos_theta * (m - m * cos_theta)), 0, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment