DirectionalLightNode.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import AnalyticLightNode from './AnalyticLightNode.js';
  2. import { addLightNode } from './LightsNode.js';
  3. import getDirectionVector from '../functions/light/getDirectionVector.js';
  4. import { uniform } from '../core/UniformNode.js';
  5. import { addNodeClass } from '../core/Node.js';
  6. import { Vector3, DirectionalLight } from 'three';
  7. class DirectionalLightNode extends AnalyticLightNode {
  8. constructor( light = null ) {
  9. super( light );
  10. this.directionNode = uniform( new Vector3() );
  11. }
  12. update( frame ) {
  13. getDirectionVector( this.light, frame.camera, this.directionNode.value );
  14. super.update( frame );
  15. }
  16. construct( builder ) {
  17. const lightDirection = this.directionNode.normalize();
  18. const lightColor = this.colorNode;
  19. const lightingModelFunctionNode = builder.context.lightingModelNode;
  20. const reflectedLight = builder.context.reflectedLight;
  21. if ( lightingModelFunctionNode && lightingModelFunctionNode.direct ) {
  22. lightingModelFunctionNode.direct.call( {
  23. lightDirection,
  24. lightColor,
  25. reflectedLight
  26. }, builder );
  27. }
  28. }
  29. }
  30. export default DirectionalLightNode;
  31. addLightNode( DirectionalLight, DirectionalLightNode );
  32. addNodeClass( DirectionalLightNode );