DFGApprox.js 973 B

1234567891011121314151617181920212223242526272829
  1. import { transformedNormalView } from '../../accessors/NormalNode.js';
  2. import { positionViewDirection } from '../../accessors/PositionNode.js';
  3. import { ShaderNode, vec2, vec4 } from '../../shadernode/ShaderNode.js';
  4. // Analytical approximation of the DFG LUT, one half of the
  5. // split-sum approximation used in indirect specular lighting.
  6. // via 'environmentBRDF' from "Physically Based Shading on Mobile"
  7. // https://www.unrealengine.com/blog/physically-based-shading-on-mobile
  8. const DFGApprox = new ShaderNode( ( inputs ) => {
  9. const { roughness } = inputs;
  10. const c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );
  11. const c1 = vec4( 1, 0.0425, 1.04, - 0.04 );
  12. const r = roughness.mul( c0 ).add( c1 );
  13. const dotNV = transformedNormalView.dot( positionViewDirection ).clamp();
  14. const a004 = r.x.mul( r.x ).min( dotNV.mul( - 9.28 ).exp2() ).mul( r.x ).add( r.y );
  15. const fab = vec2( - 1.04, 1.04 ).mul( a004 ).add( r.zw );
  16. return fab;
  17. } );
  18. export default DFGApprox;