babylonjs.materials.js 284 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058
  1. (function universalModuleDefinition(root, factory) {
  2. var amdDependencies = [];
  3. var BABYLON = root.BABYLON || this.BABYLON;
  4. if(typeof exports === 'object' && typeof module === 'object') {
  5. BABYLON = BABYLON || require("babylonjs");
  6. module.exports = factory(BABYLON);
  7. } else if(typeof define === 'function' && define.amd) {
  8. amdDependencies.push("babylonjs");
  9. define("babylonjs-materials", amdDependencies, factory);
  10. } else if(typeof exports === 'object') {
  11. BABYLON = BABYLON || require("babylonjs");
  12. exports["babylonjs-materials"] = factory(BABYLON);
  13. } else {
  14. root["BABYLON"] = factory(BABYLON);
  15. }
  16. })(this, function(BABYLON) {
  17. BABYLON = BABYLON || this.BABYLON;
  18. var __decorate=this&&this.__decorate||function(e,t,r,c){var o,f=arguments.length,n=f<3?t:null===c?c=Object.getOwnPropertyDescriptor(t,r):c;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,c);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(n=(f<3?o(n):f>3?o(t,r,n):o(t,r))||n);return f>3&&n&&Object.defineProperty(t,r,n),n};
  19. var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o}||function(t,o){for(var n in o)o.hasOwnProperty(n)&&(t[n]=o[n])};return function(o,n){function r(){this.constructor=o}t(o,n),o.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();
  20. var BABYLON;
  21. (function (BABYLON) {
  22. var ShadowOnlyMaterialDefines = /** @class */ (function (_super) {
  23. __extends(ShadowOnlyMaterialDefines, _super);
  24. function ShadowOnlyMaterialDefines() {
  25. var _this = _super.call(this) || this;
  26. _this.CLIPPLANE = false;
  27. _this.CLIPPLANE2 = false;
  28. _this.CLIPPLANE3 = false;
  29. _this.CLIPPLANE4 = false;
  30. _this.POINTSIZE = false;
  31. _this.FOG = false;
  32. _this.NORMAL = false;
  33. _this.NUM_BONE_INFLUENCERS = 0;
  34. _this.BonesPerMesh = 0;
  35. _this.INSTANCES = false;
  36. _this.rebuild();
  37. return _this;
  38. }
  39. return ShadowOnlyMaterialDefines;
  40. }(BABYLON.MaterialDefines));
  41. var ShadowOnlyMaterial = /** @class */ (function (_super) {
  42. __extends(ShadowOnlyMaterial, _super);
  43. function ShadowOnlyMaterial(name, scene) {
  44. var _this = _super.call(this, name, scene) || this;
  45. _this.shadowColor = BABYLON.Color3.Black();
  46. return _this;
  47. }
  48. ShadowOnlyMaterial.prototype.needAlphaBlending = function () {
  49. return true;
  50. };
  51. ShadowOnlyMaterial.prototype.needAlphaTesting = function () {
  52. return false;
  53. };
  54. ShadowOnlyMaterial.prototype.getAlphaTestTexture = function () {
  55. return null;
  56. };
  57. Object.defineProperty(ShadowOnlyMaterial.prototype, "activeLight", {
  58. get: function () {
  59. return this._activeLight;
  60. },
  61. set: function (light) {
  62. this._activeLight = light;
  63. },
  64. enumerable: true,
  65. configurable: true
  66. });
  67. // Methods
  68. ShadowOnlyMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  69. if (this.isFrozen) {
  70. if (this._wasPreviouslyReady && subMesh.effect) {
  71. return true;
  72. }
  73. }
  74. if (!subMesh._materialDefines) {
  75. subMesh._materialDefines = new ShadowOnlyMaterialDefines();
  76. }
  77. var defines = subMesh._materialDefines;
  78. var scene = this.getScene();
  79. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  80. if (this._renderId === scene.getRenderId()) {
  81. return true;
  82. }
  83. }
  84. var engine = scene.getEngine();
  85. // Ensure that active light is the first shadow light
  86. if (this._activeLight) {
  87. for (var _i = 0, _a = mesh._lightSources; _i < _a.length; _i++) {
  88. var light = _a[_i];
  89. if (light.shadowEnabled) {
  90. if (this._activeLight === light) {
  91. break; // We are good
  92. }
  93. var lightPosition = mesh._lightSources.indexOf(this._activeLight);
  94. if (lightPosition !== -1) {
  95. mesh._lightSources.splice(lightPosition, 1);
  96. mesh._lightSources.splice(0, 0, this._activeLight);
  97. }
  98. break;
  99. }
  100. }
  101. }
  102. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  103. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  104. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);
  105. // Attribs
  106. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
  107. // Get correct effect
  108. if (defines.isDirty) {
  109. defines.markAsProcessed();
  110. scene.resetCachedMaterial();
  111. // Fallbacks
  112. var fallbacks = new BABYLON.EffectFallbacks();
  113. if (defines.FOG) {
  114. fallbacks.addFallback(1, "FOG");
  115. }
  116. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, 1);
  117. if (defines.NUM_BONE_INFLUENCERS > 0) {
  118. fallbacks.addCPUSkinningFallback(0, mesh);
  119. }
  120. //Attributes
  121. var attribs = [BABYLON.VertexBuffer.PositionKind];
  122. if (defines.NORMAL) {
  123. attribs.push(BABYLON.VertexBuffer.NormalKind);
  124. }
  125. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  126. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  127. var shaderName = "shadowOnly";
  128. var join = defines.toString();
  129. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType",
  130. "vFogInfos", "vFogColor", "pointSize", "alpha", "shadowColor",
  131. "mBones",
  132. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4"
  133. ];
  134. var samplers = new Array();
  135. var uniformBuffers = new Array();
  136. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  137. uniformsNames: uniforms,
  138. uniformBuffersNames: uniformBuffers,
  139. samplers: samplers,
  140. defines: defines,
  141. maxSimultaneousLights: 1
  142. });
  143. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  144. attributes: attribs,
  145. uniformsNames: uniforms,
  146. uniformBuffersNames: uniformBuffers,
  147. samplers: samplers,
  148. defines: join,
  149. fallbacks: fallbacks,
  150. onCompiled: this.onCompiled,
  151. onError: this.onError,
  152. indexParameters: { maxSimultaneousLights: 1 }
  153. }, engine), defines);
  154. }
  155. if (!subMesh.effect || !subMesh.effect.isReady()) {
  156. return false;
  157. }
  158. this._renderId = scene.getRenderId();
  159. this._wasPreviouslyReady = true;
  160. return true;
  161. };
  162. ShadowOnlyMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  163. var scene = this.getScene();
  164. var defines = subMesh._materialDefines;
  165. if (!defines) {
  166. return;
  167. }
  168. var effect = subMesh.effect;
  169. if (!effect) {
  170. return;
  171. }
  172. this._activeEffect = effect;
  173. // Matrices
  174. this.bindOnlyWorldMatrix(world);
  175. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  176. // Bones
  177. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  178. if (this._mustRebind(scene, effect)) {
  179. // Clip plane
  180. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  181. // Point size
  182. if (this.pointsCloud) {
  183. this._activeEffect.setFloat("pointSize", this.pointSize);
  184. }
  185. this._activeEffect.setFloat("alpha", this.alpha);
  186. this._activeEffect.setColor3("shadowColor", this.shadowColor);
  187. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  188. }
  189. // Lights
  190. if (scene.lightsEnabled) {
  191. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, 1);
  192. }
  193. // View
  194. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  195. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  196. }
  197. // Fog
  198. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  199. this._afterBind(mesh, this._activeEffect);
  200. };
  201. ShadowOnlyMaterial.prototype.clone = function (name) {
  202. var _this = this;
  203. return BABYLON.SerializationHelper.Clone(function () { return new ShadowOnlyMaterial(name, _this.getScene()); }, this);
  204. };
  205. ShadowOnlyMaterial.prototype.serialize = function () {
  206. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  207. serializationObject.customType = "BABYLON.ShadowOnlyMaterial";
  208. return serializationObject;
  209. };
  210. ShadowOnlyMaterial.prototype.getClassName = function () {
  211. return "ShadowOnlyMaterial";
  212. };
  213. // Statics
  214. ShadowOnlyMaterial.Parse = function (source, scene, rootUrl) {
  215. return BABYLON.SerializationHelper.Parse(function () { return new ShadowOnlyMaterial(source.name, scene); }, source, scene, rootUrl);
  216. };
  217. return ShadowOnlyMaterial;
  218. }(BABYLON.PushMaterial));
  219. BABYLON.ShadowOnlyMaterial = ShadowOnlyMaterial;
  220. })(BABYLON || (BABYLON = {}));
  221. //# sourceMappingURL=babylon.shadowOnlyMaterial.js.map
  222. BABYLON.Effect.ShadersStore['shadowOnlyVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  223. BABYLON.Effect.ShadersStore['shadowOnlyPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform float alpha;\nuniform vec3 shadowColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#include<lightFragment>[0..1]\n\nvec4 color=vec4(shadowColor,(1.0-clamp(shadow,0.,1.))*alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
  224. var BABYLON;
  225. (function (BABYLON) {
  226. var GradientMaterialDefines = /** @class */ (function (_super) {
  227. __extends(GradientMaterialDefines, _super);
  228. function GradientMaterialDefines() {
  229. var _this = _super.call(this) || this;
  230. _this.DIFFUSE = false;
  231. _this.CLIPPLANE = false;
  232. _this.CLIPPLANE2 = false;
  233. _this.CLIPPLANE3 = false;
  234. _this.CLIPPLANE4 = false;
  235. _this.ALPHATEST = false;
  236. _this.DEPTHPREPASS = false;
  237. _this.POINTSIZE = false;
  238. _this.FOG = false;
  239. _this.LIGHT0 = false;
  240. _this.LIGHT1 = false;
  241. _this.LIGHT2 = false;
  242. _this.LIGHT3 = false;
  243. _this.SPOTLIGHT0 = false;
  244. _this.SPOTLIGHT1 = false;
  245. _this.SPOTLIGHT2 = false;
  246. _this.SPOTLIGHT3 = false;
  247. _this.HEMILIGHT0 = false;
  248. _this.HEMILIGHT1 = false;
  249. _this.HEMILIGHT2 = false;
  250. _this.HEMILIGHT3 = false;
  251. _this.DIRLIGHT0 = false;
  252. _this.DIRLIGHT1 = false;
  253. _this.DIRLIGHT2 = false;
  254. _this.DIRLIGHT3 = false;
  255. _this.POINTLIGHT0 = false;
  256. _this.POINTLIGHT1 = false;
  257. _this.POINTLIGHT2 = false;
  258. _this.POINTLIGHT3 = false;
  259. _this.SHADOW0 = false;
  260. _this.SHADOW1 = false;
  261. _this.SHADOW2 = false;
  262. _this.SHADOW3 = false;
  263. _this.SHADOWS = false;
  264. _this.SHADOWESM0 = false;
  265. _this.SHADOWESM1 = false;
  266. _this.SHADOWESM2 = false;
  267. _this.SHADOWESM3 = false;
  268. _this.SHADOWPOISSON0 = false;
  269. _this.SHADOWPOISSON1 = false;
  270. _this.SHADOWPOISSON2 = false;
  271. _this.SHADOWPOISSON3 = false;
  272. _this.SHADOWPCF0 = false;
  273. _this.SHADOWPCF1 = false;
  274. _this.SHADOWPCF2 = false;
  275. _this.SHADOWPCF3 = false;
  276. _this.SHADOWPCSS0 = false;
  277. _this.SHADOWPCSS1 = false;
  278. _this.SHADOWPCSS2 = false;
  279. _this.SHADOWPCSS3 = false;
  280. _this.NORMAL = false;
  281. _this.UV1 = false;
  282. _this.UV2 = false;
  283. _this.VERTEXCOLOR = false;
  284. _this.VERTEXALPHA = false;
  285. _this.NUM_BONE_INFLUENCERS = 0;
  286. _this.BonesPerMesh = 0;
  287. _this.INSTANCES = false;
  288. _this.rebuild();
  289. return _this;
  290. }
  291. return GradientMaterialDefines;
  292. }(BABYLON.MaterialDefines));
  293. var GradientMaterial = /** @class */ (function (_super) {
  294. __extends(GradientMaterial, _super);
  295. function GradientMaterial(name, scene) {
  296. var _this = _super.call(this, name, scene) || this;
  297. _this._maxSimultaneousLights = 4;
  298. // The gradient top color, red by default
  299. _this.topColor = new BABYLON.Color3(1, 0, 0);
  300. _this.topColorAlpha = 1.0;
  301. // The gradient top color, blue by default
  302. _this.bottomColor = new BABYLON.Color3(0, 0, 1);
  303. _this.bottomColorAlpha = 1.0;
  304. // Gradient offset
  305. _this.offset = 0;
  306. _this.scale = 1.0;
  307. _this.smoothness = 1.0;
  308. _this.disableLighting = false;
  309. _this._scaledDiffuse = new BABYLON.Color3();
  310. return _this;
  311. }
  312. GradientMaterial.prototype.needAlphaBlending = function () {
  313. return (this.alpha < 1.0 || this.topColorAlpha < 1.0 || this.bottomColorAlpha < 1.0);
  314. };
  315. GradientMaterial.prototype.needAlphaTesting = function () {
  316. return true;
  317. };
  318. GradientMaterial.prototype.getAlphaTestTexture = function () {
  319. return null;
  320. };
  321. // Methods
  322. GradientMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  323. if (this.isFrozen) {
  324. if (this._wasPreviouslyReady && subMesh.effect) {
  325. return true;
  326. }
  327. }
  328. if (!subMesh._materialDefines) {
  329. subMesh._materialDefines = new GradientMaterialDefines();
  330. }
  331. var defines = subMesh._materialDefines;
  332. var scene = this.getScene();
  333. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  334. if (this._renderId === scene.getRenderId()) {
  335. return true;
  336. }
  337. }
  338. var engine = scene.getEngine();
  339. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  340. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  341. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights);
  342. // Attribs
  343. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
  344. // Get correct effect
  345. if (defines.isDirty) {
  346. defines.markAsProcessed();
  347. scene.resetCachedMaterial();
  348. // Fallbacks
  349. var fallbacks = new BABYLON.EffectFallbacks();
  350. if (defines.FOG) {
  351. fallbacks.addFallback(1, "FOG");
  352. }
  353. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
  354. if (defines.NUM_BONE_INFLUENCERS > 0) {
  355. fallbacks.addCPUSkinningFallback(0, mesh);
  356. }
  357. //Attributes
  358. var attribs = [BABYLON.VertexBuffer.PositionKind];
  359. if (defines.NORMAL) {
  360. attribs.push(BABYLON.VertexBuffer.NormalKind);
  361. }
  362. if (defines.UV1) {
  363. attribs.push(BABYLON.VertexBuffer.UVKind);
  364. }
  365. if (defines.UV2) {
  366. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  367. }
  368. if (defines.VERTEXCOLOR) {
  369. attribs.push(BABYLON.VertexBuffer.ColorKind);
  370. }
  371. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  372. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  373. // Legacy browser patch
  374. var shaderName = "gradient";
  375. var join = defines.toString();
  376. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  377. "vFogInfos", "vFogColor", "pointSize",
  378. "vDiffuseInfos",
  379. "mBones",
  380. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix",
  381. "topColor", "bottomColor", "offset", "smoothness", "scale"
  382. ];
  383. var samplers = ["diffuseSampler"];
  384. var uniformBuffers = new Array();
  385. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  386. uniformsNames: uniforms,
  387. uniformBuffersNames: uniformBuffers,
  388. samplers: samplers,
  389. defines: defines,
  390. maxSimultaneousLights: 4
  391. });
  392. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  393. attributes: attribs,
  394. uniformsNames: uniforms,
  395. uniformBuffersNames: uniformBuffers,
  396. samplers: samplers,
  397. defines: join,
  398. fallbacks: fallbacks,
  399. onCompiled: this.onCompiled,
  400. onError: this.onError,
  401. indexParameters: { maxSimultaneousLights: 4 }
  402. }, engine), defines);
  403. }
  404. if (!subMesh.effect || !subMesh.effect.isReady()) {
  405. return false;
  406. }
  407. this._renderId = scene.getRenderId();
  408. this._wasPreviouslyReady = true;
  409. return true;
  410. };
  411. GradientMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  412. var scene = this.getScene();
  413. var defines = subMesh._materialDefines;
  414. if (!defines) {
  415. return;
  416. }
  417. var effect = subMesh.effect;
  418. if (!effect) {
  419. return;
  420. }
  421. this._activeEffect = effect;
  422. // Matrices
  423. this.bindOnlyWorldMatrix(world);
  424. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  425. // Bones
  426. BABYLON.MaterialHelper.BindBonesParameters(mesh, effect);
  427. if (this._mustRebind(scene, effect)) {
  428. // Clip plane
  429. BABYLON.MaterialHelper.BindClipPlane(effect, scene);
  430. // Point size
  431. if (this.pointsCloud) {
  432. this._activeEffect.setFloat("pointSize", this.pointSize);
  433. }
  434. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  435. }
  436. this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  437. if (scene.lightsEnabled && !this.disableLighting) {
  438. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines);
  439. }
  440. // View
  441. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  442. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  443. }
  444. // Fog
  445. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  446. this._activeEffect.setColor4("topColor", this.topColor, this.topColorAlpha);
  447. this._activeEffect.setColor4("bottomColor", this.bottomColor, this.bottomColorAlpha);
  448. this._activeEffect.setFloat("offset", this.offset);
  449. this._activeEffect.setFloat("scale", this.scale);
  450. this._activeEffect.setFloat("smoothness", this.smoothness);
  451. this._afterBind(mesh, this._activeEffect);
  452. };
  453. GradientMaterial.prototype.getAnimatables = function () {
  454. return [];
  455. };
  456. GradientMaterial.prototype.dispose = function (forceDisposeEffect) {
  457. _super.prototype.dispose.call(this, forceDisposeEffect);
  458. };
  459. GradientMaterial.prototype.clone = function (name) {
  460. var _this = this;
  461. return BABYLON.SerializationHelper.Clone(function () { return new GradientMaterial(name, _this.getScene()); }, this);
  462. };
  463. GradientMaterial.prototype.serialize = function () {
  464. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  465. serializationObject.customType = "BABYLON.GradientMaterial";
  466. return serializationObject;
  467. };
  468. GradientMaterial.prototype.getClassName = function () {
  469. return "GradientMaterial";
  470. };
  471. // Statics
  472. GradientMaterial.Parse = function (source, scene, rootUrl) {
  473. return BABYLON.SerializationHelper.Parse(function () { return new GradientMaterial(source.name, scene); }, source, scene, rootUrl);
  474. };
  475. __decorate([
  476. BABYLON.serialize("maxSimultaneousLights")
  477. ], GradientMaterial.prototype, "_maxSimultaneousLights", void 0);
  478. __decorate([
  479. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  480. ], GradientMaterial.prototype, "maxSimultaneousLights", void 0);
  481. __decorate([
  482. BABYLON.serializeAsColor3()
  483. ], GradientMaterial.prototype, "topColor", void 0);
  484. __decorate([
  485. BABYLON.serialize()
  486. ], GradientMaterial.prototype, "topColorAlpha", void 0);
  487. __decorate([
  488. BABYLON.serializeAsColor3()
  489. ], GradientMaterial.prototype, "bottomColor", void 0);
  490. __decorate([
  491. BABYLON.serialize()
  492. ], GradientMaterial.prototype, "bottomColorAlpha", void 0);
  493. __decorate([
  494. BABYLON.serialize()
  495. ], GradientMaterial.prototype, "offset", void 0);
  496. __decorate([
  497. BABYLON.serialize()
  498. ], GradientMaterial.prototype, "scale", void 0);
  499. __decorate([
  500. BABYLON.serialize()
  501. ], GradientMaterial.prototype, "smoothness", void 0);
  502. __decorate([
  503. BABYLON.serialize()
  504. ], GradientMaterial.prototype, "disableLighting", void 0);
  505. return GradientMaterial;
  506. }(BABYLON.PushMaterial));
  507. BABYLON.GradientMaterial = GradientMaterial;
  508. })(BABYLON || (BABYLON = {}));
  509. //# sourceMappingURL=babylon.gradientMaterial.js.map
  510. BABYLON.Effect.ShadersStore['gradientVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\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<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\nvarying vec3 vPosition;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex> \ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\nvPosition=position;\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,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 DIFFUSE\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<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  511. BABYLON.Effect.ShadersStore['gradientPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nuniform vec4 topColor;\nuniform vec4 bottomColor;\nuniform float offset;\nuniform float scale;\nuniform float smoothness;\n\nvarying vec3 vPositionW;\nvarying vec3 vPosition;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0]\n#include<__decl__lightFragment>[1]\n#include<__decl__lightFragment>[2]\n#include<__decl__lightFragment>[3]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\nfloat h=vPosition.y*scale+offset;\nfloat mysmoothness=clamp(smoothness,0.01,max(smoothness,10.));\nvec4 baseColor=mix(bottomColor,topColor,max(pow(max(h,0.0),mysmoothness),0.0));\n\nvec3 diffuseColor=baseColor.rgb;\n\nfloat alpha=baseColor.a;\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#include<lightFragment>[0]\n#include<lightFragment>[1]\n#include<lightFragment>[2]\n#include<lightFragment>[3]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}\n";
  512. var BABYLON;
  513. (function (BABYLON) {
  514. var NormalMaterialDefines = /** @class */ (function (_super) {
  515. __extends(NormalMaterialDefines, _super);
  516. function NormalMaterialDefines() {
  517. var _this = _super.call(this) || this;
  518. _this.DIFFUSE = false;
  519. _this.CLIPPLANE = false;
  520. _this.CLIPPLANE2 = false;
  521. _this.CLIPPLANE3 = false;
  522. _this.CLIPPLANE4 = false;
  523. _this.ALPHATEST = false;
  524. _this.DEPTHPREPASS = false;
  525. _this.POINTSIZE = false;
  526. _this.FOG = false;
  527. _this.LIGHT0 = false;
  528. _this.LIGHT1 = false;
  529. _this.LIGHT2 = false;
  530. _this.LIGHT3 = false;
  531. _this.SPOTLIGHT0 = false;
  532. _this.SPOTLIGHT1 = false;
  533. _this.SPOTLIGHT2 = false;
  534. _this.SPOTLIGHT3 = false;
  535. _this.HEMILIGHT0 = false;
  536. _this.HEMILIGHT1 = false;
  537. _this.HEMILIGHT2 = false;
  538. _this.HEMILIGHT3 = false;
  539. _this.DIRLIGHT0 = false;
  540. _this.DIRLIGHT1 = false;
  541. _this.DIRLIGHT2 = false;
  542. _this.DIRLIGHT3 = false;
  543. _this.POINTLIGHT0 = false;
  544. _this.POINTLIGHT1 = false;
  545. _this.POINTLIGHT2 = false;
  546. _this.POINTLIGHT3 = false;
  547. _this.SHADOW0 = false;
  548. _this.SHADOW1 = false;
  549. _this.SHADOW2 = false;
  550. _this.SHADOW3 = false;
  551. _this.SHADOWS = false;
  552. _this.SHADOWESM0 = false;
  553. _this.SHADOWESM1 = false;
  554. _this.SHADOWESM2 = false;
  555. _this.SHADOWESM3 = false;
  556. _this.SHADOWPOISSON0 = false;
  557. _this.SHADOWPOISSON1 = false;
  558. _this.SHADOWPOISSON2 = false;
  559. _this.SHADOWPOISSON3 = false;
  560. _this.SHADOWPCF0 = false;
  561. _this.SHADOWPCF1 = false;
  562. _this.SHADOWPCF2 = false;
  563. _this.SHADOWPCF3 = false;
  564. _this.SHADOWPCSS0 = false;
  565. _this.SHADOWPCSS1 = false;
  566. _this.SHADOWPCSS2 = false;
  567. _this.SHADOWPCSS3 = false;
  568. _this.NORMAL = false;
  569. _this.UV1 = false;
  570. _this.UV2 = false;
  571. _this.NUM_BONE_INFLUENCERS = 0;
  572. _this.BonesPerMesh = 0;
  573. _this.INSTANCES = false;
  574. _this.rebuild();
  575. return _this;
  576. }
  577. return NormalMaterialDefines;
  578. }(BABYLON.MaterialDefines));
  579. var NormalMaterial = /** @class */ (function (_super) {
  580. __extends(NormalMaterial, _super);
  581. function NormalMaterial(name, scene) {
  582. var _this = _super.call(this, name, scene) || this;
  583. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  584. _this._disableLighting = false;
  585. _this._maxSimultaneousLights = 4;
  586. return _this;
  587. }
  588. NormalMaterial.prototype.needAlphaBlending = function () {
  589. return (this.alpha < 1.0);
  590. };
  591. NormalMaterial.prototype.needAlphaBlendingForMesh = function (mesh) {
  592. return this.needAlphaBlending() || (mesh.visibility < 1.0);
  593. };
  594. NormalMaterial.prototype.needAlphaTesting = function () {
  595. return false;
  596. };
  597. NormalMaterial.prototype.getAlphaTestTexture = function () {
  598. return null;
  599. };
  600. // Methods
  601. NormalMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  602. if (this.isFrozen) {
  603. if (this._wasPreviouslyReady && subMesh.effect) {
  604. return true;
  605. }
  606. }
  607. if (!subMesh._materialDefines) {
  608. subMesh._materialDefines = new NormalMaterialDefines();
  609. }
  610. var defines = subMesh._materialDefines;
  611. var scene = this.getScene();
  612. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  613. if (this._renderId === scene.getRenderId()) {
  614. return true;
  615. }
  616. }
  617. var engine = scene.getEngine();
  618. // Textures
  619. if (defines._areTexturesDirty) {
  620. defines._needUVs = false;
  621. if (scene.texturesEnabled) {
  622. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  623. if (!this._diffuseTexture.isReady()) {
  624. return false;
  625. }
  626. else {
  627. defines._needUVs = true;
  628. defines.DIFFUSE = true;
  629. }
  630. }
  631. }
  632. }
  633. // Misc.
  634. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  635. // Lights
  636. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  637. // Values that need to be evaluated on every frame
  638. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  639. // Attribs
  640. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  641. // Get correct effect
  642. if (defines.isDirty) {
  643. defines.markAsProcessed();
  644. scene.resetCachedMaterial();
  645. // Fallbacks
  646. var fallbacks = new BABYLON.EffectFallbacks();
  647. if (defines.FOG) {
  648. fallbacks.addFallback(1, "FOG");
  649. }
  650. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
  651. if (defines.NUM_BONE_INFLUENCERS > 0) {
  652. fallbacks.addCPUSkinningFallback(0, mesh);
  653. }
  654. //Attributes
  655. var attribs = [BABYLON.VertexBuffer.PositionKind];
  656. if (defines.NORMAL) {
  657. attribs.push(BABYLON.VertexBuffer.NormalKind);
  658. }
  659. if (defines.UV1) {
  660. attribs.push(BABYLON.VertexBuffer.UVKind);
  661. }
  662. if (defines.UV2) {
  663. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  664. }
  665. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  666. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  667. var shaderName = "normal";
  668. var join = defines.toString();
  669. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  670. "vFogInfos", "vFogColor", "pointSize",
  671. "vDiffuseInfos",
  672. "mBones",
  673. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix"
  674. ];
  675. var samplers = ["diffuseSampler"];
  676. var uniformBuffers = new Array();
  677. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  678. uniformsNames: uniforms,
  679. uniformBuffersNames: uniformBuffers,
  680. samplers: samplers,
  681. defines: defines,
  682. maxSimultaneousLights: 4
  683. });
  684. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  685. attributes: attribs,
  686. uniformsNames: uniforms,
  687. uniformBuffersNames: uniformBuffers,
  688. samplers: samplers,
  689. defines: join,
  690. fallbacks: fallbacks,
  691. onCompiled: this.onCompiled,
  692. onError: this.onError,
  693. indexParameters: { maxSimultaneousLights: 4 }
  694. }, engine), defines);
  695. }
  696. if (!subMesh.effect || !subMesh.effect.isReady()) {
  697. return false;
  698. }
  699. this._renderId = scene.getRenderId();
  700. this._wasPreviouslyReady = true;
  701. return true;
  702. };
  703. NormalMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  704. var scene = this.getScene();
  705. var defines = subMesh._materialDefines;
  706. if (!defines) {
  707. return;
  708. }
  709. var effect = subMesh.effect;
  710. if (!effect) {
  711. return;
  712. }
  713. this._activeEffect = effect;
  714. // Matrices
  715. this.bindOnlyWorldMatrix(world);
  716. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  717. // Bones
  718. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  719. if (this._mustRebind(scene, effect)) {
  720. // Textures
  721. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  722. this._activeEffect.setTexture("diffuseSampler", this.diffuseTexture);
  723. this._activeEffect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
  724. this._activeEffect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
  725. }
  726. // Clip plane
  727. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  728. // Point size
  729. if (this.pointsCloud) {
  730. this._activeEffect.setFloat("pointSize", this.pointSize);
  731. }
  732. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  733. }
  734. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  735. // Lights
  736. if (scene.lightsEnabled && !this.disableLighting) {
  737. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines);
  738. }
  739. // View
  740. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  741. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  742. }
  743. // Fog
  744. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  745. this._afterBind(mesh, this._activeEffect);
  746. };
  747. NormalMaterial.prototype.getAnimatables = function () {
  748. var results = [];
  749. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  750. results.push(this.diffuseTexture);
  751. }
  752. return results;
  753. };
  754. NormalMaterial.prototype.getActiveTextures = function () {
  755. var activeTextures = _super.prototype.getActiveTextures.call(this);
  756. if (this._diffuseTexture) {
  757. activeTextures.push(this._diffuseTexture);
  758. }
  759. return activeTextures;
  760. };
  761. NormalMaterial.prototype.hasTexture = function (texture) {
  762. if (_super.prototype.hasTexture.call(this, texture)) {
  763. return true;
  764. }
  765. if (this.diffuseTexture === texture) {
  766. return true;
  767. }
  768. return false;
  769. };
  770. NormalMaterial.prototype.dispose = function (forceDisposeEffect) {
  771. if (this.diffuseTexture) {
  772. this.diffuseTexture.dispose();
  773. }
  774. _super.prototype.dispose.call(this, forceDisposeEffect);
  775. };
  776. NormalMaterial.prototype.clone = function (name) {
  777. var _this = this;
  778. return BABYLON.SerializationHelper.Clone(function () { return new NormalMaterial(name, _this.getScene()); }, this);
  779. };
  780. NormalMaterial.prototype.serialize = function () {
  781. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  782. serializationObject.customType = "BABYLON.NormalMaterial";
  783. return serializationObject;
  784. };
  785. NormalMaterial.prototype.getClassName = function () {
  786. return "NormalMaterial";
  787. };
  788. // Statics
  789. NormalMaterial.Parse = function (source, scene, rootUrl) {
  790. return BABYLON.SerializationHelper.Parse(function () { return new NormalMaterial(source.name, scene); }, source, scene, rootUrl);
  791. };
  792. __decorate([
  793. BABYLON.serializeAsTexture("diffuseTexture")
  794. ], NormalMaterial.prototype, "_diffuseTexture", void 0);
  795. __decorate([
  796. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  797. ], NormalMaterial.prototype, "diffuseTexture", void 0);
  798. __decorate([
  799. BABYLON.serializeAsColor3()
  800. ], NormalMaterial.prototype, "diffuseColor", void 0);
  801. __decorate([
  802. BABYLON.serialize("disableLighting")
  803. ], NormalMaterial.prototype, "_disableLighting", void 0);
  804. __decorate([
  805. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  806. ], NormalMaterial.prototype, "disableLighting", void 0);
  807. __decorate([
  808. BABYLON.serialize("maxSimultaneousLights")
  809. ], NormalMaterial.prototype, "_maxSimultaneousLights", void 0);
  810. __decorate([
  811. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  812. ], NormalMaterial.prototype, "maxSimultaneousLights", void 0);
  813. return NormalMaterial;
  814. }(BABYLON.PushMaterial));
  815. BABYLON.NormalMaterial = NormalMaterial;
  816. })(BABYLON || (BABYLON = {}));
  817. //# sourceMappingURL=babylon.normalMaterial.js.map
  818. BABYLON.Effect.ShadersStore['normalVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\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<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,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 DIFFUSE\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<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  819. BABYLON.Effect.ShadersStore['normalPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0]\n#include<__decl__lightFragment>[1]\n#include<__decl__lightFragment>[2]\n#include<__decl__lightFragment>[3]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef NORMAL\nbaseColor=mix(baseColor,vec4(vNormalW,1.0),0.5);\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#include<lightFragment>[0]\n#include<lightFragment>[1]\n#include<lightFragment>[2]\n#include<lightFragment>[3]\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
  820. var BABYLON;
  821. (function (BABYLON) {
  822. var LavaMaterialDefines = /** @class */ (function (_super) {
  823. __extends(LavaMaterialDefines, _super);
  824. function LavaMaterialDefines() {
  825. var _this = _super.call(this) || this;
  826. _this.DIFFUSE = false;
  827. _this.CLIPPLANE = false;
  828. _this.CLIPPLANE2 = false;
  829. _this.CLIPPLANE3 = false;
  830. _this.CLIPPLANE4 = false;
  831. _this.ALPHATEST = false;
  832. _this.DEPTHPREPASS = false;
  833. _this.POINTSIZE = false;
  834. _this.FOG = false;
  835. _this.LIGHT0 = false;
  836. _this.LIGHT1 = false;
  837. _this.LIGHT2 = false;
  838. _this.LIGHT3 = false;
  839. _this.SPOTLIGHT0 = false;
  840. _this.SPOTLIGHT1 = false;
  841. _this.SPOTLIGHT2 = false;
  842. _this.SPOTLIGHT3 = false;
  843. _this.HEMILIGHT0 = false;
  844. _this.HEMILIGHT1 = false;
  845. _this.HEMILIGHT2 = false;
  846. _this.HEMILIGHT3 = false;
  847. _this.DIRLIGHT0 = false;
  848. _this.DIRLIGHT1 = false;
  849. _this.DIRLIGHT2 = false;
  850. _this.DIRLIGHT3 = false;
  851. _this.POINTLIGHT0 = false;
  852. _this.POINTLIGHT1 = false;
  853. _this.POINTLIGHT2 = false;
  854. _this.POINTLIGHT3 = false;
  855. _this.SHADOW0 = false;
  856. _this.SHADOW1 = false;
  857. _this.SHADOW2 = false;
  858. _this.SHADOW3 = false;
  859. _this.SHADOWS = false;
  860. _this.SHADOWESM0 = false;
  861. _this.SHADOWESM1 = false;
  862. _this.SHADOWESM2 = false;
  863. _this.SHADOWESM3 = false;
  864. _this.SHADOWPOISSON0 = false;
  865. _this.SHADOWPOISSON1 = false;
  866. _this.SHADOWPOISSON2 = false;
  867. _this.SHADOWPOISSON3 = false;
  868. _this.SHADOWPCF0 = false;
  869. _this.SHADOWPCF1 = false;
  870. _this.SHADOWPCF2 = false;
  871. _this.SHADOWPCF3 = false;
  872. _this.SHADOWPCSS0 = false;
  873. _this.SHADOWPCSS1 = false;
  874. _this.SHADOWPCSS2 = false;
  875. _this.SHADOWPCSS3 = false;
  876. _this.NORMAL = false;
  877. _this.UV1 = false;
  878. _this.UV2 = false;
  879. _this.VERTEXCOLOR = false;
  880. _this.VERTEXALPHA = false;
  881. _this.NUM_BONE_INFLUENCERS = 0;
  882. _this.BonesPerMesh = 0;
  883. _this.INSTANCES = false;
  884. _this.UNLIT = false;
  885. _this.rebuild();
  886. return _this;
  887. }
  888. return LavaMaterialDefines;
  889. }(BABYLON.MaterialDefines));
  890. var LavaMaterial = /** @class */ (function (_super) {
  891. __extends(LavaMaterial, _super);
  892. function LavaMaterial(name, scene) {
  893. var _this = _super.call(this, name, scene) || this;
  894. _this.speed = 1;
  895. _this.movingSpeed = 1;
  896. _this.lowFrequencySpeed = 1;
  897. _this.fogDensity = 0.15;
  898. _this._lastTime = 0;
  899. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  900. _this._disableLighting = false;
  901. _this._unlit = false;
  902. _this._maxSimultaneousLights = 4;
  903. _this._scaledDiffuse = new BABYLON.Color3();
  904. return _this;
  905. }
  906. LavaMaterial.prototype.needAlphaBlending = function () {
  907. return (this.alpha < 1.0);
  908. };
  909. LavaMaterial.prototype.needAlphaTesting = function () {
  910. return false;
  911. };
  912. LavaMaterial.prototype.getAlphaTestTexture = function () {
  913. return null;
  914. };
  915. // Methods
  916. LavaMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  917. if (this.isFrozen) {
  918. if (this._wasPreviouslyReady && subMesh.effect) {
  919. return true;
  920. }
  921. }
  922. if (!subMesh._materialDefines) {
  923. subMesh._materialDefines = new LavaMaterialDefines();
  924. }
  925. var defines = subMesh._materialDefines;
  926. var scene = this.getScene();
  927. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  928. if (this._renderId === scene.getRenderId()) {
  929. return true;
  930. }
  931. }
  932. var engine = scene.getEngine();
  933. // Textures
  934. if (defines._areTexturesDirty) {
  935. defines._needUVs = false;
  936. if (scene.texturesEnabled) {
  937. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  938. if (!this._diffuseTexture.isReady()) {
  939. return false;
  940. }
  941. else {
  942. defines._needUVs = true;
  943. defines.DIFFUSE = true;
  944. }
  945. }
  946. }
  947. }
  948. // Misc.
  949. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  950. // Lights
  951. defines._needNormals = true;
  952. BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  953. // Values that need to be evaluated on every frame
  954. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  955. // Attribs
  956. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  957. // Get correct effect
  958. if (defines.isDirty) {
  959. defines.markAsProcessed();
  960. scene.resetCachedMaterial();
  961. // Fallbacks
  962. var fallbacks = new BABYLON.EffectFallbacks();
  963. if (defines.FOG) {
  964. fallbacks.addFallback(1, "FOG");
  965. }
  966. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
  967. if (defines.NUM_BONE_INFLUENCERS > 0) {
  968. fallbacks.addCPUSkinningFallback(0, mesh);
  969. }
  970. //Attributes
  971. var attribs = [BABYLON.VertexBuffer.PositionKind];
  972. if (defines.NORMAL) {
  973. attribs.push(BABYLON.VertexBuffer.NormalKind);
  974. }
  975. if (defines.UV1) {
  976. attribs.push(BABYLON.VertexBuffer.UVKind);
  977. }
  978. if (defines.UV2) {
  979. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  980. }
  981. if (defines.VERTEXCOLOR) {
  982. attribs.push(BABYLON.VertexBuffer.ColorKind);
  983. }
  984. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  985. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  986. // Legacy browser patch
  987. var shaderName = "lava";
  988. var join = defines.toString();
  989. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  990. "vFogInfos", "vFogColor", "pointSize",
  991. "vDiffuseInfos",
  992. "mBones",
  993. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix",
  994. "time", "speed", "movingSpeed",
  995. "fogColor", "fogDensity", "lowFrequencySpeed"
  996. ];
  997. var samplers = ["diffuseSampler",
  998. "noiseTexture"
  999. ];
  1000. var uniformBuffers = new Array();
  1001. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  1002. uniformsNames: uniforms,
  1003. uniformBuffersNames: uniformBuffers,
  1004. samplers: samplers,
  1005. defines: defines,
  1006. maxSimultaneousLights: this.maxSimultaneousLights
  1007. });
  1008. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  1009. attributes: attribs,
  1010. uniformsNames: uniforms,
  1011. uniformBuffersNames: uniformBuffers,
  1012. samplers: samplers,
  1013. defines: join,
  1014. fallbacks: fallbacks,
  1015. onCompiled: this.onCompiled,
  1016. onError: this.onError,
  1017. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  1018. }, engine), defines);
  1019. }
  1020. if (!subMesh.effect || !subMesh.effect.isReady()) {
  1021. return false;
  1022. }
  1023. this._renderId = scene.getRenderId();
  1024. this._wasPreviouslyReady = true;
  1025. return true;
  1026. };
  1027. LavaMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  1028. var scene = this.getScene();
  1029. var defines = subMesh._materialDefines;
  1030. if (!defines) {
  1031. return;
  1032. }
  1033. var effect = subMesh.effect;
  1034. if (!effect) {
  1035. return;
  1036. }
  1037. this._activeEffect = effect;
  1038. defines.UNLIT = this._unlit;
  1039. // Matrices
  1040. this.bindOnlyWorldMatrix(world);
  1041. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  1042. // Bones
  1043. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  1044. if (this._mustRebind(scene, effect)) {
  1045. // Textures
  1046. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  1047. this._activeEffect.setTexture("diffuseSampler", this.diffuseTexture);
  1048. this._activeEffect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
  1049. this._activeEffect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
  1050. }
  1051. if (this.noiseTexture) {
  1052. this._activeEffect.setTexture("noiseTexture", this.noiseTexture);
  1053. }
  1054. // Clip plane
  1055. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  1056. // Point size
  1057. if (this.pointsCloud) {
  1058. this._activeEffect.setFloat("pointSize", this.pointSize);
  1059. }
  1060. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  1061. }
  1062. this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  1063. if (scene.lightsEnabled && !this.disableLighting) {
  1064. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines);
  1065. }
  1066. // View
  1067. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  1068. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  1069. }
  1070. // Fog
  1071. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  1072. this._lastTime += scene.getEngine().getDeltaTime();
  1073. this._activeEffect.setFloat("time", this._lastTime * this.speed / 1000);
  1074. if (!this.fogColor) {
  1075. this.fogColor = BABYLON.Color3.Black();
  1076. }
  1077. this._activeEffect.setColor3("fogColor", this.fogColor);
  1078. this._activeEffect.setFloat("fogDensity", this.fogDensity);
  1079. this._activeEffect.setFloat("lowFrequencySpeed", this.lowFrequencySpeed);
  1080. this._activeEffect.setFloat("movingSpeed", this.movingSpeed);
  1081. this._afterBind(mesh, this._activeEffect);
  1082. };
  1083. LavaMaterial.prototype.getAnimatables = function () {
  1084. var results = [];
  1085. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  1086. results.push(this.diffuseTexture);
  1087. }
  1088. if (this.noiseTexture && this.noiseTexture.animations && this.noiseTexture.animations.length > 0) {
  1089. results.push(this.noiseTexture);
  1090. }
  1091. return results;
  1092. };
  1093. LavaMaterial.prototype.getActiveTextures = function () {
  1094. var activeTextures = _super.prototype.getActiveTextures.call(this);
  1095. if (this._diffuseTexture) {
  1096. activeTextures.push(this._diffuseTexture);
  1097. }
  1098. return activeTextures;
  1099. };
  1100. LavaMaterial.prototype.hasTexture = function (texture) {
  1101. if (_super.prototype.hasTexture.call(this, texture)) {
  1102. return true;
  1103. }
  1104. if (this.diffuseTexture === texture) {
  1105. return true;
  1106. }
  1107. return false;
  1108. };
  1109. LavaMaterial.prototype.dispose = function (forceDisposeEffect) {
  1110. if (this.diffuseTexture) {
  1111. this.diffuseTexture.dispose();
  1112. }
  1113. if (this.noiseTexture) {
  1114. this.noiseTexture.dispose();
  1115. }
  1116. _super.prototype.dispose.call(this, forceDisposeEffect);
  1117. };
  1118. LavaMaterial.prototype.clone = function (name) {
  1119. var _this = this;
  1120. return BABYLON.SerializationHelper.Clone(function () { return new LavaMaterial(name, _this.getScene()); }, this);
  1121. };
  1122. LavaMaterial.prototype.serialize = function () {
  1123. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  1124. serializationObject.customType = "BABYLON.LavaMaterial";
  1125. return serializationObject;
  1126. };
  1127. LavaMaterial.prototype.getClassName = function () {
  1128. return "LavaMaterial";
  1129. };
  1130. // Statics
  1131. LavaMaterial.Parse = function (source, scene, rootUrl) {
  1132. return BABYLON.SerializationHelper.Parse(function () { return new LavaMaterial(source.name, scene); }, source, scene, rootUrl);
  1133. };
  1134. __decorate([
  1135. BABYLON.serializeAsTexture("diffuseTexture")
  1136. ], LavaMaterial.prototype, "_diffuseTexture", void 0);
  1137. __decorate([
  1138. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1139. ], LavaMaterial.prototype, "diffuseTexture", void 0);
  1140. __decorate([
  1141. BABYLON.serializeAsTexture()
  1142. ], LavaMaterial.prototype, "noiseTexture", void 0);
  1143. __decorate([
  1144. BABYLON.serializeAsColor3()
  1145. ], LavaMaterial.prototype, "fogColor", void 0);
  1146. __decorate([
  1147. BABYLON.serialize()
  1148. ], LavaMaterial.prototype, "speed", void 0);
  1149. __decorate([
  1150. BABYLON.serialize()
  1151. ], LavaMaterial.prototype, "movingSpeed", void 0);
  1152. __decorate([
  1153. BABYLON.serialize()
  1154. ], LavaMaterial.prototype, "lowFrequencySpeed", void 0);
  1155. __decorate([
  1156. BABYLON.serialize()
  1157. ], LavaMaterial.prototype, "fogDensity", void 0);
  1158. __decorate([
  1159. BABYLON.serializeAsColor3()
  1160. ], LavaMaterial.prototype, "diffuseColor", void 0);
  1161. __decorate([
  1162. BABYLON.serialize("disableLighting")
  1163. ], LavaMaterial.prototype, "_disableLighting", void 0);
  1164. __decorate([
  1165. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1166. ], LavaMaterial.prototype, "disableLighting", void 0);
  1167. __decorate([
  1168. BABYLON.serialize("unlit")
  1169. ], LavaMaterial.prototype, "_unlit", void 0);
  1170. __decorate([
  1171. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1172. ], LavaMaterial.prototype, "unlit", void 0);
  1173. __decorate([
  1174. BABYLON.serialize("maxSimultaneousLights")
  1175. ], LavaMaterial.prototype, "_maxSimultaneousLights", void 0);
  1176. __decorate([
  1177. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1178. ], LavaMaterial.prototype, "maxSimultaneousLights", void 0);
  1179. return LavaMaterial;
  1180. }(BABYLON.PushMaterial));
  1181. BABYLON.LavaMaterial = LavaMaterial;
  1182. })(BABYLON || (BABYLON = {}));
  1183. //# sourceMappingURL=babylon.lavaMaterial.js.map
  1184. BABYLON.Effect.ShadersStore['lavaVertexShader'] = "precision highp float;\n\nuniform float time;\nuniform float lowFrequencySpeed;\n\nvarying float noise;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\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<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n\n\nvec3 mod289(vec3 x)\n{\nreturn x-floor(x*(1.0/289.0))*289.0;\n}\nvec4 mod289(vec4 x)\n{\nreturn x-floor(x*(1.0/289.0))*289.0;\n}\nvec4 permute(vec4 x)\n{\nreturn mod289(((x*34.0)+1.0)*x);\n}\nvec4 taylorInvSqrt(vec4 r)\n{\nreturn 1.79284291400159-0.85373472095314*r;\n}\nvec3 fade(vec3 t) {\nreturn t*t*t*(t*(t*6.0-15.0)+10.0);\n}\n\nfloat pnoise(vec3 P,vec3 rep)\n{\nvec3 Pi0=mod(floor(P),rep); \nvec3 Pi1=mod(Pi0+vec3(1.0),rep); \nPi0=mod289(Pi0);\nPi1=mod289(Pi1);\nvec3 Pf0=fract(P); \nvec3 Pf1=Pf0-vec3(1.0); \nvec4 ix=vec4(Pi0.x,Pi1.x,Pi0.x,Pi1.x);\nvec4 iy=vec4(Pi0.yy,Pi1.yy);\nvec4 iz0=Pi0.zzzz;\nvec4 iz1=Pi1.zzzz;\nvec4 ixy=permute(permute(ix)+iy);\nvec4 ixy0=permute(ixy+iz0);\nvec4 ixy1=permute(ixy+iz1);\nvec4 gx0=ixy0*(1.0/7.0);\nvec4 gy0=fract(floor(gx0)*(1.0/7.0))-0.5;\ngx0=fract(gx0);\nvec4 gz0=vec4(0.5)-abs(gx0)-abs(gy0);\nvec4 sz0=step(gz0,vec4(0.0));\ngx0-=sz0*(step(0.0,gx0)-0.5);\ngy0-=sz0*(step(0.0,gy0)-0.5);\nvec4 gx1=ixy1*(1.0/7.0);\nvec4 gy1=fract(floor(gx1)*(1.0/7.0))-0.5;\ngx1=fract(gx1);\nvec4 gz1=vec4(0.5)-abs(gx1)-abs(gy1);\nvec4 sz1=step(gz1,vec4(0.0));\ngx1-=sz1*(step(0.0,gx1)-0.5);\ngy1-=sz1*(step(0.0,gy1)-0.5);\nvec3 g000=vec3(gx0.x,gy0.x,gz0.x);\nvec3 g100=vec3(gx0.y,gy0.y,gz0.y);\nvec3 g010=vec3(gx0.z,gy0.z,gz0.z);\nvec3 g110=vec3(gx0.w,gy0.w,gz0.w);\nvec3 g001=vec3(gx1.x,gy1.x,gz1.x);\nvec3 g101=vec3(gx1.y,gy1.y,gz1.y);\nvec3 g011=vec3(gx1.z,gy1.z,gz1.z);\nvec3 g111=vec3(gx1.w,gy1.w,gz1.w);\nvec4 norm0=taylorInvSqrt(vec4(dot(g000,g000),dot(g010,g010),dot(g100,g100),dot(g110,g110)));\ng000*=norm0.x;\ng010*=norm0.y;\ng100*=norm0.z;\ng110*=norm0.w;\nvec4 norm1=taylorInvSqrt(vec4(dot(g001,g001),dot(g011,g011),dot(g101,g101),dot(g111,g111)));\ng001*=norm1.x;\ng011*=norm1.y;\ng101*=norm1.z;\ng111*=norm1.w;\nfloat n000=dot(g000,Pf0);\nfloat n100=dot(g100,vec3(Pf1.x,Pf0.yz));\nfloat n010=dot(g010,vec3(Pf0.x,Pf1.y,Pf0.z));\nfloat n110=dot(g110,vec3(Pf1.xy,Pf0.z));\nfloat n001=dot(g001,vec3(Pf0.xy,Pf1.z));\nfloat n101=dot(g101,vec3(Pf1.x,Pf0.y,Pf1.z));\nfloat n011=dot(g011,vec3(Pf0.x,Pf1.yz));\nfloat n111=dot(g111,Pf1);\nvec3 fade_xyz=fade(Pf0);\nvec4 n_z=mix(vec4(n000,n100,n010,n110),vec4(n001,n101,n011,n111),fade_xyz.z);\nvec2 n_yz=mix(n_z.xy,n_z.zw,fade_xyz.y);\nfloat n_xyz=mix(n_yz.x,n_yz.y,fade_xyz.x);\nreturn 2.2*n_xyz;\n}\n\nfloat turbulence( vec3 p ) {\nfloat w=100.0;\nfloat t=-.5;\nfor (float f=1.0 ; f<=10.0 ; f++ ){\nfloat power=pow( 2.0,f );\nt+=abs( pnoise( vec3( power*p ),vec3( 10.0,10.0,10.0 ) )/power );\n}\nreturn t;\n}\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\n#ifdef NORMAL\n\nnoise=10.0*-.10*turbulence( .5*normal+time*1.15 );\n\nfloat b=lowFrequencySpeed*5.0*pnoise( 0.05*position +vec3(time*1.025),vec3( 100.0 ) );\n\nfloat displacement =-1.5*noise+b;\n\nvec3 newPosition=position+normal*displacement;\ngl_Position=viewProjection*finalWorld*vec4( newPosition,1.0 );\nvec4 worldPos=finalWorld*vec4(newPosition,1.0);\nvPositionW=vec3(worldPos);\nvNormalW=normalize(vec3(finalWorld*vec4(normal,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 DIFFUSE\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<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}";
  1185. BABYLON.Effect.ShadersStore['lavaPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nvarying vec3 vPositionW;\n\nuniform float time;\nuniform float speed;\nuniform float movingSpeed;\nuniform vec3 fogColor;\nuniform sampler2D noiseTexture;\nuniform float fogDensity;\n\nvarying float noise;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0]\n#include<__decl__lightFragment>[1]\n#include<__decl__lightFragment>[2]\n#include<__decl__lightFragment>[3]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nfloat random( vec3 scale,float seed ){\nreturn fract( sin( dot( gl_FragCoord.xyz+seed,scale ) )*43758.5453+seed ) ;\n}\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\n\nvec4 noiseTex=texture2D( noiseTexture,vDiffuseUV );\nvec2 T1=vDiffuseUV+vec2( 1.5,-1.5 )*time*0.02;\nvec2 T2=vDiffuseUV+vec2( -0.5,2.0 )*time*0.01*speed;\nT1.x+=noiseTex.x*2.0;\nT1.y+=noiseTex.y*2.0;\nT2.x-=noiseTex.y*0.2+time*0.001*movingSpeed;\nT2.y+=noiseTex.z*0.2+time*0.002*movingSpeed;\nfloat p=texture2D( noiseTexture,T1*3.0 ).a;\nvec4 lavaColor=texture2D( diffuseSampler,T2*4.0);\nvec4 temp=lavaColor*( vec4( p,p,p,p )*2. )+( lavaColor*lavaColor-0.1 );\nbaseColor=temp;\nfloat depth=gl_FragCoord.z*4.0;\nconst float LOG2=1.442695;\nfloat fogFactor=exp2(-fogDensity*fogDensity*depth*depth*LOG2 );\nfogFactor=1.0-clamp( fogFactor,0.0,1.0 );\nbaseColor=mix( baseColor,vec4( fogColor,baseColor.w ),fogFactor );\ndiffuseColor=baseColor.rgb;\n\n\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n#ifdef UNLIT\nvec3 diffuseBase=vec3(1.,1.,1.);\n#else\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#include<lightFragment>[0]\n#include<lightFragment>[1]\n#include<lightFragment>[2]\n#include<lightFragment>[3]\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
  1186. var BABYLON;
  1187. (function (BABYLON) {
  1188. var SimpleMaterialDefines = /** @class */ (function (_super) {
  1189. __extends(SimpleMaterialDefines, _super);
  1190. function SimpleMaterialDefines() {
  1191. var _this = _super.call(this) || this;
  1192. _this.DIFFUSE = false;
  1193. _this.CLIPPLANE = false;
  1194. _this.CLIPPLANE2 = false;
  1195. _this.CLIPPLANE3 = false;
  1196. _this.CLIPPLANE4 = false;
  1197. _this.ALPHATEST = false;
  1198. _this.DEPTHPREPASS = false;
  1199. _this.POINTSIZE = false;
  1200. _this.FOG = false;
  1201. _this.NORMAL = false;
  1202. _this.UV1 = false;
  1203. _this.UV2 = false;
  1204. _this.VERTEXCOLOR = false;
  1205. _this.VERTEXALPHA = false;
  1206. _this.NUM_BONE_INFLUENCERS = 0;
  1207. _this.BonesPerMesh = 0;
  1208. _this.INSTANCES = false;
  1209. _this.rebuild();
  1210. return _this;
  1211. }
  1212. return SimpleMaterialDefines;
  1213. }(BABYLON.MaterialDefines));
  1214. var SimpleMaterial = /** @class */ (function (_super) {
  1215. __extends(SimpleMaterial, _super);
  1216. function SimpleMaterial(name, scene) {
  1217. var _this = _super.call(this, name, scene) || this;
  1218. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  1219. _this._disableLighting = false;
  1220. _this._maxSimultaneousLights = 4;
  1221. return _this;
  1222. }
  1223. SimpleMaterial.prototype.needAlphaBlending = function () {
  1224. return (this.alpha < 1.0);
  1225. };
  1226. SimpleMaterial.prototype.needAlphaTesting = function () {
  1227. return false;
  1228. };
  1229. SimpleMaterial.prototype.getAlphaTestTexture = function () {
  1230. return null;
  1231. };
  1232. // Methods
  1233. SimpleMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  1234. if (this.isFrozen) {
  1235. if (this._wasPreviouslyReady && subMesh.effect) {
  1236. return true;
  1237. }
  1238. }
  1239. if (!subMesh._materialDefines) {
  1240. subMesh._materialDefines = new SimpleMaterialDefines();
  1241. }
  1242. var defines = subMesh._materialDefines;
  1243. var scene = this.getScene();
  1244. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  1245. if (this._renderId === scene.getRenderId()) {
  1246. return true;
  1247. }
  1248. }
  1249. var engine = scene.getEngine();
  1250. // Textures
  1251. if (defines._areTexturesDirty) {
  1252. defines._needUVs = false;
  1253. if (scene.texturesEnabled) {
  1254. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  1255. if (!this._diffuseTexture.isReady()) {
  1256. return false;
  1257. }
  1258. else {
  1259. defines._needUVs = true;
  1260. defines.DIFFUSE = true;
  1261. }
  1262. }
  1263. }
  1264. }
  1265. // Misc.
  1266. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  1267. // Lights
  1268. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  1269. // Values that need to be evaluated on every frame
  1270. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  1271. // Attribs
  1272. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  1273. // Get correct effect
  1274. if (defines.isDirty) {
  1275. defines.markAsProcessed();
  1276. scene.resetCachedMaterial();
  1277. // Fallbacks
  1278. var fallbacks = new BABYLON.EffectFallbacks();
  1279. if (defines.FOG) {
  1280. fallbacks.addFallback(1, "FOG");
  1281. }
  1282. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  1283. if (defines.NUM_BONE_INFLUENCERS > 0) {
  1284. fallbacks.addCPUSkinningFallback(0, mesh);
  1285. }
  1286. //Attributes
  1287. var attribs = [BABYLON.VertexBuffer.PositionKind];
  1288. if (defines.NORMAL) {
  1289. attribs.push(BABYLON.VertexBuffer.NormalKind);
  1290. }
  1291. if (defines.UV1) {
  1292. attribs.push(BABYLON.VertexBuffer.UVKind);
  1293. }
  1294. if (defines.UV2) {
  1295. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  1296. }
  1297. if (defines.VERTEXCOLOR) {
  1298. attribs.push(BABYLON.VertexBuffer.ColorKind);
  1299. }
  1300. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  1301. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  1302. var shaderName = "simple";
  1303. var join = defines.toString();
  1304. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  1305. "vFogInfos", "vFogColor", "pointSize",
  1306. "vDiffuseInfos",
  1307. "mBones",
  1308. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix"
  1309. ];
  1310. var samplers = ["diffuseSampler"];
  1311. var uniformBuffers = new Array();
  1312. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  1313. uniformsNames: uniforms,
  1314. uniformBuffersNames: uniformBuffers,
  1315. samplers: samplers,
  1316. defines: defines,
  1317. maxSimultaneousLights: this.maxSimultaneousLights
  1318. });
  1319. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  1320. attributes: attribs,
  1321. uniformsNames: uniforms,
  1322. uniformBuffersNames: uniformBuffers,
  1323. samplers: samplers,
  1324. defines: join,
  1325. fallbacks: fallbacks,
  1326. onCompiled: this.onCompiled,
  1327. onError: this.onError,
  1328. indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights - 1 }
  1329. }, engine), defines);
  1330. }
  1331. if (!subMesh.effect || !subMesh.effect.isReady()) {
  1332. return false;
  1333. }
  1334. this._renderId = scene.getRenderId();
  1335. this._wasPreviouslyReady = true;
  1336. return true;
  1337. };
  1338. SimpleMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  1339. var scene = this.getScene();
  1340. var defines = subMesh._materialDefines;
  1341. if (!defines) {
  1342. return;
  1343. }
  1344. var effect = subMesh.effect;
  1345. if (!effect) {
  1346. return;
  1347. }
  1348. this._activeEffect = effect;
  1349. // Matrices
  1350. this.bindOnlyWorldMatrix(world);
  1351. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  1352. // Bones
  1353. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  1354. if (this._mustRebind(scene, effect)) {
  1355. // Textures
  1356. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  1357. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  1358. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  1359. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  1360. }
  1361. // Clip plane
  1362. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  1363. // Point size
  1364. if (this.pointsCloud) {
  1365. this._activeEffect.setFloat("pointSize", this.pointSize);
  1366. }
  1367. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  1368. }
  1369. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  1370. // Lights
  1371. if (scene.lightsEnabled && !this.disableLighting) {
  1372. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  1373. }
  1374. // View
  1375. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  1376. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  1377. }
  1378. // Fog
  1379. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  1380. this._afterBind(mesh, this._activeEffect);
  1381. };
  1382. SimpleMaterial.prototype.getAnimatables = function () {
  1383. var results = [];
  1384. if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
  1385. results.push(this._diffuseTexture);
  1386. }
  1387. return results;
  1388. };
  1389. SimpleMaterial.prototype.getActiveTextures = function () {
  1390. var activeTextures = _super.prototype.getActiveTextures.call(this);
  1391. if (this._diffuseTexture) {
  1392. activeTextures.push(this._diffuseTexture);
  1393. }
  1394. return activeTextures;
  1395. };
  1396. SimpleMaterial.prototype.hasTexture = function (texture) {
  1397. if (_super.prototype.hasTexture.call(this, texture)) {
  1398. return true;
  1399. }
  1400. if (this.diffuseTexture === texture) {
  1401. return true;
  1402. }
  1403. return false;
  1404. };
  1405. SimpleMaterial.prototype.dispose = function (forceDisposeEffect) {
  1406. if (this._diffuseTexture) {
  1407. this._diffuseTexture.dispose();
  1408. }
  1409. _super.prototype.dispose.call(this, forceDisposeEffect);
  1410. };
  1411. SimpleMaterial.prototype.clone = function (name) {
  1412. var _this = this;
  1413. return BABYLON.SerializationHelper.Clone(function () { return new SimpleMaterial(name, _this.getScene()); }, this);
  1414. };
  1415. SimpleMaterial.prototype.serialize = function () {
  1416. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  1417. serializationObject.customType = "BABYLON.SimpleMaterial";
  1418. return serializationObject;
  1419. };
  1420. SimpleMaterial.prototype.getClassName = function () {
  1421. return "SimpleMaterial";
  1422. };
  1423. // Statics
  1424. SimpleMaterial.Parse = function (source, scene, rootUrl) {
  1425. return BABYLON.SerializationHelper.Parse(function () { return new SimpleMaterial(source.name, scene); }, source, scene, rootUrl);
  1426. };
  1427. __decorate([
  1428. BABYLON.serializeAsTexture("diffuseTexture")
  1429. ], SimpleMaterial.prototype, "_diffuseTexture", void 0);
  1430. __decorate([
  1431. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1432. ], SimpleMaterial.prototype, "diffuseTexture", void 0);
  1433. __decorate([
  1434. BABYLON.serializeAsColor3("diffuse")
  1435. ], SimpleMaterial.prototype, "diffuseColor", void 0);
  1436. __decorate([
  1437. BABYLON.serialize("disableLighting")
  1438. ], SimpleMaterial.prototype, "_disableLighting", void 0);
  1439. __decorate([
  1440. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1441. ], SimpleMaterial.prototype, "disableLighting", void 0);
  1442. __decorate([
  1443. BABYLON.serialize("maxSimultaneousLights")
  1444. ], SimpleMaterial.prototype, "_maxSimultaneousLights", void 0);
  1445. __decorate([
  1446. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1447. ], SimpleMaterial.prototype, "maxSimultaneousLights", void 0);
  1448. return SimpleMaterial;
  1449. }(BABYLON.PushMaterial));
  1450. BABYLON.SimpleMaterial = SimpleMaterial;
  1451. })(BABYLON || (BABYLON = {}));
  1452. //# sourceMappingURL=babylon.simpleMaterial.js.map
  1453. BABYLON.Effect.ShadersStore['simpleVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\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<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,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 DIFFUSE\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<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  1454. BABYLON.Effect.ShadersStore['simplePixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif \n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
  1455. var BABYLON;
  1456. (function (BABYLON) {
  1457. var WaterMaterialDefines = /** @class */ (function (_super) {
  1458. __extends(WaterMaterialDefines, _super);
  1459. function WaterMaterialDefines() {
  1460. var _this = _super.call(this) || this;
  1461. _this.BUMP = false;
  1462. _this.REFLECTION = false;
  1463. _this.CLIPPLANE = false;
  1464. _this.CLIPPLANE2 = false;
  1465. _this.CLIPPLANE3 = false;
  1466. _this.CLIPPLANE4 = false;
  1467. _this.ALPHATEST = false;
  1468. _this.DEPTHPREPASS = false;
  1469. _this.POINTSIZE = false;
  1470. _this.FOG = false;
  1471. _this.NORMAL = false;
  1472. _this.UV1 = false;
  1473. _this.UV2 = false;
  1474. _this.VERTEXCOLOR = false;
  1475. _this.VERTEXALPHA = false;
  1476. _this.NUM_BONE_INFLUENCERS = 0;
  1477. _this.BonesPerMesh = 0;
  1478. _this.INSTANCES = false;
  1479. _this.SPECULARTERM = false;
  1480. _this.LOGARITHMICDEPTH = false;
  1481. _this.FRESNELSEPARATE = false;
  1482. _this.BUMPSUPERIMPOSE = false;
  1483. _this.BUMPAFFECTSREFLECTION = false;
  1484. _this.rebuild();
  1485. return _this;
  1486. }
  1487. return WaterMaterialDefines;
  1488. }(BABYLON.MaterialDefines));
  1489. var WaterMaterial = /** @class */ (function (_super) {
  1490. __extends(WaterMaterial, _super);
  1491. /**
  1492. * Constructor
  1493. */
  1494. function WaterMaterial(name, scene, renderTargetSize) {
  1495. if (renderTargetSize === void 0) { renderTargetSize = new BABYLON.Vector2(512, 512); }
  1496. var _this = _super.call(this, name, scene) || this;
  1497. _this.renderTargetSize = renderTargetSize;
  1498. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  1499. _this.specularColor = new BABYLON.Color3(0, 0, 0);
  1500. _this.specularPower = 64;
  1501. _this._disableLighting = false;
  1502. _this._maxSimultaneousLights = 4;
  1503. /**
  1504. * @param {number}: Represents the wind force
  1505. */
  1506. _this.windForce = 6;
  1507. /**
  1508. * @param {Vector2}: The direction of the wind in the plane (X, Z)
  1509. */
  1510. _this.windDirection = new BABYLON.Vector2(0, 1);
  1511. /**
  1512. * @param {number}: Wave height, represents the height of the waves
  1513. */
  1514. _this.waveHeight = 0.4;
  1515. /**
  1516. * @param {number}: Bump height, represents the bump height related to the bump map
  1517. */
  1518. _this.bumpHeight = 0.4;
  1519. /**
  1520. * @param {boolean}: Add a smaller moving bump to less steady waves.
  1521. */
  1522. _this._bumpSuperimpose = false;
  1523. /**
  1524. * @param {boolean}: Color refraction and reflection differently with .waterColor2 and .colorBlendFactor2. Non-linear (physically correct) fresnel.
  1525. */
  1526. _this._fresnelSeparate = false;
  1527. /**
  1528. * @param {boolean}: bump Waves modify the reflection.
  1529. */
  1530. _this._bumpAffectsReflection = false;
  1531. /**
  1532. * @param {number}: The water color blended with the refraction (near)
  1533. */
  1534. _this.waterColor = new BABYLON.Color3(0.1, 0.1, 0.6);
  1535. /**
  1536. * @param {number}: The blend factor related to the water color
  1537. */
  1538. _this.colorBlendFactor = 0.2;
  1539. /**
  1540. * @param {number}: The water color blended with the reflection (far)
  1541. */
  1542. _this.waterColor2 = new BABYLON.Color3(0.1, 0.1, 0.6);
  1543. /**
  1544. * @param {number}: The blend factor related to the water color (reflection, far)
  1545. */
  1546. _this.colorBlendFactor2 = 0.2;
  1547. /**
  1548. * @param {number}: Represents the maximum length of a wave
  1549. */
  1550. _this.waveLength = 0.1;
  1551. /**
  1552. * @param {number}: Defines the waves speed
  1553. */
  1554. _this.waveSpeed = 1.0;
  1555. _this._renderTargets = new BABYLON.SmartArray(16);
  1556. /*
  1557. * Private members
  1558. */
  1559. _this._mesh = null;
  1560. _this._reflectionTransform = BABYLON.Matrix.Zero();
  1561. _this._lastTime = 0;
  1562. _this._lastDeltaTime = 0;
  1563. _this._createRenderTargets(scene, renderTargetSize);
  1564. // Create render targets
  1565. _this.getRenderTargetTextures = function () {
  1566. _this._renderTargets.reset();
  1567. _this._renderTargets.push(_this._reflectionRTT);
  1568. _this._renderTargets.push(_this._refractionRTT);
  1569. return _this._renderTargets;
  1570. };
  1571. return _this;
  1572. }
  1573. Object.defineProperty(WaterMaterial.prototype, "hasRenderTargetTextures", {
  1574. /**
  1575. * Gets a boolean indicating that current material needs to register RTT
  1576. */
  1577. get: function () {
  1578. return true;
  1579. },
  1580. enumerable: true,
  1581. configurable: true
  1582. });
  1583. Object.defineProperty(WaterMaterial.prototype, "useLogarithmicDepth", {
  1584. get: function () {
  1585. return this._useLogarithmicDepth;
  1586. },
  1587. set: function (value) {
  1588. this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;
  1589. this._markAllSubMeshesAsMiscDirty();
  1590. },
  1591. enumerable: true,
  1592. configurable: true
  1593. });
  1594. Object.defineProperty(WaterMaterial.prototype, "refractionTexture", {
  1595. // Get / Set
  1596. get: function () {
  1597. return this._refractionRTT;
  1598. },
  1599. enumerable: true,
  1600. configurable: true
  1601. });
  1602. Object.defineProperty(WaterMaterial.prototype, "reflectionTexture", {
  1603. get: function () {
  1604. return this._reflectionRTT;
  1605. },
  1606. enumerable: true,
  1607. configurable: true
  1608. });
  1609. // Methods
  1610. WaterMaterial.prototype.addToRenderList = function (node) {
  1611. if (this._refractionRTT && this._refractionRTT.renderList) {
  1612. this._refractionRTT.renderList.push(node);
  1613. }
  1614. if (this._reflectionRTT && this._reflectionRTT.renderList) {
  1615. this._reflectionRTT.renderList.push(node);
  1616. }
  1617. };
  1618. WaterMaterial.prototype.enableRenderTargets = function (enable) {
  1619. var refreshRate = enable ? 1 : 0;
  1620. if (this._refractionRTT) {
  1621. this._refractionRTT.refreshRate = refreshRate;
  1622. }
  1623. if (this._reflectionRTT) {
  1624. this._reflectionRTT.refreshRate = refreshRate;
  1625. }
  1626. };
  1627. WaterMaterial.prototype.getRenderList = function () {
  1628. return this._refractionRTT ? this._refractionRTT.renderList : [];
  1629. };
  1630. Object.defineProperty(WaterMaterial.prototype, "renderTargetsEnabled", {
  1631. get: function () {
  1632. return !(this._refractionRTT && this._refractionRTT.refreshRate === 0);
  1633. },
  1634. enumerable: true,
  1635. configurable: true
  1636. });
  1637. WaterMaterial.prototype.needAlphaBlending = function () {
  1638. return (this.alpha < 1.0);
  1639. };
  1640. WaterMaterial.prototype.needAlphaTesting = function () {
  1641. return false;
  1642. };
  1643. WaterMaterial.prototype.getAlphaTestTexture = function () {
  1644. return null;
  1645. };
  1646. WaterMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  1647. if (this.isFrozen) {
  1648. if (this._wasPreviouslyReady && subMesh.effect) {
  1649. return true;
  1650. }
  1651. }
  1652. if (!subMesh._materialDefines) {
  1653. subMesh._materialDefines = new WaterMaterialDefines();
  1654. }
  1655. var defines = subMesh._materialDefines;
  1656. var scene = this.getScene();
  1657. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  1658. if (this._renderId === scene.getRenderId()) {
  1659. return true;
  1660. }
  1661. }
  1662. var engine = scene.getEngine();
  1663. // Textures
  1664. if (defines._areTexturesDirty) {
  1665. defines._needUVs = false;
  1666. if (scene.texturesEnabled) {
  1667. if (this.bumpTexture && BABYLON.StandardMaterial.BumpTextureEnabled) {
  1668. if (!this.bumpTexture.isReady()) {
  1669. return false;
  1670. }
  1671. else {
  1672. defines._needUVs = true;
  1673. defines.BUMP = true;
  1674. }
  1675. }
  1676. if (BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  1677. defines.REFLECTION = true;
  1678. }
  1679. }
  1680. }
  1681. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  1682. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  1683. if (defines._areMiscDirty) {
  1684. if (this._fresnelSeparate) {
  1685. defines.FRESNELSEPARATE = true;
  1686. }
  1687. if (this._bumpSuperimpose) {
  1688. defines.BUMPSUPERIMPOSE = true;
  1689. }
  1690. if (this._bumpAffectsReflection) {
  1691. defines.BUMPAFFECTSREFLECTION = true;
  1692. }
  1693. }
  1694. // Lights
  1695. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);
  1696. // Attribs
  1697. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  1698. // Configure this
  1699. this._mesh = mesh;
  1700. if (this._waitingRenderList) {
  1701. for (var i = 0; i < this._waitingRenderList.length; i++) {
  1702. this.addToRenderList(scene.getNodeByID(this._waitingRenderList[i]));
  1703. }
  1704. this._waitingRenderList = null;
  1705. }
  1706. // Get correct effect
  1707. if (defines.isDirty) {
  1708. defines.markAsProcessed();
  1709. scene.resetCachedMaterial();
  1710. // Fallbacks
  1711. var fallbacks = new BABYLON.EffectFallbacks();
  1712. if (defines.FOG) {
  1713. fallbacks.addFallback(1, "FOG");
  1714. }
  1715. if (defines.LOGARITHMICDEPTH) {
  1716. fallbacks.addFallback(0, "LOGARITHMICDEPTH");
  1717. }
  1718. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  1719. if (defines.NUM_BONE_INFLUENCERS > 0) {
  1720. fallbacks.addCPUSkinningFallback(0, mesh);
  1721. }
  1722. //Attributes
  1723. var attribs = [BABYLON.VertexBuffer.PositionKind];
  1724. if (defines.NORMAL) {
  1725. attribs.push(BABYLON.VertexBuffer.NormalKind);
  1726. }
  1727. if (defines.UV1) {
  1728. attribs.push(BABYLON.VertexBuffer.UVKind);
  1729. }
  1730. if (defines.UV2) {
  1731. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  1732. }
  1733. if (defines.VERTEXCOLOR) {
  1734. attribs.push(BABYLON.VertexBuffer.ColorKind);
  1735. }
  1736. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  1737. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  1738. // Legacy browser patch
  1739. var shaderName = "water";
  1740. var join = defines.toString();
  1741. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  1742. "vFogInfos", "vFogColor", "pointSize",
  1743. "vNormalInfos",
  1744. "mBones",
  1745. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "normalMatrix",
  1746. "logarithmicDepthConstant",
  1747. // Water
  1748. "worldReflectionViewProjection", "windDirection", "waveLength", "time", "windForce",
  1749. "cameraPosition", "bumpHeight", "waveHeight", "waterColor", "waterColor2", "colorBlendFactor", "colorBlendFactor2", "waveSpeed"
  1750. ];
  1751. var samplers = ["normalSampler",
  1752. // Water
  1753. "refractionSampler", "reflectionSampler"
  1754. ];
  1755. var uniformBuffers = new Array();
  1756. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  1757. uniformsNames: uniforms,
  1758. uniformBuffersNames: uniformBuffers,
  1759. samplers: samplers,
  1760. defines: defines,
  1761. maxSimultaneousLights: this.maxSimultaneousLights
  1762. });
  1763. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  1764. attributes: attribs,
  1765. uniformsNames: uniforms,
  1766. uniformBuffersNames: uniformBuffers,
  1767. samplers: samplers,
  1768. defines: join,
  1769. fallbacks: fallbacks,
  1770. onCompiled: this.onCompiled,
  1771. onError: this.onError,
  1772. indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights }
  1773. }, engine), defines);
  1774. }
  1775. if (!subMesh.effect || !subMesh.effect.isReady()) {
  1776. return false;
  1777. }
  1778. this._renderId = scene.getRenderId();
  1779. this._wasPreviouslyReady = true;
  1780. return true;
  1781. };
  1782. WaterMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  1783. var scene = this.getScene();
  1784. var defines = subMesh._materialDefines;
  1785. if (!defines) {
  1786. return;
  1787. }
  1788. var effect = subMesh.effect;
  1789. if (!effect || !this._mesh) {
  1790. return;
  1791. }
  1792. this._activeEffect = effect;
  1793. // Matrices
  1794. this.bindOnlyWorldMatrix(world);
  1795. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  1796. // Bones
  1797. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  1798. if (this._mustRebind(scene, effect)) {
  1799. // Textures
  1800. if (this.bumpTexture && BABYLON.StandardMaterial.BumpTextureEnabled) {
  1801. this._activeEffect.setTexture("normalSampler", this.bumpTexture);
  1802. this._activeEffect.setFloat2("vNormalInfos", this.bumpTexture.coordinatesIndex, this.bumpTexture.level);
  1803. this._activeEffect.setMatrix("normalMatrix", this.bumpTexture.getTextureMatrix());
  1804. }
  1805. // Clip plane
  1806. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  1807. // Point size
  1808. if (this.pointsCloud) {
  1809. this._activeEffect.setFloat("pointSize", this.pointSize);
  1810. }
  1811. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  1812. }
  1813. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  1814. if (defines.SPECULARTERM) {
  1815. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  1816. }
  1817. if (scene.lightsEnabled && !this.disableLighting) {
  1818. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  1819. }
  1820. // View
  1821. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  1822. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  1823. }
  1824. // Fog
  1825. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  1826. // Log. depth
  1827. BABYLON.MaterialHelper.BindLogDepth(defines, this._activeEffect, scene);
  1828. // Water
  1829. if (BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  1830. this._activeEffect.setTexture("refractionSampler", this._refractionRTT);
  1831. this._activeEffect.setTexture("reflectionSampler", this._reflectionRTT);
  1832. }
  1833. var wrvp = this._mesh.getWorldMatrix().multiply(this._reflectionTransform).multiply(scene.getProjectionMatrix());
  1834. // Add delta time. Prevent adding delta time if it hasn't changed.
  1835. var deltaTime = scene.getEngine().getDeltaTime();
  1836. if (deltaTime !== this._lastDeltaTime) {
  1837. this._lastDeltaTime = deltaTime;
  1838. this._lastTime += this._lastDeltaTime;
  1839. }
  1840. this._activeEffect.setMatrix("worldReflectionViewProjection", wrvp);
  1841. this._activeEffect.setVector2("windDirection", this.windDirection);
  1842. this._activeEffect.setFloat("waveLength", this.waveLength);
  1843. this._activeEffect.setFloat("time", this._lastTime / 100000);
  1844. this._activeEffect.setFloat("windForce", this.windForce);
  1845. this._activeEffect.setFloat("waveHeight", this.waveHeight);
  1846. this._activeEffect.setFloat("bumpHeight", this.bumpHeight);
  1847. this._activeEffect.setColor4("waterColor", this.waterColor, 1.0);
  1848. this._activeEffect.setFloat("colorBlendFactor", this.colorBlendFactor);
  1849. this._activeEffect.setColor4("waterColor2", this.waterColor2, 1.0);
  1850. this._activeEffect.setFloat("colorBlendFactor2", this.colorBlendFactor2);
  1851. this._activeEffect.setFloat("waveSpeed", this.waveSpeed);
  1852. this._afterBind(mesh, this._activeEffect);
  1853. };
  1854. WaterMaterial.prototype._createRenderTargets = function (scene, renderTargetSize) {
  1855. var _this = this;
  1856. // Render targets
  1857. this._refractionRTT = new BABYLON.RenderTargetTexture(name + "_refraction", { width: renderTargetSize.x, height: renderTargetSize.y }, scene, false, true);
  1858. this._refractionRTT.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
  1859. this._refractionRTT.wrapV = BABYLON.Texture.MIRROR_ADDRESSMODE;
  1860. this._refractionRTT.ignoreCameraViewport = true;
  1861. this._reflectionRTT = new BABYLON.RenderTargetTexture(name + "_reflection", { width: renderTargetSize.x, height: renderTargetSize.y }, scene, false, true);
  1862. this._reflectionRTT.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
  1863. this._reflectionRTT.wrapV = BABYLON.Texture.MIRROR_ADDRESSMODE;
  1864. this._reflectionRTT.ignoreCameraViewport = true;
  1865. var isVisible;
  1866. var clipPlane = null;
  1867. var savedViewMatrix;
  1868. var mirrorMatrix = BABYLON.Matrix.Zero();
  1869. this._refractionRTT.onBeforeRender = function () {
  1870. if (_this._mesh) {
  1871. isVisible = _this._mesh.isVisible;
  1872. _this._mesh.isVisible = false;
  1873. }
  1874. };
  1875. this._refractionRTT.onAfterRender = function () {
  1876. if (_this._mesh) {
  1877. _this._mesh.isVisible = isVisible;
  1878. }
  1879. };
  1880. this._reflectionRTT.onBeforeRender = function () {
  1881. if (_this._mesh) {
  1882. isVisible = _this._mesh.isVisible;
  1883. _this._mesh.isVisible = false;
  1884. }
  1885. // Clip plane
  1886. clipPlane = scene.clipPlane;
  1887. var positiony = _this._mesh ? _this._mesh.position.y : 0.0;
  1888. scene.clipPlane = BABYLON.Plane.FromPositionAndNormal(new BABYLON.Vector3(0, positiony - 0.05, 0), new BABYLON.Vector3(0, -1, 0));
  1889. // Transform
  1890. BABYLON.Matrix.ReflectionToRef(scene.clipPlane, mirrorMatrix);
  1891. savedViewMatrix = scene.getViewMatrix();
  1892. mirrorMatrix.multiplyToRef(savedViewMatrix, _this._reflectionTransform);
  1893. scene.setTransformMatrix(_this._reflectionTransform, scene.getProjectionMatrix());
  1894. scene.getEngine().cullBackFaces = false;
  1895. scene._mirroredCameraPosition = BABYLON.Vector3.TransformCoordinates(scene.activeCamera.position, mirrorMatrix);
  1896. };
  1897. this._reflectionRTT.onAfterRender = function () {
  1898. if (_this._mesh) {
  1899. _this._mesh.isVisible = isVisible;
  1900. }
  1901. // Clip plane
  1902. scene.clipPlane = clipPlane;
  1903. // Transform
  1904. scene.setTransformMatrix(savedViewMatrix, scene.getProjectionMatrix());
  1905. scene.getEngine().cullBackFaces = true;
  1906. scene._mirroredCameraPosition = null;
  1907. };
  1908. };
  1909. WaterMaterial.prototype.getAnimatables = function () {
  1910. var results = [];
  1911. if (this.bumpTexture && this.bumpTexture.animations && this.bumpTexture.animations.length > 0) {
  1912. results.push(this.bumpTexture);
  1913. }
  1914. if (this._reflectionRTT && this._reflectionRTT.animations && this._reflectionRTT.animations.length > 0) {
  1915. results.push(this._reflectionRTT);
  1916. }
  1917. if (this._refractionRTT && this._refractionRTT.animations && this._refractionRTT.animations.length > 0) {
  1918. results.push(this._refractionRTT);
  1919. }
  1920. return results;
  1921. };
  1922. WaterMaterial.prototype.getActiveTextures = function () {
  1923. var activeTextures = _super.prototype.getActiveTextures.call(this);
  1924. if (this._bumpTexture) {
  1925. activeTextures.push(this._bumpTexture);
  1926. }
  1927. return activeTextures;
  1928. };
  1929. WaterMaterial.prototype.hasTexture = function (texture) {
  1930. if (_super.prototype.hasTexture.call(this, texture)) {
  1931. return true;
  1932. }
  1933. if (this._bumpTexture === texture) {
  1934. return true;
  1935. }
  1936. return false;
  1937. };
  1938. WaterMaterial.prototype.dispose = function (forceDisposeEffect) {
  1939. if (this.bumpTexture) {
  1940. this.bumpTexture.dispose();
  1941. }
  1942. var index = this.getScene().customRenderTargets.indexOf(this._refractionRTT);
  1943. if (index != -1) {
  1944. this.getScene().customRenderTargets.splice(index, 1);
  1945. }
  1946. index = -1;
  1947. index = this.getScene().customRenderTargets.indexOf(this._reflectionRTT);
  1948. if (index != -1) {
  1949. this.getScene().customRenderTargets.splice(index, 1);
  1950. }
  1951. if (this._reflectionRTT) {
  1952. this._reflectionRTT.dispose();
  1953. }
  1954. if (this._refractionRTT) {
  1955. this._refractionRTT.dispose();
  1956. }
  1957. _super.prototype.dispose.call(this, forceDisposeEffect);
  1958. };
  1959. WaterMaterial.prototype.clone = function (name) {
  1960. var _this = this;
  1961. return BABYLON.SerializationHelper.Clone(function () { return new WaterMaterial(name, _this.getScene()); }, this);
  1962. };
  1963. WaterMaterial.prototype.serialize = function () {
  1964. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  1965. serializationObject.customType = "BABYLON.WaterMaterial";
  1966. serializationObject.renderList = [];
  1967. if (this._refractionRTT && this._refractionRTT.renderList) {
  1968. for (var i = 0; i < this._refractionRTT.renderList.length; i++) {
  1969. serializationObject.renderList.push(this._refractionRTT.renderList[i].id);
  1970. }
  1971. }
  1972. return serializationObject;
  1973. };
  1974. WaterMaterial.prototype.getClassName = function () {
  1975. return "WaterMaterial";
  1976. };
  1977. // Statics
  1978. WaterMaterial.Parse = function (source, scene, rootUrl) {
  1979. var mat = BABYLON.SerializationHelper.Parse(function () { return new WaterMaterial(source.name, scene); }, source, scene, rootUrl);
  1980. mat._waitingRenderList = source.renderList;
  1981. return mat;
  1982. };
  1983. WaterMaterial.CreateDefaultMesh = function (name, scene) {
  1984. var mesh = BABYLON.Mesh.CreateGround(name, 512, 512, 32, scene, false);
  1985. return mesh;
  1986. };
  1987. __decorate([
  1988. BABYLON.serializeAsTexture("bumpTexture")
  1989. ], WaterMaterial.prototype, "_bumpTexture", void 0);
  1990. __decorate([
  1991. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1992. ], WaterMaterial.prototype, "bumpTexture", void 0);
  1993. __decorate([
  1994. BABYLON.serializeAsColor3()
  1995. ], WaterMaterial.prototype, "diffuseColor", void 0);
  1996. __decorate([
  1997. BABYLON.serializeAsColor3()
  1998. ], WaterMaterial.prototype, "specularColor", void 0);
  1999. __decorate([
  2000. BABYLON.serialize()
  2001. ], WaterMaterial.prototype, "specularPower", void 0);
  2002. __decorate([
  2003. BABYLON.serialize("disableLighting")
  2004. ], WaterMaterial.prototype, "_disableLighting", void 0);
  2005. __decorate([
  2006. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  2007. ], WaterMaterial.prototype, "disableLighting", void 0);
  2008. __decorate([
  2009. BABYLON.serialize("maxSimultaneousLights")
  2010. ], WaterMaterial.prototype, "_maxSimultaneousLights", void 0);
  2011. __decorate([
  2012. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  2013. ], WaterMaterial.prototype, "maxSimultaneousLights", void 0);
  2014. __decorate([
  2015. BABYLON.serialize()
  2016. ], WaterMaterial.prototype, "windForce", void 0);
  2017. __decorate([
  2018. BABYLON.serializeAsVector2()
  2019. ], WaterMaterial.prototype, "windDirection", void 0);
  2020. __decorate([
  2021. BABYLON.serialize()
  2022. ], WaterMaterial.prototype, "waveHeight", void 0);
  2023. __decorate([
  2024. BABYLON.serialize()
  2025. ], WaterMaterial.prototype, "bumpHeight", void 0);
  2026. __decorate([
  2027. BABYLON.serialize("bumpSuperimpose")
  2028. ], WaterMaterial.prototype, "_bumpSuperimpose", void 0);
  2029. __decorate([
  2030. BABYLON.expandToProperty("_markAllSubMeshesAsMiscDirty")
  2031. ], WaterMaterial.prototype, "bumpSuperimpose", void 0);
  2032. __decorate([
  2033. BABYLON.serialize("fresnelSeparate")
  2034. ], WaterMaterial.prototype, "_fresnelSeparate", void 0);
  2035. __decorate([
  2036. BABYLON.expandToProperty("_markAllSubMeshesAsMiscDirty")
  2037. ], WaterMaterial.prototype, "fresnelSeparate", void 0);
  2038. __decorate([
  2039. BABYLON.serialize("bumpAffectsReflection")
  2040. ], WaterMaterial.prototype, "_bumpAffectsReflection", void 0);
  2041. __decorate([
  2042. BABYLON.expandToProperty("_markAllSubMeshesAsMiscDirty")
  2043. ], WaterMaterial.prototype, "bumpAffectsReflection", void 0);
  2044. __decorate([
  2045. BABYLON.serializeAsColor3()
  2046. ], WaterMaterial.prototype, "waterColor", void 0);
  2047. __decorate([
  2048. BABYLON.serialize()
  2049. ], WaterMaterial.prototype, "colorBlendFactor", void 0);
  2050. __decorate([
  2051. BABYLON.serializeAsColor3()
  2052. ], WaterMaterial.prototype, "waterColor2", void 0);
  2053. __decorate([
  2054. BABYLON.serialize()
  2055. ], WaterMaterial.prototype, "colorBlendFactor2", void 0);
  2056. __decorate([
  2057. BABYLON.serialize()
  2058. ], WaterMaterial.prototype, "waveLength", void 0);
  2059. __decorate([
  2060. BABYLON.serialize()
  2061. ], WaterMaterial.prototype, "waveSpeed", void 0);
  2062. __decorate([
  2063. BABYLON.serialize()
  2064. ], WaterMaterial.prototype, "useLogarithmicDepth", null);
  2065. return WaterMaterial;
  2066. }(BABYLON.PushMaterial));
  2067. BABYLON.WaterMaterial = WaterMaterial;
  2068. })(BABYLON || (BABYLON = {}));
  2069. //# sourceMappingURL=babylon.waterMaterial.js.map
  2070. BABYLON.Effect.ShadersStore['waterVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\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<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef BUMP\nvarying vec2 vNormalUV;\n#ifdef BUMPSUPERIMPOSE\nvarying vec2 vNormalUV2;\n#endif\nuniform mat4 normalMatrix;\nuniform vec2 vNormalInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<logDepthDeclaration>\n\nuniform mat4 worldReflectionViewProjection;\nuniform vec2 windDirection;\nuniform float waveLength;\nuniform float time;\nuniform float windForce;\nuniform float waveHeight;\nuniform float waveSpeed;\n\nvarying vec3 vPosition;\nvarying vec3 vRefractionMapTexCoord;\nvarying vec3 vReflectionMapTexCoord;\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,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 BUMP\nif (vNormalInfos.x == 0.)\n{\nvNormalUV=vec2(normalMatrix*vec4((uv*1.0)/waveLength+time*windForce*windDirection,1.0,0.0));\n#ifdef BUMPSUPERIMPOSE\nvNormalUV2=vec2(normalMatrix*vec4((uv*0.721)/waveLength+time*1.2*windForce*windDirection,1.0,0.0));\n#endif\n}\nelse\n{\nvNormalUV=vec2(normalMatrix*vec4((uv2*1.0)/waveLength+time*windForce*windDirection ,1.0,0.0));\n#ifdef BUMPSUPERIMPOSE\nvNormalUV2=vec2(normalMatrix*vec4((uv2*0.721)/waveLength+time*1.2*windForce*windDirection ,1.0,0.0));\n#endif\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\nvec3 p=position;\nfloat newY=(sin(((p.x/0.05)+time*waveSpeed))*waveHeight*windDirection.x*5.0)\n+(cos(((p.z/0.05)+time*waveSpeed))*waveHeight*windDirection.y*5.0);\np.y+=abs(newY);\ngl_Position=viewProjection*finalWorld*vec4(p,1.0);\n#ifdef REFLECTION\nworldPos=viewProjection*finalWorld*vec4(p,1.0);\n\nvPosition=position;\nvRefractionMapTexCoord.x=0.5*(worldPos.w+worldPos.x);\nvRefractionMapTexCoord.y=0.5*(worldPos.w+worldPos.y);\nvRefractionMapTexCoord.z=worldPos.w;\nworldPos=worldReflectionViewProjection*vec4(position,1.0);\nvReflectionMapTexCoord.x=0.5*(worldPos.w+worldPos.x);\nvReflectionMapTexCoord.y=0.5*(worldPos.w+worldPos.y);\nvReflectionMapTexCoord.z=worldPos.w;\n#endif\n#include<logDepthVertex>\n}\n";
  2071. BABYLON.Effect.ShadersStore['waterPixelShader'] = "#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nprecision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef BUMP\nvarying vec2 vNormalUV;\nvarying vec2 vNormalUV2;\nuniform sampler2D normalSampler;\nuniform vec2 vNormalInfos;\n#endif\nuniform sampler2D refractionSampler;\nuniform sampler2D reflectionSampler;\n\nconst float LOG2=1.442695;\nuniform vec3 cameraPosition;\nuniform vec4 waterColor;\nuniform float colorBlendFactor;\nuniform vec4 waterColor2;\nuniform float colorBlendFactor2;\nuniform float bumpHeight;\nuniform float time;\n\nvarying vec3 vRefractionMapTexCoord;\nvarying vec3 vReflectionMapTexCoord;\nvarying vec3 vPosition;\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef BUMP\n#ifdef BUMPSUPERIMPOSE\nbaseColor=0.6*texture2D(normalSampler,vNormalUV)+0.4*texture2D(normalSampler,vec2(vNormalUV2.x,vNormalUV2.y));\n#else\nbaseColor=texture2D(normalSampler,vNormalUV);\n#endif\nvec3 bumpColor=baseColor.rgb;\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\nbaseColor.rgb*=vNormalInfos.y;\n#else\nvec3 bumpColor=vec3(1.0);\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec2 perturbation=bumpHeight*(baseColor.rg-0.5);\n#ifdef BUMPAFFECTSREFLECTION\nvec3 normalW=normalize(vNormalW+vec3(perturbation.x*8.0,0.0,perturbation.y*8.0));\nif (normalW.y<0.0) {\nnormalW.y=-normalW.y;\n}\n#else\nvec3 normalW=normalize(vNormalW);\n#endif\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\nvec2 perturbation=bumpHeight*(vec2(1.0,1.0)-0.5);\n#endif\n#ifdef FRESNELSEPARATE\n#ifdef REFLECTION\n\nvec3 eyeVector=normalize(vEyePosition-vPosition);\nvec2 projectedRefractionTexCoords=clamp(vRefractionMapTexCoord.xy/vRefractionMapTexCoord.z+perturbation*0.5,0.0,1.0);\nvec4 refractiveColor=texture2D(refractionSampler,projectedRefractionTexCoords);\nvec2 projectedReflectionTexCoords=clamp(vec2(\nvReflectionMapTexCoord.x/vReflectionMapTexCoord.z+perturbation.x*0.3,\nvReflectionMapTexCoord.y/vReflectionMapTexCoord.z+perturbation.y\n),0.0,1.0);\nvec4 reflectiveColor=texture2D(reflectionSampler,projectedReflectionTexCoords);\nvec3 upVector=vec3(0.0,1.0,0.0);\nfloat fresnelTerm=clamp(abs(pow(dot(eyeVector,upVector),3.0)),0.05,0.65);\nfloat IfresnelTerm=1.0-fresnelTerm;\nrefractiveColor=colorBlendFactor*waterColor+(1.0-colorBlendFactor)*refractiveColor;\nreflectiveColor=IfresnelTerm*colorBlendFactor2*waterColor+(1.0-colorBlendFactor2*IfresnelTerm)*reflectiveColor;\nvec4 combinedColor=refractiveColor*fresnelTerm+reflectiveColor*IfresnelTerm;\nbaseColor=combinedColor;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularBase=vec3(0.,0.,0.);\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\nvec3 finalDiffuse=clamp(baseColor.rgb,0.0,1.0);\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#else \n#ifdef REFLECTION\n\nvec3 eyeVector=normalize(vEyePosition-vPosition);\nvec2 projectedRefractionTexCoords=clamp(vRefractionMapTexCoord.xy/vRefractionMapTexCoord.z+perturbation,0.0,1.0);\nvec4 refractiveColor=texture2D(refractionSampler,projectedRefractionTexCoords);\nvec2 projectedReflectionTexCoords=clamp(vReflectionMapTexCoord.xy/vReflectionMapTexCoord.z+perturbation,0.0,1.0);\nvec4 reflectiveColor=texture2D(reflectionSampler,projectedReflectionTexCoords);\nvec3 upVector=vec3(0.0,1.0,0.0);\nfloat fresnelTerm=max(dot(eyeVector,upVector),0.0);\nvec4 combinedColor=refractiveColor*fresnelTerm+reflectiveColor*(1.0-fresnelTerm);\nbaseColor=colorBlendFactor*waterColor+(1.0-colorBlendFactor)*combinedColor;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularBase=vec3(0.,0.,0.);\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\nvec3 finalDiffuse=clamp(baseColor.rgb,0.0,1.0);\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#endif\n\nvec4 color=vec4(finalDiffuse+finalSpecular,alpha);\n#include<logDepthFragment>\n#include<fogFragment>\ngl_FragColor=color;\n}\n";
  2072. var BABYLON;
  2073. (function (BABYLON) {
  2074. var FireMaterialDefines = /** @class */ (function (_super) {
  2075. __extends(FireMaterialDefines, _super);
  2076. function FireMaterialDefines() {
  2077. var _this = _super.call(this) || this;
  2078. _this.DIFFUSE = false;
  2079. _this.CLIPPLANE = false;
  2080. _this.CLIPPLANE2 = false;
  2081. _this.CLIPPLANE3 = false;
  2082. _this.CLIPPLANE4 = false;
  2083. _this.ALPHATEST = false;
  2084. _this.DEPTHPREPASS = false;
  2085. _this.POINTSIZE = false;
  2086. _this.FOG = false;
  2087. _this.UV1 = false;
  2088. _this.VERTEXCOLOR = false;
  2089. _this.VERTEXALPHA = false;
  2090. _this.BonesPerMesh = 0;
  2091. _this.NUM_BONE_INFLUENCERS = 0;
  2092. _this.INSTANCES = false;
  2093. _this.rebuild();
  2094. return _this;
  2095. }
  2096. return FireMaterialDefines;
  2097. }(BABYLON.MaterialDefines));
  2098. var FireMaterial = /** @class */ (function (_super) {
  2099. __extends(FireMaterial, _super);
  2100. function FireMaterial(name, scene) {
  2101. var _this = _super.call(this, name, scene) || this;
  2102. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  2103. _this.speed = 1.0;
  2104. _this._scaledDiffuse = new BABYLON.Color3();
  2105. _this._lastTime = 0;
  2106. return _this;
  2107. }
  2108. FireMaterial.prototype.needAlphaBlending = function () {
  2109. return false;
  2110. };
  2111. FireMaterial.prototype.needAlphaTesting = function () {
  2112. return true;
  2113. };
  2114. FireMaterial.prototype.getAlphaTestTexture = function () {
  2115. return null;
  2116. };
  2117. // Methods
  2118. FireMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  2119. if (this.isFrozen) {
  2120. if (this._wasPreviouslyReady && subMesh.effect) {
  2121. return true;
  2122. }
  2123. }
  2124. if (!subMesh._materialDefines) {
  2125. subMesh._materialDefines = new FireMaterialDefines();
  2126. }
  2127. var defines = subMesh._materialDefines;
  2128. var scene = this.getScene();
  2129. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  2130. if (this._renderId === scene.getRenderId()) {
  2131. return true;
  2132. }
  2133. }
  2134. var engine = scene.getEngine();
  2135. // Textures
  2136. if (defines._areTexturesDirty) {
  2137. defines._needUVs = false;
  2138. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2139. if (!this._diffuseTexture.isReady()) {
  2140. return false;
  2141. }
  2142. else {
  2143. defines._needUVs = true;
  2144. defines.DIFFUSE = true;
  2145. }
  2146. }
  2147. }
  2148. defines.ALPHATEST = this._opacityTexture ? true : false;
  2149. // Misc.
  2150. if (defines._areMiscDirty) {
  2151. defines.POINTSIZE = (this.pointsCloud || scene.forcePointsCloud);
  2152. defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled);
  2153. }
  2154. // Values that need to be evaluated on every frame
  2155. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  2156. // Attribs
  2157. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
  2158. // Get correct effect
  2159. if (defines.isDirty) {
  2160. defines.markAsProcessed();
  2161. scene.resetCachedMaterial();
  2162. // Fallbacks
  2163. var fallbacks = new BABYLON.EffectFallbacks();
  2164. if (defines.FOG) {
  2165. fallbacks.addFallback(1, "FOG");
  2166. }
  2167. if (defines.NUM_BONE_INFLUENCERS > 0) {
  2168. fallbacks.addCPUSkinningFallback(0, mesh);
  2169. }
  2170. //Attributes
  2171. var attribs = [BABYLON.VertexBuffer.PositionKind];
  2172. if (defines.UV1) {
  2173. attribs.push(BABYLON.VertexBuffer.UVKind);
  2174. }
  2175. if (defines.VERTEXCOLOR) {
  2176. attribs.push(BABYLON.VertexBuffer.ColorKind);
  2177. }
  2178. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  2179. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  2180. // Legacy browser patch
  2181. var shaderName = "fire";
  2182. var join = defines.toString();
  2183. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  2184. attributes: attribs,
  2185. uniformsNames: ["world", "view", "viewProjection", "vEyePosition",
  2186. "vFogInfos", "vFogColor", "pointSize",
  2187. "vDiffuseInfos",
  2188. "mBones",
  2189. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix",
  2190. // Fire
  2191. "time", "speed"
  2192. ],
  2193. uniformBuffersNames: [],
  2194. samplers: ["diffuseSampler",
  2195. // Fire
  2196. "distortionSampler", "opacitySampler"
  2197. ],
  2198. defines: join,
  2199. fallbacks: fallbacks,
  2200. onCompiled: this.onCompiled,
  2201. onError: this.onError,
  2202. indexParameters: null,
  2203. maxSimultaneousLights: 4,
  2204. transformFeedbackVaryings: null
  2205. }, engine), defines);
  2206. }
  2207. if (!subMesh.effect || !subMesh.effect.isReady()) {
  2208. return false;
  2209. }
  2210. this._renderId = scene.getRenderId();
  2211. this._wasPreviouslyReady = true;
  2212. return true;
  2213. };
  2214. FireMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  2215. var scene = this.getScene();
  2216. var defines = subMesh._materialDefines;
  2217. if (!defines) {
  2218. return;
  2219. }
  2220. var effect = subMesh.effect;
  2221. if (!effect) {
  2222. return;
  2223. }
  2224. this._activeEffect = effect;
  2225. // Matrices
  2226. this.bindOnlyWorldMatrix(world);
  2227. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  2228. // Bones
  2229. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  2230. if (this._mustRebind(scene, effect)) {
  2231. // Textures
  2232. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2233. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  2234. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  2235. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  2236. this._activeEffect.setTexture("distortionSampler", this._distortionTexture);
  2237. this._activeEffect.setTexture("opacitySampler", this._opacityTexture);
  2238. }
  2239. // Clip plane
  2240. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  2241. // Point size
  2242. if (this.pointsCloud) {
  2243. this._activeEffect.setFloat("pointSize", this.pointSize);
  2244. }
  2245. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  2246. }
  2247. this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  2248. // View
  2249. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  2250. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  2251. }
  2252. // Fog
  2253. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  2254. // Time
  2255. this._lastTime += scene.getEngine().getDeltaTime();
  2256. this._activeEffect.setFloat("time", this._lastTime);
  2257. // Speed
  2258. this._activeEffect.setFloat("speed", this.speed);
  2259. this._afterBind(mesh, this._activeEffect);
  2260. };
  2261. FireMaterial.prototype.getAnimatables = function () {
  2262. var results = [];
  2263. if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
  2264. results.push(this._diffuseTexture);
  2265. }
  2266. if (this._distortionTexture && this._distortionTexture.animations && this._distortionTexture.animations.length > 0) {
  2267. results.push(this._distortionTexture);
  2268. }
  2269. if (this._opacityTexture && this._opacityTexture.animations && this._opacityTexture.animations.length > 0) {
  2270. results.push(this._opacityTexture);
  2271. }
  2272. return results;
  2273. };
  2274. FireMaterial.prototype.getActiveTextures = function () {
  2275. var activeTextures = _super.prototype.getActiveTextures.call(this);
  2276. if (this._diffuseTexture) {
  2277. activeTextures.push(this._diffuseTexture);
  2278. }
  2279. if (this._distortionTexture) {
  2280. activeTextures.push(this._distortionTexture);
  2281. }
  2282. if (this._opacityTexture) {
  2283. activeTextures.push(this._opacityTexture);
  2284. }
  2285. return activeTextures;
  2286. };
  2287. FireMaterial.prototype.hasTexture = function (texture) {
  2288. if (_super.prototype.hasTexture.call(this, texture)) {
  2289. return true;
  2290. }
  2291. if (this._diffuseTexture === texture) {
  2292. return true;
  2293. }
  2294. if (this._distortionTexture === texture) {
  2295. return true;
  2296. }
  2297. if (this._opacityTexture === texture) {
  2298. return true;
  2299. }
  2300. return false;
  2301. };
  2302. FireMaterial.prototype.getClassName = function () {
  2303. return "FireMaterial";
  2304. };
  2305. FireMaterial.prototype.dispose = function (forceDisposeEffect) {
  2306. if (this._diffuseTexture) {
  2307. this._diffuseTexture.dispose();
  2308. }
  2309. if (this._distortionTexture) {
  2310. this._distortionTexture.dispose();
  2311. }
  2312. _super.prototype.dispose.call(this, forceDisposeEffect);
  2313. };
  2314. FireMaterial.prototype.clone = function (name) {
  2315. var _this = this;
  2316. return BABYLON.SerializationHelper.Clone(function () { return new FireMaterial(name, _this.getScene()); }, this);
  2317. };
  2318. FireMaterial.prototype.serialize = function () {
  2319. var serializationObject = _super.prototype.serialize.call(this);
  2320. serializationObject.customType = "BABYLON.FireMaterial";
  2321. serializationObject.diffuseColor = this.diffuseColor.asArray();
  2322. serializationObject.speed = this.speed;
  2323. if (this._diffuseTexture) {
  2324. serializationObject._diffuseTexture = this._diffuseTexture.serialize();
  2325. }
  2326. if (this._distortionTexture) {
  2327. serializationObject._distortionTexture = this._distortionTexture.serialize();
  2328. }
  2329. if (this._opacityTexture) {
  2330. serializationObject._opacityTexture = this._opacityTexture.serialize();
  2331. }
  2332. return serializationObject;
  2333. };
  2334. FireMaterial.Parse = function (source, scene, rootUrl) {
  2335. var material = new FireMaterial(source.name, scene);
  2336. material.diffuseColor = BABYLON.Color3.FromArray(source.diffuseColor);
  2337. material.speed = source.speed;
  2338. material.alpha = source.alpha;
  2339. material.id = source.id;
  2340. BABYLON.Tags.AddTagsTo(material, source.tags);
  2341. material.backFaceCulling = source.backFaceCulling;
  2342. material.wireframe = source.wireframe;
  2343. if (source._diffuseTexture) {
  2344. material._diffuseTexture = BABYLON.Texture.Parse(source._diffuseTexture, scene, rootUrl);
  2345. }
  2346. if (source._distortionTexture) {
  2347. material._distortionTexture = BABYLON.Texture.Parse(source._distortionTexture, scene, rootUrl);
  2348. }
  2349. if (source._opacityTexture) {
  2350. material._opacityTexture = BABYLON.Texture.Parse(source._opacityTexture, scene, rootUrl);
  2351. }
  2352. if (source.checkReadyOnlyOnce) {
  2353. material.checkReadyOnlyOnce = source.checkReadyOnlyOnce;
  2354. }
  2355. return material;
  2356. };
  2357. __decorate([
  2358. BABYLON.serializeAsTexture("diffuseTexture")
  2359. ], FireMaterial.prototype, "_diffuseTexture", void 0);
  2360. __decorate([
  2361. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2362. ], FireMaterial.prototype, "diffuseTexture", void 0);
  2363. __decorate([
  2364. BABYLON.serializeAsTexture("distortionTexture")
  2365. ], FireMaterial.prototype, "_distortionTexture", void 0);
  2366. __decorate([
  2367. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2368. ], FireMaterial.prototype, "distortionTexture", void 0);
  2369. __decorate([
  2370. BABYLON.serializeAsTexture("opacityTexture")
  2371. ], FireMaterial.prototype, "_opacityTexture", void 0);
  2372. __decorate([
  2373. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2374. ], FireMaterial.prototype, "opacityTexture", void 0);
  2375. __decorate([
  2376. BABYLON.serializeAsColor3("diffuse")
  2377. ], FireMaterial.prototype, "diffuseColor", void 0);
  2378. __decorate([
  2379. BABYLON.serialize()
  2380. ], FireMaterial.prototype, "speed", void 0);
  2381. return FireMaterial;
  2382. }(BABYLON.PushMaterial));
  2383. BABYLON.FireMaterial = FireMaterial;
  2384. })(BABYLON || (BABYLON = {}));
  2385. //# sourceMappingURL=babylon.fireMaterial.js.map
  2386. BABYLON.Effect.ShadersStore['fireVertexShader'] = "precision highp float;\n\nattribute vec3 position;\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<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n\nuniform float time;\nuniform float speed;\n#ifdef DIFFUSE\nvarying vec2 vDistortionCoords1;\nvarying vec2 vDistortionCoords2;\nvarying vec2 vDistortionCoords3;\n#endif\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n\n#ifdef DIFFUSE\nvDiffuseUV=uv;\nvDiffuseUV.y-=0.2;\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n#ifdef DIFFUSE\n\nvec3 layerSpeed=vec3(-0.2,-0.52,-0.1)*speed;\nvDistortionCoords1.x=uv.x;\nvDistortionCoords1.y=uv.y+layerSpeed.x*time/1000.0;\nvDistortionCoords2.x=uv.x;\nvDistortionCoords2.y=uv.y+layerSpeed.y*time/1000.0;\nvDistortionCoords3.x=uv.x;\nvDistortionCoords3.y=uv.y+layerSpeed.z*time/1000.0;\n#endif\n}\n";
  2387. BABYLON.Effect.ShadersStore['firePixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n\nuniform sampler2D distortionSampler;\nuniform sampler2D opacitySampler;\n#ifdef DIFFUSE\nvarying vec2 vDistortionCoords1;\nvarying vec2 vDistortionCoords2;\nvarying vec2 vDistortionCoords3;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvec4 bx2(vec4 x)\n{\nreturn vec4(2.0)*x-vec4(1.0);\n}\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\n\nfloat alpha=1.0;\n#ifdef DIFFUSE\n\nconst float distortionAmount0=0.092;\nconst float distortionAmount1=0.092;\nconst float distortionAmount2=0.092;\nvec2 heightAttenuation=vec2(0.3,0.39);\nvec4 noise0=texture2D(distortionSampler,vDistortionCoords1);\nvec4 noise1=texture2D(distortionSampler,vDistortionCoords2);\nvec4 noise2=texture2D(distortionSampler,vDistortionCoords3);\nvec4 noiseSum=bx2(noise0)*distortionAmount0+bx2(noise1)*distortionAmount1+bx2(noise2)*distortionAmount2;\nvec4 perturbedBaseCoords=vec4(vDiffuseUV,0.0,1.0)+noiseSum*(vDiffuseUV.y*heightAttenuation.x+heightAttenuation.y);\nvec4 opacityColor=texture2D(opacitySampler,perturbedBaseCoords.xy);\n#ifdef ALPHATEST\nif (opacityColor.r<0.1)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor=texture2D(diffuseSampler,perturbedBaseCoords.xy)*2.0;\nbaseColor*=opacityColor;\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 diffuseBase=vec3(1.0,1.0,1.0);\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n\nvec4 color=vec4(baseColor.rgb,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
  2388. var BABYLON;
  2389. (function (BABYLON) {
  2390. var FurMaterialDefines = /** @class */ (function (_super) {
  2391. __extends(FurMaterialDefines, _super);
  2392. function FurMaterialDefines() {
  2393. var _this = _super.call(this) || this;
  2394. _this.DIFFUSE = false;
  2395. _this.HEIGHTMAP = false;
  2396. _this.CLIPPLANE = false;
  2397. _this.CLIPPLANE2 = false;
  2398. _this.CLIPPLANE3 = false;
  2399. _this.CLIPPLANE4 = false;
  2400. _this.ALPHATEST = false;
  2401. _this.DEPTHPREPASS = false;
  2402. _this.POINTSIZE = false;
  2403. _this.FOG = false;
  2404. _this.NORMAL = false;
  2405. _this.UV1 = false;
  2406. _this.UV2 = false;
  2407. _this.VERTEXCOLOR = false;
  2408. _this.VERTEXALPHA = false;
  2409. _this.NUM_BONE_INFLUENCERS = 0;
  2410. _this.BonesPerMesh = 0;
  2411. _this.INSTANCES = false;
  2412. _this.HIGHLEVEL = false;
  2413. _this.rebuild();
  2414. return _this;
  2415. }
  2416. return FurMaterialDefines;
  2417. }(BABYLON.MaterialDefines));
  2418. var FurMaterial = /** @class */ (function (_super) {
  2419. __extends(FurMaterial, _super);
  2420. function FurMaterial(name, scene) {
  2421. var _this = _super.call(this, name, scene) || this;
  2422. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  2423. _this.furLength = 1;
  2424. _this.furAngle = 0;
  2425. _this.furColor = new BABYLON.Color3(0.44, 0.21, 0.02);
  2426. _this.furOffset = 0.0;
  2427. _this.furSpacing = 12;
  2428. _this.furGravity = new BABYLON.Vector3(0, 0, 0);
  2429. _this.furSpeed = 100;
  2430. _this.furDensity = 20;
  2431. _this.furOcclusion = 0.0;
  2432. _this._disableLighting = false;
  2433. _this._maxSimultaneousLights = 4;
  2434. _this.highLevelFur = true;
  2435. _this._furTime = 0;
  2436. return _this;
  2437. }
  2438. Object.defineProperty(FurMaterial.prototype, "furTime", {
  2439. get: function () {
  2440. return this._furTime;
  2441. },
  2442. set: function (furTime) {
  2443. this._furTime = furTime;
  2444. },
  2445. enumerable: true,
  2446. configurable: true
  2447. });
  2448. FurMaterial.prototype.needAlphaBlending = function () {
  2449. return (this.alpha < 1.0);
  2450. };
  2451. FurMaterial.prototype.needAlphaTesting = function () {
  2452. return false;
  2453. };
  2454. FurMaterial.prototype.getAlphaTestTexture = function () {
  2455. return null;
  2456. };
  2457. FurMaterial.prototype.updateFur = function () {
  2458. for (var i = 1; i < this._meshes.length; i++) {
  2459. var offsetFur = this._meshes[i].material;
  2460. offsetFur.furLength = this.furLength;
  2461. offsetFur.furAngle = this.furAngle;
  2462. offsetFur.furGravity = this.furGravity;
  2463. offsetFur.furSpacing = this.furSpacing;
  2464. offsetFur.furSpeed = this.furSpeed;
  2465. offsetFur.furColor = this.furColor;
  2466. offsetFur.diffuseTexture = this.diffuseTexture;
  2467. offsetFur.furTexture = this.furTexture;
  2468. offsetFur.highLevelFur = this.highLevelFur;
  2469. offsetFur.furTime = this.furTime;
  2470. offsetFur.furDensity = this.furDensity;
  2471. }
  2472. };
  2473. // Methods
  2474. FurMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  2475. if (this.isFrozen) {
  2476. if (this._wasPreviouslyReady && subMesh.effect) {
  2477. return true;
  2478. }
  2479. }
  2480. if (!subMesh._materialDefines) {
  2481. subMesh._materialDefines = new FurMaterialDefines();
  2482. }
  2483. var defines = subMesh._materialDefines;
  2484. var scene = this.getScene();
  2485. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  2486. if (this._renderId === scene.getRenderId()) {
  2487. return true;
  2488. }
  2489. }
  2490. var engine = scene.getEngine();
  2491. // Textures
  2492. if (defines._areTexturesDirty) {
  2493. if (scene.texturesEnabled) {
  2494. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2495. if (!this.diffuseTexture.isReady()) {
  2496. return false;
  2497. }
  2498. else {
  2499. defines._needUVs = true;
  2500. defines.DIFFUSE = true;
  2501. }
  2502. }
  2503. if (this.heightTexture && engine.getCaps().maxVertexTextureImageUnits) {
  2504. if (!this.heightTexture.isReady()) {
  2505. return false;
  2506. }
  2507. else {
  2508. defines._needUVs = true;
  2509. defines.HEIGHTMAP = true;
  2510. }
  2511. }
  2512. }
  2513. }
  2514. // High level
  2515. if (this.highLevelFur !== defines.HIGHLEVEL) {
  2516. defines.HIGHLEVEL = true;
  2517. defines.markAsUnprocessed();
  2518. }
  2519. // Misc.
  2520. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  2521. // Lights
  2522. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  2523. // Values that need to be evaluated on every frame
  2524. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  2525. // Attribs
  2526. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  2527. // Get correct effect
  2528. if (defines.isDirty) {
  2529. defines.markAsProcessed();
  2530. scene.resetCachedMaterial();
  2531. // Fallbacks
  2532. var fallbacks = new BABYLON.EffectFallbacks();
  2533. if (defines.FOG) {
  2534. fallbacks.addFallback(1, "FOG");
  2535. }
  2536. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  2537. if (defines.NUM_BONE_INFLUENCERS > 0) {
  2538. fallbacks.addCPUSkinningFallback(0, mesh);
  2539. }
  2540. //Attributes
  2541. var attribs = [BABYLON.VertexBuffer.PositionKind];
  2542. if (defines.NORMAL) {
  2543. attribs.push(BABYLON.VertexBuffer.NormalKind);
  2544. }
  2545. if (defines.UV1) {
  2546. attribs.push(BABYLON.VertexBuffer.UVKind);
  2547. }
  2548. if (defines.UV2) {
  2549. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  2550. }
  2551. if (defines.VERTEXCOLOR) {
  2552. attribs.push(BABYLON.VertexBuffer.ColorKind);
  2553. }
  2554. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  2555. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  2556. // Legacy browser patch
  2557. var shaderName = "fur";
  2558. var join = defines.toString();
  2559. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  2560. "vFogInfos", "vFogColor", "pointSize",
  2561. "vDiffuseInfos",
  2562. "mBones",
  2563. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix",
  2564. "furLength", "furAngle", "furColor", "furOffset", "furGravity", "furTime", "furSpacing", "furDensity", "furOcclusion"
  2565. ];
  2566. var samplers = ["diffuseSampler",
  2567. "heightTexture", "furTexture"
  2568. ];
  2569. var uniformBuffers = new Array();
  2570. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  2571. uniformsNames: uniforms,
  2572. uniformBuffersNames: uniformBuffers,
  2573. samplers: samplers,
  2574. defines: defines,
  2575. maxSimultaneousLights: this.maxSimultaneousLights
  2576. });
  2577. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  2578. attributes: attribs,
  2579. uniformsNames: uniforms,
  2580. uniformBuffersNames: uniformBuffers,
  2581. samplers: samplers,
  2582. defines: join,
  2583. fallbacks: fallbacks,
  2584. onCompiled: this.onCompiled,
  2585. onError: this.onError,
  2586. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  2587. }, engine), defines);
  2588. }
  2589. if (!subMesh.effect || !subMesh.effect.isReady()) {
  2590. return false;
  2591. }
  2592. this._renderId = scene.getRenderId();
  2593. this._wasPreviouslyReady = true;
  2594. return true;
  2595. };
  2596. FurMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  2597. var scene = this.getScene();
  2598. var defines = subMesh._materialDefines;
  2599. if (!defines) {
  2600. return;
  2601. }
  2602. var effect = subMesh.effect;
  2603. if (!effect) {
  2604. return;
  2605. }
  2606. this._activeEffect = effect;
  2607. // Matrices
  2608. this.bindOnlyWorldMatrix(world);
  2609. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  2610. // Bones
  2611. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  2612. if (scene.getCachedMaterial() !== this) {
  2613. // Textures
  2614. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2615. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  2616. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  2617. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  2618. }
  2619. if (this._heightTexture) {
  2620. this._activeEffect.setTexture("heightTexture", this._heightTexture);
  2621. }
  2622. // Clip plane
  2623. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  2624. // Point size
  2625. if (this.pointsCloud) {
  2626. this._activeEffect.setFloat("pointSize", this.pointSize);
  2627. }
  2628. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  2629. }
  2630. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  2631. if (scene.lightsEnabled && !this.disableLighting) {
  2632. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  2633. }
  2634. // View
  2635. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  2636. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  2637. }
  2638. // Fog
  2639. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  2640. this._activeEffect.setFloat("furLength", this.furLength);
  2641. this._activeEffect.setFloat("furAngle", this.furAngle);
  2642. this._activeEffect.setColor4("furColor", this.furColor, 1.0);
  2643. if (this.highLevelFur) {
  2644. this._activeEffect.setVector3("furGravity", this.furGravity);
  2645. this._activeEffect.setFloat("furOffset", this.furOffset);
  2646. this._activeEffect.setFloat("furSpacing", this.furSpacing);
  2647. this._activeEffect.setFloat("furDensity", this.furDensity);
  2648. this._activeEffect.setFloat("furOcclusion", this.furOcclusion);
  2649. this._furTime += this.getScene().getEngine().getDeltaTime() / this.furSpeed;
  2650. this._activeEffect.setFloat("furTime", this._furTime);
  2651. this._activeEffect.setTexture("furTexture", this.furTexture);
  2652. }
  2653. this._afterBind(mesh, this._activeEffect);
  2654. };
  2655. FurMaterial.prototype.getAnimatables = function () {
  2656. var results = [];
  2657. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  2658. results.push(this.diffuseTexture);
  2659. }
  2660. if (this.heightTexture && this.heightTexture.animations && this.heightTexture.animations.length > 0) {
  2661. results.push(this.heightTexture);
  2662. }
  2663. return results;
  2664. };
  2665. FurMaterial.prototype.getActiveTextures = function () {
  2666. var activeTextures = _super.prototype.getActiveTextures.call(this);
  2667. if (this._diffuseTexture) {
  2668. activeTextures.push(this._diffuseTexture);
  2669. }
  2670. if (this._heightTexture) {
  2671. activeTextures.push(this._heightTexture);
  2672. }
  2673. return activeTextures;
  2674. };
  2675. FurMaterial.prototype.hasTexture = function (texture) {
  2676. if (_super.prototype.hasTexture.call(this, texture)) {
  2677. return true;
  2678. }
  2679. if (this.diffuseTexture === texture) {
  2680. return true;
  2681. }
  2682. if (this._heightTexture === texture) {
  2683. return true;
  2684. }
  2685. return false;
  2686. };
  2687. FurMaterial.prototype.dispose = function (forceDisposeEffect) {
  2688. if (this.diffuseTexture) {
  2689. this.diffuseTexture.dispose();
  2690. }
  2691. if (this._meshes) {
  2692. for (var i = 1; i < this._meshes.length; i++) {
  2693. var mat = this._meshes[i].material;
  2694. if (mat) {
  2695. mat.dispose(forceDisposeEffect);
  2696. }
  2697. this._meshes[i].dispose();
  2698. }
  2699. }
  2700. _super.prototype.dispose.call(this, forceDisposeEffect);
  2701. };
  2702. FurMaterial.prototype.clone = function (name) {
  2703. var _this = this;
  2704. return BABYLON.SerializationHelper.Clone(function () { return new FurMaterial(name, _this.getScene()); }, this);
  2705. };
  2706. FurMaterial.prototype.serialize = function () {
  2707. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  2708. serializationObject.customType = "BABYLON.FurMaterial";
  2709. if (this._meshes) {
  2710. serializationObject.sourceMeshName = this._meshes[0].name;
  2711. serializationObject.quality = this._meshes.length;
  2712. }
  2713. return serializationObject;
  2714. };
  2715. FurMaterial.prototype.getClassName = function () {
  2716. return "FurMaterial";
  2717. };
  2718. // Statics
  2719. FurMaterial.Parse = function (source, scene, rootUrl) {
  2720. var material = BABYLON.SerializationHelper.Parse(function () { return new FurMaterial(source.name, scene); }, source, scene, rootUrl);
  2721. if (source.sourceMeshName && material.highLevelFur) {
  2722. scene.executeWhenReady(function () {
  2723. var sourceMesh = scene.getMeshByName(source.sourceMeshName);
  2724. if (sourceMesh) {
  2725. var furTexture = FurMaterial.GenerateTexture("Fur Texture", scene);
  2726. material.furTexture = furTexture;
  2727. FurMaterial.FurifyMesh(sourceMesh, source.quality);
  2728. }
  2729. });
  2730. }
  2731. return material;
  2732. };
  2733. FurMaterial.GenerateTexture = function (name, scene) {
  2734. // Generate fur textures
  2735. var texture = new BABYLON.DynamicTexture("FurTexture " + name, 256, scene, true);
  2736. var context = texture.getContext();
  2737. for (var i = 0; i < 20000; ++i) {
  2738. context.fillStyle = "rgba(255, " + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", 1)";
  2739. context.fillRect((Math.random() * texture.getSize().width), (Math.random() * texture.getSize().height), 2, 2);
  2740. }
  2741. texture.update(false);
  2742. texture.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
  2743. texture.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
  2744. return texture;
  2745. };
  2746. // Creates and returns an array of meshes used as shells for the Fur Material
  2747. // that can be disposed later in your code
  2748. // The quality is in interval [0, 100]
  2749. FurMaterial.FurifyMesh = function (sourceMesh, quality) {
  2750. var meshes = [sourceMesh];
  2751. var mat = sourceMesh.material;
  2752. var i;
  2753. if (!(mat instanceof FurMaterial)) {
  2754. throw "The material of the source mesh must be a Fur Material";
  2755. }
  2756. for (i = 1; i < quality; i++) {
  2757. var offsetFur = new BABYLON.FurMaterial(mat.name + i, sourceMesh.getScene());
  2758. sourceMesh.getScene().materials.pop();
  2759. BABYLON.Tags.EnableFor(offsetFur);
  2760. BABYLON.Tags.AddTagsTo(offsetFur, "furShellMaterial");
  2761. offsetFur.furLength = mat.furLength;
  2762. offsetFur.furAngle = mat.furAngle;
  2763. offsetFur.furGravity = mat.furGravity;
  2764. offsetFur.furSpacing = mat.furSpacing;
  2765. offsetFur.furSpeed = mat.furSpeed;
  2766. offsetFur.furColor = mat.furColor;
  2767. offsetFur.diffuseTexture = mat.diffuseTexture;
  2768. offsetFur.furOffset = i / quality;
  2769. offsetFur.furTexture = mat.furTexture;
  2770. offsetFur.highLevelFur = mat.highLevelFur;
  2771. offsetFur.furTime = mat.furTime;
  2772. offsetFur.furDensity = mat.furDensity;
  2773. var offsetMesh = sourceMesh.clone(sourceMesh.name + i);
  2774. offsetMesh.material = offsetFur;
  2775. offsetMesh.skeleton = sourceMesh.skeleton;
  2776. offsetMesh.position = BABYLON.Vector3.Zero();
  2777. meshes.push(offsetMesh);
  2778. }
  2779. for (i = 1; i < meshes.length; i++) {
  2780. meshes[i].parent = sourceMesh;
  2781. }
  2782. sourceMesh.material._meshes = meshes;
  2783. return meshes;
  2784. };
  2785. __decorate([
  2786. BABYLON.serializeAsTexture("diffuseTexture")
  2787. ], FurMaterial.prototype, "_diffuseTexture", void 0);
  2788. __decorate([
  2789. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2790. ], FurMaterial.prototype, "diffuseTexture", void 0);
  2791. __decorate([
  2792. BABYLON.serializeAsTexture("heightTexture")
  2793. ], FurMaterial.prototype, "_heightTexture", void 0);
  2794. __decorate([
  2795. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2796. ], FurMaterial.prototype, "heightTexture", void 0);
  2797. __decorate([
  2798. BABYLON.serializeAsColor3()
  2799. ], FurMaterial.prototype, "diffuseColor", void 0);
  2800. __decorate([
  2801. BABYLON.serialize()
  2802. ], FurMaterial.prototype, "furLength", void 0);
  2803. __decorate([
  2804. BABYLON.serialize()
  2805. ], FurMaterial.prototype, "furAngle", void 0);
  2806. __decorate([
  2807. BABYLON.serializeAsColor3()
  2808. ], FurMaterial.prototype, "furColor", void 0);
  2809. __decorate([
  2810. BABYLON.serialize()
  2811. ], FurMaterial.prototype, "furOffset", void 0);
  2812. __decorate([
  2813. BABYLON.serialize()
  2814. ], FurMaterial.prototype, "furSpacing", void 0);
  2815. __decorate([
  2816. BABYLON.serializeAsVector3()
  2817. ], FurMaterial.prototype, "furGravity", void 0);
  2818. __decorate([
  2819. BABYLON.serialize()
  2820. ], FurMaterial.prototype, "furSpeed", void 0);
  2821. __decorate([
  2822. BABYLON.serialize()
  2823. ], FurMaterial.prototype, "furDensity", void 0);
  2824. __decorate([
  2825. BABYLON.serialize()
  2826. ], FurMaterial.prototype, "furOcclusion", void 0);
  2827. __decorate([
  2828. BABYLON.serialize("disableLighting")
  2829. ], FurMaterial.prototype, "_disableLighting", void 0);
  2830. __decorate([
  2831. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  2832. ], FurMaterial.prototype, "disableLighting", void 0);
  2833. __decorate([
  2834. BABYLON.serialize("maxSimultaneousLights")
  2835. ], FurMaterial.prototype, "_maxSimultaneousLights", void 0);
  2836. __decorate([
  2837. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  2838. ], FurMaterial.prototype, "maxSimultaneousLights", void 0);
  2839. __decorate([
  2840. BABYLON.serialize()
  2841. ], FurMaterial.prototype, "highLevelFur", void 0);
  2842. __decorate([
  2843. BABYLON.serialize()
  2844. ], FurMaterial.prototype, "furTime", null);
  2845. return FurMaterial;
  2846. }(BABYLON.PushMaterial));
  2847. BABYLON.FurMaterial = FurMaterial;
  2848. })(BABYLON || (BABYLON = {}));
  2849. //# sourceMappingURL=babylon.furMaterial.js.map
  2850. BABYLON.Effect.ShadersStore['furVertexShader'] = "precision highp float;\n\nattribute vec3 position;\nattribute vec3 normal;\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<bonesDeclaration>\n\nuniform float furLength;\nuniform float furAngle;\n#ifdef HIGHLEVEL\nuniform float furOffset;\nuniform vec3 furGravity;\nuniform float furTime;\nuniform float furSpacing;\nuniform float furDensity;\n#endif\n#ifdef HEIGHTMAP\nuniform sampler2D heightTexture;\n#endif\n#ifdef HIGHLEVEL\nvarying vec2 vFurUV;\n#endif\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\nvarying float vfur_length;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nfloat Rand(vec3 rv) {\nfloat x=dot(rv,vec3(12.9898,78.233,24.65487));\nreturn fract(sin(x)*43758.5453);\n}\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\n\nfloat r=Rand(position);\n#ifdef HEIGHTMAP\n#if __VERSION__>100\nvfur_length=furLength*texture(heightTexture,uv).x;\n#else\nvfur_length=furLength*texture2D(heightTexture,uv).r;\n#endif\n#else \nvfur_length=(furLength*r);\n#endif\nvec3 tangent1=vec3(normal.y,-normal.x,0);\nvec3 tangent2=vec3(-normal.z,0,normal.x);\nr=Rand(tangent1*r);\nfloat J=(2.0+4.0*r);\nr=Rand(tangent2*r);\nfloat K=(2.0+2.0*r);\ntangent1=tangent1*J+tangent2*K;\ntangent1=normalize(tangent1);\nvec3 newPosition=position+normal*vfur_length*cos(furAngle)+tangent1*vfur_length*sin(furAngle);\n#ifdef HIGHLEVEL\n\nvec3 forceDirection=vec3(0.0,0.0,0.0);\nforceDirection.x=sin(furTime+position.x*0.05)*0.2;\nforceDirection.y=cos(furTime*0.7+position.y*0.04)*0.2;\nforceDirection.z=sin(furTime*0.7+position.z*0.04)*0.2;\nvec3 displacement=vec3(0.0,0.0,0.0);\ndisplacement=furGravity+forceDirection;\nfloat displacementFactor=pow(furOffset,3.0);\nvec3 aNormal=normal;\naNormal.xyz+=displacement*displacementFactor;\nnewPosition=vec3(newPosition.x,newPosition.y,newPosition.z)+(normalize(aNormal)*furOffset*furSpacing);\n#endif\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\ngl_Position=viewProjection*finalWorld*vec4(newPosition,1.0);\nvec4 worldPos=finalWorld*vec4(newPosition,1.0);\nvPositionW=vec3(worldPos);\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\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#ifdef HIGHLEVEL\nvFurUV=vDiffuseUV*furDensity;\n#endif\n#else\n#ifdef HIGHLEVEL\nvFurUV=uv*furDensity;\n#endif\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  2851. BABYLON.Effect.ShadersStore['furPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nuniform vec4 furColor;\nuniform float furLength;\nvarying vec3 vPositionW;\nvarying float vfur_length;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n\n#ifdef HIGHLEVEL\nuniform float furOffset;\nuniform float furOcclusion;\nuniform sampler2D furTexture;\nvarying vec2 vFurUV;\n#endif\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<fogFragmentDeclaration>\n#include<clipPlaneFragmentDeclaration>\nfloat Rand(vec3 rv) {\nfloat x=dot(rv,vec3(12.9898,78.233,24.65487));\nreturn fract(sin(x)*43758.5453);\n}\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=furColor;\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\nbaseColor*=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n#ifdef HIGHLEVEL\n\nvec4 furTextureColor=texture2D(furTexture,vec2(vFurUV.x,vFurUV.y));\nif (furTextureColor.a<=0.0 || furTextureColor.g<furOffset) {\ndiscard;\n}\nfloat occlusion=mix(0.0,furTextureColor.b*1.2,furOffset);\nbaseColor=vec4(baseColor.xyz*max(occlusion,furOcclusion),1.1-furOffset);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase.rgb*baseColor.rgb,0.0,1.0);\n\n#ifdef HIGHLEVEL\nvec4 color=vec4(finalDiffuse,alpha);\n#else\nfloat r=vfur_length/furLength*0.5;\nvec4 color=vec4(finalDiffuse*(0.5+r),alpha);\n#endif\n#include<fogFragment>\ngl_FragColor=color;\n}";
  2852. var BABYLON;
  2853. (function (BABYLON) {
  2854. var TerrainMaterialDefines = /** @class */ (function (_super) {
  2855. __extends(TerrainMaterialDefines, _super);
  2856. function TerrainMaterialDefines() {
  2857. var _this = _super.call(this) || this;
  2858. _this.DIFFUSE = false;
  2859. _this.BUMP = false;
  2860. _this.CLIPPLANE = false;
  2861. _this.CLIPPLANE2 = false;
  2862. _this.CLIPPLANE3 = false;
  2863. _this.CLIPPLANE4 = false;
  2864. _this.ALPHATEST = false;
  2865. _this.DEPTHPREPASS = false;
  2866. _this.POINTSIZE = false;
  2867. _this.FOG = false;
  2868. _this.SPECULARTERM = false;
  2869. _this.NORMAL = false;
  2870. _this.UV1 = false;
  2871. _this.UV2 = false;
  2872. _this.VERTEXCOLOR = false;
  2873. _this.VERTEXALPHA = false;
  2874. _this.NUM_BONE_INFLUENCERS = 0;
  2875. _this.BonesPerMesh = 0;
  2876. _this.INSTANCES = false;
  2877. _this.rebuild();
  2878. return _this;
  2879. }
  2880. return TerrainMaterialDefines;
  2881. }(BABYLON.MaterialDefines));
  2882. var TerrainMaterial = /** @class */ (function (_super) {
  2883. __extends(TerrainMaterial, _super);
  2884. function TerrainMaterial(name, scene) {
  2885. var _this = _super.call(this, name, scene) || this;
  2886. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  2887. _this.specularColor = new BABYLON.Color3(0, 0, 0);
  2888. _this.specularPower = 64;
  2889. _this._disableLighting = false;
  2890. _this._maxSimultaneousLights = 4;
  2891. return _this;
  2892. }
  2893. TerrainMaterial.prototype.needAlphaBlending = function () {
  2894. return (this.alpha < 1.0);
  2895. };
  2896. TerrainMaterial.prototype.needAlphaTesting = function () {
  2897. return false;
  2898. };
  2899. TerrainMaterial.prototype.getAlphaTestTexture = function () {
  2900. return null;
  2901. };
  2902. // Methods
  2903. TerrainMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  2904. if (this.isFrozen) {
  2905. if (this._wasPreviouslyReady && subMesh.effect) {
  2906. return true;
  2907. }
  2908. }
  2909. if (!subMesh._materialDefines) {
  2910. subMesh._materialDefines = new TerrainMaterialDefines();
  2911. }
  2912. var defines = subMesh._materialDefines;
  2913. var scene = this.getScene();
  2914. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  2915. if (this._renderId === scene.getRenderId()) {
  2916. return true;
  2917. }
  2918. }
  2919. var engine = scene.getEngine();
  2920. // Textures
  2921. if (scene.texturesEnabled) {
  2922. if (this.mixTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2923. if (!this.mixTexture.isReady()) {
  2924. return false;
  2925. }
  2926. else {
  2927. defines._needUVs = true;
  2928. defines.DIFFUSE = true;
  2929. }
  2930. }
  2931. if ((this.bumpTexture1 || this.bumpTexture2 || this.bumpTexture3) && BABYLON.StandardMaterial.BumpTextureEnabled) {
  2932. defines._needUVs = true;
  2933. defines._needNormals = true;
  2934. defines.BUMP = true;
  2935. }
  2936. }
  2937. // Misc.
  2938. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  2939. // Lights
  2940. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  2941. // Values that need to be evaluated on every frame
  2942. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  2943. // Attribs
  2944. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  2945. // Get correct effect
  2946. if (defines.isDirty) {
  2947. defines.markAsProcessed();
  2948. scene.resetCachedMaterial();
  2949. // Fallbacks
  2950. var fallbacks = new BABYLON.EffectFallbacks();
  2951. if (defines.FOG) {
  2952. fallbacks.addFallback(1, "FOG");
  2953. }
  2954. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  2955. if (defines.NUM_BONE_INFLUENCERS > 0) {
  2956. fallbacks.addCPUSkinningFallback(0, mesh);
  2957. }
  2958. //Attributes
  2959. var attribs = [BABYLON.VertexBuffer.PositionKind];
  2960. if (defines.NORMAL) {
  2961. attribs.push(BABYLON.VertexBuffer.NormalKind);
  2962. }
  2963. if (defines.UV1) {
  2964. attribs.push(BABYLON.VertexBuffer.UVKind);
  2965. }
  2966. if (defines.UV2) {
  2967. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  2968. }
  2969. if (defines.VERTEXCOLOR) {
  2970. attribs.push(BABYLON.VertexBuffer.ColorKind);
  2971. }
  2972. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  2973. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  2974. // Legacy browser patch
  2975. var shaderName = "terrain";
  2976. var join = defines.toString();
  2977. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  2978. "vFogInfos", "vFogColor", "pointSize",
  2979. "vTextureInfos",
  2980. "mBones",
  2981. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "textureMatrix",
  2982. "diffuse1Infos", "diffuse2Infos", "diffuse3Infos"
  2983. ];
  2984. var samplers = ["textureSampler", "diffuse1Sampler", "diffuse2Sampler", "diffuse3Sampler",
  2985. "bump1Sampler", "bump2Sampler", "bump3Sampler"
  2986. ];
  2987. var uniformBuffers = new Array();
  2988. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  2989. uniformsNames: uniforms,
  2990. uniformBuffersNames: uniformBuffers,
  2991. samplers: samplers,
  2992. defines: defines,
  2993. maxSimultaneousLights: this.maxSimultaneousLights
  2994. });
  2995. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  2996. attributes: attribs,
  2997. uniformsNames: uniforms,
  2998. uniformBuffersNames: uniformBuffers,
  2999. samplers: samplers,
  3000. defines: join,
  3001. fallbacks: fallbacks,
  3002. onCompiled: this.onCompiled,
  3003. onError: this.onError,
  3004. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  3005. }, engine), defines);
  3006. }
  3007. if (!subMesh.effect || !subMesh.effect.isReady()) {
  3008. return false;
  3009. }
  3010. this._renderId = scene.getRenderId();
  3011. this._wasPreviouslyReady = true;
  3012. return true;
  3013. };
  3014. TerrainMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  3015. var scene = this.getScene();
  3016. var defines = subMesh._materialDefines;
  3017. if (!defines) {
  3018. return;
  3019. }
  3020. var effect = subMesh.effect;
  3021. if (!effect) {
  3022. return;
  3023. }
  3024. this._activeEffect = effect;
  3025. // Matrices
  3026. this.bindOnlyWorldMatrix(world);
  3027. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  3028. // Bones
  3029. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  3030. if (this._mustRebind(scene, effect)) {
  3031. // Textures
  3032. if (this.mixTexture) {
  3033. this._activeEffect.setTexture("textureSampler", this._mixTexture);
  3034. this._activeEffect.setFloat2("vTextureInfos", this._mixTexture.coordinatesIndex, this._mixTexture.level);
  3035. this._activeEffect.setMatrix("textureMatrix", this._mixTexture.getTextureMatrix());
  3036. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  3037. if (this._diffuseTexture1) {
  3038. this._activeEffect.setTexture("diffuse1Sampler", this._diffuseTexture1);
  3039. this._activeEffect.setFloat2("diffuse1Infos", this._diffuseTexture1.uScale, this._diffuseTexture1.vScale);
  3040. }
  3041. if (this._diffuseTexture2) {
  3042. this._activeEffect.setTexture("diffuse2Sampler", this._diffuseTexture2);
  3043. this._activeEffect.setFloat2("diffuse2Infos", this._diffuseTexture2.uScale, this._diffuseTexture2.vScale);
  3044. }
  3045. if (this._diffuseTexture3) {
  3046. this._activeEffect.setTexture("diffuse3Sampler", this._diffuseTexture3);
  3047. this._activeEffect.setFloat2("diffuse3Infos", this._diffuseTexture3.uScale, this._diffuseTexture3.vScale);
  3048. }
  3049. }
  3050. if (BABYLON.StandardMaterial.BumpTextureEnabled && scene.getEngine().getCaps().standardDerivatives) {
  3051. if (this._bumpTexture1) {
  3052. this._activeEffect.setTexture("bump1Sampler", this._bumpTexture1);
  3053. }
  3054. if (this._bumpTexture2) {
  3055. this._activeEffect.setTexture("bump2Sampler", this._bumpTexture2);
  3056. }
  3057. if (this._bumpTexture3) {
  3058. this._activeEffect.setTexture("bump3Sampler", this._bumpTexture3);
  3059. }
  3060. }
  3061. }
  3062. // Clip plane
  3063. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  3064. // Point size
  3065. if (this.pointsCloud) {
  3066. this._activeEffect.setFloat("pointSize", this.pointSize);
  3067. }
  3068. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  3069. }
  3070. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  3071. if (defines.SPECULARTERM) {
  3072. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  3073. }
  3074. if (scene.lightsEnabled && !this.disableLighting) {
  3075. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  3076. }
  3077. // View
  3078. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  3079. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  3080. }
  3081. // Fog
  3082. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  3083. this._afterBind(mesh, this._activeEffect);
  3084. };
  3085. TerrainMaterial.prototype.getAnimatables = function () {
  3086. var results = [];
  3087. if (this.mixTexture && this.mixTexture.animations && this.mixTexture.animations.length > 0) {
  3088. results.push(this.mixTexture);
  3089. }
  3090. return results;
  3091. };
  3092. TerrainMaterial.prototype.getActiveTextures = function () {
  3093. var activeTextures = _super.prototype.getActiveTextures.call(this);
  3094. if (this._mixTexture) {
  3095. activeTextures.push(this._mixTexture);
  3096. }
  3097. if (this._diffuseTexture1) {
  3098. activeTextures.push(this._diffuseTexture1);
  3099. }
  3100. if (this._diffuseTexture2) {
  3101. activeTextures.push(this._diffuseTexture2);
  3102. }
  3103. if (this._diffuseTexture3) {
  3104. activeTextures.push(this._diffuseTexture3);
  3105. }
  3106. if (this._bumpTexture1) {
  3107. activeTextures.push(this._bumpTexture1);
  3108. }
  3109. if (this._bumpTexture2) {
  3110. activeTextures.push(this._bumpTexture2);
  3111. }
  3112. if (this._bumpTexture3) {
  3113. activeTextures.push(this._bumpTexture3);
  3114. }
  3115. return activeTextures;
  3116. };
  3117. TerrainMaterial.prototype.hasTexture = function (texture) {
  3118. if (_super.prototype.hasTexture.call(this, texture)) {
  3119. return true;
  3120. }
  3121. if (this._mixTexture === texture) {
  3122. return true;
  3123. }
  3124. if (this._diffuseTexture1 === texture) {
  3125. return true;
  3126. }
  3127. if (this._diffuseTexture2 === texture) {
  3128. return true;
  3129. }
  3130. if (this._diffuseTexture3 === texture) {
  3131. return true;
  3132. }
  3133. if (this._bumpTexture1 === texture) {
  3134. return true;
  3135. }
  3136. if (this._bumpTexture2 === texture) {
  3137. return true;
  3138. }
  3139. if (this._bumpTexture3 === texture) {
  3140. return true;
  3141. }
  3142. return false;
  3143. };
  3144. TerrainMaterial.prototype.dispose = function (forceDisposeEffect) {
  3145. if (this.mixTexture) {
  3146. this.mixTexture.dispose();
  3147. }
  3148. _super.prototype.dispose.call(this, forceDisposeEffect);
  3149. };
  3150. TerrainMaterial.prototype.clone = function (name) {
  3151. var _this = this;
  3152. return BABYLON.SerializationHelper.Clone(function () { return new TerrainMaterial(name, _this.getScene()); }, this);
  3153. };
  3154. TerrainMaterial.prototype.serialize = function () {
  3155. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  3156. serializationObject.customType = "BABYLON.TerrainMaterial";
  3157. return serializationObject;
  3158. };
  3159. TerrainMaterial.prototype.getClassName = function () {
  3160. return "TerrainMaterial";
  3161. };
  3162. // Statics
  3163. TerrainMaterial.Parse = function (source, scene, rootUrl) {
  3164. return BABYLON.SerializationHelper.Parse(function () { return new TerrainMaterial(source.name, scene); }, source, scene, rootUrl);
  3165. };
  3166. __decorate([
  3167. BABYLON.serializeAsTexture("mixTexture")
  3168. ], TerrainMaterial.prototype, "_mixTexture", void 0);
  3169. __decorate([
  3170. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3171. ], TerrainMaterial.prototype, "mixTexture", void 0);
  3172. __decorate([
  3173. BABYLON.serializeAsTexture("diffuseTexture1")
  3174. ], TerrainMaterial.prototype, "_diffuseTexture1", void 0);
  3175. __decorate([
  3176. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3177. ], TerrainMaterial.prototype, "diffuseTexture1", void 0);
  3178. __decorate([
  3179. BABYLON.serializeAsTexture("diffuseTexture2")
  3180. ], TerrainMaterial.prototype, "_diffuseTexture2", void 0);
  3181. __decorate([
  3182. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3183. ], TerrainMaterial.prototype, "diffuseTexture2", void 0);
  3184. __decorate([
  3185. BABYLON.serializeAsTexture("diffuseTexture3")
  3186. ], TerrainMaterial.prototype, "_diffuseTexture3", void 0);
  3187. __decorate([
  3188. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3189. ], TerrainMaterial.prototype, "diffuseTexture3", void 0);
  3190. __decorate([
  3191. BABYLON.serializeAsTexture("bumpTexture1")
  3192. ], TerrainMaterial.prototype, "_bumpTexture1", void 0);
  3193. __decorate([
  3194. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3195. ], TerrainMaterial.prototype, "bumpTexture1", void 0);
  3196. __decorate([
  3197. BABYLON.serializeAsTexture("bumpTexture2")
  3198. ], TerrainMaterial.prototype, "_bumpTexture2", void 0);
  3199. __decorate([
  3200. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3201. ], TerrainMaterial.prototype, "bumpTexture2", void 0);
  3202. __decorate([
  3203. BABYLON.serializeAsTexture("bumpTexture3")
  3204. ], TerrainMaterial.prototype, "_bumpTexture3", void 0);
  3205. __decorate([
  3206. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3207. ], TerrainMaterial.prototype, "bumpTexture3", void 0);
  3208. __decorate([
  3209. BABYLON.serializeAsColor3()
  3210. ], TerrainMaterial.prototype, "diffuseColor", void 0);
  3211. __decorate([
  3212. BABYLON.serializeAsColor3()
  3213. ], TerrainMaterial.prototype, "specularColor", void 0);
  3214. __decorate([
  3215. BABYLON.serialize()
  3216. ], TerrainMaterial.prototype, "specularPower", void 0);
  3217. __decorate([
  3218. BABYLON.serialize("disableLighting")
  3219. ], TerrainMaterial.prototype, "_disableLighting", void 0);
  3220. __decorate([
  3221. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3222. ], TerrainMaterial.prototype, "disableLighting", void 0);
  3223. __decorate([
  3224. BABYLON.serialize("maxSimultaneousLights")
  3225. ], TerrainMaterial.prototype, "_maxSimultaneousLights", void 0);
  3226. __decorate([
  3227. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3228. ], TerrainMaterial.prototype, "maxSimultaneousLights", void 0);
  3229. return TerrainMaterial;
  3230. }(BABYLON.PushMaterial));
  3231. BABYLON.TerrainMaterial = TerrainMaterial;
  3232. })(BABYLON || (BABYLON = {}));
  3233. //# sourceMappingURL=babylon.terrainMaterial.js.map
  3234. BABYLON.Effect.ShadersStore['terrainVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\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<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vTextureUV;\nuniform mat4 textureMatrix;\nuniform vec2 vTextureInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,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 DIFFUSE\nif (vTextureInfos.x == 0.)\n{\nvTextureUV=vec2(textureMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvTextureUV=vec2(textureMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  3235. BABYLON.Effect.ShadersStore['terrainPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef DIFFUSE\nvarying vec2 vTextureUV;\nuniform sampler2D textureSampler;\nuniform vec2 vTextureInfos;\nuniform sampler2D diffuse1Sampler;\nuniform sampler2D diffuse2Sampler;\nuniform sampler2D diffuse3Sampler;\nuniform vec2 diffuse1Infos;\nuniform vec2 diffuse2Infos;\nuniform vec2 diffuse3Infos;\n#endif\n#ifdef BUMP\nuniform sampler2D bump1Sampler;\nuniform sampler2D bump2Sampler;\nuniform sampler2D bump3Sampler;\n#endif\n\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\n\n#ifdef BUMP\n#extension GL_OES_standard_derivatives : enable\n\nmat3 cotangent_frame(vec3 normal,vec3 p,vec2 uv)\n{\n\nvec3 dp1=dFdx(p);\nvec3 dp2=dFdy(p);\nvec2 duv1=dFdx(uv);\nvec2 duv2=dFdy(uv);\n\nvec3 dp2perp=cross(dp2,normal);\nvec3 dp1perp=cross(normal,dp1);\nvec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;\nvec3 binormal=dp2perp*duv1.y+dp1perp*duv2.y;\n\nfloat invmax=inversesqrt(max(dot(tangent,tangent),dot(binormal,binormal)));\nreturn mat3(tangent*invmax,binormal*invmax,normal);\n}\nvec3 perturbNormal(vec3 viewDir,vec3 mixColor)\n{ \nvec3 bump1Color=texture2D(bump1Sampler,vTextureUV*diffuse1Infos).xyz;\nvec3 bump2Color=texture2D(bump2Sampler,vTextureUV*diffuse2Infos).xyz;\nvec3 bump3Color=texture2D(bump3Sampler,vTextureUV*diffuse3Infos).xyz;\nbump1Color.rgb*=mixColor.r;\nbump2Color.rgb=mix(bump1Color.rgb,bump2Color.rgb,mixColor.g);\nvec3 map=mix(bump2Color.rgb,bump3Color.rgb,mixColor.b);\nmap=map*255./127.-128./127.;\nmat3 TBN=cotangent_frame(vNormalW*vTextureInfos.y,-viewDir,vTextureUV);\nreturn normalize(TBN*map);\n}\n#endif\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n\nfloat alpha=vDiffuseColor.a;\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n#ifdef DIFFUSE\nbaseColor=texture2D(textureSampler,vTextureUV);\n#if defined(BUMP) && defined(DIFFUSE)\nnormalW=perturbNormal(viewDirectionW,baseColor.rgb);\n#endif\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vTextureInfos.y;\nvec4 diffuse1Color=texture2D(diffuse1Sampler,vTextureUV*diffuse1Infos);\nvec4 diffuse2Color=texture2D(diffuse2Sampler,vTextureUV*diffuse2Infos);\nvec4 diffuse3Color=texture2D(diffuse3Sampler,vTextureUV*diffuse3Infos);\ndiffuse1Color.rgb*=baseColor.r;\ndiffuse2Color.rgb=mix(diffuse1Color.rgb,diffuse2Color.rgb,baseColor.g);\nbaseColor.rgb=mix(diffuse2Color.rgb,diffuse3Color.rgb,baseColor.b);\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor*baseColor.rgb,0.0,1.0);\n\nvec4 color=vec4(finalDiffuse+finalSpecular,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}\n";
  3236. var BABYLON;
  3237. (function (BABYLON) {
  3238. var MixMaterialDefines = /** @class */ (function (_super) {
  3239. __extends(MixMaterialDefines, _super);
  3240. function MixMaterialDefines() {
  3241. var _this = _super.call(this) || this;
  3242. _this.DIFFUSE = false;
  3243. _this.CLIPPLANE = false;
  3244. _this.CLIPPLANE2 = false;
  3245. _this.CLIPPLANE3 = false;
  3246. _this.CLIPPLANE4 = false;
  3247. _this.ALPHATEST = false;
  3248. _this.DEPTHPREPASS = false;
  3249. _this.POINTSIZE = false;
  3250. _this.FOG = false;
  3251. _this.SPECULARTERM = false;
  3252. _this.NORMAL = false;
  3253. _this.UV1 = false;
  3254. _this.UV2 = false;
  3255. _this.VERTEXCOLOR = false;
  3256. _this.VERTEXALPHA = false;
  3257. _this.NUM_BONE_INFLUENCERS = 0;
  3258. _this.BonesPerMesh = 0;
  3259. _this.INSTANCES = false;
  3260. _this.MIXMAP2 = false;
  3261. _this.rebuild();
  3262. return _this;
  3263. }
  3264. return MixMaterialDefines;
  3265. }(BABYLON.MaterialDefines));
  3266. var MixMaterial = /** @class */ (function (_super) {
  3267. __extends(MixMaterial, _super);
  3268. function MixMaterial(name, scene) {
  3269. var _this = _super.call(this, name, scene) || this;
  3270. /**
  3271. * Uniforms
  3272. */
  3273. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  3274. _this.specularColor = new BABYLON.Color3(0, 0, 0);
  3275. _this.specularPower = 64;
  3276. _this._disableLighting = false;
  3277. _this._maxSimultaneousLights = 4;
  3278. return _this;
  3279. }
  3280. MixMaterial.prototype.needAlphaBlending = function () {
  3281. return (this.alpha < 1.0);
  3282. };
  3283. MixMaterial.prototype.needAlphaTesting = function () {
  3284. return false;
  3285. };
  3286. MixMaterial.prototype.getAlphaTestTexture = function () {
  3287. return null;
  3288. };
  3289. // Methods
  3290. MixMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  3291. if (this.isFrozen) {
  3292. if (this._wasPreviouslyReady && subMesh.effect) {
  3293. return true;
  3294. }
  3295. }
  3296. if (!subMesh._materialDefines) {
  3297. subMesh._materialDefines = new MixMaterialDefines();
  3298. }
  3299. var defines = subMesh._materialDefines;
  3300. var scene = this.getScene();
  3301. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  3302. if (this._renderId === scene.getRenderId()) {
  3303. return true;
  3304. }
  3305. }
  3306. var engine = scene.getEngine();
  3307. // Textures
  3308. if (scene.texturesEnabled) {
  3309. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  3310. if (this._mixTexture1) {
  3311. if (!this._mixTexture1.isReady()) {
  3312. return false;
  3313. }
  3314. else {
  3315. defines._needUVs = true;
  3316. defines.DIFFUSE = true;
  3317. }
  3318. }
  3319. if (this._mixTexture2) {
  3320. if (!this._mixTexture2.isReady()) {
  3321. return false;
  3322. }
  3323. else {
  3324. defines.MIXMAP2 = true;
  3325. }
  3326. }
  3327. }
  3328. }
  3329. // Misc.
  3330. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  3331. // Lights
  3332. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  3333. // Values that need to be evaluated on every frame
  3334. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  3335. // Attribs
  3336. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  3337. // Get correct effect
  3338. if (defines.isDirty) {
  3339. defines.markAsProcessed();
  3340. scene.resetCachedMaterial();
  3341. // Fallbacks
  3342. var fallbacks = new BABYLON.EffectFallbacks();
  3343. if (defines.FOG) {
  3344. fallbacks.addFallback(1, "FOG");
  3345. }
  3346. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  3347. if (defines.NUM_BONE_INFLUENCERS > 0) {
  3348. fallbacks.addCPUSkinningFallback(0, mesh);
  3349. }
  3350. //Attributes
  3351. var attribs = [BABYLON.VertexBuffer.PositionKind];
  3352. if (defines.NORMAL) {
  3353. attribs.push(BABYLON.VertexBuffer.NormalKind);
  3354. }
  3355. if (defines.UV1) {
  3356. attribs.push(BABYLON.VertexBuffer.UVKind);
  3357. }
  3358. if (defines.UV2) {
  3359. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  3360. }
  3361. if (defines.VERTEXCOLOR) {
  3362. attribs.push(BABYLON.VertexBuffer.ColorKind);
  3363. }
  3364. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  3365. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  3366. // Legacy browser patch
  3367. var shaderName = "mix";
  3368. var join = defines.toString();
  3369. var uniforms = [
  3370. "world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  3371. "vFogInfos", "vFogColor", "pointSize",
  3372. "vTextureInfos",
  3373. "mBones",
  3374. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "textureMatrix",
  3375. "diffuse1Infos", "diffuse2Infos", "diffuse3Infos", "diffuse4Infos",
  3376. "diffuse5Infos", "diffuse6Infos", "diffuse7Infos", "diffuse8Infos"
  3377. ];
  3378. var samplers = [
  3379. "mixMap1Sampler", "mixMap2Sampler",
  3380. "diffuse1Sampler", "diffuse2Sampler", "diffuse3Sampler", "diffuse4Sampler",
  3381. "diffuse5Sampler", "diffuse6Sampler", "diffuse7Sampler", "diffuse8Sampler"
  3382. ];
  3383. var uniformBuffers = new Array();
  3384. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  3385. uniformsNames: uniforms,
  3386. uniformBuffersNames: uniformBuffers,
  3387. samplers: samplers,
  3388. defines: defines,
  3389. maxSimultaneousLights: this.maxSimultaneousLights
  3390. });
  3391. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  3392. attributes: attribs,
  3393. uniformsNames: uniforms,
  3394. uniformBuffersNames: uniformBuffers,
  3395. samplers: samplers,
  3396. defines: join,
  3397. fallbacks: fallbacks,
  3398. onCompiled: this.onCompiled,
  3399. onError: this.onError,
  3400. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  3401. }, engine), defines);
  3402. }
  3403. if (!subMesh.effect || !subMesh.effect.isReady()) {
  3404. return false;
  3405. }
  3406. this._renderId = scene.getRenderId();
  3407. this._wasPreviouslyReady = true;
  3408. return true;
  3409. };
  3410. MixMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  3411. var scene = this.getScene();
  3412. var defines = subMesh._materialDefines;
  3413. if (!defines) {
  3414. return;
  3415. }
  3416. var effect = subMesh.effect;
  3417. if (!effect) {
  3418. return;
  3419. }
  3420. this._activeEffect = effect;
  3421. // Matrices
  3422. this.bindOnlyWorldMatrix(world);
  3423. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  3424. // Bones
  3425. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  3426. if (this._mustRebind(scene, effect)) {
  3427. // Textures
  3428. if (this._mixTexture1) {
  3429. this._activeEffect.setTexture("mixMap1Sampler", this._mixTexture1);
  3430. this._activeEffect.setFloat2("vTextureInfos", this._mixTexture1.coordinatesIndex, this._mixTexture1.level);
  3431. this._activeEffect.setMatrix("textureMatrix", this._mixTexture1.getTextureMatrix());
  3432. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  3433. if (this._diffuseTexture1) {
  3434. this._activeEffect.setTexture("diffuse1Sampler", this._diffuseTexture1);
  3435. this._activeEffect.setFloat2("diffuse1Infos", this._diffuseTexture1.uScale, this._diffuseTexture1.vScale);
  3436. }
  3437. if (this._diffuseTexture2) {
  3438. this._activeEffect.setTexture("diffuse2Sampler", this._diffuseTexture2);
  3439. this._activeEffect.setFloat2("diffuse2Infos", this._diffuseTexture2.uScale, this._diffuseTexture2.vScale);
  3440. }
  3441. if (this._diffuseTexture3) {
  3442. this._activeEffect.setTexture("diffuse3Sampler", this._diffuseTexture3);
  3443. this._activeEffect.setFloat2("diffuse3Infos", this._diffuseTexture3.uScale, this._diffuseTexture3.vScale);
  3444. }
  3445. if (this._diffuseTexture4) {
  3446. this._activeEffect.setTexture("diffuse4Sampler", this._diffuseTexture4);
  3447. this._activeEffect.setFloat2("diffuse4Infos", this._diffuseTexture4.uScale, this._diffuseTexture4.vScale);
  3448. }
  3449. }
  3450. }
  3451. if (this._mixTexture2) {
  3452. this._activeEffect.setTexture("mixMap2Sampler", this._mixTexture2);
  3453. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  3454. if (this._diffuseTexture5) {
  3455. this._activeEffect.setTexture("diffuse5Sampler", this._diffuseTexture5);
  3456. this._activeEffect.setFloat2("diffuse5Infos", this._diffuseTexture5.uScale, this._diffuseTexture5.vScale);
  3457. }
  3458. if (this._diffuseTexture6) {
  3459. this._activeEffect.setTexture("diffuse6Sampler", this._diffuseTexture6);
  3460. this._activeEffect.setFloat2("diffuse6Infos", this._diffuseTexture6.uScale, this._diffuseTexture6.vScale);
  3461. }
  3462. if (this._diffuseTexture7) {
  3463. this._activeEffect.setTexture("diffuse7Sampler", this._diffuseTexture7);
  3464. this._activeEffect.setFloat2("diffuse7Infos", this._diffuseTexture7.uScale, this._diffuseTexture7.vScale);
  3465. }
  3466. if (this._diffuseTexture8) {
  3467. this._activeEffect.setTexture("diffuse8Sampler", this._diffuseTexture8);
  3468. this._activeEffect.setFloat2("diffuse8Infos", this._diffuseTexture8.uScale, this._diffuseTexture8.vScale);
  3469. }
  3470. }
  3471. }
  3472. // Clip plane
  3473. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  3474. // Point size
  3475. if (this.pointsCloud) {
  3476. this._activeEffect.setFloat("pointSize", this.pointSize);
  3477. }
  3478. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  3479. }
  3480. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  3481. if (defines.SPECULARTERM) {
  3482. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  3483. }
  3484. if (scene.lightsEnabled && !this.disableLighting) {
  3485. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  3486. }
  3487. // View
  3488. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  3489. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  3490. }
  3491. // Fog
  3492. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  3493. this._afterBind(mesh, this._activeEffect);
  3494. };
  3495. MixMaterial.prototype.getAnimatables = function () {
  3496. var results = [];
  3497. if (this._mixTexture1 && this._mixTexture1.animations && this._mixTexture1.animations.length > 0) {
  3498. results.push(this._mixTexture1);
  3499. }
  3500. if (this._mixTexture2 && this._mixTexture2.animations && this._mixTexture2.animations.length > 0) {
  3501. results.push(this._mixTexture2);
  3502. }
  3503. return results;
  3504. };
  3505. MixMaterial.prototype.getActiveTextures = function () {
  3506. var activeTextures = _super.prototype.getActiveTextures.call(this);
  3507. // Mix map 1
  3508. if (this._mixTexture1) {
  3509. activeTextures.push(this._mixTexture1);
  3510. }
  3511. if (this._diffuseTexture1) {
  3512. activeTextures.push(this._diffuseTexture1);
  3513. }
  3514. if (this._diffuseTexture2) {
  3515. activeTextures.push(this._diffuseTexture2);
  3516. }
  3517. if (this._diffuseTexture3) {
  3518. activeTextures.push(this._diffuseTexture3);
  3519. }
  3520. if (this._diffuseTexture4) {
  3521. activeTextures.push(this._diffuseTexture4);
  3522. }
  3523. // Mix map 2
  3524. if (this._mixTexture2) {
  3525. activeTextures.push(this._mixTexture2);
  3526. }
  3527. if (this._diffuseTexture5) {
  3528. activeTextures.push(this._diffuseTexture5);
  3529. }
  3530. if (this._diffuseTexture6) {
  3531. activeTextures.push(this._diffuseTexture6);
  3532. }
  3533. if (this._diffuseTexture7) {
  3534. activeTextures.push(this._diffuseTexture7);
  3535. }
  3536. if (this._diffuseTexture8) {
  3537. activeTextures.push(this._diffuseTexture8);
  3538. }
  3539. return activeTextures;
  3540. };
  3541. MixMaterial.prototype.hasTexture = function (texture) {
  3542. if (_super.prototype.hasTexture.call(this, texture)) {
  3543. return true;
  3544. }
  3545. // Mix map 1
  3546. if (this._mixTexture1 === texture) {
  3547. return true;
  3548. }
  3549. if (this._diffuseTexture1 === texture) {
  3550. return true;
  3551. }
  3552. if (this._diffuseTexture2 === texture) {
  3553. return true;
  3554. }
  3555. if (this._diffuseTexture3 === texture) {
  3556. return true;
  3557. }
  3558. if (this._diffuseTexture4 === texture) {
  3559. return true;
  3560. }
  3561. // Mix map 2
  3562. if (this._mixTexture2 === texture) {
  3563. return true;
  3564. }
  3565. if (this._diffuseTexture5 === texture) {
  3566. return true;
  3567. }
  3568. if (this._diffuseTexture6 === texture) {
  3569. return true;
  3570. }
  3571. if (this._diffuseTexture7 === texture) {
  3572. return true;
  3573. }
  3574. if (this._diffuseTexture8 === texture) {
  3575. return true;
  3576. }
  3577. return false;
  3578. };
  3579. MixMaterial.prototype.dispose = function (forceDisposeEffect) {
  3580. if (this._mixTexture1) {
  3581. this._mixTexture1.dispose();
  3582. }
  3583. _super.prototype.dispose.call(this, forceDisposeEffect);
  3584. };
  3585. MixMaterial.prototype.clone = function (name) {
  3586. var _this = this;
  3587. return BABYLON.SerializationHelper.Clone(function () { return new MixMaterial(name, _this.getScene()); }, this);
  3588. };
  3589. MixMaterial.prototype.serialize = function () {
  3590. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  3591. serializationObject.customType = "BABYLON.MixMaterial";
  3592. return serializationObject;
  3593. };
  3594. MixMaterial.prototype.getClassName = function () {
  3595. return "MixMaterial";
  3596. };
  3597. // Statics
  3598. MixMaterial.Parse = function (source, scene, rootUrl) {
  3599. return BABYLON.SerializationHelper.Parse(function () { return new MixMaterial(source.name, scene); }, source, scene, rootUrl);
  3600. };
  3601. __decorate([
  3602. BABYLON.serializeAsTexture("mixTexture1")
  3603. ], MixMaterial.prototype, "_mixTexture1", void 0);
  3604. __decorate([
  3605. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3606. ], MixMaterial.prototype, "mixTexture1", void 0);
  3607. __decorate([
  3608. BABYLON.serializeAsTexture("mixTexture2")
  3609. ], MixMaterial.prototype, "_mixTexture2", void 0);
  3610. __decorate([
  3611. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3612. ], MixMaterial.prototype, "mixTexture2", void 0);
  3613. __decorate([
  3614. BABYLON.serializeAsTexture("diffuseTexture1")
  3615. ], MixMaterial.prototype, "_diffuseTexture1", void 0);
  3616. __decorate([
  3617. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3618. ], MixMaterial.prototype, "diffuseTexture1", void 0);
  3619. __decorate([
  3620. BABYLON.serializeAsTexture("diffuseTexture2")
  3621. ], MixMaterial.prototype, "_diffuseTexture2", void 0);
  3622. __decorate([
  3623. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3624. ], MixMaterial.prototype, "diffuseTexture2", void 0);
  3625. __decorate([
  3626. BABYLON.serializeAsTexture("diffuseTexture3")
  3627. ], MixMaterial.prototype, "_diffuseTexture3", void 0);
  3628. __decorate([
  3629. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3630. ], MixMaterial.prototype, "diffuseTexture3", void 0);
  3631. __decorate([
  3632. BABYLON.serializeAsTexture("diffuseTexture4")
  3633. ], MixMaterial.prototype, "_diffuseTexture4", void 0);
  3634. __decorate([
  3635. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3636. ], MixMaterial.prototype, "diffuseTexture4", void 0);
  3637. __decorate([
  3638. BABYLON.serializeAsTexture("diffuseTexture1")
  3639. ], MixMaterial.prototype, "_diffuseTexture5", void 0);
  3640. __decorate([
  3641. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3642. ], MixMaterial.prototype, "diffuseTexture5", void 0);
  3643. __decorate([
  3644. BABYLON.serializeAsTexture("diffuseTexture2")
  3645. ], MixMaterial.prototype, "_diffuseTexture6", void 0);
  3646. __decorate([
  3647. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3648. ], MixMaterial.prototype, "diffuseTexture6", void 0);
  3649. __decorate([
  3650. BABYLON.serializeAsTexture("diffuseTexture3")
  3651. ], MixMaterial.prototype, "_diffuseTexture7", void 0);
  3652. __decorate([
  3653. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3654. ], MixMaterial.prototype, "diffuseTexture7", void 0);
  3655. __decorate([
  3656. BABYLON.serializeAsTexture("diffuseTexture4")
  3657. ], MixMaterial.prototype, "_diffuseTexture8", void 0);
  3658. __decorate([
  3659. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3660. ], MixMaterial.prototype, "diffuseTexture8", void 0);
  3661. __decorate([
  3662. BABYLON.serializeAsColor3()
  3663. ], MixMaterial.prototype, "diffuseColor", void 0);
  3664. __decorate([
  3665. BABYLON.serializeAsColor3()
  3666. ], MixMaterial.prototype, "specularColor", void 0);
  3667. __decorate([
  3668. BABYLON.serialize()
  3669. ], MixMaterial.prototype, "specularPower", void 0);
  3670. __decorate([
  3671. BABYLON.serialize("disableLighting")
  3672. ], MixMaterial.prototype, "_disableLighting", void 0);
  3673. __decorate([
  3674. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3675. ], MixMaterial.prototype, "disableLighting", void 0);
  3676. __decorate([
  3677. BABYLON.serialize("maxSimultaneousLights")
  3678. ], MixMaterial.prototype, "_maxSimultaneousLights", void 0);
  3679. __decorate([
  3680. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3681. ], MixMaterial.prototype, "maxSimultaneousLights", void 0);
  3682. return MixMaterial;
  3683. }(BABYLON.PushMaterial));
  3684. BABYLON.MixMaterial = MixMaterial;
  3685. })(BABYLON || (BABYLON = {}));
  3686. //# sourceMappingURL=babylon.mixMaterial.js.map
  3687. BABYLON.Effect.ShadersStore['mixVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\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<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vTextureUV;\nuniform mat4 textureMatrix;\nuniform vec2 vTextureInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,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 DIFFUSE\nif (vTextureInfos.x == 0.)\n{\nvTextureUV=vec2(textureMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvTextureUV=vec2(textureMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  3688. BABYLON.Effect.ShadersStore['mixPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef DIFFUSE\nvarying vec2 vTextureUV;\nuniform sampler2D mixMap1Sampler;\nuniform vec2 vTextureInfos;\n#ifdef MIXMAP2\nuniform sampler2D mixMap2Sampler;\n#endif\nuniform sampler2D diffuse1Sampler;\nuniform sampler2D diffuse2Sampler;\nuniform sampler2D diffuse3Sampler;\nuniform sampler2D diffuse4Sampler;\nuniform vec2 diffuse1Infos;\nuniform vec2 diffuse2Infos;\nuniform vec2 diffuse3Infos;\nuniform vec2 diffuse4Infos;\n#ifdef MIXMAP2\nuniform sampler2D diffuse5Sampler;\nuniform sampler2D diffuse6Sampler;\nuniform sampler2D diffuse7Sampler;\nuniform sampler2D diffuse8Sampler;\nuniform vec2 diffuse5Infos;\nuniform vec2 diffuse6Infos;\nuniform vec2 diffuse7Infos;\nuniform vec2 diffuse8Infos;\n#endif\n#endif\n\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 finalMixColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n#ifdef MIXMAP2\nvec4 mixColor2=vec4(1.,1.,1.,1.);\n#endif\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n\nfloat alpha=vDiffuseColor.a;\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n#ifdef DIFFUSE\nvec4 mixColor=texture2D(mixMap1Sampler,vTextureUV);\n#include<depthPrePass>\nmixColor.rgb*=vTextureInfos.y;\nvec4 diffuse1Color=texture2D(diffuse1Sampler,vTextureUV*diffuse1Infos);\nvec4 diffuse2Color=texture2D(diffuse2Sampler,vTextureUV*diffuse2Infos);\nvec4 diffuse3Color=texture2D(diffuse3Sampler,vTextureUV*diffuse3Infos);\nvec4 diffuse4Color=texture2D(diffuse4Sampler,vTextureUV*diffuse4Infos);\ndiffuse1Color.rgb*=mixColor.r;\ndiffuse2Color.rgb=mix(diffuse1Color.rgb,diffuse2Color.rgb,mixColor.g);\ndiffuse3Color.rgb=mix(diffuse2Color.rgb,diffuse3Color.rgb,mixColor.b);\nfinalMixColor.rgb=mix(diffuse3Color.rgb,diffuse4Color.rgb,1.0-mixColor.a);\n#ifdef MIXMAP2\nmixColor=texture2D(mixMap2Sampler,vTextureUV);\nmixColor.rgb*=vTextureInfos.y;\nvec4 diffuse5Color=texture2D(diffuse5Sampler,vTextureUV*diffuse5Infos);\nvec4 diffuse6Color=texture2D(diffuse6Sampler,vTextureUV*diffuse6Infos);\nvec4 diffuse7Color=texture2D(diffuse7Sampler,vTextureUV*diffuse7Infos);\nvec4 diffuse8Color=texture2D(diffuse8Sampler,vTextureUV*diffuse8Infos);\ndiffuse5Color.rgb=mix(finalMixColor.rgb,diffuse5Color.rgb,mixColor.r);\ndiffuse6Color.rgb=mix(diffuse5Color.rgb,diffuse6Color.rgb,mixColor.g);\ndiffuse7Color.rgb=mix(diffuse6Color.rgb,diffuse7Color.rgb,mixColor.b);\nfinalMixColor.rgb=mix(diffuse7Color.rgb,diffuse8Color.rgb,1.0-mixColor.a);\n#endif\n#endif\n#ifdef VERTEXCOLOR\nfinalMixColor.rgb*=vColor.rgb;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor*finalMixColor.rgb,0.0,1.0);\n\nvec4 color=vec4(finalDiffuse+finalSpecular,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}\n";
  3689. var BABYLON;
  3690. (function (BABYLON) {
  3691. var TriPlanarMaterialDefines = /** @class */ (function (_super) {
  3692. __extends(TriPlanarMaterialDefines, _super);
  3693. function TriPlanarMaterialDefines() {
  3694. var _this = _super.call(this) || this;
  3695. _this.DIFFUSEX = false;
  3696. _this.DIFFUSEY = false;
  3697. _this.DIFFUSEZ = false;
  3698. _this.BUMPX = false;
  3699. _this.BUMPY = false;
  3700. _this.BUMPZ = false;
  3701. _this.CLIPPLANE = false;
  3702. _this.CLIPPLANE2 = false;
  3703. _this.CLIPPLANE3 = false;
  3704. _this.CLIPPLANE4 = false;
  3705. _this.ALPHATEST = false;
  3706. _this.DEPTHPREPASS = false;
  3707. _this.POINTSIZE = false;
  3708. _this.FOG = false;
  3709. _this.SPECULARTERM = false;
  3710. _this.NORMAL = false;
  3711. _this.VERTEXCOLOR = false;
  3712. _this.VERTEXALPHA = false;
  3713. _this.NUM_BONE_INFLUENCERS = 0;
  3714. _this.BonesPerMesh = 0;
  3715. _this.INSTANCES = false;
  3716. _this.rebuild();
  3717. return _this;
  3718. }
  3719. return TriPlanarMaterialDefines;
  3720. }(BABYLON.MaterialDefines));
  3721. var TriPlanarMaterial = /** @class */ (function (_super) {
  3722. __extends(TriPlanarMaterial, _super);
  3723. function TriPlanarMaterial(name, scene) {
  3724. var _this = _super.call(this, name, scene) || this;
  3725. _this.tileSize = 1;
  3726. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  3727. _this.specularColor = new BABYLON.Color3(0.2, 0.2, 0.2);
  3728. _this.specularPower = 64;
  3729. _this._disableLighting = false;
  3730. _this._maxSimultaneousLights = 4;
  3731. return _this;
  3732. }
  3733. TriPlanarMaterial.prototype.needAlphaBlending = function () {
  3734. return (this.alpha < 1.0);
  3735. };
  3736. TriPlanarMaterial.prototype.needAlphaTesting = function () {
  3737. return false;
  3738. };
  3739. TriPlanarMaterial.prototype.getAlphaTestTexture = function () {
  3740. return null;
  3741. };
  3742. // Methods
  3743. TriPlanarMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  3744. if (this.isFrozen) {
  3745. if (this._wasPreviouslyReady && subMesh.effect) {
  3746. return true;
  3747. }
  3748. }
  3749. if (!subMesh._materialDefines) {
  3750. subMesh._materialDefines = new TriPlanarMaterialDefines();
  3751. }
  3752. var defines = subMesh._materialDefines;
  3753. var scene = this.getScene();
  3754. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  3755. if (this._renderId === scene.getRenderId()) {
  3756. return true;
  3757. }
  3758. }
  3759. var engine = scene.getEngine();
  3760. // Textures
  3761. if (defines._areTexturesDirty) {
  3762. if (scene.texturesEnabled) {
  3763. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  3764. var textures = [this.diffuseTextureX, this.diffuseTextureY, this.diffuseTextureZ];
  3765. var textureDefines = ["DIFFUSEX", "DIFFUSEY", "DIFFUSEZ"];
  3766. for (var i = 0; i < textures.length; i++) {
  3767. if (textures[i]) {
  3768. if (!textures[i].isReady()) {
  3769. return false;
  3770. }
  3771. else {
  3772. defines[textureDefines[i]] = true;
  3773. }
  3774. }
  3775. }
  3776. }
  3777. if (BABYLON.StandardMaterial.BumpTextureEnabled) {
  3778. var textures = [this.normalTextureX, this.normalTextureY, this.normalTextureZ];
  3779. var textureDefines = ["BUMPX", "BUMPY", "BUMPZ"];
  3780. for (var i = 0; i < textures.length; i++) {
  3781. if (textures[i]) {
  3782. if (!textures[i].isReady()) {
  3783. return false;
  3784. }
  3785. else {
  3786. defines[textureDefines[i]] = true;
  3787. }
  3788. }
  3789. }
  3790. }
  3791. }
  3792. }
  3793. // Misc.
  3794. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  3795. // Lights
  3796. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  3797. // Values that need to be evaluated on every frame
  3798. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  3799. // Attribs
  3800. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  3801. // Get correct effect
  3802. if (defines.isDirty) {
  3803. defines.markAsProcessed();
  3804. scene.resetCachedMaterial();
  3805. // Fallbacks
  3806. var fallbacks = new BABYLON.EffectFallbacks();
  3807. if (defines.FOG) {
  3808. fallbacks.addFallback(1, "FOG");
  3809. }
  3810. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  3811. if (defines.NUM_BONE_INFLUENCERS > 0) {
  3812. fallbacks.addCPUSkinningFallback(0, mesh);
  3813. }
  3814. //Attributes
  3815. var attribs = [BABYLON.VertexBuffer.PositionKind];
  3816. if (defines.NORMAL) {
  3817. attribs.push(BABYLON.VertexBuffer.NormalKind);
  3818. }
  3819. if (defines.VERTEXCOLOR) {
  3820. attribs.push(BABYLON.VertexBuffer.ColorKind);
  3821. }
  3822. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  3823. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  3824. // Legacy browser patch
  3825. var shaderName = "triplanar";
  3826. var join = defines.toString();
  3827. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  3828. "vFogInfos", "vFogColor", "pointSize",
  3829. "mBones",
  3830. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4",
  3831. "tileSize"
  3832. ];
  3833. var samplers = ["diffuseSamplerX", "diffuseSamplerY", "diffuseSamplerZ",
  3834. "normalSamplerX", "normalSamplerY", "normalSamplerZ"
  3835. ];
  3836. var uniformBuffers = new Array();
  3837. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  3838. uniformsNames: uniforms,
  3839. uniformBuffersNames: uniformBuffers,
  3840. samplers: samplers,
  3841. defines: defines,
  3842. maxSimultaneousLights: this.maxSimultaneousLights
  3843. });
  3844. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  3845. attributes: attribs,
  3846. uniformsNames: uniforms,
  3847. uniformBuffersNames: uniformBuffers,
  3848. samplers: samplers,
  3849. defines: join,
  3850. fallbacks: fallbacks,
  3851. onCompiled: this.onCompiled,
  3852. onError: this.onError,
  3853. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  3854. }, engine), defines);
  3855. }
  3856. if (!subMesh.effect || !subMesh.effect.isReady()) {
  3857. return false;
  3858. }
  3859. this._renderId = scene.getRenderId();
  3860. this._wasPreviouslyReady = true;
  3861. return true;
  3862. };
  3863. TriPlanarMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  3864. var scene = this.getScene();
  3865. var defines = subMesh._materialDefines;
  3866. if (!defines) {
  3867. return;
  3868. }
  3869. var effect = subMesh.effect;
  3870. if (!effect) {
  3871. return;
  3872. }
  3873. this._activeEffect = effect;
  3874. // Matrices
  3875. this.bindOnlyWorldMatrix(world);
  3876. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  3877. // Bones
  3878. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  3879. this._activeEffect.setFloat("tileSize", this.tileSize);
  3880. if (scene.getCachedMaterial() !== this) {
  3881. // Textures
  3882. if (this.diffuseTextureX) {
  3883. this._activeEffect.setTexture("diffuseSamplerX", this.diffuseTextureX);
  3884. }
  3885. if (this.diffuseTextureY) {
  3886. this._activeEffect.setTexture("diffuseSamplerY", this.diffuseTextureY);
  3887. }
  3888. if (this.diffuseTextureZ) {
  3889. this._activeEffect.setTexture("diffuseSamplerZ", this.diffuseTextureZ);
  3890. }
  3891. if (this.normalTextureX) {
  3892. this._activeEffect.setTexture("normalSamplerX", this.normalTextureX);
  3893. }
  3894. if (this.normalTextureY) {
  3895. this._activeEffect.setTexture("normalSamplerY", this.normalTextureY);
  3896. }
  3897. if (this.normalTextureZ) {
  3898. this._activeEffect.setTexture("normalSamplerZ", this.normalTextureZ);
  3899. }
  3900. // Clip plane
  3901. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  3902. // Point size
  3903. if (this.pointsCloud) {
  3904. this._activeEffect.setFloat("pointSize", this.pointSize);
  3905. }
  3906. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  3907. }
  3908. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  3909. if (defines.SPECULARTERM) {
  3910. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  3911. }
  3912. if (scene.lightsEnabled && !this.disableLighting) {
  3913. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  3914. }
  3915. // View
  3916. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  3917. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  3918. }
  3919. // Fog
  3920. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  3921. this._afterBind(mesh, this._activeEffect);
  3922. };
  3923. TriPlanarMaterial.prototype.getAnimatables = function () {
  3924. var results = [];
  3925. if (this.mixTexture && this.mixTexture.animations && this.mixTexture.animations.length > 0) {
  3926. results.push(this.mixTexture);
  3927. }
  3928. return results;
  3929. };
  3930. TriPlanarMaterial.prototype.getActiveTextures = function () {
  3931. var activeTextures = _super.prototype.getActiveTextures.call(this);
  3932. if (this._diffuseTextureX) {
  3933. activeTextures.push(this._diffuseTextureX);
  3934. }
  3935. if (this._diffuseTextureY) {
  3936. activeTextures.push(this._diffuseTextureY);
  3937. }
  3938. if (this._diffuseTextureZ) {
  3939. activeTextures.push(this._diffuseTextureZ);
  3940. }
  3941. if (this._normalTextureX) {
  3942. activeTextures.push(this._normalTextureX);
  3943. }
  3944. if (this._normalTextureY) {
  3945. activeTextures.push(this._normalTextureY);
  3946. }
  3947. if (this._normalTextureZ) {
  3948. activeTextures.push(this._normalTextureZ);
  3949. }
  3950. return activeTextures;
  3951. };
  3952. TriPlanarMaterial.prototype.hasTexture = function (texture) {
  3953. if (_super.prototype.hasTexture.call(this, texture)) {
  3954. return true;
  3955. }
  3956. if (this._diffuseTextureX === texture) {
  3957. return true;
  3958. }
  3959. if (this._diffuseTextureY === texture) {
  3960. return true;
  3961. }
  3962. if (this._diffuseTextureZ === texture) {
  3963. return true;
  3964. }
  3965. if (this._normalTextureX === texture) {
  3966. return true;
  3967. }
  3968. if (this._normalTextureY === texture) {
  3969. return true;
  3970. }
  3971. if (this._normalTextureZ === texture) {
  3972. return true;
  3973. }
  3974. return false;
  3975. };
  3976. TriPlanarMaterial.prototype.dispose = function (forceDisposeEffect) {
  3977. if (this.mixTexture) {
  3978. this.mixTexture.dispose();
  3979. }
  3980. _super.prototype.dispose.call(this, forceDisposeEffect);
  3981. };
  3982. TriPlanarMaterial.prototype.clone = function (name) {
  3983. var _this = this;
  3984. return BABYLON.SerializationHelper.Clone(function () { return new TriPlanarMaterial(name, _this.getScene()); }, this);
  3985. };
  3986. TriPlanarMaterial.prototype.serialize = function () {
  3987. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  3988. serializationObject.customType = "BABYLON.TriPlanarMaterial";
  3989. return serializationObject;
  3990. };
  3991. TriPlanarMaterial.prototype.getClassName = function () {
  3992. return "TriPlanarMaterial";
  3993. };
  3994. // Statics
  3995. TriPlanarMaterial.Parse = function (source, scene, rootUrl) {
  3996. return BABYLON.SerializationHelper.Parse(function () { return new TriPlanarMaterial(source.name, scene); }, source, scene, rootUrl);
  3997. };
  3998. __decorate([
  3999. BABYLON.serializeAsTexture()
  4000. ], TriPlanarMaterial.prototype, "mixTexture", void 0);
  4001. __decorate([
  4002. BABYLON.serializeAsTexture("diffuseTextureX")
  4003. ], TriPlanarMaterial.prototype, "_diffuseTextureX", void 0);
  4004. __decorate([
  4005. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4006. ], TriPlanarMaterial.prototype, "diffuseTextureX", void 0);
  4007. __decorate([
  4008. BABYLON.serializeAsTexture("diffuseTexturY")
  4009. ], TriPlanarMaterial.prototype, "_diffuseTextureY", void 0);
  4010. __decorate([
  4011. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4012. ], TriPlanarMaterial.prototype, "diffuseTextureY", void 0);
  4013. __decorate([
  4014. BABYLON.serializeAsTexture("diffuseTextureZ")
  4015. ], TriPlanarMaterial.prototype, "_diffuseTextureZ", void 0);
  4016. __decorate([
  4017. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4018. ], TriPlanarMaterial.prototype, "diffuseTextureZ", void 0);
  4019. __decorate([
  4020. BABYLON.serializeAsTexture("normalTextureX")
  4021. ], TriPlanarMaterial.prototype, "_normalTextureX", void 0);
  4022. __decorate([
  4023. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4024. ], TriPlanarMaterial.prototype, "normalTextureX", void 0);
  4025. __decorate([
  4026. BABYLON.serializeAsTexture("normalTextureY")
  4027. ], TriPlanarMaterial.prototype, "_normalTextureY", void 0);
  4028. __decorate([
  4029. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4030. ], TriPlanarMaterial.prototype, "normalTextureY", void 0);
  4031. __decorate([
  4032. BABYLON.serializeAsTexture("normalTextureZ")
  4033. ], TriPlanarMaterial.prototype, "_normalTextureZ", void 0);
  4034. __decorate([
  4035. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4036. ], TriPlanarMaterial.prototype, "normalTextureZ", void 0);
  4037. __decorate([
  4038. BABYLON.serialize()
  4039. ], TriPlanarMaterial.prototype, "tileSize", void 0);
  4040. __decorate([
  4041. BABYLON.serializeAsColor3()
  4042. ], TriPlanarMaterial.prototype, "diffuseColor", void 0);
  4043. __decorate([
  4044. BABYLON.serializeAsColor3()
  4045. ], TriPlanarMaterial.prototype, "specularColor", void 0);
  4046. __decorate([
  4047. BABYLON.serialize()
  4048. ], TriPlanarMaterial.prototype, "specularPower", void 0);
  4049. __decorate([
  4050. BABYLON.serialize("disableLighting")
  4051. ], TriPlanarMaterial.prototype, "_disableLighting", void 0);
  4052. __decorate([
  4053. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  4054. ], TriPlanarMaterial.prototype, "disableLighting", void 0);
  4055. __decorate([
  4056. BABYLON.serialize("maxSimultaneousLights")
  4057. ], TriPlanarMaterial.prototype, "_maxSimultaneousLights", void 0);
  4058. __decorate([
  4059. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  4060. ], TriPlanarMaterial.prototype, "maxSimultaneousLights", void 0);
  4061. return TriPlanarMaterial;
  4062. }(BABYLON.PushMaterial));
  4063. BABYLON.TriPlanarMaterial = TriPlanarMaterial;
  4064. })(BABYLON || (BABYLON = {}));
  4065. //# sourceMappingURL=babylon.triPlanarMaterial.js.map
  4066. BABYLON.Effect.ShadersStore['triplanarVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSEX\nvarying vec2 vTextureUVX;\n#endif\n#ifdef DIFFUSEY\nvarying vec2 vTextureUVY;\n#endif\n#ifdef DIFFUSEZ\nvarying vec2 vTextureUVZ;\n#endif\nuniform float tileSize;\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying mat3 tangentSpace;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void)\n{\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef DIFFUSEX\nvTextureUVX=worldPos.zy/tileSize;\n#endif\n#ifdef DIFFUSEY\nvTextureUVY=worldPos.xz/tileSize;\n#endif\n#ifdef DIFFUSEZ\nvTextureUVZ=worldPos.xy/tileSize;\n#endif\n#ifdef NORMAL\n\nvec3 xtan=vec3(0,0,1);\nvec3 xbin=vec3(0,1,0);\nvec3 ytan=vec3(1,0,0);\nvec3 ybin=vec3(0,0,1);\nvec3 ztan=vec3(1,0,0);\nvec3 zbin=vec3(0,1,0);\nvec3 normalizedNormal=normalize(normal);\nnormalizedNormal*=normalizedNormal;\nvec3 worldBinormal=normalize(xbin*normalizedNormal.x+ybin*normalizedNormal.y+zbin*normalizedNormal.z);\nvec3 worldTangent=normalize(xtan*normalizedNormal.x+ytan*normalizedNormal.y+ztan*normalizedNormal.z);\nworldTangent=(world*vec4(worldTangent,1.0)).xyz;\nworldBinormal=(world*vec4(worldBinormal,1.0)).xyz;\nvec3 worldNormal=normalize(cross(worldTangent,worldBinormal));\ntangentSpace[0]=worldTangent;\ntangentSpace[1]=worldBinormal;\ntangentSpace[2]=worldNormal;\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  4067. BABYLON.Effect.ShadersStore['triplanarPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef DIFFUSEX\nvarying vec2 vTextureUVX;\nuniform sampler2D diffuseSamplerX;\n#ifdef BUMPX\nuniform sampler2D normalSamplerX;\n#endif\n#endif\n#ifdef DIFFUSEY\nvarying vec2 vTextureUVY;\nuniform sampler2D diffuseSamplerY;\n#ifdef BUMPY\nuniform sampler2D normalSamplerY;\n#endif\n#endif\n#ifdef DIFFUSEZ\nvarying vec2 vTextureUVZ;\nuniform sampler2D diffuseSamplerZ;\n#ifdef BUMPZ\nuniform sampler2D normalSamplerZ;\n#endif\n#endif\n#ifdef NORMAL\nvarying mat3 tangentSpace;\n#endif\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<fogFragmentDeclaration>\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(0.,0.,0.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n\n#ifdef NORMAL\nvec3 normalW=tangentSpace[2];\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\nvec4 baseNormal=vec4(0.0,0.0,0.0,1.0);\nnormalW*=normalW;\n#ifdef DIFFUSEX\nbaseColor+=texture2D(diffuseSamplerX,vTextureUVX)*normalW.x;\n#ifdef BUMPX\nbaseNormal+=texture2D(normalSamplerX,vTextureUVX)*normalW.x;\n#endif\n#endif\n#ifdef DIFFUSEY\nbaseColor+=texture2D(diffuseSamplerY,vTextureUVY)*normalW.y;\n#ifdef BUMPY\nbaseNormal+=texture2D(normalSamplerY,vTextureUVY)*normalW.y;\n#endif\n#endif\n#ifdef DIFFUSEZ\nbaseColor+=texture2D(diffuseSamplerZ,vTextureUVZ)*normalW.z;\n#ifdef BUMPZ\nbaseNormal+=texture2D(normalSamplerZ,vTextureUVZ)*normalW.z;\n#endif\n#endif\n#ifdef NORMAL\nnormalW=normalize((2.0*baseNormal.xyz-1.0)*tangentSpace);\n#endif\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularBase=vec3(0.,0.,0.);\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse+finalSpecular,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}\n";
  4068. var BABYLON;
  4069. (function (BABYLON) {
  4070. var SkyMaterialDefines = /** @class */ (function (_super) {
  4071. __extends(SkyMaterialDefines, _super);
  4072. function SkyMaterialDefines() {
  4073. var _this = _super.call(this) || this;
  4074. _this.CLIPPLANE = false;
  4075. _this.CLIPPLANE2 = false;
  4076. _this.CLIPPLANE3 = false;
  4077. _this.CLIPPLANE4 = false;
  4078. _this.POINTSIZE = false;
  4079. _this.FOG = false;
  4080. _this.VERTEXCOLOR = false;
  4081. _this.VERTEXALPHA = false;
  4082. _this.rebuild();
  4083. return _this;
  4084. }
  4085. return SkyMaterialDefines;
  4086. }(BABYLON.MaterialDefines));
  4087. var SkyMaterial = /** @class */ (function (_super) {
  4088. __extends(SkyMaterial, _super);
  4089. function SkyMaterial(name, scene) {
  4090. var _this = _super.call(this, name, scene) || this;
  4091. // Public members
  4092. _this.luminance = 1.0;
  4093. _this.turbidity = 10.0;
  4094. _this.rayleigh = 2.0;
  4095. _this.mieCoefficient = 0.005;
  4096. _this.mieDirectionalG = 0.8;
  4097. _this.distance = 500;
  4098. _this.inclination = 0.49;
  4099. _this.azimuth = 0.25;
  4100. _this.sunPosition = new BABYLON.Vector3(0, 100, 0);
  4101. _this.useSunPosition = false;
  4102. // Private members
  4103. _this._cameraPosition = BABYLON.Vector3.Zero();
  4104. return _this;
  4105. }
  4106. SkyMaterial.prototype.needAlphaBlending = function () {
  4107. return (this.alpha < 1.0);
  4108. };
  4109. SkyMaterial.prototype.needAlphaTesting = function () {
  4110. return false;
  4111. };
  4112. SkyMaterial.prototype.getAlphaTestTexture = function () {
  4113. return null;
  4114. };
  4115. // Methods
  4116. SkyMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  4117. if (this.isFrozen) {
  4118. if (this._wasPreviouslyReady && subMesh.effect) {
  4119. return true;
  4120. }
  4121. }
  4122. if (!subMesh._materialDefines) {
  4123. subMesh._materialDefines = new SkyMaterialDefines();
  4124. }
  4125. var defines = subMesh._materialDefines;
  4126. var scene = this.getScene();
  4127. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  4128. if (this._renderId === scene.getRenderId()) {
  4129. return true;
  4130. }
  4131. }
  4132. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, false, defines);
  4133. // Attribs
  4134. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, false);
  4135. // Get correct effect
  4136. if (defines.isDirty) {
  4137. defines.markAsProcessed();
  4138. scene.resetCachedMaterial();
  4139. // Fallbacks
  4140. var fallbacks = new BABYLON.EffectFallbacks();
  4141. if (defines.FOG) {
  4142. fallbacks.addFallback(1, "FOG");
  4143. }
  4144. //Attributes
  4145. var attribs = [BABYLON.VertexBuffer.PositionKind];
  4146. if (defines.VERTEXCOLOR) {
  4147. attribs.push(BABYLON.VertexBuffer.ColorKind);
  4148. }
  4149. var shaderName = "sky";
  4150. var join = defines.toString();
  4151. subMesh.setEffect(scene.getEngine().createEffect(shaderName, attribs, ["world", "viewProjection", "view",
  4152. "vFogInfos", "vFogColor", "pointSize", "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4",
  4153. "luminance", "turbidity", "rayleigh", "mieCoefficient", "mieDirectionalG", "sunPosition",
  4154. "cameraPosition"
  4155. ], [], join, fallbacks, this.onCompiled, this.onError), defines);
  4156. }
  4157. if (!subMesh.effect || !subMesh.effect.isReady()) {
  4158. return false;
  4159. }
  4160. this._renderId = scene.getRenderId();
  4161. this._wasPreviouslyReady = true;
  4162. return true;
  4163. };
  4164. SkyMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  4165. var scene = this.getScene();
  4166. var defines = subMesh._materialDefines;
  4167. if (!defines) {
  4168. return;
  4169. }
  4170. var effect = subMesh.effect;
  4171. if (!effect) {
  4172. return;
  4173. }
  4174. this._activeEffect = effect;
  4175. // Matrices
  4176. this.bindOnlyWorldMatrix(world);
  4177. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  4178. if (this._mustRebind(scene, effect)) {
  4179. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  4180. // Point size
  4181. if (this.pointsCloud) {
  4182. this._activeEffect.setFloat("pointSize", this.pointSize);
  4183. }
  4184. }
  4185. // View
  4186. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  4187. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  4188. }
  4189. // Fog
  4190. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  4191. // Sky
  4192. var camera = scene.activeCamera;
  4193. if (camera) {
  4194. var cameraWorldMatrix = camera.getWorldMatrix();
  4195. this._cameraPosition.x = cameraWorldMatrix.m[12];
  4196. this._cameraPosition.y = cameraWorldMatrix.m[13];
  4197. this._cameraPosition.z = cameraWorldMatrix.m[14];
  4198. this._activeEffect.setVector3("cameraPosition", this._cameraPosition);
  4199. }
  4200. if (this.luminance > 0) {
  4201. this._activeEffect.setFloat("luminance", this.luminance);
  4202. }
  4203. this._activeEffect.setFloat("turbidity", this.turbidity);
  4204. this._activeEffect.setFloat("rayleigh", this.rayleigh);
  4205. this._activeEffect.setFloat("mieCoefficient", this.mieCoefficient);
  4206. this._activeEffect.setFloat("mieDirectionalG", this.mieDirectionalG);
  4207. if (!this.useSunPosition) {
  4208. var theta = Math.PI * (this.inclination - 0.5);
  4209. var phi = 2 * Math.PI * (this.azimuth - 0.5);
  4210. this.sunPosition.x = this.distance * Math.cos(phi);
  4211. this.sunPosition.y = this.distance * Math.sin(phi) * Math.sin(theta);
  4212. this.sunPosition.z = this.distance * Math.sin(phi) * Math.cos(theta);
  4213. }
  4214. this._activeEffect.setVector3("sunPosition", this.sunPosition);
  4215. this._afterBind(mesh, this._activeEffect);
  4216. };
  4217. SkyMaterial.prototype.getAnimatables = function () {
  4218. return [];
  4219. };
  4220. SkyMaterial.prototype.dispose = function (forceDisposeEffect) {
  4221. _super.prototype.dispose.call(this, forceDisposeEffect);
  4222. };
  4223. SkyMaterial.prototype.clone = function (name) {
  4224. var _this = this;
  4225. return BABYLON.SerializationHelper.Clone(function () { return new SkyMaterial(name, _this.getScene()); }, this);
  4226. };
  4227. SkyMaterial.prototype.serialize = function () {
  4228. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  4229. serializationObject.customType = "BABYLON.SkyMaterial";
  4230. return serializationObject;
  4231. };
  4232. SkyMaterial.prototype.getClassName = function () {
  4233. return "SkyMaterial";
  4234. };
  4235. // Statics
  4236. SkyMaterial.Parse = function (source, scene, rootUrl) {
  4237. return BABYLON.SerializationHelper.Parse(function () { return new SkyMaterial(source.name, scene); }, source, scene, rootUrl);
  4238. };
  4239. __decorate([
  4240. BABYLON.serialize()
  4241. ], SkyMaterial.prototype, "luminance", void 0);
  4242. __decorate([
  4243. BABYLON.serialize()
  4244. ], SkyMaterial.prototype, "turbidity", void 0);
  4245. __decorate([
  4246. BABYLON.serialize()
  4247. ], SkyMaterial.prototype, "rayleigh", void 0);
  4248. __decorate([
  4249. BABYLON.serialize()
  4250. ], SkyMaterial.prototype, "mieCoefficient", void 0);
  4251. __decorate([
  4252. BABYLON.serialize()
  4253. ], SkyMaterial.prototype, "mieDirectionalG", void 0);
  4254. __decorate([
  4255. BABYLON.serialize()
  4256. ], SkyMaterial.prototype, "distance", void 0);
  4257. __decorate([
  4258. BABYLON.serialize()
  4259. ], SkyMaterial.prototype, "inclination", void 0);
  4260. __decorate([
  4261. BABYLON.serialize()
  4262. ], SkyMaterial.prototype, "azimuth", void 0);
  4263. __decorate([
  4264. BABYLON.serializeAsVector3()
  4265. ], SkyMaterial.prototype, "sunPosition", void 0);
  4266. __decorate([
  4267. BABYLON.serialize()
  4268. ], SkyMaterial.prototype, "useSunPosition", void 0);
  4269. return SkyMaterial;
  4270. }(BABYLON.PushMaterial));
  4271. BABYLON.SkyMaterial = SkyMaterial;
  4272. })(BABYLON || (BABYLON = {}));
  4273. //# sourceMappingURL=babylon.skyMaterial.js.map
  4274. BABYLON.Effect.ShadersStore['skyVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\nvoid main(void) {\ngl_Position=viewProjection*world*vec4(position,1.0);\nvec4 worldPos=world*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  4275. BABYLON.Effect.ShadersStore['skyPixelShader'] = "precision highp float;\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\nuniform vec3 cameraPosition;\nuniform float luminance;\nuniform float turbidity;\nuniform float rayleigh;\nuniform float mieCoefficient;\nuniform float mieDirectionalG;\nuniform vec3 sunPosition;\n\n#include<fogFragmentDeclaration>\n\nconst float e=2.71828182845904523536028747135266249775724709369995957;\nconst float pi=3.141592653589793238462643383279502884197169;\nconst float n=1.0003;\nconst float N=2.545E25;\nconst float pn=0.035;\nconst vec3 lambda=vec3(680E-9,550E-9,450E-9);\nconst vec3 K=vec3(0.686,0.678,0.666);\nconst float v=4.0;\nconst float rayleighZenithLength=8.4E3;\nconst float mieZenithLength=1.25E3;\nconst vec3 up=vec3(0.0,1.0,0.0);\nconst float EE=1000.0;\nconst float sunAngularDiameterCos=0.999956676946448443553574619906976478926848692873900859324;\nconst float cutoffAngle=pi/1.95;\nconst float steepness=1.5;\nvec3 totalRayleigh(vec3 lambda)\n{\nreturn (8.0*pow(pi,3.0)*pow(pow(n,2.0)-1.0,2.0)*(6.0+3.0*pn))/(3.0*N*pow(lambda,vec3(4.0))*(6.0-7.0*pn));\n}\nvec3 simplifiedRayleigh()\n{\nreturn 0.0005/vec3(94,40,18);\n}\nfloat rayleighPhase(float cosTheta)\n{ \nreturn (3.0/(16.0*pi))*(1.0+pow(cosTheta,2.0));\n}\nvec3 totalMie(vec3 lambda,vec3 K,float T)\n{\nfloat c=(0.2*T )*10E-18;\nreturn 0.434*c*pi*pow((2.0*pi)/lambda,vec3(v-2.0))*K;\n}\nfloat hgPhase(float cosTheta,float g)\n{\nreturn (1.0/(4.0*pi))*((1.0-pow(g,2.0))/pow(1.0-2.0*g*cosTheta+pow(g,2.0),1.5));\n}\nfloat sunIntensity(float zenithAngleCos)\n{\nreturn EE*max(0.0,1.0-exp((-(cutoffAngle-acos(zenithAngleCos))/steepness)));\n}\nfloat A=0.15;\nfloat B=0.50;\nfloat C=0.10;\nfloat D=0.20;\nfloat EEE=0.02;\nfloat F=0.30;\nfloat W=1000.0;\nvec3 Uncharted2Tonemap(vec3 x)\n{\nreturn ((x*(A*x+C*B)+D*EEE)/(x*(A*x+B)+D*F))-EEE/F;\n}\nvoid main(void) {\n\n#include<clipPlaneFragment>\n\nfloat sunfade=1.0-clamp(1.0-exp((sunPosition.y/450000.0)),0.0,1.0);\nfloat rayleighCoefficient=rayleigh-(1.0*(1.0-sunfade));\nvec3 sunDirection=normalize(sunPosition);\nfloat sunE=sunIntensity(dot(sunDirection,up));\nvec3 betaR=simplifiedRayleigh()*rayleighCoefficient;\nvec3 betaM=totalMie(lambda,K,turbidity)*mieCoefficient;\nfloat zenithAngle=acos(max(0.0,dot(up,normalize(vPositionW-cameraPosition))));\nfloat sR=rayleighZenithLength/(cos(zenithAngle)+0.15*pow(93.885-((zenithAngle*180.0)/pi),-1.253));\nfloat sM=mieZenithLength/(cos(zenithAngle)+0.15*pow(93.885-((zenithAngle*180.0)/pi),-1.253));\nvec3 Fex=exp(-(betaR*sR+betaM*sM));\nfloat cosTheta=dot(normalize(vPositionW-cameraPosition),sunDirection);\nfloat rPhase=rayleighPhase(cosTheta*0.5+0.5);\nvec3 betaRTheta=betaR*rPhase;\nfloat mPhase=hgPhase(cosTheta,mieDirectionalG);\nvec3 betaMTheta=betaM*mPhase;\nvec3 Lin=pow(sunE*((betaRTheta+betaMTheta)/(betaR+betaM))*(1.0-Fex),vec3(1.5));\nLin*=mix(vec3(1.0),pow(sunE*((betaRTheta+betaMTheta)/(betaR+betaM))*Fex,vec3(1.0/2.0)),clamp(pow(1.0-dot(up,sunDirection),5.0),0.0,1.0));\nvec3 direction=normalize(vPositionW-cameraPosition);\nfloat theta=acos(direction.y);\nfloat phi=atan(direction.z,direction.x);\nvec2 uv=vec2(phi,theta)/vec2(2.0*pi,pi)+vec2(0.5,0.0);\nvec3 L0=vec3(0.1)*Fex;\nfloat sundisk=smoothstep(sunAngularDiameterCos,sunAngularDiameterCos+0.00002,cosTheta);\nL0+=(sunE*19000.0*Fex)*sundisk;\nvec3 whiteScale=1.0/Uncharted2Tonemap(vec3(W));\nvec3 texColor=(Lin+L0); \ntexColor*=0.04 ;\ntexColor+=vec3(0.0,0.001,0.0025)*0.3;\nfloat g_fMaxLuminance=1.0;\nfloat fLumScaled=0.1/luminance; \nfloat fLumCompressed=(fLumScaled*(1.0+(fLumScaled/(g_fMaxLuminance*g_fMaxLuminance))))/(1.0+fLumScaled); \nfloat ExposureBias=fLumCompressed;\nvec3 curr=Uncharted2Tonemap((log2(2.0/pow(luminance,4.0)))*texColor);\n\n\n\nvec3 retColor=curr*whiteScale;\n\n\nfloat alpha=1.0;\n#ifdef VERTEXCOLOR\nretColor.rgb*=vColor.rgb;\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n\nvec4 color=clamp(vec4(retColor.rgb,alpha),0.0,1.0);\n\n#include<fogFragment>\ngl_FragColor=color;\n}\n";
  4276. var BABYLON;
  4277. (function (BABYLON) {
  4278. var GridMaterialDefines = /** @class */ (function (_super) {
  4279. __extends(GridMaterialDefines, _super);
  4280. function GridMaterialDefines() {
  4281. var _this = _super.call(this) || this;
  4282. _this.OPACITY = false;
  4283. _this.TRANSPARENT = false;
  4284. _this.FOG = false;
  4285. _this.PREMULTIPLYALPHA = false;
  4286. _this.UV1 = false;
  4287. _this.UV2 = false;
  4288. _this.rebuild();
  4289. return _this;
  4290. }
  4291. return GridMaterialDefines;
  4292. }(BABYLON.MaterialDefines));
  4293. /**
  4294. * The grid materials allows you to wrap any shape with a grid.
  4295. * Colors are customizable.
  4296. */
  4297. var GridMaterial = /** @class */ (function (_super) {
  4298. __extends(GridMaterial, _super);
  4299. /**
  4300. * constructor
  4301. * @param name The name given to the material in order to identify it afterwards.
  4302. * @param scene The scene the material is used in.
  4303. */
  4304. function GridMaterial(name, scene) {
  4305. var _this = _super.call(this, name, scene) || this;
  4306. /**
  4307. * Main color of the grid (e.g. between lines)
  4308. */
  4309. _this.mainColor = BABYLON.Color3.Black();
  4310. /**
  4311. * Color of the grid lines.
  4312. */
  4313. _this.lineColor = BABYLON.Color3.Teal();
  4314. /**
  4315. * The scale of the grid compared to unit.
  4316. */
  4317. _this.gridRatio = 1.0;
  4318. /**
  4319. * Allows setting an offset for the grid lines.
  4320. */
  4321. _this.gridOffset = BABYLON.Vector3.Zero();
  4322. /**
  4323. * The frequency of thicker lines.
  4324. */
  4325. _this.majorUnitFrequency = 10;
  4326. /**
  4327. * The visibility of minor units in the grid.
  4328. */
  4329. _this.minorUnitVisibility = 0.33;
  4330. /**
  4331. * The grid opacity outside of the lines.
  4332. */
  4333. _this.opacity = 1.0;
  4334. /**
  4335. * Determine RBG output is premultiplied by alpha value.
  4336. */
  4337. _this.preMultiplyAlpha = false;
  4338. _this._gridControl = new BABYLON.Vector4(_this.gridRatio, _this.majorUnitFrequency, _this.minorUnitVisibility, _this.opacity);
  4339. return _this;
  4340. }
  4341. /**
  4342. * Returns wehter or not the grid requires alpha blending.
  4343. */
  4344. GridMaterial.prototype.needAlphaBlending = function () {
  4345. return this.opacity < 1.0 || this._opacityTexture && this._opacityTexture.isReady();
  4346. };
  4347. GridMaterial.prototype.needAlphaBlendingForMesh = function (mesh) {
  4348. return this.needAlphaBlending();
  4349. };
  4350. GridMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  4351. if (this.isFrozen) {
  4352. if (this._wasPreviouslyReady && subMesh.effect) {
  4353. return true;
  4354. }
  4355. }
  4356. if (!subMesh._materialDefines) {
  4357. subMesh._materialDefines = new GridMaterialDefines();
  4358. }
  4359. var defines = subMesh._materialDefines;
  4360. var scene = this.getScene();
  4361. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  4362. if (this._renderId === scene.getRenderId()) {
  4363. return true;
  4364. }
  4365. }
  4366. if (defines.TRANSPARENT !== (this.opacity < 1.0)) {
  4367. defines.TRANSPARENT = !defines.TRANSPARENT;
  4368. defines.markAsUnprocessed();
  4369. }
  4370. if (defines.PREMULTIPLYALPHA != this.preMultiplyAlpha) {
  4371. defines.PREMULTIPLYALPHA = !defines.PREMULTIPLYALPHA;
  4372. defines.markAsUnprocessed();
  4373. }
  4374. // Textures
  4375. if (defines._areTexturesDirty) {
  4376. defines._needUVs = false;
  4377. if (scene.texturesEnabled) {
  4378. if (this._opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
  4379. if (!this._opacityTexture.isReady()) {
  4380. return false;
  4381. }
  4382. else {
  4383. defines._needUVs = true;
  4384. defines.OPACITY = true;
  4385. }
  4386. }
  4387. }
  4388. }
  4389. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, false, this.fogEnabled, false, defines);
  4390. // Get correct effect
  4391. if (defines.isDirty) {
  4392. defines.markAsProcessed();
  4393. scene.resetCachedMaterial();
  4394. // Attribs
  4395. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, false);
  4396. //Attributes
  4397. var attribs = [BABYLON.VertexBuffer.PositionKind, BABYLON.VertexBuffer.NormalKind];
  4398. if (defines.UV1) {
  4399. attribs.push(BABYLON.VertexBuffer.UVKind);
  4400. }
  4401. if (defines.UV2) {
  4402. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  4403. }
  4404. // Defines
  4405. var join = defines.toString();
  4406. subMesh.setEffect(scene.getEngine().createEffect("grid", attribs, ["projection", "worldView", "mainColor", "lineColor", "gridControl", "gridOffset", "vFogInfos", "vFogColor", "world", "view",
  4407. "opacityMatrix", "vOpacityInfos"], ["opacitySampler"], join, undefined, this.onCompiled, this.onError), defines);
  4408. }
  4409. if (!subMesh.effect || !subMesh.effect.isReady()) {
  4410. return false;
  4411. }
  4412. this._renderId = scene.getRenderId();
  4413. this._wasPreviouslyReady = true;
  4414. return true;
  4415. };
  4416. GridMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  4417. var scene = this.getScene();
  4418. var defines = subMesh._materialDefines;
  4419. if (!defines) {
  4420. return;
  4421. }
  4422. var effect = subMesh.effect;
  4423. if (!effect) {
  4424. return;
  4425. }
  4426. this._activeEffect = effect;
  4427. // Matrices
  4428. this.bindOnlyWorldMatrix(world);
  4429. this._activeEffect.setMatrix("worldView", world.multiply(scene.getViewMatrix()));
  4430. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  4431. this._activeEffect.setMatrix("projection", scene.getProjectionMatrix());
  4432. // Uniforms
  4433. if (this._mustRebind(scene, effect)) {
  4434. this._activeEffect.setColor3("mainColor", this.mainColor);
  4435. this._activeEffect.setColor3("lineColor", this.lineColor);
  4436. this._activeEffect.setVector3("gridOffset", this.gridOffset);
  4437. this._gridControl.x = this.gridRatio;
  4438. this._gridControl.y = Math.round(this.majorUnitFrequency);
  4439. this._gridControl.z = this.minorUnitVisibility;
  4440. this._gridControl.w = this.opacity;
  4441. this._activeEffect.setVector4("gridControl", this._gridControl);
  4442. if (this._opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
  4443. this._activeEffect.setTexture("opacitySampler", this._opacityTexture);
  4444. this._activeEffect.setFloat2("vOpacityInfos", this._opacityTexture.coordinatesIndex, this._opacityTexture.level);
  4445. this._activeEffect.setMatrix("opacityMatrix", this._opacityTexture.getTextureMatrix());
  4446. }
  4447. }
  4448. // Fog
  4449. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  4450. this._afterBind(mesh, this._activeEffect);
  4451. };
  4452. GridMaterial.prototype.dispose = function (forceDisposeEffect) {
  4453. _super.prototype.dispose.call(this, forceDisposeEffect);
  4454. };
  4455. GridMaterial.prototype.clone = function (name) {
  4456. var _this = this;
  4457. return BABYLON.SerializationHelper.Clone(function () { return new GridMaterial(name, _this.getScene()); }, this);
  4458. };
  4459. GridMaterial.prototype.serialize = function () {
  4460. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  4461. serializationObject.customType = "BABYLON.GridMaterial";
  4462. return serializationObject;
  4463. };
  4464. GridMaterial.prototype.getClassName = function () {
  4465. return "GridMaterial";
  4466. };
  4467. GridMaterial.Parse = function (source, scene, rootUrl) {
  4468. return BABYLON.SerializationHelper.Parse(function () { return new GridMaterial(source.name, scene); }, source, scene, rootUrl);
  4469. };
  4470. __decorate([
  4471. BABYLON.serializeAsColor3()
  4472. ], GridMaterial.prototype, "mainColor", void 0);
  4473. __decorate([
  4474. BABYLON.serializeAsColor3()
  4475. ], GridMaterial.prototype, "lineColor", void 0);
  4476. __decorate([
  4477. BABYLON.serialize()
  4478. ], GridMaterial.prototype, "gridRatio", void 0);
  4479. __decorate([
  4480. BABYLON.serializeAsColor3()
  4481. ], GridMaterial.prototype, "gridOffset", void 0);
  4482. __decorate([
  4483. BABYLON.serialize()
  4484. ], GridMaterial.prototype, "majorUnitFrequency", void 0);
  4485. __decorate([
  4486. BABYLON.serialize()
  4487. ], GridMaterial.prototype, "minorUnitVisibility", void 0);
  4488. __decorate([
  4489. BABYLON.serialize()
  4490. ], GridMaterial.prototype, "opacity", void 0);
  4491. __decorate([
  4492. BABYLON.serialize()
  4493. ], GridMaterial.prototype, "preMultiplyAlpha", void 0);
  4494. __decorate([
  4495. BABYLON.serializeAsTexture("opacityTexture")
  4496. ], GridMaterial.prototype, "_opacityTexture", void 0);
  4497. __decorate([
  4498. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4499. ], GridMaterial.prototype, "opacityTexture", void 0);
  4500. return GridMaterial;
  4501. }(BABYLON.PushMaterial));
  4502. BABYLON.GridMaterial = GridMaterial;
  4503. })(BABYLON || (BABYLON = {}));
  4504. //# sourceMappingURL=babylon.gridmaterial.js.map
  4505. BABYLON.Effect.ShadersStore['gridVertexShader'] = "precision highp float;\n\nattribute vec3 position;\nattribute vec3 normal;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n\nuniform mat4 projection;\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 worldView;\n\n#ifdef TRANSPARENT\nvarying vec4 vCameraSpacePosition;\n#endif\nvarying vec3 vPosition;\nvarying vec3 vNormal;\n#include<fogVertexDeclaration>\n#ifdef OPACITY\nvarying vec2 vOpacityUV;\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\nvoid main(void) {\n#ifdef FOG\nvec4 worldPos=world*vec4(position,1.0);\n#endif\n#include<fogVertex>\nvec4 cameraSpacePosition=worldView*vec4(position,1.0);\ngl_Position=projection*cameraSpacePosition;\n#ifdef TRANSPARENT\nvCameraSpacePosition=cameraSpacePosition;\n#endif\n#ifdef OPACITY\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\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 \nvPosition=position;\nvNormal=normal;\n}";
  4506. BABYLON.Effect.ShadersStore['gridPixelShader'] = "#extension GL_OES_standard_derivatives : enable\n#define SQRT2 1.41421356\n#define PI 3.14159\nprecision highp float;\nuniform vec3 mainColor;\nuniform vec3 lineColor;\nuniform vec4 gridControl;\nuniform vec3 gridOffset;\n\n#ifdef TRANSPARENT\nvarying vec4 vCameraSpacePosition;\n#endif\nvarying vec3 vPosition;\nvarying vec3 vNormal;\n#include<fogFragmentDeclaration>\n\n#ifdef OPACITY\nvarying vec2 vOpacityUV;\nuniform sampler2D opacitySampler;\nuniform vec2 vOpacityInfos;\n#endif\nfloat getVisibility(float position) {\n\nfloat majorGridFrequency=gridControl.y;\nif (floor(position+0.5) == floor(position/majorGridFrequency+0.5)*majorGridFrequency)\n{\nreturn 1.0;\n} \nreturn gridControl.z;\n}\nfloat getAnisotropicAttenuation(float differentialLength) {\nconst float maxNumberOfLines=10.0;\nreturn clamp(1.0/(differentialLength+1.0)-1.0/maxNumberOfLines,0.0,1.0);\n}\nfloat isPointOnLine(float position,float differentialLength) {\nfloat fractionPartOfPosition=position-floor(position+0.5); \nfractionPartOfPosition/=differentialLength; \nfractionPartOfPosition=clamp(fractionPartOfPosition,-1.,1.);\nfloat result=0.5+0.5*cos(fractionPartOfPosition*PI); \nreturn result; \n}\nfloat contributionOnAxis(float position) {\nfloat differentialLength=length(vec2(dFdx(position),dFdy(position)));\ndifferentialLength*=SQRT2; \n\nfloat result=isPointOnLine(position,differentialLength);\n\nfloat visibility=getVisibility(position);\nresult*=visibility;\n\nfloat anisotropicAttenuation=getAnisotropicAttenuation(differentialLength);\nresult*=anisotropicAttenuation;\nreturn result;\n}\nfloat normalImpactOnAxis(float x) {\nfloat normalImpact=clamp(1.0-3.0*abs(x*x*x),0.0,1.0);\nreturn normalImpact;\n}\nvoid main(void) {\n\nfloat gridRatio=gridControl.x;\nvec3 gridPos=(vPosition+gridOffset)/gridRatio;\n\nfloat x=contributionOnAxis(gridPos.x);\nfloat y=contributionOnAxis(gridPos.y);\nfloat z=contributionOnAxis(gridPos.z);\n\nvec3 normal=normalize(vNormal);\nx*=normalImpactOnAxis(normal.x);\ny*=normalImpactOnAxis(normal.y);\nz*=normalImpactOnAxis(normal.z);\n\nfloat grid=clamp(x+y+z,0.,1.);\n\nvec3 color=mix(mainColor,lineColor,grid);\n#ifdef FOG\n#include<fogFragment>\n#endif\nfloat opacity=1.0;\n#ifdef TRANSPARENT\nfloat distanceToFragment=length(vCameraSpacePosition.xyz);\nfloat cameraPassThrough=clamp(distanceToFragment-0.25,0.0,1.0);\nopacity=clamp(grid,0.08,cameraPassThrough*gridControl.w*grid);\n#endif \n#ifdef OPACITY\nopacity*=texture2D(opacitySampler,vOpacityUV).a;\n#endif \n\ngl_FragColor=vec4(color.rgb,opacity);\n#ifdef TRANSPARENT\n#ifdef PREMULTIPLYALPHA\ngl_FragColor.rgb*=opacity;\n#endif\n#else \n#endif\n}";
  4507. var BABYLON;
  4508. (function (BABYLON) {
  4509. var CustomShaderStructure = /** @class */ (function () {
  4510. function CustomShaderStructure() {
  4511. }
  4512. return CustomShaderStructure;
  4513. }());
  4514. BABYLON.CustomShaderStructure = CustomShaderStructure;
  4515. var ShaderSpecialParts = /** @class */ (function () {
  4516. function ShaderSpecialParts() {
  4517. }
  4518. return ShaderSpecialParts;
  4519. }());
  4520. BABYLON.ShaderSpecialParts = ShaderSpecialParts;
  4521. var CustomMaterial = /** @class */ (function (_super) {
  4522. __extends(CustomMaterial, _super);
  4523. function CustomMaterial(name, scene) {
  4524. var _this = _super.call(this, name, scene) || this;
  4525. _this.CustomParts = new ShaderSpecialParts();
  4526. _this.customShaderNameResolve = _this.Builder;
  4527. _this.FragmentShader = BABYLON.Effect.ShadersStore["defaultPixelShader"];
  4528. _this.VertexShader = BABYLON.Effect.ShadersStore["defaultVertexShader"];
  4529. return _this;
  4530. }
  4531. CustomMaterial.prototype.AttachAfterBind = function (mesh, effect) {
  4532. for (var el in this._newUniformInstances) {
  4533. var ea = el.toString().split('-');
  4534. if (ea[0] == 'vec2') {
  4535. effect.setVector2(ea[1], this._newUniformInstances[el]);
  4536. }
  4537. else if (ea[0] == 'vec3') {
  4538. effect.setVector3(ea[1], this._newUniformInstances[el]);
  4539. }
  4540. else if (ea[0] == 'vec4') {
  4541. effect.setVector4(ea[1], this._newUniformInstances[el]);
  4542. }
  4543. else if (ea[0] == 'mat4') {
  4544. effect.setMatrix(ea[1], this._newUniformInstances[el]);
  4545. }
  4546. else if (ea[0] == 'float') {
  4547. effect.setFloat(ea[1], this._newUniformInstances[el]);
  4548. }
  4549. }
  4550. for (var el in this._newSamplerInstances) {
  4551. var ea = el.toString().split('-');
  4552. if (ea[0] == 'sampler2D' && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady()) {
  4553. effect.setTexture(ea[1], this._newSamplerInstances[el]);
  4554. }
  4555. }
  4556. };
  4557. CustomMaterial.prototype.ReviewUniform = function (name, arr) {
  4558. if (name == "uniform") {
  4559. for (var ind in this._newUniforms) {
  4560. if (this._customUniform[ind].indexOf('sampler') == -1) {
  4561. arr.push(this._newUniforms[ind]);
  4562. }
  4563. }
  4564. }
  4565. if (name == "sampler") {
  4566. for (var ind in this._newUniforms) {
  4567. if (this._customUniform[ind].indexOf('sampler') != -1) {
  4568. arr.push(this._newUniforms[ind]);
  4569. }
  4570. }
  4571. }
  4572. return arr;
  4573. };
  4574. CustomMaterial.prototype.Builder = function (shaderName, uniforms, uniformBuffers, samplers, defines) {
  4575. var _this = this;
  4576. if (this._isCreatedShader) {
  4577. return this._createdShaderName;
  4578. }
  4579. this._isCreatedShader = false;
  4580. CustomMaterial.ShaderIndexer++;
  4581. var name = "custom_" + CustomMaterial.ShaderIndexer;
  4582. this.ReviewUniform("uniform", uniforms);
  4583. this.ReviewUniform("sampler", samplers);
  4584. var fn_afterBind = this._afterBind.bind(this);
  4585. this._afterBind = function (m, e) {
  4586. if (!e) {
  4587. return;
  4588. }
  4589. _this.AttachAfterBind(m, e);
  4590. try {
  4591. fn_afterBind(m, e);
  4592. }
  4593. catch (e) { }
  4594. };
  4595. BABYLON.Effect.ShadersStore[name + "VertexShader"] = this.VertexShader
  4596. .replace('#define CUSTOM_VERTEX_BEGIN', (this.CustomParts.Vertex_Begin ? this.CustomParts.Vertex_Begin : ""))
  4597. .replace('#define CUSTOM_VERTEX_DEFINITIONS', (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Vertex_Definitions ? this.CustomParts.Vertex_Definitions : ""))
  4598. .replace('#define CUSTOM_VERTEX_MAIN_BEGIN', (this.CustomParts.Vertex_MainBegin ? this.CustomParts.Vertex_MainBegin : ""))
  4599. .replace('#define CUSTOM_VERTEX_UPDATE_POSITION', (this.CustomParts.Vertex_Before_PositionUpdated ? this.CustomParts.Vertex_Before_PositionUpdated : ""))
  4600. .replace('#define CUSTOM_VERTEX_UPDATE_NORMAL', (this.CustomParts.Vertex_Before_NormalUpdated ? this.CustomParts.Vertex_Before_NormalUpdated : ""));
  4601. // #define CUSTOM_VERTEX_MAIN_END
  4602. BABYLON.Effect.ShadersStore[name + "PixelShader"] = this.FragmentShader
  4603. .replace('#define CUSTOM_FRAGMENT_BEGIN', (this.CustomParts.Fragment_Begin ? this.CustomParts.Fragment_Begin : ""))
  4604. .replace('#define CUSTOM_FRAGMENT_MAIN_BEGIN', (this.CustomParts.Fragment_MainBegin ? this.CustomParts.Fragment_MainBegin : ""))
  4605. .replace('#define CUSTOM_FRAGMENT_DEFINITIONS', (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Fragment_Definitions ? this.CustomParts.Fragment_Definitions : ""))
  4606. .replace('#define CUSTOM_FRAGMENT_UPDATE_DIFFUSE', (this.CustomParts.Fragment_Custom_Diffuse ? this.CustomParts.Fragment_Custom_Diffuse : ""))
  4607. .replace('#define CUSTOM_FRAGMENT_UPDATE_ALPHA', (this.CustomParts.Fragment_Custom_Alpha ? this.CustomParts.Fragment_Custom_Alpha : ""))
  4608. .replace('#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR', (this.CustomParts.Fragment_Before_FragColor ? this.CustomParts.Fragment_Before_FragColor : ""));
  4609. // #define CUSTOM_FRAGMENT_BEFORE_LIGHTS
  4610. // #define CUSTOM_FRAGMENT_BEFORE_FOG
  4611. this._isCreatedShader = true;
  4612. this._createdShaderName = name;
  4613. return name;
  4614. };
  4615. CustomMaterial.prototype.AddUniform = function (name, kind, param) {
  4616. if (!this._customUniform) {
  4617. this._customUniform = new Array();
  4618. this._newUniforms = new Array();
  4619. this._newSamplerInstances = new Array();
  4620. this._newUniformInstances = new Array();
  4621. }
  4622. if (param) {
  4623. if (kind.indexOf("sampler") == -1) {
  4624. this._newUniformInstances[kind + "-" + name] = param;
  4625. }
  4626. else {
  4627. this._newUniformInstances[kind + "-" + name] = param;
  4628. }
  4629. }
  4630. this._customUniform.push("uniform " + kind + " " + name + ";");
  4631. this._newUniforms.push(name);
  4632. return this;
  4633. };
  4634. CustomMaterial.prototype.Fragment_Begin = function (shaderPart) {
  4635. this.CustomParts.Fragment_Begin = shaderPart;
  4636. return this;
  4637. };
  4638. CustomMaterial.prototype.Fragment_Definitions = function (shaderPart) {
  4639. this.CustomParts.Fragment_Definitions = shaderPart;
  4640. return this;
  4641. };
  4642. CustomMaterial.prototype.Fragment_MainBegin = function (shaderPart) {
  4643. this.CustomParts.Fragment_MainBegin = shaderPart;
  4644. return this;
  4645. };
  4646. CustomMaterial.prototype.Fragment_Custom_Diffuse = function (shaderPart) {
  4647. this.CustomParts.Fragment_Custom_Diffuse = shaderPart.replace("result", "diffuseColor");
  4648. return this;
  4649. };
  4650. CustomMaterial.prototype.Fragment_Custom_Alpha = function (shaderPart) {
  4651. this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace("result", "alpha");
  4652. return this;
  4653. };
  4654. CustomMaterial.prototype.Fragment_Before_FragColor = function (shaderPart) {
  4655. this.CustomParts.Fragment_Before_FragColor = shaderPart.replace("result", "color");
  4656. return this;
  4657. };
  4658. CustomMaterial.prototype.Vertex_Begin = function (shaderPart) {
  4659. this.CustomParts.Vertex_Begin = shaderPart;
  4660. return this;
  4661. };
  4662. CustomMaterial.prototype.Vertex_Definitions = function (shaderPart) {
  4663. this.CustomParts.Vertex_Definitions = shaderPart;
  4664. return this;
  4665. };
  4666. CustomMaterial.prototype.Vertex_MainBegin = function (shaderPart) {
  4667. this.CustomParts.Vertex_MainBegin = shaderPart;
  4668. return this;
  4669. };
  4670. CustomMaterial.prototype.Vertex_Before_PositionUpdated = function (shaderPart) {
  4671. this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace("result", "positionUpdated");
  4672. return this;
  4673. };
  4674. CustomMaterial.prototype.Vertex_Before_NormalUpdated = function (shaderPart) {
  4675. this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace("result", "normalUpdated");
  4676. return this;
  4677. };
  4678. CustomMaterial.ShaderIndexer = 1;
  4679. return CustomMaterial;
  4680. }(BABYLON.StandardMaterial));
  4681. BABYLON.CustomMaterial = CustomMaterial;
  4682. })(BABYLON || (BABYLON = {}));
  4683. //# sourceMappingURL=babylon.customMaterial.js.map
  4684. var BABYLON;
  4685. (function (BABYLON) {
  4686. var CellMaterialDefines = /** @class */ (function (_super) {
  4687. __extends(CellMaterialDefines, _super);
  4688. function CellMaterialDefines() {
  4689. var _this = _super.call(this) || this;
  4690. _this.DIFFUSE = false;
  4691. _this.CLIPPLANE = false;
  4692. _this.CLIPPLANE2 = false;
  4693. _this.CLIPPLANE3 = false;
  4694. _this.CLIPPLANE4 = false;
  4695. _this.ALPHATEST = false;
  4696. _this.POINTSIZE = false;
  4697. _this.FOG = false;
  4698. _this.NORMAL = false;
  4699. _this.UV1 = false;
  4700. _this.UV2 = false;
  4701. _this.VERTEXCOLOR = false;
  4702. _this.VERTEXALPHA = false;
  4703. _this.NUM_BONE_INFLUENCERS = 0;
  4704. _this.BonesPerMesh = 0;
  4705. _this.INSTANCES = false;
  4706. _this.NDOTL = true;
  4707. _this.CUSTOMUSERLIGHTING = true;
  4708. _this.CELLBASIC = true;
  4709. _this.DEPTHPREPASS = false;
  4710. _this.rebuild();
  4711. return _this;
  4712. }
  4713. return CellMaterialDefines;
  4714. }(BABYLON.MaterialDefines));
  4715. var CellMaterial = /** @class */ (function (_super) {
  4716. __extends(CellMaterial, _super);
  4717. function CellMaterial(name, scene) {
  4718. var _this = _super.call(this, name, scene) || this;
  4719. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  4720. _this._computeHighLevel = false;
  4721. _this._disableLighting = false;
  4722. _this._maxSimultaneousLights = 4;
  4723. return _this;
  4724. }
  4725. CellMaterial.prototype.needAlphaBlending = function () {
  4726. return (this.alpha < 1.0);
  4727. };
  4728. CellMaterial.prototype.needAlphaTesting = function () {
  4729. return false;
  4730. };
  4731. CellMaterial.prototype.getAlphaTestTexture = function () {
  4732. return null;
  4733. };
  4734. // Methods
  4735. CellMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  4736. if (this.isFrozen) {
  4737. if (this._wasPreviouslyReady && subMesh.effect) {
  4738. return true;
  4739. }
  4740. }
  4741. if (!subMesh._materialDefines) {
  4742. subMesh._materialDefines = new CellMaterialDefines();
  4743. }
  4744. var defines = subMesh._materialDefines;
  4745. var scene = this.getScene();
  4746. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  4747. if (this._renderId === scene.getRenderId()) {
  4748. return true;
  4749. }
  4750. }
  4751. var engine = scene.getEngine();
  4752. // Textures
  4753. if (defines._areTexturesDirty) {
  4754. defines._needUVs = false;
  4755. if (scene.texturesEnabled) {
  4756. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  4757. if (!this._diffuseTexture.isReady()) {
  4758. return false;
  4759. }
  4760. else {
  4761. defines._needUVs = true;
  4762. defines.DIFFUSE = true;
  4763. }
  4764. }
  4765. }
  4766. }
  4767. // High level
  4768. defines.CELLBASIC = !this.computeHighLevel;
  4769. // Misc.
  4770. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  4771. // Lights
  4772. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  4773. // Values that need to be evaluated on every frame
  4774. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  4775. // Attribs
  4776. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  4777. // Get correct effect
  4778. if (defines.isDirty) {
  4779. defines.markAsProcessed();
  4780. scene.resetCachedMaterial();
  4781. // Fallbacks
  4782. var fallbacks = new BABYLON.EffectFallbacks();
  4783. if (defines.FOG) {
  4784. fallbacks.addFallback(1, "FOG");
  4785. }
  4786. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  4787. if (defines.NUM_BONE_INFLUENCERS > 0) {
  4788. fallbacks.addCPUSkinningFallback(0, mesh);
  4789. }
  4790. //Attributes
  4791. var attribs = [BABYLON.VertexBuffer.PositionKind];
  4792. if (defines.NORMAL) {
  4793. attribs.push(BABYLON.VertexBuffer.NormalKind);
  4794. }
  4795. if (defines.UV1) {
  4796. attribs.push(BABYLON.VertexBuffer.UVKind);
  4797. }
  4798. if (defines.UV2) {
  4799. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  4800. }
  4801. if (defines.VERTEXCOLOR) {
  4802. attribs.push(BABYLON.VertexBuffer.ColorKind);
  4803. }
  4804. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  4805. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  4806. var shaderName = "cell";
  4807. var join = defines.toString();
  4808. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  4809. "vFogInfos", "vFogColor", "pointSize",
  4810. "vDiffuseInfos",
  4811. "mBones",
  4812. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix"
  4813. ];
  4814. var samplers = ["diffuseSampler"];
  4815. var uniformBuffers = new Array();
  4816. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  4817. uniformsNames: uniforms,
  4818. uniformBuffersNames: uniformBuffers,
  4819. samplers: samplers,
  4820. defines: defines,
  4821. maxSimultaneousLights: this.maxSimultaneousLights
  4822. });
  4823. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  4824. attributes: attribs,
  4825. uniformsNames: uniforms,
  4826. uniformBuffersNames: uniformBuffers,
  4827. samplers: samplers,
  4828. defines: join,
  4829. fallbacks: fallbacks,
  4830. onCompiled: this.onCompiled,
  4831. onError: this.onError,
  4832. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights - 1 }
  4833. }, engine), defines);
  4834. }
  4835. if (!subMesh.effect || !subMesh.effect.isReady()) {
  4836. return false;
  4837. }
  4838. this._renderId = scene.getRenderId();
  4839. this._wasPreviouslyReady = true;
  4840. return true;
  4841. };
  4842. CellMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  4843. var scene = this.getScene();
  4844. var defines = subMesh._materialDefines;
  4845. if (!defines) {
  4846. return;
  4847. }
  4848. var effect = subMesh.effect;
  4849. if (!effect) {
  4850. return;
  4851. }
  4852. this._activeEffect = effect;
  4853. // Matrices
  4854. this.bindOnlyWorldMatrix(world);
  4855. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  4856. // Bones
  4857. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  4858. if (this._mustRebind(scene, effect)) {
  4859. // Textures
  4860. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  4861. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  4862. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  4863. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  4864. }
  4865. // Clip plane
  4866. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  4867. // Point size
  4868. if (this.pointsCloud) {
  4869. this._activeEffect.setFloat("pointSize", this.pointSize);
  4870. }
  4871. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  4872. }
  4873. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  4874. // Lights
  4875. if (scene.lightsEnabled && !this.disableLighting) {
  4876. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this._maxSimultaneousLights);
  4877. }
  4878. // View
  4879. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  4880. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  4881. }
  4882. // Fog
  4883. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  4884. this._afterBind(mesh, this._activeEffect);
  4885. };
  4886. CellMaterial.prototype.getAnimatables = function () {
  4887. var results = [];
  4888. if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
  4889. results.push(this._diffuseTexture);
  4890. }
  4891. return results;
  4892. };
  4893. CellMaterial.prototype.getActiveTextures = function () {
  4894. var activeTextures = _super.prototype.getActiveTextures.call(this);
  4895. if (this._diffuseTexture) {
  4896. activeTextures.push(this._diffuseTexture);
  4897. }
  4898. return activeTextures;
  4899. };
  4900. CellMaterial.prototype.hasTexture = function (texture) {
  4901. if (_super.prototype.hasTexture.call(this, texture)) {
  4902. return true;
  4903. }
  4904. return this._diffuseTexture === texture;
  4905. };
  4906. CellMaterial.prototype.dispose = function (forceDisposeEffect) {
  4907. if (this._diffuseTexture) {
  4908. this._diffuseTexture.dispose();
  4909. }
  4910. _super.prototype.dispose.call(this, forceDisposeEffect);
  4911. };
  4912. CellMaterial.prototype.getClassName = function () {
  4913. return "CellMaterial";
  4914. };
  4915. CellMaterial.prototype.clone = function (name) {
  4916. var _this = this;
  4917. return BABYLON.SerializationHelper.Clone(function () { return new CellMaterial(name, _this.getScene()); }, this);
  4918. };
  4919. CellMaterial.prototype.serialize = function () {
  4920. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  4921. serializationObject.customType = "BABYLON.CellMaterial";
  4922. return serializationObject;
  4923. };
  4924. // Statics
  4925. CellMaterial.Parse = function (source, scene, rootUrl) {
  4926. return BABYLON.SerializationHelper.Parse(function () { return new CellMaterial(source.name, scene); }, source, scene, rootUrl);
  4927. };
  4928. __decorate([
  4929. BABYLON.serializeAsTexture("diffuseTexture")
  4930. ], CellMaterial.prototype, "_diffuseTexture", void 0);
  4931. __decorate([
  4932. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4933. ], CellMaterial.prototype, "diffuseTexture", void 0);
  4934. __decorate([
  4935. BABYLON.serializeAsColor3("diffuse")
  4936. ], CellMaterial.prototype, "diffuseColor", void 0);
  4937. __decorate([
  4938. BABYLON.serialize("computeHighLevel")
  4939. ], CellMaterial.prototype, "_computeHighLevel", void 0);
  4940. __decorate([
  4941. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4942. ], CellMaterial.prototype, "computeHighLevel", void 0);
  4943. __decorate([
  4944. BABYLON.serialize("disableLighting")
  4945. ], CellMaterial.prototype, "_disableLighting", void 0);
  4946. __decorate([
  4947. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  4948. ], CellMaterial.prototype, "disableLighting", void 0);
  4949. __decorate([
  4950. BABYLON.serialize("maxSimultaneousLights")
  4951. ], CellMaterial.prototype, "_maxSimultaneousLights", void 0);
  4952. __decorate([
  4953. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  4954. ], CellMaterial.prototype, "maxSimultaneousLights", void 0);
  4955. return CellMaterial;
  4956. }(BABYLON.PushMaterial));
  4957. BABYLON.CellMaterial = CellMaterial;
  4958. })(BABYLON || (BABYLON = {}));
  4959. //# sourceMappingURL=babylon.cellMaterial.js.map
  4960. BABYLON.Effect.ShadersStore['cellVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\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<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,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 DIFFUSE\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<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  4961. BABYLON.Effect.ShadersStore['cellPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\n\nvec3 computeCustomDiffuseLighting(lightingInfo info,vec3 diffuseBase,float shadow)\n{\ndiffuseBase=info.diffuse*shadow;\n#ifdef CELLBASIC\nfloat level=1.0;\nif (info.ndl<0.5)\nlevel=0.5;\ndiffuseBase.rgb*vec3(level,level,level);\n#else\nfloat ToonThresholds[4];\nToonThresholds[0]=0.95;\nToonThresholds[1]=0.5;\nToonThresholds[2]=0.2;\nToonThresholds[3]=0.03;\nfloat ToonBrightnessLevels[5];\nToonBrightnessLevels[0]=1.0;\nToonBrightnessLevels[1]=0.8;\nToonBrightnessLevels[2]=0.6;\nToonBrightnessLevels[3]=0.35;\nToonBrightnessLevels[4]=0.2;\nif (info.ndl>ToonThresholds[0])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[0];\n}\nelse if (info.ndl>ToonThresholds[1])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[1];\n}\nelse if (info.ndl>ToonThresholds[2])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[2];\n}\nelse if (info.ndl>ToonThresholds[3])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[3];\n}\nelse\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[4];\n}\n#endif\nreturn max(diffuseBase,vec3(0.2));\n}\nvoid main(void)\n{\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nlightingInfo info;\nvec3 diffuseBase=vec3(0.,0.,0.);\nfloat shadow=1.;\nfloat glossiness=0.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif \n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
  4962. return BABYLON;
  4963. });