MeshPhongNodeMaterial.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import NodeMaterial from './NodeMaterial.js';
  2. import {
  3. float, vec3,
  4. materialShininess, materialSpecularColor,
  5. shininess, specularColor
  6. } from '../shadernode/ShaderNodeElements.js';
  7. import phongLightingModel from '../functions/PhongLightingModel.js';
  8. import { MeshPhongMaterial } from 'three';
  9. const defaultValues = new MeshPhongMaterial();
  10. class MeshPhongNodeMaterial extends NodeMaterial {
  11. constructor( parameters ) {
  12. super();
  13. this.isMeshPhongNodeMaterial = true;
  14. this.lights = true;
  15. this.colorNode = null;
  16. this.opacityNode = null;
  17. this.shininessNode = null;
  18. this.specularNode = null;
  19. this.alphaTestNode = null;
  20. this.lightNode = null;
  21. this.positionNode = null;
  22. this.setDefaultValues( defaultValues );
  23. this.setValues( parameters );
  24. }
  25. constructLightingModel( /*builder*/ ) {
  26. return phongLightingModel;
  27. }
  28. constructVariants( builder, stack ) {
  29. // SHININESS
  30. const shininessNode = float( this.shininessNode || materialShininess ).max( 1e-4 ); // to prevent pow( 0.0, 0.0 )
  31. stack.assign( shininess, shininessNode );
  32. // SPECULAR COLOR
  33. const specularNode = vec3( this.specularNode || materialSpecularColor );
  34. stack.assign( specularColor, specularNode );
  35. }
  36. copy( source ) {
  37. this.colorNode = source.colorNode;
  38. this.opacityNode = source.opacityNode;
  39. this.alphaTestNode = source.alphaTestNode;
  40. this.shininessNode = source.shininessNode;
  41. this.specularNode = source.specularNode;
  42. this.lightNode = source.lightNode;
  43. this.positionNode = source.positionNode;
  44. return super.copy( source );
  45. }
  46. }
  47. export default MeshPhongNodeMaterial;