DFGApprox.js 861 B

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