MeshPhysicalNodeMaterial.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { addNodeMaterial } from './NodeMaterial.js';
  2. import { transformedClearcoatNormalView } from '../accessors/NormalNode.js';
  3. import { clearcoat, clearcoatRoughness, sheen, sheenRoughness } from '../core/PropertyNode.js';
  4. import { materialClearcoatNormal } from '../accessors/ExtendedMaterialNode.js';
  5. import { materialClearcoat, materialClearcoatRoughness, materialSheen, materialSheenRoughness } from '../accessors/MaterialNode.js';
  6. import { float, vec3 } from '../shadernode/ShaderNode.js';
  7. import MeshStandardNodeMaterial from './MeshStandardNodeMaterial.js';
  8. import { MeshPhysicalMaterial } from 'three';
  9. const defaultValues = new MeshPhysicalMaterial();
  10. class MeshPhysicalNodeMaterial extends MeshStandardNodeMaterial {
  11. constructor( parameters ) {
  12. super();
  13. this.isMeshPhysicalNodeMaterial = true;
  14. this.clearcoatNode = null;
  15. this.clearcoatRoughnessNode = null;
  16. this.clearcoatNormalNode = null;
  17. this.sheenNode = null;
  18. this.sheenRoughnessNode = null;
  19. this.iridescenceNode = null;
  20. this.iridescenceIORNode = null;
  21. this.iridescenceThicknessNode = null;
  22. this.specularIntensityNode = null;
  23. this.specularColorNode = null;
  24. this.transmissionNode = null;
  25. this.thicknessNode = null;
  26. this.attenuationDistanceNode = null;
  27. this.attenuationColorNode = null;
  28. this.setDefaultValues( defaultValues );
  29. this.setValues( parameters );
  30. }
  31. constructVariants( builder ) {
  32. super.constructVariants( builder );
  33. const { stack } = builder;
  34. // CLEARCOAT
  35. const clearcoatNode = this.clearcoatNode ? float( this.clearcoatNode ) : materialClearcoat;
  36. const clearcoatRoughnessNode = this.clearcoatRoughnessNode ? float( this.clearcoatRoughnessNode ) : materialClearcoatRoughness;
  37. stack.assign( clearcoat, clearcoatNode );
  38. stack.assign( clearcoatRoughness, clearcoatRoughnessNode );
  39. // SHEEN
  40. const sheenNode = this.sheenNode ? vec3( this.sheenNode ) : materialSheen;
  41. const sheenRoughnessNode = this.sheenRoughnessNode ? float( this.sheenRoughnessNode ) : materialSheenRoughness;
  42. stack.assign( sheen, sheenNode );
  43. stack.assign( sheenRoughness, sheenRoughnessNode );
  44. }
  45. constructNormal( builder ) {
  46. super.constructNormal( builder );
  47. // CLEARCOAT NORMAL
  48. const clearcoatNormalNode = this.clearcoatNormalNode ? vec3( this.clearcoatNormalNode ) : materialClearcoatNormal;
  49. builder.stack.assign( transformedClearcoatNormalView, clearcoatNormalNode );
  50. }
  51. copy( source ) {
  52. this.clearcoatNode = source.clearcoatNode;
  53. this.clearcoatRoughnessNode = source.clearcoatRoughnessNode;
  54. this.clearcoatNormalNode = source.clearcoatNormalNode;
  55. this.sheenNode = source.sheenNode;
  56. this.sheenRoughnessNode = source.sheenRoughnessNode;
  57. this.iridescenceNode = source.iridescenceNode;
  58. this.iridescenceIORNode = source.iridescenceIORNode;
  59. this.iridescenceThicknessNode = source.iridescenceThicknessNode;
  60. this.specularIntensityNode = source.specularIntensityNode;
  61. this.specularColorNode = source.specularColorNode;
  62. this.transmissionNode = source.transmissionNode;
  63. this.thicknessNode = source.thicknessNode;
  64. this.attenuationDistanceNode = source.attenuationDistanceNode;
  65. this.attenuationColorNode = source.attenuationColorNode;
  66. return super.copy( source );
  67. }
  68. }
  69. export default MeshPhysicalNodeMaterial;
  70. addNodeMaterial( MeshPhysicalNodeMaterial );