BRDF_GGX.js 1.2 KB

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