LightContextNode.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import ContextNode from '../core/ContextNode.js';
  2. import VarNode from '../core/VarNode.js';
  3. import Vector3Node from '../inputs/Vector3Node.js';
  4. import OperatorNode from '../math/OperatorNode.js';
  5. import { PhysicalLightingModel } from '../functions/BSDFs.js';
  6. class LightContextNode extends ContextNode {
  7. constructor( node ) {
  8. super( node );
  9. }
  10. getNodeType( /*builder*/ ) {
  11. return 'vec3';
  12. }
  13. generate( builder ) {
  14. const material = builder.material;
  15. let lightingModel = null;
  16. if ( material.isMeshStandardMaterial === true ) {
  17. lightingModel = PhysicalLightingModel;
  18. }
  19. const directDiffuse = new VarNode( new Vector3Node(), 'DirectDiffuse', 'vec3' );
  20. const directSpecular = new VarNode( new Vector3Node(), 'DirectSpecular', 'vec3' );
  21. this.context.directDiffuse = directDiffuse;
  22. this.context.directSpecular = directSpecular;
  23. if ( lightingModel !== null ) {
  24. this.context.lightingModel = lightingModel;
  25. }
  26. // add code
  27. const type = this.getNodeType( builder );
  28. super.generate( builder, type );
  29. const totalLight = new OperatorNode( '+', directDiffuse, directSpecular );
  30. return totalLight.build( builder, type );
  31. }
  32. }
  33. export default LightContextNode;