1 |
- var BABYLON;!function(e){var r=function(e){function r(){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(r,e),r}(e.MaterialDefines),i=function(i){function n(n,t){i.call(this,n,t),this.diffuseColor=new e.Color3(1,1,1),this.disableLighting=!1,this.speed=1,this._scaledDiffuse=new e.Color3,this._defines=new r,this._cachedDefines=new r,this._lastTime=0,this._cachedDefines.BonesPerMesh=-1}return __extends(n,i),n.prototype.needAlphaBlending=function(){return this.alpha<1},n.prototype.needAlphaTesting=function(){return!1},n.prototype.getAlphaTestTexture=function(){return null},n.prototype._checkCache=function(e,r,i){return r?this._defines.INSTANCES!==i?!1:r._materialDefines&&r._materialDefines.isEqual(this._defines)?!0:!1:!0},n.prototype.isReady=function(i,n){if(this.checkReadyOnlyOnce&&this._wasPreviouslyReady)return!0;var t=this.getScene();if(!this.checkReadyOnEveryCall&&this._renderId===t.getRenderId()&&this._checkCache(t,i,n))return!0;var o=(t.getEngine(),!1),s=!1;if(this._defines.reset(),t.texturesEnabled&&this.diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled){if(!this.diffuseTexture.isReady())return!1;s=!0,this._defines.DIFFUSE=!0}if(t.clipPlane&&(this._defines.CLIPPLANE=!0),this._defines.ALPHATEST=!0,(this.pointsCloud||t.forcePointsCloud)&&(this._defines.POINTSIZE=!0),t.fogEnabled&&i&&i.applyFog&&t.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(this._defines.FOG=!0),i&&(o&&i.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(this._defines.NORMAL=!0),s&&i.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(this._defines.UV1=!0),i.useVertexColors&&i.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(this._defines.VERTEXCOLOR=!0,i.hasVertexAlpha&&(this._defines.VERTEXALPHA=!0)),i.useBones&&i.computeBonesUsingShaders&&(this._defines.BONES=!0,this._defines.BonesPerMesh=i.skeleton.bones.length+1,this._defines.BONES4=!0),n&&(this._defines.INSTANCES=!0)),!this._defines.isEqual(this._cachedDefines)){this._defines.cloneTo(this._cachedDefines),t.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=t.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=t.getRenderId(),this._wasPreviouslyReady=!0,i&&(i._materialDefines||(i._materialDefines=new r),this._defines.cloneTo(i._materialDefines)),!0):!1},n.prototype.bindOnlyWorldMatrix=function(e){this._effect.setMatrix("world",e)},n.prototype.bind=function(r,n){var t=this.getScene();if(this.bindOnlyWorldMatrix(r),this._effect.setMatrix("viewProjection",t.getTransformMatrix()),n&&n.useBones&&n.computeBonesUsingShaders&&this._effect.setMatrices("mBones",n.skeleton.getTransformMatrices()),t.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)),t.clipPlane){var o=t.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",t._mirroredCameraPosition?t._mirroredCameraPosition:t.activeCamera.position)}this._effect.setColor4("vDiffuseColor",this._scaledDiffuse,this.alpha*n.visibility),t.fogEnabled&&n.applyFog&&t.fogMode!==e.Scene.FOGMODE_NONE&&this._effect.setMatrix("view",t.getViewMatrix()),t.fogEnabled&&n.applyFog&&t.fogMode!==e.Scene.FOGMODE_NONE&&(this._effect.setFloat4("vFogInfos",t.fogMode,t.fogStart,t.fogEnd,t.fogDensity),this._effect.setColor3("vFogColor",t.fogColor)),this._lastTime+=t.getEngine().getDeltaTime(),this._effect.setFloat("time",this._lastTime),this._effect.setFloat("speed",this.speed),i.prototype.bind.call(this,r,n)},n.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},n.prototype.dispose=function(e){this.diffuseTexture&&this.diffuseTexture.dispose(),this.distortionTexture&&this.distortionTexture.dispose(),i.prototype.dispose.call(this,e)},n.prototype.clone=function(e){var r=new n(e,this.getScene());return this.copyTo(r),this.diffuseTexture&&this.diffuseTexture.clone&&(r.diffuseTexture=this.diffuseTexture.clone()),this.distortionTexture&&this.distortionTexture.clone&&(r.distortionTexture=this.distortionTexture.clone()),this.opacityTexture&&this.opacityTexture.clone&&(r.opacityTexture=this.opacityTexture.clone()),r.diffuseColor=this.diffuseColor.clone(),r},n.prototype.serialize=function(){var e=i.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},n.Parse=function(r,i,t){var o=new n(r.name,i);return o.diffuseColor=e.Color3.FromArray(r.diffuseColor),o.speed=r.speed,o.disableLighting=r.disableLighting,o.alpha=r.alpha,o.id=r.id,e.Tags.AddTagsTo(o,r.tags),o.backFaceCulling=r.backFaceCulling,o.wireframe=r.wireframe,r.diffuseTexture&&(o.diffuseTexture=e.Texture.Parse(r.diffuseTexture,i,t)),r.distortionTexture&&(o.distortionTexture=e.Texture.Parse(r.distortionTexture,i,t)),r.opacityTexture&&(o.opacityTexture=e.Texture.Parse(r.opacityTexture,i,t)),r.checkReadyOnlyOnce&&(o.checkReadyOnlyOnce=r.checkReadyOnlyOnce),o},n}(e.Material);e.FireMaterial=i}(BABYLON||(BABYLON={})),BABYLON.Effect.ShadersStore.fireVertexShader="precision highp float;\r\n\r\n// Attributes\r\nattribute vec3 position;\r\n#ifdef NORMAL\r\nattribute vec3 normal;\r\n#endif\r\n#ifdef UV1\r\nattribute vec2 uv;\r\n#endif\r\n#ifdef UV2\r\nattribute vec2 uv2;\r\n#endif\r\n#ifdef VERTEXCOLOR\r\nattribute vec4 color;\r\n#endif\r\n#ifdef BONES\r\nattribute vec4 matricesIndices;\r\nattribute vec4 matricesWeights;\r\n#endif\r\n\r\n// Uniforms\r\n\r\n#ifdef INSTANCES\r\nattribute vec4 world0;\r\nattribute vec4 world1;\r\nattribute vec4 world2;\r\nattribute vec4 world3;\r\n#else\r\nuniform mat4 world;\r\n#endif\r\n\r\nuniform mat4 view;\r\nuniform mat4 viewProjection;\r\n\r\n#ifdef DIFFUSE\r\nvarying vec2 vDiffuseUV;\r\n#endif\r\n\r\n#ifdef BONES\r\nuniform mat4 mBones[BonesPerMesh];\r\n#endif\r\n\r\n#ifdef POINTSIZE\r\nuniform float pointSize;\r\n#endif\r\n\r\n// Output\r\nvarying vec3 vPositionW;\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#ifdef CLIPPLANE\r\nuniform vec4 vClipPlane;\r\nvarying float fClipDistance;\r\n#endif\r\n\r\n#ifdef FOG\r\nvarying float fFogDistance;\r\n#endif\r\n\r\n// Fire\r\nuniform float time;\r\nuniform float speed;\r\n\r\nvarying vec2 vDistortionCoords1;\r\nvarying vec2 vDistortionCoords2;\r\nvarying vec2 vDistortionCoords3;\r\n\r\nvoid main(void) {\r\n mat4 finalWorld;\r\n\r\n#ifdef INSTANCES\r\n finalWorld = mat4(world0, world1, world2, world3);\r\n#else\r\n finalWorld = world;\r\n#endif\r\n\r\n#ifdef BONES\r\n mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\r\n mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\r\n mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\r\n\r\n#ifdef BONES4\r\n mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\r\n finalWorld = finalWorld * (m0 + m1 + m2 + m3);\r\n#else\r\n finalWorld = finalWorld * (m0 + m1 + m2);\r\n#endif \r\n\r\n#endif\r\n gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\r\n\r\n vec4 worldPos = finalWorld * vec4(position, 1.0);\r\n vPositionW = vec3(worldPos);\r\n\r\n#ifdef NORMAL\r\n vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));\r\n#endif\r\n\r\n // Texture coordinates\r\n#ifdef DIFFUSE\r\n vDiffuseUV = uv;\r\n vDiffuseUV.y -= 0.2;\r\n#endif\r\n\r\n // Clip plane\r\n#ifdef CLIPPLANE\r\n fClipDistance = dot(worldPos, vClipPlane);\r\n#endif\r\n\r\n // Fog\r\n#ifdef FOG\r\n fFogDistance = (view * worldPos).z;\r\n#endif\r\n\r\n // Vertex color\r\n#ifdef VERTEXCOLOR\r\n vColor = color;\r\n#endif\r\n\r\n // Point size\r\n#ifdef POINTSIZE\r\n gl_PointSize = pointSize;\r\n#endif\r\n\r\n // Fire\r\n vec3 layerSpeed = vec3(-0.2, -0.52, -0.1) * speed;\r\n \r\n vDistortionCoords1.x = uv.x;\r\n vDistortionCoords1.y = uv.y + layerSpeed.x * time / 1000.0;\r\n \r\n vDistortionCoords2.x = uv.x;\r\n vDistortionCoords2.y = uv.y + layerSpeed.y * time / 1000.0;\r\n \r\n vDistortionCoords3.x = uv.x;\r\n vDistortionCoords3.y = uv.y + layerSpeed.z * time / 1000.0;\r\n}\r\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}";
|