IESSpotLightNode.js 886 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import SpotLightNode from './SpotLightNode.js';
  2. import { addLightNode } from './LightsNode.js';
  3. import { texture } from '../accessors/TextureNode.js';
  4. import { vec2 } from '../shadernode/ShaderNode.js';
  5. import { addNodeClass } from '../core/Node.js';
  6. import IESSpotLight from '../../lights/IESSpotLight.js';
  7. class IESSpotLightNode extends SpotLightNode {
  8. getSpotAttenuation( angleCosine ) {
  9. const iesMap = this.light.iesMap;
  10. let spotAttenuation = null;
  11. if ( iesMap && iesMap.isTexture === true ) {
  12. const angle = angleCosine.acos().mul( 1.0 / Math.PI );
  13. spotAttenuation = texture( iesMap, vec2( angle, 0 ), 0 ).r;
  14. } else {
  15. spotAttenuation = super.getSpotAttenuation( angleCosine );
  16. }
  17. return spotAttenuation;
  18. }
  19. }
  20. export default IESSpotLightNode;
  21. addNodeClass( 'IESSpotLightNode', IESSpotLightNode );
  22. addLightNode( IESSpotLight, IESSpotLightNode );