babylonjs.materials.js 285 KB

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