BRDF_GGX.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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 {
  5. ShaderNode, dotNV, add, mul, saturate, dot, pow2, normalize,
  6. transformedNormalView, positionViewDirection
  7. } from '../../shadernode/ShaderNodeBaseElements.js';
  8. // GGX Distribution, Schlick Fresnel, GGX_SmithCorrelated Visibility
  9. const BRDF_GGX = new ShaderNode( ( inputs ) => {
  10. const { lightDirection, f0, f90, roughness } = inputs;
  11. const alpha = pow2( roughness ); // UE4's roughness
  12. const halfDir = normalize( add( lightDirection, positionViewDirection ) );
  13. const dotNL = saturate( dot( transformedNormalView, lightDirection ) );
  14. //const dotNV = saturate( dot( transformedNormalView, positionViewDirection ) );
  15. const dotNH = saturate( dot( transformedNormalView, halfDir ) );
  16. const dotVH = saturate( dot( positionViewDirection, halfDir ) );
  17. const F = F_Schlick.call( { f0, f90, dotVH } );
  18. const V = V_GGX_SmithCorrelated.call( { alpha, dotNL, dotNV } );
  19. const D = D_GGX.call( { alpha, dotNH } );
  20. return mul( F, mul( V, D ) );
  21. } ); // validated
  22. export default BRDF_GGX;