1 |
- var __extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o])};return function(r,o){function t(){this.constructor=r}e(r,o),r.prototype=null===o?Object.create(o):(t.prototype=o.prototype,new t)}})(),__decorate=this&&this.__decorate||function(e,r,o,t){var n,i=arguments.length,l=i<3?r:null===t?t=Object.getOwnPropertyDescriptor(r,o):t;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,r,o,t);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(l=(i<3?n(l):i>3?n(r,o,l):n(r,o))||l);return i>3&&l&&Object.defineProperty(r,o,l),l},BABYLON;!(function(e){var r=(function(r){function o(t,n,i,l,a){var s=r.call(this,t,n,"fireProceduralTexture",i,l,a)||this;return s._time=0,s._speed=new e.Vector2(.5,.3),s._autoGenerateTime=!0,s._alphaThreshold=.5,s._fireColors=o.RedFireColors,s.updateShaderUniforms(),s}return __extends(o,r),o.prototype.updateShaderUniforms=function(){this.setFloat("time",this._time),this.setVector2("speed",this._speed),this.setColor3("c1",this._fireColors[0]),this.setColor3("c2",this._fireColors[1]),this.setColor3("c3",this._fireColors[2]),this.setColor3("c4",this._fireColors[3]),this.setColor3("c5",this._fireColors[4]),this.setColor3("c6",this._fireColors[5]),this.setFloat("alphaThreshold",this._alphaThreshold)},o.prototype.render=function(e){var o=this.getScene();this._autoGenerateTime&&o&&(this._time+=.03*o.getAnimationRatio(),this.updateShaderUniforms()),r.prototype.render.call(this,e)},Object.defineProperty(o,"PurpleFireColors",{get:function(){return[new e.Color3(.5,0,1),new e.Color3(.9,0,1),new e.Color3(.2,0,1),new e.Color3(1,.9,1),new e.Color3(.1,.1,1),new e.Color3(.9,.9,1)]},enumerable:!0,configurable:!0}),Object.defineProperty(o,"GreenFireColors",{get:function(){return[new e.Color3(.5,1,0),new e.Color3(.5,1,0),new e.Color3(.3,.4,0),new e.Color3(.5,1,0),new e.Color3(.2,0,0),new e.Color3(.5,1,0)]},enumerable:!0,configurable:!0}),Object.defineProperty(o,"RedFireColors",{get:function(){return[new e.Color3(.5,0,.1),new e.Color3(.9,0,0),new e.Color3(.2,0,0),new e.Color3(1,.9,0),new e.Color3(.1,.1,.1),new e.Color3(.9,.9,.9)]},enumerable:!0,configurable:!0}),Object.defineProperty(o,"BlueFireColors",{get:function(){return[new e.Color3(.1,0,.5),new e.Color3(0,0,.5),new e.Color3(.1,0,.2),new e.Color3(0,0,1),new e.Color3(.1,.2,.3),new e.Color3(0,.2,.9)]},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"autoGenerateTime",{get:function(){return this._autoGenerateTime},set:function(e){this._autoGenerateTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"fireColors",{get:function(){return this._fireColors},set:function(e){this._fireColors=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"time",{get:function(){return this._time},set:function(e){this._time=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"speed",{get:function(){return this._speed},set:function(e){this._speed=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"alphaThreshold",{get:function(){return this._alphaThreshold},set:function(e){this._alphaThreshold=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),o.prototype.serialize=function(){var o=e.SerializationHelper.Serialize(this,r.prototype.serialize.call(this));o.customType="BABYLON.FireProceduralTexture",o.fireColors=[];for(var t=0;t<this._fireColors.length;t++)o.fireColors.push(this._fireColors[t].asArray());return o},o.Parse=function(r,t,n){for(var i=e.SerializationHelper.Parse((function(){return new o(r.name,r._size,t,void 0,r._generateMipMaps)}),r,t,n),l=[],a=0;a<r.fireColors.length;a++)l.push(e.Color3.FromArray(r.fireColors[a]));return i.fireColors=l,i},__decorate([e.serialize()],o.prototype,"autoGenerateTime",null),__decorate([e.serialize()],o.prototype,"time",null),__decorate([e.serializeAsVector2()],o.prototype,"speed",null),__decorate([e.serialize()],o.prototype,"alphaThreshold",null),o})(e.ProceduralTexture);e.FireProceduralTexture=r})(BABYLON||(BABYLON={})),BABYLON.Effect.ShadersStore.fireProceduralTexturePixelShader="precision highp float;\nuniform float time;\nuniform vec3 c1;\nuniform vec3 c2;\nuniform vec3 c3;\nuniform vec3 c4;\nuniform vec3 c5;\nuniform vec3 c6;\nuniform vec2 speed;\nuniform float shift;\nuniform float alphaThreshold;\nvarying vec2 vUV;\nfloat rand(vec2 n) {\nreturn fract(cos(dot(n,vec2(12.9898,4.1414)))*43758.5453);\n}\nfloat noise(vec2 n) {\nconst vec2 d=vec2(0.0,1.0);\nvec2 b=floor(n),f=smoothstep(vec2(0.0),vec2(1.0),fract(n));\nreturn mix(mix(rand(b),rand(b+d.yx),f.x),mix(rand(b+d.xy),rand(b+d.yy),f.x),f.y);\n}\nfloat fbm(vec2 n) {\nfloat total=0.0,amplitude=1.0;\nfor (int i=0; i<4; i++) {\ntotal+=noise(n)*amplitude;\nn+=n;\namplitude*=0.5;\n}\nreturn total;\n}\nvoid main() {\nvec2 p=vUV*8.0;\nfloat q=fbm(p-time*0.1);\nvec2 r=vec2(fbm(p+q+time*speed.x-p.x-p.y),fbm(p+q-time*speed.y));\nvec3 c=mix(c1,c2,fbm(p+r))+mix(c3,c4,r.x)-mix(c5,c6,r.y);\nvec3 color=c*cos(shift*vUV.y);\nfloat luminance=dot(color.rgb,vec3(0.3,0.59,0.11));\ngl_FragColor=vec4(color,luminance*alphaThreshold+(1.0-alphaThreshold));\n}";
|