BRDF_BlinnPhong.js 1005 B

123456789101112131415161718192021222324252627282930
  1. import F_Schlick from './F_Schlick.js';
  2. import { shininess, specularColor } from '../../core/PropertyNode.js';
  3. import { transformedNormalView } from '../../accessors/NormalNode.js';
  4. import { positionViewDirection } from '../../accessors/PositionNode.js';
  5. import { ShaderNode, float } from '../../shadernode/ShaderNode.js';
  6. const G_BlinnPhong_Implicit = () => float( 0.25 );
  7. const D_BlinnPhong = new ShaderNode( ( { dotNH } ) => {
  8. return shininess.mul( 0.5 / Math.PI ).add( 1.0 ).mul( dotNH.pow( shininess ) );
  9. } );
  10. const BRDF_BlinnPhong = new ShaderNode( ( { lightDirection } ) => {
  11. const halfDir = lightDirection.add( positionViewDirection ).normalize();
  12. const dotNH = transformedNormalView.dot( halfDir ).clamp();
  13. const dotVH = positionViewDirection.dot( halfDir ).clamp();
  14. const F = F_Schlick.call( { f0: specularColor, f90: 1.0, dotVH } );
  15. const G = G_BlinnPhong_Implicit();
  16. const D = D_BlinnPhong.call( { dotNH } );
  17. return F.mul( G ).mul( D );
  18. } );
  19. export default BRDF_BlinnPhong;