D_GGX.js 668 B

1234567891011121314151617181920212223
  1. import { tslFn } from '../../shadernode/ShaderNode.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 = tslFn( ( { alpha, dotNH } ) => {
  6. const a2 = alpha.pow2();
  7. const denom = dotNH.pow2().mul( a2.oneMinus() ).oneMinus(); // avoid alpha = 0 with dotNH = 1
  8. return a2.div( denom.pow2() ).mul( 1 / Math.PI );
  9. } ).setLayout( {
  10. name: 'D_GGX',
  11. type: 'float',
  12. inputs: [
  13. { name: 'alpha', type: 'float' },
  14. { name: 'dotNH', type: 'float' }
  15. ]
  16. } ); // validated
  17. export default D_GGX;