LightContextNode.js 1.2 KB

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