babylonjs.materials.js 283 KB

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