/// <summary> /// Computes the ratio of self-masked area to visible area. Used by <see cref="MaskingShadowing(Vector3)"/>. /// </summary> /// <param name="normal">Normal of the microfacets, in shading space.</param> /// <returns>Ratio of self-masked area to visible area.</returns> public float MaskingRatio(Vector3 normal) { float absTanTheta = MathF.Abs(ShadingSpace.TanTheta(normal)); if (float.IsInfinity(absTanTheta)) { return(0); } float alpha = MathF.Sqrt(ShadingSpace.CosPhiSqr(normal) * AlphaX * AlphaX + ShadingSpace.SinPhiSqr(normal) * AlphaY * AlphaY); float alpha2Tan2Theta = alpha * absTanTheta * (alpha * absTanTheta); return((-1 + MathF.Sqrt(1 + alpha2Tan2Theta)) / 2); }
/// <summary> /// Computes the distribution of microfacets with the given normal. /// </summary> /// <param name="normal">The normal vector of the microfacets, in shading space.</param> /// <returns>The fraction of microfacets that are oriented with the given normal.</returns> public float NormalDistribution(Vector3 normal) { float tan2Theta = ShadingSpace.TanThetaSqr(normal); if (float.IsInfinity(tan2Theta)) { return(0); } float cos4Theta = ShadingSpace.CosThetaSqr(normal) * ShadingSpace.CosThetaSqr(normal); float e = tan2Theta * ( ShadingSpace.CosPhiSqr(normal) / (AlphaX * AlphaX) + ShadingSpace.SinPhiSqr(normal) / (AlphaY * AlphaY) ); return(1 / (MathF.PI * AlphaX * AlphaY * cos4Theta * (1 + e) * (1 + e))); }