DirectionalLightNode.js 1.1 KB

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