DFGApprox.js 800 B

123456789101112131415161718192021222324252627
  1. import {
  2. ShaderNode, dotNV, vec2, vec4, add, mul, min, exp2
  3. } from '../../shadernode/ShaderNodeElements.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 = add( mul( roughness, c0 ), c1 );
  13. const a004 = add( mul( min( mul( r.x, r.x ), exp2( mul( - 9.28, dotNV ) ) ), r.x ), r.y );
  14. const fab = add( mul( vec2( - 1.04, 1.04 ), a004 ), r.zw );
  15. return fab;
  16. } );
  17. export default DFGApprox;