var BABYLON;!function(e){var i=function(e){function i(){e.call(this),this.DIFFUSE=!1,this.CLIPPLANE=!1,this.ALPHATEST=!1,this.POINTSIZE=!1,this.FOG=!1,this.UV1=!1,this.NORMAL=!1,this.VERTEXCOLOR=!1,this.VERTEXALPHA=!1,this.BONES=!1,this.BONES4=!1,this.BonesPerMesh=0,this.INSTANCES=!1,this._keys=Object.keys(this)}return __extends(i,e),i}(e.MaterialDefines),n=function(n){function t(t,r){n.call(this,t,r),this.diffuseColor=new e.Color3(1,1,1),this.disableLighting=!1,this.speed=1,this._scaledDiffuse=new e.Color3,this._defines=new i,this._cachedDefines=new i,this._lastTime=0,this._cachedDefines.BonesPerMesh=-1}return __extends(t,n),t.prototype.needAlphaBlending=function(){return this.alpha<1},t.prototype.needAlphaTesting=function(){return!1},t.prototype.getAlphaTestTexture=function(){return null},t.prototype._checkCache=function(e,i,n){return i?this._defines.INSTANCES!==n?!1:i._materialDefines&&i._materialDefines.isEqual(this._defines)?!0:!1:!0},t.prototype.isReady=function(n,t){if(this.checkReadyOnlyOnce&&this._wasPreviouslyReady)return!0;var r=this.getScene();if(!this.checkReadyOnEveryCall&&this._renderId===r.getRenderId()&&this._checkCache(r,n,t))return!0;var o=(r.getEngine(),!1),s=!1;if(this._defines.reset(),r.texturesEnabled&&this.diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled){if(!this.diffuseTexture.isReady())return!1;s=!0,this._defines.DIFFUSE=!0}if(r.clipPlane&&(this._defines.CLIPPLANE=!0),this._defines.ALPHATEST=!0,(this.pointsCloud||r.forcePointsCloud)&&(this._defines.POINTSIZE=!0),r.fogEnabled&&n&&n.applyFog&&r.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(this._defines.FOG=!0),n&&(o&&n.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(this._defines.NORMAL=!0),s&&n.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(this._defines.UV1=!0),n.useVertexColors&&n.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(this._defines.VERTEXCOLOR=!0,n.hasVertexAlpha&&(this._defines.VERTEXALPHA=!0)),n.useBones&&n.computeBonesUsingShaders&&(this._defines.BONES=!0,this._defines.BonesPerMesh=n.skeleton.bones.length+1,this._defines.BONES4=!0),t&&(this._defines.INSTANCES=!0)),!this._defines.isEqual(this._cachedDefines)){this._defines.cloneTo(this._cachedDefines),r.resetCachedMaterial();var f=new e.EffectFallbacks;this._defines.FOG&&f.addFallback(1,"FOG"),this._defines.BONES4&&f.addFallback(0,"BONES4");var a=[e.VertexBuffer.PositionKind];this._defines.NORMAL&&a.push(e.VertexBuffer.NormalKind),this._defines.UV1&&a.push(e.VertexBuffer.UVKind),this._defines.VERTEXCOLOR&&a.push(e.VertexBuffer.ColorKind),this._defines.BONES&&(a.push(e.VertexBuffer.MatricesIndicesKind),a.push(e.VertexBuffer.MatricesWeightsKind)),this._defines.INSTANCES&&(a.push("world0"),a.push("world1"),a.push("world2"),a.push("world3"));var d="fire",l=this._defines.toString();this._effect=r.getEngine().createEffect(d,a,["world","view","viewProjection","vEyePosition","vFogInfos","vFogColor","pointSize","vDiffuseInfos","mBones","vClipPlane","diffuseMatrix","time","speed"],["diffuseSampler","distortionSampler","opacitySampler"],l,f,this.onCompiled,this.onError)}return this._effect.isReady()?(this._renderId=r.getRenderId(),this._wasPreviouslyReady=!0,n&&(n._materialDefines||(n._materialDefines=new i),this._defines.cloneTo(n._materialDefines)),!0):!1},t.prototype.bindOnlyWorldMatrix=function(e){this._effect.setMatrix("world",e)},t.prototype.bind=function(i,t){var r=this.getScene();if(this.bindOnlyWorldMatrix(i),this._effect.setMatrix("viewProjection",r.getTransformMatrix()),t&&t.useBones&&t.computeBonesUsingShaders&&this._effect.setMatrices("mBones",t.skeleton.getTransformMatrices(t)),r.getCachedMaterial()!==this){if(this.diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled&&(this._effect.setTexture("diffuseSampler",this.diffuseTexture),this._effect.setFloat2("vDiffuseInfos",this.diffuseTexture.coordinatesIndex,this.diffuseTexture.level),this._effect.setMatrix("diffuseMatrix",this.diffuseTexture.getTextureMatrix()),this._effect.setTexture("distortionSampler",this.distortionTexture),this._effect.setTexture("opacitySampler",this.opacityTexture)),r.clipPlane){var o=r.clipPlane;this._effect.setFloat4("vClipPlane",o.normal.x,o.normal.y,o.normal.z,o.d)}this.pointsCloud&&this._effect.setFloat("pointSize",this.pointSize),this._effect.setVector3("vEyePosition",r._mirroredCameraPosition?r._mirroredCameraPosition:r.activeCamera.position)}this._effect.setColor4("vDiffuseColor",this._scaledDiffuse,this.alpha*t.visibility),r.fogEnabled&&t.applyFog&&r.fogMode!==e.Scene.FOGMODE_NONE&&this._effect.setMatrix("view",r.getViewMatrix()),r.fogEnabled&&t.applyFog&&r.fogMode!==e.Scene.FOGMODE_NONE&&(this._effect.setFloat4("vFogInfos",r.fogMode,r.fogStart,r.fogEnd,r.fogDensity),this._effect.setColor3("vFogColor",r.fogColor)),this._lastTime+=r.getEngine().getDeltaTime(),this._effect.setFloat("time",this._lastTime),this._effect.setFloat("speed",this.speed),n.prototype.bind.call(this,i,t)},t.prototype.getAnimatables=function(){var e=[];return this.diffuseTexture&&this.diffuseTexture.animations&&this.diffuseTexture.animations.length>0&&e.push(this.diffuseTexture),this.distortionTexture&&this.distortionTexture.animations&&this.distortionTexture.animations.length>0&&e.push(this.distortionTexture),this.opacityTexture&&this.opacityTexture.animations&&this.opacityTexture.animations.length>0&&e.push(this.opacityTexture),e},t.prototype.dispose=function(e){this.diffuseTexture&&this.diffuseTexture.dispose(),this.distortionTexture&&this.distortionTexture.dispose(),n.prototype.dispose.call(this,e)},t.prototype.clone=function(e){var i=new t(e,this.getScene());return this.copyTo(i),this.diffuseTexture&&this.diffuseTexture.clone&&(i.diffuseTexture=this.diffuseTexture.clone()),this.distortionTexture&&this.distortionTexture.clone&&(i.distortionTexture=this.distortionTexture.clone()),this.opacityTexture&&this.opacityTexture.clone&&(i.opacityTexture=this.opacityTexture.clone()),i.diffuseColor=this.diffuseColor.clone(),i},t.prototype.serialize=function(){var e=n.prototype.serialize.call(this);return e.customType="BABYLON.FireMaterial",e.diffuseColor=this.diffuseColor.asArray(),e.speed=this.speed,e.disableLighting=this.disableLighting,this.diffuseTexture&&(e.diffuseTexture=this.diffuseTexture.serialize()),this.distortionTexture&&(e.distortionTexture=this.distortionTexture.serialize()),this.opacityTexture&&(e.opacityTexture=this.opacityTexture.serialize()),e},t.Parse=function(i,n,r){var o=new t(i.name,n);return o.diffuseColor=e.Color3.FromArray(i.diffuseColor),o.speed=i.speed,o.disableLighting=i.disableLighting,o.alpha=i.alpha,o.id=i.id,e.Tags.AddTagsTo(o,i.tags),o.backFaceCulling=i.backFaceCulling,o.wireframe=i.wireframe,i.diffuseTexture&&(o.diffuseTexture=e.Texture.Parse(i.diffuseTexture,n,r)),i.distortionTexture&&(o.distortionTexture=e.Texture.Parse(i.distortionTexture,n,r)),i.opacityTexture&&(o.opacityTexture=e.Texture.Parse(i.opacityTexture,n,r)),i.checkReadyOnlyOnce&&(o.checkReadyOnlyOnce=i.checkReadyOnlyOnce),o},t}(e.Material);e.FireMaterial=n}(BABYLON||(BABYLON={})),BABYLON.Effect.ShadersStore.fireVertexShader="precision highp float;\n\n// Attributes\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#ifdef BONES\nattribute vec4 matricesIndices;\nattribute vec4 matricesWeights;\n#endif\n\n// Uniforms\n\n#ifdef INSTANCES\nattribute vec4 world0;\nattribute vec4 world1;\nattribute vec4 world2;\nattribute vec4 world3;\n#else\nuniform mat4 world;\n#endif\n\nuniform mat4 view;\nuniform mat4 viewProjection;\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\n#endif\n\n#ifdef BONES\nuniform mat4 mBones[BonesPerMesh];\n#endif\n\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\n// Output\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif\n\n#ifdef FOG\nvarying float fFogDistance;\n#endif\n\n// Fire\nuniform float time;\nuniform float speed;\n\nvarying vec2 vDistortionCoords1;\nvarying vec2 vDistortionCoords2;\nvarying vec2 vDistortionCoords3;\n\nvoid main(void) {\n mat4 finalWorld;\n\n#ifdef INSTANCES\n finalWorld = mat4(world0, world1, world2, world3);\n#else\n finalWorld = world;\n#endif\n\n#ifdef BONES\n mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\n mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\n mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\n\n#ifdef BONES4\n mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\n finalWorld = finalWorld * (m0 + m1 + m2 + m3);\n#else\n finalWorld = finalWorld * (m0 + m1 + m2);\n#endif \n\n#endif\n gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\n\n vec4 worldPos = finalWorld * vec4(position, 1.0);\n vPositionW = vec3(worldPos);\n\n#ifdef NORMAL\n vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));\n#endif\n\n // Texture coordinates\n#ifdef DIFFUSE\n vDiffuseUV = uv;\n vDiffuseUV.y -= 0.2;\n#endif\n\n // Clip plane\n#ifdef CLIPPLANE\n fClipDistance = dot(worldPos, vClipPlane);\n#endif\n\n // Fog\n#ifdef FOG\n fFogDistance = (view * worldPos).z;\n#endif\n\n // Vertex color\n#ifdef VERTEXCOLOR\n vColor = color;\n#endif\n\n // Point size\n#ifdef POINTSIZE\n gl_PointSize = pointSize;\n#endif\n\n // Fire\n vec3 layerSpeed = vec3(-0.2, -0.52, -0.1) * speed;\n \n vDistortionCoords1.x = uv.x;\n vDistortionCoords1.y = uv.y + layerSpeed.x * time / 1000.0;\n \n vDistortionCoords2.x = uv.x;\n vDistortionCoords2.y = uv.y + layerSpeed.y * time / 1000.0;\n \n vDistortionCoords3.x = uv.x;\n vDistortionCoords3.y = uv.y + layerSpeed.z * time / 1000.0;\n}\n",BABYLON.Effect.ShadersStore.firePixelShader="precision highp float;\r\n\r\n// Constants\r\nuniform vec3 vEyePosition;\r\n\r\n// Input\r\nvarying vec3 vPositionW;\r\n\r\n#ifdef NORMAL\r\nvarying vec3 vNormalW;\r\n#endif\r\n\r\n#ifdef VERTEXCOLOR\r\nvarying vec4 vColor;\r\n#endif\r\n\r\n// Samplers\r\n#ifdef DIFFUSE\r\nvarying vec2 vDiffuseUV;\r\nuniform sampler2D diffuseSampler;\r\nuniform vec2 vDiffuseInfos;\r\n#endif\r\n\r\n// Fire\r\nuniform sampler2D distortionSampler;\r\nuniform sampler2D opacitySampler;\r\n\r\nvarying vec2 vDistortionCoords1;\r\nvarying vec2 vDistortionCoords2;\r\nvarying vec2 vDistortionCoords3;\r\n\r\n#ifdef CLIPPLANE\r\nvarying float fClipDistance;\r\n#endif\r\n\r\n// Fog\r\n#ifdef FOG\r\n\r\n#define FOGMODE_NONE 0.\r\n#define FOGMODE_EXP 1.\r\n#define FOGMODE_EXP2 2.\r\n#define FOGMODE_LINEAR 3.\r\n#define E 2.71828\r\n\r\nuniform vec4 vFogInfos;\r\nuniform vec3 vFogColor;\r\nvarying float fFogDistance;\r\n\r\nfloat CalcFogFactor()\r\n{\r\n float fogCoeff = 1.0;\r\n float fogStart = vFogInfos.y;\r\n float fogEnd = vFogInfos.z;\r\n float fogDensity = vFogInfos.w;\r\n\r\n if (FOGMODE_LINEAR == vFogInfos.x)\r\n {\r\n fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);\r\n }\r\n else if (FOGMODE_EXP == vFogInfos.x)\r\n {\r\n fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);\r\n }\r\n else if (FOGMODE_EXP2 == vFogInfos.x)\r\n {\r\n fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);\r\n }\r\n\r\n return clamp(fogCoeff, 0.0, 1.0);\r\n}\r\n#endif\r\n\r\nvec4 bx2(vec4 x)\r\n{\r\n return vec4(2.0) * x - vec4(1.0);\r\n}\r\n\r\nvoid main(void) {\r\n // Clip plane\r\n#ifdef CLIPPLANE\r\n if (fClipDistance > 0.0)\r\n discard;\r\n#endif\r\n\r\n vec3 viewDirectionW = normalize(vEyePosition - vPositionW);\r\n\r\n // Base color\r\n vec4 baseColor = vec4(1., 1., 1., 1.);\r\n\r\n // Alpha\r\n float alpha = 1.0;\r\n\r\n#ifdef DIFFUSE\r\n // Fire\r\n const float distortionAmount0 = 0.092;\r\n const float distortionAmount1 = 0.092;\r\n const float distortionAmount2 = 0.092;\r\n \r\n vec2 heightAttenuation = vec2(0.3, 0.39);\r\n \r\n vec4 noise0 = texture2D(distortionSampler, vDistortionCoords1);\r\n vec4 noise1 = texture2D(distortionSampler, vDistortionCoords2);\r\n vec4 noise2 = texture2D(distortionSampler, vDistortionCoords3);\r\n \r\n vec4 noiseSum = bx2(noise0) * distortionAmount0 + bx2(noise1) * distortionAmount1 + bx2(noise2) * distortionAmount2;\r\n \r\n vec4 perturbedBaseCoords = vec4(vDiffuseUV, 0.0, 1.0) + noiseSum * (vDiffuseUV.y * heightAttenuation.x + heightAttenuation.y);\r\n \r\n vec4 opacityColor = texture2D(opacitySampler, perturbedBaseCoords.xy);\r\n \r\n#ifdef ALPHATEST\r\n if (opacityColor.r < 0.1)\r\n discard;\r\n#endif\r\n \r\n baseColor = texture2D(diffuseSampler, perturbedBaseCoords.xy) * 2.0;\r\n baseColor *= opacityColor;\r\n\r\n baseColor.rgb *= vDiffuseInfos.y;\r\n#endif\r\n\r\n#ifdef VERTEXCOLOR\r\n baseColor.rgb *= vColor.rgb;\r\n#endif\r\n\r\n // Bump\r\n#ifdef NORMAL\r\n vec3 normalW = normalize(vNormalW);\r\n#else\r\n vec3 normalW = vec3(1.0, 1.0, 1.0);\r\n#endif\r\n\r\n // Lighting\r\n vec3 diffuseBase = vec3(1.0, 1.0, 1.0);\r\n\r\n#ifdef VERTEXALPHA\r\n alpha *= vColor.a;\r\n#endif\r\n\r\n // Composition\r\n vec4 color = vec4(baseColor.rgb, alpha);\r\n\r\n#ifdef FOG\r\n float fog = CalcFogFactor();\r\n color.rgb = fog * color.rgb + (1.0 - fog) * vFogColor;\r\n#endif\r\n\r\n gl_FragColor = color;\r\n}";