MeshPhysicalNodeMaterial.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. get useClearcoat() {
  33. return this.clearcoat > 0 || this.clearcoatNode !== null;
  34. }
  35. get useIridescence() {
  36. return this.iridescence > 0 || this.iridescenceNode !== null;
  37. }
  38. get useSheen() {
  39. return this.sheen > 0 || this.sheenNode !== null;
  40. }
  41. setupLightingModel( /*builder*/ ) {
  42. return new PhysicalLightingModel( this.useClearcoat, this.useSheen, this.useIridescence );
  43. }
  44. setupVariants( builder ) {
  45. super.setupVariants( builder );
  46. // CLEARCOAT
  47. if ( this.useClearcoat ) {
  48. const clearcoatNode = this.clearcoatNode ? float( this.clearcoatNode ) : materialClearcoat;
  49. const clearcoatRoughnessNode = this.clearcoatRoughnessNode ? float( this.clearcoatRoughnessNode ) : materialClearcoatRoughness;
  50. clearcoat.assign( clearcoatNode );
  51. clearcoatRoughness.assign( clearcoatRoughnessNode );
  52. }
  53. // SHEEN
  54. if ( this.useSheen ) {
  55. const sheenNode = this.sheenNode ? vec3( this.sheenNode ) : materialSheen;
  56. const sheenRoughnessNode = this.sheenRoughnessNode ? float( this.sheenRoughnessNode ) : materialSheenRoughness;
  57. sheen.assign( sheenNode );
  58. sheenRoughness.assign( sheenRoughnessNode );
  59. }
  60. // IRIDESCENCE
  61. if ( this.useIridescence ) {
  62. const iridescenceNode = this.iridescenceNode ? float( this.iridescenceNode ) : materialIridescence;
  63. const iridescenceIORNode = this.iridescenceIORNode ? float( this.iridescenceIORNode ) : materialIridescenceIOR;
  64. const iridescenceThicknessNode = this.iridescenceThicknessNode ? float( this.iridescenceThicknessNode ) : materialIridescenceThickness;
  65. iridescence.assign( iridescenceNode );
  66. iridescenceIOR.assign( iridescenceIORNode );
  67. iridescenceThickness.assign( iridescenceThicknessNode );
  68. }
  69. }
  70. setupNormal( builder ) {
  71. super.setupNormal( builder );
  72. // CLEARCOAT NORMAL
  73. const clearcoatNormalNode = this.clearcoatNormalNode ? vec3( this.clearcoatNormalNode ) : materialClearcoatNormal;
  74. transformedClearcoatNormalView.assign( clearcoatNormalNode );
  75. }
  76. copy( source ) {
  77. this.clearcoatNode = source.clearcoatNode;
  78. this.clearcoatRoughnessNode = source.clearcoatRoughnessNode;
  79. this.clearcoatNormalNode = source.clearcoatNormalNode;
  80. this.sheenNode = source.sheenNode;
  81. this.sheenRoughnessNode = source.sheenRoughnessNode;
  82. this.iridescenceNode = source.iridescenceNode;
  83. this.iridescenceIORNode = source.iridescenceIORNode;
  84. this.iridescenceThicknessNode = source.iridescenceThicknessNode;
  85. this.specularIntensityNode = source.specularIntensityNode;
  86. this.specularColorNode = source.specularColorNode;
  87. this.transmissionNode = source.transmissionNode;
  88. this.thicknessNode = source.thicknessNode;
  89. this.attenuationDistanceNode = source.attenuationDistanceNode;
  90. this.attenuationColorNode = source.attenuationColorNode;
  91. return super.copy( source );
  92. }
  93. }
  94. export default MeshPhysicalNodeMaterial;
  95. addNodeMaterial( 'MeshPhysicalNodeMaterial', MeshPhysicalNodeMaterial );