PhysicalMaterialFunctions.js 789 B

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