!(function(e,t){var i=[],r=e.CANNON||this.CANNON,n=e.OIMO||this.OIMO,o=e.earcut||this.earcut;if("object"==typeof exports&&"object"==typeof module){try{r=r||require("cannon")}catch(e){}try{n=n||require("oimo")}catch(e){}try{o=o||require("earcut")}catch(e){}module.exports=t(r,n,o)}else if("function"==typeof define&&define.amd)require.specified&&require.specified("cannon")&&i.push("cannon"),require.specified&&require.specified("oimo")&&i.push("oimo"),require.specified&&require.specified("earcut")&&i.push("earcut"),define("babylonjs",i,t);else if("object"==typeof exports){try{r=r||require("cannon")}catch(e){}try{n=n||require("oimo")}catch(e){}try{o=o||require("earcut")}catch(e){}exports.babylonjs=t(r,n,o)}else e.BABYLON=t(r,n,o)})(this,(function(i,t,_){i=i||this.CANNON,t=t||this.OIMO,_=_||this.earcut;var r,e,n,o,s,a,l,c,h,u,d,f,p,m,g,v,b=this&&this.__decorate||function(e,t,i,r){var n,o=arguments.length,s=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,r);else for(var a=e.length-1;0<=a;a--)(n=e[a])&&(s=(o<3?n(s):3this._maxRank&&(this._maxRank=e),this._defines[e]=new Array),this._defines[e].push(t)},e.prototype.addCPUSkinningFallback=function(e,t){this._mesh=t,ethis._maxRank&&(this._maxRank=e)},Object.defineProperty(e.prototype,"isMoreFallbacks",{get:function(){return this._currentRank<=this._maxRank},enumerable:!0,configurable:!0}),e.prototype.reduce=function(e,t){if(this._mesh&&this._mesh.computeBonesUsingShaders&&0(\((.*)\))*(\[(.*)\])*/g,n=r.exec(e),o=new String(e);null!=n;){var s=n[1];if(-1!==s.indexOf("__decl__")&&(s=s.replace(/__decl__/,""),this._engine.supportsUniformBuffers&&(s=(s=s.replace(/Vertex/,"Ubo")).replace(/Fragment/,"Ubo")),s+="Declaration"),!y.IncludesShadersStore[s]){var a=b.Engine.ShadersRepository+"ShadersInclude/"+s+".fx";return void this._engine._loadFile(a,(function(e){y.IncludesShadersStore[s]=e,i._processIncludes(o,t)}))}var l=y.IncludesShadersStore[s];if(n[2])for(var c=n[3].split(","),h=0;hi.x?i.x:r)i.y?i.y:n)t.x?e.x:t.x,e.y>t.y?e.y:t.y)},u.Transform=function(e,t){var i=u.Zero();return u.TransformToRef(e,t,i),i},u.TransformToRef=function(e,t,i){var r=e.x*t.m[0]+e.y*t.m[4]+t.m[12],n=e.x*t.m[1]+e.y*t.m[5]+t.m[13];i.x=r,i.y=n},u.PointInTriangle=function(e,t,i,r){var n=.5*(-i.y*r.x+t.y*(-i.x+r.x)+t.x*(i.y-r.y)+i.x*r.y),o=n<0?-1:1,s=(t.y*r.x-t.x*r.y+(r.y-t.y)*e.x+(t.x-r.x)*e.y)*o,a=(t.x*i.y-t.y*i.x+(t.y-i.y)*e.x+(i.x-t.x)*e.y)*o;return 0this.x&&(this.x=e),t>this.y&&(this.y=t),i>this.z&&(this.z=i),this},Object.defineProperty(d.prototype,"isNonUniform",{get:function(){var e=Math.abs(this.x),t=Math.abs(this.y);if(e!==t)return!0;var i=Math.abs(this.z);return e!==i||t!==i},enumerable:!0,configurable:!0}),d.prototype.floor=function(){return new d(Math.floor(this.x),Math.floor(this.y),Math.floor(this.z))},d.prototype.fract=function(){return new d(this.x-Math.floor(this.x),this.y-Math.floor(this.y),this.z-Math.floor(this.z))},d.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},d.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},d.prototype.normalize=function(){var e=this.length();if(0===e||1===e)return this;var t=1/e;return this.x*=t,this.y*=t,this.z*=t,this},d.prototype.normalizeToNew=function(){var e=new d(0,0,0);return this.normalizeToRef(e),e},d.prototype.normalizeToRef=function(e){var t=this.length();if(0===t||1===t)return e.set(this.x,this.y,this.z),e;var i=1/t;return this.scaleToRef(i,e),e},d.prototype.clone=function(){return new d(this.x,this.y,this.z)},d.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this},d.prototype.copyFromFloats=function(e,t,i){return this.x=e,this.y=t,this.z=i,this},d.prototype.set=function(e,t,i){return this.copyFromFloats(e,t,i)},d.GetClipFactor=function(e,t,i,r){var n=d.Dot(e,i)-r;return n/(n-(d.Dot(t,i)-r))},d.GetAngleBetweenVectors=function(e,t,i){var r=P.Vector3[1].copyFrom(e).normalize(),n=P.Vector3[2].copyFrom(t).normalize(),o=d.Dot(r,n),s=P.Vector3[3];return d.CrossToRef(r,n,s),0i.x?i.x:r)i.y?i.y:n)i.z?i.z:o)this.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),e.w>this.w&&(this.w=e.w),this},n.prototype.floor=function(){return new n(Math.floor(this.x),Math.floor(this.y),Math.floor(this.z),Math.floor(this.w))},n.prototype.fract=function(){return new n(this.x-Math.floor(this.x),this.y-Math.floor(this.y),this.z-Math.floor(this.z),this.w-Math.floor(this.w))},n.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},n.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},n.prototype.normalize=function(){var e=this.length();if(0===e)return this;var t=1/e;return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},n.prototype.toVector3=function(){return new m(this.x,this.y,this.z)},n.prototype.clone=function(){return new n(this.x,this.y,this.z,this.w)},n.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},n.prototype.copyFromFloats=function(e,t,i,r){return this.x=e,this.y=t,this.z=i,this.w=r,this},n.prototype.set=function(e,t,i,r){return this.copyFromFloats(e,t,i,r)},n.FromArray=function(e,t){return t||(t=0),new n(e[t],e[t+1],e[t+2],e[t+3])},n.FromArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1],i.z=e[t+2],i.w=e[t+3]},n.FromFloatArrayToRef=function(e,t,i){n.FromArrayToRef(e,t,i)},n.FromFloatsToRef=function(e,t,i,r,n){n.x=e,n.y=t,n.z=i,n.w=r},n.Zero=function(){return new n(0,0,0,0)},n.One=function(){return new n(1,1,1,1)},n.Normalize=function(e){var t=n.Zero();return n.NormalizeToRef(e,t),t},n.NormalizeToRef=function(e,t){t.copyFrom(e),t.normalize()},n.Minimize=function(e,t){var i=e.clone();return i.minimizeInPlace(t),i},n.Maximize=function(e,t){var i=e.clone();return i.maximizeInPlace(t),i},n.Distance=function(e,t){return Math.sqrt(n.DistanceSquared(e,t))},n.DistanceSquared=function(e,t){var i=e.x-t.x,r=e.y-t.y,n=e.z-t.z,o=e.w-t.w;return i*i+r*r+n*n+o*o},n.Center=function(e,t){var i=e.add(t);return i.scaleInPlace(.5),i},n.TransformNormal=function(e,t){var i=n.Zero();return n.TransformNormalToRef(e,t,i),i},n.TransformNormalToRef=function(e,t,i){var r=e.x*t.m[0]+e.y*t.m[4]+e.z*t.m[8],n=e.x*t.m[1]+e.y*t.m[5]+e.z*t.m[9],o=e.x*t.m[2]+e.y*t.m[6]+e.z*t.m[10];i.x=r,i.y=n,i.z=o,i.w=e.w},n.TransformNormalFromFloatsToRef=function(e,t,i,r,n,o){o.x=e*n.m[0]+t*n.m[4]+i*n.m[8],o.y=e*n.m[1]+t*n.m[5]+i*n.m[9],o.z=e*n.m[2]+t*n.m[6]+i*n.m[10],o.w=r},n})();f.Vector4=r;var e=(function(){function r(e,t){this.width=e,this.height=t}return r.prototype.toString=function(){return"{W: "+this.width+", H: "+this.height+"}"},r.prototype.getClassName=function(){return"Size"},r.prototype.getHashCode=function(){var e=this.width||0;return e=397*e^(this.height||0)},r.prototype.copyFrom=function(e){this.width=e.width,this.height=e.height},r.prototype.copyFromFloats=function(e,t){return this.width=e,this.height=t,this},r.prototype.set=function(e,t){return this.copyFromFloats(e,t)},r.prototype.multiplyByFloats=function(e,t){return new r(this.width*e,this.height*t)},r.prototype.clone=function(){return new r(this.width,this.height)},r.prototype.equals=function(e){return!!e&&(this.width===e.width&&this.height===e.height)},Object.defineProperty(r.prototype,"surface",{get:function(){return this.width*this.height},enumerable:!0,configurable:!0}),r.Zero=function(){return new r(0,0)},r.prototype.add=function(e){return new r(this.width+e.width,this.height+e.height)},r.prototype.subtract=function(e){return new r(this.width-e.width,this.height-e.height)},r.Lerp=function(e,t,i){return new r(e.width+(t.width-e.width)*i,e.height+(t.height-e.height)*i)},r})();f.Size=e;var _=(function(){function u(e,t,i,r){void 0===e&&(e=0),void 0===t&&(t=0),void 0===i&&(i=0),void 0===r&&(r=1),this.x=e,this.y=t,this.z=i,this.w=r}return u.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+" W:"+this.w+"}"},u.prototype.getClassName=function(){return"Quaternion"},u.prototype.getHashCode=function(){var e=this.x||0;return e=397*(e=397*(e=397*e^(this.y||0))^(this.z||0))^(this.w||0)},u.prototype.asArray=function(){return[this.x,this.y,this.z,this.w]},u.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w},u.prototype.clone=function(){return new u(this.x,this.y,this.z,this.w)},u.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},u.prototype.copyFromFloats=function(e,t,i,r){return this.x=e,this.y=t,this.z=i,this.w=r,this},u.prototype.set=function(e,t,i,r){return this.copyFromFloats(e,t,i,r)},u.prototype.add=function(e){return new u(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)},u.prototype.addInPlace=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this},u.prototype.subtract=function(e){return new u(this.x-e.x,this.y-e.y,this.z-e.z,this.w-e.w)},u.prototype.scale=function(e){return new u(this.x*e,this.y*e,this.z*e,this.w*e)},u.prototype.scaleToRef=function(e,t){return t.x=this.x*e,t.y=this.y*e,t.z=this.z*e,t.w=this.w*e,this},u.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this},u.prototype.scaleAndAddToRef=function(e,t){return t.x+=this.x*e,t.y+=this.y*e,t.z+=this.z*e,t.w+=this.w*e,this},u.prototype.multiply=function(e){var t=new u(0,0,0,1);return this.multiplyToRef(e,t),t},u.prototype.multiplyToRef=function(e,t){var i=this.x*e.w+this.y*e.z-this.z*e.y+this.w*e.x,r=-this.x*e.z+this.y*e.w+this.z*e.x+this.w*e.y,n=this.x*e.y-this.y*e.x+this.z*e.w+this.w*e.z,o=-this.x*e.x-this.y*e.y-this.z*e.z+this.w*e.w;return t.copyFromFloats(i,r,n,o),this},u.prototype.multiplyInPlace=function(e){return this.multiplyToRef(e,this),this},u.prototype.conjugateToRef=function(e){return e.copyFromFloats(-this.x,-this.y,-this.z,this.w),this},u.prototype.conjugateInPlace=function(){return this.x*=-1,this.y*=-1,this.z*=-1,this},u.prototype.conjugate=function(){return new u(-this.x,-this.y,-this.z,this.w)},u.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},u.prototype.normalize=function(){var e=1/this.length();return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this},u.prototype.toEulerAngles=function(e){void 0===e&&(e="YZX");var t=m.Zero();return this.toEulerAnglesToRef(t,e),t},u.prototype.toEulerAnglesToRef=function(e,t){void 0===t&&(t="YZX");var i=this.z,r=this.x,n=this.y,o=this.w,s=o*o,a=i*i,l=r*r,c=n*n,h=n*i-r*o;return h<-.4999999?(e.y=2*Math.atan2(n,o),e.x=Math.PI/2,e.z=0):.4999999this.data.length&&(this.data.length*=2)},t.prototype.forEach=function(e){for(var t=0;tthis.data.length&&(this.data.length=2*(this.length+e.length));for(var t=0;t=this.length?-1:t},t.prototype.contains=function(e){return-1!==this.indexOf(e)},t._GlobalId=0,t})(),c=(function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._duplicateId=0,e}return T(e,t),e.prototype.push=function(e){t.prototype.push.call(this,e),e.__smartArrayFlags||(e.__smartArrayFlags={}),e.__smartArrayFlags[this._id]=this._duplicateId},e.prototype.pushNoDuplicate=function(e){return(!e.__smartArrayFlags||e.__smartArrayFlags[this._id]!==this._duplicateId)&&(this.push(e),!0)},e.prototype.reset=function(){t.prototype.reset.call(this),this._duplicateId++},e.prototype.concatWithNoDuplicate=function(e){if(0!==e.length){this.length+e.length>this.data.length&&(this.data.length=2*(this.length+e.length));for(var t=0;t>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,++e},_.FloorPOT=function(e){return e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,(e|=e>>16)-(e>>1)},_.NearestPOT=function(e){var t=_.CeilingPOT(e),i=_.FloorPOT(e);return e-i>2,o=(3&t)<<4|(i=h>4,s=(15&i)<<2|(r=h>6,a=63&r,isNaN(i)?s=a=64:isNaN(r)&&(a=64),c+=l.charAt(n)+l.charAt(o)+l.charAt(s)+l.charAt(a);return"data:image/png;base64,"+c},_.ExtractMinAndMaxIndexed=function(e,t,i,r,n){void 0===n&&(n=null);for(var o=new m.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),s=new m.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),a=i;ai.x&&(i.x=e.x),e.y>i.y&&(i.y=e.y),e.z>i.z&&(i.z=e.z)},_.DeepCopy=function(e,t,i,r){for(var n in e)if(("_"!==n[0]||r&&-1!==r.indexOf(n))&&(!i||-1===i.indexOf(n))){var o=e[n],s=typeof o;if("function"!==s)try{if("object"===s)if(o instanceof Array){if(t[n]=[],0"+t+"
")},_._WarnDisabled=function(e){},_._WarnEnabled=function(e){var t=_._FormatMessage(e);console.warn("BJS - "+t),_._AddLogEntry("
"+t+"

")},_._ErrorDisabled=function(e){},_._ErrorEnabled=function(e){_.errorsCount++;var t=_._FormatMessage(e);console.error("BJS - "+t),_._AddLogEntry("
"+t+"

")},Object.defineProperty(_,"LogCache",{get:function(){return _._LogCache},enumerable:!0,configurable:!0}),_.ClearLogCache=function(){_._LogCache="",_.errorsCount=0},Object.defineProperty(_,"LogLevels",{set:function(e){_.Log=(e&_.MessageLogLevel)===_.MessageLogLevel?_._LogEnabled:_._LogDisabled,_.Warn=(e&_.WarningLogLevel)===_.WarningLogLevel?_._WarnEnabled:_._WarnDisabled,_.Error=(e&_.ErrorLogLevel)===_.ErrorLogLevel?_._ErrorEnabled:_._ErrorDisabled},enumerable:!0,configurable:!0}),_.IsFileURL=function(){return"file:"===location.protocol},_.IsWindowObjectExist=function(){return"undefined"!=typeof window},Object.defineProperty(_,"PerformanceLogLevel",{set:function(e){return(e&_.PerformanceUserMarkLogLevel)===_.PerformanceUserMarkLogLevel?(_.StartPerformanceCounter=_._StartUserMark,void(_.EndPerformanceCounter=_._EndUserMark)):(e&_.PerformanceConsoleLogLevel)===_.PerformanceConsoleLogLevel?(_.StartPerformanceCounter=_._StartPerformanceConsole,void(_.EndPerformanceCounter=_._EndPerformanceConsole)):(_.StartPerformanceCounter=_._StartPerformanceCounterDisabled,void(_.EndPerformanceCounter=_._EndPerformanceCounterDisabled))},enumerable:!0,configurable:!0}),_._StartPerformanceCounterDisabled=function(e,t){},_._EndPerformanceCounterDisabled=function(e,t){},_._StartUserMark=function(e,t){if(void 0===t&&(t=!0),!_._performance){if(!_.IsWindowObjectExist())return;_._performance=window.performance}t&&_._performance.mark&&_._performance.mark(e+"-Begin")},_._EndUserMark=function(e,t){void 0===t&&(t=!0),t&&_._performance.mark&&(_._performance.mark(e+"-End"),_._performance.measure(e,e+"-Begin",e+"-End"))},_._StartPerformanceConsole=function(e,t){void 0===t&&(t=!0),t&&(_._StartUserMark(e,t),console.time&&console.time(e))},_._EndPerformanceConsole=function(e,t){void 0===t&&(t=!0),t&&(_._EndUserMark(e,t),console.time&&console.timeEnd(e))},Object.defineProperty(_,"Now",{get:function(){return _.IsWindowObjectExist()&&window.performance&&window.performance.now?window.performance.now():Date.now()},enumerable:!0,configurable:!0}),_.GetClassName=function(e,t){void 0===t&&(t=!1);var i=null;if(!t&&e.getClassName)i=e.getClassName();else{if(e instanceof Object)i=(t?e:Object.getPrototypeOf(e)).constructor.__bjsclassName__;i||(i=typeof e)}return i},_.First=function(e,t){for(var i=0,r=e;i=n.gradient&&e<=o.gradient)return void i(n,o,(e-n.gradient)/(o.gradient-n.gradient))}var s=t.length-1;i(t[s],t[s],1)},_.BaseUrl="",_.DefaultRetryStrategy=r.ExponentialBackoff(),_.CorsBehavior="anonymous",_.UseFallbackTexture=!0,_.RegisteredExternalClasses={},_.fallbackTexture="data:image/jpg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QBmRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUAAAABAAAARgEoAAMAAAABAAIAAAExAAIAAAAQAAAATgAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQubmV0IDQuMC41AP/bAEMABAIDAwMCBAMDAwQEBAQFCQYFBQUFCwgIBgkNCw0NDQsMDA4QFBEODxMPDAwSGBITFRYXFxcOERkbGRYaFBYXFv/bAEMBBAQEBQUFCgYGChYPDA8WFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFv/AABEIAQABAAMBIgACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEAAhEDEQA/APH6KKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76CiiigD5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BQooooA+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/voKKKKAPl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76CiiigD5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BQooooA+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/voKKKKAPl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76P//Z",_._tmpFloatArray=new Float32Array(1),_.PreprocessUrl=function(e){return e},_.NoneLogLevel=0,_.MessageLogLevel=1,_.WarningLogLevel=2,_.ErrorLogLevel=4,_.AllLogLevel=7,_._LogCache="",_.errorsCount=0,_.Log=_._LogEnabled,_.Warn=_._WarnEnabled,_.Error=_._ErrorEnabled,_.PerformanceNoneLogLevel=0,_.PerformanceUserMarkLogLevel=1,_.PerformanceConsoleLogLevel=2,_.StartPerformanceCounter=_._StartPerformanceCounterDisabled,_.EndPerformanceCounter=_._EndPerformanceCounterDisabled,_})();m.Tools=n;var o=(function(){function i(){this._startMonitoringTime=0,this._min=0,this._max=0,this._average=0,this._lastSecAverage=0,this._current=0,this._totalValueCount=0,this._totalAccumulated=0,this._lastSecAccumulated=0,this._lastSecTime=0,this._lastSecValueCount=0}return Object.defineProperty(i.prototype,"min",{get:function(){return this._min},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"max",{get:function(){return this._max},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"average",{get:function(){return this._average},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"lastSecAverage",{get:function(){return this._lastSecAverage},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"current",{get:function(){return this._current},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"total",{get:function(){return this._totalAccumulated},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"count",{get:function(){return this._totalValueCount},enumerable:!0,configurable:!0}),i.prototype.fetchNewFrame=function(){this._totalValueCount++,this._current=0,this._lastSecValueCount++},i.prototype.addCount=function(e,t){i.Enabled&&(this._current+=e,t&&this._fetchResult())},i.prototype.beginMonitoring=function(){i.Enabled&&(this._startMonitoringTime=n.Now)},i.prototype.endMonitoring=function(e){if(void 0===e&&(e=!0),i.Enabled){e&&this.fetchNewFrame();var t=n.Now;this._current=t-this._startMonitoringTime,e&&this._fetchResult()}},i.prototype._fetchResult=function(){this._totalAccumulated+=this._current,this._lastSecAccumulated+=this._current,this._min=Math.min(this._min,this._current),this._max=Math.max(this._max,this._current),this._average=this._totalAccumulated/this._totalValueCount;var e=n.Now;1e3s||l.height>s)return u._prepareWorkingCanvas(),u._workingCanvas&&u._workingContext&&(u._workingCanvas.width=e,u._workingCanvas.height=t,u._workingContext.drawImage(l,0,0,l.width,l.height,0,0,e,t),r.texImage2D(r.TEXTURE_2D,0,o,o,r.UNSIGNED_BYTE,u._workingCanvas),_.width=e,_.height=t),!1;var a=new M.InternalTexture(u,M.InternalTexture.DATASOURCE_TEMP);return u._bindTextureDirectly(r.TEXTURE_2D,a,!0),r.texImage2D(r.TEXTURE_2D,0,o,o,r.UNSIGNED_BYTE,l),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),u._rescaleTexture(a,_,c,o,(function(){u._releaseTexture(a),u._bindTextureDirectly(r.TEXTURE_2D,_,!0),i()})),!0}),s)};!f||m?l instanceof HTMLImageElement?S(l):M.Tools.LoadImage(d,S,A,c?c.database:null):"string"==typeof l||l instanceof ArrayBuffer||l instanceof Blob?M.Tools.LoadImage(l,S,A,c?c.database:null):S(l)}return _},R.prototype._rescaleTexture=function(t,i,r,n,o){var s=this,a=this.createRenderTargetTexture({width:i.width,height:i.height},{generateMipMaps:!1,type:R.TEXTURETYPE_UNSIGNED_INT,samplingMode:R.TEXTURE_BILINEAR_SAMPLINGMODE,generateDepthBuffer:!1,generateStencilBuffer:!1});this._rescalePostProcess||(this._rescalePostProcess=new M.PassPostProcess("rescale",1,null,R.TEXTURE_BILINEAR_SAMPLINGMODE,this,!1,R.TEXTURETYPE_UNSIGNED_INT)),this._rescalePostProcess.getEffect().executeWhenCompiled((function(){s._rescalePostProcess.onApply=function(e){e._bindTexture("textureSampler",t)};var e=r;e||(e=s.scenes[s.scenes.length-1]),e.postProcessManager.directRender([s._rescalePostProcess],a,!0),s._bindTextureDirectly(s._gl.TEXTURE_2D,i,!0),s._gl.copyTexImage2D(s._gl.TEXTURE_2D,0,n,0,0,i.width,i.height,0),s.unBindFramebuffer(a),s._releaseTexture(a),o&&o()}))},R.prototype.updateRawTexture=function(e,t,i,r,n,o){if(void 0===n&&(n=null),void 0===o&&(o=R.TEXTURETYPE_UNSIGNED_INT),e){var s=this._getRGBABufferInternalSizedFormat(o,i),a=this._getInternalFormat(i),l=this._getWebGLTextureType(o);this._bindTextureDirectly(this._gl.TEXTURE_2D,e,!0),this._unpackFlipY(void 0===r||!!r),this._doNotHandleContextLost||(e._bufferView=t,e.format=i,e.type=o,e.invertY=r,e._compression=n),e.width%4!=0&&this._gl.pixelStorei(this._gl.UNPACK_ALIGNMENT,1),n&&t?this._gl.compressedTexImage2D(this._gl.TEXTURE_2D,0,this.getCaps().s3tc[n],e.width,e.height,0,t):this._gl.texImage2D(this._gl.TEXTURE_2D,0,s,e.width,e.height,0,a,l,t),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(this._gl.TEXTURE_2D,null),e.isReady=!0}},R.prototype.createRawTexture=function(e,t,i,r,n,o,s,a,l){void 0===a&&(a=null),void 0===l&&(l=R.TEXTURETYPE_UNSIGNED_INT);var c=new M.InternalTexture(this,M.InternalTexture.DATASOURCE_RAW);c.baseWidth=t,c.baseHeight=i,c.width=t,c.height=i,c.format=r,c.generateMipMaps=n,c.samplingMode=s,c.invertY=o,c._compression=a,c.type=l,this._doNotHandleContextLost||(c._bufferView=e),this.updateRawTexture(c,e,r,o,a,l),this._bindTextureDirectly(this._gl.TEXTURE_2D,c,!0);var h=this._getSamplingParameters(s,n);return this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,h.mag),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,h.min),n&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(this._gl.TEXTURE_2D,null),this._internalTexturesCache.push(c),c},R.prototype._unpackFlipY=function(e){this._unpackFlipYCached!==e&&(this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,e?1:0),this.enableUnpackFlipYCached&&(this._unpackFlipYCached=e))},R.prototype._getUnpackAlignement=function(){return this._gl.getParameter(this._gl.UNPACK_ALIGNMENT)},R.prototype.createDynamicTexture=function(e,t,i,r){var n=new M.InternalTexture(this,M.InternalTexture.DATASOURCE_DYNAMIC);return n.baseWidth=e,n.baseHeight=t,i&&(e=this.needPOTTextures?M.Tools.GetExponentOfTwo(e,this._caps.maxTextureSize):e,t=this.needPOTTextures?M.Tools.GetExponentOfTwo(t,this._caps.maxTextureSize):t),n.width=e,n.height=t,n.isReady=!1,n.generateMipMaps=i,n.samplingMode=r,this.updateTextureSamplingMode(r,n),this._internalTexturesCache.push(n),n},R.prototype.updateTextureSamplingMode=function(e,t){var i=this._getSamplingParameters(e,t.generateMipMaps);t.isCube?(this._setTextureParameterInteger(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_MAG_FILTER,i.mag,t),this._setTextureParameterInteger(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_MIN_FILTER,i.min),this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,null)):t.is3D?(this._setTextureParameterInteger(this._gl.TEXTURE_3D,this._gl.TEXTURE_MAG_FILTER,i.mag,t),this._setTextureParameterInteger(this._gl.TEXTURE_3D,this._gl.TEXTURE_MIN_FILTER,i.min),this._bindTextureDirectly(this._gl.TEXTURE_3D,null)):(this._setTextureParameterInteger(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,i.mag,t),this._setTextureParameterInteger(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,i.min),this._bindTextureDirectly(this._gl.TEXTURE_2D,null)),t.samplingMode=e},R.prototype.updateDynamicTexture=function(e,t,i,r,n){if(void 0===r&&(r=!1),e){this._bindTextureDirectly(this._gl.TEXTURE_2D,e,!0),this._unpackFlipY(i),r&&this._gl.pixelStorei(this._gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1);var o=n?this._getInternalFormat(n):this._gl.RGBA;this._gl.texImage2D(this._gl.TEXTURE_2D,0,o,o,this._gl.UNSIGNED_BYTE,t),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(this._gl.TEXTURE_2D,null),r&&this._gl.pixelStorei(this._gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,0),e.isReady=!0}},R.prototype.updateVideoTexture=function(t,e,i){if(t&&!t._isDisabled){var r=this._bindTextureDirectly(this._gl.TEXTURE_2D,t,!0);this._unpackFlipY(!i);try{if(void 0===this._videoTextureSupported&&(this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,e),0!==this._gl.getError()?this._videoTextureSupported=!1:this._videoTextureSupported=!0),this._videoTextureSupported)this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,e);else{if(!t._workingCanvas){t._workingCanvas=document.createElement("canvas");var n=t._workingCanvas.getContext("2d");if(!n)throw new Error("Unable to get 2d context");t._workingContext=n,t._workingCanvas.width=t.width,t._workingCanvas.height=t.height}t._workingContext.drawImage(e,0,0,e.videoWidth,e.videoHeight,0,0,t.width,t.height),this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,t._workingCanvas)}t.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),r||this._bindTextureDirectly(this._gl.TEXTURE_2D,null),t.isReady=!0}catch(e){t._isDisabled=!0}}},R.prototype.updateTextureComparisonFunction=function(e,t){if(1!==this.webGLVersion){var i=this._gl;e.isCube?(this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,e,!0),0===t?(i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_COMPARE_FUNC,R.LEQUAL),i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_COMPARE_MODE,i.NONE)):(i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_COMPARE_FUNC,t),i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_COMPARE_MODE,i.COMPARE_REF_TO_TEXTURE)),this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,null)):(this._bindTextureDirectly(this._gl.TEXTURE_2D,e,!0),0===t?(i.texParameteri(i.TEXTURE_2D,i.TEXTURE_COMPARE_FUNC,R.LEQUAL),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_COMPARE_MODE,i.NONE)):(i.texParameteri(i.TEXTURE_2D,i.TEXTURE_COMPARE_FUNC,t),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_COMPARE_MODE,i.COMPARE_REF_TO_TEXTURE)),this._bindTextureDirectly(this._gl.TEXTURE_2D,null)),e._comparisonFunction=t}else M.Tools.Error("WebGL 1 does not support texture comparison.")},R.prototype._setupDepthStencilTexture=function(e,t,i,r,n){var o=t.width||t,s=t.height||t;e.baseWidth=o,e.baseHeight=s,e.width=o,e.height=s,e.isReady=!0,e.samples=1,e.generateMipMaps=!1,e._generateDepthBuffer=!0,e._generateStencilBuffer=i,e.samplingMode=r?R.TEXTURE_BILINEAR_SAMPLINGMODE:R.TEXTURE_NEAREST_SAMPLINGMODE,e.type=R.TEXTURETYPE_UNSIGNED_INT,e._comparisonFunction=n;var a=this._gl,l=e.isCube?a.TEXTURE_CUBE_MAP:a.TEXTURE_2D,c=this._getSamplingParameters(e.samplingMode,!1);a.texParameteri(l,a.TEXTURE_MAG_FILTER,c.mag),a.texParameteri(l,a.TEXTURE_MIN_FILTER,c.min),a.texParameteri(l,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(l,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),0===n?(a.texParameteri(l,a.TEXTURE_COMPARE_FUNC,R.LEQUAL),a.texParameteri(l,a.TEXTURE_COMPARE_MODE,a.NONE)):(a.texParameteri(l,a.TEXTURE_COMPARE_FUNC,n),a.texParameteri(l,a.TEXTURE_COMPARE_MODE,a.COMPARE_REF_TO_TEXTURE))},R.prototype.createDepthStencilTexture=function(e,t){if(t.isCube){var i=e.width||e;return this._createDepthStencilCubeTexture(i,t)}return this._createDepthStencilTexture(e,t)},R.prototype._createDepthStencilTexture=function(e,t){var i=new M.InternalTexture(this,M.InternalTexture.DATASOURCE_DEPTHTEXTURE);if(!this._caps.depthTextureExtension)return M.Tools.Error("Depth texture is not supported by your browser or hardware."),i;var r=ae({bilinearFiltering:!1,comparisonFunction:0,generateStencil:!1},t),n=this._gl;return this._bindTextureDirectly(n.TEXTURE_2D,i,!0),this._setupDepthStencilTexture(i,e,r.generateStencil,r.bilinearFiltering,r.comparisonFunction),1>l,h=0;h<6;h++){var u=a[l][h];s&&(u=y._convertRGBtoRGBATextureData(u,c,c,p)),b.texImage2D(h,l,o,c,c,0,n,r,u)}y._bindTextureDirectly(b.TEXTURE_CUBE_MAP,null)}else y.updateRawCubeTexture(T,i,f,p,v);T.isReady=!0,d._removePendingData(T),g&&g()}})(e)}),void 0,d.database,!0,(function(e,t){d._removePendingData(T),r&&e&&r(e.status+" "+e.statusText,t)})),T},R.prototype.updateRawTexture3D=function(e,t,i,r,n,o){void 0===n&&(n=null),void 0===o&&(o=R.TEXTURETYPE_UNSIGNED_INT);var s=this._getWebGLTextureType(o),a=this._getInternalFormat(i),l=this._getRGBABufferInternalSizedFormat(o,i);this._bindTextureDirectly(this._gl.TEXTURE_3D,e,!0),this._unpackFlipY(void 0===r||!!r),this._doNotHandleContextLost||(e._bufferView=t,e.format=i,e.invertY=r,e._compression=n),e.width%4!=0&&this._gl.pixelStorei(this._gl.UNPACK_ALIGNMENT,1),n&&t?this._gl.compressedTexImage3D(this._gl.TEXTURE_3D,0,this.getCaps().s3tc[n],e.width,e.height,e.depth,0,t):this._gl.texImage3D(this._gl.TEXTURE_3D,0,l,e.width,e.height,e.depth,0,a,s,t),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_3D),this._bindTextureDirectly(this._gl.TEXTURE_3D,null),e.isReady=!0},R.prototype.createRawTexture3D=function(e,t,i,r,n,o,s,a,l,c){void 0===l&&(l=null),void 0===c&&(c=R.TEXTURETYPE_UNSIGNED_INT);var h=new M.InternalTexture(this,M.InternalTexture.DATASOURCE_RAW3D);h.baseWidth=t,h.baseHeight=i,h.baseDepth=r,h.width=t,h.height=i,h.depth=r,h.format=n,h.type=c,h.generateMipMaps=o,h.samplingMode=a,h.is3D=!0,this._doNotHandleContextLost||(h._bufferView=e),this.updateRawTexture3D(h,e,n,s,l,c),this._bindTextureDirectly(this._gl.TEXTURE_3D,h,!0);var u=this._getSamplingParameters(a,o);return this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_MAG_FILTER,u.mag),this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_MIN_FILTER,u.min),o&&this._gl.generateMipmap(this._gl.TEXTURE_3D),this._bindTextureDirectly(this._gl.TEXTURE_3D,null),this._internalTexturesCache.push(h),h},R.prototype._prepareWebGLTextureContinuation=function(e,t,i,r,n){var o=this._gl;if(o){var s=this._getSamplingParameters(n,!i);o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,s.mag),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,s.min),i||r||o.generateMipmap(o.TEXTURE_2D),this._bindTextureDirectly(o.TEXTURE_2D,null),t&&t._removePendingData(e),e.onLoadedObservable.notifyObservers(e),e.onLoadedObservable.clear()}},R.prototype._prepareWebGLTexture=function(e,t,i,r,n,o,s,a,l){var c=this;void 0===l&&(l=R.TEXTURE_TRILINEAR_SAMPLINGMODE);var h=this.getCaps().maxTextureSize,u=Math.min(h,this.needPOTTextures?M.Tools.GetExponentOfTwo(i,h):i),d=Math.min(h,this.needPOTTextures?M.Tools.GetExponentOfTwo(r,h):r),f=this._gl;f&&(e._webGLTexture?(this._bindTextureDirectly(f.TEXTURE_2D,e,!0),this._unpackFlipY(void 0===n||!!n),e.baseWidth=i,e.baseHeight=r,e.width=u,e.height=d,e.isReady=!0,a(u,d,(function(){c._prepareWebGLTextureContinuation(e,t,o,s,l)}))||this._prepareWebGLTextureContinuation(e,t,o,s,l)):t&&t._removePendingData(e))},R.prototype._convertRGBtoRGBATextureData=function(e,t,i,r){var n;n=r===R.TEXTURETYPE_FLOAT?new Float32Array(t*i*4):new Uint32Array(t*i*4);for(var o=0;o=this._caps.maxVertexAttribs||!this._vertexAttribArraysEnabled[e]||(this._gl.disableVertexAttribArray(e),this._vertexAttribArraysEnabled[e]=!1,this._currentBufferPointers[e].active=!1)}},R.prototype.releaseEffects=function(){for(var e in this._compiledEffects)this._deleteProgram(this._compiledEffects[e]._program);this._compiledEffects={}},R.prototype.dispose=function(){for(this.hideLoadingUI(),this.stopRenderLoop();this.postProcesses.length;)this.postProcesses[0].dispose();for(this._emptyTexture&&(this._releaseTexture(this._emptyTexture),this._emptyTexture=null),this._emptyCubeTexture&&(this._releaseTexture(this._emptyCubeTexture),this._emptyCubeTexture=null),this._rescalePostProcess&&this._rescalePostProcess.dispose();this.scenes.length;)this.scenes[0].dispose();1===R.Instances.length&&R.audioEngine&&R.audioEngine.dispose(),this.releaseEffects(),this.unbindAllAttributes(),this._boundUniforms=[],this._dummyFramebuffer&&this._gl.deleteFramebuffer(this._dummyFramebuffer),this.disableVR(),M.Tools.IsWindowObjectExist()&&(window.removeEventListener("blur",this._onBlur),window.removeEventListener("focus",this._onFocus),window.removeEventListener("vrdisplaypointerrestricted",this._onVRDisplayPointerRestricted),window.removeEventListener("vrdisplaypointerunrestricted",this._onVRDisplayPointerUnrestricted),this._renderingCanvas&&(this._renderingCanvas.removeEventListener("focus",this._onCanvasFocus),this._renderingCanvas.removeEventListener("blur",this._onCanvasBlur),this._renderingCanvas.removeEventListener("pointerout",this._onCanvasPointerOut),this._doNotHandleContextLost||(this._renderingCanvas.removeEventListener("webglcontextlost",this._onContextLost),this._renderingCanvas.removeEventListener("webglcontextrestored",this._onContextRestored))),document.removeEventListener("fullscreenchange",this._onFullscreenChange),document.removeEventListener("mozfullscreenchange",this._onFullscreenChange),document.removeEventListener("webkitfullscreenchange",this._onFullscreenChange),document.removeEventListener("msfullscreenchange",this._onFullscreenChange),document.removeEventListener("pointerlockchange",this._onPointerLockChange),document.removeEventListener("mspointerlockchange",this._onPointerLockChange),document.removeEventListener("mozpointerlockchange",this._onPointerLockChange),document.removeEventListener("webkitpointerlockchange",this._onPointerLockChange),this._onVrDisplayConnect&&(window.removeEventListener("vrdisplayconnect",this._onVrDisplayConnect),this._onVrDisplayDisconnect&&window.removeEventListener("vrdisplaydisconnect",this._onVrDisplayDisconnect),this._onVrDisplayPresentChange&&window.removeEventListener("vrdisplaypresentchange",this._onVrDisplayPresentChange),this._onVrDisplayConnect=null,this._onVrDisplayDisconnect=null));var e=R.Instances.indexOf(this);0<=e&&R.Instances.splice(e,1),this._workingCanvas=null,this._workingContext=null,this._currentBufferPointers=[],this._renderingCanvas=null,this._currentProgram=null,this._bindedRenderFunction=null,this.onResizeObservable.clear(),this.onCanvasBlurObservable.clear(),this.onCanvasFocusObservable.clear(),this.onCanvasPointerOutObservable.clear(),this.onBeginFrameObservable.clear(),this.onEndFrameObservable.clear(),M.Effect.ResetCache();for(var t=0,i=this._activeRequests;te.x-this.minimumWorld.x)&&(!(this.maximumWorld.y-e.ye.y-this.minimumWorld.y)&&!(this.maximumWorld.z-e.ze.z-this.minimumWorld.z))},t.prototype.intersectsSphere=function(e){return t.IntersectsSphere(this.minimumWorld,this.maximumWorld,e.centerWorld,e.radiusWorld)},t.prototype.intersectsMinMax=function(e,t){return!(this.maximumWorld.xt.x)&&(!(this.maximumWorld.yt.y)&&!(this.maximumWorld.zt.z))},t.Intersects=function(e,t){return!(e.maximumWorld.xt.maximumWorld.x)&&(!(e.maximumWorld.yt.maximumWorld.y)&&!(e.maximumWorld.zt.maximumWorld.z))},t.IntersectsSphere=function(e,t,i,r){var n=S.Vector3.Clamp(i,e,t);return S.Vector3.DistanceSquared(i,n)<=r*r},t.IsCompletelyInFrustum=function(e,t){for(var i=0;i<6;i++)for(var r=0;r<8;r++)if(t[i].dotCoordinate(e[r])<0)return!1;return!0},t.IsInFrustum=function(e,t){for(var i=0;i<6;i++){for(var r=8,n=0;n<8&&t[i].dotCoordinate(e[n])<0;n++)--r;if(0===r)return!1}return!0},t})(),S.BoundingBox=R,M=$a||($a={}),C=function(e,t){var i=M.Vector3.Dot(t.centerWorld,e),r=Math.abs(M.Vector3.Dot(t.directions[0],e))*t.extendSize.x+Math.abs(M.Vector3.Dot(t.directions[1],e))*t.extendSize.y+Math.abs(M.Vector3.Dot(t.directions[2],e))*t.extendSize.z;return{min:i-r,max:i+r}},O=function(e,t,i){var r,n,o,s=C(e,t),a=C(e,i);return r=s.min,n=s.max,o=a.min,!(a.maxL.Engine.CollisionsEpsilon&&r.position.addInPlace(r._diffPositionForCollisions),i&&r.onCollideObservable.notifyObservers(i),r.onCollisionPositionChangeObservable.notifyObservers(r.position)},r.getScene().addMesh(r),r._resyncLightSources(),r}return T(i,a),Object.defineProperty(i,"BILLBOARDMODE_NONE",{get:function(){return L.TransformNode.BILLBOARDMODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_X",{get:function(){return L.TransformNode.BILLBOARDMODE_X},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_Y",{get:function(){return L.TransformNode.BILLBOARDMODE_Y},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_Z",{get:function(){return L.TransformNode.BILLBOARDMODE_Z},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_ALL",{get:function(){return L.TransformNode.BILLBOARDMODE_ALL},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"facetNb",{get:function(){return this._facetData.facetNb},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"partitioningSubdivisions",{get:function(){return this._facetData.partitioningSubdivisions},set:function(e){this._facetData.partitioningSubdivisions=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"partitioningBBoxRatio",{get:function(){return this._facetData.partitioningBBoxRatio},set:function(e){this._facetData.partitioningBBoxRatio=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"mustDepthSortFacets",{get:function(){return this._facetData.facetDepthSort},set:function(e){this._facetData.facetDepthSort=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"facetDepthSortFrom",{get:function(){return this._facetData.facetDepthSortFrom},set:function(e){this._facetData.facetDepthSortFrom=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"isFacetDataEnabled",{get:function(){return this._facetData.facetDataEnabled},enumerable:!0,configurable:!0}),i.prototype._updateNonUniformScalingState=function(e){return!!a.prototype._updateNonUniformScalingState.call(this,e)&&(this._markSubMeshesAsMiscDirty(),!0)},Object.defineProperty(i.prototype,"onCollide",{set:function(e){this._onCollideObserver&&this.onCollideObservable.remove(this._onCollideObserver),this._onCollideObserver=this.onCollideObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onCollisionPositionChange",{set:function(e){this._onCollisionPositionChangeObserver&&this.onCollisionPositionChangeObservable.remove(this._onCollisionPositionChangeObserver),this._onCollisionPositionChangeObserver=this.onCollisionPositionChangeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"visibility",{get:function(){return this._visibility},set:function(e){this._visibility!==e&&(this._visibility=e,this._markSubMeshesAsMiscDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"material",{get:function(){return this._material},set:function(e){this._material!==e&&(this._material=e,this.onMaterialChangedObservable.hasObservers&&this.onMaterialChangedObservable.notifyObservers(this),this.subMeshes&&this._unBindEffect())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"receiveShadows",{get:function(){return this._receiveShadows},set:function(e){this._receiveShadows!==e&&(this._receiveShadows=e,this._markSubMeshesAsLightDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"hasVertexAlpha",{get:function(){return this._hasVertexAlpha},set:function(e){this._hasVertexAlpha!==e&&(this._hasVertexAlpha=e,this._markSubMeshesAsAttributesDirty(),this._markSubMeshesAsMiscDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"useVertexColors",{get:function(){return this._useVertexColors},set:function(e){this._useVertexColors!==e&&(this._useVertexColors=e,this._markSubMeshesAsAttributesDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"computeBonesUsingShaders",{get:function(){return this._computeBonesUsingShaders},set:function(e){this._computeBonesUsingShaders!==e&&(this._computeBonesUsingShaders=e,this._markSubMeshesAsAttributesDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"numBoneInfluencers",{get:function(){return this._numBoneInfluencers},set:function(e){this._numBoneInfluencers!==e&&(this._numBoneInfluencers=e,this._markSubMeshesAsAttributesDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"applyFog",{get:function(){return this._applyFog},set:function(e){this._applyFog!==e&&(this._applyFog=e,this._markSubMeshesAsMiscDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"layerMask",{get:function(){return this._layerMask},set:function(e){e!==this._layerMask&&(this._layerMask=e,this._resyncLightSources())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"collisionMask",{get:function(){return this._collisionMask},set:function(e){this._collisionMask=isNaN(e)?-1:e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"collisionGroup",{get:function(){return this._collisionGroup},set:function(e){this._collisionGroup=isNaN(e)?-1:e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"_positions",{get:function(){return null},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"skeleton",{get:function(){return this._skeleton},set:function(e){this._skeleton&&this._skeleton.needInitialSkinMatrix&&this._skeleton._unregisterMeshWithPoseMatrix(this),e&&e.needInitialSkinMatrix&&e._registerMeshWithPoseMatrix(this),this._skeleton=e,this._skeleton||(this._bonesTransformMatrices=null),this._markSubMeshesAsAttributesDirty()},enumerable:!0,configurable:!0}),i.prototype.getClassName=function(){return"AbstractMesh"},i.prototype.toString=function(e){var t="Name: "+this.name+", isInstance: "+(this instanceof L.InstancedMesh?"YES":"NO");return t+=", # of submeshes: "+(this.subMeshes?this.subMeshes.length:0),this._skeleton&&(t+=", skeleton: "+this._skeleton.name),e&&(t+=", billboard mode: "+["NONE","X","Y",null,"Z",null,null,"ALL"][this.billboardMode],t+=", freeze wrld mat: "+(this._isWorldMatrixFrozen||this._waitingFreezeWorldMatrix?"YES":"NO")),t},i.prototype._rebuild=function(){if(this.onRebuildObservable.notifyObservers(this),this._occlusionQuery&&(this._occlusionQuery=null),this.subMeshes)for(var e=0,t=this.subMeshes;eL.Epsilon?n.maximum.x-n.minimum.x:L.Epsilon,e.bbSize.y=n.maximum.y-n.minimum.y>L.Epsilon?n.maximum.y-n.minimum.y:L.Epsilon,e.bbSize.z=n.maximum.z-n.minimum.z>L.Epsilon?n.maximum.z-n.minimum.z:L.Epsilon;var h=e.bbSize.x>e.bbSize.y?e.bbSize.x:e.bbSize.y;if(h=h>e.bbSize.z?h:e.bbSize.z,e.subDiv.max=e.partitioningSubdivisions,e.subDiv.X=Math.floor(e.subDiv.max*e.bbSize.x/h),e.subDiv.Y=Math.floor(e.subDiv.max*e.bbSize.y/h),e.subDiv.Z=Math.floor(e.subDiv.max*e.bbSize.z/h),e.subDiv.X=e.subDiv.X<1?1:e.subDiv.X,e.subDiv.Y=e.subDiv.Y<1?1:e.subDiv.Y,e.subDiv.Z=e.subDiv.Z<1?1:e.subDiv.Z,e.facetParameters.facetNormals=this.getFacetLocalNormals(),e.facetParameters.facetPositions=this.getFacetLocalPositions(),e.facetParameters.facetPartitioning=this.getFacetLocalPartitioning(),e.facetParameters.bInfo=n,e.facetParameters.bbSize=e.bbSize,e.facetParameters.subDiv=e.subDiv,e.facetParameters.ratio=this.partitioningBBoxRatio,e.facetParameters.depthSort=e.facetDepthSort,e.facetDepthSort&&e.facetDepthSortEnabled&&(this.computeWorldMatrix(!0),this._worldMatrix.invertToRef(e.invertedMatrix),L.Vector3.TransformCoordinatesToRef(e.facetDepthSortFrom,e.invertedMatrix,e.facetDepthSortOrigin),e.facetParameters.distanceTo=e.facetDepthSortOrigin),e.facetParameters.depthSortedFacets=e.depthSortedFacets,L.VertexData.ComputeNormals(t,i,r,e.facetParameters),e.facetDepthSort&&e.facetDepthSortEnabled){e.depthSortedFacets.sort(e.facetDepthSortFunction);var u=e.depthSortedIndices.length/3|0;for(l=0;ln.subDiv.max||s<0||s>n.subDiv.max||a<0||a>n.subDiv.max?null:n.facetPartitioning[o+n.subDiv.max*s+n.subDiv.max*n.subDiv.max*a]},i.prototype.getClosestFacetAtCoordinates=function(e,t,i,r,n,o){void 0===n&&(n=!1),void 0===o&&(o=!0);var s=this.getWorldMatrix(),a=L.Tmp.Matrix[5];s.invertToRef(a);var l=L.Tmp.Vector3[8];L.Vector3.TransformCoordinatesFromFloatsToRef(e,t,i,a,l);var c=this.getClosestFacetAtLocalCoordinates(l.x,l.y,l.z,r,n,o);return r&&L.Vector3.TransformCoordinatesFromFloatsToRef(r.x,r.y,r.z,s,r),c},i.prototype.getClosestFacetAtLocalCoordinates=function(e,t,i,r,n,o){void 0===n&&(n=!1),void 0===o&&(o=!0);var s=null,a=0,l=0,c=0,h=0,u=0,d=0,f=0,p=0,m=this.getFacetLocalPositions(),_=this.getFacetLocalNormals(),g=this.getFacetsAtLocalCoordinates(e,t,i);if(!g)return null;for(var v,y,b,T=Number.MAX_VALUE,x=T,E=0;Et._alphaIndex?1:e._alphaIndext._distanceToCamera?-1:0},i.frontToBackSortCompare=function(e,t){return e._distanceToCamerat._distanceToCamera?1:0},i.prototype.prepare=function(){this._opaqueSubMeshes.reset(),this._transparentSubMeshes.reset(),this._alphaTestSubMeshes.reset(),this._depthOnlySubMeshes.reset(),this._particleSystems.reset(),this._spriteManagers.reset(),this._edgesRenderers.reset()},i.prototype.dispose=function(){this._opaqueSubMeshes.dispose(),this._transparentSubMeshes.dispose(),this._alphaTestSubMeshes.dispose(),this._depthOnlySubMeshes.dispose(),this._particleSystems.dispose(),this._spriteManagers.dispose(),this._edgesRenderers.dispose()},i.prototype.dispatch=function(e,t,i){void 0===t&&(t=e.getMesh()),void 0===i&&(i=e.getMaterial()),null!=i&&(i.needAlphaBlendingForMesh(t)?this._transparentSubMeshes.push(e):i.needAlphaTesting()?(i.needDepthPrePass&&this._depthOnlySubMeshes.push(e),this._alphaTestSubMeshes.push(e)):(i.needDepthPrePass&&this._depthOnlySubMeshes.push(e),this._opaqueSubMeshes.push(e)),t._edgesRenderer&&t._edgesRenderer.isEnabled&&this._edgesRenderers.push(t._edgesRenderer))},i.prototype.dispatchSprites=function(e){this._spriteManagers.push(e)},i.prototype.dispatchParticles=function(e){this._particleSystems.push(e)},i.prototype._renderParticles=function(e){if(0!==this._particleSystems.length){var t=this._scene.activeCamera;this._scene.onBeforeParticlesRenderingObservable.notifyObservers(this._scene);for(var i=0;ix.LongPressDelay&&!i._isPointerSwiping()&&(i._startingPointerTime=0,r.processTrigger(E.ActionManager.OnLongPressTrigger,E.ActionEvent.CreateNew(e.pickedMesh,t)))}),x.LongPressDelay)}}else for(var n=0,o=this._pointerDownStage;nx.DragMovementThreshold||Math.abs(this._startingPointerPosition.y-this._pointerY)>x.DragMovementThreshold},x.prototype.attachControl=function(e,t,i){var h=this;void 0===e&&(e=!0),void 0===t&&(t=!0),void 0===i&&(i=!0),this._initActionManager=function(e,t){if(!h._meshPickProceed){var i=h.pick(h._unTranslatedPointerX,h._unTranslatedPointerY,h.pointerDownPredicate,!1,h.cameraToUseForPointers);(h._currentPickResult=i)&&(e=i.hit&&i.pickedMesh?i.pickedMesh.actionManager:null),h._meshPickProceed=!0}return e},this._delayedSimpleClick=function(e,t,i){(Date.now()-h._previousStartingPointerTime>x.DoubleClickDelay&&!h._doubleClickOccured||e!==h._previousButtonPressed)&&(h._doubleClickOccured=!1,t.singleClick=!0,t.ignore=!1,i(t,h._currentPickResult))},this._initClickEvent=function(e,t,i,r){var n=new u,o=h._currentPickResult=null,s=e.hasSpecificMask(E.PointerEventTypes.POINTERPICK)||t.hasSpecificMask(E.PointerEventTypes.POINTERPICK)||e.hasSpecificMask(E.PointerEventTypes.POINTERTAP)||t.hasSpecificMask(E.PointerEventTypes.POINTERTAP)||e.hasSpecificMask(E.PointerEventTypes.POINTERDOUBLETAP)||t.hasSpecificMask(E.PointerEventTypes.POINTERDOUBLETAP);if(!s&&E.ActionManager&&E.ActionManager.HasPickTriggers&&(o=h._initActionManager(o,n))&&(s=o.hasPickTriggers),s){var a=i.button;if(n.hasSwiped=h._isPointerSwiping(),!n.hasSwiped){var l=!x.ExclusiveDoubleClickMode;l||(l=!e.hasSpecificMask(E.PointerEventTypes.POINTERDOUBLETAP)&&!t.hasSpecificMask(E.PointerEventTypes.POINTERDOUBLETAP))&&!E.ActionManager.HasSpecificTrigger(E.ActionManager.OnDoublePickTrigger)&&(o=h._initActionManager(o,n))&&(l=!o.hasSpecificTrigger(E.ActionManager.OnDoublePickTrigger)),l?(Date.now()-h._previousStartingPointerTime>x.DoubleClickDelay||a!==h._previousButtonPressed)&&(n.singleClick=!0,r(n,h._currentPickResult)):(h._previousDelayedSimpleClickTimeout=h._delayedSimpleClickTimeout,h._delayedSimpleClickTimeout=window.setTimeout(h._delayedSimpleClick.bind(h,a,n,r),x.DoubleClickDelay));var c=e.hasSpecificMask(E.PointerEventTypes.POINTERDOUBLETAP)||t.hasSpecificMask(E.PointerEventTypes.POINTERDOUBLETAP);!c&&E.ActionManager.HasSpecificTrigger(E.ActionManager.OnDoublePickTrigger)&&(o=h._initActionManager(o,n))&&(c=o.hasSpecificTrigger(E.ActionManager.OnDoublePickTrigger)),c&&(a===h._previousButtonPressed&&Date.now()-h._previousStartingPointerTime=r.distance))&&(r=a,i)))break}return r||new E.PickingInfo},x.prototype._internalMultiPick=function(e,t){if(!E.PickingInfo)return null;for(var i=new Array,r=0;rt.distance?-1:0}))},m.prototype.addLODLevel=function(e,t){if(t&&t._masterMesh)return S.Tools.Warn("You cannot use a mesh as LOD level twice"),this;var i=new S.MeshLODLevel(e,t);return this._LODLevels.push(i),t&&(t._masterMesh=this),this._sortLODLevels(),this},m.prototype.getLODLevelAtDistance=function(e){for(var t=0;tr)return this.onLODLevelSelection&&this.onLODLevelSelection(r,this,this._LODLevels[this._LODLevels.length-1].mesh),this;for(var n=0;n=r){n=!0;break}if(a.verticesStart+a.verticesCount>=t){n=!0;break}}if(!n)return this.subMeshes[0]}return this.releaseSubMeshes(),new S.SubMesh(0,0,t,0,this.getTotalIndices(),this)},m.prototype.subdivide=function(e){if(!(e<1)){for(var t=this.getTotalIndices(),i=t/e|0,r=0;i%3!=0;)i++;this.releaseSubMeshes();for(var n=0;n=e.minHeight,T=n[3*g+1]>=e.minHeight,x=n[3*v+1]>=e.minHeight;b&&T&&x&&(r.push(_),r.push(g),r.push(v)),n[3*y+1]>=e.minHeight&&b&&x&&(r.push(y),r.push(_),r.push(v))}q.ComputeNormals(n,r,o);var E=new q;return E.indices=r,E.positions=n,E.normals=o,E.uvs=s,E},q.CreatePlane=function(e){var t=[],i=[],r=[],n=[],o=e.width||e.size||1,s=e.height||e.size||1,a=0===e.sideOrientation?0:e.sideOrientation||he.Mesh.DEFAULTSIDE,l=o/2,c=s/2;i.push(-l,-c,0),r.push(0,0,-1),n.push(0,0),i.push(l,-c,0),r.push(0,0,-1),n.push(1,0),i.push(l,c,0),r.push(0,0,-1),n.push(1,1),i.push(-l,c,0),r.push(0,0,-1),n.push(0,1),t.push(0),t.push(1),t.push(2),t.push(0),t.push(2),t.push(3),q._ComputeSides(a,i,t,r,n,e.frontUVs,e.backUVs);var h=new q;return h.indices=t,h.positions=i,h.normals=r,h.uvs=n,h},q.CreateDisc=function(e){var t=new Array,i=new Array,r=new Array,n=new Array,o=e.radius||.5,s=e.tessellation||64,a=e.arc&&(e.arc<=0||1=t.length)?0:e.type||0,c=e.size,h=e.sizeX||c||1,u=e.sizeY||c||1,d=e.sizeZ||c||1,f=e.custom||t[l],p=f.face.length,m=e.faceUV||new Array(p),_=e.faceColors,g=void 0===e.flat||e.flat,v=0===e.sideOrientation?0:e.sideOrientation||he.Mesh.DEFAULTSIDE,y=new Array,b=new Array,T=new Array,x=new Array,E=new Array,A=0,P=0,S=new Array,R=0,M=0;if(g)for(M=0;Mr.bbSize.y?r.bbSize.x:r.bbSize.y;J=J>r.bbSize.z?J:r.bbSize.z,I=r.subDiv.X*C/r.bbSize.x,w=r.subDiv.Y*C/r.bbSize.y,L=r.subDiv.Z*C/r.bbSize.z,F=r.subDiv.max*r.subDiv.max,r.facetPartitioning.length=0}for(n=0;n>8),g.push((16711680&y)>>16),g.push(y>>24)}t.setVerticesData(I.VertexBuffer.MatricesIndicesKind,g,!1)}if(o.matricesWeightsAttrDesc&&0>8),g.push((16711680&M)>>16),g.push(M>>24)}t.setVerticesData(I.VertexBuffer.MatricesIndicesKind,g,e.matricesIndices._updatable)}if(e.matricesIndicesExtra)if(e.matricesIndicesExtra._isExpanded)delete e.matricesIndices._isExpanded,t.setVerticesData(I.VertexBuffer.MatricesIndicesExtraKind,e.matricesIndicesExtra,e.matricesIndicesExtra._updatable);else{for(g=[],v=0;v>8),g.push((16711680&M)>>16),g.push(M>>24)}t.setVerticesData(I.VertexBuffer.MatricesIndicesExtraKind,g,e.matricesIndicesExtra._updatable)}e.matricesWeights&&(D._CleanMatricesWeights(e,t),t.setVerticesData(I.VertexBuffer.MatricesWeightsKind,e.matricesWeights,e.matricesWeights._updatable)),e.matricesWeightsExtra&&t.setVerticesData(I.VertexBuffer.MatricesWeightsExtraKind,e.matricesWeightsExtra,e.matricesWeights._updatable),t.setIndices(e.indices,null)}if(e.subMeshes){t.subMeshes=[];for(var C=0;C=this._sampleCount||e>=this._samples.length)return 0;var t=this._wrapPosition(this._pos-1);return this._samples[this._wrapPosition(t-e)]},e.prototype.isSaturated=function(){return this._sampleCount>=this._samples.length},e.prototype.reset=function(){this.average=0,this.variance=0,this._sampleCount=0,this._pos=0,this._m2=0},e.prototype._wrapPosition=function(e){var t=this._samples.length;return(e%t+t)%t},e})();i.RollingAverage=t})($a||($a={})),de=$a||($a={}),fe=(function(){function u(){}return u.BindEyePosition=function(e,t){t._forcedViewPosition?e.setVector3("vEyePosition",t._forcedViewPosition):e.setVector3("vEyePosition",t._mirroredCameraPosition?t._mirroredCameraPosition:t.activeCamera.globalPosition)},u.PrepareDefinesForMergedUV=function(e,t,i){t._needUVs=!0,t[i]=!0,e.getTextureMatrix().isIdentity(!0)?(t[i+"DIRECTUV"]=e.coordinatesIndex+1,0===e.coordinatesIndex?t.MAINUV1=!0:t.MAINUV2=!0):t[i+"DIRECTUV"]=0},u.BindTextureMatrix=function(e,t,i){var r=e.getTextureMatrix();r.isIdentity(!0)||t.updateMatrix(i+"Matrix",r)},u.PrepareDefinesForMisc=function(e,t,i,r,n,o,s){s._areMiscDirty&&(s.LOGARITHMICDEPTH=i,s.POINTSIZE=r,s.FOG=t.fogEnabled&&e.applyFog&&t.fogMode!==de.Scene.FOGMODE_NONE&&n,s.NONUNIFORMSCALING=e.nonUniformScaling,s.ALPHATEST=o)},u.PrepareDefinesForFrameBoundValues=function(e,t,i,r,n){void 0===n&&(n=null);var o,s,a,l,c=!1;o=null==n?void 0!==e.clipPlane&&null!==e.clipPlane:n,s=null==n?void 0!==e.clipPlane2&&null!==e.clipPlane2:n,a=null==n?void 0!==e.clipPlane3&&null!==e.clipPlane3:n,l=null==n?void 0!==e.clipPlane4&&null!==e.clipPlane4:n,i.CLIPPLANE!==o&&(i.CLIPPLANE=o,c=!0),i.CLIPPLANE2!==s&&(i.CLIPPLANE2=s,c=!0),i.CLIPPLANE3!==a&&(i.CLIPPLANE3=a,c=!0),i.CLIPPLANE4!==l&&(i.CLIPPLANE4=l,c=!0),i.DEPTHPREPASS!==!t.getColorWrite()&&(i.DEPTHPREPASS=!i.DEPTHPREPASS,c=!0),i.INSTANCES!==r&&(i.INSTANCES=r,c=!0),c&&i.markAsUnprocessed()},u.PrepareDefinesForAttributes=function(e,t,i,r,n,o){if(void 0===n&&(n=!1),void 0===o&&(o=!0),!t._areAttributesDirty&&t._needNormals===t._normals&&t._needUVs===t._uvs)return!1;if(t._normals=t._needNormals,t._uvs=t._needUVs,t.NORMAL=t._needNormals&&e.isVerticesDataPresent(de.VertexBuffer.NormalKind),t._needNormals&&e.isVerticesDataPresent(de.VertexBuffer.TangentKind)&&(t.TANGENT=!0),t._needUVs?(t.UV1=e.isVerticesDataPresent(de.VertexBuffer.UVKind),t.UV2=e.isVerticesDataPresent(de.VertexBuffer.UV2Kind)):(t.UV1=!1,t.UV2=!1),i){var s=e.useVertexColors&&e.isVerticesDataPresent(de.VertexBuffer.ColorKind);t.VERTEXCOLOR=s,t.VERTEXALPHA=e.hasVertexAlpha&&s&&o}if(r&&(e.useBones&&e.computeBonesUsingShaders&&e.skeleton?(t.NUM_BONE_INFLUENCERS=e.numBoneInfluencers,t.BonesPerMesh=e.skeleton.bones.length+1):(t.NUM_BONE_INFLUENCERS=0,t.BonesPerMesh=0)),n){var a=e.morphTargetManager;a?(t.MORPHTARGETS_TANGENT=a.supportsTangents&&t.TANGENT,t.MORPHTARGETS_NORMAL=a.supportsNormals&&t.NORMAL,t.MORPHTARGETS=0n&&de.Tools.Error("Cannot add more vertex attributes for mesh "+t.name)},u.PrepareAttributesForBones=function(e,t,i,r){0i&&(this.rotation.x=i),this.rotation.x<-i&&(this.rotation.x=-i)}}e&&(Math.abs(this.cameraDirection.x)s.Engine.CollisionsEpsilon&&(n.position.addInPlace(n._diffPosition),n.onCollide&&i&&n.onCollide(i))},n.inputs=new s.FreeCameraInputsManager(n),n.inputs.addKeyboard().addMouse(),n}return T(e,o),Object.defineProperty(e.prototype,"angularSensibility",{get:function(){var e=this.inputs.attached.mouse;return e?e.angularSensibility:0},set:function(e){var t=this.inputs.attached.mouse;t&&(t.angularSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"keysUp",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysUp:[]},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysUp=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"keysDown",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysDown:[]},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysDown=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"keysLeft",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysLeft:[]},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysLeft=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"keysRight",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysRight:[]},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysRight=e)},enumerable:!0,configurable:!0}),e.prototype.attachControl=function(e,t){this.inputs.attachElement(e,t)},e.prototype.detachControl=function(e){this.inputs.detachElement(e),this.cameraDirection=new s.Vector3(0,0,0),this.cameraRotation=new s.Vector2(0,0)},Object.defineProperty(e.prototype,"collisionMask",{get:function(){return this._collisionMask},set:function(e){this._collisionMask=isNaN(e)?-1:e},enumerable:!0,configurable:!0}),e.prototype._collideWithWorld=function(e){(this.parent?s.Vector3.TransformCoordinates(this.position,this.parent.getWorldMatrix()):this.position).subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPosition),this._oldPosition.addInPlace(this.ellipsoidOffset),this._collider||(this._collider=new s.Collider),this._collider._radius=this.ellipsoid,this._collider.collisionMask=this._collisionMask;var t=e;this.applyGravity&&(t=e.add(this.getScene().gravity)),this.getScene().collisionCoordinator.getNewPosition(this._oldPosition,t,this._collider,3,null,this._onCollisionPositionChange,this.uniqueId)},e.prototype._checkInputs=function(){this._localDirection||(this._localDirection=s.Vector3.Zero(),this._transformedDirection=s.Vector3.Zero()),this.inputs.checkInputs(),o.prototype._checkInputs.call(this)},e.prototype._decideIfNeedsToMove=function(){return this._needMoveForGravity||0b.camera.pinchToPanMaxDistance)b.pinchDeltaPercentage?b.camera.inertialRadiusOffset+=.001*(u-A)*b.camera.radius*b.pinchDeltaPercentage:b.camera.inertialRadiusOffset+=(u-A)/(b.pinchPrecision*((b.angularSensibilityX+b.angularSensibilityY)/2)*l),R.isPaning=!1,R.isPinching=!0;else if(y&&y.pointerId===a.pointerId&&0!==b.panningSensibility&&b.multiTouchPanning){if(!R.isPaning)return R.isPaning=!0,R.isPinching=!1,R.x=a.x,void(R.y=a.y);b.camera.inertialPanningX+=-(a.x-R.x)/b.panningSensibility,b.camera.inertialPanningY+=(a.y-R.y)/b.panningSensibility}y&&y.pointerId===i.pointerId&&(R.x=a.x,R.y=a.y)}A=u}}},this._observer=this.camera.getScene().onPointerObservable.add(this._pointerInput,ke.PointerEventTypes.POINTERDOWN|ke.PointerEventTypes.POINTERUP|ke.PointerEventTypes.POINTERMOVE|ke.PointerEventTypes.POINTERDOUBLETAP),this._onContextMenu=function(e){e.preventDefault()},this.camera._useCtrlForPanning||g.addEventListener("contextmenu",this._onContextMenu,!1),this._onLostFocus=function(){x=E=null,A=0,R.isPaning=!1,R.isPinching=!1,y=null,P=S=0},this._onMouseMove=function(e){if(T.isPointerLock){var t=e.movementX||e.mozMovementX||e.webkitMovementX||e.msMovementX||0,i=e.movementY||e.mozMovementY||e.webkitMovementY||e.msMovementY||0;b.camera.inertialAlphaOffset-=t/b.angularSensibilityX,b.camera.inertialBetaOffset-=i/b.angularSensibilityY,v||e.preventDefault()}},this._onGestureStart=function(e){void 0!==window.MSGesture&&(b._MSGestureHandler||(b._MSGestureHandler=new MSGesture,b._MSGestureHandler.target=g),b._MSGestureHandler.addPointer(e.pointerId))},this._onGesture=function(e){b.camera.radius*=e.scale,e.preventDefault&&(v||(e.stopPropagation(),e.preventDefault()))},g.addEventListener("mousemove",this._onMouseMove,!1),g.addEventListener("MSPointerDown",this._onGestureStart,!1),g.addEventListener("MSGestureChange",this._onGesture,!1),ke.Tools.RegisterTopRootEvents([{name:"blur",handler:this._onLostFocus}])},e.prototype.detachControl=function(e){this._onLostFocus&&ke.Tools.UnregisterTopRootEvents([{name:"blur",handler:this._onLostFocus}]),e&&this._observer&&(this.camera.getScene().onPointerObservable.remove(this._observer),this._observer=null,this._onContextMenu&&e.removeEventListener("contextmenu",this._onContextMenu),this._onMouseMove&&e.removeEventListener("mousemove",this._onMouseMove),this._onGestureStart&&e.removeEventListener("MSPointerDown",this._onGestureStart),this._onGesture&&e.removeEventListener("MSGestureChange",this._onGesture),this._isPanClick=!1,this.pinchInwards=!0,this._onMouseMove=null,this._onGestureStart=null,this._onGesture=null,this._MSGestureHandler=null,this._onLostFocus=null,this._onContextMenu=null)},e.prototype.getClassName=function(){return"ArcRotateCameraPointersInput"},e.prototype.getSimpleName=function(){return"pointers"},b([ke.serialize()],e.prototype,"buttons",void 0),b([ke.serialize()],e.prototype,"angularSensibilityX",void 0),b([ke.serialize()],e.prototype,"angularSensibilityY",void 0),b([ke.serialize()],e.prototype,"pinchPrecision",void 0),b([ke.serialize()],e.prototype,"pinchDeltaPercentage",void 0),b([ke.serialize()],e.prototype,"panningSensibility",void 0),b([ke.serialize()],e.prototype,"multiTouchPanning",void 0),b([ke.serialize()],e.prototype,"multiTouchPanAndZoom",void 0),e})(),ke.ArcRotateCameraPointersInput=We,ke.CameraInputTypes.ArcRotateCameraPointersInput=We,He=$a||($a={}),Xe=(function(t){function e(e){return t.call(this,e)||this}return T(e,t),e.prototype.addMouseWheel=function(){return this.add(new He.ArcRotateCameraMouseWheelInput),this},e.prototype.addPointers=function(){return this.add(new He.ArcRotateCameraPointersInput),this},e.prototype.addKeyboard=function(){return this.add(new He.ArcRotateCameraKeyboardMoveInput),this},e.prototype.addVRDeviceOrientation=function(){return this.add(new He.ArcRotateCameraVRDeviceOrientationInput),this},e})(He.CameraInputsManager),He.ArcRotateCameraInputsManager=Xe,(function(l){l.Node.AddNodeConstructor("ArcRotateCamera",(function(e,t){return function(){return new i(e,0,0,1,l.Vector3.Zero(),t)}}));var i=(function(a){function n(e,t,i,r,n,o,s){void 0===s&&(s=!0);var c=a.call(this,e,l.Vector3.Zero(),o,s)||this;return c.inertialAlphaOffset=0,c.inertialBetaOffset=0,c.inertialRadiusOffset=0,c.lowerAlphaLimit=null,c.upperAlphaLimit=null,c.lowerBetaLimit=.01,c.upperBetaLimit=Math.PI,c.lowerRadiusLimit=null,c.upperRadiusLimit=null,c.inertialPanningX=0,c.inertialPanningY=0,c.pinchToPanMaxDistance=20,c.panningDistanceLimit=null,c.panningOriginTarget=l.Vector3.Zero(),c.panningInertia=.9,c.zoomOnFactor=1,c.targetScreenOffset=l.Vector2.Zero(),c.allowUpsideDown=!0,c.useInputToRestoreState=!0,c._viewMatrix=new l.Matrix,c.panningAxis=new l.Vector3(1,1,0),c.onMeshTargetChangedObservable=new l.Observable,c.checkCollisions=!1,c.collisionRadius=new l.Vector3(.5,.5,.5),c._previousPosition=l.Vector3.Zero(),c._collisionVelocity=l.Vector3.Zero(),c._newPosition=l.Vector3.Zero(),c._computationVector=l.Vector3.Zero(),c._onCollisionPositionChange=function(e,t,i){void 0===i&&(i=null),c.getScene().workerCollisions&&c.checkCollisions&&t.multiplyInPlace(c._collider._radius),i?(c.setPosition(t),c.onCollide&&c.onCollide(i)):c._previousPosition.copyFrom(c.position);var r=Math.cos(c.alpha),n=Math.sin(c.alpha),o=Math.cos(c.beta),s=Math.sin(c.beta);0===s&&(s=1e-4);var a=c._getTargetPosition();c._computationVector.copyFromFloats(c.radius*r*s,c.radius*o,c.radius*n*s),a.addToRef(c._computationVector,c._newPosition),c.position.copyFrom(c._newPosition);var l=c.upVector;c.allowUpsideDown&&c.beta<0&&(l=(l=l.clone()).negate()),c._computeViewMatrix(c.position,a,l),c._viewMatrix.m[12]+=c.targetScreenOffset.x,c._viewMatrix.m[13]+=c.targetScreenOffset.y,c._collisionTriggered=!1},c._target=l.Vector3.Zero(),n&&c.setTarget(n),c.alpha=t,c.beta=i,c.radius=r,c.getViewMatrix(),c.inputs=new l.ArcRotateCameraInputsManager(c),c.inputs.addKeyboard().addMouseWheel().addPointers(),c}return T(n,a),Object.defineProperty(n.prototype,"target",{get:function(){return this._target},set:function(e){this.setTarget(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"angularSensibilityX",{get:function(){var e=this.inputs.attached.pointers;return e?e.angularSensibilityX:0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.angularSensibilityX=e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"angularSensibilityY",{get:function(){var e=this.inputs.attached.pointers;return e?e.angularSensibilityY:0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.angularSensibilityY=e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"pinchPrecision",{get:function(){var e=this.inputs.attached.pointers;return e?e.pinchPrecision:0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.pinchPrecision=e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"pinchDeltaPercentage",{get:function(){var e=this.inputs.attached.pointers;return e?e.pinchDeltaPercentage:0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.pinchDeltaPercentage=e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"panningSensibility",{get:function(){var e=this.inputs.attached.pointers;return e?e.panningSensibility:0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.panningSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"keysUp",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysUp:[]},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysUp=e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"keysDown",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysDown:[]},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysDown=e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"keysLeft",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysLeft:[]},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysLeft=e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"keysRight",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysRight:[]},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysRight=e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"wheelPrecision",{get:function(){var e=this.inputs.attached.mousewheel;return e?e.wheelPrecision:0},set:function(e){var t=this.inputs.attached.mousewheel;t&&(t.wheelPrecision=e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"wheelDeltaPercentage",{get:function(){var e=this.inputs.attached.mousewheel;return e?e.wheelDeltaPercentage:0},set:function(e){var t=this.inputs.attached.mousewheel;t&&(t.wheelDeltaPercentage=e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bouncingBehavior",{get:function(){return this._bouncingBehavior},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"useBouncingBehavior",{get:function(){return null!=this._bouncingBehavior},set:function(e){e!==this.useBouncingBehavior&&(e?(this._bouncingBehavior=new l.BouncingBehavior,this.addBehavior(this._bouncingBehavior)):this._bouncingBehavior&&(this.removeBehavior(this._bouncingBehavior),this._bouncingBehavior=null))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"framingBehavior",{get:function(){return this._framingBehavior},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"useFramingBehavior",{get:function(){return null!=this._framingBehavior},set:function(e){e!==this.useFramingBehavior&&(e?(this._framingBehavior=new l.FramingBehavior,this.addBehavior(this._framingBehavior)):this._framingBehavior&&(this.removeBehavior(this._framingBehavior),this._framingBehavior=null))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"autoRotationBehavior",{get:function(){return this._autoRotationBehavior},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"useAutoRotationBehavior",{get:function(){return null!=this._autoRotationBehavior},set:function(e){e!==this.useAutoRotationBehavior&&(e?(this._autoRotationBehavior=new l.AutoRotationBehavior,this.addBehavior(this._autoRotationBehavior)):this._autoRotationBehavior&&(this.removeBehavior(this._autoRotationBehavior),this._autoRotationBehavior=null))},enumerable:!0,configurable:!0}),n.prototype._initCache=function(){a.prototype._initCache.call(this),this._cache._target=new l.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.alpha=void 0,this._cache.beta=void 0,this._cache.radius=void 0,this._cache.targetScreenOffset=l.Vector2.Zero()},n.prototype._updateCache=function(e){e||a.prototype._updateCache.call(this),this._cache._target.copyFrom(this._getTargetPosition()),this._cache.alpha=this.alpha,this._cache.beta=this.beta,this._cache.radius=this.radius,this._cache.targetScreenOffset.copyFrom(this.targetScreenOffset)},n.prototype._getTargetPosition=function(){if(this._targetHost&&this._targetHost.getAbsolutePosition){var e=this._targetHost.getAbsolutePosition();this._targetBoundingCenter?e.addToRef(this._targetBoundingCenter,this._target):this._target.copyFrom(e)}var t=this._getLockedTargetPosition();return t||this._target},n.prototype.storeState=function(){return this._storedAlpha=this.alpha,this._storedBeta=this.beta,this._storedRadius=this.radius,this._storedTarget=this._getTargetPosition().clone(),a.prototype.storeState.call(this)},n.prototype._restoreStateValues=function(){return!!a.prototype._restoreStateValues.call(this)&&(this.alpha=this._storedAlpha,this.beta=this._storedBeta,this.radius=this._storedRadius,this.setTarget(this._storedTarget.clone()),this.inertialAlphaOffset=0,this.inertialBetaOffset=0,this.inertialRadiusOffset=0,this.inertialPanningX=0,!(this.inertialPanningY=0))},n.prototype._isSynchronizedViewMatrix=function(){return!!a.prototype._isSynchronizedViewMatrix.call(this)&&(this._cache._target.equals(this._getTargetPosition())&&this._cache.alpha===this.alpha&&this._cache.beta===this.beta&&this._cache.radius===this.radius&&this._cache.targetScreenOffset.equals(this.targetScreenOffset))},n.prototype.attachControl=function(e,t,i,r){var n=this;void 0===i&&(i=!0),void 0===r&&(r=2),this._useCtrlForPanning=i,this._panningMouseButton=r,this.inputs.attachElement(e,t),this._reset=function(){n.inertialAlphaOffset=0,n.inertialBetaOffset=0,n.inertialRadiusOffset=0,n.inertialPanningX=0,n.inertialPanningY=0}},n.prototype.detachControl=function(e){this.inputs.detachElement(e),this._reset&&this._reset()},n.prototype._checkInputs=function(){if(!this._collisionTriggered){if(this.inputs.checkInputs(),0!==this.inertialAlphaOffset||0!==this.inertialBetaOffset||0!==this.inertialRadiusOffset){var e=this.inertialAlphaOffset;this.beta<=0&&(e*=-1),this.getScene().useRightHandedSystem&&(e*=-1),this.parent&&this.parent._getWorldMatrixDeterminant()<0&&(e*=-1),this.alpha+=e,this.beta+=this.inertialBetaOffset,this.radius-=this.inertialRadiusOffset,this.inertialAlphaOffset*=this.inertia,this.inertialBetaOffset*=this.inertia,this.inertialRadiusOffset*=this.inertia,Math.abs(this.inertialAlphaOffset)Math.PI&&(this.beta=this.beta-2*Math.PI):this.betathis.upperBetaLimit&&(this.beta=this.upperBetaLimit),null!==this.lowerAlphaLimit&&this.alphathis.upperAlphaLimit&&(this.alpha=this.upperAlphaLimit),null!==this.lowerRadiusLimit&&this.radiusthis.upperRadiusLimit&&(this.radius=this.upperRadiusLimit)},n.prototype.rebuildAnglesAndRadius=function(){this.position.subtractToRef(this._getTargetPosition(),this._computationVector),this.radius=this._computationVector.length(),0===this.radius&&(this.radius=1e-4),this.alpha=Math.acos(this._computationVector.x/Math.sqrt(Math.pow(this._computationVector.x,2)+Math.pow(this._computationVector.z,2))),this._computationVector.z<0&&(this.alpha=2*Math.PI-this.alpha),this.beta=Math.acos(this._computationVector.y/this.radius),this._checkLimits()},n.prototype.setPosition=function(e){this.position.equals(e)||(this.position.copyFrom(e),this.rebuildAnglesAndRadius())},n.prototype.setTarget=function(e,t,i){if(void 0===t&&(t=!1),void 0===i&&(i=!1),e.getBoundingInfo)this._targetBoundingCenter=t?e.getBoundingInfo().boundingBox.centerWorld.clone():null,this._targetHost=e,this._target=this._getTargetPosition(),this.onMeshTargetChangedObservable.notifyObservers(this._targetHost);else{var r=e,n=this._getTargetPosition();if(n&&!i&&n.equals(r))return;this._targetHost=null,this._target=r,this._targetBoundingCenter=null,this.onMeshTargetChangedObservable.notifyObservers(null)}this.rebuildAnglesAndRadius()},n.prototype._getViewMatrix=function(){var e=Math.cos(this.alpha),t=Math.sin(this.alpha),i=Math.cos(this.beta),r=Math.sin(this.beta);0===r&&(r=1e-4);var n=this._getTargetPosition();if(this._computationVector.copyFromFloats(this.radius*e*r,this.radius*i,this.radius*t*r),n.addToRef(this._computationVector,this._newPosition),this.getScene().collisionsEnabled&&this.checkCollisions)this._collider||(this._collider=new l.Collider),this._collider._radius=this.collisionRadius,this._newPosition.subtractToRef(this.position,this._collisionVelocity),this._collisionTriggered=!0,this.getScene().collisionCoordinator.getNewPosition(this.position,this._collisionVelocity,this._collider,3,null,this._onCollisionPositionChange,this.uniqueId);else{this.position.copyFrom(this._newPosition);var o=this.upVector;this.allowUpsideDown&&r<0&&(o=(o=o.clone()).negate()),this._computeViewMatrix(this.position,n,o),this._viewMatrix.m[12]+=this.targetScreenOffset.x,this._viewMatrix.m[13]+=this.targetScreenOffset.y}return this._currentTarget=n,this._viewMatrix},n.prototype.zoomOn=function(e,t){void 0===t&&(t=!1),e=e||this.getScene().meshes;var i=l.Mesh.MinMax(e),r=l.Vector3.Distance(i.min,i.max);this.radius=r*this.zoomOnFactor,this.focusOn({min:i.min,max:i.max,distance:r},t)},n.prototype.focusOn=function(e,t){var i,r;if(void 0===t&&(t=!1),void 0===e.min){var n=e||this.getScene().meshes;i=l.Mesh.MinMax(n),r=l.Vector3.Distance(i.min,i.max)}else{var o=e;r=(i=o).distance}this._target=l.Mesh.Center(i),t||(this.maxZ=2*r)},n.prototype.createRigCamera=function(e,t){var i=0;switch(this.cameraRigMode){case l.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case l.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case l.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:case l.Camera.RIG_MODE_VR:i=this._cameraRigParams.stereoHalfAngle*(0===t?1:-1);break;case l.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:i=this._cameraRigParams.stereoHalfAngle*(0===t?-1:1)}var r=new n(e,this.alpha+i,this.beta,this.radius,this._target,this.getScene());return r._cameraRigParams={},r},n.prototype._updateRigCameras=function(){var e=this._rigCameras[0],t=this._rigCameras[1];switch(e.beta=t.beta=this.beta,e.radius=t.radius=this.radius,this.cameraRigMode){case l.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case l.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case l.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:case l.Camera.RIG_MODE_VR:e.alpha=this.alpha-this._cameraRigParams.stereoHalfAngle,t.alpha=this.alpha+this._cameraRigParams.stereoHalfAngle;break;case l.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:e.alpha=this.alpha+this._cameraRigParams.stereoHalfAngle,t.alpha=this.alpha-this._cameraRigParams.stereoHalfAngle}a.prototype._updateRigCameras.call(this)},n.prototype.dispose=function(){this.inputs.clear(),a.prototype.dispose.call(this)},n.prototype.getClassName=function(){return"ArcRotateCamera"},b([l.serialize()],n.prototype,"alpha",void 0),b([l.serialize()],n.prototype,"beta",void 0),b([l.serialize()],n.prototype,"radius",void 0),b([l.serializeAsVector3("target")],n.prototype,"_target",void 0),b([l.serialize()],n.prototype,"inertialAlphaOffset",void 0),b([l.serialize()],n.prototype,"inertialBetaOffset",void 0),b([l.serialize()],n.prototype,"inertialRadiusOffset",void 0),b([l.serialize()],n.prototype,"lowerAlphaLimit",void 0),b([l.serialize()],n.prototype,"upperAlphaLimit",void 0),b([l.serialize()],n.prototype,"lowerBetaLimit",void 0),b([l.serialize()],n.prototype,"upperBetaLimit",void 0),b([l.serialize()],n.prototype,"lowerRadiusLimit",void 0),b([l.serialize()],n.prototype,"upperRadiusLimit",void 0),b([l.serialize()],n.prototype,"inertialPanningX",void 0),b([l.serialize()],n.prototype,"inertialPanningY",void 0),b([l.serialize()],n.prototype,"pinchToPanMaxDistance",void 0),b([l.serialize()],n.prototype,"panningDistanceLimit",void 0),b([l.serializeAsVector3()],n.prototype,"panningOriginTarget",void 0),b([l.serialize()],n.prototype,"panningInertia",void 0),b([l.serialize()],n.prototype,"zoomOnFactor",void 0),b([l.serialize()],n.prototype,"targetScreenOffset",void 0),b([l.serialize()],n.prototype,"allowUpsideDown",void 0),b([l.serialize()],n.prototype,"useInputToRestoreState",void 0),n})(l.TargetCamera);l.ArcRotateCamera=i})($a||($a={})),(function(o){o.Node.AddNodeConstructor("Light_Type_3",(function(e,t){return function(){return new i(e,o.Vector3.Zero(),t)}}));var i=(function(n){function e(e,t,i){var r=n.call(this,e,i)||this;return r.groundColor=new o.Color3(0,0,0),r.direction=t||o.Vector3.Up(),r}return T(e,n),e.prototype._buildUniformLayout=function(){this._uniformBuffer.addUniform("vLightData",4),this._uniformBuffer.addUniform("vLightDiffuse",4),this._uniformBuffer.addUniform("vLightSpecular",3),this._uniformBuffer.addUniform("vLightGround",3),this._uniformBuffer.addUniform("shadowsInfo",3),this._uniformBuffer.addUniform("depthValues",2),this._uniformBuffer.create()},e.prototype.getClassName=function(){return"HemisphericLight"},e.prototype.setDirectionToTarget=function(e){return this.direction=o.Vector3.Normalize(e.subtract(o.Vector3.Zero())),this.direction},e.prototype.getShadowGenerator=function(){return null},e.prototype.transferToEffect=function(e,t){var i=o.Vector3.Normalize(this.direction);return this._uniformBuffer.updateFloat4("vLightData",i.x,i.y,i.z,0,t),this._uniformBuffer.updateColor3("vLightGround",this.groundColor.scale(this.intensity),t),this},e.prototype.computeWorldMatrix=function(e,t){return this._worldMatrix||(this._worldMatrix=o.Matrix.Identity()),this._worldMatrix},e.prototype.getTypeID=function(){return o.Light.LIGHTTYPEID_HEMISPHERICLIGHT},e.prototype.prepareLightSpecificDefines=function(e,t){e["HEMILIGHT"+t]=!0},b([o.serializeAsColor3()],e.prototype,"groundColor",void 0),b([o.serializeAsVector3()],e.prototype,"direction",void 0),e})(o.Light);o.HemisphericLight=i})($a||($a={})),je=$a||($a={}),Ye=(function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._needProjectionMatrixCompute=!0,e}return T(e,t),e.prototype._setPosition=function(e){this._position=e},Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(e){this._setPosition(e)},enumerable:!0,configurable:!0}),e.prototype._setDirection=function(e){this._direction=e},Object.defineProperty(e.prototype,"direction",{get:function(){return this._direction},set:function(e){this._setDirection(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"shadowMinZ",{get:function(){return this._shadowMinZ},set:function(e){this._shadowMinZ=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"shadowMaxZ",{get:function(){return this._shadowMaxZ},set:function(e){this._shadowMaxZ=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),e.prototype.computeTransformedInformation=function(){return!(!this.parent||!this.parent.getWorldMatrix)&&(this.transformedPosition||(this.transformedPosition=je.Vector3.Zero()),je.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this.transformedPosition),this.direction&&(this.transformedDirection||(this.transformedDirection=je.Vector3.Zero()),je.Vector3.TransformNormalToRef(this.direction,this.parent.getWorldMatrix(),this.transformedDirection)),!0)},e.prototype.getDepthScale=function(){return 50},e.prototype.getShadowDirection=function(e){return this.transformedDirection?this.transformedDirection:this.direction},e.prototype.getAbsolutePosition=function(){return this.transformedPosition?this.transformedPosition:this.position},e.prototype.setDirectionToTarget=function(e){return this.direction=je.Vector3.Normalize(e.subtract(this.position)),this.direction},e.prototype.getRotation=function(){this.direction.normalize();var e=je.Vector3.Cross(this.direction,je.Axis.Y),t=je.Vector3.Cross(e,this.direction);return je.Vector3.RotationFromAxis(e,t,this.direction)},e.prototype.needCube=function(){return!1},e.prototype.needProjectionMatrixCompute=function(){return this._needProjectionMatrixCompute},e.prototype.forceProjectionMatrixCompute=function(){this._needProjectionMatrixCompute=!0},e.prototype._initCache=function(){t.prototype._initCache.call(this),this._cache.position=je.Vector3.Zero()},e.prototype._isSynchronized=function(){return!!this._cache.position.equals(this.position)},e.prototype.computeWorldMatrix=function(e){return!e&&this.isSynchronized()?this._currentRenderId=this.getScene().getRenderId():(this._updateCache(),this._cache.position.copyFrom(this.position),this._worldMatrix||(this._worldMatrix=je.Matrix.Identity()),je.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix),this.parent&&this.parent.getWorldMatrix&&(this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(),this._worldMatrix),this._markSyncedWithParent()),this._worldMatrixDeterminant=this._worldMatrix.determinant()),this._worldMatrix},e.prototype.getDepthMinZ=function(e){return void 0!==this.shadowMinZ?this.shadowMinZ:e.minZ},e.prototype.getDepthMaxZ=function(e){return void 0!==this.shadowMaxZ?this.shadowMaxZ:e.maxZ},e.prototype.setShadowProjectionMatrix=function(e,t,i){return this.customProjectionMatrixBuilder?this.customProjectionMatrixBuilder(t,i,e):this._setDefaultShadowProjectionMatrix(e,t,i),this},b([je.serializeAsVector3()],e.prototype,"position",null),b([je.serializeAsVector3()],e.prototype,"direction",null),b([je.serialize()],e.prototype,"shadowMinZ",null),b([je.serialize()],e.prototype,"shadowMaxZ",null),e})(je.Light),je.ShadowLight=Ye,(function(o){o.Node.AddNodeConstructor("Light_Type_0",(function(e,t){return function(){return new i(e,o.Vector3.Zero(),t)}}));var i=(function(n){function e(e,t,i){var r=n.call(this,e,i)||this;return r._shadowAngle=Math.PI/2,r.position=t,r}return T(e,n),Object.defineProperty(e.prototype,"shadowAngle",{get:function(){return this._shadowAngle},set:function(e){this._shadowAngle=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"direction",{get:function(){return this._direction},set:function(e){var t=this.needCube();this._direction=e,this.needCube()!==t&&this._shadowGenerator&&this._shadowGenerator.recreateShadowMap()},enumerable:!0,configurable:!0}),e.prototype.getClassName=function(){return"PointLight"},e.prototype.getTypeID=function(){return o.Light.LIGHTTYPEID_POINTLIGHT},e.prototype.needCube=function(){return!this.direction},e.prototype.getShadowDirection=function(e){if(this.direction)return n.prototype.getShadowDirection.call(this,e);switch(e){case 0:return new o.Vector3(1,0,0);case 1:return new o.Vector3(-1,0,0);case 2:return new o.Vector3(0,-1,0);case 3:return new o.Vector3(0,1,0);case 4:return new o.Vector3(0,0,1);case 5:return new o.Vector3(0,0,-1)}return o.Vector3.Zero()},e.prototype._setDefaultShadowProjectionMatrix=function(e,t,i){var r=this.getScene().activeCamera;r&&o.Matrix.PerspectiveFovLHToRef(this.shadowAngle,1,this.getDepthMinZ(r),this.getDepthMaxZ(r),e)},e.prototype._buildUniformLayout=function(){this._uniformBuffer.addUniform("vLightData",4),this._uniformBuffer.addUniform("vLightDiffuse",4),this._uniformBuffer.addUniform("vLightSpecular",3),this._uniformBuffer.addUniform("vLightFalloff",4),this._uniformBuffer.addUniform("shadowsInfo",3),this._uniformBuffer.addUniform("depthValues",2),this._uniformBuffer.create()},e.prototype.transferToEffect=function(e,t){return this.computeTransformedInformation()?this._uniformBuffer.updateFloat4("vLightData",this.transformedPosition.x,this.transformedPosition.y,this.transformedPosition.z,0,t):this._uniformBuffer.updateFloat4("vLightData",this.position.x,this.position.y,this.position.z,0,t),this._uniformBuffer.updateFloat4("vLightFalloff",this.range,this._inverseSquaredRange,0,0,t),this},e.prototype.prepareLightSpecificDefines=function(e,t){e["POINTLIGHT"+t]=!0},b([o.serialize()],e.prototype,"shadowAngle",null),e})(o.ShadowLight);o.PointLight=i})($a||($a={})),(function(u){u.Node.AddNodeConstructor("Light_Type_1",(function(e,t){return function(){return new i(e,u.Vector3.Zero(),t)}}));var i=(function(n){function e(e,t,i){var r=n.call(this,e,i)||this;return r._shadowFrustumSize=0,r._shadowOrthoScale=.1,r.autoUpdateExtends=!0,r._orthoLeft=Number.MAX_VALUE,r._orthoRight=Number.MIN_VALUE,r._orthoTop=Number.MIN_VALUE,r._orthoBottom=Number.MAX_VALUE,r.position=t.scale(-1),r.direction=t,r}return T(e,n),Object.defineProperty(e.prototype,"shadowFrustumSize",{get:function(){return this._shadowFrustumSize},set:function(e){this._shadowFrustumSize=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"shadowOrthoScale",{get:function(){return this._shadowOrthoScale},set:function(e){this._shadowOrthoScale=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),e.prototype.getClassName=function(){return"DirectionalLight"},e.prototype.getTypeID=function(){return u.Light.LIGHTTYPEID_DIRECTIONALLIGHT},e.prototype._setDefaultShadowProjectionMatrix=function(e,t,i){0this._orthoRight&&(this._orthoRight=n.x),n.y>this._orthoTop&&(this._orthoTop=n.y)}}var c=this._orthoRight-this._orthoLeft,h=this._orthoTop-this._orthoBottom;u.Matrix.OrthoOffCenterLHToRef(this._orthoLeft-c*this.shadowOrthoScale,this._orthoRight+c*this.shadowOrthoScale,this._orthoBottom-h*this.shadowOrthoScale,this._orthoTop+h*this.shadowOrthoScale,void 0!==this.shadowMinZ?this.shadowMinZ:r.minZ,void 0!==this.shadowMaxZ?this.shadowMaxZ:r.maxZ,e)}},e.prototype._buildUniformLayout=function(){this._uniformBuffer.addUniform("vLightData",4),this._uniformBuffer.addUniform("vLightDiffuse",4),this._uniformBuffer.addUniform("vLightSpecular",3),this._uniformBuffer.addUniform("shadowsInfo",3),this._uniformBuffer.addUniform("depthValues",2),this._uniformBuffer.create()},e.prototype.transferToEffect=function(e,t){return this.computeTransformedInformation()?this._uniformBuffer.updateFloat4("vLightData",this.transformedDirection.x,this.transformedDirection.y,this.transformedDirection.z,1,t):this._uniformBuffer.updateFloat4("vLightData",this.direction.x,this.direction.y,this.direction.z,1,t),this},e.prototype.getDepthMinZ=function(e){return 1},e.prototype.getDepthMaxZ=function(e){return 1},e.prototype.prepareLightSpecificDefines=function(e,t){e["DIRLIGHT"+t]=!0},b([u.serialize()],e.prototype,"shadowFrustumSize",null),b([u.serialize()],e.prototype,"shadowOrthoScale",null),b([u.serialize()],e.prototype,"autoUpdateExtends",void 0),e})(u.ShadowLight);u.DirectionalLight=i})($a||($a={})),(function(l){l.Node.AddNodeConstructor("Light_Type_2",(function(e,t){return function(){return new i(e,l.Vector3.Zero(),l.Vector3.Zero(),0,0,t)}}));var i=(function(a){function e(e,t,i,r,n,o){var s=a.call(this,e,o)||this;return s._innerAngle=0,s._projectionTextureMatrix=l.Matrix.Zero(),s._projectionTextureLightNear=1e-6,s._projectionTextureLightFar=1e3,s._projectionTextureUpDirection=l.Vector3.Up(),s._projectionTextureViewLightDirty=!0,s._projectionTextureProjectionLightDirty=!0,s._projectionTextureDirty=!0,s._projectionTextureViewTargetVector=l.Vector3.Zero(),s._projectionTextureViewLightMatrix=l.Matrix.Zero(),s._projectionTextureProjectionLightMatrix=l.Matrix.Zero(),s._projectionTextureScalingMatrix=l.Matrix.FromValues(.5,0,0,0,0,.5,0,0,0,0,.5,0,.5,.5,.5,1),s.position=t,s.direction=i,s.angle=r,s.exponent=n,s}return T(e,a),Object.defineProperty(e.prototype,"angle",{get:function(){return this._angle},set:function(e){this._angle=e,this._cosHalfAngle=Math.cos(.5*e),this._projectionTextureProjectionLightDirty=!0,this.forceProjectionMatrixCompute(),this._computeAngleValues()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"innerAngle",{get:function(){return this._innerAngle},set:function(e){this._innerAngle=e,this._computeAngleValues()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"shadowAngleScale",{get:function(){return this._shadowAngleScale},set:function(e){this._shadowAngleScale=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"projectionTextureMatrix",{get:function(){return this._projectionTextureMatrix},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"projectionTextureLightNear",{get:function(){return this._projectionTextureLightNear},set:function(e){this._projectionTextureLightNear=e,this._projectionTextureProjectionLightDirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"projectionTextureLightFar",{get:function(){return this._projectionTextureLightFar},set:function(e){this._projectionTextureLightFar=e,this._projectionTextureProjectionLightDirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"projectionTextureUpDirection",{get:function(){return this._projectionTextureUpDirection},set:function(e){this._projectionTextureUpDirection=e,this._projectionTextureProjectionLightDirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"projectionTexture",{get:function(){return this._projectionTexture},set:function(e){this._projectionTexture=e,this._projectionTextureDirty=!0},enumerable:!0,configurable:!0}),e.prototype.getClassName=function(){return"SpotLight"},e.prototype.getTypeID=function(){return l.Light.LIGHTTYPEID_SPOTLIGHT},e.prototype._setDirection=function(e){a.prototype._setDirection.call(this,e),this._projectionTextureViewLightDirty=!0},e.prototype._setPosition=function(e){a.prototype._setPosition.call(this,e),this._projectionTextureViewLightDirty=!0},e.prototype._setDefaultShadowProjectionMatrix=function(e,t,i){var r=this.getScene().activeCamera;if(r){this._shadowAngleScale=this._shadowAngleScale||1;var n=this._shadowAngleScale*this._angle;l.Matrix.PerspectiveFovLHToRef(n,1,this.getDepthMinZ(r),this.getDepthMaxZ(r),e)}},e.prototype._computeProjectionTextureViewLightMatrix=function(){this._projectionTextureViewLightDirty=!1,this._projectionTextureDirty=!0,this.position.addToRef(this.direction,this._projectionTextureViewTargetVector),l.Matrix.LookAtLHToRef(this.position,this._projectionTextureViewTargetVector,this._projectionTextureUpDirection,this._projectionTextureViewLightMatrix)},e.prototype._computeProjectionTextureProjectionLightMatrix=function(){this._projectionTextureProjectionLightDirty=!1,this._projectionTextureDirty=!0;var e=this.projectionTextureLightFar,t=this.projectionTextureLightNear,i=e/(e-t),r=-i*t,n=1/Math.tan(this._angle/2);l.Matrix.FromValuesToRef(n/1,0,0,0,0,n,0,0,0,0,i,1,0,0,r,0,this._projectionTextureProjectionLightMatrix)},e.prototype._computeProjectionTextureMatrix=function(){this._projectionTextureDirty=!1,this._projectionTextureViewLightMatrix.multiplyToRef(this._projectionTextureProjectionLightMatrix,this._projectionTextureMatrix),this._projectionTextureMatrix.multiplyToRef(this._projectionTextureScalingMatrix,this._projectionTextureMatrix)},e.prototype._buildUniformLayout=function(){this._uniformBuffer.addUniform("vLightData",4),this._uniformBuffer.addUniform("vLightDiffuse",4),this._uniformBuffer.addUniform("vLightSpecular",3),this._uniformBuffer.addUniform("vLightDirection",3),this._uniformBuffer.addUniform("vLightFalloff",4),this._uniformBuffer.addUniform("shadowsInfo",3),this._uniformBuffer.addUniform("depthValues",2),this._uniformBuffer.create()},e.prototype._computeAngleValues=function(){this._lightAngleScale=1/Math.max(.001,Math.cos(.5*this._innerAngle)-this._cosHalfAngle),this._lightAngleOffset=-this._cosHalfAngle*this._lightAngleScale},e.prototype.transferToEffect=function(e,t){var i;return this.computeTransformedInformation()?(this._uniformBuffer.updateFloat4("vLightData",this.transformedPosition.x,this.transformedPosition.y,this.transformedPosition.z,this.exponent,t),i=l.Vector3.Normalize(this.transformedDirection)):(this._uniformBuffer.updateFloat4("vLightData",this.position.x,this.position.y,this.position.z,this.exponent,t),i=l.Vector3.Normalize(this.direction)),this._uniformBuffer.updateFloat4("vLightDirection",i.x,i.y,i.z,this._cosHalfAngle,t),this._uniformBuffer.updateFloat4("vLightFalloff",this.range,this._inverseSquaredRange,this._lightAngleScale,this._lightAngleOffset,t),this.projectionTexture&&this.projectionTexture.isReady()&&(this._projectionTextureViewLightDirty&&this._computeProjectionTextureViewLightMatrix(),this._projectionTextureProjectionLightDirty&&this._computeProjectionTextureProjectionLightMatrix(),this._projectionTextureDirty&&this._computeProjectionTextureMatrix(),e.setMatrix("textureProjectionMatrix"+t,this._projectionTextureMatrix),e.setTexture("projectionLightSampler"+t,this.projectionTexture)),this},e.prototype.dispose=function(){a.prototype.dispose.call(this),this._projectionTexture&&this._projectionTexture.dispose()},e.prototype.prepareLightSpecificDefines=function(e,t){e["SPOTLIGHT"+t]=!0,e["PROJECTEDLIGHTTEXTURE"+t]=!!this.projectionTexture},b([l.serialize()],e.prototype,"angle",null),b([l.serialize()],e.prototype,"innerAngle",null),b([l.serialize()],e.prototype,"shadowAngleScale",null),b([l.serialize()],e.prototype,"exponent",void 0),b([l.serialize()],e.prototype,"projectionTextureLightNear",null),b([l.serialize()],e.prototype,"projectionTextureLightFar",null),b([l.serialize()],e.prototype,"projectionTextureUpDirection",null),b([l.serializeAsTexture("projectedLightTexture")],e.prototype,"_projectionTexture",void 0),e})(l.ShadowLight);l.SpotLight=i})($a||($a={})),Ke=$a||($a={}),Qe=function(){this.enableBlending=!1,this.blendingSpeed=.01,this.loopMode=Ke.Animation.ANIMATIONLOOPMODE_CYCLE},Ke.AnimationPropertiesOverride=Qe,(function(d){var r=(function(){function e(e,t,i){this.name=e,this.from=t,this.to=i}return e.prototype.clone=function(){return new e(this.name,this.from,this.to)},e})();d.AnimationRange=r;var e=(function(){function e(e,t,i){this.frame=e,this.action=t,this.onlyOnce=i,this.isDone=!1}return e.prototype._clone=function(){return new e(this.frame,this.action,this.onlyOnce)},e})();d.AnimationEvent=e;var x,t,i=(function(){function e(e){this.path=e,this._onchange=new Array,this.value=0,this.animations=new Array}return e.prototype.getPoint=function(){var e=this.path.getPointAtLengthPosition(this.value);return new d.Vector3(e.x,0,e.y)},e.prototype.moveAhead=function(e){return void 0===e&&(e=.002),this.move(e),this},e.prototype.moveBack=function(e){return void 0===e&&(e=.002),this.move(-e),this},e.prototype.move=function(e){if(1=r&&this._keys[o].frame<=n&&this._keys.splice(o,1);this._ranges[e]=null}},T.prototype.getRange=function(e){return this._ranges[e]},T.prototype.getKeys=function(){return this._keys},T.prototype.getHighestFrame=function(){for(var e=0,t=0,i=this._keys.length;t=e)for(;0<=a-1&&s[a].frame>=e;)a--;for(var l=a;l=e){var h=s[l],u=this._getKeyValue(h.value);if(h.interpolation===x.STEP)return u;var d=this._getKeyValue(c.value),f=void 0!==h.outTangent&&void 0!==c.inTangent,p=c.frame-h.frame,m=(e-h.frame)/p,_=this.getEasingFunction();switch(null!=_&&(m=_.ease(m)),this.dataType){case T.ANIMATIONTYPE_FLOAT:var g=f?this.floatInterpolateFunctionWithTangents(u,h.outTangent*p,d,c.inTangent*p,m):this.floatInterpolateFunction(u,d,m);switch(r){case T.ANIMATIONLOOPMODE_CYCLE:case T.ANIMATIONLOOPMODE_CONSTANT:return g;case T.ANIMATIONLOOPMODE_RELATIVE:return n*t+g}break;case T.ANIMATIONTYPE_QUATERNION:var v=f?this.quaternionInterpolateFunctionWithTangents(u,h.outTangent.scale(p),d,c.inTangent.scale(p),m):this.quaternionInterpolateFunction(u,d,m);switch(r){case T.ANIMATIONLOOPMODE_CYCLE:case T.ANIMATIONLOOPMODE_CONSTANT:return v;case T.ANIMATIONLOOPMODE_RELATIVE:return v.addInPlace(n.scale(t))}return v;case T.ANIMATIONTYPE_VECTOR3:var y=f?this.vector3InterpolateFunctionWithTangents(u,h.outTangent.scale(p),d,c.inTangent.scale(p),m):this.vector3InterpolateFunction(u,d,m);switch(r){case T.ANIMATIONLOOPMODE_CYCLE:case T.ANIMATIONLOOPMODE_CONSTANT:return y;case T.ANIMATIONLOOPMODE_RELATIVE:return y.add(n.scale(t))}case T.ANIMATIONTYPE_VECTOR2:var b=f?this.vector2InterpolateFunctionWithTangents(u,h.outTangent.scale(p),d,c.inTangent.scale(p),m):this.vector2InterpolateFunction(u,d,m);switch(r){case T.ANIMATIONLOOPMODE_CYCLE:case T.ANIMATIONLOOPMODE_CONSTANT:return b;case T.ANIMATIONLOOPMODE_RELATIVE:return b.add(n.scale(t))}case T.ANIMATIONTYPE_SIZE:switch(r){case T.ANIMATIONLOOPMODE_CYCLE:case T.ANIMATIONLOOPMODE_CONSTANT:return this.sizeInterpolateFunction(u,d,m);case T.ANIMATIONLOOPMODE_RELATIVE:return this.sizeInterpolateFunction(u,d,m).add(n.scale(t))}case T.ANIMATIONTYPE_COLOR3:switch(r){case T.ANIMATIONLOOPMODE_CYCLE:case T.ANIMATIONLOOPMODE_CONSTANT:return this.color3InterpolateFunction(u,d,m);case T.ANIMATIONLOOPMODE_RELATIVE:return this.color3InterpolateFunction(u,d,m).add(n.scale(t))}case T.ANIMATIONTYPE_MATRIX:switch(r){case T.ANIMATIONLOOPMODE_CYCLE:case T.ANIMATIONLOOPMODE_CONSTANT:if(T.AllowMatricesInterpolation)return this.matrixInterpolateFunction(u,d,m,i);case T.ANIMATIONLOOPMODE_RELATIVE:return u}}break}}return this._getKeyValue(s[s.length-1].value)},T.prototype.matrixInterpolateFunction=function(e,t,i,r){return T.AllowMatrixDecomposeForInterpolation?r?(d.Matrix.DecomposeLerpToRef(e,t,i,r),r):d.Matrix.DecomposeLerp(e,t,i):r?(d.Matrix.LerpToRef(e,t,i,r),r):d.Matrix.Lerp(e,t,i)},T.prototype.clone=function(){var e=new T(this.name,this.targetPropertyPath.join("."),this.framePerSecond,this.dataType,this.loopMode);if(e.enableBlending=this.enableBlending,e.blendingSpeed=this.blendingSpeed,this._keys&&e.setKeys(this._keys),this._ranges)for(var t in e._ranges={},this._ranges){var i=this._ranges[t];i&&(e._ranges[t]=i.clone())}return e},T.prototype.setKeys=function(e){this._keys=e.slice(0)},T.prototype.serialize=function(){var e={};e.name=this.name,e.property=this.targetProperty,e.framePerSecond=this.framePerSecond,e.dataType=this.dataType,e.loopBehavior=this.loopMode,e.enableBlending=this.enableBlending,e.blendingSpeed=this.blendingSpeed;var t=this.dataType;e.keys=[];for(var i=this.getKeys(),r=0;rr[0].frame&&(this._from=r[0].frame),this._toe){var s={frame:e,value:n.value,inTangent:n.inTangent,outTangent:n.outTangent,interpolation:n.interpolation};r.splice(0,0,s)}if(o.framet[t.length-1].frame&&(e=t[t.length-1].frame);var i=this._interpolate(e,0,this._getCorrectLoopMode());this.setValue(i,-1)},e.prototype._prepareForSpeedRatioChange=function(e){var t=this._previousDelay*(this._animation.framePerSecond*e)/1e3;this._ratioOffset=this._previousRatio-t},e.prototype.animate=function(e,t,i,r,n,o){void 0===o&&(o=-1);var s=this._animation.targetPropertyPath;if(!s||s.length<1)return!(this._stopped=!0);var a=!0,l=this._animation.getKeys();if(0!==l[0].frame){var c={frame:0,value:l[0].value};l.splice(0,0,c)}else if(1===l.length){c={frame:.001,value:l[0].value};l.push(c)}(tl[l.length-1].frame)&&(t=l[0].frame),(il[l.length-1].frame)&&(i=l[l.length-1].frame),t===i&&(t>l[0].frame?t--:i>0,v=a?t+d%u:i;if(this._host&&this._host.syncRoot){var y=this._host.syncRoot;v=t+(i-t)*((y.masterFrame-y.fromFrame)/(y.toFrame-y.fromFrame))}var b=this._events;if(0v||u<0&&this.currentFrame=b[T].frame&&b[T].frame>=t||u<0&&v<=b[T].frame&&b[T].frame<=t){var E=b[T];E.isDone||(E.onlyOnce&&(b.splice(T,1),T--),E.isDone=!0,E.action(v))}return a||(this._stopped=!0),a},e})(),Ze.RuntimeAnimation=it,rt=$a||($a={}),nt=(function(){function e(e,t,i,r,n,o,s,a){void 0===i&&(i=0),void 0===r&&(r=100),void 0===n&&(n=!1),void 0===o&&(o=1),this.target=t,this.fromFrame=i,this.toFrame=r,this.loopAnimation=n,this.onAnimationEnd=s,this._localDelayOffset=null,this._pausedDelay=null,this._runtimeAnimations=new Array,this._paused=!1,this._speedRatio=1,this._weight=-1,this.disposeOnEnd=!0,this.animationStarted=!1,this.onAnimationEndObservable=new rt.Observable,this._scene=e,a&&this.appendAnimations(t,a),this._speedRatio=o,e._activeAnimatables.push(this)}return Object.defineProperty(e.prototype,"syncRoot",{get:function(){return this._syncRoot},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"masterFrame",{get:function(){return 0===this._runtimeAnimations.length?0:this._runtimeAnimations[0].currentFrame},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"weight",{get:function(){return this._weight},set:function(e){this._weight=-1!==e?Math.min(Math.max(e,0),1):-1},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"speedRatio",{get:function(){return this._speedRatio},set:function(e){for(var t=0;tthis.value;case a.IsLesser:return this._effectiveTarget[this._property]=P.OnPickTrigger&&t.trigger<=P.OnPointerOutTrigger)return!0}return!1},enumerable:!0,configurable:!0}),Object.defineProperty(P.prototype,"hasPickTriggers",{get:function(){for(var e=0;e=P.OnPickTrigger&&t.trigger<=P.OnPickUpTrigger)return!0}return!1},enumerable:!0,configurable:!0}),Object.defineProperty(P,"HasTriggers",{get:function(){for(var e in P.Triggers)if(P.Triggers.hasOwnProperty(e))return!0;return!1},enumerable:!0,configurable:!0}),Object.defineProperty(P,"HasPickTriggers",{get:function(){for(var e in P.Triggers)if(P.Triggers.hasOwnProperty(e)){var t=parseInt(e);if(P.OnPickTrigger<=t&&t<=P.OnPickUpTrigger)return!0}return!1},enumerable:!0,configurable:!0}),P.HasSpecificTrigger=function(e){for(var t in P.Triggers){if(P.Triggers.hasOwnProperty(t))if(parseInt(t)===e)return!0}return!1},P.prototype.registerAction=function(e){return e.trigger===P.OnEveryFrameTrigger&&this.getScene().actionManager!==this?(S.Tools.Warn("OnEveryFrameTrigger can only be used with scene.actionManager"),null):(this.actions.push(e),P.Triggers[e.trigger]?P.Triggers[e.trigger]++:P.Triggers[e.trigger]=1,e._actionManager=this,e._prepare(),e)},P.prototype.unregisterAction=function(e){var t=this.actions.indexOf(e);return-1!==t&&(this.actions.splice(t,1),P.Triggers[e.trigger]-=1,0===P.Triggers[e.trigger]&&delete P.Triggers[e.trigger],delete e._actionManager,!0)},P.prototype.processTrigger=function(e,t){for(var i=0;i>0;this._vertexData[o+10]=t.cellIndex-s*n,this._vertexData[o+11]=s,this._vertexData[o+12]=t.color.r,this._vertexData[o+13]=t.color.g,this._vertexData[o+14]=t.color.b,this._vertexData[o+15]=t.color.a},e.prototype.intersects=function(e,t,i,r){for(var n=Math.min(this._capacity,this.sprites.length),o=ct.Vector3.Zero(),s=ct.Vector3.Zero(),a=Number.MAX_VALUE,l=null,c=ct.Vector3.Zero(),h=t.getViewMatrix(),u=0;uthis._delay&&(this._time=this._time%this._delay,this.cellIndex+=this._direction,this.cellIndex>this._toIndex&&(this._loopAnimation?this.cellIndex=this._fromIndex:(this.cellIndex=this._toIndex,this._animationStarted=!1,this._onAnimationEnd&&this._onAnimationEnd(),this.disposeWhenFinishedAnimating&&this.dispose()))))},e.prototype.dispose=function(){for(var e=0;e=n.distance))&&(n=a,i))break}}return n||new l.PickingInfo},l.Scene.prototype.pickSprite=function(e,t,i,r,n){return this.createPickingRayInCameraSpaceToRef(e,t,this._tempSpritePickingRay,n),this._internalPickSprites(this._tempSpritePickingRay,i,r,n)},l.Scene.prototype.pickSpriteWithRay=function(e,t,i,r){if(!this._tempSpritePickingRay)return null;if(!r){if(!this.activeCamera)return null;r=this.activeCamera}return l.Ray.TransformToRef(e,r.getViewMatrix(),this._tempSpritePickingRay),this._internalPickSprites(this._tempSpritePickingRay,t,i,r)},l.Scene.prototype.setPointerOverSprite=function(e){this._pointerOverSprite!==e&&(this._pointerOverSprite&&this._pointerOverSprite.actionManager&&this._pointerOverSprite.actionManager.processTrigger(l.ActionManager.OnPointerOutTrigger,l.ActionEvent.CreateNewFromSprite(this._pointerOverSprite,this)),this._pointerOverSprite=e,this._pointerOverSprite&&this._pointerOverSprite.actionManager&&this._pointerOverSprite.actionManager.processTrigger(l.ActionManager.OnPointerOverTrigger,l.ActionEvent.CreateNewFromSprite(this._pointerOverSprite,this)))},l.Scene.prototype.getPointerOverSprite=function(){return this._pointerOverSprite};var e=(function(){function e(e){this.name=l.SceneComponentConstants.NAME_SPRITE,this.scene=e,this.scene.spriteManagers=new Array,this.scene._tempSpritePickingRay=l.Ray?l.Ray.Zero():null,this.scene.onBeforeSpritesRenderingObservable=new l.Observable,this.scene.onAfterSpritesRenderingObservable=new l.Observable,this._spritePredicate=function(e){return!!e.actionManager&&(e.isPickable&&e.actionManager.hasPointerTriggers)}}return e.prototype.register=function(){this.scene._pointerMoveStage.registerStep(l.SceneComponentConstants.STEP_POINTERMOVE_SPRITE,this,this._pointerMove),this.scene._pointerDownStage.registerStep(l.SceneComponentConstants.STEP_POINTERDOWN_SPRITE,this,this._pointerDown),this.scene._pointerUpStage.registerStep(l.SceneComponentConstants.STEP_POINTERUP_SPRITE,this,this._pointerUp)},e.prototype.rebuild=function(){},e.prototype.dispose=function(){this.scene.onBeforeSpritesRenderingObservable.clear(),this.scene.onAfterSpritesRenderingObservable.clear();for(var e=this.scene.spriteManagers;e.length;)e[0].dispose()},e.prototype._pickSpriteButKeepRay=function(e,t,i,r,n){var o=this.scene.pickSprite(t,i,this._spritePredicate,r,n);return o&&(o.ray=e?e.ray:null),o},e.prototype._pointerMove=function(e,t,i,r,n){var o=this.scene;return r?o.setPointerOverSprite(null):(i=this._pickSpriteButKeepRay(i,e,t,!1,o.cameraToUseForPointers||void 0))&&i.hit&&i.pickedSprite?(o.setPointerOverSprite(i.pickedSprite),o._pointerOverSprite&&o._pointerOverSprite.actionManager&&o._pointerOverSprite.actionManager.hoverCursor?n.style.cursor=o._pointerOverSprite.actionManager.hoverCursor:n.style.cursor=o.hoverCursor):o.setPointerOverSprite(null),i},e.prototype._pointerDown=function(e,t,i,r){var n=this.scene;if(n._pickedDownSprite=null,0t.x)return!1}else if(i=1/this.direction.x,r=(e.x-this.origin.x)*i,(n=(t.x-this.origin.x)*i)===-1/0&&(n=1/0),nt.y)return!1}else if(i=1/this.direction.y,r=(e.y-this.origin.y)*i,(n=(t.y-this.origin.y)*i)===-1/0&&(n=1/0),nt.z)return!1}else if(i=1/this.direction.z,r=(e.z-this.origin.z)*i,(n=(t.z-this.origin.z)*i)===-1/0&&(n=1/0),nthis.length?null:new ft.IntersectionInfo(o,s,a)},T.prototype.intersectsPlane=function(e){var t,i=ft.Vector3.Dot(e.normal,this.direction);if(Math.abs(i)<9.99999997475243e-7)return null;var r=ft.Vector3.Dot(e.normal,this.origin);return(t=(-e.d-r)/i)<0?t<-9.99999997475243e-7?null:0:t},T.prototype.intersectsMesh=function(e,t){var i=ft.Tmp.Matrix[0];return e.getWorldMatrix().invertToRef(i),this._tmpRay?T.TransformToRef(this,i,this._tmpRay):this._tmpRay=T.Transform(this,i),e.intersects(this._tmpRay,t)},T.prototype.intersectsMeshes=function(e,t,i){i?i.length=0:i=[];for(var r=0;rt.distance?1:0},T.prototype.intersectionSegment=function(e,t,i){var r,n,o,s,a=this.origin.add(this.direction.multiplyByFloats(T.rayl,T.rayl,T.rayl)),l=t.subtract(e),c=a.subtract(this.origin),h=e.subtract(this.origin),u=ft.Vector3.Dot(l,l),d=ft.Vector3.Dot(l,c),f=ft.Vector3.Dot(c,c),p=ft.Vector3.Dot(l,h),m=ft.Vector3.Dot(c,h),_=u*f-d*d,g=_,v=_;_this._velocityWorldLength+c+t)&&(n=i,o=r,s=this._basePointWorld,a=this._velocityWorldLength+c,!(n.x>s.x+a||s.x-a>o.x||n.y>s.y+a||s.y-a>o.y||n.z>s.z+a||s.z-a>o.z))},e.prototype._testTriangle=function(e,t,i,r,n,o){var s,a=!1;t||(t=[]),t[e]||(t[e]=new mt.Plane(0,0,0,0),t[e].copyFromPoints(i,r,n));var l=t[e];if(o||l.isFrontFacingTo(this._normalizedVelocity,0)){var c=l.signedDistanceTo(this._basePoint),h=mt.Vector3.Dot(l.normal,this._velocity);if(0==h){if(1<=Math.abs(c))return;a=!0,s=0}else{var u=(1-c)/h;if(u<(s=(-1-c)/h)){var d=u;u=s,s=d}if(1=r)n.copyFrom(e);else{var a=o?o.collisionMask:i.collisionMask;i._initialize(e,t,s);for(var l=0;lf.lifeTime){var i=f.age-t;e=(f.lifeTime-t)*e/i,f.age=f.lifeTime}var r=f.age/f.lifeTime;m._colorGradients&&0=f.lifeTime)return m._emitFromParticle(f),f._attachedSubEmitters&&(f._attachedSubEmitters.forEach((function(e){e.particleSystem.disposeOnStop=!0,e.particleSystem.stop()})),f._attachedSubEmitters=null),m.recycleParticle(f),p--,"continue"},p=0;pt.gradient?1:0}))},m.prototype._removeFactorGradient=function(e,t){if(e)for(var i=0,r=0,n=e;rt.gradient?1:0})),this._rampGradientsTexture&&(this._rampGradientsTexture.dispose(),this._rampGradientsTexture=null),this._createRampGradientTexture(),this},m.prototype.removeRampGradient=function(e){return this._removeGradientAndTexture(e,this._rampGradients,this._rampGradientsTexture),this._rampGradientsTexture=null,this._rampGradients&&0t.gradient?1:0})),this},m.prototype.removeColorGradient=function(e){if(!this._colorGradients)return this;for(var t=0,i=0,r=this._colorGradients;i>0,this._newPartsExcess+=n*this._scaledUpdateSpeed-t}if(1>0,this._newPartsExcess-=this._newPartsExcess>>0),this._alive=!1,this._stopped?t=0:(this._actualFrame+=this._scaledUpdateSpeed,this.targetStopDuration&&this._actualFrame>=this.targetStopDuration&&this.stop()),this._update(t),this._stopped&&(this._alive||(this._started=!1,this.onAnimationEnd&&this.onAnimationEnd(),this.disposeOnStop&&this._scene._toBeDisposed.push(this))),!e){for(var o=0,s=0;sthis._maxX||tthis._maxZ)return this.position.y;this._heightQuads&&0!=this._heightQuads.length||(this._initHeightQuads(),this._computeHeightQuads());var o=this._getFacetAt(e,t),s=-(o.x*e+o.z*t+o.w)/o.y;return kt.Vector3.TransformCoordinatesFromFloatsToRef(0,s,0,i,n),n.y},n.prototype.getNormalAtCoordinates=function(e,t){var i=new kt.Vector3(0,1,0);return this.getNormalAtCoordinatesToRef(e,t,i),i},n.prototype.getNormalAtCoordinatesToRef=function(e,t,i){var r=this.getWorldMatrix(),n=kt.Tmp.Matrix[5];r.invertToRef(n);var o=kt.Tmp.Vector3[8];if(kt.Vector3.TransformCoordinatesFromFloatsToRef(e,0,t,n,o),e=o.x,t=o.z,ethis._maxX||tthis._maxZ)return this;this._heightQuads&&0!=this._heightQuads.length||(this._initHeightQuads(),this._computeHeightQuads());var s=this._getFacetAt(e,t);return kt.Vector3.TransformNormalFromFloatsToRef(s.x,s.y,s.z,r,i),this},n.prototype.updateCoordinateHeights=function(){return this._heightQuads&&0!=this._heightQuads.length||this._initHeightQuads(),this._computeHeightQuads(),this},n.prototype._getFacetAt=function(e,t){var i=Math.floor((e+this._maxX)*this._subdivisionsX/this._width),r=Math.floor(-(t+this._maxZ)*this._subdivisionsY/this._height+this._subdivisionsY),n=this._heightQuads[r*this._subdivisionsX+i];return tt.gradient?1:0})),this._colorGradientsTexture&&(this._colorGradientsTexture.dispose(),this._colorGradientsTexture=null),this._releaseBuffers(),this},o.prototype.removeColorGradient=function(e){return this._removeGradientAndTexture(e,this._colorGradients,this._colorGradientsTexture),this._colorGradientsTexture=null,this},o.prototype._addFactorGradient=function(e,t,i){var r=new ui.FactorGradient;r.gradient=t,r.factor1=i,e.push(r),e.sort((function(e,t){return e.gradientt.gradient?1:0})),this._releaseBuffers()},o.prototype.addSizeGradient=function(e,t){return this._sizeGradients||(this._sizeGradients=[]),this._addFactorGradient(this._sizeGradients,e,t),this._sizeGradientsTexture&&(this._sizeGradientsTexture.dispose(),this._sizeGradientsTexture=null),this._releaseBuffers(),this},o.prototype.removeSizeGradient=function(e){return this._removeGradientAndTexture(e,this._sizeGradients,this._sizeGradientsTexture),this._sizeGradientsTexture=null,this},o.prototype.addAngularSpeedGradient=function(e,t){return this._angularSpeedGradients||(this._angularSpeedGradients=[]),this._addFactorGradient(this._angularSpeedGradients,e,t),this._angularSpeedGradientsTexture&&(this._angularSpeedGradientsTexture.dispose(),this._angularSpeedGradientsTexture=null),this._releaseBuffers(),this},o.prototype.removeAngularSpeedGradient=function(e){return this._removeGradientAndTexture(e,this._angularSpeedGradients,this._angularSpeedGradientsTexture),this._angularSpeedGradientsTexture=null,this},o.prototype.addVelocityGradient=function(e,t){return this._velocityGradients||(this._velocityGradients=[]),this._addFactorGradient(this._velocityGradients,e,t),this._velocityGradientsTexture&&(this._velocityGradientsTexture.dispose(),this._velocityGradientsTexture=null),this._releaseBuffers(),this},o.prototype.removeVelocityGradient=function(e){return this._removeGradientAndTexture(e,this._velocityGradients,this._velocityGradientsTexture),this._velocityGradientsTexture=null,this},o.prototype.addLimitVelocityGradient=function(e,t){return this._limitVelocityGradients||(this._limitVelocityGradients=[]),this._addFactorGradient(this._limitVelocityGradients,e,t),this._limitVelocityGradientsTexture&&(this._limitVelocityGradientsTexture.dispose(),this._limitVelocityGradientsTexture=null),this._releaseBuffers(),this},o.prototype.removeLimitVelocityGradient=function(e){return this._removeGradientAndTexture(e,this._limitVelocityGradients,this._limitVelocityGradientsTexture),this._limitVelocityGradientsTexture=null,this},o.prototype.addDragGradient=function(e,t){return this._dragGradients||(this._dragGradients=[]),this._addFactorGradient(this._dragGradients,e,t),this._dragGradientsTexture&&(this._dragGradientsTexture.dispose(),this._dragGradientsTexture=null),this._releaseBuffers(),this},o.prototype.removeDragGradient=function(e){return this._removeGradientAndTexture(e,this._dragGradients,this._dragGradientsTexture),this._dragGradientsTexture=null,this},o.prototype.addEmitRateGradient=function(e,t,i){return this},o.prototype.removeEmitRateGradient=function(e){return this},o.prototype.addStartSizeGradient=function(e,t,i){return this},o.prototype.removeStartSizeGradient=function(e){return this},o.prototype.addColorRemapGradient=function(e,t,i){return this},o.prototype.removeColorRemapGradient=function(e){return this},o.prototype.addAlphaRemapGradient=function(e,t,i){return this},o.prototype.removeAlphaRemapGradient=function(e){return this},o.prototype.addRampGradient=function(e,t){return this},o.prototype.removeRampGradient=function(e){return this},o.prototype.getRampGradients=function(){return null},Object.defineProperty(o.prototype,"useRampGradients",{get:function(){return!1},set:function(e){},enumerable:!0,configurable:!0}),o.prototype.addLifeTimeGradient=function(e,t,i){return this},o.prototype.removeLifeTimeGradient=function(e){return this},o.prototype._reset=function(){this._releaseBuffers()},o.prototype._createUpdateVAO=function(e){var t={};t.position=e.createVertexBuffer("position",0,3),t.age=e.createVertexBuffer("age",3,1),t.life=e.createVertexBuffer("life",4,1),t.seed=e.createVertexBuffer("seed",5,4),t.size=e.createVertexBuffer("size",9,3);var i=12;this._colorGradientsTexture||(t.color=e.createVertexBuffer("color",i,4),i+=4),t.direction=e.createVertexBuffer("direction",i,3),i+=3,this._isBillboardBased||(t.initialDirection=e.createVertexBuffer("initialDirection",i,3),i+=3),this._angularSpeedGradientsTexture?(t.angle=e.createVertexBuffer("angle",i,1),i+=1):(t.angle=e.createVertexBuffer("angle",i,2),i+=2),this._isAnimationSheetEnabled&&(t.cellIndex=e.createVertexBuffer("cellIndex",i,1),i+=1,this.spriteRandomStartCell&&(t.cellStartOffset=e.createVertexBuffer("cellStartOffset",i,1),i+=1)),this.noiseTexture&&(t.noiseCoordinates1=e.createVertexBuffer("noiseCoordinates1",i,3),i+=3,t.noiseCoordinates2=e.createVertexBuffer("noiseCoordinates2",i,3),i+=3);var r=this._engine.recordVertexArrayObject(t,null,this._updateEffect);return this._engine.bindArrayBuffer(null),r},o.prototype._createRenderVAO=function(e,t){var i={};i.position=e.createVertexBuffer("position",0,3,this._attributesStrideSize,!0),i.age=e.createVertexBuffer("age",3,1,this._attributesStrideSize,!0),i.life=e.createVertexBuffer("life",4,1,this._attributesStrideSize,!0),i.size=e.createVertexBuffer("size",9,3,this._attributesStrideSize,!0);var r=12;this._colorGradientsTexture||(i.color=e.createVertexBuffer("color",r,4,this._attributesStrideSize,!0),r+=4),this.billboardMode===ui.ParticleSystem.BILLBOARDMODE_STRETCHED&&(i.direction=e.createVertexBuffer("direction",r,3,this._attributesStrideSize,!0)),r+=3,this._isBillboardBased||(i.initialDirection=e.createVertexBuffer("initialDirection",r,3,this._attributesStrideSize,!0),r+=3),i.angle=e.createVertexBuffer("angle",r,1,this._attributesStrideSize,!0),this._angularSpeedGradientsTexture?r++:r+=2,this._isAnimationSheetEnabled&&(i.cellIndex=e.createVertexBuffer("cellIndex",r,1,this._attributesStrideSize,!0),r+=1,this.spriteRandomStartCell&&(i.cellStartOffset=e.createVertexBuffer("cellStartOffset",r,1,this._attributesStrideSize,!0),r+=1)),this.noiseTexture&&(i.noiseCoordinates1=e.createVertexBuffer("noiseCoordinates1",r,3,this._attributesStrideSize,!0),r+=3,i.noiseCoordinates2=e.createVertexBuffer("noiseCoordinates2",r,3,this._attributesStrideSize,!0),r+=3),i.offset=t.createVertexBuffer("offset",0,2),i.uv=t.createVertexBuffer("uv",2,2);var n=this._engine.recordVertexArrayObject(i,null,this._renderEffect);return this._engine.bindArrayBuffer(null),n},o.prototype._initialize=function(e){if(void 0===e&&(e=!1),!this._buffer0||e){var t=this._scene.getEngine(),i=new Array;this.isBillboardBased||(this._attributesStrideSize+=3),this._colorGradientsTexture&&(this._attributesStrideSize-=4),this._angularSpeedGradientsTexture&&(this._attributesStrideSize-=1),this._isAnimationSheetEnabled&&(this._attributesStrideSize+=1,this.spriteRandomStartCell&&(this._attributesStrideSize+=1)),this.noiseTexture&&(this._attributesStrideSize+=6);for(var r=0;r=this.targetStopDuration&&this.stop()},o.prototype._createFactorGradientTexture=function(e,t){var i=this[t];if(e&&e.length&&!i){for(var r=new Float32Array(this._rawTextureWidth),n=0;n=this.nbParticles?this.nbParticles-1:t,this._computeBoundingBox&&(0==e&&t==this.nbParticles-1?(fi.Vector3.FromFloatsToRef(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE,this._minimum),fi.Vector3.FromFloatsToRef(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE,this._maximum)):this.mesh._boundingInfo&&(this._minimum.copyFrom(this.mesh._boundingInfo.boundingBox.minimum),this._maximum.copyFrom(this.mesh._boundingInfo.boundingBox.maximum)));var u=(o=this.particles[e]._pos)/3|0;a=4*u,c=2*u;for(var d=e;d<=t;d++){if(this._particle=this.particles[d],this._shape=this._particle._model._shape,this._shapeUV=this._particle._model._shapeUV,this.updateParticle(this._particle),this._depthSort&&this._depthSortParticles){var f=this.depthSortedParticles[d];f.ind=this._particle._ind,f.indicesLength=this._particle._model._indicesLength,f.sqDistance=fi.Vector3.DistanceSquared(this._particle.position,this._camInvertedPosition)}if(!this._particle.alive||this._particle._stillInvisible&&!this._particle.isVisible)o+=3*(h=this._shape.length),a+=4*h,c+=2*h;else{if(this._particle.isVisible)for(this._particle._stillInvisible=!1,this._particleHasParent=null!==this._particle.parentId,this._scaledPivot.x=this._particle.pivot.x*this._particle.scaling.x,this._scaledPivot.y=this._particle.pivot.y*this._particle.scaling.y,this._scaledPivot.z=this._particle.pivot.z*this._particle.scaling.z,this.billboard&&(this._particle.rotation.x=0,this._particle.rotation.y=0),(this._computeParticleRotation||this.billboard)&&(this._particle.rotationQuaternion?this._quaternion.copyFrom(this._particle.rotationQuaternion):(this._yaw=this._particle.rotation.y,this._pitch=this._particle.rotation.x,this._roll=this._particle.rotation.z,this._quaternionRotationYPR()),this._quaternionToRotationMatrix()),this._particleHasParent?(this._parent=this.particles[this._particle.parentId],this._rotated.x=this._particle.position.x*this._parent._rotationMatrix[0]+this._particle.position.y*this._parent._rotationMatrix[3]+this._particle.position.z*this._parent._rotationMatrix[6],this._rotated.y=this._particle.position.x*this._parent._rotationMatrix[1]+this._particle.position.y*this._parent._rotationMatrix[4]+this._particle.position.z*this._parent._rotationMatrix[7],this._rotated.z=this._particle.position.x*this._parent._rotationMatrix[2]+this._particle.position.y*this._parent._rotationMatrix[5]+this._particle.position.z*this._parent._rotationMatrix[8],this._particle._globalPosition.x=this._parent._globalPosition.x+this._rotated.x,this._particle._globalPosition.y=this._parent._globalPosition.y+this._rotated.y,this._particle._globalPosition.z=this._parent._globalPosition.z+this._rotated.z,(this._computeParticleRotation||this.billboard)&&(this._particle._rotationMatrix[0]=this._rotMatrix.m[0]*this._parent._rotationMatrix[0]+this._rotMatrix.m[1]*this._parent._rotationMatrix[3]+this._rotMatrix.m[2]*this._parent._rotationMatrix[6],this._particle._rotationMatrix[1]=this._rotMatrix.m[0]*this._parent._rotationMatrix[1]+this._rotMatrix.m[1]*this._parent._rotationMatrix[4]+this._rotMatrix.m[2]*this._parent._rotationMatrix[7],this._particle._rotationMatrix[2]=this._rotMatrix.m[0]*this._parent._rotationMatrix[2]+this._rotMatrix.m[1]*this._parent._rotationMatrix[5]+this._rotMatrix.m[2]*this._parent._rotationMatrix[8],this._particle._rotationMatrix[3]=this._rotMatrix.m[4]*this._parent._rotationMatrix[0]+this._rotMatrix.m[5]*this._parent._rotationMatrix[3]+this._rotMatrix.m[6]*this._parent._rotationMatrix[6],this._particle._rotationMatrix[4]=this._rotMatrix.m[4]*this._parent._rotationMatrix[1]+this._rotMatrix.m[5]*this._parent._rotationMatrix[4]+this._rotMatrix.m[6]*this._parent._rotationMatrix[7],this._particle._rotationMatrix[5]=this._rotMatrix.m[4]*this._parent._rotationMatrix[2]+this._rotMatrix.m[5]*this._parent._rotationMatrix[5]+this._rotMatrix.m[6]*this._parent._rotationMatrix[8],this._particle._rotationMatrix[6]=this._rotMatrix.m[8]*this._parent._rotationMatrix[0]+this._rotMatrix.m[9]*this._parent._rotationMatrix[3]+this._rotMatrix.m[10]*this._parent._rotationMatrix[6],this._particle._rotationMatrix[7]=this._rotMatrix.m[8]*this._parent._rotationMatrix[1]+this._rotMatrix.m[9]*this._parent._rotationMatrix[4]+this._rotMatrix.m[10]*this._parent._rotationMatrix[7],this._particle._rotationMatrix[8]=this._rotMatrix.m[8]*this._parent._rotationMatrix[2]+this._rotMatrix.m[9]*this._parent._rotationMatrix[5]+this._rotMatrix.m[10]*this._parent._rotationMatrix[8])):(this._particle._globalPosition.x=this._particle.position.x,this._particle._globalPosition.y=this._particle.position.y,this._particle._globalPosition.z=this._particle.position.z,(this._computeParticleRotation||this.billboard)&&(this._particle._rotationMatrix[0]=this._rotMatrix.m[0],this._particle._rotationMatrix[1]=this._rotMatrix.m[1],this._particle._rotationMatrix[2]=this._rotMatrix.m[2],this._particle._rotationMatrix[3]=this._rotMatrix.m[4],this._particle._rotationMatrix[4]=this._rotMatrix.m[5],this._particle._rotationMatrix[5]=this._rotMatrix.m[6],this._particle._rotationMatrix[6]=this._rotMatrix.m[8],this._particle._rotationMatrix[7]=this._rotMatrix.m[9],this._particle._rotationMatrix[8]=this._rotMatrix.m[10])),this._particle.translateFromPivot?(this._pivotBackTranslation.x=0,this._pivotBackTranslation.y=0,this._pivotBackTranslation.z=0):(this._pivotBackTranslation.x=this._scaledPivot.x,this._pivotBackTranslation.y=this._scaledPivot.y,this._pivotBackTranslation.z=this._scaledPivot.z),h=0;hthis._maximum.x&&(this._maximum.x=this._positions32[n]),this._positions32[n+1]this._maximum.y&&(this._maximum.y=this._positions32[n+1]),this._positions32[n+2]this._maximum.z&&(this._maximum.z=this._positions32[n+2])),this._computeParticleVertex||(this._normal.x=this._fixedNormal32[n],this._normal.y=this._fixedNormal32[n+1],this._normal.z=this._fixedNormal32[n+2],this._rotated.x=this._normal.x*this._particle._rotationMatrix[0]+this._normal.y*this._particle._rotationMatrix[3]+this._normal.z*this._particle._rotationMatrix[6],this._rotated.y=this._normal.x*this._particle._rotationMatrix[1]+this._normal.y*this._particle._rotationMatrix[4]+this._normal.z*this._particle._rotationMatrix[7],this._rotated.z=this._normal.x*this._particle._rotationMatrix[2]+this._normal.y*this._particle._rotationMatrix[5]+this._normal.z*this._particle._rotationMatrix[8],this._normals32[n]=this._cam_axisX.x*this._rotated.x+this._cam_axisY.x*this._rotated.y+this._cam_axisZ.x*this._rotated.z,this._normals32[n+1]=this._cam_axisX.y*this._rotated.x+this._cam_axisY.y*this._rotated.y+this._cam_axisZ.y*this._rotated.z,this._normals32[n+2]=this._cam_axisX.z*this._rotated.x+this._cam_axisY.z*this._rotated.y+this._cam_axisZ.z*this._rotated.z),this._computeParticleColor&&this._particle.color&&(this._colors32[s]=this._particle.color.r,this._colors32[s+1]=this._particle.color.g,this._colors32[s+2]=this._particle.color.b,this._colors32[s+3]=this._particle.color.a),this._computeParticleTexture&&(this._uvs32[l]=this._shapeUV[2*h]*(this._particle.uvs.z-this._particle.uvs.x)+this._particle.uvs.x,this._uvs32[l+1]=this._shapeUV[2*h+1]*(this._particle.uvs.w-this._particle.uvs.y)+this._particle.uvs.y);else for(this._particle._stillInvisible=!0,h=0;hmi.Tmp.Vector3[1].x&&(mi.Tmp.Vector3[1].x=a[c].x),a[c].ymi.Tmp.Vector3[1].y&&(mi.Tmp.Vector3[1].y=a[c].y),a[c].zmi.Tmp.Vector3[1].z&&(mi.Tmp.Vector3[1].z=a[c].z),c++,r+=3;i._creationDataStorage&&i._creationDataStorage.closePath&&(e[r]=a[0].x,e[r+1]=a[0].y,e[r+2]=a[0].z,r+=3)}}(a),u._boundingInfo=new mi.BoundingInfo(mi.Tmp.Vector3[2],mi.Tmp.Vector3[3]),u._boundingInfo.update(u._worldMatrix),u.updateVerticesData(mi.VertexBuffer.PositionKind,a,!1,!1),t.colors){for(var l=u.getVerticesData(mi.VertexBuffer.ColorKind),c=0;cmi.Epsilon&&r.rotate(o,n)}return r},E.CreateGround=function(e,t,i){var r=new mi.GroundMesh(e,i);return r._setReady(!1),r._subdivisionsX=t.subdivisionsX||t.subdivisions||1,r._subdivisionsY=t.subdivisionsY||t.subdivisions||1,r._width=t.width||1,r._height=t.height||1,r._maxX=r._width/2,r._maxZ=r._height/2,r._minX=-r._maxX,r._minZ=-r._maxZ,mi.VertexData.CreateGround(t).applyToMesh(r,t.updatable),r._setReady(!0),r},E.CreateTiledGround=function(e,t,i){var r=new mi.Mesh(e,i);return mi.VertexData.CreateTiledGround(t).applyToMesh(r,t.updatable),r},E.CreateGroundFromHeightMap=function(e,t,i,s){var a=i.width||10,l=i.height||10,c=i.subdivisions||1,h=i.minHeight||0,u=i.maxHeight||1,d=i.colorFilter||new mi.Color3(.3,.59,.11),f=i.alphaFilter||0,p=i.updatable,m=i.onReady,_=new mi.GroundMesh(e,s);_._subdivisionsX=c,_._subdivisionsY=c,_._width=a,_._height=l,_._maxX=_._width/2,_._maxZ=_._height/2,_._minX=-_._maxX,_._minZ=-_._maxZ,_._setReady(!1);return mi.Tools.LoadImage(t,(function(e){var t=document.createElement("canvas"),i=t.getContext("2d");if(!i)throw new Error("Unable to get 2d context for CreateGroundFromHeightMap");if(!s.isDisposed){var r=e.width,n=e.height;t.width=r,t.height=n,i.drawImage(e,0,0);var o=i.getImageData(0,0,r,n).data;mi.VertexData.CreateGroundFromHeightMap({width:a,height:l,subdivisions:c,minHeight:h,maxHeight:u,colorFilter:d,buffer:o,bufferWidth:r,bufferHeight:n,alphaFilter:f}).applyToMesh(_,p),m&&m(_),_._setReady(!0)}}),(function(){}),s.database),_},E.CreatePolygon=function(e,t,i){t.sideOrientation=E.updateSideOrientation(t.sideOrientation);for(var r=t.shape,n=t.holes||[],o=t.depth||0,s=[],a=[],l=0;l=a.video.HAVE_CURRENT_DATA&&a._createInternalTexture(),s.poster&&(a._texture=a._engine.createTexture(s.poster,!1,!0,i),a._poster=!0),a}return T(o,l),Object.defineProperty(o.prototype,"onUserActionRequestedObservable",{get:function(){return this._onUserActionRequestedObservable||(this._onUserActionRequestedObservable=new Gi.Observable),this._onUserActionRequestedObservable},enumerable:!0,configurable:!0}),o.prototype._getName=function(e){return e instanceof HTMLVideoElement?e.currentSrc:"object"==typeof e?e.toString():e},o.prototype._getVideo=function(e){if(e instanceof HTMLVideoElement)return Gi.Tools.SetCorsBehavior(e.currentSrc,e),e;var i=document.createElement("video");return"string"==typeof e?(Gi.Tools.SetCorsBehavior(e,i),i.src=e):(Gi.Tools.SetCorsBehavior(e[0],i),e.forEach((function(e){var t=document.createElement("source");t.src=e,i.appendChild(t)}))),i},o.prototype._rebuild=function(){this.update()},o.prototype.update=function(){this.autoUpdateTexture&&this.updateTexture(!0)},o.prototype.updateTexture=function(e){e&&(this.video.paused&&this._stillImageCaptured||(this._stillImageCaptured=!0,this._updateInternalTexture()))},o.prototype.updateURL=function(e){this.video.src=e},o.prototype.dispose=function(){l.prototype.dispose.call(this),this._onUserActionRequestedObservable&&(this._onUserActionRequestedObservable.clear(),this._onUserActionRequestedObservable=null),this.video.removeEventListener("canplay",this._createInternalTexture),this.video.removeEventListener("paused",this._updateInternalTexture),this.video.removeEventListener("seeked",this._updateInternalTexture),this.video.removeEventListener("emptied",this.reset),this.video.pause()},o.CreateFromWebCam=function(i,r,e){var t,n=document.createElement("video");n.setAttribute("autoplay",""),n.setAttribute("muted",""),n.setAttribute("playsinline",""),e&&e.deviceId&&(t={exact:e.deviceId}),window.URL=window.URL||window.webkitURL||window.mozURL||window.msURL,navigator.mediaDevices?navigator.mediaDevices.getUserMedia({video:e}).then((function(e){void 0!==n.mozSrcObject?n.mozSrcObject=e:n.srcObject=e;var t=function(){r&&r(new o("video",n,i,!0,!0)),n.removeEventListener("playing",t)};n.addEventListener("playing",t),n.play()})).catch((function(e){Gi.Tools.Error(e.name)})):(navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia,navigator.getUserMedia&&navigator.getUserMedia({video:{deviceId:t,width:{min:e&&e.minWidth||256,max:e&&e.maxWidth||640},height:{min:e&&e.minHeight||256,max:e&&e.maxHeight||480}}},(function(e){void 0!==n.mozSrcObject?n.mozSrcObject=e:n.src=window.URL&&window.URL.createObjectURL(e)||e,n.play(),r&&r(new o("video",n,i,!0,!0))}),(function(e){Gi.Tools.Error(e.name)})))},o})(Gi.Texture),Gi.VideoTexture=ki,Wi=$a||($a={}),Hi=(function(h){function l(e,t,i,r,n,o,s,a,l){void 0===o&&(o=!0),void 0===s&&(s=!1),void 0===a&&(a=Wi.Texture.TRILINEAR_SAMPLINGMODE),void 0===l&&(l=Wi.Engine.TEXTURETYPE_UNSIGNED_INT);var c=h.call(this,null,n,!o,s)||this;return c.format=r,c._engine=n.getEngine(),c._texture=n.getEngine().createRawTexture(e,t,i,r,o,s,a,null,l),c.wrapU=Wi.Texture.CLAMP_ADDRESSMODE,c.wrapV=Wi.Texture.CLAMP_ADDRESSMODE,c}return T(l,h),l.prototype.update=function(e){this._engine.updateRawTexture(this._texture,e,this._texture.format,this._texture.invertY,void 0,this._texture.type)},l.CreateLuminanceTexture=function(e,t,i,r,n,o,s){return void 0===n&&(n=!0),void 0===o&&(o=!1),void 0===s&&(s=Wi.Texture.TRILINEAR_SAMPLINGMODE),new l(e,t,i,Wi.Engine.TEXTUREFORMAT_LUMINANCE,r,n,o,s)},l.CreateLuminanceAlphaTexture=function(e,t,i,r,n,o,s){return void 0===n&&(n=!0),void 0===o&&(o=!1),void 0===s&&(s=Wi.Texture.TRILINEAR_SAMPLINGMODE),new l(e,t,i,Wi.Engine.TEXTUREFORMAT_LUMINANCE_ALPHA,r,n,o,s)},l.CreateAlphaTexture=function(e,t,i,r,n,o,s){return void 0===n&&(n=!0),void 0===o&&(o=!1),void 0===s&&(s=Wi.Texture.TRILINEAR_SAMPLINGMODE),new l(e,t,i,Wi.Engine.TEXTUREFORMAT_ALPHA,r,n,o,s)},l.CreateRGBTexture=function(e,t,i,r,n,o,s,a){return void 0===n&&(n=!0),void 0===o&&(o=!1),void 0===s&&(s=Wi.Texture.TRILINEAR_SAMPLINGMODE),void 0===a&&(a=Wi.Engine.TEXTURETYPE_UNSIGNED_INT),new l(e,t,i,Wi.Engine.TEXTUREFORMAT_RGB,r,n,o,s,a)},l.CreateRGBATexture=function(e,t,i,r,n,o,s,a){return void 0===n&&(n=!0),void 0===o&&(o=!1),void 0===s&&(s=Wi.Texture.TRILINEAR_SAMPLINGMODE),void 0===a&&(a=Wi.Engine.TEXTURETYPE_UNSIGNED_INT),new l(e,t,i,Wi.Engine.TEXTUREFORMAT_RGBA,r,n,o,s,a)},l.CreateRTexture=function(e,t,i,r,n,o,s,a){return void 0===n&&(n=!0),void 0===o&&(o=!1),void 0===s&&(s=Wi.Texture.TRILINEAR_SAMPLINGMODE),void 0===a&&(a=Wi.Engine.TEXTURETYPE_FLOAT),new l(e,t,i,Wi.Engine.TEXTUREFORMAT_R,r,n,o,s,a)},l})(Wi.Texture),Wi.RawTexture=Hi,Xi=$a||($a={}),ji=(function(u){function e(e,t,i,r,n,o,s,a,l,c){void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===l&&(l=Xi.Texture.TRILINEAR_SAMPLINGMODE),void 0===c&&(c=Xi.Engine.TEXTURETYPE_UNSIGNED_INT);var h=u.call(this,null,o,!s,a)||this;return h.format=n,h._engine=o.getEngine(),h._texture=o.getEngine().createRawTexture3D(e,t,i,r,n,s,a,l,void 0,c),h.is3D=!0,h}return T(e,u),e.prototype.update=function(e){this._texture&&this._engine.updateRawTexture3D(this._texture,e,this._texture.format,this._texture.invertY,void 0,this._texture.type)},e})(Xi.Texture),Xi.RawTexture3D=ji,Yi=$a||($a={}),Ki=(function(){function e(e){this._vertexBuffers={},this._scene=e}return e.prototype._prepareBuffers=function(){if(!this._vertexBuffers[Yi.VertexBuffer.PositionKind]){var e=[];e.push(1,1),e.push(-1,1),e.push(-1,-1),e.push(1,-1),this._vertexBuffers[Yi.VertexBuffer.PositionKind]=new Yi.VertexBuffer(this._scene.getEngine(),e,Yi.VertexBuffer.PositionKind,!1,!1,2),this._buildIndexBuffer()}},e.prototype._buildIndexBuffer=function(){var e=[];e.push(0),e.push(1),e.push(2),e.push(0),e.push(2),e.push(3),this._indexBuffer=this._scene.getEngine().createIndexBuffer(e)},e.prototype._rebuild=function(){var e=this._vertexBuffers[Yi.VertexBuffer.PositionKind];e&&(e._rebuild(),this._buildIndexBuffer())},e.prototype._prepareFrame=function(e,t){void 0===e&&(e=null),void 0===t&&(t=null);var i=this._scene.activeCamera;return!!i&&(!(!(t=t||i._postProcesses.filter((function(e){return null!=e})))||0===t.length||!this._scene.postProcessesEnabled)&&(t[0].activate(i,e,null!=t),!0))},e.prototype.directRender=function(e,t,i,r,n){void 0===t&&(t=null),void 0===i&&(i=!1),void 0===r&&(r=0),void 0===n&&(n=0);for(var o=this._scene.getEngine(),s=0;s=s.length)return void(e&&e(i));setTimeout(u,16)}};u()}else e&&e(this)}else e&&e(this)}else e&&e(this)},s.prototype.forceCompilationAsync=function(t){var i=this;return new Promise(function(e){i.forceCompilation((function(){e()}),t)})},s.prototype.isReady=function(e,t){var i=[];this._textureType!==$i.Engine.TEXTURETYPE_UNSIGNED_INT&&i.push("#define FLOAT"),this.useExponentialShadowMap||this.useBlurExponentialShadowMap?i.push("#define ESM"):(this.usePercentageCloserFiltering||this.useContactHardeningShadow)&&i.push("#define DEPTHTEXTURE");var r=[$i.VertexBuffer.PositionKind],n=e.getMesh(),o=e.getMaterial();if(this.normalBias&&n.isVerticesDataPresent($i.VertexBuffer.NormalKind)&&(r.push($i.VertexBuffer.NormalKind),i.push("#define NORMAL"),n.nonUniformScaling&&i.push("#define NONUNIFORMSCALING"),this.getLight().getTypeID()===$i.Light.LIGHTTYPEID_DIRECTIONALLIGHT&&i.push("#define DIRECTIONINLIGHTDATA")),o&&o.needAlphaTesting()){var s=o.getAlphaTestTexture();s&&(i.push("#define ALPHATEST"),n.isVerticesDataPresent($i.VertexBuffer.UVKind)&&(r.push($i.VertexBuffer.UVKind),i.push("#define UV1")),n.isVerticesDataPresent($i.VertexBuffer.UV2Kind)&&1===s.coordinatesIndex&&(r.push($i.VertexBuffer.UV2Kind),i.push("#define UV2")))}n.useBones&&n.computeBonesUsingShaders?(r.push($i.VertexBuffer.MatricesIndicesKind),r.push($i.VertexBuffer.MatricesWeightsKind),4=this.subMaterials.length?this.getScene().defaultMaterial:this.subMaterials[e]},s.prototype.getActiveTextures=function(){var e;return(e=n.prototype.getActiveTextures.call(this)).concat.apply(e,this.subMaterials.map((function(e){return e?e.getActiveTextures():[]})))},s.prototype.getClassName=function(){return"MultiMaterial"},s.prototype.isReadyForSubMesh=function(e,t,i){for(var r=0;rthis._maxRotationDistFromHeadset){var r=i-(i<0?-this._maxRotationDistFromHeadset:this._maxRotationDistFromHeadset);this._draggedRoomRotation+=r;var n=Math.sin(-r),o=Math.cos(-r);this._calculatedPosition.x=this._calculatedPosition.x*o-this._calculatedPosition.z*n,this._calculatedPosition.z=this._calculatedPosition.x*n+this._calculatedPosition.z*o}}s.Vector3.TransformCoordinatesToRef(this._calculatedPosition,this._deviceToWorld,this.devicePosition),this._deviceToWorld.getRotationMatrixToRef(this._workingMatrix),s.Quaternion.FromRotationMatrixToRef(this._workingMatrix,this.deviceRotationQuaternion),this.deviceRotationQuaternion.multiplyInPlace(this._calculatedRotation),this._mesh&&(this._mesh.position.copyFrom(this.devicePosition),this._mesh.rotationQuaternion&&this._mesh.rotationQuaternion.copyFrom(this.deviceRotationQuaternion))},e.prototype.updateFromDevice=function(e){if(e){(this.rawPose=e).position&&(this._deviceRoomPosition.copyFromFloats(e.position[0],e.position[1],-e.position[2]),this._mesh&&this._mesh.getScene().useRightHandedSystem&&(this._deviceRoomPosition.z*=-1),this._trackPosition&&this._deviceRoomPosition.scaleToRef(this.deviceScaleFactor,this._calculatedPosition),this._calculatedPosition.addInPlace(this.position));var t=this.rawPose;e.orientation&&t.orientation&&(this._deviceRoomRotationQuaternion.copyFromFloats(t.orientation[0],t.orientation[1],-t.orientation[2],-t.orientation[3]),this._mesh&&(this._mesh.getScene().useRightHandedSystem?(this._deviceRoomRotationQuaternion.z*=-1,this._deviceRoomRotationQuaternion.w*=-1):this._deviceRoomRotationQuaternion.multiplyToRef(this._leftHandSystemQuaternion,this._deviceRoomRotationQuaternion)),this._deviceRoomRotationQuaternion.multiplyToRef(this.rotationQuaternion,this._calculatedRotation))}},e.prototype.attachToMesh=function(e){if(this._mesh&&(this._mesh.parent=null),this._mesh=e,this._poseControlledCamera&&(this._mesh.parent=this._poseControlledCamera),this._mesh.rotationQuaternion||(this._mesh.rotationQuaternion=new s.Quaternion),this._updatePoseAndMesh(),this._pointingPoseNode){for(var t=[],i=this._pointingPoseNode;i.parent;)t.push(i.parent),i=i.parent;t.reverse().forEach((function(e){e.computeWorldMatrix(!0)}))}this._meshAttachedObservable.notifyObservers(e)},e.prototype.attachToPoseControlledCamera=function(e){this._poseControlledCamera=e,this._mesh&&(this._mesh.parent=this._poseControlledCamera)},e.prototype.dispose=function(){this._mesh&&this._mesh.dispose(),this._mesh=null,i.prototype.dispose.call(this)},Object.defineProperty(e.prototype,"mesh",{get:function(){return this._mesh},enumerable:!0,configurable:!0}),e.prototype.getForwardRay=function(e){if(void 0===e&&(e=100),!this.mesh)return new s.Ray(s.Vector3.Zero(),new s.Vector3(0,0,1),e);var t=this._pointingPoseNode?this._pointingPoseNode.getWorldMatrix():this.mesh.getWorldMatrix(),i=t.getTranslation(),r=new s.Vector3(0,0,-1),n=s.Vector3.TransformNormal(r,t),o=s.Vector3.Normalize(n);return new s.Ray(i,o,e)},e.POINTING_POSE="POINTING_POSE",e})(s.Gamepad);s.PoseEnabledController=i})($a||($a={})),Lr=$a||($a={}),Fr=(function(i){function e(e){var t=i.call(this,e)||this;return t.onTriggerStateChangedObservable=new Lr.Observable,t.onMainButtonStateChangedObservable=new Lr.Observable,t.onSecondaryButtonStateChangedObservable=new Lr.Observable,t.onPadStateChangedObservable=new Lr.Observable,t.onPadValuesChangedObservable=new Lr.Observable,t.pad={x:0,y:0},t._changes={pressChanged:!1,touchChanged:!1,valueChanged:!1,changed:!1},t._buttons=new Array(e.buttons.length),t.hand=e.hand,t}return T(e,i),e.prototype.onButtonStateChange=function(e){this._onButtonStateChange=e},Object.defineProperty(e.prototype,"defaultModel",{get:function(){return this._defaultModel},enumerable:!0,configurable:!0}),e.prototype.update=function(){i.prototype.update.call(this);for(var e=0;ethis.maxCameraSpeed||h<-this.maxCameraSpeed)&&(h=h<1?-this.maxCameraSpeed:this.maxCameraSpeed),(u>this.maxCameraSpeed||u<-this.maxCameraSpeed)&&(u=u<1?-this.maxCameraSpeed:this.maxCameraSpeed),(d>this.maxCameraSpeed||d<-this.maxCameraSpeed)&&(d=d<1?-this.maxCameraSpeed:this.maxCameraSpeed),this.position=new f.Vector3(this.position.x+h,this.position.y+u,this.position.z+d),this.setTarget(n)}},e.prototype._checkInputs=function(){o.prototype._checkInputs.call(this),this.lockedTarget&&this._follow(this.lockedTarget)},e.prototype.getClassName=function(){return"FollowCamera"},b([f.serialize()],e.prototype,"radius",void 0),b([f.serialize()],e.prototype,"rotationOffset",void 0),b([f.serialize()],e.prototype,"heightOffset",void 0),b([f.serialize()],e.prototype,"cameraAcceleration",void 0),b([f.serialize()],e.prototype,"maxCameraSpeed",void 0),b([f.serializeAsMeshReference("lockedTargetId")],e.prototype,"lockedTarget",void 0),e})(f.TargetCamera);f.FollowCamera=i;var r=(function(a){function e(e,t,i,r,n,o){var s=a.call(this,e,f.Vector3.Zero(),o)||this;return s.alpha=t,s.beta=i,s.radius=r,s.target=n,s._cartesianCoordinates=f.Vector3.Zero(),s._follow(),s}return T(e,a),e.prototype._follow=function(){if(this.target){this._cartesianCoordinates.x=this.radius*Math.cos(this.alpha)*Math.cos(this.beta),this._cartesianCoordinates.y=this.radius*Math.sin(this.beta),this._cartesianCoordinates.z=this.radius*Math.sin(this.alpha)*Math.cos(this.beta);var e=this.target.getAbsolutePosition();this.position=e.add(this._cartesianCoordinates),this.setTarget(e)}},e.prototype._checkInputs=function(){a.prototype._checkInputs.call(this),this._follow()},e.prototype.getClassName=function(){return"ArcFollowCamera"},e})(f.TargetCamera);f.ArcFollowCamera=r})($a||($a={})),Qr=$a||($a={}),Zr=(function(n){function e(e,t,i){var r=n.call(this,e,t,i)||this;return r.inputs.addGamepad(),r}return T(e,n),Object.defineProperty(e.prototype,"gamepadAngularSensibility",{get:function(){var e=this.inputs.attached.gamepad;return e?e.gamepadAngularSensibility:0},set:function(e){var t=this.inputs.attached.gamepad;t&&(t.gamepadAngularSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"gamepadMoveSensibility",{get:function(){var e=this.inputs.attached.gamepad;return e?e.gamepadMoveSensibility:0},set:function(e){var t=this.inputs.attached.gamepad;t&&(t.gamepadMoveSensibility=e)},enumerable:!0,configurable:!0}),e.prototype.getClassName=function(){return"UniversalCamera"},e})(Qr.TouchCamera),Qr.UniversalCamera=Zr,(function(i){i.Node.AddNodeConstructor("GamepadCamera",(function(e,t){return function(){return new r(e,i.Vector3.Zero(),t)}}));var r=(function(r){function e(e,t,i){return r.call(this,e,t,i)||this}return T(e,r),e.prototype.getClassName=function(){return"GamepadCamera"},e})(i.UniversalCamera);i.GamepadCamera=r})($a||($a={})),qr=$a||($a={}),Jr=(function(){function e(){this._renderPipelines={}}return e.prototype.addPipeline=function(e){this._renderPipelines[e._name]=e},e.prototype.attachCamerasToRenderPipeline=function(e,t,i){void 0===i&&(i=!1);var r=this._renderPipelines[e];r&&r._attachCameras(t,i)},e.prototype.detachCamerasFromRenderPipeline=function(e,t){var i=this._renderPipelines[e];i&&i._detachCameras(t)},e.prototype.enableEffectInPipeline=function(e,t,i){var r=this._renderPipelines[e];r&&r._enableEffect(t,i)},e.prototype.disableEffectInPipeline=function(e,t,i){var r=this._renderPipelines[e];r&&r._disableEffect(t,i)},e.prototype.update=function(){for(var e in this._renderPipelines)if(this._renderPipelines.hasOwnProperty(e)){var t=this._renderPipelines[e];t.isSupported?t._update():(t.dispose(),delete this._renderPipelines[e])}},e.prototype._rebuild=function(){for(var e in this._renderPipelines){if(this._renderPipelines.hasOwnProperty(e))this._renderPipelines[e]._rebuild()}},e.prototype.dispose=function(){for(var e in this._renderPipelines){if(this._renderPipelines.hasOwnProperty(e))this._renderPipelines[e].dispose()}},e})(),qr.PostProcessRenderPipelineManager=Jr,(function(t){Object.defineProperty(t.Scene.prototype,"postProcessRenderPipelineManager",{get:function(){if(!this._postProcessRenderPipelineManager){var e=this._getComponent(t.SceneComponentConstants.NAME_POSTPROCESSRENDERPIPELINEMANAGER);e||(e=new i(this),this._addComponent(e)),this._postProcessRenderPipelineManager=new t.PostProcessRenderPipelineManager}return this._postProcessRenderPipelineManager},enumerable:!0,configurable:!0});var i=(function(){function e(e){this.name=t.SceneComponentConstants.NAME_POSTPROCESSRENDERPIPELINEMANAGER,this.scene=e}return e.prototype.register=function(){this.scene._gatherRenderTargetsStage.registerStep(t.SceneComponentConstants.STEP_GATHERRENDERTARGETS_POSTPROCESSRENDERPIPELINEMANAGER,this,this._gatherRenderTargets)},e.prototype.rebuild=function(){this.scene._postProcessRenderPipelineManager&&this.scene._postProcessRenderPipelineManager._rebuild()},e.prototype.dispose=function(){this.scene._postProcessRenderPipelineManager&&this.scene._postProcessRenderPipelineManager.dispose()},e.prototype._gatherRenderTargets=function(e){this.scene._postProcessRenderPipelineManager&&this.scene._postProcessRenderPipelineManager.update()},e})();t.PostProcessRenderPipelineManagerSceneComponent=i})($a||($a={})),$r=$a||($a={}),en=(function(){function e(e,t,i,r){this._name=t,this._singleInstance=r||!0,this._getPostProcesses=i,this._cameras={},this._indicesForCamera={},this._postProcesses={}}return Object.defineProperty(e.prototype,"isSupported",{get:function(){for(var e in this._postProcesses)if(this._postProcesses.hasOwnProperty(e))for(var t=this._postProcesses[e],i=0;i>16)>>>0,this._bits[0]=(1431655765&this._bits[0])<<1|(2863311530&this._bits[0])>>>1>>>0,this._bits[0]=(858993459&this._bits[0])<<2|(3435973836&this._bits[0])>>>2>>>0,this._bits[0]=(252645135&this._bits[0])<<4|(4042322160&this._bits[0])>>>4>>>0,this._bits[0]=(16711935&this._bits[0])<<8|(4278255360&this._bits[0])>>>8>>>0,2.3283064365386963e-10*this._bits[0]},r.prototype._hammersley=function(e,t){return[e/t,this._radicalInverse_VdC(e)]},r.prototype._hemisphereSample_uniform=function(e,t){var i=2*t*Math.PI,r=1-(.85*e+.15),n=Math.sqrt(1-r*r);return new hn.Vector3(Math.cos(i)*n,Math.sin(i)*n,r)},r.prototype._generateHemisphere=function(){for(var e,t=this.samples,i=[],r=0;r= 2.0")},c.prototype._createDownSampleX4PostProcess=function(e,t){var s=this,a=new Array(32);this.downSampleX4PostProcess=new pn.PostProcess("HDRDownSampleX4","standard",["dsOffsets"],[],t,null,pn.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define DOWN_SAMPLE_X4",pn.Engine.TEXTURETYPE_UNSIGNED_INT),this.downSampleX4PostProcess.onApply=function(e){for(var t=0,i=s.downSampleX4PostProcess.width,r=s.downSampleX4PostProcess.height,n=-2;n<2;n++)for(var o=-2;o<2;o++)a[t]=(n+.5)*(1/i),a[t+1]=(o+.5)*(1/r),t+=2;e.setArray2("dsOffsets",a)},this.addEffect(new pn.PostProcessRenderEffect(e.getEngine(),"HDRDownSampleX4",function(){return s.downSampleX4PostProcess},!0))},c.prototype._createBrightPassPostProcess=function(e,t){var r=this,n=new Array(8);this.brightPassPostProcess=new pn.PostProcess("HDRBrightPass","standard",["dsOffsets","brightThreshold"],[],t,null,pn.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define BRIGHT_PASS",pn.Engine.TEXTURETYPE_UNSIGNED_INT),this.brightPassPostProcess.onApply=function(e){var t=1/r.brightPassPostProcess.width,i=1/r.brightPassPostProcess.height;n[0]=-.5*t,n[1]=.5*i,n[2]=.5*t,n[3]=.5*i,n[4]=-.5*t,n[5]=-.5*i,n[6]=.5*t,n[7]=-.5*i,e.setArray2("dsOffsets",n),e.setFloat("brightThreshold",r.brightThreshold)},this.addEffect(new pn.PostProcessRenderEffect(e.getEngine(),"HDRBrightPass",function(){return r.brightPassPostProcess},!0))},c.prototype._createBlurPostProcesses=function(e,t,i,r){var n=this;void 0===r&&(r="blurWidth");var o=e.getEngine(),s=new pn.BlurPostProcess("HDRBlurH_"+i,new pn.Vector2(1,0),this[r],t,null,pn.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,pn.Engine.TEXTURETYPE_UNSIGNED_INT),a=new pn.BlurPostProcess("HDRBlurV_"+i,new pn.Vector2(0,1),this[r],t,null,pn.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,pn.Engine.TEXTURETYPE_UNSIGNED_INT);s.onActivateObservable.add((function(){var e=s.width/o.getRenderWidth();s.kernel=n[r]*e})),a.onActivateObservable.add((function(){var e=a.height/o.getRenderHeight();a.kernel=n.horizontalBlur?64*e:n[r]*e})),this.addEffect(new pn.PostProcessRenderEffect(e.getEngine(),"HDRBlurH"+i,function(){return s},!0)),this.addEffect(new pn.PostProcessRenderEffect(e.getEngine(),"HDRBlurV"+i,function(){return a},!0)),this.blurHPostProcesses.push(s),this.blurVPostProcesses.push(a)},c.prototype._createTextureAdderPostProcess=function(e,t){var i=this;this.textureAdderPostProcess=new pn.PostProcess("HDRTextureAdder","standard",["exposure"],["otherSampler","lensSampler"],t,null,pn.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define TEXTURE_ADDER",pn.Engine.TEXTURETYPE_UNSIGNED_INT),this.textureAdderPostProcess.onApply=function(e){e.setTextureFromPostProcess("otherSampler",i._vlsEnabled?i._currentDepthOfFieldSource:i.originalPostProcess),e.setTexture("lensSampler",i.lensTexture),e.setFloat("exposure",i.exposure),i._currentDepthOfFieldSource=i.textureAdderFinalPostProcess},this.addEffect(new pn.PostProcessRenderEffect(e.getEngine(),"HDRTextureAdder",function(){return i.textureAdderPostProcess},!0))},c.prototype._createVolumetricLightPostProcess=function(e,t){var i=this,r=e.enableGeometryBufferRenderer();r.enablePosition=!0;var n=r.getGBuffer();this.volumetricLightPostProcess=new pn.PostProcess("HDRVLS","standard",["shadowViewProjection","cameraPosition","sunDirection","sunColor","scatteringCoefficient","scatteringPower","depthValues"],["shadowMapSampler","positionSampler"],t/8,null,pn.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define VLS\n#define NB_STEPS "+this._volumetricLightStepsCount.toFixed(1));var o=pn.Vector2.Zero();this.volumetricLightPostProcess.onApply=function(e){if(i.sourceLight&&i.sourceLight.getShadowGenerator()&&i._scene.activeCamera){var t=i.sourceLight.getShadowGenerator();e.setTexture("shadowMapSampler",t.getShadowMap()),e.setTexture("positionSampler",n.textures[2]),e.setColor3("sunColor",i.sourceLight.diffuse),e.setVector3("sunDirection",i.sourceLight.getShadowDirection()),e.setVector3("cameraPosition",i._scene.activeCamera.globalPosition),e.setMatrix("shadowViewProjection",t.getTransformMatrix()),e.setFloat("scatteringCoefficient",i.volumetricLightCoefficient),e.setFloat("scatteringPower",i.volumetricLightPower),o.x=i.sourceLight.getDepthMinZ(i._scene.activeCamera),o.y=i.sourceLight.getDepthMaxZ(i._scene.activeCamera),e.setVector2("depthValues",o)}},this.addEffect(new pn.PostProcessRenderEffect(e.getEngine(),"HDRVLS",function(){return i.volumetricLightPostProcess},!0)),this._createBlurPostProcesses(e,t/4,0,"volumetricLightBlurScale"),this.volumetricLightMergePostProces=new pn.PostProcess("HDRVLSMerge","standard",[],["originalSampler"],t,null,pn.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define VLSMERGE"),this.volumetricLightMergePostProces.onApply=function(e){e.setTextureFromPostProcess("originalSampler",i._bloomEnabled?i.textureAdderFinalPostProcess:i.originalPostProcess),i._currentDepthOfFieldSource=i.volumetricLightFinalPostProcess},this.addEffect(new pn.PostProcessRenderEffect(e.getEngine(),"HDRVLSMerge",function(){return i.volumetricLightMergePostProces},!0))},c.prototype._createLuminancePostProcesses=function(r,e){var a=this,t=Math.pow(3,c.LuminanceSteps);this.luminancePostProcess=new pn.PostProcess("HDRLuminance","standard",["lumOffsets"],[],{width:t,height:t},null,pn.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1,"#define LUMINANCE",e);var n=[];this.luminancePostProcess.onApply=function(e){var t=1/a.luminancePostProcess.width,i=1/a.luminancePostProcess.height;n[0]=-.5*t,n[1]=.5*i,n[2]=.5*t,n[3]=.5*i,n[4]=-.5*t,n[5]=-.5*i,n[6]=.5*t,n[7]=-.5*i,e.setArray2("lumOffsets",n)},this.addEffect(new pn.PostProcessRenderEffect(r.getEngine(),"HDRLuminance",function(){return a.luminancePostProcess},!0));for(var i=c.LuminanceSteps-1;0<=i;i--){t=Math.pow(3,i);var o="#define LUMINANCE_DOWN_SAMPLE\n";0===i&&(o+="#define FINAL_DOWN_SAMPLER");var s=new pn.PostProcess("HDRLuminanceDownSample"+i,"standard",["dsOffsets","halfDestPixelSize"],[],{width:t,height:t},null,pn.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1,o,e);this.luminanceDownSamplePostProcesses.push(s)}var l=this.luminancePostProcess;this.luminanceDownSamplePostProcesses.forEach((function(n,o){var s=new Array(18);n.onApply=function(e){if(l){for(var t=0,i=-1;i<2;i++)for(var r=-1;r<2;r++)s[t]=i/l.width,s[t+1]=r/l.height,t+=2;e.setArray2("dsOffsets",s),e.setFloat("halfDestPixelSize",.5/l.width),l=o===a.luminanceDownSamplePostProcesses.length-1?a.luminancePostProcess:n}},o===a.luminanceDownSamplePostProcesses.length-1&&(n.onAfterRender=function(e){var t=r.getEngine().readPixels(0,0,1,1),i=new pn.Vector4(1/16581375,1/65025,1/255,1);a._hdrCurrentLuminance=(t[0]*i.x+t[1]*i.y+t[2]*i.z+t[3]*i.w)/100}),a.addEffect(new pn.PostProcessRenderEffect(r.getEngine(),"HDRLuminanceDownSample"+o,function(){return n},!0))}))},c.prototype._createHdrPostProcess=function(i,e){var r=this;this.hdrPostProcess=new pn.PostProcess("HDR","standard",["averageLuminance"],["textureAdderSampler"],e,null,pn.Texture.BILINEAR_SAMPLINGMODE,i.getEngine(),!1,"#define HDR",pn.Engine.TEXTURETYPE_UNSIGNED_INT);var n=1,o=0,s=0;this.hdrPostProcess.onApply=function(e){if(e.setTextureFromPostProcess("textureAdderSampler",r._currentDepthOfFieldSource),o+=i.getEngine().getDeltaTime(),n<0)n=r._hdrCurrentLuminance;else{var t=(s-o)/1e3;r._hdrCurrentLuminancen-r.hdrIncreaseRate*t?n-=r.hdrIncreaseRate*t:n=r._hdrCurrentLuminance}n=pn.Scalar.Clamp(n,r.hdrMinimumLuminance,1e20),e.setFloat("averageLuminance",n),s=o,r._currentDepthOfFieldSource=r.hdrFinalPostProcess},this.addEffect(new pn.PostProcessRenderEffect(i.getEngine(),"HDR",function(){return r.hdrPostProcess},!0))},c.prototype._createLensFlarePostProcess=function(e,t){var s=this;this.lensFlarePostProcess=new pn.PostProcess("HDRLensFlare","standard",["strength","ghostDispersal","haloWidth","resolution","distortionStrength"],["lensColorSampler"],t/2,null,pn.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define LENS_FLARE",pn.Engine.TEXTURETYPE_UNSIGNED_INT),this.addEffect(new pn.PostProcessRenderEffect(e.getEngine(),"HDRLensFlare",function(){return s.lensFlarePostProcess},!0)),this._createBlurPostProcesses(e,t/4,2),this.lensFlareComposePostProcess=new pn.PostProcess("HDRLensFlareCompose","standard",["lensStarMatrix"],["otherSampler","lensDirtSampler","lensStarSampler"],t,null,pn.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define LENS_FLARE_COMPOSE",pn.Engine.TEXTURETYPE_UNSIGNED_INT),this.addEffect(new pn.PostProcessRenderEffect(e.getEngine(),"HDRLensFlareCompose",function(){return s.lensFlareComposePostProcess},!0));var i=new pn.Vector2(0,0);this.lensFlarePostProcess.onApply=function(e){e.setTextureFromPostProcess("textureSampler",s._bloomEnabled?s.blurHPostProcesses[0]:s.originalPostProcess),e.setTexture("lensColorSampler",s.lensColorTexture),e.setFloat("strength",s.lensFlareStrength),e.setFloat("ghostDispersal",s.lensFlareGhostDispersal),e.setFloat("haloWidth",s.lensFlareHaloWidth),i.x=s.lensFlarePostProcess.width,i.y=s.lensFlarePostProcess.height,e.setVector2("resolution",i),e.setFloat("distortionStrength",s.lensFlareDistortionStrength)};var a=pn.Matrix.FromValues(2,0,-1,0,0,2,-1,0,0,0,1,0,0,0,0,1),l=pn.Matrix.FromValues(.5,0,.5,0,0,.5,.5,0,0,0,1,0,0,0,0,1);this.lensFlareComposePostProcess.onApply=function(e){if(s._scene.activeCamera){e.setTextureFromPostProcess("otherSampler",s._currentDepthOfFieldSource),e.setTexture("lensDirtSampler",s.lensFlareDirtTexture),e.setTexture("lensStarSampler",s.lensStarTexture);var t=s._scene.activeCamera.getViewMatrix().getRow(0),i=s._scene.activeCamera.getViewMatrix().getRow(2),r=pn.Vector3.Dot(t.toVector3(),new pn.Vector3(1,0,0))+pn.Vector3.Dot(i.toVector3(),new pn.Vector3(0,0,1));r*=4;var n=pn.Matrix.FromValues(.5*Math.cos(r),-Math.sin(r),0,0,Math.sin(r),.5*Math.cos(r),0,0,0,0,1,0,0,0,0,1),o=l.multiply(n).multiply(a);e.setMatrix("lensStarMatrix",o),s._currentDepthOfFieldSource=s.lensFlareFinalPostProcess}}},c.prototype._createDepthOfFieldPostProcess=function(e,t){var i=this;this.depthOfFieldPostProcess=new pn.PostProcess("HDRDepthOfField","standard",["distance"],["otherSampler","depthSampler"],t,null,pn.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define DEPTH_OF_FIELD",pn.Engine.TEXTURETYPE_UNSIGNED_INT),this.depthOfFieldPostProcess.onApply=function(e){e.setTextureFromPostProcess("otherSampler",i._currentDepthOfFieldSource),e.setTexture("depthSampler",i._getDepthTexture()),e.setFloat("distance",i.depthOfFieldDistance)},this.addEffect(new pn.PostProcessRenderEffect(e.getEngine(),"HDRDepthOfField",function(){return i.depthOfFieldPostProcess},!0))},c.prototype._createMotionBlurPostProcess=function(t,e){var i=this;this.motionBlurPostProcess=new pn.PostProcess("HDRMotionBlur","standard",["inverseViewProjection","prevViewProjection","screenSize","motionScale","motionStrength"],["depthSampler"],e,null,pn.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define MOTION_BLUR\n#define MAX_MOTION_SAMPLES "+this.motionBlurSamples.toFixed(1),pn.Engine.TEXTURETYPE_UNSIGNED_INT);var r=0,n=pn.Matrix.Identity(),o=pn.Matrix.Identity(),s=pn.Matrix.Identity(),a=pn.Vector2.Zero();this.motionBlurPostProcess.onApply=function(e){(s=t.getProjectionMatrix().multiply(t.getViewMatrix())).invertToRef(o),e.setMatrix("inverseViewProjection",o),e.setMatrix("prevViewProjection",n),n=s,a.x=i.motionBlurPostProcess.width,a.y=i.motionBlurPostProcess.height,e.setVector2("screenSize",a),r=t.getEngine().getFps()/60,e.setFloat("motionScale",r),e.setFloat("motionStrength",i.motionStrength),e.setTexture("depthSampler",i._getDepthTexture())},this.addEffect(new pn.PostProcessRenderEffect(t.getEngine(),"HDRMotionBlur",function(){return i.motionBlurPostProcess},!0))},c.prototype._getDepthTexture=function(){return this._scene.getEngine().getCaps().drawBuffersExtension?this._scene.enableGeometryBufferRenderer().getGBuffer().textures[0]:this._scene.enableDepthRenderer().getDepthMap()},c.prototype._disposePostProcesses=function(){for(var e=0;e= 2.0")}},r.prototype._disposePostProcesses=function(e){void 0===e&&(e=!1);for(var t=0;tt._alphaIndex?1:e._alphaIndext._distanceToCamera?-1:0})),o.setAlphaMode(Zn.Engine.ALPHA_COMBINE),n=0;n=c&&s.frame<=h&&(r?(l=s.value.clone(),m?(a=l.getTranslation(),l.setTranslation(a.scaleInPlace(_))):g&&n?(a=l.getTranslation(),l.setTranslation(a.multiplyInPlace(n))):l=s.value):l=s.value,v.push({frame:s.frame+i,value:l}));return this.animations[0].createRange(t,c+i,h+i),!0},d.prototype.translate=function(e,t,i){void 0===t&&(t=so.Space.LOCAL);var r=this.getLocalMatrix();if(t==so.Space.LOCAL)r.m[12]+=e.x,r.m[13]+=e.y,r.m[14]+=e.z;else{var n=null;i&&(n=i.getWorldMatrix()),this._skeleton.computeAbsoluteTransforms();var o=d._tmpMats[0],s=d._tmpVecs[0];this._parent&&(i&&n?(o.copyFrom(this._parent.getAbsoluteTransform()),o.multiplyToRef(n,o)):o.copyFrom(this._parent.getAbsoluteTransform())),o.m[12]=0,o.m[13]=0,o.m[14]=0,o.invert(),so.Vector3.TransformCoordinatesToRef(e,o,s),r.m[12]+=s.x,r.m[13]+=s.y,r.m[14]+=s.z}this._markAsDirtyAndDecompose()},d.prototype.setPosition=function(e,t,i){void 0===t&&(t=so.Space.LOCAL);var r=this.getLocalMatrix();if(t==so.Space.LOCAL)r.m[12]=e.x,r.m[13]=e.y,r.m[14]=e.z;else{var n=null;i&&(n=i.getWorldMatrix()),this._skeleton.computeAbsoluteTransforms();var o=d._tmpMats[0],s=d._tmpVecs[0];this._parent&&(i&&n?(o.copyFrom(this._parent.getAbsoluteTransform()),o.multiplyToRef(n,o)):o.copyFrom(this._parent.getAbsoluteTransform())),o.invert(),so.Vector3.TransformCoordinatesToRef(e,o,s),r.m[12]=s.x,r.m[13]=s.y,r.m[14]=s.z}this._markAsDirtyAndDecompose()},d.prototype.setAbsolutePosition=function(e,t){this.setPosition(e,so.Space.WORLD,t)},d.prototype.scale=function(e,t,i,r){void 0===r&&(r=!1);var n=this.getLocalMatrix(),o=d._tmpMats[0];so.Matrix.ScalingToRef(e,t,i,o),o.multiplyToRef(n,n),o.invert();for(var s=0,a=this.children;sr.y&&r.x>r.z&&(this._adjustRoll=.5*Math.PI,this._bendAxis.z=1)),this._bone1.length){var n=this._bone1.getScale(),o=this._bone2.getScale();this._bone1Length=this._bone1.length*n.y*this.mesh.scaling.y,this._bone2Length=this._bone2.length*o.y*this.mesh.scaling.y}else if(this._bone1.children[0]){e.computeWorldMatrix(!0);var s=this._bone2.children[0].getAbsolutePosition(e),a=this._bone2.getAbsolutePosition(e),l=this._bone1.getAbsolutePosition(e);this._bone1Length=lo.Vector3.Distance(s,a),this._bone2Length=lo.Vector3.Distance(a,l)}this._bone1.getRotationMatrixToRef(lo.Space.WORLD,e,this._bone1Mat),this.maxAngle=Math.PI,i&&(i.targetMesh&&(this.targetMesh=i.targetMesh,this.targetMesh.computeWorldMatrix(!0)),i.poleTargetMesh?(this.poleTargetMesh=i.poleTargetMesh,this.poleTargetMesh.computeWorldMatrix(!0)):i.poleTargetBone?this.poleTargetBone=i.poleTargetBone:this._bone1.getParent()&&(this.poleTargetBone=this._bone1.getParent()),i.poleTargetLocalOffset&&this.poleTargetLocalOffset.copyFrom(i.poleTargetLocalOffset),i.poleAngle&&(this.poleAngle=i.poleAngle),i.bendAxis&&this._bendAxis.copyFrom(i.bendAxis),i.maxAngle&&(this.maxAngle=i.maxAngle),i.slerpAmount&&(this.slerpAmount=i.slerpAmount))}}return Object.defineProperty(b.prototype,"maxAngle",{get:function(){return this._maxAngle},set:function(e){this._setMaxAngle(e)},enumerable:!0,configurable:!0}),b.prototype._setMaxAngle=function(e){e<0&&(e=0),(e>Math.PI||null==e)&&(e=Math.PI),this._maxAngle=e;var t=this._bone1Length,i=this._bone2Length;this._maxReach=Math.sqrt(t*t+i*i-2*t*i*Math.cos(e))},b.prototype.update=function(){var e=this._bone1;if(e){var t=this.targetPosition,i=this.poleTargetPosition,r=b._tmpMats[0],n=b._tmpMats[1];this.targetMesh&&t.copyFrom(this.targetMesh.getAbsolutePosition()),this.poleTargetBone?this.poleTargetBone.getAbsolutePositionFromLocalToRef(this.poleTargetLocalOffset,this.mesh,i):this.poleTargetMesh&&lo.Vector3.TransformCoordinatesToRef(this.poleTargetLocalOffset,this.poleTargetMesh.getWorldMatrix(),i);var o=b._tmpVecs[0],s=b._tmpVecs[1],a=b._tmpVecs[2],l=b._tmpVecs[3],c=b._tmpVecs[4],h=b._tmpQuat;e.getAbsolutePositionToRef(this.mesh,o),i.subtractToRef(o,c),0==c.x&&0==c.y&&0==c.z?c.y=1:c.normalize(),t.subtractToRef(o,l),l.normalize(),lo.Vector3.CrossToRef(l,c,s),s.normalize(),lo.Vector3.CrossToRef(l,s,a),a.normalize(),lo.Matrix.FromXYZAxesToRef(a,l,s,r);var u=this._bone1Length,d=this._bone2Length,f=lo.Vector3.Distance(o,t);0this._maxPitch?(m.y=this._maxPitchTan*p,g=this._maxPitch):_this._maxYaw||vMath.PI?this._isAngleBetween(v,this._maxYaw,this._midYawConstraint)?(m.z=this._maxYawCos*p,m.x=this._maxYawSin*p,y=this._maxYaw):this._isAngleBetween(v,this._midYawConstraint,this._minYaw)&&(m.z=this._minYawCos*p,m.x=this._minYawSin*p,y=this._minYaw):v>this._maxYaw?(m.z=this._maxYawCos*p,m.x=this._maxYawSin*p,y=this._maxYaw):vMath.PI){var b=C._tmpVecs[8];b.copyFrom(ho.Axis.Z),this._transformYawPitch&&ho.Vector3.TransformCoordinatesToRef(b,this._transformYawPitchInv,b);var T=C._tmpMats[4];this._boneQuat.toRotationMatrix(T),this.mesh.getWorldMatrix().multiplyToRef(T,T),ho.Vector3.TransformCoordinatesToRef(b,T,b),ho.Vector3.TransformCoordinatesToRef(b,u,b);var x=Math.atan2(b.x,b.z),E=this._getAngleBetween(x,v);if(this._getAngleBetween(x,this._midYawConstraint)Math.PI?i-=2*Math.PI:i<-Math.PI&&(i+=2*Math.PI),i},C.prototype._getAngleBetween=function(e,t){var i=0;return(i=(e=(e%=2*Math.PI)<0?e+2*Math.PI:e)<(t=(t%=2*Math.PI)<0?t+2*Math.PI:t)?t-e:e-t)>Math.PI&&(i=2*Math.PI-i),i},C.prototype._isAngleBetween=function(e,t,i){if(e=(e%=2*Math.PI)<0?e+2*Math.PI:e,(t=(t%=2*Math.PI)<0?t+2*Math.PI:t)<(i=(i%=2*Math.PI)<0?i+2*Math.PI:i)){if(tMath.PI;)n-=2*Math.PI;var s=n/Math.PI,a=o/Math.PI;s=.5*s+.5;var l=Math.round(s*i);l<0?l=0:i<=l&&(l=i-1);var c=Math.round(a*r);c<0?c=0:r<=c&&(c=r-1);var h=r-c-1;return{r:t[h*i*3+3*l+0],g:t[h*i*3+3*l+1],b:t[h*i*3+3*l+2]}},e.FACE_FRONT=[new yo.Vector3(-1,-1,-1),new yo.Vector3(1,-1,-1),new yo.Vector3(-1,1,-1),new yo.Vector3(1,1,-1)],e.FACE_BACK=[new yo.Vector3(1,-1,1),new yo.Vector3(-1,-1,1),new yo.Vector3(1,1,1),new yo.Vector3(-1,1,1)],e.FACE_RIGHT=[new yo.Vector3(1,-1,-1),new yo.Vector3(1,-1,1),new yo.Vector3(1,1,-1),new yo.Vector3(1,1,1)],e.FACE_LEFT=[new yo.Vector3(-1,-1,1),new yo.Vector3(-1,-1,-1),new yo.Vector3(-1,1,1),new yo.Vector3(-1,1,-1)],e.FACE_DOWN=[new yo.Vector3(-1,1,-1),new yo.Vector3(1,1,-1),new yo.Vector3(-1,1,1),new yo.Vector3(1,1,1)],e.FACE_UP=[new yo.Vector3(-1,-1,1),new yo.Vector3(1,-1,1),new yo.Vector3(-1,-1,-1),new yo.Vector3(1,-1,-1)],e})(),yo.PanoramaToCubeMapTools=bo,(function(g){var n=(function(r){function e(e,t){var i=r.call(this,e.x,e.y)||this;return i.index=t,i}return T(e,r),e})(g.Vector2),o=(function(){function e(){this.elements=new Array}return e.prototype.add=function(e){var i=this,r=new Array;return e.forEach((function(e){if(0===r.length||!e.equalsWithEpsilon(r[0])){var t=new n(e,i.elements.length);r.push(t),i.elements.push(t)}})),r},e.prototype.computeBounds=function(){var t=new g.Vector2(this.elements[0].x,this.elements[0].y),i=new g.Vector2(this.elements[0].x,this.elements[0].y);return this.elements.forEach((function(e){e.xi.x&&(i.x=e.x),e.yi.y&&(i.y=e.y)})),{min:t,max:i,width:i.x-t.x,height:i.y-t.y}},e})(),e=(function(){function e(){}return e.Rectangle=function(e,t,i,r){return[new g.Vector2(e,t),new g.Vector2(i,t),new g.Vector2(i,r),new g.Vector2(e,r)]},e.Circle=function(e,t,i,r){void 0===t&&(t=0),void 0===i&&(i=0),void 0===r&&(r=32);for(var n=new Array,o=0,s=2*Math.PI/r,a=0;ao.elements.length-1?o.elements[0]:o.elements[h+1],e.push(d.x,0,d.y),e.push(d.x,-s,d.y),e.push(u.x,0,u.y),e.push(u.x,-s,u.y);var f=new g.Vector3(d.x,0,d.y),p=new g.Vector3(u.x,0,u.y).subtract(f),m=new g.Vector3(0,1,0),_=g.Vector3.Cross(p,m);_=_.normalize(),i.push(c/n.width,0),i.push(c/n.width,1),c+=p.length(),i.push(c/n.width,0),i.push(c/n.width,1),a?(t.push(_.x,_.y,_.z),t.push(_.x,_.y,_.z),t.push(_.x,_.y,_.z),t.push(_.x,_.y,_.z),r.push(l),r.push(l+2),r.push(l+1),r.push(l+1),r.push(l+2),r.push(l+3)):(t.push(-_.x,-_.y,-_.z),t.push(-_.x,-_.y,-_.z),t.push(-_.x,-_.y,-_.z),t.push(-_.x,-_.y,-_.z),r.push(l),r.push(l+1),r.push(l+2),r.push(l+1),r.push(l+3),r.push(l+2)),l+=4}},e})();g.PolygonMeshBuilder=t})($a||($a={})),To=$a||($a={}),xo=0,Eo=(function(){function i(e,t,i){this.pos=e,this.normal=t,this.uv=i}return i.prototype.clone=function(){return new i(this.pos.clone(),this.normal.clone(),this.uv.clone())},i.prototype.flip=function(){this.normal=this.normal.scale(-1)},i.prototype.interpolate=function(e,t){return new i(To.Vector3.Lerp(this.pos,e.pos,t),To.Vector3.Lerp(this.normal,e.normal,t),To.Vector2.Lerp(this.uv,e.uv,t))},i})(),Ao=(function(){function y(e,t){this.normal=e,this.w=t}return y.FromPoints=function(e,t,i){var r=i.subtract(e),n=t.subtract(e);if(0===r.lengthSquared()||0===n.lengthSquared())return null;var o=To.Vector3.Normalize(To.Vector3.Cross(r,n));return new y(o,To.Vector3.Dot(o,e))},y.prototype.clone=function(){return new y(this.normal.clone(),this.w)},y.prototype.flip=function(){this.normal.scaleInPlace(-1),this.w=-this.w},y.prototype.splitPolygon=function(e,t,i,r,n){var o,s,a=0,l=[];for(o=0;oe.x&&this._positionXe.y&&(this._positionY,e.y,e.height),!0)},l.prototype._isVisible=function(){if(!this._isEnabled||!this._scene.activeCamera)return!1;var e=this.getEmitterPosition().subtract(this._scene.activeCamera.globalPosition),t=e.length();e.normalize();var i=new Oo.Ray(this._scene.activeCamera.globalPosition,e),r=this._scene.pickWithRay(i,this.meshesSelectionPredicate,!0);return!r||!r.hit||r.distance>t},l.prototype.render=function(){if(!this._effect.isReady()||!this._scene.activeCamera)return!1;var e,t,i=this._scene.getEngine(),r=this._scene.activeCamera.viewport.toGlobal(i.getRenderWidth(!0),i.getRenderHeight(!0));if(!this.computeEffectivePosition(r))return!1;if(!this._isVisible())return!1;e=this._positionXr.x+r.width-this.borderLimit?this._positionX-r.x-r.width+this.borderLimit:0;var n=(t=this._positionYr.y+r.height-this.borderLimit?this._positionY-r.y-r.height+this.borderLimit:0)this.borderLimit&&(n=this.borderLimit);var o=1-Oo.Scalar.Clamp(n/this.borderLimit,0,1);if(o<0)return!1;1this._centripetalForceThreshold&&(l=l.negate()),s>this._centripetalForceThreshold)var c=l.x*this._strength/8,h=l.y*this._updraftMultiplier,u=l.z*this._strength/8;else c=(a.x+l.x)/2,h=this._originTop.y*this._updraftMultiplier,u=(a.z+l.z)/2;var d=new f.Vector3(c,h,u);return{force:d=d.multiplyByFloats(this._strength,this._strength,this._strength),contactPoint:t}},e.prototype._tick=function(){var i=this;this._physicsEngine.getImpostors().forEach((function(e){var t=i.getImpostorForceAndContactPoint(e);t&&e.applyForce(t.force,t.contactPoint)}))},e.prototype._prepareCylinder=function(){this._cylinder||(this._cylinder=f.MeshBuilder.CreateCylinder("vortexEventCylinder",{height:this._height,diameter:2*this._radius},this._scene),this._cylinder.isVisible=!1)},e.prototype._intersectsWithCylinder=function(e){var t=e.object;return this._prepareCylinder(),this._cylinder.position=this._cylinderPosition,this._cylinder.intersectsMesh(t,!0)},e})();f.PhysicsVortexEvent=l,(i=h=f.PhysicsRadialImpulseFalloff||(f.PhysicsRadialImpulseFalloff={}))[i.Constant=0]="Constant",i[i.Linear=1]="Linear",(r=a=f.PhysicsUpdraftMode||(f.PhysicsUpdraftMode={}))[r.Center=0]="Center",r[r.Perpendicular=1]="Perpendicular"})($a||($a={})),Bo=$a||($a={}),No=(function(){function e(e,t){void 0===e&&(e=!0),void 0===t&&(t=10),this._useDeltaForWorldStep=e,this.name="CannonJSPlugin",this._physicsMaterials=new Array,this._fixedTimeStep=1/60,this.BJSCANNON=i,this._minus90X=new Bo.Quaternion(-.7071067811865475,0,0,.7071067811865475),this._plus90X=new Bo.Quaternion(.7071067811865475,0,0,.7071067811865475),this._tmpPosition=Bo.Vector3.Zero(),this._tmpDeltaPosition=Bo.Vector3.Zero(),this._tmpUnityRotation=new Bo.Quaternion,this.isSupported()?(this._extendNamespace(),this.world=new this.BJSCANNON.World,this.world.broadphase=new this.BJSCANNON.NaiveBroadphase,this.world.solver.iterations=t):Bo.Tools.Error("CannonJS is not available. Please make sure you included the js file.")}return e.prototype.setGravity=function(e){this.world.gravity.copy(e)},e.prototype.setTimeStep=function(e){this._fixedTimeStep=e},e.prototype.getTimeStep=function(){return this._fixedTimeStep},e.prototype.executeStep=function(e,t){this.world.step(this._fixedTimeStep,this._useDeltaForWorldStep?e:0,3)},e.prototype.applyImpulse=function(e,t,i){var r=new this.BJSCANNON.Vec3(i.x,i.y,i.z),n=new this.BJSCANNON.Vec3(t.x,t.y,t.z);e.physicsBody.applyImpulse(n,r)},e.prototype.applyForce=function(e,t,i){var r=new this.BJSCANNON.Vec3(i.x,i.y,i.z),n=new this.BJSCANNON.Vec3(t.x,t.y,t.z);e.physicsBody.applyForce(n,r)},e.prototype.generatePhysicsBody=function(t){if(t.parent)t.physicsBody&&(this.removePhysicsBody(t),t.forceUpdate());else{if(t.isBodyInitRequired()){var e=this._createShape(t),i=t.physicsBody;i&&this.removePhysicsBody(t);var r=this._addMaterial("mat-"+t.uniqueId,t.getParam("friction"),t.getParam("restitution")),n={mass:t.getParam("mass"),material:r},o=t.getParam("nativeOptions");for(var s in o)o.hasOwnProperty(s)&&(n[s]=o[s]);t.physicsBody=new this.BJSCANNON.Body(n),t.physicsBody.addEventListener("collide",t.onCollide),this.world.addEventListener("preStep",t.beforeStep),this.world.addEventListener("postStep",t.afterStep),t.physicsBody.addShape(e),this.world.add(t.physicsBody),i&&["force","torque","velocity","angularVelocity"].forEach((function(e){t.physicsBody[e].copy(i[e])})),this._processChildMeshes(t)}this._updatePhysicsBodyTransformation(t)}},e.prototype._processChildMeshes=function(o){var s=this,e=o.object.getChildMeshes?o.object.getChildMeshes(!0):[],a=o.object.rotationQuaternion;if(e.length){var l=function(e,t){if(a&&t.rotationQuaternion){var i=t.getPhysicsImpostor();if(i)if(i.parent!==o){var r=t.getAbsolutePosition().subtract(o.object.getAbsolutePosition()),n=t.rotationQuaternion.multiply(Bo.Quaternion.Inverse(a));i.physicsBody&&(s.removePhysicsBody(i),i.physicsBody=null),i.parent=o,i.resetUpdateFlags(),o.physicsBody.addShape(s._createShape(i),new s.BJSCANNON.Vec3(r.x,r.y,r.z),new s.BJSCANNON.Quaternion(n.x,n.y,n.z,n.w)),o.physicsBody.mass+=i.getParam("mass")}a.multiplyInPlace(t.rotationQuaternion),t.getChildMeshes(!0).filter((function(e){return!!e.physicsImpostor})).forEach(l.bind(s,t.getAbsolutePosition()))}};e.filter((function(e){return!!e.physicsImpostor})).forEach(l.bind(this,o.object.getAbsolutePosition()))}},e.prototype.removePhysicsBody=function(e){e.physicsBody.removeEventListener("collide",e.onCollide),this.world.removeEventListener("preStep",e.beforeStep),this.world.removeEventListener("postStep",e.afterStep),this.world.remove(e.physicsBody)},e.prototype.generateJoint=function(e){var t=e.mainImpostor.physicsBody,i=e.connectedImpostor.physicsBody;if(t&&i){var r,n=e.joint.jointData,o={pivotA:n.mainPivot?(new this.BJSCANNON.Vec3).copy(n.mainPivot):null,pivotB:n.connectedPivot?(new this.BJSCANNON.Vec3).copy(n.connectedPivot):null,axisA:n.mainAxis?(new this.BJSCANNON.Vec3).copy(n.mainAxis):null,axisB:n.connectedAxis?(new this.BJSCANNON.Vec3).copy(n.connectedAxis):null,maxForce:n.nativeParams.maxForce,collideConnected:!!n.collision};switch(e.joint.type){case Bo.PhysicsJoint.HingeJoint:case Bo.PhysicsJoint.Hinge2Joint:r=new this.BJSCANNON.HingeConstraint(t,i,o);break;case Bo.PhysicsJoint.DistanceJoint:r=new this.BJSCANNON.DistanceConstraint(t,i,n.maxDistance||2);break;case Bo.PhysicsJoint.SpringJoint:var s=n;r=new this.BJSCANNON.Spring(t,i,{restLength:s.length,stiffness:s.stiffness,damping:s.damping,localAnchorA:o.pivotA,localAnchorB:o.pivotB});break;case Bo.PhysicsJoint.LockJoint:r=new this.BJSCANNON.LockConstraint(t,i,o);break;case Bo.PhysicsJoint.PointToPointJoint:case Bo.PhysicsJoint.BallAndSocketJoint:default:r=new this.BJSCANNON.PointToPointConstraint(t,o.pivotA,i,o.pivotA,o.maxForce)}r.collideConnected=!!n.collision,e.joint.physicsJoint=r,e.joint.type!==Bo.PhysicsJoint.SpringJoint?this.world.addConstraint(r):(e.joint.jointData.forceApplicationCallback=e.joint.jointData.forceApplicationCallback||function(){r.applyForce()},e.mainImpostor.registerAfterPhysicsStep(e.joint.jointData.forceApplicationCallback))}},e.prototype.removeJoint=function(e){e.joint.type!==Bo.PhysicsJoint.SpringJoint?this.world.removeConstraint(e.joint.physicsJoint):e.mainImpostor.unregisterAfterPhysicsStep(e.joint.jointData.forceApplicationCallback)},e.prototype._addMaterial=function(e,t,i){var r,n;for(r=0;r1e3*e));o++);this.time+=t;for(var s=this.time%e/e,a=u,l=this.bodies,c=0;c!==l.length;c++){var h=l[c];h.type!==d.Body.STATIC&&h.sleepState!==d.Body.SLEEPING?(h.position.vsub(h.previousPosition,a),a.scale(s,a),h.position.vadd(a,h.interpolatedPosition)):(h.interpolatedPosition.copy(h.position),h.interpolatedQuaternion.copy(h.quaternion))}}}},e})(),Bo.CannonJSPlugin=No,Vo=$a||($a={}),Uo=(function(){function e(e){this.name="OimoJSPlugin",this._tmpImpostorsArray=[],this._tmpPositionVector=Vo.Vector3.Zero(),this.BJSOIMO=t,this.world=new this.BJSOIMO.World({iterations:e}),this.world.clear()}return e.prototype.setGravity=function(e){this.world.gravity.copy(e)},e.prototype.setTimeStep=function(e){this.world.timeStep=e},e.prototype.getTimeStep=function(){return this.world.timeStep},e.prototype.executeStep=function(e,t){var i=this;t.forEach((function(e){e.beforeStep()})),this.world.step(),t.forEach((function(e){e.afterStep(),i._tmpImpostorsArray[e.uniqueId]=e}));for(var r=this.world.contacts;null!==r;)if(!r.touching||r.body1.sleeping||r.body2.sleeping){var n=this._tmpImpostorsArray[+r.body1.name],o=this._tmpImpostorsArray[+r.body2.name];n&&o&&(n.onCollide({body:o.physicsBody}),o.onCollide({body:n.physicsBody})),r=r.next}else r=r.next},e.prototype.applyImpulse=function(e,t,i){var r=e.physicsBody.mass;e.physicsBody.applyImpulse(i.scale(this.world.invScale),t.scale(this.world.invScale*r))},e.prototype.applyForce=function(e,t,i){Vo.Tools.Warn("Oimo doesn't support applying force. Using impule instead."),this.applyImpulse(e,t,i)},e.prototype.generatePhysicsBody=function(p){var m=this;if(p.parent)p.physicsBody&&(this.removePhysicsBody(p),p.forceUpdate());else{if(p.isBodyInitRequired()){var _={name:p.uniqueId,config:[p.getParam("mass")||1,p.getParam("friction"),p.getParam("restitution")],size:[],type:[],pos:[],posShape:[],rot:[],rotShape:[],move:0!==p.getParam("mass"),density:p.getParam("mass"),friction:p.getParam("friction"),restitution:p.getParam("restitution"),world:this.world},t=[p];(e=p.object).getChildMeshes&&e.getChildMeshes().forEach((function(e){e.physicsImpostor&&t.push(e.physicsImpostor)}));var g=function(e){return Math.max(e,Vo.PhysicsEngine.Epsilon)},v=new Vo.Quaternion;t.forEach((function(e){if(e.object.rotationQuaternion){var t=e.object.rotationQuaternion;v=t.clone();var i=t.toEulerAngles(),r=e.getObjectExtendSize(),n=57.29577951308232;if(e===p){var o=p.getObjectCenter();p.object.getAbsolutePivotPoint().subtractToRef(o,m._tmpPositionVector),m._tmpPositionVector.divideInPlace(p.object.scaling),_.pos.push(o.x),_.pos.push(o.y),_.pos.push(o.z),_.posShape.push(0,0,0),_.rot.push(0),_.rot.push(0),_.rot.push(0),_.rotShape.push(0,0,0)}else{var s=e.object.getAbsolutePosition().subtract(p.object.getAbsolutePosition());_.posShape.push(s.x),_.posShape.push(s.y),_.posShape.push(s.z),_.pos.push(0,0,0),_.rot.push(0),_.rot.push(0),_.rot.push(0),_.rotShape.push(i.x*n),_.rotShape.push(i.y*n),_.rotShape.push(i.z*n)}switch(e.type){case Vo.PhysicsImpostor.ParticleImpostor:Vo.Tools.Warn("No Particle support in OIMO.js. using SphereImpostor instead");case Vo.PhysicsImpostor.SphereImpostor:var a=r.x,l=r.y,c=r.z,h=Math.max(g(a),g(l),g(c))/2;_.type.push("sphere"),_.size.push(h),_.size.push(h),_.size.push(h);break;case Vo.PhysicsImpostor.CylinderImpostor:var u=g(r.x)/2,d=g(r.y);_.type.push("cylinder"),_.size.push(u),_.size.push(d),_.size.push(d);break;case Vo.PhysicsImpostor.PlaneImpostor:case Vo.PhysicsImpostor.BoxImpostor:default:u=g(r.x),d=g(r.y);var f=g(r.z);_.type.push("box"),_.size.push(u),_.size.push(d),_.size.push(f)}e.object.rotationQuaternion=t}})),p.physicsBody=this.world.add(_),p.physicsBody.resetQuaternion(v),p.physicsBody.updatePosition(0)}else this._tmpPositionVector.copyFromFloats(0,0,0);var e;p.setDeltaPosition(this._tmpPositionVector)}},e.prototype.removePhysicsBody=function(e){this.world.removeRigidBody(e.physicsBody)},e.prototype.generateJoint=function(e){var t=e.mainImpostor.physicsBody,i=e.connectedImpostor.physicsBody;if(t&&i){var r,n=e.joint.jointData,o=n.nativeParams||{},s={body1:t,body2:i,axe1:o.axe1||(n.mainAxis?n.mainAxis.asArray():null),axe2:o.axe2||(n.connectedAxis?n.connectedAxis.asArray():null),pos1:o.pos1||(n.mainPivot?n.mainPivot.asArray():null),pos2:o.pos2||(n.connectedPivot?n.connectedPivot.asArray():null),min:o.min,max:o.max,collision:o.collision||n.collision,spring:o.spring,world:this.world};switch(e.joint.type){case Vo.PhysicsJoint.BallAndSocketJoint:r="jointBall";break;case Vo.PhysicsJoint.SpringJoint:Vo.Tools.Warn("OIMO.js doesn't support Spring Constraint. Simulating using DistanceJoint instead");var a=n;s.min=a.length||s.min,s.max=Math.max(s.min,s.max);case Vo.PhysicsJoint.DistanceJoint:r="jointDistance",s.max=n.maxDistance;break;case Vo.PhysicsJoint.PrismaticJoint:r="jointPrisme";break;case Vo.PhysicsJoint.SliderJoint:r="jointSlide";break;case Vo.PhysicsJoint.WheelJoint:r="jointWheel";break;case Vo.PhysicsJoint.HingeJoint:default:r="jointHinge"}s.type=r,e.joint.physicsJoint=this.world.add(s)}},e.prototype.removeJoint=function(e){try{this.world.removeJoint(e.joint.physicsJoint)}catch(e){Vo.Tools.Warn(e)}},e.prototype.isSupported=function(){return void 0!==this.BJSOIMO},e.prototype.setTransformationFromPhysicsBody=function(e){e.physicsBody.sleeping||(e.object.position.copyFrom(e.physicsBody.getPosition()),e.object.rotationQuaternion&&e.object.rotationQuaternion.copyFrom(e.physicsBody.getQuaternion()))},e.prototype.setPhysicsBodyTransformation=function(e,t,i){var r=e.physicsBody;r.position.copy(t),r.orientation.copy(i),r.syncShapes(),r.awake()},e.prototype.setLinearVelocity=function(e,t){e.physicsBody.linearVelocity.copy(t)},e.prototype.setAngularVelocity=function(e,t){e.physicsBody.angularVelocity.copy(t)},e.prototype.getLinearVelocity=function(e){var t=e.physicsBody.linearVelocity;return t?new Vo.Vector3(t.x,t.y,t.z):null},e.prototype.getAngularVelocity=function(e){var t=e.physicsBody.angularVelocity;return t?new Vo.Vector3(t.x,t.y,t.z):null},e.prototype.setBodyMass=function(e,t){var i=0===t;e.physicsBody.shapes.density=i?1:t,e.physicsBody.setupMass(i?2:1)},e.prototype.getBodyMass=function(e){return e.physicsBody.shapes.density},e.prototype.getBodyFriction=function(e){return e.physicsBody.shapes.friction},e.prototype.setBodyFriction=function(e,t){e.physicsBody.shapes.friction=t},e.prototype.getBodyRestitution=function(e){return e.physicsBody.shapes.restitution},e.prototype.setBodyRestitution=function(e,t){e.physicsBody.shapes.restitution=t},e.prototype.sleepBody=function(e){e.physicsBody.sleep()},e.prototype.wakeUpBody=function(e){e.physicsBody.awake()},e.prototype.updateDistanceJoint=function(e,t,i){e.physicsJoint.limitMotor.upperLimit=t,void 0!==i&&(e.physicsJoint.limitMotor.lowerLimit=i)},e.prototype.setMotor=function(e,t,i,r){var n=r?e.physicsJoint.rotationalLimitMotor2:e.physicsJoint.rotationalLimitMotor1||e.physicsJoint.rotationalLimitMotor||e.physicsJoint.limitMotor;n&&n.setMotor(t,i)},e.prototype.setLimit=function(e,t,i,r){var n=r?e.physicsJoint.rotationalLimitMotor2:e.physicsJoint.rotationalLimitMotor1||e.physicsJoint.rotationalLimitMotor||e.physicsJoint.limitMotor;n&&n.setLimit(t,void 0===i?-t:i)},e.prototype.syncMeshWithImpostor=function(e,t){var i=t.physicsBody;e.position.x=i.position.x,e.position.y=i.position.y,e.position.z=i.position.z,e.rotationQuaternion&&(e.rotationQuaternion.x=i.orientation.x,e.rotationQuaternion.y=i.orientation.y,e.rotationQuaternion.z=i.orientation.z,e.rotationQuaternion.w=i.orientation.s)},e.prototype.getRadius=function(e){return e.physicsBody.shapes.radius},e.prototype.getBoxSizeToRef=function(e,t){var i=e.physicsBody.shapes;t.x=2*i.halfWidth,t.y=2*i.halfHeight,t.z=2*i.halfDepth},e.prototype.dispose=function(){this.world.clear()},e})(),Vo.OimoJSPlugin=Uo,(function(n){n.Scene.prototype.getPhysicsEngine=function(){return this._physicsEngine},n.Scene.prototype.enablePhysics=function(e,t){if(void 0===e&&(e=null),this._physicsEngine)return!0;var i=this._getComponent(n.SceneComponentConstants.NAME_PHYSICSENGINE);i||(i=new r(this),this._addComponent(i));try{return this._physicsEngine=new n.PhysicsEngine(e,t),!0}catch(e){return n.Tools.Error(e.message),!1}},n.Scene.prototype.disablePhysicsEngine=function(){this._physicsEngine&&(this._physicsEngine.dispose(),this._physicsEngine=null)},n.Scene.prototype.isPhysicsEnabled=function(){return void 0!==this._physicsEngine},n.Scene.prototype.deleteCompoundImpostor=function(e){var t=e.parts[0].mesh;t.physicsImpostor&&(t.physicsImpostor.dispose(),t.physicsImpostor=null)},n.Scene.prototype._advancePhysicsEngineStep=function(e){this._physicsEngine&&(this.onBeforePhysicsObservable.notifyObservers(this),this._physicsEngine._step(e/1e3),this.onAfterPhysicsObservable.notifyObservers(this))},Object.defineProperty(n.AbstractMesh.prototype,"physicsImpostor",{get:function(){return this._physicsImpostor},set:function(e){var t=this;this._physicsImpostor!==e&&(this._disposePhysicsObserver&&this.onDisposeObservable.remove(this._disposePhysicsObserver),(this._physicsImpostor=e)&&(this._disposePhysicsObserver=this.onDisposeObservable.add((function(){t.physicsImpostor&&(t.physicsImpostor.dispose(),t.physicsImpostor=null)}))))},enumerable:!0,configurable:!0}),n.AbstractMesh.prototype.getPhysicsImpostor=function(){return this.physicsImpostor},n.AbstractMesh.prototype.applyImpulse=function(e,t){return this.physicsImpostor&&this.physicsImpostor.applyImpulse(e,t),this},n.AbstractMesh.prototype.setPhysicsLinkWith=function(e,t,i,r){return this.physicsImpostor&&e.physicsImpostor&&this.physicsImpostor.createJoint(e.physicsImpostor,n.PhysicsJoint.HingeJoint,{mainPivot:t,connectedPivot:i,nativeParams:r}),this};var r=(function(){function e(e){var t=this;this.name=n.SceneComponentConstants.NAME_PHYSICSENGINE,this.scene=e,this.scene.onBeforePhysicsObservable=new n.Observable,this.scene.onAfterPhysicsObservable=new n.Observable,this.scene.getDeterministicFrameTime=function(){return t.scene._physicsEngine?1e3*t.scene._physicsEngine.getTimeStep():1e3/60}}return e.prototype.register=function(){},e.prototype.rebuild=function(){},e.prototype.dispose=function(){this.scene.onBeforePhysicsObservable.clear(),this.scene.onAfterPhysicsObservable.clear(),this.scene._physicsEngine&&this.scene.disablePhysicsEngine()},e})();n.PhysicsEngineSceneComponent=r})($a||($a={})),(function(B){function e(e){return e.charCodeAt(0)+(e.charCodeAt(1)<<8)+(e.charCodeAt(2)<<16)+(e.charCodeAt(3)<<24)}var N=e("DXT1"),V=e("DXT3"),U=e("DXT5"),z=e("DX10"),t=(function(){function F(){}return F.GetDDSInfo=function(e){var t=new Int32Array(e,0,31),i=new Int32Array(e,0,35),r=1;131072&t[2]&&(r=Math.max(1,t[7]));var n=t[21],o=n===z?i[32]:0,s=B.Engine.TEXTURETYPE_UNSIGNED_INT;switch(n){case 113:s=B.Engine.TEXTURETYPE_HALF_FLOAT;break;case 116:s=B.Engine.TEXTURETYPE_FLOAT;break;case z:if(10===o){s=B.Engine.TEXTURETYPE_HALF_FLOAT;break}}return{width:t[4],height:t[3],mipmapCount:r,isFourCC:4==(4&t[20]),isRGB:64==(64&t[20]),isLuminance:131072==(131072&t[20]),isCube:512==(512&t[28]),isCompressed:n===N||n===V||n===U,dxgiFormat:o,textureType:s}},F._ToHalfFloat=function(e){F._FloatView||(F._FloatView=new Float32Array(1),F._Int32View=new Int32Array(F._FloatView.buffer)),F._FloatView[0]=e;var t=F._Int32View[0],i=t>>16&32768,r=t>>12&2047,n=t>>23&255;return n<103?i:142>114-n)+(r>>113-n&1):(i|=n-112<<10|r>>1,i+=1&r)},F._FromHalfFloat=function(e){var t=(32768&e)>>15,i=(31744&e)>>10,r=1023&e;return 0===i?(t?-1:1)*Math.pow(2,-14)*(r/Math.pow(2,10)):31==i?r?NaN:1/0*(t?-1:1):(t?-1:1)*Math.pow(2,i-15)*(1+r/Math.pow(2,10))},F._GetHalfFloatAsFloatRGBAArrayBuffer=function(e,t,i,r,n,o){for(var s=new Float32Array(r),a=new Uint16Array(n,i),l=0,c=0;c>8)},F._GetRGBArrayBuffer=function(e,t,i,r,n,o,s,a){for(var l=new Uint8Array(r),c=new Uint8Array(n,i),h=0,u=0;u>8&255,x>>16&255,x>>24&255)))}var P=F._ExtractLongWordOrder(g[23]),S=F._ExtractLongWordOrder(g[24]),R=F._ExtractLongWordOrder(g[25]),M=F._ExtractLongWordOrder(g[26]);E&&(y=e._getRGBABufferInternalSizedFormat(r.textureType)),p=1,131072&g[2]&&!1!==n&&(p=Math.max(1,g[7]));for(var C=0;C>r.mipmapCount-1==1;i(r.width,r.height,n,r.isFourCC,(function(){zo.DDSTools.UploadDDSLevels(t.getEngine(),t,e,r,n,1)}))},e})(),zo.Engine._TextureLoaders.push(new Go),ko=$a||($a={}),Wo=(function(){function E(){}return E.GetTGAHeader=function(e){var t=0;return{id_length:e[t++],colormap_type:e[t++],image_type:e[t++],colormap_index:e[t++]|e[t++]<<8,colormap_length:e[t++]|e[t++]<<8,colormap_size:e[t++],origin:[e[t++]|e[t++]<<8,e[t++]|e[t++]<<8],width:e[t++]|e[t++]<<8,height:e[t++]|e[t++]<<8,pixel_size:e[t++],flags:e[t++]}},E.UploadContent=function(e,t){if(t.length<19)ko.Tools.Error("Unable to load TGA file - Not enough data to contain header");else{var i=18,r=E.GetTGAHeader(t);if(r.id_length+i>t.length)ko.Tools.Error("Unable to load TGA file - Not enough data");else{i+=r.id_length;var n,o=!1,s=!1,a=!1;switch(r.image_type){case E._TYPE_RLE_INDEXED:o=!0;case E._TYPE_INDEXED:s=!0;break;case E._TYPE_RLE_RGB:o=!0;case E._TYPE_RGB:break;case E._TYPE_RLE_GREY:o=!0;case E._TYPE_GREY:a=!0}var l,c,h,u,d,f,p,m=r.pixel_size>>3,_=r.width*r.height*m;if(s&&(l=t.subarray(i,i+=r.colormap_length*(r.colormap_size>>3))),o){var g,v,y;n=new Uint8Array(_);for(var b=0,T=new Uint8Array(m);i<_&&b<_;)if(v=1+(127&(g=t[i++])),128&g){for(y=0;y>E._ORIGIN_SHIFT){default:case E._ORIGIN_UL:c=0,u=1,p=r.width,h=0,d=1,f=r.height;break;case E._ORIGIN_BL:c=0,u=1,p=r.width,h=r.height-1,f=d=-1;break;case E._ORIGIN_UR:c=r.width-1,p=u=-1,h=0,d=1,f=r.height;break;case E._ORIGIN_BR:c=r.width-1,p=u=-1,h=r.height-1,f=d=-1}var x=E["_getImageData"+(a?"Grey":"")+r.pixel_size+"bits"](r,l,n,h,d,f,c,u,p);e.getEngine()._uploadDataToTextureDirectly(e,x)}}},E._getImageData8bits=function(e,t,i,r,n,o,s,a,l){var c,h,u,d=i,f=t,p=e.width,m=e.height,_=0,g=new Uint8Array(p*m*4);for(u=r;u!==o;u+=n)for(h=s;h!==l;h+=a,_++)c=d[_],g[4*(h+p*u)+3]=255,g[4*(h+p*u)+2]=f[3*c+0],g[4*(h+p*u)+1]=f[3*c+1],g[4*(h+p*u)+0]=f[3*c+2];return g},E._getImageData16bits=function(e,t,i,r,n,o,s,a,l){var c,h,u,d=i,f=e.width,p=e.height,m=0,_=new Uint8Array(f*p*4);for(u=r;u!==o;u+=n)for(h=s;h!==l;h+=a,m+=2){var g=255*((31744&(c=d[m+0]+(d[m+1]<<8)))>>10)/31|0,v=255*((992&c)>>5)/31|0,y=255*(31&c)/31|0;_[4*(h+f*u)+0]=g,_[4*(h+f*u)+1]=v,_[4*(h+f*u)+2]=y,_[4*(h+f*u)+3]=32768&c?0:255}return _},E._getImageData24bits=function(e,t,i,r,n,o,s,a,l){var c,h,u=i,d=e.width,f=e.height,p=0,m=new Uint8Array(d*f*4);for(h=r;h!==o;h+=n)for(c=s;c!==l;c+=a,p+=3)m[4*(c+d*h)+3]=255,m[4*(c+d*h)+2]=u[p+0],m[4*(c+d*h)+1]=u[p+1],m[4*(c+d*h)+0]=u[p+2];return m},E._getImageData32bits=function(e,t,i,r,n,o,s,a,l){var c,h,u=i,d=e.width,f=e.height,p=0,m=new Uint8Array(d*f*4);for(h=r;h!==o;h+=n)for(c=s;c!==l;c+=a,p+=4)m[4*(c+d*h)+2]=u[p+0],m[4*(c+d*h)+1]=u[p+1],m[4*(c+d*h)+0]=u[p+2],m[4*(c+d*h)+3]=u[p+3];return m},E._getImageDataGrey8bits=function(e,t,i,r,n,o,s,a,l){var c,h,u,d=i,f=e.width,p=e.height,m=0,_=new Uint8Array(f*p*4);for(u=r;u!==o;u+=n)for(h=s;h!==l;h+=a,m++)c=d[m],_[4*(h+f*u)+0]=c,_[4*(h+f*u)+1]=c,_[4*(h+f*u)+2]=c,_[4*(h+f*u)+3]=255;return _},E._getImageDataGrey16bits=function(e,t,i,r,n,o,s,a,l){var c,h,u=i,d=e.width,f=e.height,p=0,m=new Uint8Array(d*f*4);for(h=r;h!==o;h+=n)for(c=s;c!==l;c+=a,p+=2)m[4*(c+d*h)+0]=u[p+0],m[4*(c+d*h)+1]=u[p+0],m[4*(c+d*h)+2]=u[p+0],m[4*(c+d*h)+3]=u[p+1];return m},E._TYPE_INDEXED=1,E._TYPE_RGB=2,E._TYPE_GREY=3,E._TYPE_RLE_INDEXED=9,E._TYPE_RLE_RGB=10,E._TYPE_RLE_GREY=11,E._ORIGIN_MASK=48,E._ORIGIN_SHIFT=4,E._ORIGIN_BL=0,E._ORIGIN_BR=1,E._ORIGIN_UL=2,E._ORIGIN_UR=3,E})(),ko.TGATools=Wo,Ho=$a||($a={}),Xo=(function(){function e(){this.supportCascades=!1}return e.prototype.canLoad=function(e,t,i,r,n){return 0===e.indexOf(".tga")},e.prototype.transformUrl=function(e,t){return e},e.prototype.getFallbackTextureUrl=function(e,t){return null},e.prototype.loadCubeData=function(e,t,i,r,n){throw".env not supported in Cube."},e.prototype.loadData=function(e,t,i){var r=new Uint8Array(e),n=Ho.TGATools.GetTGAHeader(r);i(n.width,n.height,t.generateMipMaps,!1,(function(){Ho.TGATools.UploadContent(t,r)}))},e})(),Ho.Engine._TextureLoaders.push(new Xo),jo=$a||($a={}),Yo=(function(){function h(e,t,i,r){this.arrayBuffer=e;var n=new Uint8Array(this.arrayBuffer,0,12);if(171===n[0]&&75===n[1]&&84===n[2]&&88===n[3]&&32===n[4]&&49===n[5]&&49===n[6]&&187===n[7]&&13===n[8]&&10===n[9]&&26===n[10]&&10===n[11]){var o=new Int32Array(this.arrayBuffer,12,13),s=16909060===o[0];this.glType=s?this.switchEndianness(o[1]):o[1],this.glTypeSize=s?this.switchEndianness(o[2]):o[2],this.glFormat=s?this.switchEndianness(o[3]):o[3],this.glInternalFormat=s?this.switchEndianness(o[4]):o[4],this.glBaseInternalFormat=s?this.switchEndianness(o[5]):o[5],this.pixelWidth=s?this.switchEndianness(o[6]):o[6],this.pixelHeight=s?this.switchEndianness(o[7]):o[7],this.pixelDepth=s?this.switchEndianness(o[8]):o[8],this.numberOfArrayElements=s?this.switchEndianness(o[9]):o[9],this.numberOfFaces=s?this.switchEndianness(o[10]):o[10],this.numberOfMipmapLevels=s?this.switchEndianness(o[11]):o[11],this.bytesOfKeyValueData=s?this.switchEndianness(o[12]):o[12],0===this.glType?(this.numberOfMipmapLevels=Math.max(1,this.numberOfMipmapLevels),0!==this.pixelHeight&&0===this.pixelDepth?0===this.numberOfArrayElements?this.numberOfFaces===t?this.loadType=h.COMPRESSED_2D:jo.Tools.Error("number of faces expected"+t+", but found "+this.numberOfFaces):jo.Tools.Error("texture arrays not currently supported"):jo.Tools.Error("only 2D textures currently supported")):jo.Tools.Error("only compressed formats currently supported")}else jo.Tools.Error("texture missing KTX identifier")}return h.prototype.switchEndianness=function(e){return(255&e)<<24|(65280&e)<<8|e>>8&65280|e>>24&255},h.prototype.uploadLevels=function(e,t){switch(this.loadType){case h.COMPRESSED_2D:this._upload2DCompressedLevels(e,t)}},h.prototype._upload2DCompressedLevels=function(e,t){for(var i=h.HEADER_LEN+this.bytesOfKeyValueData,r=this.pixelWidth,n=this.pixelHeight,o=t?this.numberOfMipmapLevels:1,s=0;sn.distance&&(a.mainSceneTrackerPredicate&&a.mainSceneTrackerPredicate(n.pickedMesh)?(a._notifyObservers(e,n,o),e.skipOnPointerObservable=!0):a._lastPointerEvents[o.pointerId]&&(a.onPointerOutObservable.notifyObservers(o.pointerId),delete a._lastPointerEvents[o.pointerId])),e.type===es.PointerEventTypes.POINTERUP&&a._pointerCaptures[o.pointerId]&&(a._pointerCaptures[o.pointerId]=!1))}}}})),this.utilityLayerScene.autoClear=!1,this._afterRenderObserver=this.originalScene.onAfterRenderObservable.add((function(){a.shouldRender&&a.render()})),this._sceneDisposeObserver=this.originalScene.onDisposeObservable.add((function(){a.dispose()})),this._updateCamera()}return Object.defineProperty(e,"DefaultUtilityLayer",{get:function(){return null==e._DefaultUtilityLayer&&(e._DefaultUtilityLayer=new e(es.Engine.LastCreatedScene)).originalScene.onDisposeObservable.addOnce((function(){e._DefaultUtilityLayer=null})),e._DefaultUtilityLayer},enumerable:!0,configurable:!0}),Object.defineProperty(e,"DefaultKeepDepthUtilityLayer",{get:function(){return null==e._DefaultKeepDepthUtilityLayer&&((e._DefaultKeepDepthUtilityLayer=new e(es.Engine.LastCreatedScene)).utilityLayerScene.autoClearDepthAndStencil=!1,e._DefaultKeepDepthUtilityLayer.originalScene.onDisposeObservable.addOnce((function(){e._DefaultKeepDepthUtilityLayer=null}))),e._DefaultKeepDepthUtilityLayer},enumerable:!0,configurable:!0}),e.prototype._notifyObservers=function(e,t,i){e.skipOnPointerObservable||(this.utilityLayerScene.onPointerObservable.notifyObservers(new es.PointerInfo(e.type,e.event,t)),this._lastPointerEvents[i.pointerId]=!0)},e.prototype.render=function(){if(this._updateCamera(),this.utilityLayerScene.activeCamera){var e=this.utilityLayerScene.activeCamera.getScene(),t=this.utilityLayerScene.activeCamera;t._scene=this.utilityLayerScene,t.leftCamera&&(t.leftCamera._scene=this.utilityLayerScene),t.rightCamera&&(t.rightCamera._scene=this.utilityLayerScene),this.utilityLayerScene.render(!1),t._scene=e,t.leftCamera&&(t.leftCamera._scene=e),t.rightCamera&&(t.rightCamera._scene=e)}},e.prototype.dispose=function(){this.onPointerOutObservable.clear(),this._afterRenderObserver&&this.originalScene.onAfterRenderObservable.remove(this._afterRenderObserver),this._sceneDisposeObserver&&this.originalScene.onDisposeObservable.remove(this._sceneDisposeObserver),this._originalPointerObserver&&this.originalScene.onPrePointerObservable.remove(this._originalPointerObserver),this.utilityLayerScene.dispose()},e.prototype._updateCamera=function(){this.utilityLayerScene.activeCamera=this.originalScene.activeCamera},e._DefaultUtilityLayer=null,e._DefaultKeepDepthUtilityLayer=null,e})(),es.UtilityLayerRenderer=ts,is=$a||($a={}),rs=(function(){function o(e){this.maxDragAngle=0,this._useAlternatePickedPointAboveMaxDragAngle=!1,this.currentDraggingPointerID=-1,this.dragging=!1,this.dragDeltaRatio=.2,this.updateDragPlane=!0,this._debugMode=!1,this._moving=!1,this.onDragObservable=new is.Observable,this.onDragStartObservable=new is.Observable,this.onDragEndObservable=new is.Observable,this.moveAttached=!0,this.enabled=!0,this.detachCameraControls=!0,this.useObjectOrienationForDragging=!0,this._tmpVector=new is.Vector3(0,0,0),this._alternatePickedPoint=new is.Vector3(0,0,0),this._worldDragAxis=new is.Vector3(0,0,0),this._targetPosition=new is.Vector3(0,0,0),this._attachedElement=null,this._startDragRay=new is.Ray(new is.Vector3,new is.Vector3),this._lastPointerRay={},this._dragDelta=new is.Vector3,this._pointA=new is.Vector3(0,0,0),this._pointB=new is.Vector3(0,0,0),this._pointC=new is.Vector3(0,0,0),this._lineA=new is.Vector3(0,0,0),this._lineB=new is.Vector3(0,0,0),this._localAxis=new is.Vector3(0,0,0),this._lookAt=new is.Vector3(0,0,0),this._options=e||{};var t=0;if(this._options.dragAxis&&t++,this._options.dragPlaneNormal&&t++,1Math.PI/2&&(i=Math.PI-i),0this.maxDragAngle){if(this._useAlternatePickedPointAboveMaxDragAngle){this._tmpVector.copyFrom(e.direction),this._attachedNode.absolutePosition.subtractToRef(e.origin,this._alternatePickedPoint),this._alternatePickedPoint.normalize(),this._alternatePickedPoint.scaleInPlace(-2*is.Vector3.Dot(this._alternatePickedPoint,this._tmpVector)),this._tmpVector.addInPlace(this._alternatePickedPoint);var r=is.Vector3.Dot(this._dragPlane.forward,this._tmpVector);return this._dragPlane.forward.scaleToRef(-r,this._alternatePickedPoint),this._alternatePickedPoint.addInPlace(this._tmpVector),this._alternatePickedPoint.addInPlace(this._attachedNode.absolutePosition),this._alternatePickedPoint}return null}var n=o._planeScene.pickWithRay(e,(function(e){return e==t._dragPlane}));return n&&n.hit&&n.pickedMesh&&n.pickedPoint?n.pickedPoint:null},o.prototype._updateDragPlanePosition=function(e,t){this._pointA.copyFrom(t),this._options.dragAxis?(this.useObjectOrienationForDragging?is.Vector3.TransformCoordinatesToRef(this._options.dragAxis,this._attachedNode.getWorldMatrix().getRotationMatrix(),this._localAxis):this._localAxis.copyFrom(this._options.dragAxis),this._pointA.addToRef(this._localAxis,this._pointB),e.origin.subtractToRef(this._pointA,this._pointC),this._pointA.addToRef(this._pointC.normalize(),this._pointC),this._pointB.subtractToRef(this._pointA,this._lineA),this._pointC.subtractToRef(this._pointA,this._lineB),is.Vector3.CrossToRef(this._lineA,this._lineB,this._lookAt),is.Vector3.CrossToRef(this._lineA,this._lookAt,this._lookAt),this._lookAt.normalize(),this._dragPlane.position.copyFrom(this._pointA),this._pointA.subtractToRef(this._lookAt,this._lookAt),this._dragPlane.lookAt(this._lookAt)):this._options.dragPlaneNormal?(this.useObjectOrienationForDragging?is.Vector3.TransformCoordinatesToRef(this._options.dragPlaneNormal,this._attachedNode.getWorldMatrix().getRotationMatrix(),this._localAxis):this._localAxis.copyFrom(this._options.dragPlaneNormal),this._dragPlane.position.copyFrom(this._pointA),this._pointA.subtractToRef(this._localAxis,this._lookAt),this._dragPlane.lookAt(this._lookAt)):(this._dragPlane.position.copyFrom(this._pointA),this._dragPlane.lookAt(e.origin)),this._dragPlane.computeWorldMatrix(!0)},o.prototype.detach=function(){this._pointerObserver&&this._scene.onPointerObservable.remove(this._pointerObserver),this._beforeRenderObserver&&this._scene.onBeforeRenderObservable.remove(this._beforeRenderObserver)},o._AnyMouseID=-2,o})(),is.PointerDragBehavior=rs,ns=$a||($a={}),os=(function(){function e(){this._startDistance=0,this._initialScale=new ns.Vector3(0,0,0),this._targetScale=new ns.Vector3(0,0,0),this._sceneRenderObserver=null,this._dragBehaviorA=new ns.PointerDragBehavior({}),this._dragBehaviorA.moveAttached=!1,this._dragBehaviorB=new ns.PointerDragBehavior({}),this._dragBehaviorB.moveAttached=!1}return Object.defineProperty(e.prototype,"name",{get:function(){return"MultiPointerScale"},enumerable:!0,configurable:!0}),e.prototype.init=function(){},e.prototype._getCurrentDistance=function(){return this._dragBehaviorA.lastDragPosition.subtract(this._dragBehaviorB.lastDragPosition).length()},e.prototype.attach=function(t){var i=this;this._ownerNode=t,this._dragBehaviorA.onDragStartObservable.add((function(e){i._dragBehaviorA.dragging&&i._dragBehaviorB.dragging&&(i._dragBehaviorA.currentDraggingPointerID==i._dragBehaviorB.currentDraggingPointerID?i._dragBehaviorA.releaseDrag():(i._initialScale.copyFrom(t.scaling),i._startDistance=i._getCurrentDistance()))})),this._dragBehaviorB.onDragStartObservable.add((function(e){i._dragBehaviorA.dragging&&i._dragBehaviorB.dragging&&(i._dragBehaviorA.currentDraggingPointerID==i._dragBehaviorB.currentDraggingPointerID?i._dragBehaviorB.releaseDrag():(i._initialScale.copyFrom(t.scaling),i._startDistance=i._getCurrentDistance()))})),[this._dragBehaviorA,this._dragBehaviorB].forEach((function(e){e.onDragObservable.add((function(){if(i._dragBehaviorA.dragging&&i._dragBehaviorB.dragging){var e=i._getCurrentDistance()/i._startDistance;i._initialScale.scaleToRef(e,i._targetScale)}}))})),t.addBehavior(this._dragBehaviorA),t.addBehavior(this._dragBehaviorB),this._sceneRenderObserver=t.getScene().onBeforeRenderObservable.add((function(){if(i._dragBehaviorA.dragging&&i._dragBehaviorB.dragging){var e=i._targetScale.subtract(t.scaling).scaleInPlace(.1);.01r.snapDistance){var t=Math.floor(Math.abs(c)/r.snapDistance);c%=r.snapDistance,d.normalizeToRef(h),h.scaleInPlace(r.snapDistance*t),r.attachedMesh.position.addInPlace(h),u.snapDistance=r.snapDistance*t,r.onSnapObservable.notifyObservers(u)}})),r._pointerObserver=i.utilityLayerScene.onPointerObservable.add((function(e,t){if(!r._customMeshSet){var i=e.pickInfo&&-1!=r._rootMesh.getChildMeshes().indexOf(e.pickInfo.pickedMesh)?o:n;r._rootMesh.getChildMeshes().forEach((function(e){e.material=i,e.color&&(e.color=i.emissiveColor)}))}})),r}return T(e,p),e.prototype._attachedMeshChanged=function(e){this.dragBehavior&&(this.dragBehavior.enabled=!!e)},e.prototype.dispose=function(){this.onSnapObservable.clear(),this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver),this.dragBehavior.detach(),p.prototype.dispose.call(this)},e})(ms.Gizmo),ms.AxisDragGizmo=_s,gs=$a||($a={}),vs=(function(u){function e(r,e,t){void 0===e&&(e=gs.Color3.Gray()),void 0===t&&(t=gs.UtilityLayerRenderer.DefaultUtilityLayer);var n=u.call(this,t)||this;n._pointerObserver=null,n.snapDistance=0,n.onSnapObservable=new gs.Observable,n.uniformScaling=!1,n._coloredMaterial=new gs.StandardMaterial("",t.utilityLayerScene),n._coloredMaterial.disableLighting=!0,n._coloredMaterial.emissiveColor=e;var o=new gs.StandardMaterial("",t.utilityLayerScene);o.disableLighting=!0,o.emissiveColor=e.add(new gs.Color3(.3,.3,.3));var i=new gs.AbstractMesh("",t.utilityLayerScene),s=gs.MeshBuilder.CreateBox("yPosMesh",{size:.4},t.utilityLayerScene),a=gs.MeshBuilder.CreateLines("yPosMesh",{points:[new gs.Vector3(0,0,0),new gs.Vector3(0,1.1,0)]},t.utilityLayerScene);a.color=n._coloredMaterial.emissiveColor,i.addChild(s),i.addChild(a),s.scaling.scaleInPlace(.1),s.material=n._coloredMaterial,s.rotation.x=Math.PI/2,s.position.z+=.3,a.scaling.scaleInPlace(.26),a.rotation.x=Math.PI/2,a.material=n._coloredMaterial,i.lookAt(n._rootMesh.position.subtract(r)),n._rootMesh.addChild(i),i.scaling.scaleInPlace(1/3),n.dragBehavior=new gs.PointerDragBehavior({dragAxis:r}),n.dragBehavior.moveAttached=!1,n._rootMesh.addBehavior(n.dragBehavior);var l=0,c=new gs.Vector3,h={snapDistance:0};return n.dragBehavior.onDragObservable.add((function(e){if(n.attachedMesh){var t=!1,i=0;n.uniformScaling?(n.attachedMesh.scaling.normalizeToRef(c),c.y<0&&c.scaleInPlace(-1)):c.copyFrom(r),0==n.snapDistance?c.scaleToRef(e.dragDistance,c):(l+=e.dragDistance,Math.abs(l)>n.snapDistance?(i=Math.floor(l/n.snapDistance),l%=n.snapDistance,c.scaleToRef(n.snapDistance*i,c),t=!0):c.scaleInPlace(0)),n.attachedMesh.scaling.addInPlace(c),t&&(h.snapDistance=n.snapDistance*i,n.onSnapObservable.notifyObservers(h))}})),n._pointerObserver=t.utilityLayerScene.onPointerObservable.add((function(e,t){if(!n._customMeshSet){var i=e.pickInfo&&-1!=n._rootMesh.getChildMeshes().indexOf(e.pickInfo.pickedMesh)?o:n._coloredMaterial;n._rootMesh.getChildMeshes().forEach((function(e){e.material=i,e.color&&(e.color=i.emissiveColor)}))}})),n}return T(e,u),e.prototype._attachedMeshChanged=function(e){this.dragBehavior&&(this.dragBehavior.enabled=!!e)},e.prototype.dispose=function(){this.onSnapObservable.clear(),this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver),this.dragBehavior.detach(),u.prototype.dispose.call(this)},e.prototype.setCustomMesh=function(e,t){var i=this;void 0===t&&(t=!1),u.prototype.setCustomMesh.call(this,e),t&&(this._rootMesh.getChildMeshes().forEach((function(e){e.material=i._coloredMaterial,e.color&&(e.color=i._coloredMaterial.emissiveColor)})),this._customMeshSet=!1)},e})(gs.Gizmo),gs.AxisScaleGizmo=vs,ys=$a||($a={}),bs=(function(c){function e(h,e,u,t){void 0===e&&(e=ys.Color3.Gray()),void 0===u&&(u=ys.UtilityLayerRenderer.DefaultUtilityLayer),void 0===t&&(t=32);var d=c.call(this,u)||this;d._pointerObserver=null,d.snapDistance=0,d.onSnapObservable=new ys.Observable;var r=new ys.StandardMaterial("",u.utilityLayerScene);r.disableLighting=!0,r.emissiveColor=e;var n=new ys.StandardMaterial("",u.utilityLayerScene);n.disableLighting=!0,n.emissiveColor=e.add(new ys.Color3(.3,.3,.3));for(var i=new ys.AbstractMesh("",u.utilityLayerScene),o=new Array,s=0;sd.snapDistance){var l=Math.floor(v/d.snapDistance);v%=d.snapDistance,o=d.snapDistance*l,a=!0}else o=0;y.reset(),d.attachedMesh.parent&&(d.attachedMesh.parent.computeWorldMatrix().invertToRef(y),y.getRotationMatrixToRef(y),ys.Vector3.TransformCoordinatesToRef(m,y,m));var c=Math.sin(o/2);T.set(m.x*c,m.y*c,m.z*c,Math.cos(o/2)),0this.capacity&&this._depthr._padSensibilityUp&&t._selectionPointerDown()})))},e.prototype._checkTeleportWithRay=function(e,t){this._teleportationRequestInitiated&&!t._teleportationRequestInitiated||(t._teleportationRequestInitiated?Math.sqrt(e.y*e.y+e.x*e.x)-this._padSensibilityDown&&(t._rotationLeftAsked=!1):e.x<-this._padSensibilityUp&&t._dpadPressed&&(t._rotationLeftAsked=!0,this._rotationAllowed&&this._rotateCamera(!1)),t._rotationRightAsked?e.xthis._padSensibilityUp&&t._dpadPressed&&(t._rotationRightAsked=!0,this._rotationAllowed&&this._rotateCamera(!0)))},e.prototype._checkTeleportBackwards=function(e,t){if(!t._teleportationRequestInitiated)if(e.y>this._padSensibilityUp&&t._dpadPressed){if(!t._teleportationBackRequestInitiated){if(!this.currentVRCamera)return;var i=qs.Quaternion.FromRotationMatrix(this.currentVRCamera.getWorldMatrix().getRotationMatrix()),r=this.currentVRCamera.position;this.currentVRCamera.devicePosition&&this.currentVRCamera.deviceRotationQuaternion&&(i=this.currentVRCamera.deviceRotationQuaternion,r=this.currentVRCamera.devicePosition),i.toEulerAnglesToRef(this._workingVector),this._workingVector.z=0,this._workingVector.x=0,qs.Quaternion.RotationYawPitchRollToRef(this._workingVector.y,this._workingVector.x,this._workingVector.z,this._workingQuaternion),this._workingQuaternion.toRotationMatrix(this._workingMatrix),qs.Vector3.TransformCoordinatesToRef(this._teleportBackwardsVector,this._workingMatrix,this._workingVector);var n=new qs.Ray(r,this._workingVector),o=this._scene.pickWithRay(n,this._raySelectionPredicate);o&&o.pickedPoint&&o.pickedMesh&&this._isTeleportationFloor(o.pickedMesh)&&o.distance<5&&this.teleportCamera(o.pickedPoint),t._teleportationBackRequestInitiated=!0}}else t._teleportationBackRequestInitiated=!1},e.prototype._enableTeleportationOnController=function(t){var i=this;t.webVRController.mesh&&(t._interactionsEnabled||this._enableInteractionOnController(t),t._interactionsEnabled=!0,t._teleportationEnabled=!0,t.webVRController.controllerType===qs.PoseEnabledControllerType.VIVE&&(t._dpadPressed=!1,t.webVRController.onPadStateChangedObservable.add((function(e){t._dpadPressed=e.pressed,t._dpadPressed||(t._rotationLeftAsked=!1,t._rotationRightAsked=!1,t._teleportationBackRequestInitiated=!1)}))),t.webVRController.onPadValuesChangedObservable.add((function(e){i.teleportationEnabled&&(i._checkTeleportBackwards(e,t),i._checkTeleportWithRay(e,t)),i._checkRotate(e,t)})))},e.prototype._createTeleportationCircles=function(){this._teleportationTarget=qs.Mesh.CreateGround("teleportationTarget",2,2,2,this._scene),this._teleportationTarget.isPickable=!1;var e=new qs.DynamicTexture("DynamicTexture",512,this._scene,!0);e.hasAlpha=!0;var t=e.getContext();t.beginPath(),t.arc(256,256,200,0,2*Math.PI,!1),t.fillStyle=this._teleportationFillColor,t.fill(),t.lineWidth=10,t.strokeStyle=this._teleportationBorderColor,t.stroke(),t.closePath(),e.update();var i=new qs.StandardMaterial("TextPlaneMaterial",this._scene);i.diffuseTexture=e,this._teleportationTarget.material=i;var r=qs.Mesh.CreateTorus("torusTeleportation",.75,.1,25,this._scene,!1);r.isPickable=!1,r.parent=this._teleportationTarget;var n=new qs.Animation("animationInnerCircle","position.y",30,qs.Animation.ANIMATIONTYPE_FLOAT,qs.Animation.ANIMATIONLOOPMODE_CYCLE),o=[];o.push({frame:0,value:0}),o.push({frame:30,value:.4}),o.push({frame:60,value:0}),n.setKeys(o);var s=new qs.SineEase;s.setEasingMode(qs.EasingFunction.EASINGMODE_EASEINOUT),n.setEasingFunction(s),r.animations=[],r.animations.push(n),this._scene.beginAnimation(r,0,60,!0),this._hideTeleportationTarget()},e.prototype._displayTeleportationTarget=function(){this._teleportActive=!0,this._teleportationInitialized&&(this._teleportationTarget.isVisible=!0,this._isDefaultTeleportationTarget&&(this._teleportationTarget.getChildren()[0].isVisible=!0))},e.prototype._hideTeleportationTarget=function(){this._teleportActive=!1,this._teleportationInitialized&&(this._teleportationTarget.isVisible=!1,this._isDefaultTeleportationTarget&&(this._teleportationTarget.getChildren()[0].isVisible=!1))},e.prototype._rotateCamera=function(e){var t=this;if(this.currentVRCamera instanceof qs.FreeCamera){e?this._rotationAngle++:this._rotationAngle--,this.currentVRCamera.animations=[];var i=qs.Quaternion.FromRotationMatrix(qs.Matrix.RotationY(Math.PI/4*this._rotationAngle)),r=new qs.Animation("animationRotation","rotationQuaternion",90,qs.Animation.ANIMATIONTYPE_QUATERNION,qs.Animation.ANIMATIONLOOPMODE_CONSTANT),n=[];n.push({frame:0,value:this.currentVRCamera.rotationQuaternion}),n.push({frame:6,value:i}),r.setKeys(n),r.setEasingFunction(this._circleEase),this.currentVRCamera.animations.push(r),this._postProcessMove.animations=[];var o=new qs.Animation("animationPP","vignetteWeight",90,qs.Animation.ANIMATIONTYPE_FLOAT,qs.Animation.ANIMATIONLOOPMODE_CONSTANT),s=[];s.push({frame:0,value:0}),s.push({frame:3,value:4}),s.push({frame:6,value:0}),o.setKeys(s),o.setEasingFunction(this._circleEase),this._postProcessMove.animations.push(o);var a=new qs.Animation("animationPP2","vignetteStretch",90,qs.Animation.ANIMATIONTYPE_FLOAT,qs.Animation.ANIMATIONLOOPMODE_CONSTANT),l=[];l.push({frame:0,value:0}),l.push({frame:3,value:10}),l.push({frame:6,value:0}),a.setKeys(l),a.setEasingFunction(this._circleEase),this._postProcessMove.animations.push(a),this._postProcessMove.imageProcessingConfiguration.vignetteWeight=0,this._postProcessMove.imageProcessingConfiguration.vignetteStretch=0,this._postProcessMove.samples=4,this._webVRCamera.attachPostProcess(this._postProcessMove),this._scene.beginAnimation(this._postProcessMove,0,6,!1,1,(function(){t._webVRCamera.detachPostProcess(t._postProcessMove)})),this._scene.beginAnimation(this.currentVRCamera,0,6,!1,1)}},e.prototype._moveTeleportationSelectorTo=function(e,t,i){if(e.pickedPoint){t._teleportationRequestInitiated&&(this._displayTeleportationTarget(),this._haloCenter.copyFrom(e.pickedPoint),this._teleportationTarget.position.copyFrom(e.pickedPoint));var r=this._convertNormalToDirectionOfRay(e.getNormal(!0,!1),i);if(r){var n=qs.Vector3.Cross(qs.Axis.Y,r),o=qs.Vector3.Cross(r,n);qs.Vector3.RotationFromAxisToRef(o,r,n,this._teleportationTarget.rotation)}this._teleportationTarget.position.y+=.1}},e.prototype.teleportCamera=function(e){var t=this;if(this.currentVRCamera instanceof qs.FreeCamera){this.webVRCamera.leftCamera?(this._workingVector.copyFrom(this.webVRCamera.leftCamera.globalPosition),this._workingVector.subtractInPlace(this.webVRCamera.position),e.subtractToRef(this._workingVector,this._workingVector)):this._workingVector.copyFrom(e),this.isInVRMode?this._workingVector.y+=this.webVRCamera.deviceDistanceToRoomGround()*this._webVRCamera.deviceScaleFactor:this._workingVector.y+=this._defaultHeight,this.onBeforeCameraTeleport.notifyObservers(this._workingVector),this.currentVRCamera.animations=[];var i=new qs.Animation("animationCameraTeleportation","position",90,qs.Animation.ANIMATIONTYPE_VECTOR3,qs.Animation.ANIMATIONLOOPMODE_CONSTANT),r=[{frame:0,value:this.currentVRCamera.position},{frame:11,value:this._workingVector}];i.setKeys(r),i.setEasingFunction(this._circleEase),this.currentVRCamera.animations.push(i),this._postProcessMove.animations=[];var n=new qs.Animation("animationPP","vignetteWeight",90,qs.Animation.ANIMATIONTYPE_FLOAT,qs.Animation.ANIMATIONLOOPMODE_CONSTANT),o=[];o.push({frame:0,value:0}),o.push({frame:5,value:8}),o.push({frame:11,value:0}),n.setKeys(o),this._postProcessMove.animations.push(n);var s=new qs.Animation("animationPP2","vignetteStretch",90,qs.Animation.ANIMATIONTYPE_FLOAT,qs.Animation.ANIMATIONLOOPMODE_CONSTANT),a=[];a.push({frame:0,value:0}),a.push({frame:5,value:10}),a.push({frame:11,value:0}),s.setKeys(a),this._postProcessMove.animations.push(s),this._postProcessMove.imageProcessingConfiguration.vignetteWeight=0,this._postProcessMove.imageProcessingConfiguration.vignetteStretch=0,this._webVRCamera.attachPostProcess(this._postProcessMove),this._scene.beginAnimation(this._postProcessMove,0,11,!1,1,(function(){t._webVRCamera.detachPostProcess(t._postProcessMove)})),this._scene.beginAnimation(this.currentVRCamera,0,11,!1,1,(function(){t.onAfterCameraTeleport.notifyObservers(t._workingVector)})),this._hideTeleportationTarget()}},e.prototype._convertNormalToDirectionOfRay=function(e,t){e&&(Math.acos(qs.Vector3.Dot(e,t.direction))r.halfWidth)&&this._joystickPointerID<0?(this._joystickPointerID=e.pointerId,this._joystickPointerStartPos.x=e.clientX,this._joystickPointerStartPos.y=e.clientY,this._joystickPointerPos=this._joystickPointerStartPos.clone(),this._joystickPreviousPointerPos=this._joystickPointerStartPos.clone(),this._deltaJoystickVector.x=0,this._deltaJoystickVector.y=0,this.pressed=!0,this._touches.add(e.pointerId.toString(),e)):r._globalJoystickIndex<2&&this._action&&(this._action(),this._touches.add(e.pointerId.toString(),{x:e.clientX,y:e.clientY,prevX:e.clientX,prevY:e.clientY}))},r.prototype._onPointerMove=function(e){if(this._joystickPointerID==e.pointerId){this._joystickPointerPos.x=e.clientX,this._joystickPointerPos.y=e.clientY,this._deltaJoystickVector=this._joystickPointerPos.clone(),this._deltaJoystickVector=this._deltaJoystickVector.subtract(this._joystickPointerStartPos);var t=(this.reverseLeftRight?-1:1)*this._deltaJoystickVector.x/this._inversedSensibility;switch(this._axisTargetedByLeftAndRight){case o.X:this.deltaPosition.x=Math.min(1,Math.max(-1,t));break;case o.Y:this.deltaPosition.y=Math.min(1,Math.max(-1,t));break;case o.Z:this.deltaPosition.z=Math.min(1,Math.max(-1,t))}var i=(this.reverseUpDown?1:-1)*this._deltaJoystickVector.y/this._inversedSensibility;switch(this._axisTargetedByUpAndDown){case o.X:this.deltaPosition.x=Math.min(1,Math.max(-1,i));break;case o.Y:this.deltaPosition.y=Math.min(1,Math.max(-1,i));break;case o.Z:this.deltaPosition.z=Math.min(1,Math.max(-1,i))}}else{var r=this._touches.get(e.pointerId.toString());r&&(r.x=e.clientX,r.y=e.clientY)}},r.prototype._onPointerUp=function(e){if(this._joystickPointerID==e.pointerId)r.vjCanvasContext.clearRect(this._joystickPointerStartPos.x-64,this._joystickPointerStartPos.y-64,128,128),r.vjCanvasContext.clearRect(this._joystickPreviousPointerPos.x-42,this._joystickPreviousPointerPos.y-42,84,84),this._joystickPointerID=-1,this.pressed=!1;else{var t=this._touches.get(e.pointerId.toString());t&&r.vjCanvasContext.clearRect(t.prevX-44,t.prevY-44,88,88)}this._deltaJoystickVector.x=0,this._deltaJoystickVector.y=0,this._touches.remove(e.pointerId.toString())},r.prototype.setJoystickColor=function(e){this._joystickColor=e},r.prototype.setActionOnTouch=function(e){this._action=e},r.prototype.setAxisForLeftRight=function(e){switch(e){case o.X:case o.Y:case o.Z:this._axisTargetedByLeftAndRight=e;break;default:this._axisTargetedByLeftAndRight=o.X}},r.prototype.setAxisForUpDown=function(e){switch(e){case o.X:case o.Y:case o.Z:this._axisTargetedByUpAndDown=e;break;default:this._axisTargetedByUpAndDown=o.Y}},r.prototype._drawVirtualJoystick=function(){var i=this;this.pressed&&this._touches.forEach((function(e,t){t.pointerId===i._joystickPointerID?(r.vjCanvasContext.clearRect(i._joystickPointerStartPos.x-64,i._joystickPointerStartPos.y-64,128,128),r.vjCanvasContext.clearRect(i._joystickPreviousPointerPos.x-42,i._joystickPreviousPointerPos.y-42,84,84),r.vjCanvasContext.beginPath(),r.vjCanvasContext.lineWidth=6,r.vjCanvasContext.strokeStyle=i._joystickColor,r.vjCanvasContext.arc(i._joystickPointerStartPos.x,i._joystickPointerStartPos.y,40,0,2*Math.PI,!0),r.vjCanvasContext.stroke(),r.vjCanvasContext.closePath(),r.vjCanvasContext.beginPath(),r.vjCanvasContext.strokeStyle=i._joystickColor,r.vjCanvasContext.lineWidth=2,r.vjCanvasContext.arc(i._joystickPointerStartPos.x,i._joystickPointerStartPos.y,60,0,2*Math.PI,!0),r.vjCanvasContext.stroke(),r.vjCanvasContext.closePath(),r.vjCanvasContext.beginPath(),r.vjCanvasContext.strokeStyle=i._joystickColor,r.vjCanvasContext.arc(i._joystickPointerPos.x,i._joystickPointerPos.y,40,0,2*Math.PI,!0),r.vjCanvasContext.stroke(),r.vjCanvasContext.closePath(),i._joystickPreviousPointerPos=i._joystickPointerPos.clone()):(r.vjCanvasContext.clearRect(t.prevX-44,t.prevY-44,88,88),r.vjCanvasContext.beginPath(),r.vjCanvasContext.fillStyle="white",r.vjCanvasContext.beginPath(),r.vjCanvasContext.strokeStyle="red",r.vjCanvasContext.lineWidth=6,r.vjCanvasContext.arc(t.x,t.y,40,0,2*Math.PI,!0),r.vjCanvasContext.stroke(),r.vjCanvasContext.closePath(),t.prevX=t.x,t.prevY=t.y)})),requestAnimationFrame((function(){i._drawVirtualJoystick()}))},r.prototype.releaseCanvas=function(){r.vjCanvas&&(r.vjCanvas.removeEventListener("pointerdown",this._onPointerDownHandlerRef),r.vjCanvas.removeEventListener("pointermove",this._onPointerMoveHandlerRef),r.vjCanvas.removeEventListener("pointerup",this._onPointerUpHandlerRef),r.vjCanvas.removeEventListener("pointerout",this._onPointerUpHandlerRef),window.removeEventListener("resize",this._onResize),document.body.removeChild(r.vjCanvas),r.vjCanvas=null)},r._globalJoystickIndex=0,r})();n.VirtualJoystick=t})($a||($a={})),(function(i){i.Node.AddNodeConstructor("VirtualJoysticksCamera",(function(e,t){return function(){return new r(e,i.Vector3.Zero(),t)}}));var r=(function(n){function e(e,t,i){var r=n.call(this,e,t,i)||this;return r.inputs.addVirtualJoystick(),r}return T(e,n),e.prototype.getClassName=function(){return"VirtualJoysticksCamera"},e})(i.FreeCamera);i.VirtualJoysticksCamera=r})($a||($a={})),ia=$a||($a={}),ra=(function(){function e(){}return e.prototype.getLeftJoystick=function(){return this._leftjoystick},e.prototype.getRightJoystick=function(){return this._rightjoystick},e.prototype.checkInputs=function(){if(this._leftjoystick){var e=this.camera,t=50*e._computeLocalCameraSpeed(),i=ia.Matrix.RotationYawPitchRoll(e.rotation.y,e.rotation.x,0),r=ia.Vector3.TransformCoordinates(new ia.Vector3(this._leftjoystick.deltaPosition.x*t,this._leftjoystick.deltaPosition.y*t,this._leftjoystick.deltaPosition.z*t),i);e.cameraDirection=e.cameraDirection.add(r),e.cameraRotation=e.cameraRotation.addVector3(this._rightjoystick.deltaPosition),this._leftjoystick.pressed||(this._leftjoystick.deltaPosition=this._leftjoystick.deltaPosition.scale(.9)),this._rightjoystick.pressed||(this._rightjoystick.deltaPosition=this._rightjoystick.deltaPosition.scale(.9))}},e.prototype.attachControl=function(e,t){this._leftjoystick=new ia.VirtualJoystick(!0),this._leftjoystick.setAxisForUpDown(ia.JoystickAxis.Z),this._leftjoystick.setAxisForLeftRight(ia.JoystickAxis.X),this._leftjoystick.setJoystickSensibility(.15),this._rightjoystick=new ia.VirtualJoystick(!1),this._rightjoystick.setAxisForUpDown(ia.JoystickAxis.X),this._rightjoystick.setAxisForLeftRight(ia.JoystickAxis.Y),this._rightjoystick.reverseUpDown=!0,this._rightjoystick.setJoystickSensibility(.05),this._rightjoystick.setJoystickColor("yellow")},e.prototype.detachControl=function(e){this._leftjoystick.releaseCanvas(),this._rightjoystick.releaseCanvas()},e.prototype.getClassName=function(){return"FreeCameraVirtualJoystickInput"},e.prototype.getSimpleName=function(){return"virtualJoystick"},e})(),ia.FreeCameraVirtualJoystickInput=ra,ia.CameraInputTypes.FreeCameraVirtualJoystickInput=ra,(function(b){var e=function(e,t,i){this.quality=e,this.distance=t,this.optimizeMesh=i};b.SimplificationSettings=e;var t,i,r=(function(){function e(){this.running=!1,this._simplificationArray=[]}return e.prototype.addTask=function(e){this._simplificationArray.push(e)},e.prototype.executeNext=function(){var e=this._simplificationArray.pop();e?(this.running=!0,this.runSimplification(e)):this.running=!1},e.prototype.runSimplification=function(r){var i=this;if(r.parallelProcessing)r.settings.forEach((function(t){i.getSimplifier(r).simplify(t,(function(e){r.mesh.addLODLevel(t.distance,e),e.isVisible=!0,t.quality===r.settings[r.settings.length-1].quality&&r.successCallback&&r.successCallback(),i.executeNext()}))}));else{var n=this.getSimplifier(r);b.AsyncLoop.Run(r.settings.length,(function(e){var t,i;t=r.settings[e.index],i=function(){e.executeNext()},n.simplify(t,(function(e){r.mesh.addLODLevel(t.distance,e),e.isVisible=!0,i()}))}),(function(){r.successCallback&&r.successCallback(),i.executeNext()}))}},e.prototype.getSimplifier=function(e){switch(e.simplificationType){case t.QUADRATIC:default:return new o(e.mesh)}},e})();b.SimplificationQueue=r,(i=t=b.SimplificationType||(b.SimplificationType={}))[i.QUADRATIC=0]="QUADRATIC";var f=function(e){this.vertices=e,this.error=new Array(4),this.deleted=!1,this.isDirty=!1,this.deletePending=!1,this.borderFactor=0},s=(function(){function e(e,t){this.position=e,this.id=t,this.isBorder=!0,this.q=new n,this.triangleCount=0,this.triangleStart=0,this.originalOffsets=[]}return e.prototype.updatePosition=function(e){this.position.copyFrom(e)},e})(),n=(function(){function n(e){this.data=new Array(10);for(var t=0;t<10;++t)e&&e[t]?this.data[t]=e[t]:this.data[t]=0}return n.prototype.det=function(e,t,i,r,n,o,s,a,l){return this.data[e]*this.data[n]*this.data[l]+this.data[i]*this.data[r]*this.data[a]+this.data[t]*this.data[o]*this.data[s]-this.data[i]*this.data[n]*this.data[s]-this.data[e]*this.data[o]*this.data[a]-this.data[t]*this.data[r]*this.data[l]},n.prototype.addInPlace=function(e){for(var t=0;t<10;++t)this.data[t]+=e.data[t]},n.prototype.addArrayInPlace=function(e){for(var t=0;t<10;++t)this.data[t]+=e[t]},n.prototype.add=function(e){for(var t=new n,i=0;i<10;++i)t.data[i]=this.data[i]+e.data[i];return t},n.FromData=function(e,t,i,r){return new n(n.DataFromNumbers(e,t,i,r))},n.DataFromNumbers=function(e,t,i,r){return[e*e,e*t,e*i,e*r,t*t,t*i,t*r,i*i,i*r,r*r]},n})(),l=function(e,t){this.vertexId=e,this.triangleId=t},o=(function(){function e(e){this._mesh=e,this.syncIterations=5e3,this.aggressiveness=7,this.decimationIterations=100,this.boundingBoxEpsilon=b.Epsilon}return e.prototype.simplify=function(t,e){var i=this;this.initDecimatedMesh(),b.AsyncLoop.Run(this._mesh.subMeshes.length,(function(e){i.initWithMesh(e.index,(function(){i.runDecimation(t,e.index,(function(){e.executeNext()}))}),t.optimizeMesh)}),(function(){setTimeout((function(){e(i._reconstructedMesh)}),0)}))},e.prototype.runDecimation=function(e,t,i){var v=this,r=~~(this.triangles.length*e.quality),y=0,n=this.triangles.length;b.AsyncLoop.Run(this.decimationIterations,(function(e){var t,i;n-y<=r?e.breakLoop():(t=e.index,i=function(){e.executeNext()},setTimeout((function(){t%5==0&&v.updateMesh(0===t);for(var e=0;eg||i.deleted||i.isDirty))for(var r=0;r<3;++r)if(i.error[r]>0,(function(e){if(o){var t=e+u.verticesStart,i=b.Vector3.FromArray(o,3*t),r=(function(e){if(n)for(var t=0;tthis.maximumSize&&(n.scale(this.step),i=!1)}}return i},e})(d.SceneOptimization=e);d.TextureOptimization=n;var o=(function(n){function e(e,t,i){void 0===e&&(e=0),void 0===t&&(t=2),void 0===i&&(i=.25);var r=n.call(this,e)||this;return r.priority=e,r.maximumScale=t,r.step=i,r._currentScale=-1,r._directionOffset=1,r}return T(e,n),e.prototype.getDescription=function(){return"Setting hardware scaling level to "+this._currentScale},e.prototype.apply=function(e,t){return-1===this._currentScale&&(this._currentScale=e.getEngine().getHardwareScalingLevel(),this._currentScale>this.maximumScale&&(this._directionOffset=-1)),this._currentScale+=this._directionOffset*this.step,e.getEngine().setHardwareScalingLevel(this._currentScale),1===this._directionOffset?this._currentScale>=this.maximumScale:this._currentScale<=this.maximumScale},e})(e);d.HardwareScalingOptimization=o;var s=(function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return T(t,e),t.prototype.getDescription=function(){return"Turning shadows on/off"},t.prototype.apply=function(e,t){return e.shadowsEnabled=t.isInImprovementMode,!0},t})(e);d.ShadowsOptimization=s;var a=(function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return T(t,e),t.prototype.getDescription=function(){return"Turning post-processes on/off"},t.prototype.apply=function(e,t){return e.postProcessesEnabled=t.isInImprovementMode,!0},t})(e);d.PostProcessesOptimization=a;var l=(function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return T(t,e),t.prototype.getDescription=function(){return"Turning lens flares on/off"},t.prototype.apply=function(e,t){return e.lensFlaresEnabled=t.isInImprovementMode,!0},t})(e);d.LensFlaresOptimization=l;var c=(function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return T(t,e),t.prototype.getDescription=function(){return this.onGetDescription?this.onGetDescription():"Running user defined callback"},t.prototype.apply=function(e,t){return!this.onApply||this.onApply(e,t)},t})(e);d.CustomOptimization=c;var h=(function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return T(t,e),t.prototype.getDescription=function(){return"Turning particles on/off"},t.prototype.apply=function(e,t){return e.particlesEnabled=t.isInImprovementMode,!0},t})(e);d.ParticlesOptimization=h;var u=(function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return T(t,e),t.prototype.getDescription=function(){return"Turning render targets off"},t.prototype.apply=function(e,t){return e.renderTargetsEnabled=t.isInImprovementMode,!0},t})(e);d.RenderTargetsOptimization=u;var f=(function(t){function u(){var e=null!==t&&t.apply(this,arguments)||this;return e._canBeMerged=function(e){if(!(e instanceof d.Mesh))return!1;var t=e;return!t.isDisposed()&&(!(!t.isVisible||!t.isEnabled())&&(!(0=this._targetFrameRate)return this._isRunning=!1,void this.onSuccessObservable.notifyObservers(this);for(var r=!0,n=!0,o=0;ol.upperRadiusLimit?l.upperRadiusLimit:a),a):0},p.prototype._maintainCameraAboveGround=function(){var e=this;if(!(this._elevationReturnTime<0)){var t=Ea.Tools.Now-this._lastInteractionTime,i=.5*Math.PI-this._defaultElevation,r=.5*Math.PI;if(this._attachedCamera&&!this._betaIsAnimating&&this._attachedCamera.beta>r&&t>=this._elevationReturnWaitTime){this._betaIsAnimating=!0,this.stopAllAnimations(),this._betaTransition||(this._betaTransition=Ea.Animation.CreateAnimation("beta",Ea.Animation.ANIMATIONTYPE_FLOAT,60,p.EasingFunction));var n=Ea.Animation.TransitionTo("beta",i,this._attachedCamera,this._attachedCamera.getScene(),60,this._betaTransition,this._elevationReturnTime,(function(){e._clearAnimationLocks(),e.stopAllAnimations()}));n&&this._animatables.push(n)}}},p.prototype._getFrustumSlope=function(){var e=this._attachedCamera;if(!e)return Ea.Vector2.Zero();var t=e.getScene().getEngine().getAspectRatio(e),i=Math.tan(e.fov/2),r=i*t;return new Ea.Vector2(r,i)},p.prototype._clearAnimationLocks=function(){this._betaIsAnimating=!1},p.prototype._applyUserInteraction=function(){this.isUserIsMoving&&(this._lastInteractionTime=Ea.Tools.Now,this.stopAllAnimations(),this._clearAnimationLocks())},p.prototype.stopAllAnimations=function(){for(this._attachedCamera&&(this._attachedCamera.animations=[]);this._animatables.length;)this._animatables[0]&&(this._animatables[0].onAnimationEnd=null,this._animatables[0].stop()),this._animatables.shift()},Object.defineProperty(p.prototype,"isUserIsMoving",{get:function(){return!!this._attachedCamera&&(0!==this._attachedCamera.inertialAlphaOffset||0!==this._attachedCamera.inertialBetaOffset||0!==this._attachedCamera.inertialRadiusOffset||0!==this._attachedCamera.inertialPanningX||0!==this._attachedCamera.inertialPanningY||this._isPointerDown)},enumerable:!0,configurable:!0}),p.EasingFunction=new Ea.ExponentialEase,p.EasingMode=Ea.EasingFunction.EASINGMODE_EASEINOUT,p.IgnoreBoundsSizeMode=0,p.FitFrustumSidesMode=1,p})(),Ea.FramingBehavior=Aa,Pa=$a||($a={}),Sa=(function(){function r(){this.transitionDuration=450,this.lowerRadiusTransitionRange=2,this.upperRadiusTransitionRange=-2,this._autoTransitionRange=!1,this._radiusIsAnimating=!1,this._radiusBounceTransition=null,this._animatables=new Array}return Object.defineProperty(r.prototype,"name",{get:function(){return"Bouncing"},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"autoTransitionRange",{get:function(){return this._autoTransitionRange},set:function(e){var i=this;if(this._autoTransitionRange!==e){this._autoTransitionRange=e;var t=this._attachedCamera;t&&(e?this._onMeshTargetChangedObserver=t.onMeshTargetChangedObservable.add((function(e){if(e){e.computeWorldMatrix(!0);var t=e.getBoundingInfo().diagonalLength;i.lowerRadiusTransitionRange=.05*t,i.upperRadiusTransitionRange=.05*t}})):this._onMeshTargetChangedObserver&&t.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver))}},enumerable:!0,configurable:!0}),r.prototype.init=function(){},r.prototype.attach=function(e){var t=this;this._attachedCamera=e,this._onAfterCheckInputsObserver=e.onAfterCheckInputsObservable.add((function(){t._attachedCamera&&(t._isRadiusAtLimit(t._attachedCamera.lowerRadiusLimit)&&t._applyBoundRadiusAnimation(t.lowerRadiusTransitionRange),t._isRadiusAtLimit(t._attachedCamera.upperRadiusLimit)&&t._applyBoundRadiusAnimation(t.upperRadiusTransitionRange))}))},r.prototype.detach=function(){this._attachedCamera&&(this._onAfterCheckInputsObserver&&this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver),this._onMeshTargetChangedObserver&&this._attachedCamera.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver),this._attachedCamera=null)},r.prototype._isRadiusAtLimit=function(e){return!!this._attachedCamera&&(this._attachedCamera.radius===e&&!this._radiusIsAnimating)},r.prototype._applyBoundRadiusAnimation=function(e){var t=this;if(this._attachedCamera){this._radiusBounceTransition||(r.EasingFunction.setEasingMode(r.EasingMode),this._radiusBounceTransition=Pa.Animation.CreateAnimation("radius",Pa.Animation.ANIMATIONTYPE_FLOAT,60,r.EasingFunction)),this._cachedWheelPrecision=this._attachedCamera.wheelPrecision,this._attachedCamera.wheelPrecision=1/0,this._attachedCamera.inertialRadiusOffset=0,this.stopAllAnimations(),this._radiusIsAnimating=!0;var i=Pa.Animation.TransitionTo("radius",this._attachedCamera.radius+e,this._attachedCamera,this._attachedCamera.getScene(),60,this._radiusBounceTransition,this.transitionDuration,(function(){return t._clearAnimationLocks()}));i&&this._animatables.push(i)}},r.prototype._clearAnimationLocks=function(){this._radiusIsAnimating=!1,this._attachedCamera&&(this._attachedCamera.wheelPrecision=this._cachedWheelPrecision)},r.prototype.stopAllAnimations=function(){for(this._attachedCamera&&(this._attachedCamera.animations=[]);this._animatables.length;)this._animatables[0].onAnimationEnd=null,this._animatables[0].stop(),this._animatables.shift()},r.EasingFunction=new Pa.BackEase(.3),r.EasingMode=Pa.EasingFunction.EASINGMODE_EASEOUT,r})(),Pa.BouncingBehavior=Sa,Ra=$a||($a={}),Ma=(function(){function e(){this._zoomStopsAnimation=!1,this._idleRotationSpeed=.05,this._idleRotationWaitTime=2e3,this._idleRotationSpinupTime=2e3,this._isPointerDown=!1,this._lastFrameTime=null,this._lastInteractionTime=-1/0,this._cameraRotationSpeed=0,this._lastFrameRadius=0}return Object.defineProperty(e.prototype,"name",{get:function(){return"AutoRotation"},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"zoomStopsAnimation",{get:function(){return this._zoomStopsAnimation},set:function(e){this._zoomStopsAnimation=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"idleRotationSpeed",{get:function(){return this._idleRotationSpeed},set:function(e){this._idleRotationSpeed=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"idleRotationWaitTime",{get:function(){return this._idleRotationWaitTime},set:function(e){this._idleRotationWaitTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"idleRotationSpinupTime",{get:function(){return this._idleRotationSpinupTime},set:function(e){this._idleRotationSpinupTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotationInProgress",{get:function(){return 0e.occlusionRetryCount))return!1;e.isOcclusionQueryInProgress=!1,e.occlusionInternalRetryCounter=0,e.isOccluded=e.occlusionType!==Ya.AbstractMesh.OCCLUSION_TYPE_OPTIMISTIC&&e.isOccluded}var r=this.getScene();if(r.getBoundingBoxRenderer){var n=r.getBoundingBoxRenderer();this._occlusionQuery||(this._occlusionQuery=t.createQuery()),t.beginOcclusionQuery(e.occlusionQueryAlgorithmType,this._occlusionQuery),n.renderOcclusionBoundingBox(this),t.endOcclusionQuery(e.occlusionQueryAlgorithmType),this._occlusionDataStorage.isOcclusionQueryInProgress=!0}return e.isOccluded},Qa=$a||($a={}),Za=(function(s){function n(e,t,i,r,n){void 0===t&&(t=256),void 0===i&&(i=Qa.Engine.LastCreatedScene);var o=s.call(this,e,t,"noise",i,r,n)||this;return o._time=0,o.brightness=.2,o.octaves=3,o.persistence=.8,o.animationSpeedFactor=1,o.autoClear=!1,o._updateShaderUniforms(),o}return T(n,s),n.prototype._updateShaderUniforms=function(){var e=this.getScene();e&&(this._time+=e.getAnimationRatio()*this.animationSpeedFactor*.01,this.setFloat("brightness",this.brightness),this.setFloat("persistence",this.persistence),this.setFloat("timeScale",this._time))},n.prototype._getDefines=function(){return"#define OCTAVES "+(0|this.octaves)},n.prototype.render=function(e){this._updateShaderUniforms(),s.prototype.render.call(this,e)},n.prototype.serialize=function(){var e={customType:"BABYLON.NoiseProceduralTexture"};return e.brightness=this.brightness,e.octaves=this.octaves,e.persistence=this.persistence,e.animationSpeedFactor=this.animationSpeedFactor,e.size=this.getSize().width,e.generateMipMaps=this._generateMipMaps,e},n.Parse=function(e,t,i){var r=new n(e.name,e.size,t,void 0,e.generateMipMaps);return r.brightness=e.brightness,r.octaves=e.octaves,r.persistence=e.persistence,r.animationSpeedFactor=e.animationSpeedFactor,r},n})(Qa.ProceduralTexture),Qa.NoiseProceduralTexture=Za;var qa,Ja,$a,el;ae=this&&this.__assign||function(){return(ae=Object.assign||function(e){for(var t,i=1,r=arguments.length;i\n\n#define CUSTOM_VERTEX_BEGIN\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\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#include\n#include\n\n#include\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nvarying vec2 vDiffuseUV;\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nvarying vec2 vAmbientUV;\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nvarying vec2 vOpacityUV;\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nvarying vec2 vEmissiveUV;\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nvarying vec2 vLightmapUV;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0\nvarying vec2 vSpecularUV;\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nvarying vec2 vBumpUV;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include\n#include\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nvec3 positionUpdated=position;\n#ifdef NORMAL \nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#include[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\n#ifdef REFLECTIONMAP_SKYBOX_TRANSFORMED\nvPositionUVW=(reflectionMatrix*vec4(position,1.0)).xyz;\n#else\nvPositionUVW=position;\n#endif\n#endif \n#define CUSTOM_VERTEX_UPDATE_POSITION\n#define CUSTOM_VERTEX_UPDATE_NORMAL\n#include\n#include\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normalUpdated);\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uv;\n#endif\n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nif (vLightmapInfos.x == 0.)\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0\nif (vSpecularInfos.x == 0.)\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nif (vBumpInfos.x == 0.)\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#include\n#include\n#include\n#include[0..maxSimultaneousLights]\n#ifdef VERTEXCOLOR\n\nvColor=color;\n#endif\n#include\n#include\n#define CUSTOM_VERTEX_MAIN_END\n}\n",defaultPixelShader:"#include<__decl__defaultFragment>\n#if defined(BUMP) || !defined(NORMAL)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#define CUSTOM_FRAGMENT_BEGIN\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n\n#define RECIPROCAL_PI2 0.15915494\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n\n#include\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\n\n#ifdef DIFFUSE\n#if DIFFUSEDIRECTUV == 1\n#define vDiffuseUV vMainUV1\n#elif DIFFUSEDIRECTUV == 2\n#define vDiffuseUV vMainUV2\n#else\nvarying vec2 vDiffuseUV;\n#endif\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef AMBIENT\n#if AMBIENTDIRECTUV == 1\n#define vAmbientUV vMainUV1\n#elif AMBIENTDIRECTUV == 2\n#define vAmbientUV vMainUV2\n#else\nvarying vec2 vAmbientUV;\n#endif\nuniform sampler2D ambientSampler;\n#endif\n#ifdef OPACITY \n#if OPACITYDIRECTUV == 1\n#define vOpacityUV vMainUV1\n#elif OPACITYDIRECTUV == 2\n#define vOpacityUV vMainUV2\n#else\nvarying vec2 vOpacityUV;\n#endif\nuniform sampler2D opacitySampler;\n#endif\n#ifdef EMISSIVE\n#if EMISSIVEDIRECTUV == 1\n#define vEmissiveUV vMainUV1\n#elif EMISSIVEDIRECTUV == 2\n#define vEmissiveUV vMainUV2\n#else\nvarying vec2 vEmissiveUV;\n#endif\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\n#if LIGHTMAPDIRECTUV == 1\n#define vLightmapUV vMainUV1\n#elif LIGHTMAPDIRECTUV == 2\n#define vLightmapUV vMainUV2\n#else\nvarying vec2 vLightmapUV;\n#endif\nuniform sampler2D lightmapSampler;\n#endif\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\n#if SPECULARDIRECTUV == 1\n#define vSpecularUV vMainUV1\n#elif SPECULARDIRECTUV == 2\n#define vSpecularUV vMainUV2\n#else\nvarying vec2 vSpecularUV;\n#endif\nuniform sampler2D specularSampler;\n#endif\n#ifdef ALPHATEST\nuniform float alphaCutOff;\n#endif\n\n#include\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include\n#endif\n#include\n#include\n#include\n#include\n#include\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(-cross(dFdx(vPositionW),dFdy(vPositionW)));\n#endif\n#include\n#ifdef TWOSIDEDLIGHTING\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);\n#ifdef ALPHATEST\nif (baseColor.a\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n#define CUSTOM_FRAGMENT_UPDATE_DIFFUSE\n\nvec3 baseAmbientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nbaseAmbientColor=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_LIGHTS\n\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularColor=vSpecularColor.rgb;\n#ifdef SPECULAR\nvec4 specularMapColor=texture2D(specularSampler,vSpecularUV+uvOffset);\nspecularColor=specularMapColor.rgb;\n#ifdef GLOSSINESS\nglossiness=glossiness*specularMapColor.a;\n#endif\n#endif\n#else\nfloat glossiness=0.;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\nfloat shadow=1.;\n#ifdef LIGHTMAP\nvec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;\n#endif\n#include[0..maxSimultaneousLights]\n\nvec3 refractionColor=vec3(0.,0.,0.);\n#ifdef REFRACTION\nvec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));\n#ifdef REFRACTIONMAP_3D\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;\nif (dot(refractionVector,viewDirectionW)<1.0) {\nrefractionColor=textureCube(refractionCubeSampler,refractionVector).rgb;\n}\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\nvec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;\nrefractionCoords.y=1.0-refractionCoords.y;\nrefractionColor=texture2D(refraction2DSampler,refractionCoords).rgb;\n#endif\n#ifdef IS_REFRACTION_LINEAR\nrefractionColor=toGammaSpace(refractionColor);\n#endif\nrefractionColor*=vRefractionInfos.x;\n#endif\n\nvec3 reflectionColor=vec3(0.,0.,0.);\n#ifdef REFLECTION\nvec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_3D\n#ifdef ROUGHNESS\nfloat bias=vReflectionInfos.y;\n#ifdef SPECULARTERM\n#ifdef SPECULAR\n#ifdef GLOSSINESS\nbias*=(1.0-specularMapColor.a);\n#endif\n#endif\n#endif\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW,bias).rgb;\n#else\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW).rgb;\n#endif\n#else\nvec2 coords=vReflectionUVW.xy;\n#ifdef REFLECTIONMAP_PROJECTION\ncoords/=vReflectionUVW.z;\n#endif\ncoords.y=1.0-coords.y;\nreflectionColor=texture2D(reflection2DSampler,coords).rgb;\n#endif\n#ifdef IS_REFLECTION_LINEAR\nreflectionColor=toGammaSpace(reflectionColor);\n#endif\nreflectionColor*=vReflectionInfos.x;\n#ifdef REFLECTIONFRESNEL\nfloat reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);\n#ifdef REFLECTIONFRESNELFROMSPECULAR\n#ifdef SPECULARTERM\nreflectionColor*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#else\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#else\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#endif\n#endif\n#ifdef REFRACTIONFRESNEL\nfloat refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);\nrefractionColor*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\nalpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef OPACITYFRESNEL\nfloat opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);\nalpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n#endif\n\nvec3 emissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nemissiveColor+=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb*vEmissiveInfos.y;\n#endif\n#ifdef EMISSIVEFRESNEL\nfloat emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);\nemissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n#endif\n\n#ifdef DIFFUSEFRESNEL\nfloat diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);\ndiffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\n#ifdef LINKEMISSIVEWITHDIFFUSE\nvec3 finalDiffuse=clamp((diffuseBase+emissiveColor)*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#endif\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef REFLECTIONOVERALPHA\nalpha=clamp(alpha+dot(reflectionColor,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec4 color=vec4(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+emissiveColor+refractionColor,0.0,1.0),alpha);\n#else\nvec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+refractionColor,alpha);\n#endif\n\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\ncolor.rgb*=lightmapColor;\n#else\ncolor.rgb+=lightmapColor;\n#endif\n#endif\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_FOG\ncolor.rgb=max(color.rgb,0.);\n#include\n#include\n\n\n#ifdef IMAGEPROCESSINGPOSTPROCESS\ncolor.rgb=toLinearSpace(color.rgb);\n#else\n#ifdef IMAGEPROCESSING\ncolor.rgb=toLinearSpace(color.rgb);\ncolor=applyImageProcessing(color);\n#endif\n#endif\n#ifdef PREMULTIPLYALPHA\n\ncolor.rgb*=color.a;\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR\ngl_FragColor=color;\n}\n",pbrVertexShader:"precision highp float;\n#include<__decl__pbrVertex>\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2; \n#endif \n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include\n#include\n\n#include\n#if defined(ALBEDO) && ALBEDODIRECTUV == 0\nvarying vec2 vAlbedoUV;\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nvarying vec2 vAmbientUV;\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nvarying vec2 vOpacityUV;\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nvarying vec2 vEmissiveUV;\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nvarying vec2 vLightmapUV;\n#endif\n#if defined(REFLECTIVITY) && REFLECTIVITYDIRECTUV == 0\nvarying vec2 vReflectivityUV;\n#endif\n#if defined(MICROSURFACEMAP) && MICROSURFACEMAPDIRECTUV == 0\nvarying vec2 vMicroSurfaceSamplerUV;\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nvarying vec2 vBumpUV;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\nvarying vec3 vEnvironmentIrradiance;\n#include\n#endif\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include\n#include\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include\nvoid main(void) {\nvec3 positionUpdated=position;\n#ifdef NORMAL\nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#include[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\n#ifdef REFLECTIONMAP_SKYBOX_TRANSFORMED\nvPositionUVW=(reflectionMatrix*vec4(positionUpdated,1.0)).xyz;\n#else\nvPositionUVW=positionUpdated;\n#endif\n#endif \n#include\n#include\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normalUpdated);\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\nvec3 reflectionVector=vec3(reflectionMatrix*vec4(vNormalW,0)).xyz;\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflectionVector.z*=-1.0;\n#endif\nvEnvironmentIrradiance=environmentIrradianceJones(reflectionVector);\n#endif\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uv;\n#endif \n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif \n#if defined(ALBEDO) && ALBEDODIRECTUV == 0 \nif (vAlbedoInfos.x == 0.)\n{\nvAlbedoUV=vec2(albedoMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAlbedoUV=vec2(albedoMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0 \nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0 \nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0 \nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0 \nif (vLightmapInfos.x == 0.)\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(REFLECTIVITY) && REFLECTIVITYDIRECTUV == 0 \nif (vReflectivityInfos.x == 0.)\n{\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(MICROSURFACEMAP) && MICROSURFACEMAPDIRECTUV == 0 \nif (vMicroSurfaceSamplerInfos.x == 0.)\n{\nvMicroSurfaceSamplerUV=vec2(microSurfaceSamplerMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvMicroSurfaceSamplerUV=vec2(microSurfaceSamplerMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0 \nif (vBumpInfos.x == 0.)\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include\n\n#include\n\n#include\n\n#include[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n\n#include\n}",pbrPixelShader:"#if defined(BUMP) || !defined(NORMAL) || defined(FORCENORMALFORWARD) || defined(SPECULARAA)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef LODBASEDMICROSFURACE\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nprecision highp float;\n#include<__decl__pbrFragment>\nuniform vec4 vEyePosition;\nuniform vec3 vAmbientColor;\nuniform vec4 vCameraInfos;\n\nvarying vec3 vPositionW;\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif \n#ifdef MAINUV2 \nvarying vec2 vMainUV2;\n#endif \n#ifdef NORMAL\nvarying vec3 vNormalW;\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\nvarying vec3 vEnvironmentIrradiance;\n#endif\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef ALBEDO\n#if ALBEDODIRECTUV == 1\n#define vAlbedoUV vMainUV1\n#elif ALBEDODIRECTUV == 2\n#define vAlbedoUV vMainUV2\n#else\nvarying vec2 vAlbedoUV;\n#endif\nuniform sampler2D albedoSampler;\n#endif\n#ifdef AMBIENT\n#if AMBIENTDIRECTUV == 1\n#define vAmbientUV vMainUV1\n#elif AMBIENTDIRECTUV == 2\n#define vAmbientUV vMainUV2\n#else\nvarying vec2 vAmbientUV;\n#endif\nuniform sampler2D ambientSampler;\n#endif\n#ifdef OPACITY\n#if OPACITYDIRECTUV == 1\n#define vOpacityUV vMainUV1\n#elif OPACITYDIRECTUV == 2\n#define vOpacityUV vMainUV2\n#else\nvarying vec2 vOpacityUV;\n#endif\nuniform sampler2D opacitySampler;\n#endif\n#ifdef EMISSIVE\n#if EMISSIVEDIRECTUV == 1\n#define vEmissiveUV vMainUV1\n#elif EMISSIVEDIRECTUV == 2\n#define vEmissiveUV vMainUV2\n#else\nvarying vec2 vEmissiveUV;\n#endif\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\n#if LIGHTMAPDIRECTUV == 1\n#define vLightmapUV vMainUV1\n#elif LIGHTMAPDIRECTUV == 2\n#define vLightmapUV vMainUV2\n#else\nvarying vec2 vLightmapUV;\n#endif\nuniform sampler2D lightmapSampler;\n#endif\n#ifdef REFLECTIVITY\n#if REFLECTIVITYDIRECTUV == 1\n#define vReflectivityUV vMainUV1\n#elif REFLECTIVITYDIRECTUV == 2\n#define vReflectivityUV vMainUV2\n#else\nvarying vec2 vReflectivityUV;\n#endif\nuniform sampler2D reflectivitySampler;\n#endif\n#ifdef MICROSURFACEMAP\n#if MICROSURFACEMAPDIRECTUV == 1\n#define vMicroSurfaceSamplerUV vMainUV1\n#elif MICROSURFACEMAPDIRECTUV == 2\n#define vMicroSurfaceSamplerUV vMainUV2\n#else\nvarying vec2 vMicroSurfaceSamplerUV;\n#endif\nuniform sampler2D microSurfaceSampler;\n#endif\n\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\n#define sampleRefraction(s,c) textureCube(s,c)\nuniform samplerCube refractionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleRefractionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube refractionSamplerLow;\nuniform samplerCube refractionSamplerHigh;\n#endif\n#else\n#define sampleRefraction(s,c) texture2D(s,c)\nuniform sampler2D refractionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleRefractionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform samplerCube refractionSamplerLow;\nuniform samplerCube refractionSamplerHigh;\n#endif\n#endif\n#endif\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\n#define sampleReflection(s,c) textureCube(s,c)\nuniform samplerCube reflectionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleReflectionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;\nuniform samplerCube reflectionSamplerHigh;\n#endif\n#else\n#define sampleReflection(s,c) texture2D(s,c)\nuniform sampler2D reflectionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleReflectionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;\nuniform samplerCube reflectionSamplerHigh;\n#endif\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include\n#endif\n#ifdef ENVIRONMENTBRDF\nuniform sampler2D environmentBrdfSampler;\n#endif\n\n#ifndef FROMLINEARSPACE\n#define FROMLINEARSPACE;\n#endif\n#include\n#include\n#include\n\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n\n#include\nvoid main(void) {\n#include\n\n\nvec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(cross(dFdx(vPositionW),dFdy(vPositionW)))*vEyePosition.w;\n#endif\n#include\n#ifdef SPECULARAA\nvec3 nDfdx=dFdx(normalW.xyz);\nvec3 nDfdy=dFdy(normalW.xyz);\nfloat slopeSquare=max(dot(nDfdx,nDfdx),dot(nDfdy,nDfdy));\n\nfloat geometricRoughnessFactor=pow(clamp(slopeSquare ,0.,1.),0.333);\n\nfloat geometricAlphaGFactor=sqrt(slopeSquare);\n#else\nfloat geometricRoughnessFactor=0.;\n#endif\n#if defined(FORCENORMALFORWARD) && defined(NORMAL)\nvec3 faceNormal=normalize(cross(dFdx(vPositionW),dFdy(vPositionW)))*vEyePosition.w;\n#if defined(TWOSIDEDLIGHTING)\nfaceNormal=gl_FrontFacing ? faceNormal : -faceNormal;\n#endif\nnormalW*=sign(dot(normalW,faceNormal));\n#endif\n#if defined(TWOSIDEDLIGHTING) && defined(NORMAL)\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n\n\nvec3 surfaceAlbedo=vAlbedoColor.rgb;\n\nfloat alpha=vAlbedoColor.a;\n#ifdef ALBEDO\nvec4 albedoTexture=texture2D(albedoSampler,vAlbedoUV+uvOffset);\n#if defined(ALPHAFROMALBEDO) || defined(ALPHATEST)\nalpha*=albedoTexture.a;\n#endif\nsurfaceAlbedo*=toLinearSpace(albedoTexture.rgb);\nsurfaceAlbedo*=vAlbedoInfos.y;\n#endif\n\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#ifdef OPACITYRGB\nalpha=getLuminance(opacityMap.rgb);\n#else\nalpha*=opacityMap.a;\n#endif\nalpha*=vOpacityInfos.y;\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#if !defined(LINKREFRACTIONTOTRANSPARENCY) && !defined(ALPHAFRESNEL)\n#ifdef ALPHATEST\nif (alpha\n#ifdef VERTEXCOLOR\nsurfaceAlbedo*=vColor.rgb;\n#endif\n\nvec3 ambientOcclusionColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nvec3 ambientOcclusionColorMap=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n#ifdef AMBIENTINGRAYSCALE\nambientOcclusionColorMap=vec3(ambientOcclusionColorMap.r,ambientOcclusionColorMap.r,ambientOcclusionColorMap.r);\n#endif\nambientOcclusionColor=mix(ambientOcclusionColor,ambientOcclusionColorMap,vAmbientInfos.z);\n#endif\n#ifdef UNLIT\nvec3 diffuseBase=vec3(1.,1.,1.);\n#else\n\nfloat microSurface=vReflectivityColor.a;\nvec3 surfaceReflectivityColor=vReflectivityColor.rgb;\n#ifdef METALLICWORKFLOW\nvec2 metallicRoughness=surfaceReflectivityColor.rg;\n#ifdef REFLECTIVITY\nvec4 surfaceMetallicColorMap=texture2D(reflectivitySampler,vReflectivityUV+uvOffset);\n#ifdef AOSTOREINMETALMAPRED\nvec3 aoStoreInMetalMap=vec3(surfaceMetallicColorMap.r,surfaceMetallicColorMap.r,surfaceMetallicColorMap.r);\nambientOcclusionColor=mix(ambientOcclusionColor,aoStoreInMetalMap,vReflectivityInfos.z);\n#endif\n#ifdef METALLNESSSTOREINMETALMAPBLUE\nmetallicRoughness.r*=surfaceMetallicColorMap.b;\n#else\nmetallicRoughness.r*=surfaceMetallicColorMap.r;\n#endif\n#ifdef ROUGHNESSSTOREINMETALMAPALPHA\nmetallicRoughness.g*=surfaceMetallicColorMap.a;\n#else\n#ifdef ROUGHNESSSTOREINMETALMAPGREEN\nmetallicRoughness.g*=surfaceMetallicColorMap.g;\n#endif\n#endif\n#endif\n#ifdef MICROSURFACEMAP\nvec4 microSurfaceTexel=texture2D(microSurfaceSampler,vMicroSurfaceSamplerUV+uvOffset)*vMicroSurfaceSamplerInfos.y;\nmetallicRoughness.g*=microSurfaceTexel.r;\n#endif\n\nmicroSurface=1.0-metallicRoughness.g;\n\nvec3 baseColor=surfaceAlbedo;\n\n\nconst vec3 DefaultSpecularReflectanceDielectric=vec3(0.04,0.04,0.04);\n\nsurfaceAlbedo=mix(baseColor.rgb*(1.0-DefaultSpecularReflectanceDielectric.r),vec3(0.,0.,0.),metallicRoughness.r);\n\nsurfaceReflectivityColor=mix(DefaultSpecularReflectanceDielectric,baseColor,metallicRoughness.r);\n#else\n#ifdef REFLECTIVITY\nvec4 surfaceReflectivityColorMap=texture2D(reflectivitySampler,vReflectivityUV+uvOffset);\nsurfaceReflectivityColor*=toLinearSpace(surfaceReflectivityColorMap.rgb);\nsurfaceReflectivityColor*=vReflectivityInfos.y;\n#ifdef MICROSURFACEFROMREFLECTIVITYMAP\nmicroSurface*=surfaceReflectivityColorMap.a;\nmicroSurface*=vReflectivityInfos.z;\n#else\n#ifdef MICROSURFACEAUTOMATIC\nmicroSurface*=computeDefaultMicroSurface(microSurface,surfaceReflectivityColor);\n#endif\n#ifdef MICROSURFACEMAP\nvec4 microSurfaceTexel=texture2D(microSurfaceSampler,vMicroSurfaceSamplerUV+uvOffset)*vMicroSurfaceSamplerInfos.y;\nmicroSurface*=microSurfaceTexel.r;\n#endif\n#endif\n#endif\n#endif\n\nmicroSurface=clamp(microSurface,0.,1.);\n\nfloat roughness=1.-microSurface;\n\n#ifdef ALPHAFRESNEL\n#if defined(ALPHATEST) || defined(ALPHABLEND)\n\n\n\nfloat opacityPerceptual=alpha;\n#ifdef LINEARALPHAFRESNEL\nfloat opacity0=opacityPerceptual;\n#else\nfloat opacity0=opacityPerceptual*opacityPerceptual;\n#endif\nfloat opacity90=fresnelGrazingReflectance(opacity0);\nvec3 normalForward=faceforward(normalW,-viewDirectionW,normalW);\n\nalpha=fresnelSchlickEnvironmentGGX(clamp(dot(viewDirectionW,normalForward),0.0,1.0),vec3(opacity0),vec3(opacity90),sqrt(microSurface)).x;\n#ifdef ALPHATEST\nif (alpha[0..maxSimultaneousLights]\n\n#if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)\n\nvec2 brdfSamplerUV=vec2(NdotV,roughness);\n\nvec4 environmentBrdf=texture2D(environmentBrdfSampler,brdfSamplerUV);\nvec3 specularEnvironmentReflectance=specularEnvironmentR0*environmentBrdf.x+environmentBrdf.y;\n#ifdef RADIANCEOCCLUSION\n#ifdef AMBIENTINGRAYSCALE\nfloat ambientMonochrome=ambientOcclusionColor.r;\n#else\nfloat ambientMonochrome=getLuminance(ambientOcclusionColor);\n#endif\nfloat seo=environmentRadianceOcclusion(ambientMonochrome,NdotVUnclamped);\nspecularEnvironmentReflectance*=seo;\n#endif\n#ifdef HORIZONOCCLUSION\n#ifdef BUMP\n#ifdef REFLECTIONMAP_3D\nfloat eho=environmentHorizonOcclusion(-viewDirectionW,normalW);\nspecularEnvironmentReflectance*=eho;\n#endif\n#endif\n#endif\n#else\n\nvec3 specularEnvironmentReflectance=fresnelSchlickEnvironmentGGX(NdotV,specularEnvironmentR0,specularEnvironmentR90,sqrt(microSurface));\n#endif\n\n#ifdef REFRACTION\nvec3 refractance=vec3(0.0,0.0,0.0);\nvec3 transmission=vec3(1.0,1.0,1.0);\n#ifdef LINKREFRACTIONTOTRANSPARENCY\n\ntransmission*=(1.0-alpha);\n\n\nvec3 mixedAlbedo=surfaceAlbedo;\nfloat maxChannel=max(max(mixedAlbedo.r,mixedAlbedo.g),mixedAlbedo.b);\nvec3 tint=clamp(maxChannel*mixedAlbedo,0.0,1.0);\n\nsurfaceAlbedo*=alpha;\n\nenvironmentIrradiance*=alpha;\n\nenvironmentRefraction.rgb*=tint;\n\nalpha=1.0;\n#endif\n\nvec3 bounceSpecularEnvironmentReflectance=(2.0*specularEnvironmentReflectance)/(1.0+specularEnvironmentReflectance);\nspecularEnvironmentReflectance=mix(bounceSpecularEnvironmentReflectance,specularEnvironmentReflectance,alpha);\n\ntransmission*=1.0-specularEnvironmentReflectance;\n\nrefractance=transmission;\n#endif\n\n\n\n\nsurfaceAlbedo.rgb=(1.-reflectance)*surfaceAlbedo.rgb;\n\n#ifdef REFLECTION\nvec3 finalIrradiance=environmentIrradiance;\nfinalIrradiance*=surfaceAlbedo.rgb;\n#endif\n\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase;\nfinalSpecular=max(finalSpecular,0.0);\n\nvec3 finalSpecularScaled=finalSpecular*vLightingIntensity.x*vLightingIntensity.w;\n#endif\n\n#ifdef REFLECTION\nvec3 finalRadiance=environmentRadiance.rgb;\nfinalRadiance*=specularEnvironmentReflectance;\n\nvec3 finalRadianceScaled=finalRadiance*vLightingIntensity.z;\n#endif\n\n#ifdef REFRACTION\nvec3 finalRefraction=environmentRefraction.rgb;\nfinalRefraction*=refractance;\n#endif\n\n#ifdef ALPHABLEND\nfloat luminanceOverAlpha=0.0;\n#if defined(REFLECTION) && defined(RADIANCEOVERALPHA)\nluminanceOverAlpha+=getLuminance(finalRadianceScaled);\n#endif\n#if defined(SPECULARTERM) && defined(SPECULAROVERALPHA)\nluminanceOverAlpha+=getLuminance(finalSpecularScaled);\n#endif\n#if defined(RADIANCEOVERALPHA) || defined(SPECULAROVERALPHA)\nalpha=clamp(alpha+luminanceOverAlpha*luminanceOverAlpha,0.,1.);\n#endif\n#endif\n#endif\n\nvec3 finalDiffuse=diffuseBase;\nfinalDiffuse.rgb+=vAmbientColor;\nfinalDiffuse*=surfaceAlbedo.rgb;\nfinalDiffuse=max(finalDiffuse,0.0);\n\nvec3 finalEmissive=vEmissiveColor;\n#ifdef EMISSIVE\nvec3 emissiveColorTex=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb;\nfinalEmissive*=toLinearSpace(emissiveColorTex.rgb);\nfinalEmissive*=vEmissiveInfos.y;\n#endif\n\n#ifdef AMBIENT\nvec3 ambientOcclusionForDirectDiffuse=mix(vec3(1.),ambientOcclusionColor,vAmbientInfos.w);\n#else\nvec3 ambientOcclusionForDirectDiffuse=ambientOcclusionColor;\n#endif\n\n\n\nvec4 finalColor=vec4(\nfinalDiffuse*ambientOcclusionForDirectDiffuse*vLightingIntensity.x +\n#ifndef UNLIT\n#ifdef REFLECTION\nfinalIrradiance*ambientOcclusionColor*vLightingIntensity.z +\n#endif\n#ifdef SPECULARTERM\n\n\nfinalSpecularScaled +\n#endif\n#ifdef REFLECTION\n\n\nfinalRadianceScaled +\n#endif\n#ifdef REFRACTION\nfinalRefraction*vLightingIntensity.z +\n#endif\n#endif\nfinalEmissive*vLightingIntensity.y,\nalpha);\n\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\nfinalColor.rgb*=lightmapColor;\n#else\nfinalColor.rgb+=lightmapColor;\n#endif\n#endif\n#endif\n\nfinalColor=max(finalColor,0.0);\n#include\n#include(color,finalColor)\n#ifdef IMAGEPROCESSINGPOSTPROCESS\n\n\nfinalColor.rgb=clamp(finalColor.rgb,0.,30.0);\n#else\n\nfinalColor=applyImageProcessing(finalColor);\n#endif\n#ifdef PREMULTIPLYALPHA\n\nfinalColor.rgb*=finalColor.a;\n#endif\ngl_FragColor=finalColor;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n}",rgbdEncodePixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n#include\nvoid main(void) \n{\ngl_FragColor=toRGBD(texture2D(textureSampler,vUV).rgb);\n}",rgbdDecodePixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n#include\nvoid main(void) \n{\ngl_FragColor=vec4(fromRGBD(texture2D(textureSampler,vUV)),1.0);\n}",spritesVertexShader:"\nattribute vec4 position;\nattribute vec4 options;\nattribute vec4 cellInfo;\nattribute vec4 color;\n\nuniform vec2 textureInfos;\nuniform mat4 view;\nuniform mat4 projection;\n\nvarying vec2 vUV;\nvarying vec4 vColor;\n#include\nvoid main(void) { \nvec3 viewPos=(view*vec4(position.xyz,1.0)).xyz; \nvec2 cornerPos;\nfloat angle=position.w;\nvec2 size=vec2(options.x,options.y);\nvec2 offset=options.zw;\nvec2 uvScale=textureInfos.xy;\ncornerPos=vec2(offset.x-0.5,offset.y-0.5)*size;\n\nvec3 rotatedCorner;\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);\nrotatedCorner.y=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);\nrotatedCorner.z=0.;\n\nviewPos+=rotatedCorner;\ngl_Position=projection*vec4(viewPos,1.0); \n\nvColor=color;\n\nvec2 uvOffset=vec2(abs(offset.x-cellInfo.x),1.0-abs(offset.y-cellInfo.y));\nvUV=(uvOffset+cellInfo.zw)*uvScale;\n\n#ifdef FOG\nvFogDistance=viewPos;\n#endif\n}",spritesPixelShader:"uniform bool alphaTest;\nvarying vec4 vColor;\n\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n\n#include\nvoid main(void) {\nvec4 color=texture2D(diffuseSampler,vUV);\nif (alphaTest) \n{\nif (color.a<0.95)\ndiscard;\n}\ncolor*=vColor;\n#include\ngl_FragColor=color;\n}",particlesVertexShader:"\nattribute vec3 position;\nattribute vec4 color;\nattribute float angle;\nattribute vec2 size;\n#ifdef ANIMATESHEET \nattribute float cellIndex;\n#endif\n#ifndef BILLBOARD \nattribute vec3 direction;\n#endif\n#ifdef BILLBOARDSTRETCHED\nattribute vec3 direction; \n#endif\n#ifdef RAMPGRADIENT\nattribute vec4 remapData;\n#endif\nattribute vec2 offset;\n\nuniform mat4 view;\nuniform mat4 projection;\nuniform vec2 translationPivot;\n#ifdef ANIMATESHEET \nuniform vec3 particlesInfos; \n#endif\n\nvarying vec2 vUV;\nvarying vec4 vColor;\n#ifdef RAMPGRADIENT\nvarying vec4 remapRanges;\n#endif\n#if defined(CLIPPLANE) || defined(CLIPPLANE2) || defined(CLIPPLANE3) || defined(CLIPPLANE4)\nuniform mat4 invView;\n#endif\n#include\n#ifdef BILLBOARD\nuniform vec3 eyePosition; \n#endif\nvec3 rotate(vec3 yaxis,vec3 rotatedCorner) {\nvec3 xaxis=normalize(cross(vec3(0.,1.0,0.),yaxis));\nvec3 zaxis=normalize(cross(yaxis,xaxis));\nvec3 row0=vec3(xaxis.x,xaxis.y,xaxis.z);\nvec3 row1=vec3(yaxis.x,yaxis.y,yaxis.z);\nvec3 row2=vec3(zaxis.x,zaxis.y,zaxis.z);\nmat3 rotMatrix=mat3(row0,row1,row2);\nvec3 alignedCorner=rotMatrix*rotatedCorner;\nreturn position+alignedCorner; \n}\n#ifdef BILLBOARDSTRETCHED\nvec3 rotateAlign(vec3 toCamera,vec3 rotatedCorner) {\nvec3 normalizedToCamera=normalize(toCamera);\nvec3 normalizedCrossDirToCamera=normalize(cross(normalize(direction),normalizedToCamera));\nvec3 crossProduct=normalize(cross(normalizedToCamera,normalizedCrossDirToCamera));\nvec3 row0=vec3(normalizedCrossDirToCamera.x,normalizedCrossDirToCamera.y,normalizedCrossDirToCamera.z);\nvec3 row1=vec3(crossProduct.x,crossProduct.y,crossProduct.z);\nvec3 row2=vec3(normalizedToCamera.x,normalizedToCamera.y,normalizedToCamera.z);\nmat3 rotMatrix=mat3(row0,row1,row2);\nvec3 alignedCorner=rotMatrix*rotatedCorner;\nreturn position+alignedCorner; \n}\n#endif\nvoid main(void) { \nvec2 cornerPos;\ncornerPos=(vec2(offset.x-0.5,offset.y-0.5)-translationPivot)*size+translationPivot;\n#ifdef BILLBOARD \n\nvec3 rotatedCorner;\n#ifdef BILLBOARDY \nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);\nrotatedCorner.z=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);\nrotatedCorner.y=0.;\nvec3 yaxis=position-eyePosition;\nyaxis.y=0.;\nvec3 worldPos=rotate(normalize(yaxis),rotatedCorner);\nvec3 viewPos=(view*vec4(worldPos,1.0)).xyz; \n#elif defined(BILLBOARDSTRETCHED)\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);\nrotatedCorner.y=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);\nrotatedCorner.z=0.;\nvec3 toCamera=position-eyePosition; \nvec3 worldPos=rotateAlign(toCamera,rotatedCorner);\nvec3 viewPos=(view*vec4(worldPos,1.0)).xyz; \n#else\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);\nrotatedCorner.y=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);\nrotatedCorner.z=0.;\nvec3 viewPos=(view*vec4(position,1.0)).xyz+rotatedCorner; \n#endif\n#ifdef RAMPGRADIENT\nremapRanges=remapData;\n#endif\n\ngl_Position=projection*vec4(viewPos,1.0); \n#else\n\nvec3 rotatedCorner;\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);\nrotatedCorner.z=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);\nrotatedCorner.y=0.;\nvec3 yaxis=normalize(direction);\nvec3 worldPos=rotate(yaxis,rotatedCorner);\ngl_Position=projection*view*vec4(worldPos,1.0); \n#endif \nvColor=color;\n#ifdef ANIMATESHEET\nfloat rowOffset=floor(cellIndex/particlesInfos.z);\nfloat columnOffset=cellIndex-rowOffset*particlesInfos.z;\nvec2 uvScale=particlesInfos.xy;\nvec2 uvOffset=vec2(offset.x ,1.0-offset.y);\nvUV=(uvOffset+vec2(columnOffset,rowOffset))*uvScale;\n#else\nvUV=offset;\n#endif\n\n#if defined(CLIPPLANE) || defined(CLIPPLANE2) || defined(CLIPPLANE3) || defined(CLIPPLANE4)\nvec4 worldPos=invView*vec4(viewPos,1.0);\n#endif\n#include\n}",particlesPixelShader:"\nvarying vec2 vUV;\nvarying vec4 vColor;\nuniform vec4 textureMask;\nuniform sampler2D diffuseSampler;\n#include\n#include\n#include\n#include\n#ifdef RAMPGRADIENT\nvarying vec4 remapRanges;\nuniform sampler2D rampSampler;\n#endif\nvoid main(void) {\n#include\nvec4 textureColor=texture2D(diffuseSampler,vUV);\nvec4 baseColor=(textureColor*textureMask+(vec4(1.,1.,1.,1.)-textureMask))*vColor;\n#ifdef RAMPGRADIENT\nfloat alpha=baseColor.a;\nfloat remappedColorIndex=clamp((alpha-remapRanges.x)/remapRanges.y,0.0,1.0);\nvec4 rampColor=texture2D(rampSampler,vec2(1.0-remappedColorIndex,0.));\nbaseColor.rgb*=rampColor.rgb;\n\nfloat finalAlpha=baseColor.a;\nbaseColor.a=clamp((alpha*rampColor.a-remapRanges.z)/remapRanges.w,0.0,1.0);\n#endif\n#ifdef BLENDMULTIPLYMODE\nfloat sourceAlpha=vColor.a*textureColor.a;\nbaseColor.rgb=baseColor.rgb*sourceAlpha+vec3(1.0)*(1.0-sourceAlpha);\n#endif\n\n\n#ifdef IMAGEPROCESSINGPOSTPROCESS\nbaseColor.rgb=toLinearSpace(baseColor.rgb);\n#else\n#ifdef IMAGEPROCESSING\nbaseColor.rgb=toLinearSpace(baseColor.rgb);\nbaseColor=applyImageProcessing(baseColor);\n#endif\n#endif\ngl_FragColor=baseColor;\n}",colorVertexShader:"\nattribute vec3 position;\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include\n\n#include\nuniform mat4 viewProjection;\n\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\nvoid main(void) {\n#include\n#include\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#ifdef VERTEXCOLOR\n\nvColor=color;\n#endif\n}",colorPixelShader:"#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#else\nuniform vec4 color;\n#endif\nvoid main(void) {\n#ifdef VERTEXCOLOR\ngl_FragColor=vColor;\n#else\ngl_FragColor=color;\n#endif\n}",gpuRenderParticlesVertexShader:"#version 300 es\nuniform mat4 view;\nuniform mat4 projection;\nuniform vec2 translationPivot;\n\nin vec3 position;\nin float age;\nin float life;\nin vec3 size;\n#ifndef BILLBOARD\nin vec3 initialDirection;\n#endif\n#ifdef BILLBOARDSTRETCHED\nin vec3 direction;\n#endif\nin float angle;\n#ifdef ANIMATESHEET\nin float cellIndex;\n#endif\nin vec2 offset;\nin vec2 uv;\nout vec2 vUV;\nout vec4 vColor;\n#if defined(CLIPPLANE) || defined(CLIPPLANE2) || defined(CLIPPLANE3) || defined(CLIPPLANE4)\nuniform mat4 invView;\n#endif\n#include\n#ifdef COLORGRADIENTS\nuniform sampler2D colorGradientSampler;\n#else\nuniform vec4 colorDead;\nin vec4 color;\n#endif\n#ifdef ANIMATESHEET\nuniform vec3 sheetInfos;\n#endif\n#ifdef BILLBOARD\nuniform vec3 eyePosition; \n#endif\nvec3 rotate(vec3 yaxis,vec3 rotatedCorner) {\nvec3 xaxis=normalize(cross(vec3(0.,1.0,0.),yaxis));\nvec3 zaxis=normalize(cross(yaxis,xaxis));\nvec3 row0=vec3(xaxis.x,xaxis.y,xaxis.z);\nvec3 row1=vec3(yaxis.x,yaxis.y,yaxis.z);\nvec3 row2=vec3(zaxis.x,zaxis.y,zaxis.z);\nmat3 rotMatrix=mat3(row0,row1,row2);\nvec3 alignedCorner=rotMatrix*rotatedCorner;\nreturn position+alignedCorner;\n}\n#ifdef BILLBOARDSTRETCHED\nvec3 rotateAlign(vec3 toCamera,vec3 rotatedCorner) {\nvec3 normalizedToCamera=normalize(toCamera);\nvec3 normalizedCrossDirToCamera=normalize(cross(normalize(direction),normalizedToCamera));\nvec3 crossProduct=normalize(cross(normalizedToCamera,normalizedCrossDirToCamera));\nvec3 row0=vec3(normalizedCrossDirToCamera.x,normalizedCrossDirToCamera.y,normalizedCrossDirToCamera.z);\nvec3 row1=vec3(crossProduct.x,crossProduct.y,crossProduct.z);\nvec3 row2=vec3(normalizedToCamera.x,normalizedToCamera.y,normalizedToCamera.z);\nmat3 rotMatrix=mat3(row0,row1,row2);\nvec3 alignedCorner=rotMatrix*rotatedCorner;\nreturn position+alignedCorner; \n}\n#endif\nvoid main() {\n#ifdef ANIMATESHEET\nfloat rowOffset=floor(cellIndex/sheetInfos.z);\nfloat columnOffset=cellIndex-rowOffset*sheetInfos.z;\nvec2 uvScale=sheetInfos.xy;\nvec2 uvOffset=vec2(uv.x ,1.0-uv.y);\nvUV=(uvOffset+vec2(columnOffset,rowOffset))*uvScale;\n#else \nvUV=uv;\n#endif\nfloat ratio=age/life;\n#ifdef COLORGRADIENTS\nvColor=texture(colorGradientSampler,vec2(ratio,0));\n#else\nvColor=color*vec4(1.0-ratio)+colorDead*vec4(ratio);\n#endif\nvec2 cornerPos=(offset-translationPivot)*size.yz*size.x+translationPivot;\n#ifdef BILLBOARD\nvec4 rotatedCorner;\nrotatedCorner.w=0.;\n#ifdef BILLBOARDY \nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);\nrotatedCorner.z=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);\nrotatedCorner.y=0.;\nvec3 yaxis=position-eyePosition;\nyaxis.y=0.;\nvec3 worldPos=rotate(normalize(yaxis),rotatedCorner.xyz);\nvec4 viewPosition=(view*vec4(worldPos,1.0)); \n#elif defined(BILLBOARDSTRETCHED)\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);\nrotatedCorner.y=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);\nrotatedCorner.z=0.;\nvec3 toCamera=position-eyePosition; \nvec3 worldPos=rotateAlign(toCamera,rotatedCorner.xyz);\nvec4 viewPosition=(view*vec4(worldPos,1.0)); \n#else\n\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);\nrotatedCorner.y=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);\nrotatedCorner.z=0.;\n\nvec4 viewPosition=view*vec4(position,1.0)+rotatedCorner;\n#endif\n#else\n\nvec3 rotatedCorner;\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);\nrotatedCorner.y=0.;\nrotatedCorner.z=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);\nvec3 yaxis=normalize(initialDirection);\nvec3 worldPos=rotate(yaxis,rotatedCorner);\n\nvec4 viewPosition=view*vec4(worldPos,1.0); \n#endif\ngl_Position=projection*viewPosition;\n\n#if defined(CLIPPLANE) || defined(CLIPPLANE2) || defined(CLIPPLANE3) || defined(CLIPPLANE4)\nvec4 worldPos=invView*viewPosition;\n#endif \n#include\n}",gpuRenderParticlesPixelShader:"#version 300 es\nuniform sampler2D textureSampler;\nin vec2 vUV;\nin vec4 vColor;\nout vec4 outFragColor;\n#include \n#include\n#include\n#include\nvoid main() {\n#include \nvec4 textureColor=texture(textureSampler,vUV);\noutFragColor=textureColor*vColor;\n#ifdef BLENDMULTIPLYMODE\nfloat alpha=vColor.a*textureColor.a;\noutFragColor.rgb=outFragColor.rgb*alpha+vec3(1.0)*(1.0-alpha); \n#endif \n\n\n#ifdef IMAGEPROCESSINGPOSTPROCESS\noutFragColor.rgb=toLinearSpace(outFragColor.rgb);\n#else\n#ifdef IMAGEPROCESSING\noutFragColor.rgb=toLinearSpace(outFragColor.rgb);\noutFragColor=applyImageProcessing(outFragColor);\n#endif\n#endif\n}\n",gpuUpdateParticlesVertexShader:"#version 300 es\n#define PI 3.14159\nuniform float currentCount;\nuniform float timeDelta;\nuniform float stopFactor;\nuniform mat4 emitterWM;\nuniform vec2 lifeTime;\nuniform vec2 emitPower;\nuniform vec2 sizeRange;\nuniform vec4 scaleRange;\n#ifndef COLORGRADIENTS\nuniform vec4 color1;\nuniform vec4 color2;\n#endif\nuniform vec3 gravity;\nuniform sampler2D randomSampler;\nuniform sampler2D randomSampler2;\nuniform vec4 angleRange;\n#ifdef BOXEMITTER\nuniform vec3 direction1;\nuniform vec3 direction2;\nuniform vec3 minEmitBox;\nuniform vec3 maxEmitBox;\n#endif\n#ifdef POINTEMITTER\nuniform vec3 direction1;\nuniform vec3 direction2;\n#endif\n#ifdef HEMISPHERICEMITTER\nuniform float radius;\nuniform float radiusRange;\nuniform float directionRandomizer;\n#endif\n#ifdef SPHEREEMITTER\nuniform float radius;\nuniform float radiusRange;\n#ifdef DIRECTEDSPHEREEMITTER\nuniform vec3 direction1;\nuniform vec3 direction2;\n#else\nuniform float directionRandomizer;\n#endif\n#endif\n#ifdef CYLINDEREMITTER\nuniform float radius;\nuniform float height;\nuniform float radiusRange;\n#ifdef DIRECTEDCYLINDEREMITTER\nuniform vec3 direction1;\nuniform vec3 direction2;\n#else\nuniform float directionRandomizer;\n#endif\n#endif\n#ifdef CONEEMITTER\nuniform vec2 radius;\nuniform float coneAngle;\nuniform vec2 height;\nuniform float directionRandomizer;\n#endif\n\nin vec3 position;\nin float age;\nin float life;\nin vec4 seed;\nin vec3 size;\n#ifndef COLORGRADIENTS\nin vec4 color;\n#endif\nin vec3 direction;\n#ifndef BILLBOARD\nin vec3 initialDirection;\n#endif\n#ifdef ANGULARSPEEDGRADIENTS\nin float angle;\n#else\nin vec2 angle;\n#endif\n#ifdef ANIMATESHEET\nin float cellIndex;\n#ifdef ANIMATESHEETRANDOMSTART\nin float cellStartOffset;\n#endif\n#endif\n#ifdef NOISE\nin vec3 noiseCoordinates1;\nin vec3 noiseCoordinates2;\n#endif\n\nout vec3 outPosition;\nout float outAge;\nout float outLife;\nout vec4 outSeed;\nout vec3 outSize;\n#ifndef COLORGRADIENTS\nout vec4 outColor;\n#endif\nout vec3 outDirection;\n#ifndef BILLBOARD\nout vec3 outInitialDirection;\n#endif\n#ifdef ANGULARSPEEDGRADIENTS\nout float outAngle;\n#else\nout vec2 outAngle;\n#endif\n#ifdef ANIMATESHEET\nout float outCellIndex;\n#ifdef ANIMATESHEETRANDOMSTART\nout float outCellStartOffset;\n#endif\n#endif\n#ifdef NOISE\nout vec3 outNoiseCoordinates1;\nout vec3 outNoiseCoordinates2;\n#endif\n#ifdef SIZEGRADIENTS\nuniform sampler2D sizeGradientSampler;\n#endif \n#ifdef ANGULARSPEEDGRADIENTS\nuniform sampler2D angularSpeedGradientSampler;\n#endif \n#ifdef VELOCITYGRADIENTS\nuniform sampler2D velocityGradientSampler;\n#endif\n#ifdef LIMITVELOCITYGRADIENTS\nuniform sampler2D limitVelocityGradientSampler;\nuniform float limitVelocityDamping;\n#endif\n#ifdef DRAGGRADIENTS\nuniform sampler2D dragGradientSampler;\n#endif\n#ifdef NOISE\nuniform vec3 noiseStrength;\nuniform sampler2D noiseSampler;\n#endif\n#ifdef ANIMATESHEET\nuniform vec3 cellInfos;\n#endif\nvec3 getRandomVec3(float offset) {\nreturn texture(randomSampler2,vec2(float(gl_VertexID)*offset/currentCount,0)).rgb;\n}\nvec4 getRandomVec4(float offset) {\nreturn texture(randomSampler,vec2(float(gl_VertexID)*offset/currentCount,0));\n}\nvoid main() {\nfloat newAge=age+timeDelta; \n\nif (newAge>=life && stopFactor != 0.) {\nvec3 position;\nvec3 direction;\n\nvec4 randoms=getRandomVec4(seed.x);\n\noutLife=lifeTime.x+(lifeTime.y-lifeTime.x)*randoms.r;\noutAge=mod(newAge,outLife);\n\noutSeed=seed;\n\n#ifdef SIZEGRADIENTS \noutSize.x=texture(sizeGradientSampler,vec2(0,0)).r;\n#else\noutSize.x=sizeRange.x+(sizeRange.y-sizeRange.x)*randoms.g;\n#endif\noutSize.y=scaleRange.x+(scaleRange.y-scaleRange.x)*randoms.b;\noutSize.z=scaleRange.z+(scaleRange.w-scaleRange.z)*randoms.a; \n#ifndef COLORGRADIENTS\n\noutColor=color1+(color2-color1)*randoms.b;\n#endif\n\n#ifndef ANGULARSPEEDGRADIENTS \noutAngle.y=angleRange.x+(angleRange.y-angleRange.x)*randoms.a;\noutAngle.x=angleRange.z+(angleRange.w-angleRange.z)*randoms.r;\n#else\noutAngle=angleRange.z+(angleRange.w-angleRange.z)*randoms.r;\n#endif \n\n#ifdef POINTEMITTER\nvec3 randoms2=getRandomVec3(seed.y);\nvec3 randoms3=getRandomVec3(seed.z);\nposition=vec3(0,0,0);\ndirection=direction1+(direction2-direction1)*randoms3;\n#elif defined(BOXEMITTER)\nvec3 randoms2=getRandomVec3(seed.y);\nvec3 randoms3=getRandomVec3(seed.z);\nposition=minEmitBox+(maxEmitBox-minEmitBox)*randoms2;\ndirection=direction1+(direction2-direction1)*randoms3; \n#elif defined(HEMISPHERICEMITTER)\nvec3 randoms2=getRandomVec3(seed.y);\nvec3 randoms3=getRandomVec3(seed.z);\n\nfloat phi=2.0*PI*randoms2.x;\nfloat theta=acos(2.0*randoms2.y-1.0);\nfloat randX=cos(phi)*sin(theta);\nfloat randY=cos(theta);\nfloat randZ=sin(phi)*sin(theta);\nposition=(radius-(radius*radiusRange*randoms2.z))*vec3(randX,abs(randY),randZ);\ndirection=position+directionRandomizer*randoms3; \n#elif defined(SPHEREEMITTER)\nvec3 randoms2=getRandomVec3(seed.y);\nvec3 randoms3=getRandomVec3(seed.z);\n\nfloat phi=2.0*PI*randoms2.x;\nfloat theta=acos(2.0*randoms2.y-1.0);\nfloat randX=cos(phi)*sin(theta);\nfloat randY=cos(theta);\nfloat randZ=sin(phi)*sin(theta);\nposition=(radius-(radius*radiusRange*randoms2.z))*vec3(randX,randY,randZ);\n#ifdef DIRECTEDSPHEREEMITTER\ndirection=direction1+(direction2-direction1)*randoms3;\n#else\n\ndirection=position+directionRandomizer*randoms3;\n#endif\n#elif defined(CYLINDEREMITTER)\nvec3 randoms2=getRandomVec3(seed.y);\nvec3 randoms3=getRandomVec3(seed.z);\n\nfloat yPos=(randoms2.x-0.5)*height;\nfloat angle=randoms2.y*PI*2.;\nfloat inverseRadiusRangeSquared=((1.-radiusRange)*(1.-radiusRange));\nfloat positionRadius=radius*sqrt(inverseRadiusRangeSquared+(randoms2.z*(1.-inverseRadiusRangeSquared)));\nfloat xPos=positionRadius*cos(angle);\nfloat zPos=positionRadius*sin(angle);\nposition=vec3(xPos,yPos,zPos);\n#ifdef DIRECTEDCYLINDEREMITTER\ndirection=direction1+(direction2-direction1)*randoms3;\n#else\n\nangle=angle+((randoms3.x-0.5)*PI);\ndirection=vec3(cos(angle),randoms3.y-0.5,sin(angle));\ndirection=normalize(direction);\n#endif\n#elif defined(CONEEMITTER)\nvec3 randoms2=getRandomVec3(seed.y);\nfloat s=2.0*PI*randoms2.x;\n#ifdef CONEEMITTERSPAWNPOINT\nfloat h=0.00001;\n#else\nfloat h=randoms2.y*height.y;\n\nh=1.-h*h; \n#endif\nfloat lRadius=radius.x-radius.x*randoms2.z*radius.y;\nlRadius=lRadius*h;\nfloat randX=lRadius*sin(s);\nfloat randZ=lRadius*cos(s);\nfloat randY=h*height.x;\nposition=vec3(randX,randY,randZ); \n\nif (abs(cos(coneAngle)) == 1.0) {\ndirection=vec3(0.,1.0,0.);\n} else {\nvec3 randoms3=getRandomVec3(seed.z);\ndirection=position+directionRandomizer*randoms3;\n}\n#else \n\nposition=vec3(0.,0.,0.);\n\ndirection=2.0*(getRandomVec3(seed.w)-vec3(0.5,0.5,0.5));\n#endif\nfloat power=emitPower.x+(emitPower.y-emitPower.x)*randoms.a;\noutPosition=(emitterWM*vec4(position,1.)).xyz;\nvec3 initial=(emitterWM*vec4(direction,0.)).xyz;\noutDirection=initial*power;\n#ifndef BILLBOARD \noutInitialDirection=initial;\n#endif\n#ifdef ANIMATESHEET \noutCellIndex=cellInfos.x;\n#ifdef ANIMATESHEETRANDOMSTART\noutCellStartOffset=randoms.a*outLife;\n#endif \n#endif\n#ifdef NOISE\noutNoiseCoordinates1=noiseCoordinates1;\noutNoiseCoordinates2=noiseCoordinates2;\n#endif\n} else {\nfloat directionScale=timeDelta;\noutAge=newAge;\nfloat ageGradient=newAge/life;\n#ifdef VELOCITYGRADIENTS\ndirectionScale*=texture(velocityGradientSampler,vec2(ageGradient,0)).r;\n#endif\n#ifdef DRAGGRADIENTS\ndirectionScale*=1.0-texture(dragGradientSampler,vec2(ageGradient,0)).r;\n#endif\noutPosition=position+direction*directionScale;\noutLife=life;\noutSeed=seed;\n#ifndef COLORGRADIENTS \noutColor=color;\n#endif\n#ifdef SIZEGRADIENTS\noutSize.x=texture(sizeGradientSampler,vec2(ageGradient,0)).r;\noutSize.yz=size.yz;\n#else\noutSize=size;\n#endif \n#ifndef BILLBOARD \noutInitialDirection=initialDirection;\n#endif\nvec3 updatedDirection=direction+gravity*timeDelta;\n#ifdef LIMITVELOCITYGRADIENTS\nfloat limitVelocity=texture(limitVelocityGradientSampler,vec2(ageGradient,0)).r;\nfloat currentVelocity=length(updatedDirection);\nif (currentVelocity>limitVelocity) {\nupdatedDirection=updatedDirection*limitVelocityDamping;\n}\n#endif\noutDirection=updatedDirection;\n#ifdef NOISE\nvec3 localPosition=outPosition-emitterWM[3].xyz;\nfloat fetchedR=texture(noiseSampler,vec2(noiseCoordinates1.x,noiseCoordinates1.y)*vec2(0.5)+vec2(0.5)).r;\nfloat fetchedG=texture(noiseSampler,vec2(noiseCoordinates1.z,noiseCoordinates2.x)*vec2(0.5)+vec2(0.5)).r;\nfloat fetchedB=texture(noiseSampler,vec2(noiseCoordinates2.y,noiseCoordinates2.z)*vec2(0.5)+vec2(0.5)).r;\nvec3 force=vec3(2.*fetchedR-1.,2.*fetchedG-1.,2.*fetchedB-1.)*noiseStrength;\noutDirection=outDirection+force*timeDelta;\noutNoiseCoordinates1=noiseCoordinates1;\noutNoiseCoordinates2=noiseCoordinates2;\n#endif \n#ifdef ANGULARSPEEDGRADIENTS\nfloat angularSpeed=texture(angularSpeedGradientSampler,vec2(ageGradient,0)).r;\noutAngle=angle+angularSpeed*timeDelta;\n#else\noutAngle=vec2(angle.x+angle.y*timeDelta,angle.y);\n#endif\n#ifdef ANIMATESHEET \nfloat offsetAge=outAge;\nfloat dist=cellInfos.y-cellInfos.x;\n#ifdef ANIMATESHEETRANDOMSTART\noutCellStartOffset=cellStartOffset;\noffsetAge+=cellStartOffset;\n#endif \nfloat ratio=clamp(mod(offsetAge*cellInfos.z,life)/life,0.,1.0);\noutCellIndex=float(int(cellInfos.x+ratio*dist));\n#endif\n}\n}",gpuUpdateParticlesPixelShader:"#version 300 es\nvoid main() {\ndiscard;\n}\n",postprocessVertexShader:"\nattribute vec2 position;\nuniform vec2 scale;\n\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvUV=(position*madd+madd)*scale;\ngl_Position=vec4(position,0.0,1.0);\n}",passPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nvoid main(void) \n{\ngl_FragColor=texture2D(textureSampler,vUV);\n}",shadowMapVertexShader:"\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\nuniform vec3 lightData;\n#endif\n#include\n#include\n#include[0..maxSimultaneousMorphTargets]\n\n#include\n#include\nuniform mat4 viewProjection;\nuniform vec3 biasAndScale;\nuniform vec2 depthValues;\nvarying float vDepthMetric;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\nvoid main(void)\n{\nvec3 positionUpdated=position;\n#include[0..maxSimultaneousMorphTargets]\n#include\n#include\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\n\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvec3 worldNor=normalize(normalWorld*normal);\n#ifdef DIRECTIONINLIGHTDATA\nvec3 worldLightDir=normalize(-lightData.xyz);\n#else\nvec3 directionToLight=lightData.xyz-worldPos.xyz;\nvec3 worldLightDir=normalize(directionToLight);\n#endif\nfloat ndl=dot(worldNor,worldLightDir);\nfloat sinNL=sqrt(1.0-ndl*ndl);\nfloat normalBias=biasAndScale.y*sinNL;\nworldPos.xyz-=worldNor*normalBias;\n#endif\n\ngl_Position=viewProjection*worldPos;\n#ifdef DEPTHTEXTURE\n\ngl_Position.z+=biasAndScale.x*gl_Position.w;\n#endif\n\nvDepthMetric=((gl_Position.z+depthValues.x)/(depthValues.y))+biasAndScale.x;\n#ifdef ALPHATEST\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}",shadowMapPixelShader:"#ifndef FLOAT\nvec4 pack(float depth)\n{\nconst vec4 bit_shift=vec4(255.0*255.0*255.0,255.0*255.0,255.0,1.0);\nconst vec4 bit_mask=vec4(0.0,1.0/255.0,1.0/255.0,1.0/255.0);\nvec4 res=fract(depth*bit_shift);\nres-=res.xxyz*bit_mask;\nreturn res;\n}\n#endif\nvarying float vDepthMetric;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\nuniform vec3 biasAndScale;\nuniform vec2 depthValues;\nvoid main(void)\n{\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\nfloat depth=vDepthMetric;\n#ifdef ESM\ndepth=clamp(exp(-min(87.,biasAndScale.z*depth)),0.,1.);\n#endif\n#ifdef FLOAT\ngl_FragColor=vec4(depth,1.0,1.0,1.0);\n#else\ngl_FragColor=pack(depth);\n#endif\n}",depthBoxBlurPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec2 screenSize;\nvoid main(void)\n{\nvec4 colorDepth=vec4(0.0);\nfor (int x=-OFFSET; x<=OFFSET; x++)\nfor (int y=-OFFSET; y<=OFFSET; y++)\ncolorDepth+=texture2D(textureSampler,vUV+vec2(x,y)/screenSize);\ngl_FragColor=(colorDepth/float((OFFSET*2+1)*(OFFSET*2+1)));\n}",proceduralVertexShader:"\nattribute vec2 position;\n\nvarying vec2 vPosition;\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvPosition=position;\nvUV=position*madd+madd;\ngl_Position=vec4(position,0.0,1.0);\n}",depthVertexShader:"\nattribute vec3 position;\n#include\n\n#include\nuniform mat4 viewProjection;\nuniform vec2 depthValues;\n#if defined(ALPHATEST) || defined(NEED_UV)\nvarying vec2 vUV;\nuniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\nvarying float vDepthMetric;\nvoid main(void)\n{\n#include\n#include\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvDepthMetric=((gl_Position.z+depthValues.x)/(depthValues.y));\n#if defined(ALPHATEST) || defined(BASIC_RENDER)\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}",depthPixelShader:"#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\nvarying float vDepthMetric;\nvoid main(void)\n{\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\ngl_FragColor=vec4(vDepthMetric,vDepthMetric*vDepthMetric,0.0,1.0);\n}",geometryVertexShader:"precision highp float;\nprecision highp int;\n#include\n#include\nattribute vec3 position;\nattribute vec3 normal;\n#if defined(ALPHATEST) || defined(NEED_UV)\nvarying vec2 vUV;\nuniform mat4 diffuseMatrix;\n#ifdef UV1\nvarying vec2 uv;\n#endif\n#ifdef UV2\nvarying vec2 uv2;\n#endif\n#endif\n\nuniform mat4 viewProjection;\nuniform mat4 view;\nvarying vec3 vNormalV;\nvarying vec4 vViewPos;\n#ifdef POSITION\nvarying vec3 vPosition;\n#endif\nvoid main(void)\n{\n#include\n#include\nvec4 pos=vec4(finalWorld*vec4(position,1.0));\nvNormalV=normalize(vec3((view*finalWorld)*vec4(normal,0.0)));\nvViewPos=view*pos;\n#ifdef POSITION\nvPosition=pos.xyz/pos.w;\n#endif\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#if defined(ALPHATEST) || defined(BASIC_RENDER)\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}",geometryPixelShader:"#extension GL_EXT_draw_buffers : require\nprecision highp float;\nprecision highp int;\nvarying vec3 vNormalV;\nvarying vec4 vViewPos;\n#ifdef POSITION\nvarying vec3 vPosition;\n#endif\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef POSITION\n#include[3]\n#else\n#include[2]\n#endif\nvoid main() {\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\ngl_FragData[0]=vec4(vViewPos.z/vViewPos.w,0.0,0.0,1.0);\n\ngl_FragData[1]=vec4(normalize(vNormalV),1.0);\n\n#ifdef POSITION\ngl_FragData[2]=vec4(vPosition,1.0);\n#endif\n}",ssaoPixelShader:"\nuniform sampler2D textureSampler;\nvarying vec2 vUV;\n#ifdef SSAO\nuniform sampler2D randomSampler;\nuniform float randTextureTiles;\nuniform float samplesFactor;\nuniform vec3 sampleSphere[SAMPLES];\nuniform float totalStrength;\nuniform float radius;\nuniform float area;\nuniform float fallOff;\nuniform float base;\nvec3 normalFromDepth(float depth,vec2 coords)\n{\nvec2 offset1=vec2(0.0,radius);\nvec2 offset2=vec2(radius,0.0);\nfloat depth1=texture2D(textureSampler,coords+offset1).r;\nfloat depth2=texture2D(textureSampler,coords+offset2).r;\nvec3 p1=vec3(offset1,depth1-depth);\nvec3 p2=vec3(offset2,depth2-depth);\nvec3 normal=cross(p1,p2);\nnormal.z=-normal.z;\nreturn normalize(normal);\n}\nvoid main()\n{\nvec3 random=normalize(texture2D(randomSampler,vUV*randTextureTiles).rgb);\nfloat depth=texture2D(textureSampler,vUV).r;\nvec3 position=vec3(vUV,depth);\nvec3 normal=normalFromDepth(depth,vUV);\nfloat radiusDepth=radius/depth;\nfloat occlusion=0.0;\nvec3 ray;\nvec3 hemiRay;\nfloat occlusionDepth;\nfloat difference;\nfor (int i=0; i1e-2 ? rvec : vec3(-rvec.y,0.0,rvec.x);\nvec3 tangent=normalize(rvec-normal*dot(rvec,normal));\nvec3 bitangent=cross(normal,tangent);\nmat3 tbn=mat3(tangent,bitangent,normal);\nfloat difference;\nfor (int i=0; i1.0 || offset.y>1.0) {\ncontinue;\n}\n\nfloat sampleDepth=abs(texture2D(textureSampler,offset.xy).r);\n\ndifference=depthSign*samplePosition.z-sampleDepth;\nfloat rangeCheck=1.0-smoothstep(correctedRadius*0.5,correctedRadius,difference);\nocclusion+=(difference>=0.0 ? 1.0 : 0.0)*rangeCheck;\n}\nocclusion=occlusion*(1.0-smoothstep(maxZ*0.75,maxZ,depth));\nfloat ao=1.0-totalStrength*occlusion*samplesFactor;\nfloat result=clamp(ao+base,0.0,1.0);\ngl_FragColor=vec4(vec3(result),1.0);\n}\n#endif\n#ifdef BILATERAL_BLUR\nuniform sampler2D depthSampler;\nuniform float outSize;\nuniform float samplerOffsets[SAMPLES];\nvec4 blur9(sampler2D image,vec2 uv,float resolution,vec2 direction) {\nvec4 color=vec4(0.0);\nvec2 off1=vec2(1.3846153846)*direction;\nvec2 off2=vec2(3.2307692308)*direction;\ncolor+=texture2D(image,uv)*0.2270270270;\ncolor+=texture2D(image,uv+(off1/resolution))*0.3162162162;\ncolor+=texture2D(image,uv-(off1/resolution))*0.3162162162;\ncolor+=texture2D(image,uv+(off2/resolution))*0.0702702703;\ncolor+=texture2D(image,uv-(off2/resolution))*0.0702702703;\nreturn color;\n}\nvec4 blur13(sampler2D image,vec2 uv,float resolution,vec2 direction) {\nvec4 color=vec4(0.0);\nvec2 off1=vec2(1.411764705882353)*direction;\nvec2 off2=vec2(3.2941176470588234)*direction;\nvec2 off3=vec2(5.176470588235294)*direction;\ncolor+=texture2D(image,uv)*0.1964825501511404;\ncolor+=texture2D(image,uv+(off1/resolution))*0.2969069646728344;\ncolor+=texture2D(image,uv-(off1/resolution))*0.2969069646728344;\ncolor+=texture2D(image,uv+(off2/resolution))*0.09447039785044732;\ncolor+=texture2D(image,uv-(off2/resolution))*0.09447039785044732;\ncolor+=texture2D(image,uv+(off3/resolution))*0.010381362401148057;\ncolor+=texture2D(image,uv-(off3/resolution))*0.010381362401148057;\nreturn color;\n}\nvec4 blur13Bilateral(sampler2D image,vec2 uv,float resolution,vec2 direction) {\nvec4 color=vec4(0.0);\nvec2 off1=vec2(1.411764705882353)*direction;\nvec2 off2=vec2(3.2941176470588234)*direction;\nvec2 off3=vec2(5.176470588235294)*direction;\nfloat compareDepth=abs(texture2D(depthSampler,uv).r);\nfloat sampleDepth;\nfloat weight;\nfloat weightSum=30.0;\ncolor+=texture2D(image,uv)*30.0;\nsampleDepth=abs(texture2D(depthSampler,uv+(off1/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv+(off1/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv-(off1/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv-(off1/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv+(off2/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv+(off2/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv-(off2/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv-(off2/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv+(off3/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv+(off3/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv-(off3/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv-(off3/resolution))*weight;\nreturn color/weightSum;\n}\nvoid main()\n{\n#if EXPENSIVE\nfloat compareDepth=abs(texture2D(depthSampler,vUV).r);\nfloat texelsize=1.0/outSize;\nfloat result=0.0;\nfloat weightSum=0.0;\nfor (int i=0; i1.0) { lum_threshold=0.94+0.01*threshold; }\nelse { lum_threshold=0.5+0.44*threshold; }\nluminance=clamp((luminance-lum_threshold)*(1.0/(1.0-lum_threshold)),0.0,1.0);\nhighlight*=luminance*gain;\nhighlight.a=1.0;\nreturn highlight;\n}\nvoid main(void)\n{\nvec4 original=texture2D(textureSampler,vUV);\n\nif (gain == -1.0) {\ngl_FragColor=vec4(0.0,0.0,0.0,1.0);\nreturn;\n}\nfloat w=2.0/screen_width;\nfloat h=2.0/screen_height;\nfloat weight=1.0;\n\nvec4 blurred=vec4(0.0,0.0,0.0,0.0);\n#ifdef PENTAGON\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.84*w,0.43*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.48*w,-1.29*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.61*w,1.51*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.55*w,-0.74*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.71*w,-0.52*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.94*w,1.59*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.40*w,-1.87*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.62*w,1.16*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.09*w,0.25*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.46*w,-1.71*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.08*w,2.42*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.85*w,-1.89*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.89*w,0.16*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.29*w,1.88*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.40*w,-2.81*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.54*w,2.26*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.60*w,-0.61*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.31*w,-1.30*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.83*w,2.53*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.12*w,-2.48*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.60*w,1.11*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.82*w,0.99*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.50*w,-2.81*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.85*w,3.33*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.94*w,-1.92*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.27*w,-0.53*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.95*w,2.48*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.23*w,-3.04*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.17*w,2.05*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.97*w,-0.04*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.25*w,-2.00*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.31*w,3.08*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.94*w,-2.59*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.37*w,0.64*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-3.13*w,1.93*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.03*w,-3.65*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.60*w,3.17*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-3.14*w,-1.19*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.00*w,-1.19*h)));\n#else\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.85*w,0.36*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.52*w,-1.14*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.46*w,1.42*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.46*w,-0.83*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.79*w,-0.42*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.11*w,1.62*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.29*w,-2.07*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.69*w,1.39*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.28*w,0.12*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.65*w,-1.69*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.08*w,2.44*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.63*w,-1.90*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.55*w,0.31*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.13*w,1.52*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.56*w,-2.61*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.38*w,2.34*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.64*w,-0.81*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.53*w,-1.21*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.06*w,2.63*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.00*w,-2.69*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.59*w,1.32*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.82*w,0.78*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.57*w,-2.50*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.54*w,2.93*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.39*w,-1.81*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.01*w,-0.28*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.04*w,2.25*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.02*w,-3.05*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.09*w,2.25*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-3.07*w,-0.25*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.44*w,-1.90*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.52*w,3.05*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.68*w,-2.61*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.01*w,0.79*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.76*w,1.46*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.05*w,-2.94*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.21*w,2.88*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.84*w,-1.30*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.98*w,-0.96*h)));\n#endif\nblurred/=39.0;\ngl_FragColor=blurred;\n\n}",depthOfFieldPixelShader:"\n\n\n\n\nuniform sampler2D textureSampler;\nuniform sampler2D highlightsSampler;\nuniform sampler2D depthSampler;\nuniform sampler2D grainSampler;\n\nuniform float grain_amount;\nuniform bool blur_noise;\nuniform float screen_width;\nuniform float screen_height;\nuniform float distortion;\nuniform bool dof_enabled;\n\nuniform float screen_distance; \nuniform float aperture;\nuniform float darken;\nuniform float edge_blur;\nuniform bool highlights;\n\nuniform float near;\nuniform float far;\n\nvarying vec2 vUV;\n\n#define PI 3.14159265\n#define TWOPI 6.28318530\n#define inverse_focal_length 0.1 \n\nvec2 centered_screen_pos;\nvec2 distorted_coords;\nfloat radius2;\nfloat radius;\n\nvec2 rand(vec2 co)\n{\nfloat noise1=(fract(sin(dot(co,vec2(12.9898,78.233)))*43758.5453));\nfloat noise2=(fract(sin(dot(co,vec2(12.9898,78.233)*2.0))*43758.5453));\nreturn clamp(vec2(noise1,noise2),0.0,1.0);\n}\n\nvec2 getDistortedCoords(vec2 coords) {\nif (distortion == 0.0) { return coords; }\nvec2 direction=1.0*normalize(centered_screen_pos);\nvec2 dist_coords=vec2(0.5,0.5);\ndist_coords.x=0.5+direction.x*radius2*1.0;\ndist_coords.y=0.5+direction.y*radius2*1.0;\nfloat dist_amount=clamp(distortion*0.23,0.0,1.0);\ndist_coords=mix(coords,dist_coords,dist_amount);\nreturn dist_coords;\n}\n\nfloat sampleScreen(inout vec4 color,const in vec2 offset,const in float weight) {\n\nvec2 coords=distorted_coords;\nfloat angle=rand(coords*100.0).x*TWOPI;\ncoords+=vec2(offset.x*cos(angle)-offset.y*sin(angle),offset.x*sin(angle)+offset.y*cos(angle));\ncolor+=texture2D(textureSampler,coords)*weight;\nreturn weight;\n}\n\nfloat getBlurLevel(float size) {\nreturn min(3.0,ceil(size/1.0));\n}\n\nvec4 getBlurColor(float size) {\nvec4 col=texture2D(textureSampler,distorted_coords);\nif (size == 0.0) { return col; }\n\n\nfloat blur_level=getBlurLevel(size);\nfloat w=(size/screen_width);\nfloat h=(size/screen_height);\nfloat total_weight=1.0;\nvec2 sample_coords;\ntotal_weight+=sampleScreen(col,vec2(-0.50*w,0.24*h),0.93);\ntotal_weight+=sampleScreen(col,vec2(0.30*w,-0.75*h),0.90);\ntotal_weight+=sampleScreen(col,vec2(0.36*w,0.96*h),0.87);\ntotal_weight+=sampleScreen(col,vec2(-1.08*w,-0.55*h),0.85);\ntotal_weight+=sampleScreen(col,vec2(1.33*w,-0.37*h),0.83);\ntotal_weight+=sampleScreen(col,vec2(-0.82*w,1.31*h),0.80);\ntotal_weight+=sampleScreen(col,vec2(-0.31*w,-1.67*h),0.78);\ntotal_weight+=sampleScreen(col,vec2(1.47*w,1.11*h),0.76);\ntotal_weight+=sampleScreen(col,vec2(-1.97*w,0.19*h),0.74);\ntotal_weight+=sampleScreen(col,vec2(1.42*w,-1.57*h),0.72);\nif (blur_level>1.0) {\ntotal_weight+=sampleScreen(col,vec2(0.01*w,2.25*h),0.70);\ntotal_weight+=sampleScreen(col,vec2(-1.62*w,-1.74*h),0.67);\ntotal_weight+=sampleScreen(col,vec2(2.49*w,0.20*h),0.65);\ntotal_weight+=sampleScreen(col,vec2(-2.07*w,1.61*h),0.63);\ntotal_weight+=sampleScreen(col,vec2(0.46*w,-2.70*h),0.61);\ntotal_weight+=sampleScreen(col,vec2(1.55*w,2.40*h),0.59);\ntotal_weight+=sampleScreen(col,vec2(-2.88*w,-0.75*h),0.56);\ntotal_weight+=sampleScreen(col,vec2(2.73*w,-1.44*h),0.54);\ntotal_weight+=sampleScreen(col,vec2(-1.08*w,3.02*h),0.52);\ntotal_weight+=sampleScreen(col,vec2(-1.28*w,-3.05*h),0.49);\n}\nif (blur_level>2.0) {\ntotal_weight+=sampleScreen(col,vec2(3.11*w,1.43*h),0.46);\ntotal_weight+=sampleScreen(col,vec2(-3.36*w,1.08*h),0.44);\ntotal_weight+=sampleScreen(col,vec2(1.80*w,-3.16*h),0.41);\ntotal_weight+=sampleScreen(col,vec2(0.83*w,3.65*h),0.38);\ntotal_weight+=sampleScreen(col,vec2(-3.16*w,-2.19*h),0.34);\ntotal_weight+=sampleScreen(col,vec2(3.92*w,-0.53*h),0.31);\ntotal_weight+=sampleScreen(col,vec2(-2.59*w,3.12*h),0.26);\ntotal_weight+=sampleScreen(col,vec2(-0.20*w,-4.15*h),0.22);\ntotal_weight+=sampleScreen(col,vec2(3.02*w,3.00*h),0.15);\n}\ncol/=total_weight; \n\nif (darken>0.0) {\ncol.rgb*=clamp(0.3,1.0,1.05-size*0.5*darken);\n}\n\n\n\n\nreturn col;\n}\nvoid main(void)\n{\n\ncentered_screen_pos=vec2(vUV.x-0.5,vUV.y-0.5);\nradius2=centered_screen_pos.x*centered_screen_pos.x+centered_screen_pos.y*centered_screen_pos.y;\nradius=sqrt(radius2);\ndistorted_coords=getDistortedCoords(vUV); \nvec2 texels_coords=vec2(vUV.x*screen_width,vUV.y*screen_height); \nfloat depth=texture2D(depthSampler,distorted_coords).r; \nfloat distance=near+(far-near)*depth; \nvec4 color=texture2D(textureSampler,vUV); \n\n\nfloat coc=abs(aperture*(screen_distance*(inverse_focal_length-1.0/distance)-1.0));\n\nif (dof_enabled == false || coc<0.07) { coc=0.0; }\n\nfloat edge_blur_amount=0.0;\nif (edge_blur>0.0) {\nedge_blur_amount=clamp((radius*2.0-1.0+0.15*edge_blur)*1.5,0.0,1.0)*1.3;\n}\n\nfloat blur_amount=max(edge_blur_amount,coc);\n\nif (blur_amount == 0.0) {\ngl_FragColor=texture2D(textureSampler,distorted_coords);\n}\nelse {\n\ngl_FragColor=getBlurColor(blur_amount*1.7);\n\nif (highlights) {\ngl_FragColor.rgb+=clamp(coc,0.0,1.0)*texture2D(highlightsSampler,distorted_coords).rgb;\n}\nif (blur_noise) {\n\nvec2 noise=rand(distorted_coords)*0.01*blur_amount;\nvec2 blurred_coord=vec2(distorted_coords.x+noise.x,distorted_coords.y+noise.y);\ngl_FragColor=0.04*texture2D(textureSampler,blurred_coord)+0.96*gl_FragColor;\n}\n}\n\nif (grain_amount>0.0) {\nvec4 grain_color=texture2D(grainSampler,texels_coords*0.003);\ngl_FragColor.rgb+=(-0.5+grain_color.rgb)*0.30*grain_amount;\n}\n}\n",standardPixelShader:"uniform sampler2D textureSampler;\nvarying vec2 vUV;\n#if defined(PASS_POST_PROCESS)\nvoid main(void)\n{\nvec4 color=texture2D(textureSampler,vUV);\ngl_FragColor=color;\n}\n#endif\n#if defined(DOWN_SAMPLE_X4)\nuniform vec2 dsOffsets[16];\nvoid main(void)\n{\nvec4 average=vec4(0.0,0.0,0.0,0.0);\naverage=texture2D(textureSampler,vUV+dsOffsets[0]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[1]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[2]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[3]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[4]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[5]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[6]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[7]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[8]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[9]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[10]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[11]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[12]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[13]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[14]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[15]);\naverage/=16.0;\ngl_FragColor=average;\n}\n#endif\n#if defined(BRIGHT_PASS)\nuniform vec2 dsOffsets[4];\nuniform float brightThreshold;\nvoid main(void)\n{\nvec4 average=vec4(0.0,0.0,0.0,0.0);\naverage=texture2D(textureSampler,vUV+vec2(dsOffsets[0].x,dsOffsets[0].y));\naverage+=texture2D(textureSampler,vUV+vec2(dsOffsets[1].x,dsOffsets[1].y));\naverage+=texture2D(textureSampler,vUV+vec2(dsOffsets[2].x,dsOffsets[2].y));\naverage+=texture2D(textureSampler,vUV+vec2(dsOffsets[3].x,dsOffsets[3].y));\naverage*=0.25;\nfloat luminance=length(average.rgb);\nif (luminanceshadowPixelDepth)\naccumFog+=sunColor*computeScattering(dot(rayDirection,sunDirection));\ncurrentPosition+=stepL;\n}\naccumFog/=NB_STEPS;\nvec3 color=accumFog*scatteringPower;\ngl_FragColor=vec4(color*exp(color) ,1.0);\n}\n#endif\n#if defined(VLSMERGE)\nuniform sampler2D originalSampler;\nvoid main(void)\n{\ngl_FragColor=texture2D(originalSampler,vUV)+texture2D(textureSampler,vUV);\n}\n#endif\n#if defined(LUMINANCE)\nuniform vec2 lumOffsets[4];\nvoid main()\n{\nfloat average=0.0;\nvec4 color=vec4(0.0);\nfloat maximum=-1e20;\nvec3 weight=vec3(0.299,0.587,0.114);\nfor (int i=0; i<4; i++)\n{\ncolor=texture2D(textureSampler,vUV+ lumOffsets[i]);\n\nfloat GreyValue=dot(color.rgb,vec3(0.33,0.33,0.33));\n\n#ifdef WEIGHTED_AVERAGE\nfloat GreyValue=dot(color.rgb,weight);\n#endif\n#ifdef BRIGHTNESS\nfloat GreyValue=max(color.r,max(color.g,color.b));\n#endif\n#ifdef HSL_COMPONENT\nfloat GreyValue=0.5*(max(color.r,max(color.g,color.b))+min(color.r,min(color.g,color.b)));\n#endif\n#ifdef MAGNITUDE\nfloat GreyValue=length(color.rgb);\n#endif\nmaximum=max(maximum,GreyValue);\naverage+=(0.25*log(1e-5+GreyValue));\n}\naverage=exp(average);\ngl_FragColor=vec4(average,maximum,0.0,1.0);\n}\n#endif\n#if defined(LUMINANCE_DOWN_SAMPLE)\nuniform vec2 dsOffsets[9];\nuniform float halfDestPixelSize;\n#ifdef FINAL_DOWN_SAMPLER\nvec4 pack(float value) {\nconst vec4 bit_shift=vec4(255.0*255.0*255.0,255.0*255.0,255.0,1.0);\nconst vec4 bit_mask=vec4(0.0,1.0/255.0,1.0/255.0,1.0/255.0);\nvec4 res=fract(value*bit_shift);\nres-=res.xxyz*bit_mask;\nreturn res;\n}\n#endif\nvoid main()\n{\nvec4 color=vec4(0.0);\nfloat average=0.0;\nfor (int i=0; i<9; i++)\n{\ncolor=texture2D(textureSampler,vUV+vec2(halfDestPixelSize,halfDestPixelSize)+dsOffsets[i]);\naverage+=color.r;\n}\naverage/=9.0;\n#ifdef FINAL_DOWN_SAMPLER\ngl_FragColor=pack(average);\n#else\ngl_FragColor=vec4(average,average,0.0,1.0);\n#endif\n}\n#endif\n#if defined(HDR)\nuniform sampler2D textureAdderSampler;\nuniform float averageLuminance;\nvoid main()\n{\nvec4 color=texture2D(textureAdderSampler,vUV);\nvec4 adjustedColor=color/averageLuminance;\ncolor=adjustedColor;\ncolor.a=1.0;\ngl_FragColor=color;\n}\n#endif\n#if defined(LENS_FLARE)\n#define GHOSTS 3\nuniform sampler2D lensColorSampler;\nuniform float strength;\nuniform float ghostDispersal;\nuniform float haloWidth;\nuniform vec2 resolution;\nuniform float distortionStrength;\nfloat hash(vec2 p)\n{\nfloat h=dot(p,vec2(127.1,311.7));\nreturn -1.0+2.0*fract(sin(h)*43758.5453123);\n}\nfloat noise(in vec2 p)\n{\nvec2 i=floor(p);\nvec2 f=fract(p);\nvec2 u=f*f*(3.0-2.0*f);\nreturn mix(mix(hash(i+vec2(0.0,0.0)),\nhash(i+vec2(1.0,0.0)),u.x),\nmix(hash(i+vec2(0.0,1.0)),\nhash(i+vec2(1.0,1.0)),u.x),u.y);\n}\nfloat fbm(vec2 p)\n{\nfloat f=0.0;\nf+=0.5000*noise(p); p*=2.02;\nf+=0.2500*noise(p); p*=2.03;\nf+=0.1250*noise(p); p*=2.01;\nf+=0.0625*noise(p); p*=2.04;\nf/=0.9375;\nreturn f;\n}\nvec3 pattern(vec2 uv)\n{\nvec2 p=-1.0+2.0*uv;\nfloat p2=dot(p,p);\nfloat f=fbm(vec2(15.0*p2))/2.0;\nfloat r=0.2+0.6*sin(12.5*length(uv-vec2(0.5)));\nfloat g=0.2+0.6*sin(20.5*length(uv-vec2(0.5)));\nfloat b=0.2+0.6*sin(17.2*length(uv-vec2(0.5)));\nreturn (1.0-f)*vec3(r,g,b);\n}\nfloat luminance(vec3 color)\n{\nreturn dot(color.rgb,vec3(0.2126,0.7152,0.0722));\n}\nvec4 textureDistorted(sampler2D tex,vec2 texcoord,vec2 direction,vec3 distortion)\n{\nreturn vec4(\ntexture2D(tex,texcoord+direction*distortion.r).r,\ntexture2D(tex,texcoord+direction*distortion.g).g,\ntexture2D(tex,texcoord+direction*distortion.b).b,\n1.0\n);\n}\nvoid main(void)\n{\nvec2 uv=-vUV+vec2(1.0);\nvec2 ghostDir=(vec2(0.5)-uv)*ghostDispersal;\nvec2 texelSize=1.0/resolution;\nvec3 distortion=vec3(-texelSize.x*distortionStrength,0.0,texelSize.x*distortionStrength);\nvec4 result=vec4(0.0);\nfloat ghostIndice=1.0;\nfor (int i=0; i=nSamples)\nbreak;\nvec2 offset1=vUV+velocity*(float(i)/float(nSamples-1)-0.5);\nresult+=texture2D(textureSampler,offset1);\n}\ngl_FragColor=result/float(nSamples);\n}\n#endif\n",fxaaVertexShader:"\nattribute vec2 position;\nuniform vec2 texelSize;\n\nvarying vec2 vUV;\nvarying vec2 sampleCoordS;\nvarying vec2 sampleCoordE;\nvarying vec2 sampleCoordN;\nvarying vec2 sampleCoordW;\nvarying vec2 sampleCoordNW;\nvarying vec2 sampleCoordSE;\nvarying vec2 sampleCoordNE;\nvarying vec2 sampleCoordSW;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvUV=(position*madd+madd);\nsampleCoordS=vUV+vec2( 0.0,1.0)*texelSize;\nsampleCoordE=vUV+vec2( 1.0,0.0)*texelSize;\nsampleCoordN=vUV+vec2( 0.0,-1.0)*texelSize;\nsampleCoordW=vUV+vec2(-1.0,0.0)*texelSize;\nsampleCoordNW=vUV+vec2(-1.0,-1.0)*texelSize;\nsampleCoordSE=vUV+vec2( 1.0,1.0)*texelSize;\nsampleCoordNE=vUV+vec2( 1.0,-1.0)*texelSize;\nsampleCoordSW=vUV+vec2(-1.0,1.0)*texelSize;\ngl_Position=vec4(position,0.0,1.0);\n}",fxaaPixelShader:"uniform sampler2D textureSampler;\nuniform vec2 texelSize;\nvarying vec2 vUV;\nvarying vec2 sampleCoordS;\nvarying vec2 sampleCoordE;\nvarying vec2 sampleCoordN;\nvarying vec2 sampleCoordW;\nvarying vec2 sampleCoordNW;\nvarying vec2 sampleCoordSE;\nvarying vec2 sampleCoordNE;\nvarying vec2 sampleCoordSW;\nconst float fxaaQualitySubpix=1.0;\nconst float fxaaQualityEdgeThreshold=0.166;\nconst float fxaaQualityEdgeThresholdMin=0.0833;\nconst vec3 kLumaCoefficients=vec3(0.2126,0.7152,0.0722);\n#define FxaaLuma(rgba) dot(rgba.rgb,kLumaCoefficients)\nvoid main(){\nvec2 posM;\nposM.x=vUV.x;\nposM.y=vUV.y;\nvec4 rgbyM=texture2D(textureSampler,vUV,0.0);\nfloat lumaM=FxaaLuma(rgbyM);\nfloat lumaS=FxaaLuma(texture2D(textureSampler,sampleCoordS,0.0));\nfloat lumaE=FxaaLuma(texture2D(textureSampler,sampleCoordE,0.0));\nfloat lumaN=FxaaLuma(texture2D(textureSampler,sampleCoordN,0.0));\nfloat lumaW=FxaaLuma(texture2D(textureSampler,sampleCoordW,0.0));\nfloat maxSM=max(lumaS,lumaM);\nfloat minSM=min(lumaS,lumaM);\nfloat maxESM=max(lumaE,maxSM);\nfloat minESM=min(lumaE,minSM);\nfloat maxWN=max(lumaN,lumaW);\nfloat minWN=min(lumaN,lumaW);\nfloat rangeMax=max(maxWN,maxESM);\nfloat rangeMin=min(minWN,minESM);\nfloat rangeMaxScaled=rangeMax*fxaaQualityEdgeThreshold;\nfloat range=rangeMax-rangeMin;\nfloat rangeMaxClamped=max(fxaaQualityEdgeThresholdMin,rangeMaxScaled);\n#ifndef MALI\nif(range=edgeVert;\nfloat subpixA=subpixNSWE*2.0+subpixNWSWNESE;\nif (!horzSpan)\n{\nlumaN=lumaW;\n}\nif (!horzSpan) \n{\nlumaS=lumaE;\n}\nif (horzSpan) \n{\nlengthSign=texelSize.y;\n}\nfloat subpixB=(subpixA*(1.0/12.0))-lumaM;\nfloat gradientN=lumaN-lumaM;\nfloat gradientS=lumaS-lumaM;\nfloat lumaNN=lumaN+lumaM;\nfloat lumaSS=lumaS+lumaM;\nbool pairN=abs(gradientN)>=abs(gradientS);\nfloat gradient=max(abs(gradientN),abs(gradientS));\nif (pairN)\n{\nlengthSign=-lengthSign;\n}\nfloat subpixC=clamp(abs(subpixB)*subpixRcpRange,0.0,1.0);\nvec2 posB;\nposB.x=posM.x;\nposB.y=posM.y;\nvec2 offNP;\noffNP.x=(!horzSpan) ? 0.0 : texelSize.x;\noffNP.y=(horzSpan) ? 0.0 : texelSize.y;\nif (!horzSpan) \n{\nposB.x+=lengthSign*0.5;\n}\nif (horzSpan)\n{\nposB.y+=lengthSign*0.5;\n}\nvec2 posN;\nposN.x=posB.x-offNP.x*1.5;\nposN.y=posB.y-offNP.y*1.5;\nvec2 posP;\nposP.x=posB.x+offNP.x*1.5;\nposP.y=posB.y+offNP.y*1.5;\nfloat subpixD=((-2.0)*subpixC)+3.0;\nfloat lumaEndN=FxaaLuma(texture2D(textureSampler,posN,0.0));\nfloat subpixE=subpixC*subpixC;\nfloat lumaEndP=FxaaLuma(texture2D(textureSampler,posP,0.0));\nif (!pairN) \n{\nlumaNN=lumaSS;\n}\nfloat gradientScaled=gradient*1.0/4.0;\nfloat lumaMM=lumaM-lumaNN*0.5;\nfloat subpixF=subpixD*subpixE;\nbool lumaMLTZero=lumaMM<0.0;\nlumaEndN-=lumaNN*0.5;\nlumaEndP-=lumaNN*0.5;\nbool doneN=abs(lumaEndN)>=gradientScaled;\nbool doneP=abs(lumaEndP)>=gradientScaled;\nif (!doneN) \n{\nposN.x-=offNP.x*3.0;\n}\nif (!doneN) \n{\nposN.y-=offNP.y*3.0;\n}\nbool doneNP=(!doneN) || (!doneP);\nif (!doneP) \n{\nposP.x+=offNP.x*3.0;\n}\nif (!doneP)\n{\nposP.y+=offNP.y*3.0;\n}\nif (doneNP)\n{\nif (!doneN) lumaEndN=FxaaLuma(texture2D(textureSampler,posN.xy,0.0));\nif (!doneP) lumaEndP=FxaaLuma(texture2D(textureSampler,posP.xy,0.0));\nif (!doneN) lumaEndN=lumaEndN-lumaNN*0.5;\nif (!doneP) lumaEndP=lumaEndP-lumaNN*0.5;\ndoneN=abs(lumaEndN)>=gradientScaled;\ndoneP=abs(lumaEndP)>=gradientScaled;\nif (!doneN) posN.x-=offNP.x*12.0;\nif (!doneN) posN.y-=offNP.y*12.0;\ndoneNP=(!doneN) || (!doneP);\nif (!doneP) posP.x+=offNP.x*12.0;\nif (!doneP) posP.y+=offNP.y*12.0;\n}\nfloat dstN=posM.x-posN.x;\nfloat dstP=posP.x-posM.x;\nif (!horzSpan)\n{\ndstN=posM.y-posN.y;\n}\nif (!horzSpan) \n{\ndstP=posP.y-posM.y;\n}\nbool goodSpanN=(lumaEndN<0.0) != lumaMLTZero;\nfloat spanLength=(dstP+dstN);\nbool goodSpanP=(lumaEndP<0.0) != lumaMLTZero;\nfloat spanLengthRcp=1.0/spanLength;\nbool directionN=dstN\n\nuniform sampler2D textureSampler; \n\nuniform float intensity;\nuniform float animatedSeed;\n\nvarying vec2 vUV;\nvoid main(void)\n{\ngl_FragColor=texture2D(textureSampler,vUV);\nvec2 seed=vUV*(animatedSeed);\nfloat grain=dither(seed,intensity);\n\nfloat lum=getLuminance(gl_FragColor.rgb);\nfloat grainAmount=(cos(-PI+(lum*PI*2.))+1.)/2.;\ngl_FragColor.rgb+=grain*grainAmount;\ngl_FragColor.rgb=max(gl_FragColor.rgb,0.0);\n}",sharpenPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform vec2 screenSize;\nuniform vec2 sharpnessAmounts;\nvoid main(void)\n{\nvec2 onePixel=vec2(1.0,1.0)/screenSize;\nvec4 color=texture2D(textureSampler,vUV);\nvec4 edgeDetection=texture2D(textureSampler,vUV+onePixel*vec2(0,-1)) +\ntexture2D(textureSampler,vUV+onePixel*vec2(-1,0)) +\ntexture2D(textureSampler,vUV+onePixel*vec2(1,0)) +\ntexture2D(textureSampler,vUV+onePixel*vec2(0,1)) -\ncolor*4.0;\ngl_FragColor=max(vec4(color.rgb*sharpnessAmounts.y,color.a)-(sharpnessAmounts.x*vec4(edgeDetection.rgb,0)),0.);\n}",kernelBlurVertexShader:"\nattribute vec2 position;\n\nuniform vec2 delta;\n\nvarying vec2 sampleCenter;\n#include[0..varyingCount]\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nsampleCenter=(position*madd+madd);\n#include[0..varyingCount]\ngl_Position=vec4(position,0.0,1.0);\n}",kernelBlurPixelShader:"\nuniform sampler2D textureSampler;\nuniform vec2 delta;\n\nvarying vec2 sampleCenter;\n#ifdef DOF\nuniform sampler2D circleOfConfusionSampler;\nuniform vec2 cameraMinMaxZ;\nfloat sampleDistance(const in vec2 offset) {\nfloat depth=texture2D(circleOfConfusionSampler,offset).g; \nreturn cameraMinMaxZ.x+(cameraMinMaxZ.y-cameraMinMaxZ.x)*depth; \n}\nfloat sampleCoC(const in vec2 offset) {\nfloat coc=texture2D(circleOfConfusionSampler,offset).r; \nreturn coc; \n}\n#endif\n#include[0..varyingCount]\n#ifdef PACKEDFLOAT\nvec4 pack(float depth)\n{\nconst vec4 bit_shift=vec4(255.0*255.0*255.0,255.0*255.0,255.0,1.0);\nconst vec4 bit_mask=vec4(0.0,1.0/255.0,1.0/255.0,1.0/255.0);\nvec4 res=fract(depth*bit_shift);\nres-=res.xxyz*bit_mask;\nreturn res;\n}\nfloat unpack(vec4 color)\n{\nconst vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);\nreturn dot(color,bit_shift);\n}\n#endif\nvoid main(void)\n{\nfloat computedWeight=0.0;\n#ifdef PACKEDFLOAT \nfloat blend=0.;\n#else\nvec4 blend=vec4(0.);\n#endif\n#ifdef DOF\nfloat sumOfWeights=CENTER_WEIGHT; \nfloat factor=0.0;\n\n#ifdef PACKEDFLOAT\nblend+=unpack(texture2D(textureSampler,sampleCenter))*CENTER_WEIGHT;\n#else\nblend+=texture2D(textureSampler,sampleCenter)*CENTER_WEIGHT;\n#endif\n#endif\n#include[0..varyingCount]\n#include[0..depCount]\n#ifdef PACKEDFLOAT\ngl_FragColor=pack(blend);\n#else\ngl_FragColor=blend;\n#endif\n#ifdef DOF\ngl_FragColor/=sumOfWeights;\n#endif\n}",depthOfFieldMergePixelShader:"uniform sampler2D textureSampler;\nvarying vec2 vUV;\nuniform sampler2D circleOfConfusionSampler;\nuniform sampler2D blurStep0;\n#if BLUR_LEVEL>0\nuniform sampler2D blurStep1;\n#endif\n#if BLUR_LEVEL>1\nuniform sampler2D blurStep2;\n#endif\nvoid main(void)\n{\nfloat coc=texture2D(circleOfConfusionSampler,vUV).r;\n#if BLUR_LEVEL == 0\nvec4 original=texture2D(textureSampler,vUV);\nvec4 blurred0=texture2D(blurStep0,vUV);\ngl_FragColor=mix(original,blurred0,coc);\n#endif\n#if BLUR_LEVEL == 1\nif(coc<0.5){\nvec4 original=texture2D(textureSampler,vUV);\nvec4 blurred1=texture2D(blurStep1,vUV);\ngl_FragColor=mix(original,blurred1,coc/0.5);\n}else{\nvec4 blurred0=texture2D(blurStep0,vUV); \nvec4 blurred1=texture2D(blurStep1,vUV);\ngl_FragColor=mix(blurred1,blurred0,(coc-0.5)/0.5);\n}\n#endif\n#if BLUR_LEVEL == 2\nif(coc<0.33){\nvec4 original=texture2D(textureSampler,vUV);\nvec4 blurred2=texture2D(blurStep2,vUV);\ngl_FragColor=mix(original,blurred2,coc/0.33);\n}else if(coc<0.66){\nvec4 blurred1=texture2D(blurStep1,vUV);\nvec4 blurred2=texture2D(blurStep2,vUV);\ngl_FragColor=mix(blurred2,blurred1,(coc-0.33)/0.33);\n}else{\nvec4 blurred0=texture2D(blurStep0,vUV);\nvec4 blurred1=texture2D(blurStep1,vUV);\ngl_FragColor=mix(blurred1,blurred0,(coc-0.66)/0.34);\n}\n#endif\n}\n",circleOfConfusionPixelShader:"\nuniform sampler2D depthSampler;\n\nvarying vec2 vUV;\n\nuniform vec2 cameraMinMaxZ;\n\nuniform float focusDistance;\nuniform float cocPrecalculation;\nvoid main(void)\n{\nfloat depth=texture2D(depthSampler,vUV).r;\nfloat pixelDistance=(cameraMinMaxZ.x+(cameraMinMaxZ.y-cameraMinMaxZ.x)*depth)*1000.0; \nfloat coc=abs(cocPrecalculation* ((focusDistance-pixelDistance)/pixelDistance));\ncoc=clamp(coc,0.0,1.0);\ngl_FragColor=vec4(coc,depth,coc,1.0);\n}\n",bloomMergePixelShader:"uniform sampler2D textureSampler;\nuniform sampler2D bloomBlur;\nvarying vec2 vUV;\nuniform float bloomWeight;\nvoid main(void)\n{\ngl_FragColor=texture2D(textureSampler,vUV);\nvec3 blurred=texture2D(bloomBlur,vUV).rgb;\ngl_FragColor.rgb=gl_FragColor.rgb+(blurred.rgb*bloomWeight); \n}\n",extractHighlightsPixelShader:"#include\n\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform float threshold;\nuniform float exposure;\nvoid main(void) \n{\ngl_FragColor=texture2D(textureSampler,vUV);\nfloat luma=getLuminance(gl_FragColor.rgb*exposure);\ngl_FragColor.rgb=step(threshold,luma)*gl_FragColor.rgb;\n}",refractionPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D refractionSampler;\n\nuniform vec3 baseColor;\nuniform float depth;\nuniform float colorLevel;\nvoid main() {\nfloat ref=1.0-texture2D(refractionSampler,vUV).r;\nvec2 uv=vUV-vec2(0.5);\nvec2 offset=uv*depth*ref;\nvec3 sourceColor=texture2D(textureSampler,vUV-offset).rgb;\ngl_FragColor=vec4(sourceColor+sourceColor*ref*colorLevel,1.0);\n}",blackAndWhitePixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform float degree;\nvoid main(void) \n{\nvec3 color=texture2D(textureSampler,vUV).rgb;\nfloat luminance=dot(color,vec3(0.3,0.59,0.11)); \nvec3 blackAndWhite=vec3(luminance,luminance,luminance);\ngl_FragColor=vec4(color-((color-blackAndWhite)*degree),1.0);\n}",convolutionPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform vec2 screenSize;\nuniform float kernel[9];\nvoid main(void)\n{\nvec2 onePixel=vec2(1.0,1.0)/screenSize;\nvec4 colorSum =\ntexture2D(textureSampler,vUV+onePixel*vec2(-1,-1))*kernel[0] +\ntexture2D(textureSampler,vUV+onePixel*vec2(0,-1))*kernel[1] +\ntexture2D(textureSampler,vUV+onePixel*vec2(1,-1))*kernel[2] +\ntexture2D(textureSampler,vUV+onePixel*vec2(-1,0))*kernel[3] +\ntexture2D(textureSampler,vUV+onePixel*vec2(0,0))*kernel[4] +\ntexture2D(textureSampler,vUV+onePixel*vec2(1,0))*kernel[5] +\ntexture2D(textureSampler,vUV+onePixel*vec2(-1,1))*kernel[6] +\ntexture2D(textureSampler,vUV+onePixel*vec2(0,1))*kernel[7] +\ntexture2D(textureSampler,vUV+onePixel*vec2(1,1))*kernel[8];\nfloat kernelWeight =\nkernel[0] +\nkernel[1] +\nkernel[2] +\nkernel[3] +\nkernel[4] +\nkernel[5] +\nkernel[6] +\nkernel[7] +\nkernel[8];\nif (kernelWeight<=0.0) {\nkernelWeight=1.0;\n}\ngl_FragColor=vec4((colorSum/kernelWeight).rgb,1);\n}",filterPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform mat4 kernelMatrix;\nvoid main(void)\n{\nvec3 baseColor=texture2D(textureSampler,vUV).rgb;\nvec3 updatedColor=(kernelMatrix*vec4(baseColor,1.0)).rgb;\ngl_FragColor=vec4(updatedColor,1.0);\n}",volumetricLightScatteringPixelShader:"uniform sampler2D textureSampler;\nuniform sampler2D lightScatteringSampler;\nuniform float decay;\nuniform float exposure;\nuniform float weight;\nuniform float density;\nuniform vec2 meshPositionOnScreen;\nvarying vec2 vUV;\nvoid main(void) {\nvec2 tc=vUV;\nvec2 deltaTexCoord=(tc-meshPositionOnScreen.xy);\ndeltaTexCoord*=1.0/float(NUM_SAMPLES)*density;\nfloat illuminationDecay=1.0;\nvec4 color=texture2D(lightScatteringSampler,tc)*0.4;\nfor(int i=0; i\n#include\n#include\nvoid main(void)\n{\nvec4 result=texture2D(textureSampler,vUV);\n#ifdef IMAGEPROCESSING\n#ifndef FROMLINEARSPACE\n\nresult.rgb=toLinearSpace(result.rgb);\n#endif\nresult=applyImageProcessing(result);\n#else\n\n#ifdef FROMLINEARSPACE\nresult=applyImageProcessing(result);\n#endif\n#endif\ngl_FragColor=result;\n}",lensFlareVertexShader:"\nattribute vec2 position;\n\nuniform mat4 viewportMatrix;\n\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvUV=position*madd+madd;\ngl_Position=viewportMatrix*vec4(position,0.0,1.0);\n}",lensFlarePixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec4 color;\nvoid main(void) {\nvec4 baseColor=texture2D(textureSampler,vUV);\ngl_FragColor=baseColor*color;\n}",anaglyphPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D leftSampler;\nvoid main(void)\n{\nvec4 leftFrag=texture2D(leftSampler,vUV);\nleftFrag=vec4(1.0,leftFrag.g,leftFrag.b,1.0);\nvec4 rightFrag=texture2D(textureSampler,vUV);\nrightFrag=vec4(rightFrag.r,1.0,1.0,1.0);\ngl_FragColor=vec4(rightFrag.rgb*leftFrag.rgb,1.0);\n}",stereoscopicInterlacePixelShader:"const vec3 TWO=vec3(2.0,2.0,2.0);\nvarying vec2 vUV;\nuniform sampler2D camASampler;\nuniform sampler2D textureSampler;\nuniform vec2 stepSize;\nvoid main(void)\n{\nbool useCamB;\nvec2 texCoord1;\nvec2 texCoord2;\nvec3 frag1;\nvec3 frag2;\n#ifdef IS_STEREOSCOPIC_HORIZ\nuseCamB=vUV.x>0.5;\ntexCoord1=vec2(useCamB ? (vUV.x-0.5)*2.0 : vUV.x*2.0,vUV.y);\ntexCoord2=vec2(texCoord1.x+stepSize.x,vUV.y);\n#else\nuseCamB=vUV.y>0.5;\ntexCoord1=vec2(vUV.x,useCamB ? (vUV.y-0.5)*2.0 : vUV.y*2.0);\ntexCoord2=vec2(vUV.x,texCoord1.y+stepSize.y);\n#endif\n\nif (useCamB){\nfrag1=texture2D(textureSampler,texCoord1).rgb;\nfrag2=texture2D(textureSampler,texCoord2).rgb;\n}else{\nfrag1=texture2D(camASampler ,texCoord1).rgb;\nfrag2=texture2D(camASampler ,texCoord2).rgb;\n}\ngl_FragColor=vec4((frag1+frag2)/TWO,1.0);\n}",vrDistortionCorrectionPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform vec2 LensCenter;\nuniform vec2 Scale;\nuniform vec2 ScaleIn;\nuniform vec4 HmdWarpParam;\nvec2 HmdWarp(vec2 in01) {\nvec2 theta=(in01-LensCenter)*ScaleIn; \nfloat rSq=theta.x*theta.x+theta.y*theta.y;\nvec2 rvector=theta*(HmdWarpParam.x+HmdWarpParam.y*rSq+HmdWarpParam.z*rSq*rSq+HmdWarpParam.w*rSq*rSq*rSq);\nreturn LensCenter+Scale*rvector;\n}\nvoid main(void)\n{\nvec2 tc=HmdWarp(vUV);\nif (tc.x <0.0 || tc.x>1.0 || tc.y<0.0 || tc.y>1.0)\ngl_FragColor=vec4(0.0,0.0,0.0,0.0);\nelse{\ngl_FragColor=texture2D(textureSampler,tc);\n}\n}",glowBlurPostProcessPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec2 screenSize;\nuniform vec2 direction;\nuniform float blurWidth;\n\nfloat getLuminance(vec3 color)\n{\nreturn dot(color,vec3(0.2126,0.7152,0.0722));\n}\nvoid main(void)\n{\nfloat weights[7];\nweights[0]=0.05;\nweights[1]=0.1;\nweights[2]=0.2;\nweights[3]=0.3;\nweights[4]=0.2;\nweights[5]=0.1;\nweights[6]=0.05;\nvec2 texelSize=vec2(1.0/screenSize.x,1.0/screenSize.y);\nvec2 texelStep=texelSize*direction*blurWidth;\nvec2 start=vUV-3.0*texelStep;\nvec4 baseColor=vec4(0.,0.,0.,0.);\nvec2 texelOffset=vec2(0.,0.);\nfor (int i=0; i<7; i++)\n{\n\nvec4 texel=texture2D(textureSampler,start+texelOffset);\nbaseColor.a+=texel.a*weights[i];\n\nfloat luminance=getLuminance(baseColor.rgb);\nfloat luminanceTexel=getLuminance(texel.rgb);\nfloat choice=step(luminanceTexel,luminance);\nbaseColor.rgb=choice*baseColor.rgb+(1.0-choice)*texel.rgb;\ntexelOffset+=texelStep;\n}\ngl_FragColor=baseColor;\n}",glowMapGenerationPixelShader:"#ifdef ALPHATEST\nvarying vec2 vUVDiffuse;\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vUVEmissive;\nuniform sampler2D emissiveSampler;\n#endif\nuniform vec4 color;\nvoid main(void)\n{\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUVDiffuse).a<0.4)\ndiscard;\n#endif\n#ifdef EMISSIVE\ngl_FragColor=texture2D(emissiveSampler,vUVEmissive)*color;\n#else\ngl_FragColor=color;\n#endif\n}",glowMapGenerationVertexShader:"\nattribute vec3 position;\n#include\n#include\n#include[0..maxSimultaneousMorphTargets]\n\n#include\nuniform mat4 viewProjection;\nvarying vec4 vPosition;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef ALPHATEST\nvarying vec2 vUVDiffuse;\nuniform mat4 diffuseMatrix;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vUVEmissive;\nuniform mat4 emissiveMatrix;\n#endif\nvoid main(void)\n{\nvec3 positionUpdated=position;\n#include[0..maxSimultaneousMorphTargets]\n#include\n#include\n#ifdef CUBEMAP\nvPosition=finalWorld*vec4(positionUpdated,1.0);\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#else\nvPosition=viewProjection*finalWorld*vec4(positionUpdated,1.0);\ngl_Position=vPosition;\n#endif\n#ifdef ALPHATEST\n#ifdef DIFFUSEUV1\nvUVDiffuse=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef DIFFUSEUV2\nvUVDiffuse=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#ifdef EMISSIVE\n#ifdef EMISSIVEUV1\nvUVEmissive=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef EMISSIVEUV2\nvUVEmissive=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}",glowMapMergePixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n#ifdef EMISSIVE\nuniform sampler2D textureSampler2;\n#endif\n\nuniform float offset;\nvoid main(void) {\nvec4 baseColor=texture2D(textureSampler,vUV);\n#ifdef EMISSIVE\nbaseColor+=texture2D(textureSampler2,vUV);\nbaseColor*=offset;\n#else\nbaseColor.a=abs(offset-baseColor.a);\n#ifdef STROKE\nfloat alpha=smoothstep(.0,.1,baseColor.a);\nbaseColor.a=alpha;\nbaseColor.rgb=baseColor.rgb*alpha;\n#endif\n#endif\ngl_FragColor=baseColor;\n}",glowMapMergeVertexShader:"\nattribute vec2 position;\n\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) {\nvUV=position*madd+madd;\ngl_Position=vec4(position,0.0,1.0);\n}",lineVertexShader:"\nattribute vec3 position;\nattribute vec4 normal;\n\nuniform mat4 worldViewProjection;\nuniform float width;\nuniform float aspectRatio;\nvoid main(void) {\nvec4 viewPosition=worldViewProjection*vec4(position,1.0);\nvec4 viewPositionNext=worldViewProjection*vec4(normal.xyz,1.0);\nvec2 currentScreen=viewPosition.xy/viewPosition.w;\nvec2 nextScreen=viewPositionNext.xy/viewPositionNext.w;\ncurrentScreen.x*=aspectRatio;\nnextScreen.x*=aspectRatio;\nvec2 dir=normalize(nextScreen-currentScreen);\nvec2 normalDir=vec2(-dir.y,dir.x);\nnormalDir*=width/2.0;\nnormalDir.x/=aspectRatio;\nvec4 offset=vec4(normalDir*normal.w,0.0,0.0);\ngl_Position=viewPosition+offset;\n}",linePixelShader:"uniform vec4 color;\nvoid main(void) {\ngl_FragColor=color;\n}",outlineVertexShader:"\nattribute vec3 position;\nattribute vec3 normal;\n#include\n\nuniform float offset;\n#include\nuniform mat4 viewProjection;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\n#include\nvoid main(void)\n{\nvec3 offsetPosition=position+normal*offset;\n#include\n#include\ngl_Position=viewProjection*finalWorld*vec4(offsetPosition,1.0);\n#ifdef ALPHATEST\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#include\n}\n",outlinePixelShader:"#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nuniform vec4 color;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\n#include\nvoid main(void) {\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\n#include\ngl_FragColor=color;\n}",layerVertexShader:"\nattribute vec2 position;\n\nuniform vec2 scale;\nuniform vec2 offset;\nuniform mat4 textureMatrix;\n\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvec2 shiftedPosition=position*scale+offset;\nvUV=vec2(textureMatrix*vec4(shiftedPosition*madd+madd,1.0,0.0));\ngl_Position=vec4(shiftedPosition,0.0,1.0);\n}",layerPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec4 color;\nvoid main(void) {\nvec4 baseColor=texture2D(textureSampler,vUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\ngl_FragColor=baseColor*color;\n}",backgroundVertexShader:"precision highp float;\n#include<__decl__backgroundVertex>\n#include\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#include\n\n#include\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2; \n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nvarying vec2 vDiffuseUV;\n#endif\n#include\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\nvoid main(void) {\n#ifdef REFLECTIONMAP_SKYBOX\n#ifdef REFLECTIONMAP_SKYBOX_TRANSFORMED\nvPositionUVW=(reflectionMatrix*vec4(position,1.0)).xyz;\n#else\nvPositionUVW=position;\n#endif\n#endif \n#include\n#include\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normal);\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(position,0.0)));\n#ifdef EQUIRECTANGULAR_RELFECTION_FOV\nmat3 screenToWorld=inverseMat3(mat3(finalWorld*viewProjection));\nvec3 segment=mix(vDirectionW,screenToWorld*vec3(0.0,0.0,1.0),abs(fFovMultiplier-1.0));\nif (fFovMultiplier<=1.0) {\nvDirectionW=normalize(segment);\n} else {\nvDirectionW=normalize(vDirectionW+(vDirectionW-segment));\n}\n#endif\n#endif\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uv;\n#endif \n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0 \nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include\n\n#include\n\n#include[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n",backgroundPixelShader:"#ifdef TEXTURELODSUPPORT\n#extension GL_EXT_shader_texture_lod : enable\n#endif\nprecision highp float;\n#include<__decl__backgroundFragment>\n#define RECIPROCAL_PI2 0.15915494\n\nuniform vec3 vEyePosition;\n\nvarying vec3 vPositionW;\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif \n#ifdef MAINUV2 \nvarying vec2 vMainUV2; \n#endif \n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef DIFFUSE\n#if DIFFUSEDIRECTUV == 1\n#define vDiffuseUV vMainUV1\n#elif DIFFUSEDIRECTUV == 2\n#define vDiffuseUV vMainUV2\n#else\nvarying vec2 vDiffuseUV;\n#endif\nuniform sampler2D diffuseSampler;\n#endif\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\n#define sampleReflection(s,c) textureCube(s,c)\nuniform samplerCube reflectionSampler;\n#ifdef TEXTURELODSUPPORT\n#define sampleReflectionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;\nuniform samplerCube reflectionSamplerHigh;\n#endif\n#else\n#define sampleReflection(s,c) texture2D(s,c)\nuniform sampler2D reflectionSampler;\n#ifdef TEXTURELODSUPPORT\n#define sampleReflectionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;\nuniform samplerCube reflectionSamplerHigh;\n#endif\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include\n#endif\n\n#ifndef FROMLINEARSPACE\n#define FROMLINEARSPACE;\n#endif\n\n#ifndef SHADOWONLY\n#define SHADOWONLY;\n#endif\n#include\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\n#include\n#include\n#include\n\n#include\n#ifdef REFLECTIONFRESNEL\n#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\nvec3 fresnelSchlickEnvironmentGGX(float VdotN,vec3 reflectance0,vec3 reflectance90,float smoothness)\n{\n\nfloat weight=mix(FRESNEL_MAXIMUM_ON_ROUGH,1.0,smoothness);\nreturn reflectance0+weight*(reflectance90-reflectance0)*pow(clamp(1.0-VdotN,0.,1.),5.0);\n}\n#endif\nvoid main(void) {\n#include\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(0.0,1.0,0.0);\n#endif\n\nfloat shadow=1.;\nfloat globalShadow=0.;\nfloat shadowLightCount=0.;\n#include[0..maxSimultaneousLights]\n#ifdef SHADOWINUSE\nglobalShadow/=shadowLightCount;\n#else\nglobalShadow=1.0;\n#endif\n\nvec4 reflectionColor=vec4(1.,1.,1.,1.);\n#ifdef REFLECTION\nvec3 reflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflectionVector.z*=-1.0;\n#endif\n\n#ifdef REFLECTIONMAP_3D\nvec3 reflectionCoords=reflectionVector;\n#else\nvec2 reflectionCoords=reflectionVector.xy;\n#ifdef REFLECTIONMAP_PROJECTION\nreflectionCoords/=reflectionVector.z;\n#endif\nreflectionCoords.y=1.0-reflectionCoords.y;\n#endif\n#ifdef REFLECTIONBLUR\nfloat reflectionLOD=vReflectionInfos.y;\n#ifdef TEXTURELODSUPPORT\n\nreflectionLOD=reflectionLOD*log2(vReflectionMicrosurfaceInfos.x)*vReflectionMicrosurfaceInfos.y+vReflectionMicrosurfaceInfos.z;\nreflectionColor=sampleReflectionLod(reflectionSampler,reflectionCoords,reflectionLOD);\n#else\nfloat lodReflectionNormalized=clamp(reflectionLOD,0.,1.);\nfloat lodReflectionNormalizedDoubled=lodReflectionNormalized*2.0;\nvec4 reflectionSpecularMid=sampleReflection(reflectionSampler,reflectionCoords);\nif(lodReflectionNormalizedDoubled<1.0){\nreflectionColor=mix(\nsampleReflection(reflectionSamplerHigh,reflectionCoords),\nreflectionSpecularMid,\nlodReflectionNormalizedDoubled\n);\n} else {\nreflectionColor=mix(\nreflectionSpecularMid,\nsampleReflection(reflectionSamplerLow,reflectionCoords),\nlodReflectionNormalizedDoubled-1.0\n);\n}\n#endif\n#else\nvec4 reflectionSample=sampleReflection(reflectionSampler,reflectionCoords);\nreflectionColor=reflectionSample;\n#endif\n#ifdef RGBDREFLECTION\nreflectionColor.rgb=fromRGBD(reflectionColor);\n#endif\n#ifdef GAMMAREFLECTION\nreflectionColor.rgb=toLinearSpace(reflectionColor.rgb);\n#endif\n#ifdef REFLECTIONBGR\nreflectionColor.rgb=reflectionColor.bgr;\n#endif\n\nreflectionColor.rgb*=vReflectionInfos.x;\n#endif\n\nvec3 diffuseColor=vec3(1.,1.,1.);\nfloat finalAlpha=alpha;\n#ifdef DIFFUSE\nvec4 diffuseMap=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef GAMMADIFFUSE\ndiffuseMap.rgb=toLinearSpace(diffuseMap.rgb);\n#endif\n\ndiffuseMap.rgb*=vDiffuseInfos.y;\n#ifdef DIFFUSEHASALPHA\nfinalAlpha*=diffuseMap.a;\n#endif\ndiffuseColor=diffuseMap.rgb;\n#endif\n\n#ifdef REFLECTIONFRESNEL\nvec3 colorBase=diffuseColor;\n#else\nvec3 colorBase=reflectionColor.rgb*diffuseColor;\n#endif\ncolorBase=max(colorBase,0.0);\n\n#ifdef USERGBCOLOR\nvec3 finalColor=colorBase;\n#else\n#ifdef USEHIGHLIGHTANDSHADOWCOLORS\nvec3 mainColor=mix(vPrimaryColorShadow.rgb,vPrimaryColor.rgb,colorBase);\n#else\nvec3 mainColor=vPrimaryColor.rgb;\n#endif\nvec3 finalColor=colorBase*mainColor;\n#endif\n\n#ifdef REFLECTIONFRESNEL\nvec3 reflectionAmount=vReflectionControl.xxx;\nvec3 reflectionReflectance0=vReflectionControl.yyy;\nvec3 reflectionReflectance90=vReflectionControl.zzz;\nfloat VdotN=dot(normalize(vEyePosition),normalW);\nvec3 planarReflectionFresnel=fresnelSchlickEnvironmentGGX(clamp(VdotN,0.0,1.0),reflectionReflectance0,reflectionReflectance90,1.0);\nreflectionAmount*=planarReflectionFresnel;\n#ifdef REFLECTIONFALLOFF\nfloat reflectionDistanceFalloff=1.0-clamp(length(vPositionW.xyz-vBackgroundCenter)*vReflectionControl.w,0.0,1.0);\nreflectionDistanceFalloff*=reflectionDistanceFalloff;\nreflectionAmount*=reflectionDistanceFalloff;\n#endif\nfinalColor=mix(finalColor,reflectionColor.rgb,clamp(reflectionAmount,0.,1.));\n#endif\n#ifdef OPACITYFRESNEL\nfloat viewAngleToFloor=dot(normalW,normalize(vEyePosition-vBackgroundCenter));\n\nconst float startAngle=0.1;\nfloat fadeFactor=clamp(viewAngleToFloor/startAngle,0.0,1.0);\nfinalAlpha*=fadeFactor*fadeFactor;\n#endif\n\n#ifdef SHADOWINUSE\nfinalColor=mix(finalColor*shadowLevel,finalColor,globalShadow);\n#endif\n\nvec4 color=vec4(finalColor,finalAlpha);\n#include\n#ifdef IMAGEPROCESSINGPOSTPROCESS\n\n\ncolor.rgb=clamp(color.rgb,0.,30.0);\n#else\n\ncolor=applyImageProcessing(color);\n#endif\n#ifdef PREMULTIPLYALPHA\n\ncolor.rgb*=color.a;\n#endif\n#ifdef NOISE\ncolor.rgb+=dither(vPositionW.xy,0.5);\ncolor=max(color,0.0);\n#endif\ngl_FragColor=color;\n}\n",noisePixelShader:"\n\nuniform float brightness;\nuniform float persistence;\nuniform float timeScale;\n\nvarying vec2 vUV;\n\nvec2 hash22(vec2 p)\n{\np=p*mat2(127.1,311.7,269.5,183.3);\np=-1.0+2.0*fract(sin(p)*43758.5453123);\nreturn sin(p*6.283+timeScale);\n}\nfloat interpolationNoise(vec2 p)\n{\nvec2 pi=floor(p);\nvec2 pf=p-pi;\nvec2 w=pf*pf*(3.-2.*pf);\nfloat f00=dot(hash22(pi+vec2(.0,.0)),pf-vec2(.0,.0));\nfloat f01=dot(hash22(pi+vec2(.0,1.)),pf-vec2(.0,1.));\nfloat f10=dot(hash22(pi+vec2(1.0,0.)),pf-vec2(1.0,0.));\nfloat f11=dot(hash22(pi+vec2(1.0,1.)),pf-vec2(1.0,1.));\nfloat xm1=mix(f00,f10,w.x);\nfloat xm2=mix(f01,f11,w.x);\nfloat ym=mix(xm1,xm2,w.y); \nreturn ym;\n}\nfloat perlinNoise2D(float x,float y)\n{\nfloat sum=0.0;\nfloat frequency=0.0;\nfloat amplitude=0.0;\nfor(int i=0; i0\nuniform mat4 mBones[BonesPerMesh];\nattribute vec4 matricesIndices;\nattribute vec4 matricesWeights;\n#if NUM_BONE_INFLUENCERS>4\nattribute vec4 matricesIndicesExtra;\nattribute vec4 matricesWeightsExtra;\n#endif\n#endif",instancesDeclaration:"#ifdef INSTANCES\nattribute vec4 world0;\nattribute vec4 world1;\nattribute vec4 world2;\nattribute vec4 world3;\n#else\nuniform mat4 world;\n#endif",pointCloudVertexDeclaration:"#ifdef POINTSIZE\nuniform float pointSize;\n#endif",bumpVertexDeclaration:"#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n#endif\n",clipPlaneVertexDeclaration:"#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif\n#ifdef CLIPPLANE2\nuniform vec4 vClipPlane2;\nvarying float fClipDistance2;\n#endif\n#ifdef CLIPPLANE3\nuniform vec4 vClipPlane3;\nvarying float fClipDistance3;\n#endif\n#ifdef CLIPPLANE4\nuniform vec4 vClipPlane4;\nvarying float fClipDistance4;\n#endif",fogVertexDeclaration:"#ifdef FOG\nvarying vec3 vFogDistance;\n#endif",morphTargetsVertexGlobalDeclaration:"#ifdef MORPHTARGETS\nuniform float morphTargetInfluences[NUM_MORPH_INFLUENCERS];\n#endif",morphTargetsVertexDeclaration:"#ifdef MORPHTARGETS\nattribute vec3 position{X};\n#ifdef MORPHTARGETS_NORMAL\nattribute vec3 normal{X};\n#endif\n#ifdef MORPHTARGETS_TANGENT\nattribute vec3 tangent{X};\n#endif\n#endif",logDepthDeclaration:"#ifdef LOGARITHMICDEPTH\nuniform float logarithmicDepthConstant;\nvarying float vFragmentDepth;\n#endif",morphTargetsVertex:"#ifdef MORPHTARGETS\npositionUpdated+=(position{X}-position)*morphTargetInfluences[{X}];\n#ifdef MORPHTARGETS_NORMAL\nnormalUpdated+=(normal{X}-normal)*morphTargetInfluences[{X}];\n#endif\n#ifdef MORPHTARGETS_TANGENT\ntangentUpdated.xyz+=(tangent{X}-tangent.xyz)*morphTargetInfluences[{X}];\n#endif\n#endif",instancesVertex:"#ifdef INSTANCES\nmat4 finalWorld=mat4(world0,world1,world2,world3);\n#else\nmat4 finalWorld=world;\n#endif",bonesVertex:"#if NUM_BONE_INFLUENCERS>0\nmat4 influence;\ninfluence=mBones[int(matricesIndices[0])]*matricesWeights[0];\n#if NUM_BONE_INFLUENCERS>1\ninfluence+=mBones[int(matricesIndices[1])]*matricesWeights[1];\n#endif \n#if NUM_BONE_INFLUENCERS>2\ninfluence+=mBones[int(matricesIndices[2])]*matricesWeights[2];\n#endif \n#if NUM_BONE_INFLUENCERS>3\ninfluence+=mBones[int(matricesIndices[3])]*matricesWeights[3];\n#endif \n#if NUM_BONE_INFLUENCERS>4\ninfluence+=mBones[int(matricesIndicesExtra[0])]*matricesWeightsExtra[0];\n#endif \n#if NUM_BONE_INFLUENCERS>5\ninfluence+=mBones[int(matricesIndicesExtra[1])]*matricesWeightsExtra[1];\n#endif \n#if NUM_BONE_INFLUENCERS>6\ninfluence+=mBones[int(matricesIndicesExtra[2])]*matricesWeightsExtra[2];\n#endif \n#if NUM_BONE_INFLUENCERS>7\ninfluence+=mBones[int(matricesIndicesExtra[3])]*matricesWeightsExtra[3];\n#endif \nfinalWorld=finalWorld*influence;\n#endif",bumpVertex:"#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL)\nvec3 tbnNormal=normalize(normalUpdated);\nvec3 tbnTangent=normalize(tangentUpdated.xyz);\nvec3 tbnBitangent=cross(tbnNormal,tbnTangent)*tangentUpdated.w;\nvTBN=mat3(finalWorld)*mat3(tbnTangent,tbnBitangent,tbnNormal);\n#endif\n#endif",clipPlaneVertex:"#ifdef CLIPPLANE\nfClipDistance=dot(worldPos,vClipPlane);\n#endif\n#ifdef CLIPPLANE2\nfClipDistance2=dot(worldPos,vClipPlane2);\n#endif\n#ifdef CLIPPLANE3\nfClipDistance3=dot(worldPos,vClipPlane3);\n#endif\n#ifdef CLIPPLANE4\nfClipDistance4=dot(worldPos,vClipPlane4);\n#endif",fogVertex:"#ifdef FOG\nvFogDistance=(view*worldPos).xyz;\n#endif",shadowsVertex:"#ifdef SHADOWS\n#if defined(SHADOW{X}) && !defined(SHADOWCUBE{X})\nvPositionFromLight{X}=lightMatrix{X}*worldPos;\nvDepthMetric{X}=((vPositionFromLight{X}.z+light{X}.depthValues.x)/(light{X}.depthValues.y));\n#endif\n#endif",pointCloudVertex:"#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif",logDepthVertex:"#ifdef LOGARITHMICDEPTH\nvFragmentDepth=1.0+gl_Position.w;\ngl_Position.z=log2(max(0.000001,vFragmentDepth))*logarithmicDepthConstant;\n#endif",helperFunctions:"const float PI=3.1415926535897932384626433832795;\nconst float LinearEncodePowerApprox=2.2;\nconst float GammaEncodePowerApprox=1.0/LinearEncodePowerApprox;\nconst vec3 LuminanceEncodeApprox=vec3(0.2126,0.7152,0.0722);\nmat3 transposeMat3(mat3 inMatrix) {\nvec3 i0=inMatrix[0];\nvec3 i1=inMatrix[1];\nvec3 i2=inMatrix[2];\nmat3 outMatrix=mat3(\nvec3(i0.x,i1.x,i2.x),\nvec3(i0.y,i1.y,i2.y),\nvec3(i0.z,i1.z,i2.z)\n);\nreturn outMatrix;\n}\n\nmat3 inverseMat3(mat3 inMatrix) {\nfloat a00=inMatrix[0][0],a01=inMatrix[0][1],a02=inMatrix[0][2];\nfloat a10=inMatrix[1][0],a11=inMatrix[1][1],a12=inMatrix[1][2];\nfloat a20=inMatrix[2][0],a21=inMatrix[2][1],a22=inMatrix[2][2];\nfloat b01=a22*a11-a12*a21;\nfloat b11=-a22*a10+a12*a20;\nfloat b21=a21*a10-a11*a20;\nfloat det=a00*b01+a01*b11+a02*b21;\nreturn mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),\nb11,(a22*a00-a02*a20),(-a12*a00+a02*a10),\nb21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;\n}\nfloat computeFallOff(float value,vec2 clipSpace,float frustumEdgeFalloff)\n{\nfloat mask=smoothstep(1.0-frustumEdgeFalloff,1.0,clamp(dot(clipSpace,clipSpace),0.,1.));\nreturn mix(value,1.0,mask);\n}\nvec3 applyEaseInOut(vec3 x){\nreturn x*x*(3.0-2.0*x);\n}\nvec3 toLinearSpace(vec3 color)\n{\nreturn pow(color,vec3(LinearEncodePowerApprox));\n}\nvec3 toGammaSpace(vec3 color)\n{\nreturn pow(color,vec3(GammaEncodePowerApprox));\n}\nfloat square(float value)\n{\nreturn value*value;\n}\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,LuminanceEncodeApprox),0.,1.);\n}\n\nfloat getRand(vec2 seed) {\nreturn fract(sin(dot(seed.xy ,vec2(12.9898,78.233)))*43758.5453);\n}\nfloat dither(vec2 seed,float varianceAmount) {\nfloat rand=getRand(seed);\nfloat dither=mix(-varianceAmount/255.0,varianceAmount/255.0,rand);\nreturn dither;\n}\n\nconst float rgbdMaxRange=255.0;\nvec4 toRGBD(vec3 color) {\nfloat maxRGB=max(0.0000001,max(color.r,max(color.g,color.b)));\nfloat D=max(rgbdMaxRange/maxRGB,1.);\nD=clamp(floor(D)/255.0,0.,1.);\n\nvec3 rgb=color.rgb*D;\n\nrgb=toGammaSpace(rgb);\nreturn vec4(rgb,D); \n}\nvec3 fromRGBD(vec4 rgbd) {\n\nrgbd.rgb=toLinearSpace(rgbd.rgb);\n\nreturn rgbd.rgb/rgbd.a;\n}",lightFragmentDeclaration:"#ifdef LIGHT{X}\nuniform vec4 vLightData{X};\nuniform vec4 vLightDiffuse{X};\n#ifdef SPECULARTERM\nuniform vec3 vLightSpecular{X};\n#else\nvec3 vLightSpecular{X}=vec3(0.);\n#endif\n#ifdef SHADOW{X}\n#if defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X};\n#else\nvarying vec4 vPositionFromLight{X};\nvarying float vDepthMetric{X};\n#if defined(SHADOWPCSS{X})\nuniform highp sampler2DShadow shadowSampler{X};\nuniform highp sampler2D depthSampler{X};\n#elif defined(SHADOWPCF{X})\nuniform highp sampler2DShadow shadowSampler{X};\n#else\nuniform sampler2D shadowSampler{X};\n#endif\nuniform mat4 lightMatrix{X};\n#endif\nuniform vec4 shadowsInfo{X};\nuniform vec2 depthValues{X};\n#endif\n#ifdef SPOTLIGHT{X}\nuniform vec4 vLightDirection{X};\nuniform vec4 vLightFalloff{X};\n#elif defined(POINTLIGHT{X})\nuniform vec4 vLightFalloff{X};\n#elif defined(HEMILIGHT{X})\nuniform vec3 vLightGround{X};\n#endif\n#ifdef PROJECTEDLIGHTTEXTURE{X}\nuniform mat4 textureProjectionMatrix{X};\nuniform sampler2D projectionLightSampler{X};\n#endif\n#endif",lightsFragmentFunctions:"\nstruct lightingInfo\n{\nvec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n#ifdef NDOTL\nfloat ndl;\n#endif\n};\nlightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {\nlightingInfo result;\nvec3 lightVectorW;\nfloat attenuation=1.0;\nif (lightData.w == 0.)\n{\nvec3 direction=lightData.xyz-vPositionW;\nattenuation=max(0.,1.0-length(direction)/range);\nlightVectorW=normalize(direction);\n}\nelse\n{\nlightVectorW=normalize(-lightData.xyz);\n}\n\nfloat ndl=max(0.,dot(vNormal,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightVectorW);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {\nlightingInfo result;\nvec3 direction=lightData.xyz-vPositionW;\nvec3 lightVectorW=normalize(direction);\nfloat attenuation=max(0.,1.0-length(direction)/range);\n\nfloat cosAngle=max(0.,dot(lightDirection.xyz,-lightVectorW));\nif (cosAngle>=lightDirection.w)\n{\ncosAngle=max(0.,pow(cosAngle,lightData.w));\nattenuation*=cosAngle;\n\nfloat ndl=max(0.,dot(vNormal,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightVectorW);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;\n}\nresult.diffuse=vec3(0.);\n#ifdef SPECULARTERM\nresult.specular=vec3(0.);\n#endif\n#ifdef NDOTL\nresult.ndl=0.;\n#endif\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float glossiness) {\nlightingInfo result;\n\nfloat ndl=dot(vNormal,lightData.xyz)*0.5+0.5;\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=mix(groundColor,diffuseColor,ndl);\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightData.xyz);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor;\n#endif\nreturn result;\n}\nvec3 computeProjectionTextureDiffuseLighting(sampler2D projectionLightSampler,mat4 textureProjectionMatrix){\nvec4 strq=textureProjectionMatrix*vec4(vPositionW,1.0);\nstrq/=strq.w;\nvec3 textureColor=texture2D(projectionLightSampler,strq.xy).rgb;\nreturn textureColor;\n}",lightUboDeclaration:"#ifdef LIGHT{X}\nuniform Light{X}\n{\nvec4 vLightData;\nvec4 vLightDiffuse;\nvec3 vLightSpecular;\n#ifdef SPOTLIGHT{X}\nvec4 vLightDirection;\nvec4 vLightFalloff;\n#elif defined(POINTLIGHT{X})\nvec4 vLightFalloff;\n#elif defined(HEMILIGHT{X})\nvec3 vLightGround;\n#endif\nvec4 shadowsInfo;\nvec2 depthValues;\n} light{X};\n#ifdef PROJECTEDLIGHTTEXTURE{X}\nuniform mat4 textureProjectionMatrix{X};\nuniform sampler2D projectionLightSampler{X};\n#endif\n#ifdef SHADOW{X}\n#if defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X}; \n#else\nvarying vec4 vPositionFromLight{X};\nvarying float vDepthMetric{X};\n#if defined(SHADOWPCSS{X})\nuniform highp sampler2DShadow shadowSampler{X};\nuniform highp sampler2D depthSampler{X};\n#elif defined(SHADOWPCF{X})\nuniform highp sampler2DShadow shadowSampler{X};\n#else\nuniform sampler2D shadowSampler{X};\n#endif\nuniform mat4 lightMatrix{X};\n#endif\n#endif\n#endif",defaultVertexDeclaration:"\nuniform mat4 viewProjection;\nuniform mat4 view;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\nuniform mat4 lightmapMatrix;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;\nuniform mat4 specularMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n#ifdef REFLECTION\nuniform mat4 reflectionMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n",defaultFragmentDeclaration:"uniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\nuniform vec3 vEmissiveColor;\n\n#ifdef DIFFUSE\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY \nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform vec2 vTangentSpaceParams;\n#endif\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\n#endif\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\n#ifndef REFRACTIONMAP_3D\nuniform mat4 refractionMatrix;\n#endif\n#ifdef REFRACTIONFRESNEL\nuniform vec4 refractionLeftColor;\nuniform vec4 refractionRightColor;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;\n#endif\n#ifdef DIFFUSEFRESNEL\nuniform vec4 diffuseLeftColor;\nuniform vec4 diffuseRightColor;\n#endif\n#ifdef OPACITYFRESNEL\nuniform vec4 opacityParts;\n#endif\n#ifdef EMISSIVEFRESNEL\nuniform vec4 emissiveLeftColor;\nuniform vec4 emissiveRightColor;\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\n#ifdef REFLECTIONMAP_SKYBOX\n#else\n#if defined(REFLECTIONMAP_PLANAR) || defined(REFLECTIONMAP_CUBIC) || defined(REFLECTIONMAP_PROJECTION)\nuniform mat4 reflectionMatrix;\n#endif\n#if defined(USE_LOCAL_REFLECTIONMAP_CUBIC) && defined(REFLECTIONMAP_CUBIC)\nuniform vec3 vReflectionPosition;\nuniform vec3 vReflectionSize; \n#endif\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 reflectionLeftColor;\nuniform vec4 reflectionRightColor;\n#endif\n#endif",defaultUboDeclaration:"layout(std140,column_major) uniform;\nuniform Material\n{\nvec4 diffuseLeftColor;\nvec4 diffuseRightColor;\nvec4 opacityParts;\nvec4 reflectionLeftColor;\nvec4 reflectionRightColor;\nvec4 refractionLeftColor;\nvec4 refractionRightColor;\nvec4 emissiveLeftColor; \nvec4 emissiveRightColor;\nvec2 vDiffuseInfos;\nvec2 vAmbientInfos;\nvec2 vOpacityInfos;\nvec2 vReflectionInfos;\nvec3 vReflectionPosition;\nvec3 vReflectionSize;\nvec2 vEmissiveInfos;\nvec2 vLightmapInfos;\nvec2 vSpecularInfos;\nvec3 vBumpInfos;\nmat4 diffuseMatrix;\nmat4 ambientMatrix;\nmat4 opacityMatrix;\nmat4 reflectionMatrix;\nmat4 emissiveMatrix;\nmat4 lightmapMatrix;\nmat4 specularMatrix;\nmat4 bumpMatrix; \nvec4 vTangentSpaceParams;\nmat4 refractionMatrix;\nvec4 vRefractionInfos;\nvec4 vSpecularColor;\nvec3 vEmissiveColor;\nvec4 vDiffuseColor;\nfloat pointSize; \n};\nuniform Scene {\nmat4 viewProjection;\nmat4 view;\n};",shadowsFragmentFunctions:"#ifdef SHADOWS\n#ifndef SHADOWFLOAT\nfloat unpack(vec4 color)\n{\nconst vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);\nreturn dot(color,bit_shift);\n}\n#endif\nfloat computeShadowCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadow=textureCube(shadowSampler,directionToLight).x;\n#endif\nif (depth>shadow)\n{\nreturn darkness;\n}\nreturn 1.0;\n}\nfloat computeShadowWithPoissonSamplingCube(vec3 lightPosition,samplerCube shadowSampler,float mapSize,float darkness,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\nfloat visibility=1.;\nvec3 poissonDisk[4];\npoissonDisk[0]=vec3(-1.0,1.0,-1.0);\npoissonDisk[1]=vec3(1.0,-1.0,-1.0);\npoissonDisk[2]=vec3(-1.0,-1.0,-1.0);\npoissonDisk[3]=vec3(1.0,-1.0,1.0);\n\n#ifndef SHADOWFLOAT\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize))1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadow=texture2D(shadowSampler,uv).x;\n#endif\nif (shadowPixelDepth>shadow)\n{\nreturn computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff);\n}\nreturn 1.;\n}\nfloat computeShadowWithPoissonSampling(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float mapSize,float darkness,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\nfloat visibility=1.;\nvec2 poissonDisk[4];\npoissonDisk[0]=vec2(-0.94201624,-0.39906216);\npoissonDisk[1]=vec2(0.94558609,-0.76890725);\npoissonDisk[2]=vec2(-0.094184101,-0.92938870);\npoissonDisk[3]=vec2(0.34495938,0.29387760);\n\n#ifndef SHADOWFLOAT\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[0]*mapSize))1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadowMapSample=texture2D(shadowSampler,uv).x;\n#endif\nfloat esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);\nreturn computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);\n}\nfloat computeShadowWithCloseESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0); \n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadowMapSample=texture2D(shadowSampler,uv).x;\n#endif\nfloat esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);\nreturn computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);\n}\n#ifdef WEBGL2\n\nfloat computeShadowWithPCF1(vec4 vPositionFromLight,float depthMetric,sampler2DShadow shadowSampler,float darkness,float frustumEdgeFalloff)\n{\nif (depthMetric>1.0 || depthMetric<0.0) {\nreturn 1.0;\n}\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));\nfloat shadow=texture2D(shadowSampler,uvDepth);\nshadow=mix(darkness,1.,shadow);\nreturn computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);\n}\n\n\n\nfloat computeShadowWithPCF3(vec4 vPositionFromLight,float depthMetric,sampler2DShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)\n{\nif (depthMetric>1.0 || depthMetric<0.0) {\nreturn 1.0;\n}\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));\nvec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x; \nuv+=0.5; \nvec2 st=fract(uv); \nvec2 base_uv=floor(uv)-0.5; \nbase_uv*=shadowMapSizeAndInverse.y; \n\n\n\n\nvec2 uvw0=3.-2.*st;\nvec2 uvw1=1.+2.*st;\nvec2 u=vec2((2.-st.x)/uvw0.x-1.,st.x/uvw1.x+1.)*shadowMapSizeAndInverse.y;\nvec2 v=vec2((2.-st.y)/uvw0.y-1.,st.y/uvw1.y+1.)*shadowMapSizeAndInverse.y;\nfloat shadow=0.;\nshadow+=uvw0.x*uvw0.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[0]),uvDepth.z));\nshadow+=uvw1.x*uvw0.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[0]),uvDepth.z));\nshadow+=uvw0.x*uvw1.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[1]),uvDepth.z));\nshadow+=uvw1.x*uvw1.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[1]),uvDepth.z));\nshadow=shadow/16.;\nshadow=mix(darkness,1.,shadow);\nreturn computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);\n}\n\n\n\nfloat computeShadowWithPCF5(vec4 vPositionFromLight,float depthMetric,sampler2DShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)\n{\nif (depthMetric>1.0 || depthMetric<0.0) {\nreturn 1.0;\n}\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));\nvec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x; \nuv+=0.5; \nvec2 st=fract(uv); \nvec2 base_uv=floor(uv)-0.5; \nbase_uv*=shadowMapSizeAndInverse.y; \n\n\nvec2 uvw0=4.-3.*st;\nvec2 uvw1=vec2(7.);\nvec2 uvw2=1.+3.*st;\nvec3 u=vec3((3.-2.*st.x)/uvw0.x-2.,(3.+st.x)/uvw1.x,st.x/uvw2.x+2.)*shadowMapSizeAndInverse.y;\nvec3 v=vec3((3.-2.*st.y)/uvw0.y-2.,(3.+st.y)/uvw1.y,st.y/uvw2.y+2.)*shadowMapSizeAndInverse.y;\nfloat shadow=0.;\nshadow+=uvw0.x*uvw0.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[0]),uvDepth.z));\nshadow+=uvw1.x*uvw0.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[0]),uvDepth.z));\nshadow+=uvw2.x*uvw0.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[0]),uvDepth.z));\nshadow+=uvw0.x*uvw1.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[1]),uvDepth.z));\nshadow+=uvw1.x*uvw1.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[1]),uvDepth.z));\nshadow+=uvw2.x*uvw1.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[1]),uvDepth.z));\nshadow+=uvw0.x*uvw2.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[2]),uvDepth.z));\nshadow+=uvw1.x*uvw2.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[2]),uvDepth.z));\nshadow+=uvw2.x*uvw2.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[2]),uvDepth.z));\nshadow=shadow/144.;\nshadow=mix(darkness,1.,shadow);\nreturn computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);\n}\nconst vec3 PoissonSamplers32[64]=vec3[64](\nvec3(0.06407013,0.05409927,0.),\nvec3(0.7366577,0.5789394,0.),\nvec3(-0.6270542,-0.5320278,0.),\nvec3(-0.4096107,0.8411095,0.),\nvec3(0.6849564,-0.4990818,0.),\nvec3(-0.874181,-0.04579735,0.),\nvec3(0.9989998,0.0009880066,0.),\nvec3(-0.004920578,-0.9151649,0.),\nvec3(0.1805763,0.9747483,0.),\nvec3(-0.2138451,0.2635818,0.),\nvec3(0.109845,0.3884785,0.),\nvec3(0.06876755,-0.3581074,0.),\nvec3(0.374073,-0.7661266,0.),\nvec3(0.3079132,-0.1216763,0.),\nvec3(-0.3794335,-0.8271583,0.),\nvec3(-0.203878,-0.07715034,0.),\nvec3(0.5912697,0.1469799,0.),\nvec3(-0.88069,0.3031784,0.),\nvec3(0.5040108,0.8283722,0.),\nvec3(-0.5844124,0.5494877,0.),\nvec3(0.6017799,-0.1726654,0.),\nvec3(-0.5554981,0.1559997,0.),\nvec3(-0.3016369,-0.3900928,0.),\nvec3(-0.5550632,-0.1723762,0.),\nvec3(0.925029,0.2995041,0.),\nvec3(-0.2473137,0.5538505,0.),\nvec3(0.9183037,-0.2862392,0.),\nvec3(0.2469421,0.6718712,0.),\nvec3(0.3916397,-0.4328209,0.),\nvec3(-0.03576927,-0.6220032,0.),\nvec3(-0.04661255,0.7995201,0.),\nvec3(0.4402924,0.3640312,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.)\n);\nconst vec3 PoissonSamplers64[64]=vec3[64](\nvec3(-0.613392,0.617481,0.),\nvec3(0.170019,-0.040254,0.),\nvec3(-0.299417,0.791925,0.),\nvec3(0.645680,0.493210,0.),\nvec3(-0.651784,0.717887,0.),\nvec3(0.421003,0.027070,0.),\nvec3(-0.817194,-0.271096,0.),\nvec3(-0.705374,-0.668203,0.),\nvec3(0.977050,-0.108615,0.),\nvec3(0.063326,0.142369,0.),\nvec3(0.203528,0.214331,0.),\nvec3(-0.667531,0.326090,0.),\nvec3(-0.098422,-0.295755,0.),\nvec3(-0.885922,0.215369,0.),\nvec3(0.566637,0.605213,0.),\nvec3(0.039766,-0.396100,0.),\nvec3(0.751946,0.453352,0.),\nvec3(0.078707,-0.715323,0.),\nvec3(-0.075838,-0.529344,0.),\nvec3(0.724479,-0.580798,0.),\nvec3(0.222999,-0.215125,0.),\nvec3(-0.467574,-0.405438,0.),\nvec3(-0.248268,-0.814753,0.),\nvec3(0.354411,-0.887570,0.),\nvec3(0.175817,0.382366,0.),\nvec3(0.487472,-0.063082,0.),\nvec3(-0.084078,0.898312,0.),\nvec3(0.488876,-0.783441,0.),\nvec3(0.470016,0.217933,0.),\nvec3(-0.696890,-0.549791,0.),\nvec3(-0.149693,0.605762,0.),\nvec3(0.034211,0.979980,0.),\nvec3(0.503098,-0.308878,0.),\nvec3(-0.016205,-0.872921,0.),\nvec3(0.385784,-0.393902,0.),\nvec3(-0.146886,-0.859249,0.),\nvec3(0.643361,0.164098,0.),\nvec3(0.634388,-0.049471,0.),\nvec3(-0.688894,0.007843,0.),\nvec3(0.464034,-0.188818,0.),\nvec3(-0.440840,0.137486,0.),\nvec3(0.364483,0.511704,0.),\nvec3(0.034028,0.325968,0.),\nvec3(0.099094,-0.308023,0.),\nvec3(0.693960,-0.366253,0.),\nvec3(0.678884,-0.204688,0.),\nvec3(0.001801,0.780328,0.),\nvec3(0.145177,-0.898984,0.),\nvec3(0.062655,-0.611866,0.),\nvec3(0.315226,-0.604297,0.),\nvec3(-0.780145,0.486251,0.),\nvec3(-0.371868,0.882138,0.),\nvec3(0.200476,0.494430,0.),\nvec3(-0.494552,-0.711051,0.),\nvec3(0.612476,0.705252,0.),\nvec3(-0.578845,-0.768792,0.),\nvec3(-0.772454,-0.090976,0.),\nvec3(0.504440,0.372295,0.),\nvec3(0.155736,0.065157,0.),\nvec3(0.391522,0.849605,0.),\nvec3(-0.620106,-0.328104,0.),\nvec3(0.789239,-0.419965,0.),\nvec3(-0.545396,0.538133,0.),\nvec3(-0.178564,-0.596057,0.)\n);\n\n\n\n\n\nfloat computeShadowWithPCSS(vec4 vPositionFromLight,float depthMetric,sampler2D depthSampler,sampler2DShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff,int searchTapCount,int pcfTapCount,vec3[64] poissonSamplers)\n{\nif (depthMetric>1.0 || depthMetric<0.0) {\nreturn 1.0;\n}\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));\nfloat blockerDepth=0.0;\nfloat sumBlockerDepth=0.0;\nfloat numBlocker=0.0;\nfor (int i=0; icurrRayHeight)\n{\nfloat delta1=currSampledHeight-currRayHeight;\nfloat delta2=(currRayHeight+stepSize)-lastSampledHeight;\nfloat ratio=delta1/(delta1+delta2);\nvCurrOffset=(ratio)* vLastOffset+(1.0-ratio)*vCurrOffset;\n\nbreak;\n}\nelse\n{\ncurrRayHeight-=stepSize;\nvLastOffset=vCurrOffset;\nvCurrOffset+=stepSize*vMaxOffset;\nlastSampledHeight=currSampledHeight;\n}\n}\nreturn vCurrOffset;\n}\nvec2 parallaxOffset(vec3 viewDir,float heightScale)\n{\n\nfloat height=texture2D(bumpSampler,vBumpUV).w;\nvec2 texCoordOffset=heightScale*viewDir.xy*height;\nreturn -texCoordOffset;\n}\n#endif\n#endif",clipPlaneFragmentDeclaration:"#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif\n#ifdef CLIPPLANE2\nvarying float fClipDistance2;\n#endif\n#ifdef CLIPPLANE3\nvarying float fClipDistance3;\n#endif\n#ifdef CLIPPLANE4\nvarying float fClipDistance4;\n#endif",fogFragmentDeclaration:"#ifdef FOG\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nvarying vec3 vFogDistance;\nfloat CalcFogFactor()\n{\nfloat fogCoeff=1.0;\nfloat fogStart=vFogInfos.y;\nfloat fogEnd=vFogInfos.z;\nfloat fogDensity=vFogInfos.w;\nfloat fogDistance=length(vFogDistance);\nif (FOGMODE_LINEAR == vFogInfos.x)\n{\nfogCoeff=(fogEnd-fogDistance)/(fogEnd-fogStart);\n}\nelse if (FOGMODE_EXP == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fogDistance*fogDensity);\n}\nelse if (FOGMODE_EXP2 == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fogDistance*fogDistance*fogDensity*fogDensity);\n}\nreturn clamp(fogCoeff,0.0,1.0);\n}\n#endif",clipPlaneFragment:"#ifdef CLIPPLANE\nif (fClipDistance>0.0)\n{\ndiscard;\n}\n#endif\n#ifdef CLIPPLANE2\nif (fClipDistance2>0.0)\n{\ndiscard;\n}\n#endif\n#ifdef CLIPPLANE3\nif (fClipDistance3>0.0)\n{\ndiscard;\n}\n#endif\n#ifdef CLIPPLANE4\nif (fClipDistance4>0.0)\n{\ndiscard;\n}\n#endif",bumpFragment:"vec2 uvOffset=vec2(0.0,0.0);\n#if defined(BUMP) || defined(PARALLAX)\n#ifdef NORMALXYSCALE\nfloat normalScale=1.0;\n#else \nfloat normalScale=vBumpInfos.y;\n#endif\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBN=vTBN;\n#else\nmat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,vBumpUV);\n#endif\n#endif\n#ifdef PARALLAX\nmat3 invTBN=transposeMat3(TBN);\n#ifdef PARALLAXOCCLUSION\nuvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,vBumpUV,vBumpInfos.z);\n#else\nuvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);\n#endif\n#endif\n#ifdef BUMP\n#ifdef OBJECTSPACE_NORMALMAP\nnormalW=normalize(texture2D(bumpSampler,vBumpUV).xyz*2.0-1.0);\nnormalW=normalize(mat3(normalMatrix)*normalW); \n#else\nnormalW=perturbNormal(TBN,vBumpUV+uvOffset);\n#endif\n#endif",lightFragment:"#ifdef LIGHT{X}\n#if defined(SHADOWONLY) || (defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X}) && defined(LIGHTMAPNOSPECULAR{X}))\n\n#else\n#ifdef PBR\n#ifdef SPOTLIGHT{X}\nspotInfo=computeSpotLightingInfo(light{X}.vLightData);\n#ifdef LIGHT_FALLOFF_GLTF{X}\nspotInfo.attenuation=computeDistanceLightFalloff_GLTF(spotInfo.lightDistanceSquared,light{X}.vLightFalloff.y);\nspotInfo.attenuation*=computeDirectionalLightFalloff_GLTF(light{X}.vLightDirection.xyz,spotInfo.directionToLightCenterW,light{X}.vLightFalloff.z,light{X}.vLightFalloff.w);\n#elif defined(LIGHT_FALLOFF_PHYSICAL{X})\nspotInfo.attenuation=computeDistanceLightFalloff_Physical(spotInfo.lightDistanceSquared);\nspotInfo.attenuation*=computeDirectionalLightFalloff_Physical(light{X}.vLightDirection.xyz,spotInfo.directionToLightCenterW,light{X}.vLightDirection.w);\n#elif defined(LIGHT_FALLOFF_STANDARD{X})\nspotInfo.attenuation=computeDistanceLightFalloff_Standard(spotInfo.lightOffset,light{X}.vLightFalloff.x);\nspotInfo.attenuation*=computeDirectionalLightFalloff_Standard(light{X}.vLightDirection.xyz,spotInfo.directionToLightCenterW,light{X}.vLightDirection.w,light{X}.vLightData.w);\n#else\nspotInfo.attenuation=computeDistanceLightFalloff(spotInfo.lightOffset,spotInfo.lightDistanceSquared,light{X}.vLightFalloff.x,light{X}.vLightFalloff.y);\nspotInfo.attenuation*=computeDirectionalLightFalloff(light{X}.vLightDirection.xyz,spotInfo.directionToLightCenterW,light{X}.vLightDirection.w,light{X}.vLightData.w,light{X}.vLightFalloff.z,light{X}.vLightFalloff.w);\n#endif\ninfo=computeSpotLighting(spotInfo,viewDirectionW,normalW,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);\n#elif defined(POINTLIGHT{X})\npointInfo=computePointLightingInfo(light{X}.vLightData);\n#ifdef LIGHT_FALLOFF_GLTF{X}\npointInfo.attenuation=computeDistanceLightFalloff_GLTF(pointInfo.lightDistanceSquared,light{X}.vLightFalloff.y);\n#elif defined(LIGHT_FALLOFF_PHYSICAL{X})\npointInfo.attenuation=computeDistanceLightFalloff_Physical(pointInfo.lightDistanceSquared);\n#elif defined(LIGHT_FALLOFF_STANDARD{X})\npointInfo.attenuation=computeDistanceLightFalloff_Standard(pointInfo.lightOffset,light{X}.vLightFalloff.x);\n#else\npointInfo.attenuation=computeDistanceLightFalloff(pointInfo.lightOffset,pointInfo.lightDistanceSquared,light{X}.vLightFalloff.x,light{X}.vLightFalloff.y);\n#endif\ninfo=computePointLighting(pointInfo,viewDirectionW,normalW,light{X}.vLightDiffuse.rgb,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);\n#elif defined(HEMILIGHT{X})\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightGround,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);\n#elif defined(DIRLIGHT{X})\ninfo=computeDirectionalLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);\n#endif\n#else\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,glossiness);\n#elif defined(HEMILIGHT{X})\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightGround,glossiness);\n#elif defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,glossiness);\n#endif\n#endif\n#ifdef PROJECTEDLIGHTTEXTURE{X}\ninfo.diffuse*=computeProjectionTextureDiffuseLighting(projectionLightSampler{X},textureProjectionMatrix{X});\n#endif\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWCLOSEESM{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithCloseESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithCloseESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWESM{X})\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWPOISSON{X})\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithPoissonSamplingCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadowWithPoissonSampling(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWPCF{X})\n#if defined(SHADOWLOWQUALITY{X})\nshadow=computeShadowWithPCF1(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#elif defined(SHADOWMEDIUMQUALITY{X})\nshadow=computeShadowWithPCF3(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#else\nshadow=computeShadowWithPCF5(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWPCSS{X})\n#if defined(SHADOWLOWQUALITY{X})\nshadow=computeShadowWithPCSS16(vPositionFromLight{X},vDepthMetric{X},depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#elif defined(SHADOWMEDIUMQUALITY{X})\nshadow=computeShadowWithPCSS32(vPositionFromLight{X},vDepthMetric{X},depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#else\nshadow=computeShadowWithPCSS64(vPositionFromLight{X},vDepthMetric{X},depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#else\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadow(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#endif\n#ifdef SHADOWONLY\n#ifndef SHADOWINUSE\n#define SHADOWINUSE\n#endif\nglobalShadow+=shadow;\nshadowLightCount+=1.0;\n#endif\n#else\nshadow=1.;\n#endif\n#ifndef SHADOWONLY\n#ifdef CUSTOMUSERLIGHTING\ndiffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);\n#ifdef SPECULARTERM\nspecularBase+=computeCustomSpecularLighting(info,specularBase,shadow);\n#endif\n#elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X})\ndiffuseBase+=lightmapColor*shadow;\n#ifdef SPECULARTERM\n#ifndef LIGHTMAPNOSPECULAR{X}\nspecularBase+=info.specular*shadow*lightmapColor;\n#endif\n#endif\n#else\ndiffuseBase+=info.diffuse*shadow;\n#ifdef SPECULARTERM\nspecularBase+=info.specular*shadow;\n#endif\n#endif\n#endif\n#endif",logDepthFragment:"#ifdef LOGARITHMICDEPTH\ngl_FragDepthEXT=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;\n#endif",fogFragment:"#ifdef FOG\nfloat fog=CalcFogFactor();\ncolor.rgb=fog*color.rgb+(1.0-fog)*vFogColor;\n#endif",pbrVertexDeclaration:"uniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef ALBEDO\nuniform mat4 albedoMatrix;\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;\nuniform vec4 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\nuniform mat4 lightmapMatrix;\n#endif\n#ifdef REFLECTIVITY \nuniform vec3 vReflectivityInfos;\nuniform mat4 reflectivityMatrix;\n#endif\n#ifdef MICROSURFACEMAP\nuniform vec2 vMicroSurfaceSamplerInfos;\nuniform mat4 microSurfaceSamplerMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\nuniform mat4 refractionMatrix;\nuniform vec3 vRefractionMicrosurfaceInfos;\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionMicrosurfaceInfos;\n#endif\n",pbrFragmentDeclaration:"uniform vec3 vReflectionColor;\nuniform vec4 vAlbedoColor;\n\nuniform vec4 vLightingIntensity;\nuniform vec4 vReflectivityColor;\nuniform vec3 vEmissiveColor;\n\n#ifdef ALBEDO\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nuniform vec4 vAmbientInfos;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform vec2 vTangentSpaceParams;\n#endif\n#ifdef OPACITY \nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\n#endif\n#ifdef REFLECTIVITY\nuniform vec3 vReflectivityInfos;\n#endif\n#ifdef MICROSURFACEMAP\nuniform vec2 vMicroSurfaceSamplerInfos;\n#endif\n\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\n#endif\n\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\nuniform mat4 refractionMatrix;\nuniform vec3 vRefractionMicrosurfaceInfos;\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionMicrosurfaceInfos;\n#if defined(USE_LOCAL_REFLECTIONMAP_CUBIC) && defined(REFLECTIONMAP_CUBIC)\nuniform vec3 vReflectionPosition;\nuniform vec3 vReflectionSize; \n#endif\n#endif",pbrUboDeclaration:"layout(std140,column_major) uniform;\nuniform Material\n{\nuniform vec2 vAlbedoInfos;\nuniform vec4 vAmbientInfos;\nuniform vec2 vOpacityInfos;\nuniform vec2 vEmissiveInfos;\nuniform vec2 vLightmapInfos;\nuniform vec3 vReflectivityInfos;\nuniform vec2 vMicroSurfaceSamplerInfos;\nuniform vec4 vRefractionInfos;\nuniform vec2 vReflectionInfos;\nuniform vec3 vReflectionPosition;\nuniform vec3 vReflectionSize; \nuniform vec3 vBumpInfos;\nuniform mat4 albedoMatrix;\nuniform mat4 ambientMatrix;\nuniform mat4 opacityMatrix;\nuniform mat4 emissiveMatrix;\nuniform mat4 lightmapMatrix;\nuniform mat4 reflectivityMatrix;\nuniform mat4 microSurfaceSamplerMatrix;\nuniform mat4 bumpMatrix;\nuniform vec2 vTangentSpaceParams;\nuniform mat4 refractionMatrix;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionColor;\nuniform vec4 vAlbedoColor;\nuniform vec4 vLightingIntensity;\nuniform vec3 vRefractionMicrosurfaceInfos;\nuniform vec3 vReflectionMicrosurfaceInfos;\nuniform vec4 vReflectivityColor;\nuniform vec3 vEmissiveColor;\nuniform float pointSize;\n};\nuniform Scene {\nmat4 viewProjection;\nmat4 view;\n};",pbrFunctions:"\n#define RECIPROCAL_PI2 0.15915494\n#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\n\nconst float kRougnhessToAlphaScale=0.1;\nconst float kRougnhessToAlphaOffset=0.29248125;\nfloat convertRoughnessToAverageSlope(float roughness)\n{\n\nconst float kMinimumVariance=0.0005;\nfloat alphaG=square(roughness)+kMinimumVariance;\nreturn alphaG;\n}\n\nfloat smithVisibilityG1_TrowbridgeReitzGGX(float dot,float alphaG)\n{\nfloat tanSquared=(1.0-dot*dot)/(dot*dot);\nreturn 2.0/(1.0+sqrt(1.0+alphaG*alphaG*tanSquared));\n}\nfloat smithVisibilityG_TrowbridgeReitzGGX_Walter(float NdotL,float NdotV,float alphaG)\n{\nreturn smithVisibilityG1_TrowbridgeReitzGGX(NdotL,alphaG)*smithVisibilityG1_TrowbridgeReitzGGX(NdotV,alphaG);\n}\n\n\nfloat normalDistributionFunction_TrowbridgeReitzGGX(float NdotH,float alphaG)\n{\n\n\n\nfloat a2=square(alphaG);\nfloat d=NdotH*NdotH*(a2-1.0)+1.0;\nreturn a2/(PI*d*d);\n}\nvec3 fresnelSchlickGGX(float VdotH,vec3 reflectance0,vec3 reflectance90)\n{\nreturn reflectance0+(reflectance90-reflectance0)*pow(clamp(1.0-VdotH,0.,1.),5.0);\n}\nvec3 fresnelSchlickEnvironmentGGX(float VdotN,vec3 reflectance0,vec3 reflectance90,float smoothness)\n{\n\nfloat weight=mix(FRESNEL_MAXIMUM_ON_ROUGH,1.0,smoothness);\nreturn reflectance0+weight*(reflectance90-reflectance0)*pow(clamp(1.0-VdotN,0.,1.),5.0);\n}\n\nvec3 computeSpecularTerm(float NdotH,float NdotL,float NdotV,float VdotH,float roughness,vec3 reflectance0,vec3 reflectance90,float geometricRoughnessFactor)\n{\nroughness=max(roughness,geometricRoughnessFactor);\nfloat alphaG=convertRoughnessToAverageSlope(roughness);\nfloat distribution=normalDistributionFunction_TrowbridgeReitzGGX(NdotH,alphaG);\nfloat visibility=smithVisibilityG_TrowbridgeReitzGGX_Walter(NdotL,NdotV,alphaG);\nvisibility/=(4.0*NdotL*NdotV); \nfloat specTerm=max(0.,visibility*distribution)*NdotL;\nvec3 fresnel=fresnelSchlickGGX(VdotH,reflectance0,reflectance90);\nreturn fresnel*specTerm;\n}\nfloat computeDiffuseTerm(float NdotL,float NdotV,float VdotH,float roughness)\n{\n\n\nfloat diffuseFresnelNV=pow(clamp(1.0-NdotL,0.000001,1.),5.0);\nfloat diffuseFresnelNL=pow(clamp(1.0-NdotV,0.000001,1.),5.0);\nfloat diffuseFresnel90=0.5+2.0*VdotH*VdotH*roughness;\nfloat fresnel =\n(1.0+(diffuseFresnel90-1.0)*diffuseFresnelNL) *\n(1.0+(diffuseFresnel90-1.0)*diffuseFresnelNV);\nreturn fresnel*NdotL/PI;\n}\nfloat adjustRoughnessFromLightProperties(float roughness,float lightRadius,float lightDistance)\n{\n#if defined(USEPHYSICALLIGHTFALLOFF) || defined(USEGLTFLIGHTFALLOFF)\n\nfloat lightRoughness=lightRadius/lightDistance;\n\nfloat totalRoughness=clamp(lightRoughness+roughness,0.,1.);\nreturn totalRoughness;\n#else\nreturn roughness;\n#endif\n}\nfloat computeDefaultMicroSurface(float microSurface,vec3 reflectivityColor)\n{\nconst float kReflectivityNoAlphaWorkflow_SmoothnessMax=0.95;\nfloat reflectivityLuminance=getLuminance(reflectivityColor);\nfloat reflectivityLuma=sqrt(reflectivityLuminance);\nmicroSurface=reflectivityLuma*kReflectivityNoAlphaWorkflow_SmoothnessMax;\nreturn microSurface;\n}\n\n\nfloat fresnelGrazingReflectance(float reflectance0) {\nfloat reflectance90=clamp(reflectance0*25.0,0.0,1.0);\nreturn reflectance90;\n}\n\n\n#define UNPACK_LOD(x) (1.0-x)*255.0\nfloat getLodFromAlphaG(float cubeMapDimensionPixels,float alphaG,float NdotV) {\nfloat microsurfaceAverageSlope=alphaG;\n\n\n\n\n\n\nmicrosurfaceAverageSlope*=sqrt(abs(NdotV));\nfloat microsurfaceAverageSlopeTexels=microsurfaceAverageSlope*cubeMapDimensionPixels;\nfloat lod=log2(microsurfaceAverageSlopeTexels);\nreturn lod;\n}\nfloat environmentRadianceOcclusion(float ambientOcclusion,float NdotVUnclamped) {\n\n\nfloat temp=NdotVUnclamped+ambientOcclusion;\nreturn clamp(square(temp)-1.0+ambientOcclusion,0.0,1.0);\n}\nfloat environmentHorizonOcclusion(vec3 view,vec3 normal) {\n\nvec3 reflection=reflect(view,normal);\nfloat temp=clamp( 1.0+1.1*dot(reflection,normal),0.0,1.0);\nreturn square(temp);\n}",harmonicsFunctions:"#ifdef USESPHERICALFROMREFLECTIONMAP\nuniform vec3 vSphericalX;\nuniform vec3 vSphericalY;\nuniform vec3 vSphericalZ;\nuniform vec3 vSphericalXX_ZZ;\nuniform vec3 vSphericalYY_ZZ;\nuniform vec3 vSphericalZZ;\nuniform vec3 vSphericalXY;\nuniform vec3 vSphericalYZ;\nuniform vec3 vSphericalZX;\nvec3 quaternionVectorRotation_ScaledSqrtTwo(vec4 Q,vec3 V){\nvec3 T=cross(Q.xyz,V);\nT+=Q.www*V;\nreturn cross(Q.xyz,T)+V;\n}\nvec3 environmentIrradianceJones(vec3 normal)\n{\n\n\n\n\n\n\n\n\n\nfloat Nx=normal.x;\nfloat Ny=normal.y;\nfloat Nz=normal.z;\nvec3 C1=vSphericalZZ.rgb;\nvec3 Cx=vSphericalX.rgb;\nvec3 Cy=vSphericalY.rgb;\nvec3 Cz=vSphericalZ.rgb;\nvec3 Cxx_zz=vSphericalXX_ZZ.rgb;\nvec3 Cyy_zz=vSphericalYY_ZZ.rgb;\nvec3 Cxy=vSphericalXY.rgb;\nvec3 Cyz=vSphericalYZ.rgb;\nvec3 Czx=vSphericalZX.rgb;\nvec3 a1=Cyy_zz*Ny+Cy;\nvec3 a2=Cyz*Nz+a1;\nvec3 b1=Czx*Nz+Cx;\nvec3 b2=Cxy*Ny+b1;\nvec3 b3=Cxx_zz*Nx+b2;\nvec3 t1=Cz*Nz+C1;\nvec3 t2=a2*Ny+t1;\nvec3 t3=b3*Nx+t2;\nreturn t3;\n}\n#endif",pbrLightFunctions:"\nstruct lightingInfo\n{\nvec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n};\nstruct pointLightingInfo\n{\nvec3 lightOffset;\nfloat lightDistanceSquared;\nfloat attenuation;\n};\nstruct spotLightingInfo\n{\nvec3 lightOffset;\nfloat lightDistanceSquared;\nvec3 directionToLightCenterW;\nfloat attenuation;\n};\nfloat computeDistanceLightFalloff_Standard(vec3 lightOffset,float range)\n{\nreturn max(0.,1.0-length(lightOffset)/range);\n}\nfloat computeDistanceLightFalloff_Physical(float lightDistanceSquared)\n{\nreturn 1.0/((lightDistanceSquared+0.001));\n}\nfloat computeDistanceLightFalloff_GLTF(float lightDistanceSquared,float inverseSquaredRange)\n{\nconst float minDistanceSquared=0.01*0.01;\nfloat lightDistanceFalloff=1.0/(max(lightDistanceSquared,minDistanceSquared));\nfloat factor=lightDistanceSquared*inverseSquaredRange;\nfloat attenuation=clamp(1.0-factor*factor,0.,1.);\nattenuation*=attenuation;\n\nlightDistanceFalloff*=attenuation;\nreturn lightDistanceFalloff;\n}\nfloat computeDistanceLightFalloff(vec3 lightOffset,float lightDistanceSquared,float range,float inverseSquaredRange)\n{ \n#ifdef USEPHYSICALLIGHTFALLOFF\nreturn computeDistanceLightFalloff_Physical(lightDistanceSquared);\n#elif defined(USEGLTFLIGHTFALLOFF)\nreturn computeDistanceLightFalloff_GLTF(lightDistanceSquared,inverseSquaredRange);\n#else\nreturn computeDistanceLightFalloff_Standard(lightOffset,range);\n#endif\n}\nfloat computeDirectionalLightFalloff_Standard(vec3 lightDirection,vec3 directionToLightCenterW,float cosHalfAngle,float exponent)\n{\nfloat falloff=0.0;\nfloat cosAngle=max(0.000000000000001,dot(-lightDirection,directionToLightCenterW));\nif (cosAngle>=cosHalfAngle)\n{\nfalloff=max(0.,pow(cosAngle,exponent));\n}\nreturn falloff;\n}\nfloat computeDirectionalLightFalloff_Physical(vec3 lightDirection,vec3 directionToLightCenterW,float cosHalfAngle)\n{\nconst float kMinusLog2ConeAngleIntensityRatio=6.64385618977; \n\n\n\n\n\nfloat concentrationKappa=kMinusLog2ConeAngleIntensityRatio/(1.0-cosHalfAngle);\n\n\nvec4 lightDirectionSpreadSG=vec4(-lightDirection*concentrationKappa,-concentrationKappa);\nfloat falloff=exp2(dot(vec4(directionToLightCenterW,1.0),lightDirectionSpreadSG));\nreturn falloff;\n}\nfloat computeDirectionalLightFalloff_GLTF(vec3 lightDirection,vec3 directionToLightCenterW,float lightAngleScale,float lightAngleOffset)\n{\n\n\n\nfloat cd=dot(-lightDirection,directionToLightCenterW);\nfloat falloff=clamp(cd*lightAngleScale+lightAngleOffset,0.,1.);\n\nfalloff*=falloff;\nreturn falloff;\n}\nfloat computeDirectionalLightFalloff(vec3 lightDirection,vec3 directionToLightCenterW,float cosHalfAngle,float exponent,float lightAngleScale,float lightAngleOffset)\n{\n#ifdef USEPHYSICALLIGHTFALLOFF\nreturn computeDirectionalLightFalloff_Physical(lightDirection,directionToLightCenterW,cosHalfAngle);\n#elif defined(USEGLTFLIGHTFALLOFF)\nreturn computeDirectionalLightFalloff_GLTF(lightDirection,directionToLightCenterW,lightAngleScale,lightAngleOffset);\n#else\nreturn computeDirectionalLightFalloff_Standard(lightDirection,directionToLightCenterW,cosHalfAngle,exponent);\n#endif\n}\npointLightingInfo computePointLightingInfo(vec4 lightData) {\npointLightingInfo result;\nresult.lightOffset=lightData.xyz-vPositionW;\nresult.lightDistanceSquared=dot(result.lightOffset,result.lightOffset);\nreturn result;\n}\nspotLightingInfo computeSpotLightingInfo(vec4 lightData) {\nspotLightingInfo result;\nresult.lightOffset=lightData.xyz-vPositionW;\nresult.directionToLightCenterW=normalize(result.lightOffset);\nresult.lightDistanceSquared=dot(result.lightOffset,result.lightOffset);\nreturn result;\n}\nlightingInfo computePointLighting(pointLightingInfo info,vec3 viewDirectionW,vec3 vNormal,vec3 diffuseColor,float lightRadius,float roughness,float NdotV,vec3 reflectance0,vec3 reflectance90,float geometricRoughnessFactor,out float NdotL) {\nlightingInfo result;\nfloat lightDistance=sqrt(info.lightDistanceSquared);\nvec3 lightDirection=normalize(info.lightOffset);\n\nroughness=adjustRoughnessFromLightProperties(roughness,lightRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW+lightDirection);\nNdotL=clamp(dot(vNormal,lightDirection),0.00000000001,1.0);\nfloat VdotH=clamp(dot(viewDirectionW,H),0.0,1.0);\nfloat diffuseTerm=computeDiffuseTerm(NdotL,NdotV,VdotH,roughness);\nresult.diffuse=diffuseTerm*diffuseColor*info.attenuation;\n#ifdef SPECULARTERM\n\nfloat NdotH=clamp(dot(vNormal,H),0.000000000001,1.0);\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,reflectance0,reflectance90,geometricRoughnessFactor);\nresult.specular=specTerm*diffuseColor*info.attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeSpotLighting(spotLightingInfo info,vec3 viewDirectionW,vec3 vNormal,vec4 lightDirection,vec3 diffuseColor,float lightRadius,float roughness,float NdotV,vec3 reflectance0,vec3 reflectance90,float geometricRoughnessFactor,out float NdotL) {\nlightingInfo result;\n\nfloat lightDistance=sqrt(info.lightDistanceSquared);\nroughness=adjustRoughnessFromLightProperties(roughness,lightRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW+info.directionToLightCenterW);\nNdotL=clamp(dot(vNormal,info.directionToLightCenterW),0.000000000001,1.0);\nfloat VdotH=clamp(dot(viewDirectionW,H),0.0,1.0);\nfloat diffuseTerm=computeDiffuseTerm(NdotL,NdotV,VdotH,roughness);\nresult.diffuse=diffuseTerm*diffuseColor*info.attenuation;\n#ifdef SPECULARTERM\n\nfloat NdotH=clamp(dot(vNormal,H),0.000000000001,1.0);\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,reflectance0,reflectance90,geometricRoughnessFactor);\nresult.specular=specTerm*diffuseColor*info.attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeDirectionalLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float lightRadius,float roughness,float NdotV,vec3 reflectance0,vec3 reflectance90,float geometricRoughnessFactor,out float NdotL) {\nlightingInfo result;\nfloat lightDistance=length(-lightData.xyz);\nvec3 lightDirection=normalize(-lightData.xyz);\n\nroughness=adjustRoughnessFromLightProperties(roughness,lightRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW+lightDirection);\nNdotL=clamp(dot(vNormal,lightDirection),0.00000000001,1.0);\nfloat VdotH=clamp(dot(viewDirectionW,H),0.0,1.0);\nfloat diffuseTerm=computeDiffuseTerm(NdotL,NdotV,VdotH,roughness);\nresult.diffuse=diffuseTerm*diffuseColor;\n#ifdef SPECULARTERM\n\nfloat NdotH=clamp(dot(vNormal,H),0.000000000001,1.0);\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,reflectance0,reflectance90,geometricRoughnessFactor);\nresult.specular=specTerm*diffuseColor;\n#endif\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float roughness,float NdotV,vec3 reflectance0,vec3 reflectance90,float geometricRoughnessFactor,out float NdotL) {\nlightingInfo result;\n\n\n\nNdotL=dot(vNormal,lightData.xyz)*0.5+0.5;\nresult.diffuse=mix(groundColor,diffuseColor,NdotL);\n#ifdef SPECULARTERM\n\nvec3 lightVectorW=normalize(lightData.xyz);\nvec3 H=normalize(viewDirectionW+lightVectorW);\nfloat NdotH=clamp(dot(vNormal,H),0.000000000001,1.0);\nNdotL=clamp(NdotL,0.000000000001,1.0);\nfloat VdotH=clamp(dot(viewDirectionW,H),0.0,1.0);\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,reflectance0,reflectance90,geometricRoughnessFactor);\nresult.specular=specTerm*diffuseColor;\n#endif\nreturn result;\n}\nvec3 computeProjectionTextureDiffuseLighting(sampler2D projectionLightSampler,mat4 textureProjectionMatrix){\nvec4 strq=textureProjectionMatrix*vec4(vPositionW,1.0);\nstrq/=strq.w;\nvec3 textureColor=texture2D(projectionLightSampler,strq.xy).rgb;\nreturn toLinearSpace(textureColor);\n}",clipPlaneVertexDeclaration2:"#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nout float fClipDistance;\n#endif\n#ifdef CLIPPLANE2\nuniform vec4 vClipPlane2;\nout float fClipDistance2;\n#endif\n#ifdef CLIPPLANE3\nuniform vec4 vClipPlane3;\nout float fClipDistance3;\n#endif\n#ifdef CLIPPLANE4\nuniform vec4 vClipPlane4;\nout float fClipDistance4;\n#endif",clipPlaneFragmentDeclaration2:"#ifdef CLIPPLANE\nin float fClipDistance;\n#endif\n#ifdef CLIPPLANE2\nin float fClipDistance2;\n#endif\n#ifdef CLIPPLANE3\nin float fClipDistance3;\n#endif\n#ifdef CLIPPLANE4\nin float fClipDistance4;\n#endif",mrtFragmentDeclaration:"#if __VERSION__>=200\nlayout(location=0) out vec4 glFragData[{X}];\n#endif\n",bones300Declaration:"#if NUM_BONE_INFLUENCERS>0\nuniform mat4 mBones[BonesPerMesh];\nin vec4 matricesIndices;\nin vec4 matricesWeights;\n#if NUM_BONE_INFLUENCERS>4\nin vec4 matricesIndicesExtra;\nin vec4 matricesWeightsExtra;\n#endif\n#endif",instances300Declaration:"#ifdef INSTANCES\nin vec4 world0;\nin vec4 world1;\nin vec4 world2;\nin vec4 world3;\n#else\nuniform mat4 world;\n#endif",kernelBlurFragment:"#ifdef DOF\nfactor=sampleCoC(sampleCoord{X}); \ncomputedWeight=KERNEL_WEIGHT{X}*factor;\nsumOfWeights+=computedWeight;\n#else\ncomputedWeight=KERNEL_WEIGHT{X};\n#endif\n#ifdef PACKEDFLOAT\nblend+=unpack(texture2D(textureSampler,sampleCoord{X}))*computedWeight;\n#else\nblend+=texture2D(textureSampler,sampleCoord{X})*computedWeight;\n#endif",kernelBlurFragment2:"#ifdef DOF\nfactor=sampleCoC(sampleCenter+delta*KERNEL_DEP_OFFSET{X});\ncomputedWeight=KERNEL_DEP_WEIGHT{X}*factor;\nsumOfWeights+=computedWeight;\n#else\ncomputedWeight=KERNEL_DEP_WEIGHT{X};\n#endif\n#ifdef PACKEDFLOAT\nblend+=unpack(texture2D(textureSampler,sampleCenter+delta*KERNEL_DEP_OFFSET{X}))*computedWeight;\n#else\nblend+=texture2D(textureSampler,sampleCenter+delta*KERNEL_DEP_OFFSET{X})*computedWeight;\n#endif",kernelBlurVaryingDeclaration:"varying vec2 sampleCoord{X};",kernelBlurVertex:"sampleCoord{X}=sampleCenter+delta*KERNEL_OFFSET{X};",backgroundVertexDeclaration:"uniform mat4 view;\nuniform mat4 viewProjection;\nuniform float shadowLevel;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionMicrosurfaceInfos;\nuniform float fFovMultiplier;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif",backgroundFragmentDeclaration:" uniform vec4 vPrimaryColor;\n#ifdef USEHIGHLIGHTANDSHADOWCOLORS\nuniform vec4 vPrimaryColorShadow;\n#endif\nuniform float shadowLevel;\nuniform float alpha;\n#ifdef DIFFUSE\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionMicrosurfaceInfos;\n#endif\n#if defined(REFLECTIONFRESNEL) || defined(OPACITYFRESNEL)\nuniform vec3 vBackgroundCenter;\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 vReflectionControl;\n#endif\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\n#endif",backgroundUboDeclaration:"layout(std140,column_major) uniform;\nuniform Material\n{\nuniform vec4 vPrimaryColor;\nuniform vec4 vPrimaryColorShadow;\nuniform vec2 vDiffuseInfos;\nuniform vec2 vReflectionInfos;\nuniform mat4 diffuseMatrix;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionMicrosurfaceInfos;\nuniform float fFovMultiplier;\nuniform float pointSize;\nuniform float shadowLevel;\nuniform float alpha;\n#if defined(REFLECTIONFRESNEL) || defined(OPACITYFRESNEL)\nuniform vec3 vBackgroundCenter;\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 vReflectionControl;\n#endif\n};\nuniform Scene {\nmat4 viewProjection;\nmat4 view;\n};"},$a.CollisionWorker='var BABYLON;!function(D){var a,x=(a={root:0,found:!1},function(t,e,o,i){a.root=0,a.found=!1;var s=e*e-4*t*o;if(s<0)return a;var r=Math.sqrt(s),n=(-e-r)/(2*t),c=(-e+r)/(2*t);if(cthis._velocityWorldLength+a+e)&&(s=o,r=i,n=this._basePointWorld,c=this._velocityWorldLength+a,!(s.x>n.x+c||n.x-c>r.x||s.y>n.y+c||n.y-c>r.y||s.z>n.z+c||n.z-c>r.z))},t.prototype._testTriangle=function(t,e,o,i,s,r){var n,c=!1;e||(e=[]),e[t]||(e[t]=new D.Plane(0,0,0,0),e[t].copyFromPoints(o,i,s));var h=e[t];if(r||h.isFrontFacingTo(this._normalizedVelocity,0)){var a=h.signedDistanceTo(this._basePoint),l=D.Vector3.Dot(h.normal,this._velocity);if(0==l){if(1<=Math.abs(a))return;c=!0,n=0}else{var _=(1-a)/l;if(_<(n=(-1-a)/l)){var d=_;_=n,n=d}if(1=i)this.finalPosition.copyFrom(e);else{this.collider._initialize(e,o,.01);for(var t,s=this._collisionCache.getMeshes(),l=Object.keys(s),n=l.length,a=0;a=t)r.copyFrom(e);else{var a=s?s.collisionMask:i.collisionMask;i._initialize(e,o,n);for(var d=0;dr.x?r.x:o)r.y?r.y:n)i.x?t.x:i.x,t.y>i.y?t.y:i.y)},y.Transform=function(t,i){var r=y.Zero();return y.TransformToRef(t,i,r),r},y.TransformToRef=function(t,i,r){var o=t.x*i.m[0]+t.y*i.m[4]+i.m[12],n=t.x*i.m[1]+t.y*i.m[5]+i.m[13];r.x=o,r.y=n},y.PointInTriangle=function(t,i,r,o){var n=.5*(-r.y*o.x+i.y*(-r.x+o.x)+i.x*(r.y-o.y)+r.x*o.y),e=n<0?-1:1,s=(i.y*o.x-i.x*o.y+(o.y-i.y)*t.x+(i.x-o.x)*t.y)*e,h=(i.x*r.y-i.y*r.x+(i.y-r.y)*t.x+(r.x-i.x)*t.y)*e;return 0this.x&&(this.x=t),i>this.y&&(this.y=i),r>this.z&&(this.z=r),this},Object.defineProperty(c.prototype,"isNonUniform",{get:function(){var t=Math.abs(this.x),i=Math.abs(this.y);if(t!==i)return!0;var r=Math.abs(this.z);return t!==r||i!==r},enumerable:!0,configurable:!0}),c.prototype.floor=function(){return new c(Math.floor(this.x),Math.floor(this.y),Math.floor(this.z))},c.prototype.fract=function(){return new c(this.x-Math.floor(this.x),this.y-Math.floor(this.y),this.z-Math.floor(this.z))},c.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},c.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},c.prototype.normalize=function(){var t=this.length();if(0===t||1===t)return this;var i=1/t;return this.x*=i,this.y*=i,this.z*=i,this},c.prototype.normalizeToNew=function(){var t=new c(0,0,0);return this.normalizeToRef(t),t},c.prototype.normalizeToRef=function(t){var i=this.length();if(0===i||1===i)return t.set(this.x,this.y,this.z),t;var r=1/i;return this.scaleToRef(r,t),t},c.prototype.clone=function(){return new c(this.x,this.y,this.z)},c.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},c.prototype.copyFromFloats=function(t,i,r){return this.x=t,this.y=i,this.z=r,this},c.prototype.set=function(t,i,r){return this.copyFromFloats(t,i,r)},c.GetClipFactor=function(t,i,r,o){var n=c.Dot(t,r)-o;return n/(n-(c.Dot(i,r)-o))},c.GetAngleBetweenVectors=function(t,i,r){var o=_.Vector3[1].copyFrom(t).normalize(),n=_.Vector3[2].copyFrom(i).normalize(),e=c.Dot(o,n),s=_.Vector3[3];return c.CrossToRef(o,n,s),0r.x?r.x:o)r.y?r.y:n)r.z?r.z:e)this.x&&(this.x=t.x),t.y>this.y&&(this.y=t.y),t.z>this.z&&(this.z=t.z),t.w>this.w&&(this.w=t.w),this},n.prototype.floor=function(){return new n(Math.floor(this.x),Math.floor(this.y),Math.floor(this.z),Math.floor(this.w))},n.prototype.fract=function(){return new n(this.x-Math.floor(this.x),this.y-Math.floor(this.y),this.z-Math.floor(this.z),this.w-Math.floor(this.w))},n.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},n.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},n.prototype.normalize=function(){var t=this.length();if(0===t)return this;var i=1/t;return this.x*=i,this.y*=i,this.z*=i,this.w*=i,this},n.prototype.toVector3=function(){return new l(this.x,this.y,this.z)},n.prototype.clone=function(){return new n(this.x,this.y,this.z,this.w)},n.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},n.prototype.copyFromFloats=function(t,i,r,o){return this.x=t,this.y=i,this.z=r,this.w=o,this},n.prototype.set=function(t,i,r,o){return this.copyFromFloats(t,i,r,o)},n.FromArray=function(t,i){return i||(i=0),new n(t[i],t[i+1],t[i+2],t[i+3])},n.FromArrayToRef=function(t,i,r){r.x=t[i],r.y=t[i+1],r.z=t[i+2],r.w=t[i+3]},n.FromFloatArrayToRef=function(t,i,r){n.FromArrayToRef(t,i,r)},n.FromFloatsToRef=function(t,i,r,o,n){n.x=t,n.y=i,n.z=r,n.w=o},n.Zero=function(){return new n(0,0,0,0)},n.One=function(){return new n(1,1,1,1)},n.Normalize=function(t){var i=n.Zero();return n.NormalizeToRef(t,i),i},n.NormalizeToRef=function(t,i){i.copyFrom(t),i.normalize()},n.Minimize=function(t,i){var r=t.clone();return r.minimizeInPlace(i),r},n.Maximize=function(t,i){var r=t.clone();return r.maximizeInPlace(i),r},n.Distance=function(t,i){return Math.sqrt(n.DistanceSquared(t,i))},n.DistanceSquared=function(t,i){var r=t.x-i.x,o=t.y-i.y,n=t.z-i.z,e=t.w-i.w;return r*r+o*o+n*n+e*e},n.Center=function(t,i){var r=t.add(i);return r.scaleInPlace(.5),r},n.TransformNormal=function(t,i){var r=n.Zero();return n.TransformNormalToRef(t,i,r),r},n.TransformNormalToRef=function(t,i,r){var o=t.x*i.m[0]+t.y*i.m[4]+t.z*i.m[8],n=t.x*i.m[1]+t.y*i.m[5]+t.z*i.m[9],e=t.x*i.m[2]+t.y*i.m[6]+t.z*i.m[10];r.x=o,r.y=n,r.z=e,r.w=t.w},n.TransformNormalFromFloatsToRef=function(t,i,r,o,n,e){e.x=t*n.m[0]+i*n.m[4]+r*n.m[8],e.y=t*n.m[1]+i*n.m[5]+r*n.m[9],e.z=t*n.m[2]+i*n.m[6]+r*n.m[10],e.w=o},n}();p.Vector4=o;var t=function(){function o(t,i){this.width=t,this.height=i}return o.prototype.toString=function(){return"{W: "+this.width+", H: "+this.height+"}"},o.prototype.getClassName=function(){return"Size"},o.prototype.getHashCode=function(){var t=this.width||0;return t=397*t^(this.height||0)},o.prototype.copyFrom=function(t){this.width=t.width,this.height=t.height},o.prototype.copyFromFloats=function(t,i){return this.width=t,this.height=i,this},o.prototype.set=function(t,i){return this.copyFromFloats(t,i)},o.prototype.multiplyByFloats=function(t,i){return new o(this.width*t,this.height*i)},o.prototype.clone=function(){return new o(this.width,this.height)},o.prototype.equals=function(t){return!!t&&(this.width===t.width&&this.height===t.height)},Object.defineProperty(o.prototype,"surface",{get:function(){return this.width*this.height},enumerable:!0,configurable:!0}),o.Zero=function(){return new o(0,0)},o.prototype.add=function(t){return new o(this.width+t.width,this.height+t.height)},o.prototype.subtract=function(t){return new o(this.width-t.width,this.height-t.height)},o.Lerp=function(t,i,r){return new o(t.width+(i.width-t.width)*r,t.height+(i.height-t.height)*r)},o}();p.Size=t;var x=function(){function y(t,i,r,o){void 0===t&&(t=0),void 0===i&&(i=0),void 0===r&&(r=0),void 0===o&&(o=1),this.x=t,this.y=i,this.z=r,this.w=o}return y.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+" W:"+this.w+"}"},y.prototype.getClassName=function(){return"Quaternion"},y.prototype.getHashCode=function(){var t=this.x||0;return t=397*(t=397*(t=397*t^(this.y||0))^(this.z||0))^(this.w||0)},y.prototype.asArray=function(){return[this.x,this.y,this.z,this.w]},y.prototype.equals=function(t){return t&&this.x===t.x&&this.y===t.y&&this.z===t.z&&this.w===t.w},y.prototype.clone=function(){return new y(this.x,this.y,this.z,this.w)},y.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},y.prototype.copyFromFloats=function(t,i,r,o){return this.x=t,this.y=i,this.z=r,this.w=o,this},y.prototype.set=function(t,i,r,o){return this.copyFromFloats(t,i,r,o)},y.prototype.add=function(t){return new y(this.x+t.x,this.y+t.y,this.z+t.z,this.w+t.w)},y.prototype.addInPlace=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this},y.prototype.subtract=function(t){return new y(this.x-t.x,this.y-t.y,this.z-t.z,this.w-t.w)},y.prototype.scale=function(t){return new y(this.x*t,this.y*t,this.z*t,this.w*t)},y.prototype.scaleToRef=function(t,i){return i.x=this.x*t,i.y=this.y*t,i.z=this.z*t,i.w=this.w*t,this},y.prototype.scaleInPlace=function(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},y.prototype.scaleAndAddToRef=function(t,i){return i.x+=this.x*t,i.y+=this.y*t,i.z+=this.z*t,i.w+=this.w*t,this},y.prototype.multiply=function(t){var i=new y(0,0,0,1);return this.multiplyToRef(t,i),i},y.prototype.multiplyToRef=function(t,i){var r=this.x*t.w+this.y*t.z-this.z*t.y+this.w*t.x,o=-this.x*t.z+this.y*t.w+this.z*t.x+this.w*t.y,n=this.x*t.y-this.y*t.x+this.z*t.w+this.w*t.z,e=-this.x*t.x-this.y*t.y-this.z*t.z+this.w*t.w;return i.copyFromFloats(r,o,n,e),this},y.prototype.multiplyInPlace=function(t){return this.multiplyToRef(t,this),this},y.prototype.conjugateToRef=function(t){return t.copyFromFloats(-this.x,-this.y,-this.z,this.w),this},y.prototype.conjugateInPlace=function(){return this.x*=-1,this.y*=-1,this.z*=-1,this},y.prototype.conjugate=function(){return new y(-this.x,-this.y,-this.z,this.w)},y.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},y.prototype.normalize=function(){var t=1/this.length();return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},y.prototype.toEulerAngles=function(t){void 0===t&&(t="YZX");var i=l.Zero();return this.toEulerAnglesToRef(i,t),i},y.prototype.toEulerAnglesToRef=function(t,i){void 0===i&&(i="YZX");var r=this.z,o=this.x,n=this.y,e=this.w,s=e*e,h=r*r,a=o*o,u=n*n,m=n*r-o*e;return m<-.4999999?(t.y=2*Math.atan2(n,e),t.x=Math.PI/2,t.z=0):.4999999