BRDF_GGX.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import F_Schlick from './F_Schlick.js';
  2. import V_GGX_SmithCorrelated from './V_GGX_SmithCorrelated.js';
  3. import D_GGX from './D_GGX.js';
  4. import { transformedNormalView } from '../../accessors/NormalNode.js';
  5. import { positionViewDirection } from '../../accessors/PositionNode.js';
  6. import { ShaderNode } from '../../shadernode/ShaderNode.js';
  7. // GGX Distribution, Schlick Fresnel, GGX_SmithCorrelated Visibility
  8. const BRDF_GGX = new ShaderNode( ( inputs ) => {
  9. const { lightDirection, f0, f90, roughness } = inputs;
  10. const alpha = roughness.pow2(); // UE4's roughness
  11. const halfDir = lightDirection.add( positionViewDirection ).normalize();
  12. const dotNL = transformedNormalView.dot( lightDirection ).clamp();
  13. const dotNV = transformedNormalView.dot( positionViewDirection ).clamp();
  14. const dotNH = transformedNormalView.dot( halfDir ).clamp();
  15. const dotVH = positionViewDirection.dot( halfDir ).clamp();
  16. const F = F_Schlick.call( { f0, f90, dotVH } );
  17. const V = V_GGX_SmithCorrelated.call( { alpha, dotNL, dotNV } );
  18. const D = D_GGX.call( { alpha, dotNH } );
  19. return F.mul( V ).mul( D );
  20. } ); // validated
  21. export default BRDF_GGX;