D_GGX.js 619 B

123456789101112131415161718
  1. import { ShaderNode, add, sub, mul, div, pow2 } from '../../shadernode/ShaderNodeBaseElements.js';
  2. // Microfacet Models for Refraction through Rough Surfaces - equation (33)
  3. // http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html
  4. // alpha is "roughness squared" in Disney’s reparameterization
  5. const D_GGX = new ShaderNode( ( inputs ) => {
  6. const { alpha, dotNH } = inputs;
  7. const a2 = pow2( alpha );
  8. const denom = add( mul( pow2( dotNH ), sub( a2, 1.0 ) ), 1.0 ); // avoid alpha = 0 with dotNH = 1
  9. return mul( 1 / Math.PI, div( a2, pow2( denom ) ) );
  10. } ); // validated
  11. export default D_GGX;