text: import { __extends } from "tslib";
  import { NodeMaterialBlock } from '../../nodeMaterialBlock';
  import { NodeMaterialBlockConnectionPointTypes } from '../../Enums/nodeMaterialBlockConnectionPointTypes';
  import { NodeMaterialBlockTargets } from '../../Enums/nodeMaterialBlockTargets';
  import { _TypeStore } from '../../../../Misc/typeStore';
  import { PointLight } from '../../../../Lights/pointLight';
  /**
   * Block used to get data information from a light
   */
  var LightInformationBlock = /** @class */ (function (_super) {
      __extends(LightInformationBlock, _super);
      /**
       * Creates a new LightInformationBlock
       * @param name defines the block name
       */
      function LightInformationBlock(name) {
          var _this = _super.call(this, name, NodeMaterialBlockTargets.Vertex) || this;
          _this.registerInput("worldPosition", NodeMaterialBlockConnectionPointTypes.Vector4, false, NodeMaterialBlockTargets.Vertex);
          _this.registerOutput("direction", NodeMaterialBlockConnectionPointTypes.Vector3);
          _this.registerOutput("color", NodeMaterialBlockConnectionPointTypes.Color3);
          _this.registerOutput("intensity", NodeMaterialBlockConnectionPointTypes.Float);
          return _this;
      }
      /**
       * Gets the current class name
       * @returns the class name
       */
      LightInformationBlock.prototype.getClassName = function () {
          return "LightInformationBlock";
      };
      Object.defineProperty(LightInformationBlock.prototype, "worldPosition", {
          /**
           * Gets the world position input component
           */
          get: function () {
              return this._inputs[0];
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(LightInformationBlock.prototype, "direction", {
          /**
           * Gets the direction output component
           */
          get: function () {
              return this._outputs[0];
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(LightInformationBlock.prototype, "color", {
          /**
           * Gets the direction output component
           */
          get: function () {
              return this._outputs[1];
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(LightInformationBlock.prototype, "intensity", {
          /**
       * Gets the direction output component
       */
          get: function () {
              return this._outputs[2];
          },
          enumerable: false,
          configurable: true
      });
      LightInformationBlock.prototype.bind = function (effect, nodeMaterial, mesh) {
          if (!mesh) {
              return;
          }
          if (this.light && this.light.isDisposed) {
              this.light = null;
          }
          var light = this.light;
          var scene = nodeMaterial.getScene();
          if (!light && scene.lights.length) {
              light = scene.lights[0];
          }
          if (!light || !light.isEnabled) {
              effect.setFloat3(this._lightDataUniformName, 0, 0, 0);
              effect.setFloat4(this._lightColorUniformName, 0, 0, 0, 0);
              return;
          }
          light.transferToNodeMaterialEffect(effect, this._lightDataUniformName);
          effect.setColor4(this._lightColorUniformName, light.diffuse, light.intensity);
      };
      LightInformationBlock.prototype.prepareDefines = function (mesh, nodeMaterial, defines) {
          if (!defines._areLightsDirty) {
              return;
          }
          var light = this.light;
          defines.setValue(this._lightTypeDefineName, light && light instanceof PointLight ? true : false);
      };
      LightInformationBlock.prototype._buildBlock = function (state) {
          _super.prototype._buildBlock.call(this, state);
          state.sharedData.bindableBlocks.push(this);
          state.sharedData.blocksWithDefines.push(this);
          var direction = this.direction;
          var color = this.color;
          var intensity = this.intensity;
          this._lightDataUniformName = state._getFreeVariableName("lightData");
          this._lightColorUniformName = state._getFreeVariableName("lightColor");
          this._lightTypeDefineName = state._getFreeDefineName("LIGHTPOINTTYPE");
          state._emitUniformFromString(this._lightDataUniformName, "vec3");
          state._emitUniformFromString(this._lightColorUniformName, "vec4");
          state.compilationString += "#ifdef " + this._lightTypeDefineName + "\r\n";
          state.compilationString += this._declareOutput(direction, state) + (" = normalize(" + this.worldPosition.associatedVariableName + ".xyz - " + this._lightDataUniformName + ");\r\n");
          state.compilationString += "#else\r\n";
          state.compilationString += this._declareOutput(direction, state) + (" = " + this._lightDataUniformName + ";\r\n");
          state.compilationString += "#endif\r\n";
          state.compilationString += this._declareOutput(color, state) + (" = " + this._lightColorUniformName + ".rgb;\r\n");
          state.compilationString += this._declareOutput(intensity, state) + (" = " + this._lightColorUniformName + ".a;\r\n");
          return this;
      };
      LightInformationBlock.prototype.serialize = function () {
          var serializationObject = _super.prototype.serialize.call(this);
          if (this.light) {
              serializationObject.lightId = this.light.id;
          }
          return serializationObject;
      };
      LightInformationBlock.prototype._deserialize = function (serializationObject, scene, rootUrl) {
          _super.prototype._deserialize.call(this, serializationObject, scene, rootUrl);
          if (serializationObject.lightId) {
              this.light = scene.getLightByID(serializationObject.lightId);
          }
      };
      return LightInformationBlock;
  }(NodeMaterialBlock));
  export { LightInformationBlock };
  _TypeStore.RegisteredTypes["BABYLON.LightInformationBlock"] = LightInformationBlock;
  //# sourceMappingURL=lightInformationBlock.js.map