!(function(e,r){var t=[],o=e.BABYLON||this.BABYLON;"object"==typeof exports&&"object"==typeof module?(o=o||require("babylonjs"),module.exports=r(o)):"function"==typeof define&&define.amd?(t.push("babylonjs"),define("babylonjs-procedural-textures",t,r)):"object"==typeof exports?(o=o||require("babylonjs"),exports["babylonjs-procedural-textures"]=r(o)):e.BABYLON=r(o)})(this,(function(e){e=e||this.BABYLON;var o,l,r,s,t,u,n,c,i,f,a,p,d,h,m,v,b,y,g,x,C,_=this&&this.__decorate||function(e,r,t,o){var n,i=arguments.length,a=i<3?r:null===o?o=Object.getOwnPropertyDescriptor(r,t):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,r,t,o);else for(var l=e.length-1;0<=l;l--)(n=e[l])&&(a=(i<3?n(a):3nyi-jointHPercentage){\ncolor=mix(jointColor,vec3(0.37,0.25,0.25),(yi-nyi)/jointHPercentage+0.2);\n}\nelse if (xinxi-jointWPercentage){\ncolor=mix(jointColor,vec3(0.44,0.44,0.44),(xi-nxi)/jointWPercentage+0.2);\n}\nelse {\nfloat brickColorSwitch=mod(floor(yi)+floor(xi),3.0);\nif (brickColorSwitch == 0.0)\ncolor=mix(color,vec3(0.33,0.33,0.33),0.3);\nelse if (brickColorSwitch == 2.0)\ncolor=mix(color,vec3(0.11,0.11,0.11),0.3);\n}\ngl_FragColor=vec4(color,1.0);\n}",h=e||(e={}),m=(function(a){function o(e,r,t,o,n){var i=a.call(this,e,r,"marbleProceduralTexture",t,o,n)||this;return i._numberOfTilesHeight=3,i._numberOfTilesWidth=3,i._amplitude=9,i._jointColor=new h.Color3(.72,.72,.72),i.updateShaderUniforms(),i}return P(o,a),o.prototype.updateShaderUniforms=function(){this.setFloat("numberOfTilesHeight",this._numberOfTilesHeight),this.setFloat("numberOfTilesWidth",this._numberOfTilesWidth),this.setFloat("amplitude",this._amplitude),this.setColor3("jointColor",this._jointColor)},Object.defineProperty(o.prototype,"numberOfTilesHeight",{get:function(){return this._numberOfTilesHeight},set:function(e){this._numberOfTilesHeight=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"amplitude",{get:function(){return this._amplitude},set:function(e){this._amplitude=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"numberOfTilesWidth",{get:function(){return this._numberOfTilesWidth},set:function(e){this._numberOfTilesWidth=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"jointColor",{get:function(){return this._jointColor},set:function(e){this._jointColor=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),o.prototype.serialize=function(){var e=h.SerializationHelper.Serialize(this,a.prototype.serialize.call(this));return e.customType="BABYLON.MarbleProceduralTexture",e},o.Parse=function(e,r,t){return h.SerializationHelper.Parse((function(){return new o(e.name,e._size,r,void 0,e._generateMipMaps)}),e,r,t)},_([h.serialize()],o.prototype,"numberOfTilesHeight",null),_([h.serialize()],o.prototype,"amplitude",null),_([h.serialize()],o.prototype,"numberOfTilesWidth",null),_([h.serialize()],o.prototype,"jointColor",null),o})(h.ProceduralTexture),h.MarbleProceduralTexture=m,e.Effect.ShadersStore.marbleProceduralTexturePixelShader="precision highp float;\nvarying vec2 vPosition;\nvarying vec2 vUV;\nuniform float numberOfTilesHeight;\nuniform float numberOfTilesWidth;\nuniform float amplitude;\nuniform vec3 marbleColor;\nuniform vec3 jointColor;\nconst vec3 tileSize=vec3(1.1,1.0,1.1);\nconst vec3 tilePct=vec3(0.98,1.0,0.98);\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 turbulence(vec2 P)\n{\nfloat val=0.0;\nfloat freq=1.0;\nfor (int i=0; i<4; i++)\n{\nval+=abs(noise(P*freq)/freq);\nfreq*=2.07;\n}\nreturn val;\n}\nfloat roundF(float number){\nreturn sign(number)*floor(abs(number)+0.5);\n}\nvec3 marble_color(float x)\n{\nvec3 col;\nx=0.5*(x+1.);\nx=sqrt(x); \nx=sqrt(x);\nx=sqrt(x);\ncol=vec3(.2+.75*x); \ncol.b*=0.95; \nreturn col;\n}\nvoid main()\n{\nfloat brickW=1.0/numberOfTilesWidth;\nfloat brickH=1.0/numberOfTilesHeight;\nfloat jointWPercentage=0.01;\nfloat jointHPercentage=0.01;\nvec3 color=marbleColor;\nfloat yi=vUV.y/brickH;\nfloat nyi=roundF(yi);\nfloat xi=vUV.x/brickW;\nif (mod(floor(yi),2.0) == 0.0){\nxi=xi-0.5;\n}\nfloat nxi=roundF(xi);\nvec2 brickvUV=vec2((xi-floor(xi))/brickH,(yi-floor(yi))/brickW);\nif (yinyi-jointHPercentage){\ncolor=mix(jointColor,vec3(0.37,0.25,0.25),(yi-nyi)/jointHPercentage+0.2);\n}\nelse if (xinxi-jointWPercentage){\ncolor=mix(jointColor,vec3(0.44,0.44,0.44),(xi-nxi)/jointWPercentage+0.2);\n}\nelse {\nfloat t=6.28*brickvUV.x/(tileSize.x+noise(vec2(vUV)*6.0));\nt+=amplitude*turbulence(brickvUV.xy);\nt=sin(t);\ncolor=marble_color(t);\n}\ngl_FragColor=vec4(color,0.0);\n}",v=e||(e={}),b=(function(a){function o(e,r,t,o,n){var i=a.call(this,e,r,"starfieldProceduralTexture",t,o,n)||this;return i._time=1,i._alpha=.5,i._beta=.8,i._zoom=.8,i._formuparam=.53,i._stepsize=.1,i._tile=.85,i._brightness=.0015,i._darkmatter=.4,i._distfading=.73,i._saturation=.85,i.updateShaderUniforms(),i}return P(o,a),o.prototype.updateShaderUniforms=function(){this.setFloat("time",this._time),this.setFloat("alpha",this._alpha),this.setFloat("beta",this._beta),this.setFloat("zoom",this._zoom),this.setFloat("formuparam",this._formuparam),this.setFloat("stepsize",this._stepsize),this.setFloat("tile",this._tile),this.setFloat("brightness",this._brightness),this.setFloat("darkmatter",this._darkmatter),this.setFloat("distfading",this._distfading),this.setFloat("saturation",this._saturation)},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,"alpha",{get:function(){return this._alpha},set:function(e){this._alpha=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"beta",{get:function(){return this._beta},set:function(e){this._beta=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"formuparam",{get:function(){return this._formuparam},set:function(e){this._formuparam=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"stepsize",{get:function(){return this._stepsize},set:function(e){this._stepsize=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"zoom",{get:function(){return this._zoom},set:function(e){this._zoom=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"tile",{get:function(){return this._tile},set:function(e){this._tile=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"brightness",{get:function(){return this._brightness},set:function(e){this._brightness=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"darkmatter",{get:function(){return this._darkmatter},set:function(e){this._darkmatter=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"distfading",{get:function(){return this._distfading},set:function(e){this._distfading=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"saturation",{get:function(){return this._saturation},set:function(e){this._saturation=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),o.prototype.serialize=function(){var e=v.SerializationHelper.Serialize(this,a.prototype.serialize.call(this));return e.customType="BABYLON.StarfieldProceduralTexture",e},o.Parse=function(e,r,t){return v.SerializationHelper.Parse((function(){return new o(e.name,e._size,r,void 0,e._generateMipMaps)}),e,r,t)},_([v.serialize()],o.prototype,"time",null),_([v.serialize()],o.prototype,"alpha",null),_([v.serialize()],o.prototype,"beta",null),_([v.serialize()],o.prototype,"formuparam",null),_([v.serialize()],o.prototype,"stepsize",null),_([v.serialize()],o.prototype,"zoom",null),_([v.serialize()],o.prototype,"tile",null),_([v.serialize()],o.prototype,"brightness",null),_([v.serialize()],o.prototype,"darkmatter",null),_([v.serialize()],o.prototype,"distfading",null),_([v.serialize()],o.prototype,"saturation",null),o})(v.ProceduralTexture),v.StarfieldProceduralTexture=b,e.Effect.ShadersStore.starfieldProceduralTexturePixelShader="precision highp float;\n\n#define volsteps 20\n#define iterations 15\nvarying vec2 vPosition;\nvarying vec2 vUV;\nuniform float time;\nuniform float alpha;\nuniform float beta;\nuniform float zoom;\nuniform float formuparam;\nuniform float stepsize;\nuniform float tile;\nuniform float brightness;\nuniform float darkmatter;\nuniform float distfading;\nuniform float saturation;\nvoid main()\n{\nvec3 dir=vec3(vUV*zoom,1.);\nfloat localTime=time*0.0001;\n\nmat2 rot1=mat2(cos(alpha),sin(alpha),-sin(alpha),cos(alpha));\nmat2 rot2=mat2(cos(beta),sin(beta),-sin(beta),cos(beta));\ndir.xz*=rot1;\ndir.xy*=rot2;\nvec3 from=vec3(1.,.5,0.5);\nfrom+=vec3(-2.,localTime*2.,localTime);\nfrom.xz*=rot1;\nfrom.xy*=rot2;\n\nfloat s=0.1,fade=1.;\nvec3 v=vec3(0.);\nfor (int r=0; r6) fade*=1.-dm; \n\nv+=fade;\nv+=vec3(s,s*s,s*s*s*s)*a*brightness*fade; \nfade*=distfading; \ns+=stepsize;\n}\nv=mix(vec3(length(v)),v,saturation); \ngl_FragColor=vec4(v*.01,1.);\n}",y=e||(e={}),g=(function(a){function o(e,r,t,o,n){var i=a.call(this,e,r,"normalMapProceduralTexture",t,o,n)||this;return i.updateShaderUniforms(),i}return P(o,a),o.prototype.updateShaderUniforms=function(){this.setTexture("baseSampler",this._baseTexture),this.setFloat("size",this.getRenderSize())},o.prototype.render=function(e){a.prototype.render.call(this,e)},o.prototype.resize=function(e,r){a.prototype.resize.call(this,e,r),this.updateShaderUniforms()},Object.defineProperty(o.prototype,"baseTexture",{get:function(){return this._baseTexture},set:function(e){this._baseTexture=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),o.prototype.serialize=function(){var e=y.SerializationHelper.Serialize(this,a.prototype.serialize.call(this));return e.customType="BABYLON.NormalMapProceduralTexture",e},o.Parse=function(e,r,t){return y.SerializationHelper.Parse((function(){return new o(e.name,e._size,r,void 0,e._generateMipMaps)}),e,r,t)},_([y.serializeAsTexture()],o.prototype,"baseTexture",null),o})(y.ProceduralTexture),y.NormalMapProceduralTexture=g,e.Effect.ShadersStore.normalMapProceduralTexturePixelShader="precision highp float;\n\nuniform sampler2D baseSampler;\nuniform float size;\n\nvarying vec2 vUV;\n\nconst vec3 LUMA_COEFFICIENT=vec3(0.2126,0.7152,0.0722);\nfloat lumaAtCoord(vec2 coord)\n{\nvec3 pixel=texture2D(baseSampler,coord).rgb;\nfloat luma=dot(pixel,LUMA_COEFFICIENT);\nreturn luma;\n}\nvoid main()\n{\nfloat lumaU0=lumaAtCoord(vUV+vec2(-1.0,0.0)/size);\nfloat lumaU1=lumaAtCoord(vUV+vec2( 1.0,0.0)/size);\nfloat lumaV0=lumaAtCoord(vUV+vec2( 0.0,-1.0)/size);\nfloat lumaV1=lumaAtCoord(vUV+vec2( 0.0,1.0)/size);\nvec2 slope=(vec2(lumaU0-lumaU1,lumaV0-lumaV1)+1.0)*0.5;\ngl_FragColor=vec4(slope,1.0,1.0);\n}\n",x=e||(e={}),C=(function(a){function o(e,r,t,o,n){var i=a.call(this,e,r,"perlinNoiseProceduralTexture",t,o,n)||this;return i.time=0,i.timeScale=1,i.translationSpeed=1,i._currentTranslation=0,i.updateShaderUniforms(),i}return P(o,a),o.prototype.updateShaderUniforms=function(){this.setFloat("size",this.getRenderSize());var e=this.getScene();if(e){var r=e.getEngine().getDeltaTime();this.time+=r,this.setFloat("time",this.time*this.timeScale/1e3),this._currentTranslation+=r*this.translationSpeed/1e3,this.setFloat("translationSpeed",this._currentTranslation)}},o.prototype.render=function(e){this.updateShaderUniforms(),a.prototype.render.call(this,e)},o.prototype.resize=function(e,r){a.prototype.resize.call(this,e,r)},o.prototype.serialize=function(){var e=x.SerializationHelper.Serialize(this,a.prototype.serialize.call(this));return e.customType="BABYLON.PerlinNoiseProceduralTexture",e},o.Parse=function(e,r,t){return x.SerializationHelper.Parse((function(){return new o(e.name,e._size,r,void 0,e._generateMipMaps)}),e,r,t)},_([x.serialize()],o.prototype,"time",void 0),_([x.serialize()],o.prototype,"timeScale",void 0),_([x.serialize()],o.prototype,"translationSpeed",void 0),o})(x.ProceduralTexture),x.PerlinNoiseProceduralTexture=C,e.Effect.ShadersStore.perlinNoiseProceduralTexturePixelShader="\nprecision highp float;\n\nuniform float size;\nuniform float time;\nuniform float translationSpeed;\n\nvarying vec2 vUV;\n\nfloat r(float n)\n{\nreturn fract(cos(n*89.42)*343.42);\n}\nvec2 r(vec2 n)\n{\nreturn vec2(r(n.x*23.62-300.0+n.y*34.35),r(n.x*45.13+256.0+n.y*38.89)); \n}\nfloat worley(vec2 n,float s)\n{\nfloat dis=1.0;\nfor(int x=-1; x<=1; x++)\n{\nfor(int y=-1; y<=1; y++)\n{\nvec2 p=floor(n/s)+vec2(x,y);\nfloat d=length(r(p)+vec2(x,y)-fract(n/s));\nif (dis>d)\ndis=d;\n}\n}\nreturn 1.0-dis;\n}\nvec3 hash33(vec3 p3)\n{\np3=fract(p3*vec3(0.1031,0.11369,0.13787));\np3+=dot(p3,p3.yxz+19.19);\nreturn -1.0+2.0*fract(vec3((p3.x+p3.y)*p3.z,(p3.x+p3.z)*p3.y,(p3.y+p3.z)*p3.x));\n}\nfloat perlinNoise(vec3 p)\n{\nvec3 pi=floor(p);\nvec3 pf=p-pi;\nvec3 w=pf*pf*(3.0-2.0*pf);\nreturn mix(\nmix(\nmix(\ndot(pf-vec3(0,0,0),hash33(pi+vec3(0,0,0))),\ndot(pf-vec3(1,0,0),hash33(pi+vec3(1,0,0))),\nw.x\n),\nmix(\ndot(pf-vec3(0,0,1),hash33(pi+vec3(0,0,1))),\ndot(pf-vec3(1,0,1),hash33(pi+vec3(1,0,1))),\nw.x\n),\nw.z\n),\nmix(\nmix(\ndot(pf-vec3(0,1,0),hash33(pi+vec3(0,1,0))),\ndot(pf-vec3(1,1,0),hash33(pi+vec3(1,1,0))),\nw.x\n),\nmix(\ndot(pf-vec3(0,1,1),hash33(pi+vec3(0,1,1))),\ndot(pf-vec3(1,1,1),hash33(pi+vec3(1,1,1))),\nw.x\n),\nw.z\n),\nw.y\n);\n}\n\nvoid main(void)\n{\nvec2 uv=gl_FragCoord.xy+translationSpeed;\nfloat dis=(\n1.0+perlinNoise(vec3(uv/vec2(size,size),time*0.05)*8.0))\n*(1.0+(worley(uv,32.0)+ 0.5*worley(2.0*uv,32.0)+0.25*worley(4.0*uv,32.0))\n);\ngl_FragColor=vec4(vec3(dis/4.0),1.0);\n}\n",e}));