MeshPhysicalNodeMaterial.js 4.3 KB

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