MeshPhysicalNodeMaterial.js 4.1 KB

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