D_GGX.js 660 B

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