PhysicalMaterialFunctions.js 730 B

123456789101112131415161718192021222324252627
  1. import { ShaderNode,
  2. add, max, min, abs, dFdx, dFdy,
  3. normalGeometry
  4. } from '../ShaderNode.js';
  5. export const getGeometryRoughness = new ShaderNode( () => {
  6. const dxy = max( abs( dFdx( normalGeometry ) ), abs( dFdy( normalGeometry ) ) );
  7. const geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
  8. return geometryRoughness;
  9. } );
  10. export const getRoughness = new ShaderNode( ( inputs ) => {
  11. const { roughness } = inputs;
  12. const geometryRoughness = getGeometryRoughness();
  13. let roughnessFactor = max( roughness, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.
  14. roughnessFactor = add( roughnessFactor, geometryRoughness );
  15. roughnessFactor = min( roughnessFactor, 1.0 );
  16. return roughnessFactor;
  17. } );