MeshPhysicalNodeMaterial.js 4.5 KB

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