AmbientLightDataNode.js 1003 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { Color, Node } from 'three/webgpu';
  2. import { NodeUpdateType, renderGroup, uniform } from 'three/tsl';
  3. /**
  4. * Batched data node for ambient lights in dynamic lighting mode.
  5. *
  6. * @augments Node
  7. */
  8. class AmbientLightDataNode extends Node {
  9. static get type() {
  10. return 'AmbientLightDataNode';
  11. }
  12. constructor() {
  13. super();
  14. this._color = new Color();
  15. this._lights = [];
  16. this.colorNode = uniform( this._color ).setGroup( renderGroup );
  17. this.updateType = NodeUpdateType.RENDER;
  18. }
  19. setLights( lights ) {
  20. this._lights = lights;
  21. return this;
  22. }
  23. update() {
  24. this._color.setScalar( 0 );
  25. for ( let i = 0; i < this._lights.length; i ++ ) {
  26. const light = this._lights[ i ];
  27. this._color.r += light.color.r * light.intensity;
  28. this._color.g += light.color.g * light.intensity;
  29. this._color.b += light.color.b * light.intensity;
  30. }
  31. }
  32. setup( builder ) {
  33. builder.context.irradiance.addAssign( this.colorNode );
  34. }
  35. }
  36. export default AmbientLightDataNode;
粤ICP备19079148号