babylon.fireProceduralTexture.min.js 7.9 KB

12345678910111213141516
  1. !function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-procedural-textures",["babylonjs"],r):"object"==typeof exports?exports["babylonjs-procedural-textures"]=r(require("babylonjs")):e.PROCEDURALTEXTURES=r(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(function(e){return function(e){var r={};function t(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,t),n.l=!0,n.exports}return t.m=e,t.c=r,t.d=function(e,r,o){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)t.d(o,n,function(r){return e[r]}.bind(null,n));return o},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=17)}({0:function(r,t){r.exports=e},1:function(e,r,t){"use strict";t.d(r,"b",(function(){return n})),t.d(r,"a",(function(){return i}));
  2. /*! *****************************************************************************
  3. Copyright (c) Microsoft Corporation.
  4. Permission to use, copy, modify, and/or distribute this software for any
  5. purpose with or without fee is hereby granted.
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  7. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  8. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  9. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  10. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  11. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  12. PERFORMANCE OF THIS SOFTWARE.
  13. ***************************************************************************** */
  14. var o=function(e,r){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)r.hasOwnProperty(t)&&(e[t]=r[t])})(e,r)};function n(e,r){function t(){this.constructor=e}o(e,r),e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)}function i(e,r,t,o){var n,i=arguments.length,l=i<3?r:null===o?o=Object.getOwnPropertyDescriptor(r,t):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,r,t,o);else for(var c=e.length-1;c>=0;c--)(n=e[c])&&(l=(i<3?n(l):i>3?n(r,t,l):n(r,t))||l);return i>3&&l&&Object.defineProperty(r,t,l),l}Object.create;Object.create},17:function(e,r,t){"use strict";t.r(r),function(e){var o=t(6);t.d(r,"FireProceduralTexture",(function(){return o.FireProceduralTexture}));var n=void 0!==e?e:"undefined"!=typeof window?window:void 0;if(void 0!==n)for(var i in o)n.BABYLON[i]=o[i]}.call(this,t(2))},2:function(e,r){var t;t=function(){return this}();try{t=t||new Function("return this")()}catch(e){"object"==typeof window&&(t=window)}e.exports=t},6:function(e,r,t){"use strict";t.r(r),t.d(r,"FireProceduralTexture",(function(){return l}));var o=t(1),n=t(0),i="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}";n.Effect.ShadersStore.fireProceduralTexturePixelShader=i;var l=function(e){function r(t,o,i,l,c){var u=e.call(this,t,o,"fireProceduralTexture",i,l,c)||this;return u._time=0,u._speed=new n.Vector2(.5,.3),u._autoGenerateTime=!0,u._alphaThreshold=.5,u._fireColors=r.RedFireColors,u.updateShaderUniforms(),u}return Object(o.b)(r,e),r.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)},r.prototype.render=function(r){var t=this.getScene();this._autoGenerateTime&&t&&(this._time+=.03*t.getAnimationRatio(),this.updateShaderUniforms()),e.prototype.render.call(this,r)},Object.defineProperty(r,"PurpleFireColors",{get:function(){return[new n.Color3(.5,0,1),new n.Color3(.9,0,1),new n.Color3(.2,0,1),new n.Color3(1,.9,1),new n.Color3(.1,.1,1),new n.Color3(.9,.9,1)]},enumerable:!1,configurable:!0}),Object.defineProperty(r,"GreenFireColors",{get:function(){return[new n.Color3(.5,1,0),new n.Color3(.5,1,0),new n.Color3(.3,.4,0),new n.Color3(.5,1,0),new n.Color3(.2,0,0),new n.Color3(.5,1,0)]},enumerable:!1,configurable:!0}),Object.defineProperty(r,"RedFireColors",{get:function(){return[new n.Color3(.5,0,.1),new n.Color3(.9,0,0),new n.Color3(.2,0,0),new n.Color3(1,.9,0),new n.Color3(.1,.1,.1),new n.Color3(.9,.9,.9)]},enumerable:!1,configurable:!0}),Object.defineProperty(r,"BlueFireColors",{get:function(){return[new n.Color3(.1,0,.5),new n.Color3(0,0,.5),new n.Color3(.1,0,.2),new n.Color3(0,0,1),new n.Color3(.1,.2,.3),new n.Color3(0,.2,.9)]},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"autoGenerateTime",{get:function(){return this._autoGenerateTime},set:function(e){this._autoGenerateTime=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"fireColors",{get:function(){return this._fireColors},set:function(e){this._fireColors=e,this.updateShaderUniforms()},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"time",{get:function(){return this._time},set:function(e){this._time=e,this.updateShaderUniforms()},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"speed",{get:function(){return this._speed},set:function(e){this._speed=e,this.updateShaderUniforms()},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"alphaThreshold",{get:function(){return this._alphaThreshold},set:function(e){this._alphaThreshold=e,this.updateShaderUniforms()},enumerable:!1,configurable:!0}),r.prototype.serialize=function(){var r=n.SerializationHelper.Serialize(this,e.prototype.serialize.call(this));r.customType="BABYLON.FireProceduralTexture",r.fireColors=[];for(var t=0;t<this._fireColors.length;t++)r.fireColors.push(this._fireColors[t].asArray());return r},r.Parse=function(e,t,o){for(var i=n.SerializationHelper.Parse((function(){return new r(e.name,e._size,t,void 0,e._generateMipMaps)}),e,t,o),l=[],c=0;c<e.fireColors.length;c++)l.push(n.Color3.FromArray(e.fireColors[c]));return i.fireColors=l,i},Object(o.a)([Object(n.serialize)()],r.prototype,"autoGenerateTime",null),Object(o.a)([Object(n.serialize)()],r.prototype,"time",null),Object(o.a)([Object(n.serializeAsVector2)()],r.prototype,"speed",null),Object(o.a)([Object(n.serialize)()],r.prototype,"alphaThreshold",null),r}(n.ProceduralTexture);n._TypeStore.RegisteredTypes["BABYLON.FireProceduralTexture"]=l}})}));