import { P as A, i as E, k as p, l as m, c9 as O, m as x, n as H, E as D, ca as _, o as h, cb as N, p as C, A as v, cc as F, cd as G, q as y, r as M, ce as R, w as b, t as B, u as g, v as W, _ as l, g as U, h as d, s as w, e as P, R as k } from "./chunk-CrnJfeNw.js";
class z extends W {
  constructor() {
    super(), this.DIFFUSE = !1, this.CLIPPLANE = !1, this.CLIPPLANE2 = !1, this.CLIPPLANE3 = !1, this.CLIPPLANE4 = !1, this.CLIPPLANE5 = !1, this.CLIPPLANE6 = !1, this.ALPHATEST = !1, this.DEPTHPREPASS = !1, this.POINTSIZE = !1, this.FOG = !1, this.LIGHT0 = !1, this.LIGHT1 = !1, this.LIGHT2 = !1, this.LIGHT3 = !1, this.SPOTLIGHT0 = !1, this.SPOTLIGHT1 = !1, this.SPOTLIGHT2 = !1, this.SPOTLIGHT3 = !1, this.HEMILIGHT0 = !1, this.HEMILIGHT1 = !1, this.HEMILIGHT2 = !1, this.HEMILIGHT3 = !1, this.DIRLIGHT0 = !1, this.DIRLIGHT1 = !1, this.DIRLIGHT2 = !1, this.DIRLIGHT3 = !1, this.POINTLIGHT0 = !1, this.POINTLIGHT1 = !1, this.POINTLIGHT2 = !1, this.POINTLIGHT3 = !1, this.SHADOW0 = !1, this.SHADOW1 = !1, this.SHADOW2 = !1, this.SHADOW3 = !1, this.SHADOWS = !1, this.SHADOWESM0 = !1, this.SHADOWESM1 = !1, this.SHADOWESM2 = !1, this.SHADOWESM3 = !1, this.SHADOWPOISSON0 = !1, this.SHADOWPOISSON1 = !1, this.SHADOWPOISSON2 = !1, this.SHADOWPOISSON3 = !1, this.SHADOWPCF0 = !1, this.SHADOWPCF1 = !1, this.SHADOWPCF2 = !1, this.SHADOWPCF3 = !1, this.SHADOWPCSS0 = !1, this.SHADOWPCSS1 = !1, this.SHADOWPCSS2 = !1, this.SHADOWPCSS3 = !1, this.NORMAL = !1, this.UV1 = !1, this.UV2 = !1, this.NUM_BONE_INFLUENCERS = 0, this.BonesPerMesh = 0, this.INSTANCES = !1, this.THIN_INSTANCES = !1, this.LIGHTING = !1, this.IMAGEPROCESSINGPOSTPROCESS = !1, this.SKIPFINALCOLORCLAMP = !1, this.LOGARITHMICDEPTH = !1, this.AREALIGHTSUPPORTED = !0, this.AREALIGHTNOROUGHTNESS = !0, this.rebuild();
  }
}
class f extends A {
  /**
   * Instantiates a Normal Material in the given scene
   * @param name The friendly name of the material
   * @param scene The scene to add the material to
   * @param forceGLSL Use the GLSL code generation for the shader (even on WebGPU). Default is false
   */
  constructor(e, i, r = !1) {
    super(e, i, void 0, r), this.diffuseColor = new E(1, 1, 1), this._disableLighting = !1, this._maxSimultaneousLights = 4, this._shadersLoaded = !1;
  }
  needAlphaBlending() {
    return this.alpha < 1;
  }
  needAlphaBlendingForMesh(e) {
    return this.needAlphaBlending() || e.visibility < 1;
  }
  needAlphaTesting() {
    return !1;
  }
  getAlphaTestTexture() {
    return null;
  }
  // Methods
  isReadyForSubMesh(e, i, r) {
    const t = i._drawWrapper;
    if (this.isFrozen && t.effect && t._wasPreviouslyReady && t._wasPreviouslyUsingInstances === r)
      return !0;
    i.materialDefines || (i.materialDefines = new z());
    const s = i.materialDefines, a = this.getScene();
    if (this._isReadyForSubMesh(i))
      return !0;
    const S = a.getEngine();
    if (s._areTexturesDirty && (s._needUVs = !1, a.texturesEnabled && this._diffuseTexture && p.DiffuseTextureEnabled))
      if (this._diffuseTexture.isReady())
        s._needUVs = !0, s.DIFFUSE = !0;
      else
        return !1;
    if (m(e, a, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this.needAlphaTestingForMesh(e), s, void 0, void 0, void 0, this._isVertexOutputInvariant), s._needNormals = !0, O(a, e, s, !1, this._maxSimultaneousLights, this._disableLighting), x(a, S, this, s, !!r, null, i.getRenderingMesh().hasThinInstances), s.LIGHTING = !this._disableLighting, H(e, s, !0, !0), s.isDirty) {
      s.markAsProcessed(), a.resetCachedMaterial();
      const n = new D();
      s.FOG && n.addFallback(1, "FOG"), _(s, n), s.NUM_BONE_INFLUENCERS > 0 && n.addCPUSkinningFallback(0, e), s.IMAGEPROCESSINGPOSTPROCESS = a.imageProcessingConfiguration.applyByPostProcess;
      const o = [h.PositionKind];
      s.NORMAL && o.push(h.NormalKind), s.UV1 && o.push(h.UVKind), s.UV2 && o.push(h.UV2Kind), N(o, e, s, n), C(o, s);
      const L = "normal", I = s.toString(), u = [
        "world",
        "view",
        "viewProjection",
        "vEyePosition",
        "vLightsType",
        "vDiffuseColor",
        "vFogInfos",
        "vFogColor",
        "pointSize",
        "vDiffuseInfos",
        "mBones",
        "diffuseMatrix",
        "logarithmicDepthConstant"
      ], c = ["diffuseSampler", "areaLightsLTC1Sampler", "areaLightsLTC2Sampler"], T = [];
      v(u), F({
        uniformsNames: u,
        uniformBuffersNames: T,
        samplers: c,
        defines: s,
        maxSimultaneousLights: 4
      }), i.setEffect(a.getEngine().createEffect(L, {
        attributes: o,
        uniformsNames: u,
        uniformBuffersNames: T,
        samplers: c,
        defines: I,
        fallbacks: n,
        onCompiled: this.onCompiled,
        onError: this.onError,
        indexParameters: { maxSimultaneousLights: 4 },
        shaderLanguage: this._shaderLanguage,
        extraInitializationsAsync: this._shadersLoaded ? void 0 : async () => {
          this.shaderLanguage === 1 ? await Promise.all([import("./chunk-CUlivvXR.js"), import("./chunk-ChJUh3Iq.js")]) : await Promise.all([import("./chunk-DbKzZGtM.js"), import("./chunk-BVPVdoWT.js")]), this._shadersLoaded = !0;
        }
      }, S), s, this._materialContext);
    }
    if (s.AREALIGHTUSED) {
      for (let n = 0; n < e.lightSources.length; n++)
        if (!e.lightSources[n]._isReady())
          return !1;
    }
    return !i.effect || !i.effect.isReady() ? !1 : (s._renderId = a.getRenderId(), t._wasPreviouslyReady = !0, t._wasPreviouslyUsingInstances = !!r, !0);
  }
  bindForSubMesh(e, i, r) {
    const t = this.getScene(), s = r.materialDefines;
    if (!s)
      return;
    const a = r.effect;
    a && (this._activeEffect = a, this.bindOnlyWorldMatrix(e), this._activeEffect.setMatrix("viewProjection", t.getTransformMatrix()), G(i, this._activeEffect), this._mustRebind(t, a, r) && (this.diffuseTexture && p.DiffuseTextureEnabled && (this._activeEffect.setTexture("diffuseSampler", this.diffuseTexture), this._activeEffect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level), this._activeEffect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix())), y(a, this, t), this.pointsCloud && this._activeEffect.setFloat("pointSize", this.pointSize), this._useLogarithmicDepth && M(s, a, t), t.bindEyePosition(a)), this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * i.visibility), t.lightsEnabled && !this.disableLighting && R(t, i, this._activeEffect, s), t.fogEnabled && i.applyFog && t.fogMode !== b.FOGMODE_NONE && this._activeEffect.setMatrix("view", t.getViewMatrix()), B(t, i, this._activeEffect), this._afterBind(i, this._activeEffect, r));
  }
  getAnimatables() {
    const e = [];
    return this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0 && e.push(this.diffuseTexture), e;
  }
  getActiveTextures() {
    const e = super.getActiveTextures();
    return this._diffuseTexture && e.push(this._diffuseTexture), e;
  }
  hasTexture(e) {
    return !!(super.hasTexture(e) || this.diffuseTexture === e);
  }
  dispose(e) {
    this.diffuseTexture && this.diffuseTexture.dispose(), super.dispose(e);
  }
  clone(e) {
    return g.Clone(() => new f(e, this.getScene()), this);
  }
  serialize() {
    const e = super.serialize();
    return e.customType = "BABYLON.NormalMaterial", e;
  }
  getClassName() {
    return "NormalMaterial";
  }
  // Statics
  static Parse(e, i, r) {
    return g.Parse(() => new f(e.name, i), e, i, r);
  }
}
l([
  U("diffuseTexture")
], f.prototype, "_diffuseTexture", void 0);
l([
  d("_markAllSubMeshesAsTexturesDirty")
], f.prototype, "diffuseTexture", void 0);
l([
  w()
], f.prototype, "diffuseColor", void 0);
l([
  P("disableLighting")
], f.prototype, "_disableLighting", void 0);
l([
  d("_markAllSubMeshesAsLightsDirty")
], f.prototype, "disableLighting", void 0);
l([
  P("maxSimultaneousLights")
], f.prototype, "_maxSimultaneousLights", void 0);
l([
  d("_markAllSubMeshesAsLightsDirty")
], f.prototype, "maxSimultaneousLights", void 0);
k("BABYLON.NormalMaterial", f);
export {
  f as NormalMaterial
};