babylonjs.materials.js 282 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022
  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. };
  1877. this._refractionRTT.onAfterRender = function () {
  1878. if (_this._mesh) {
  1879. _this._mesh.isVisible = isVisible;
  1880. }
  1881. };
  1882. this._reflectionRTT.onBeforeRender = function () {
  1883. if (_this._mesh) {
  1884. isVisible = _this._mesh.isVisible;
  1885. _this._mesh.isVisible = false;
  1886. }
  1887. // Clip plane
  1888. clipPlane = scene.clipPlane;
  1889. var positiony = _this._mesh ? _this._mesh.position.y : 0.0;
  1890. scene.clipPlane = BABYLON.Plane.FromPositionAndNormal(new BABYLON.Vector3(0, positiony - 0.05, 0), new BABYLON.Vector3(0, -1, 0));
  1891. // Transform
  1892. BABYLON.Matrix.ReflectionToRef(scene.clipPlane, mirrorMatrix);
  1893. savedViewMatrix = scene.getViewMatrix();
  1894. mirrorMatrix.multiplyToRef(savedViewMatrix, _this._reflectionTransform);
  1895. scene.setTransformMatrix(_this._reflectionTransform, scene.getProjectionMatrix());
  1896. scene.getEngine().cullBackFaces = false;
  1897. scene._mirroredCameraPosition = BABYLON.Vector3.TransformCoordinates(scene.activeCamera.position, mirrorMatrix);
  1898. };
  1899. this._reflectionRTT.onAfterRender = function () {
  1900. if (_this._mesh) {
  1901. _this._mesh.isVisible = isVisible;
  1902. }
  1903. // Clip plane
  1904. scene.clipPlane = clipPlane;
  1905. // Transform
  1906. scene.setTransformMatrix(savedViewMatrix, scene.getProjectionMatrix());
  1907. scene.getEngine().cullBackFaces = true;
  1908. scene._mirroredCameraPosition = null;
  1909. };
  1910. };
  1911. WaterMaterial.prototype.getAnimatables = function () {
  1912. var results = [];
  1913. if (this.bumpTexture && this.bumpTexture.animations && this.bumpTexture.animations.length > 0) {
  1914. results.push(this.bumpTexture);
  1915. }
  1916. if (this._reflectionRTT && this._reflectionRTT.animations && this._reflectionRTT.animations.length > 0) {
  1917. results.push(this._reflectionRTT);
  1918. }
  1919. if (this._refractionRTT && this._refractionRTT.animations && this._refractionRTT.animations.length > 0) {
  1920. results.push(this._refractionRTT);
  1921. }
  1922. return results;
  1923. };
  1924. WaterMaterial.prototype.getActiveTextures = function () {
  1925. var activeTextures = _super.prototype.getActiveTextures.call(this);
  1926. if (this._bumpTexture) {
  1927. activeTextures.push(this._bumpTexture);
  1928. }
  1929. return activeTextures;
  1930. };
  1931. WaterMaterial.prototype.hasTexture = function (texture) {
  1932. if (_super.prototype.hasTexture.call(this, texture)) {
  1933. return true;
  1934. }
  1935. if (this._bumpTexture === texture) {
  1936. return true;
  1937. }
  1938. return false;
  1939. };
  1940. WaterMaterial.prototype.dispose = function (forceDisposeEffect) {
  1941. if (this.bumpTexture) {
  1942. this.bumpTexture.dispose();
  1943. }
  1944. var index = this.getScene().customRenderTargets.indexOf(this._refractionRTT);
  1945. if (index != -1) {
  1946. this.getScene().customRenderTargets.splice(index, 1);
  1947. }
  1948. index = -1;
  1949. index = this.getScene().customRenderTargets.indexOf(this._reflectionRTT);
  1950. if (index != -1) {
  1951. this.getScene().customRenderTargets.splice(index, 1);
  1952. }
  1953. if (this._reflectionRTT) {
  1954. this._reflectionRTT.dispose();
  1955. }
  1956. if (this._refractionRTT) {
  1957. this._refractionRTT.dispose();
  1958. }
  1959. _super.prototype.dispose.call(this, forceDisposeEffect);
  1960. };
  1961. WaterMaterial.prototype.clone = function (name) {
  1962. var _this = this;
  1963. return BABYLON.SerializationHelper.Clone(function () { return new WaterMaterial(name, _this.getScene()); }, this);
  1964. };
  1965. WaterMaterial.prototype.serialize = function () {
  1966. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  1967. serializationObject.customType = "BABYLON.WaterMaterial";
  1968. serializationObject.renderList = [];
  1969. if (this._refractionRTT && this._refractionRTT.renderList) {
  1970. for (var i = 0; i < this._refractionRTT.renderList.length; i++) {
  1971. serializationObject.renderList.push(this._refractionRTT.renderList[i].id);
  1972. }
  1973. }
  1974. return serializationObject;
  1975. };
  1976. WaterMaterial.prototype.getClassName = function () {
  1977. return "WaterMaterial";
  1978. };
  1979. // Statics
  1980. WaterMaterial.Parse = function (source, scene, rootUrl) {
  1981. var mat = BABYLON.SerializationHelper.Parse(function () { return new WaterMaterial(source.name, scene); }, source, scene, rootUrl);
  1982. mat._waitingRenderList = source.renderList;
  1983. return mat;
  1984. };
  1985. WaterMaterial.CreateDefaultMesh = function (name, scene) {
  1986. var mesh = BABYLON.Mesh.CreateGround(name, 512, 512, 32, scene, false);
  1987. return mesh;
  1988. };
  1989. __decorate([
  1990. BABYLON.serializeAsTexture("bumpTexture")
  1991. ], WaterMaterial.prototype, "_bumpTexture", void 0);
  1992. __decorate([
  1993. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1994. ], WaterMaterial.prototype, "bumpTexture", void 0);
  1995. __decorate([
  1996. BABYLON.serializeAsColor3()
  1997. ], WaterMaterial.prototype, "diffuseColor", void 0);
  1998. __decorate([
  1999. BABYLON.serializeAsColor3()
  2000. ], WaterMaterial.prototype, "specularColor", void 0);
  2001. __decorate([
  2002. BABYLON.serialize()
  2003. ], WaterMaterial.prototype, "specularPower", void 0);
  2004. __decorate([
  2005. BABYLON.serialize("disableLighting")
  2006. ], WaterMaterial.prototype, "_disableLighting", void 0);
  2007. __decorate([
  2008. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  2009. ], WaterMaterial.prototype, "disableLighting", void 0);
  2010. __decorate([
  2011. BABYLON.serialize("maxSimultaneousLights")
  2012. ], WaterMaterial.prototype, "_maxSimultaneousLights", void 0);
  2013. __decorate([
  2014. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  2015. ], WaterMaterial.prototype, "maxSimultaneousLights", void 0);
  2016. __decorate([
  2017. BABYLON.serialize()
  2018. ], WaterMaterial.prototype, "windForce", void 0);
  2019. __decorate([
  2020. BABYLON.serializeAsVector2()
  2021. ], WaterMaterial.prototype, "windDirection", void 0);
  2022. __decorate([
  2023. BABYLON.serialize()
  2024. ], WaterMaterial.prototype, "waveHeight", void 0);
  2025. __decorate([
  2026. BABYLON.serialize()
  2027. ], WaterMaterial.prototype, "bumpHeight", void 0);
  2028. __decorate([
  2029. BABYLON.serialize("bumpSuperimpose")
  2030. ], WaterMaterial.prototype, "_bumpSuperimpose", void 0);
  2031. __decorate([
  2032. BABYLON.expandToProperty("_markAllSubMeshesAsMiscDirty")
  2033. ], WaterMaterial.prototype, "bumpSuperimpose", void 0);
  2034. __decorate([
  2035. BABYLON.serialize("fresnelSeparate")
  2036. ], WaterMaterial.prototype, "_fresnelSeparate", void 0);
  2037. __decorate([
  2038. BABYLON.expandToProperty("_markAllSubMeshesAsMiscDirty")
  2039. ], WaterMaterial.prototype, "fresnelSeparate", void 0);
  2040. __decorate([
  2041. BABYLON.serialize("bumpAffectsReflection")
  2042. ], WaterMaterial.prototype, "_bumpAffectsReflection", void 0);
  2043. __decorate([
  2044. BABYLON.expandToProperty("_markAllSubMeshesAsMiscDirty")
  2045. ], WaterMaterial.prototype, "bumpAffectsReflection", void 0);
  2046. __decorate([
  2047. BABYLON.serializeAsColor3()
  2048. ], WaterMaterial.prototype, "waterColor", void 0);
  2049. __decorate([
  2050. BABYLON.serialize()
  2051. ], WaterMaterial.prototype, "colorBlendFactor", void 0);
  2052. __decorate([
  2053. BABYLON.serializeAsColor3()
  2054. ], WaterMaterial.prototype, "waterColor2", void 0);
  2055. __decorate([
  2056. BABYLON.serialize()
  2057. ], WaterMaterial.prototype, "colorBlendFactor2", void 0);
  2058. __decorate([
  2059. BABYLON.serialize()
  2060. ], WaterMaterial.prototype, "waveLength", void 0);
  2061. __decorate([
  2062. BABYLON.serialize()
  2063. ], WaterMaterial.prototype, "waveSpeed", void 0);
  2064. __decorate([
  2065. BABYLON.serialize()
  2066. ], WaterMaterial.prototype, "useLogarithmicDepth", null);
  2067. return WaterMaterial;
  2068. }(BABYLON.PushMaterial));
  2069. BABYLON.WaterMaterial = WaterMaterial;
  2070. })(BABYLON || (BABYLON = {}));
  2071. //# sourceMappingURL=babylon.waterMaterial.js.map
  2072. 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";
  2073. 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";
  2074. var BABYLON;
  2075. (function (BABYLON) {
  2076. var FireMaterialDefines = /** @class */ (function (_super) {
  2077. __extends(FireMaterialDefines, _super);
  2078. function FireMaterialDefines() {
  2079. var _this = _super.call(this) || this;
  2080. _this.DIFFUSE = false;
  2081. _this.CLIPPLANE = false;
  2082. _this.CLIPPLANE2 = false;
  2083. _this.CLIPPLANE3 = false;
  2084. _this.CLIPPLANE4 = false;
  2085. _this.ALPHATEST = false;
  2086. _this.DEPTHPREPASS = false;
  2087. _this.POINTSIZE = false;
  2088. _this.FOG = false;
  2089. _this.UV1 = false;
  2090. _this.VERTEXCOLOR = false;
  2091. _this.VERTEXALPHA = false;
  2092. _this.BonesPerMesh = 0;
  2093. _this.NUM_BONE_INFLUENCERS = 0;
  2094. _this.INSTANCES = false;
  2095. _this.rebuild();
  2096. return _this;
  2097. }
  2098. return FireMaterialDefines;
  2099. }(BABYLON.MaterialDefines));
  2100. var FireMaterial = /** @class */ (function (_super) {
  2101. __extends(FireMaterial, _super);
  2102. function FireMaterial(name, scene) {
  2103. var _this = _super.call(this, name, scene) || this;
  2104. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  2105. _this.speed = 1.0;
  2106. _this._scaledDiffuse = new BABYLON.Color3();
  2107. _this._lastTime = 0;
  2108. return _this;
  2109. }
  2110. FireMaterial.prototype.needAlphaBlending = function () {
  2111. return false;
  2112. };
  2113. FireMaterial.prototype.needAlphaTesting = function () {
  2114. return true;
  2115. };
  2116. FireMaterial.prototype.getAlphaTestTexture = function () {
  2117. return null;
  2118. };
  2119. // Methods
  2120. FireMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  2121. if (this.isFrozen) {
  2122. if (this._wasPreviouslyReady && subMesh.effect) {
  2123. return true;
  2124. }
  2125. }
  2126. if (!subMesh._materialDefines) {
  2127. subMesh._materialDefines = new FireMaterialDefines();
  2128. }
  2129. var defines = subMesh._materialDefines;
  2130. var scene = this.getScene();
  2131. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  2132. if (this._renderId === scene.getRenderId()) {
  2133. return true;
  2134. }
  2135. }
  2136. var engine = scene.getEngine();
  2137. // Textures
  2138. if (defines._areTexturesDirty) {
  2139. defines._needUVs = false;
  2140. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2141. if (!this._diffuseTexture.isReady()) {
  2142. return false;
  2143. }
  2144. else {
  2145. defines._needUVs = true;
  2146. defines.DIFFUSE = true;
  2147. }
  2148. }
  2149. }
  2150. defines.ALPHATEST = this._opacityTexture ? true : false;
  2151. // Misc.
  2152. if (defines._areMiscDirty) {
  2153. defines.POINTSIZE = (this.pointsCloud || scene.forcePointsCloud);
  2154. defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled);
  2155. }
  2156. // Values that need to be evaluated on every frame
  2157. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  2158. // Attribs
  2159. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
  2160. // Get correct effect
  2161. if (defines.isDirty) {
  2162. defines.markAsProcessed();
  2163. scene.resetCachedMaterial();
  2164. // Fallbacks
  2165. var fallbacks = new BABYLON.EffectFallbacks();
  2166. if (defines.FOG) {
  2167. fallbacks.addFallback(1, "FOG");
  2168. }
  2169. if (defines.NUM_BONE_INFLUENCERS > 0) {
  2170. fallbacks.addCPUSkinningFallback(0, mesh);
  2171. }
  2172. //Attributes
  2173. var attribs = [BABYLON.VertexBuffer.PositionKind];
  2174. if (defines.UV1) {
  2175. attribs.push(BABYLON.VertexBuffer.UVKind);
  2176. }
  2177. if (defines.VERTEXCOLOR) {
  2178. attribs.push(BABYLON.VertexBuffer.ColorKind);
  2179. }
  2180. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  2181. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  2182. // Legacy browser patch
  2183. var shaderName = "fire";
  2184. var join = defines.toString();
  2185. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  2186. attributes: attribs,
  2187. uniformsNames: ["world", "view", "viewProjection", "vEyePosition",
  2188. "vFogInfos", "vFogColor", "pointSize",
  2189. "vDiffuseInfos",
  2190. "mBones",
  2191. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix",
  2192. // Fire
  2193. "time", "speed"
  2194. ],
  2195. uniformBuffersNames: [],
  2196. samplers: ["diffuseSampler",
  2197. // Fire
  2198. "distortionSampler", "opacitySampler"
  2199. ],
  2200. defines: join,
  2201. fallbacks: fallbacks,
  2202. onCompiled: this.onCompiled,
  2203. onError: this.onError,
  2204. indexParameters: null,
  2205. maxSimultaneousLights: 4,
  2206. transformFeedbackVaryings: null
  2207. }, engine), defines);
  2208. }
  2209. if (!subMesh.effect || !subMesh.effect.isReady()) {
  2210. return false;
  2211. }
  2212. this._renderId = scene.getRenderId();
  2213. this._wasPreviouslyReady = true;
  2214. return true;
  2215. };
  2216. FireMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  2217. var scene = this.getScene();
  2218. var defines = subMesh._materialDefines;
  2219. if (!defines) {
  2220. return;
  2221. }
  2222. var effect = subMesh.effect;
  2223. if (!effect) {
  2224. return;
  2225. }
  2226. this._activeEffect = effect;
  2227. // Matrices
  2228. this.bindOnlyWorldMatrix(world);
  2229. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  2230. // Bones
  2231. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  2232. if (this._mustRebind(scene, effect)) {
  2233. // Textures
  2234. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2235. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  2236. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  2237. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  2238. this._activeEffect.setTexture("distortionSampler", this._distortionTexture);
  2239. this._activeEffect.setTexture("opacitySampler", this._opacityTexture);
  2240. }
  2241. // Clip plane
  2242. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  2243. // Point size
  2244. if (this.pointsCloud) {
  2245. this._activeEffect.setFloat("pointSize", this.pointSize);
  2246. }
  2247. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  2248. }
  2249. this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  2250. // View
  2251. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  2252. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  2253. }
  2254. // Fog
  2255. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  2256. // Time
  2257. this._lastTime += scene.getEngine().getDeltaTime();
  2258. this._activeEffect.setFloat("time", this._lastTime);
  2259. // Speed
  2260. this._activeEffect.setFloat("speed", this.speed);
  2261. this._afterBind(mesh, this._activeEffect);
  2262. };
  2263. FireMaterial.prototype.getAnimatables = function () {
  2264. var results = [];
  2265. if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
  2266. results.push(this._diffuseTexture);
  2267. }
  2268. if (this._distortionTexture && this._distortionTexture.animations && this._distortionTexture.animations.length > 0) {
  2269. results.push(this._distortionTexture);
  2270. }
  2271. if (this._opacityTexture && this._opacityTexture.animations && this._opacityTexture.animations.length > 0) {
  2272. results.push(this._opacityTexture);
  2273. }
  2274. return results;
  2275. };
  2276. FireMaterial.prototype.getActiveTextures = function () {
  2277. var activeTextures = _super.prototype.getActiveTextures.call(this);
  2278. if (this._diffuseTexture) {
  2279. activeTextures.push(this._diffuseTexture);
  2280. }
  2281. if (this._distortionTexture) {
  2282. activeTextures.push(this._distortionTexture);
  2283. }
  2284. if (this._opacityTexture) {
  2285. activeTextures.push(this._opacityTexture);
  2286. }
  2287. return activeTextures;
  2288. };
  2289. FireMaterial.prototype.hasTexture = function (texture) {
  2290. if (_super.prototype.hasTexture.call(this, texture)) {
  2291. return true;
  2292. }
  2293. if (this._diffuseTexture === texture) {
  2294. return true;
  2295. }
  2296. if (this._distortionTexture === texture) {
  2297. return true;
  2298. }
  2299. if (this._opacityTexture === texture) {
  2300. return true;
  2301. }
  2302. return false;
  2303. };
  2304. FireMaterial.prototype.getClassName = function () {
  2305. return "FireMaterial";
  2306. };
  2307. FireMaterial.prototype.dispose = function (forceDisposeEffect) {
  2308. if (this._diffuseTexture) {
  2309. this._diffuseTexture.dispose();
  2310. }
  2311. if (this._distortionTexture) {
  2312. this._distortionTexture.dispose();
  2313. }
  2314. _super.prototype.dispose.call(this, forceDisposeEffect);
  2315. };
  2316. FireMaterial.prototype.clone = function (name) {
  2317. var _this = this;
  2318. return BABYLON.SerializationHelper.Clone(function () { return new FireMaterial(name, _this.getScene()); }, this);
  2319. };
  2320. FireMaterial.prototype.serialize = function () {
  2321. var serializationObject = _super.prototype.serialize.call(this);
  2322. serializationObject.customType = "BABYLON.FireMaterial";
  2323. serializationObject.diffuseColor = this.diffuseColor.asArray();
  2324. serializationObject.speed = this.speed;
  2325. if (this._diffuseTexture) {
  2326. serializationObject._diffuseTexture = this._diffuseTexture.serialize();
  2327. }
  2328. if (this._distortionTexture) {
  2329. serializationObject._distortionTexture = this._distortionTexture.serialize();
  2330. }
  2331. if (this._opacityTexture) {
  2332. serializationObject._opacityTexture = this._opacityTexture.serialize();
  2333. }
  2334. return serializationObject;
  2335. };
  2336. FireMaterial.Parse = function (source, scene, rootUrl) {
  2337. var material = new FireMaterial(source.name, scene);
  2338. material.diffuseColor = BABYLON.Color3.FromArray(source.diffuseColor);
  2339. material.speed = source.speed;
  2340. material.alpha = source.alpha;
  2341. material.id = source.id;
  2342. BABYLON.Tags.AddTagsTo(material, source.tags);
  2343. material.backFaceCulling = source.backFaceCulling;
  2344. material.wireframe = source.wireframe;
  2345. if (source._diffuseTexture) {
  2346. material._diffuseTexture = BABYLON.Texture.Parse(source._diffuseTexture, scene, rootUrl);
  2347. }
  2348. if (source._distortionTexture) {
  2349. material._distortionTexture = BABYLON.Texture.Parse(source._distortionTexture, scene, rootUrl);
  2350. }
  2351. if (source._opacityTexture) {
  2352. material._opacityTexture = BABYLON.Texture.Parse(source._opacityTexture, scene, rootUrl);
  2353. }
  2354. if (source.checkReadyOnlyOnce) {
  2355. material.checkReadyOnlyOnce = source.checkReadyOnlyOnce;
  2356. }
  2357. return material;
  2358. };
  2359. __decorate([
  2360. BABYLON.serializeAsTexture("diffuseTexture")
  2361. ], FireMaterial.prototype, "_diffuseTexture", void 0);
  2362. __decorate([
  2363. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2364. ], FireMaterial.prototype, "diffuseTexture", void 0);
  2365. __decorate([
  2366. BABYLON.serializeAsTexture("distortionTexture")
  2367. ], FireMaterial.prototype, "_distortionTexture", void 0);
  2368. __decorate([
  2369. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2370. ], FireMaterial.prototype, "distortionTexture", void 0);
  2371. __decorate([
  2372. BABYLON.serializeAsTexture("opacityTexture")
  2373. ], FireMaterial.prototype, "_opacityTexture", void 0);
  2374. __decorate([
  2375. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2376. ], FireMaterial.prototype, "opacityTexture", void 0);
  2377. __decorate([
  2378. BABYLON.serializeAsColor3("diffuse")
  2379. ], FireMaterial.prototype, "diffuseColor", void 0);
  2380. __decorate([
  2381. BABYLON.serialize()
  2382. ], FireMaterial.prototype, "speed", void 0);
  2383. return FireMaterial;
  2384. }(BABYLON.PushMaterial));
  2385. BABYLON.FireMaterial = FireMaterial;
  2386. })(BABYLON || (BABYLON = {}));
  2387. //# sourceMappingURL=babylon.fireMaterial.js.map
  2388. 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";
  2389. 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}";
  2390. var BABYLON;
  2391. (function (BABYLON) {
  2392. var FurMaterialDefines = /** @class */ (function (_super) {
  2393. __extends(FurMaterialDefines, _super);
  2394. function FurMaterialDefines() {
  2395. var _this = _super.call(this) || this;
  2396. _this.DIFFUSE = false;
  2397. _this.HEIGHTMAP = false;
  2398. _this.CLIPPLANE = false;
  2399. _this.CLIPPLANE2 = false;
  2400. _this.CLIPPLANE3 = false;
  2401. _this.CLIPPLANE4 = false;
  2402. _this.ALPHATEST = false;
  2403. _this.DEPTHPREPASS = false;
  2404. _this.POINTSIZE = false;
  2405. _this.FOG = false;
  2406. _this.NORMAL = false;
  2407. _this.UV1 = false;
  2408. _this.UV2 = false;
  2409. _this.VERTEXCOLOR = false;
  2410. _this.VERTEXALPHA = false;
  2411. _this.NUM_BONE_INFLUENCERS = 0;
  2412. _this.BonesPerMesh = 0;
  2413. _this.INSTANCES = false;
  2414. _this.HIGHLEVEL = false;
  2415. _this.rebuild();
  2416. return _this;
  2417. }
  2418. return FurMaterialDefines;
  2419. }(BABYLON.MaterialDefines));
  2420. var FurMaterial = /** @class */ (function (_super) {
  2421. __extends(FurMaterial, _super);
  2422. function FurMaterial(name, scene) {
  2423. var _this = _super.call(this, name, scene) || this;
  2424. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  2425. _this.furLength = 1;
  2426. _this.furAngle = 0;
  2427. _this.furColor = new BABYLON.Color3(0.44, 0.21, 0.02);
  2428. _this.furOffset = 0.0;
  2429. _this.furSpacing = 12;
  2430. _this.furGravity = new BABYLON.Vector3(0, 0, 0);
  2431. _this.furSpeed = 100;
  2432. _this.furDensity = 20;
  2433. _this.furOcclusion = 0.0;
  2434. _this._disableLighting = false;
  2435. _this._maxSimultaneousLights = 4;
  2436. _this.highLevelFur = true;
  2437. _this._furTime = 0;
  2438. return _this;
  2439. }
  2440. Object.defineProperty(FurMaterial.prototype, "furTime", {
  2441. get: function () {
  2442. return this._furTime;
  2443. },
  2444. set: function (furTime) {
  2445. this._furTime = furTime;
  2446. },
  2447. enumerable: true,
  2448. configurable: true
  2449. });
  2450. FurMaterial.prototype.needAlphaBlending = function () {
  2451. return (this.alpha < 1.0);
  2452. };
  2453. FurMaterial.prototype.needAlphaTesting = function () {
  2454. return false;
  2455. };
  2456. FurMaterial.prototype.getAlphaTestTexture = function () {
  2457. return null;
  2458. };
  2459. FurMaterial.prototype.updateFur = function () {
  2460. for (var i = 1; i < this._meshes.length; i++) {
  2461. var offsetFur = this._meshes[i].material;
  2462. offsetFur.furLength = this.furLength;
  2463. offsetFur.furAngle = this.furAngle;
  2464. offsetFur.furGravity = this.furGravity;
  2465. offsetFur.furSpacing = this.furSpacing;
  2466. offsetFur.furSpeed = this.furSpeed;
  2467. offsetFur.furColor = this.furColor;
  2468. offsetFur.diffuseTexture = this.diffuseTexture;
  2469. offsetFur.furTexture = this.furTexture;
  2470. offsetFur.highLevelFur = this.highLevelFur;
  2471. offsetFur.furTime = this.furTime;
  2472. offsetFur.furDensity = this.furDensity;
  2473. }
  2474. };
  2475. // Methods
  2476. FurMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  2477. if (this.isFrozen) {
  2478. if (this._wasPreviouslyReady && subMesh.effect) {
  2479. return true;
  2480. }
  2481. }
  2482. if (!subMesh._materialDefines) {
  2483. subMesh._materialDefines = new FurMaterialDefines();
  2484. }
  2485. var defines = subMesh._materialDefines;
  2486. var scene = this.getScene();
  2487. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  2488. if (this._renderId === scene.getRenderId()) {
  2489. return true;
  2490. }
  2491. }
  2492. var engine = scene.getEngine();
  2493. // Textures
  2494. if (defines._areTexturesDirty) {
  2495. if (scene.texturesEnabled) {
  2496. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2497. if (!this.diffuseTexture.isReady()) {
  2498. return false;
  2499. }
  2500. else {
  2501. defines._needUVs = true;
  2502. defines.DIFFUSE = true;
  2503. }
  2504. }
  2505. if (this.heightTexture && engine.getCaps().maxVertexTextureImageUnits) {
  2506. if (!this.heightTexture.isReady()) {
  2507. return false;
  2508. }
  2509. else {
  2510. defines._needUVs = true;
  2511. defines.HEIGHTMAP = true;
  2512. }
  2513. }
  2514. }
  2515. }
  2516. // High level
  2517. if (this.highLevelFur !== defines.HIGHLEVEL) {
  2518. defines.HIGHLEVEL = true;
  2519. defines.markAsUnprocessed();
  2520. }
  2521. // Misc.
  2522. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  2523. // Lights
  2524. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  2525. // Values that need to be evaluated on every frame
  2526. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  2527. // Attribs
  2528. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  2529. // Get correct effect
  2530. if (defines.isDirty) {
  2531. defines.markAsProcessed();
  2532. scene.resetCachedMaterial();
  2533. // Fallbacks
  2534. var fallbacks = new BABYLON.EffectFallbacks();
  2535. if (defines.FOG) {
  2536. fallbacks.addFallback(1, "FOG");
  2537. }
  2538. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  2539. if (defines.NUM_BONE_INFLUENCERS > 0) {
  2540. fallbacks.addCPUSkinningFallback(0, mesh);
  2541. }
  2542. //Attributes
  2543. var attribs = [BABYLON.VertexBuffer.PositionKind];
  2544. if (defines.NORMAL) {
  2545. attribs.push(BABYLON.VertexBuffer.NormalKind);
  2546. }
  2547. if (defines.UV1) {
  2548. attribs.push(BABYLON.VertexBuffer.UVKind);
  2549. }
  2550. if (defines.UV2) {
  2551. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  2552. }
  2553. if (defines.VERTEXCOLOR) {
  2554. attribs.push(BABYLON.VertexBuffer.ColorKind);
  2555. }
  2556. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  2557. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  2558. // Legacy browser patch
  2559. var shaderName = "fur";
  2560. var join = defines.toString();
  2561. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  2562. "vFogInfos", "vFogColor", "pointSize",
  2563. "vDiffuseInfos",
  2564. "mBones",
  2565. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix",
  2566. "furLength", "furAngle", "furColor", "furOffset", "furGravity", "furTime", "furSpacing", "furDensity", "furOcclusion"
  2567. ];
  2568. var samplers = ["diffuseSampler",
  2569. "heightTexture", "furTexture"
  2570. ];
  2571. var uniformBuffers = new Array();
  2572. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  2573. uniformsNames: uniforms,
  2574. uniformBuffersNames: uniformBuffers,
  2575. samplers: samplers,
  2576. defines: defines,
  2577. maxSimultaneousLights: this.maxSimultaneousLights
  2578. });
  2579. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  2580. attributes: attribs,
  2581. uniformsNames: uniforms,
  2582. uniformBuffersNames: uniformBuffers,
  2583. samplers: samplers,
  2584. defines: join,
  2585. fallbacks: fallbacks,
  2586. onCompiled: this.onCompiled,
  2587. onError: this.onError,
  2588. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  2589. }, engine), defines);
  2590. }
  2591. if (!subMesh.effect || !subMesh.effect.isReady()) {
  2592. return false;
  2593. }
  2594. this._renderId = scene.getRenderId();
  2595. this._wasPreviouslyReady = true;
  2596. return true;
  2597. };
  2598. FurMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  2599. var scene = this.getScene();
  2600. var defines = subMesh._materialDefines;
  2601. if (!defines) {
  2602. return;
  2603. }
  2604. var effect = subMesh.effect;
  2605. if (!effect) {
  2606. return;
  2607. }
  2608. this._activeEffect = effect;
  2609. // Matrices
  2610. this.bindOnlyWorldMatrix(world);
  2611. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  2612. // Bones
  2613. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  2614. if (scene.getCachedMaterial() !== this) {
  2615. // Textures
  2616. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2617. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  2618. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  2619. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  2620. }
  2621. if (this._heightTexture) {
  2622. this._activeEffect.setTexture("heightTexture", this._heightTexture);
  2623. }
  2624. // Clip plane
  2625. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  2626. // Point size
  2627. if (this.pointsCloud) {
  2628. this._activeEffect.setFloat("pointSize", this.pointSize);
  2629. }
  2630. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  2631. }
  2632. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  2633. if (scene.lightsEnabled && !this.disableLighting) {
  2634. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  2635. }
  2636. // View
  2637. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  2638. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  2639. }
  2640. // Fog
  2641. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  2642. this._activeEffect.setFloat("furLength", this.furLength);
  2643. this._activeEffect.setFloat("furAngle", this.furAngle);
  2644. this._activeEffect.setColor4("furColor", this.furColor, 1.0);
  2645. if (this.highLevelFur) {
  2646. this._activeEffect.setVector3("furGravity", this.furGravity);
  2647. this._activeEffect.setFloat("furOffset", this.furOffset);
  2648. this._activeEffect.setFloat("furSpacing", this.furSpacing);
  2649. this._activeEffect.setFloat("furDensity", this.furDensity);
  2650. this._activeEffect.setFloat("furOcclusion", this.furOcclusion);
  2651. this._furTime += this.getScene().getEngine().getDeltaTime() / this.furSpeed;
  2652. this._activeEffect.setFloat("furTime", this._furTime);
  2653. this._activeEffect.setTexture("furTexture", this.furTexture);
  2654. }
  2655. this._afterBind(mesh, this._activeEffect);
  2656. };
  2657. FurMaterial.prototype.getAnimatables = function () {
  2658. var results = [];
  2659. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  2660. results.push(this.diffuseTexture);
  2661. }
  2662. if (this.heightTexture && this.heightTexture.animations && this.heightTexture.animations.length > 0) {
  2663. results.push(this.heightTexture);
  2664. }
  2665. return results;
  2666. };
  2667. FurMaterial.prototype.getActiveTextures = function () {
  2668. var activeTextures = _super.prototype.getActiveTextures.call(this);
  2669. if (this._diffuseTexture) {
  2670. activeTextures.push(this._diffuseTexture);
  2671. }
  2672. if (this._heightTexture) {
  2673. activeTextures.push(this._heightTexture);
  2674. }
  2675. return activeTextures;
  2676. };
  2677. FurMaterial.prototype.hasTexture = function (texture) {
  2678. if (_super.prototype.hasTexture.call(this, texture)) {
  2679. return true;
  2680. }
  2681. if (this.diffuseTexture === texture) {
  2682. return true;
  2683. }
  2684. if (this._heightTexture === texture) {
  2685. return true;
  2686. }
  2687. return false;
  2688. };
  2689. FurMaterial.prototype.dispose = function (forceDisposeEffect) {
  2690. if (this.diffuseTexture) {
  2691. this.diffuseTexture.dispose();
  2692. }
  2693. if (this._meshes) {
  2694. for (var i = 1; i < this._meshes.length; i++) {
  2695. var mat = this._meshes[i].material;
  2696. if (mat) {
  2697. mat.dispose(forceDisposeEffect);
  2698. }
  2699. this._meshes[i].dispose();
  2700. }
  2701. }
  2702. _super.prototype.dispose.call(this, forceDisposeEffect);
  2703. };
  2704. FurMaterial.prototype.clone = function (name) {
  2705. var _this = this;
  2706. return BABYLON.SerializationHelper.Clone(function () { return new FurMaterial(name, _this.getScene()); }, this);
  2707. };
  2708. FurMaterial.prototype.serialize = function () {
  2709. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  2710. serializationObject.customType = "BABYLON.FurMaterial";
  2711. if (this._meshes) {
  2712. serializationObject.sourceMeshName = this._meshes[0].name;
  2713. serializationObject.quality = this._meshes.length;
  2714. }
  2715. return serializationObject;
  2716. };
  2717. FurMaterial.prototype.getClassName = function () {
  2718. return "FurMaterial";
  2719. };
  2720. // Statics
  2721. FurMaterial.Parse = function (source, scene, rootUrl) {
  2722. var material = BABYLON.SerializationHelper.Parse(function () { return new FurMaterial(source.name, scene); }, source, scene, rootUrl);
  2723. if (source.sourceMeshName && material.highLevelFur) {
  2724. scene.executeWhenReady(function () {
  2725. var sourceMesh = scene.getMeshByName(source.sourceMeshName);
  2726. if (sourceMesh) {
  2727. var furTexture = FurMaterial.GenerateTexture("Fur Texture", scene);
  2728. material.furTexture = furTexture;
  2729. FurMaterial.FurifyMesh(sourceMesh, source.quality);
  2730. }
  2731. });
  2732. }
  2733. return material;
  2734. };
  2735. FurMaterial.GenerateTexture = function (name, scene) {
  2736. // Generate fur textures
  2737. var texture = new BABYLON.DynamicTexture("FurTexture " + name, 256, scene, true);
  2738. var context = texture.getContext();
  2739. for (var i = 0; i < 20000; ++i) {
  2740. context.fillStyle = "rgba(255, " + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", 1)";
  2741. context.fillRect((Math.random() * texture.getSize().width), (Math.random() * texture.getSize().height), 2, 2);
  2742. }
  2743. texture.update(false);
  2744. texture.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
  2745. texture.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
  2746. return texture;
  2747. };
  2748. // Creates and returns an array of meshes used as shells for the Fur Material
  2749. // that can be disposed later in your code
  2750. // The quality is in interval [0, 100]
  2751. FurMaterial.FurifyMesh = function (sourceMesh, quality) {
  2752. var meshes = [sourceMesh];
  2753. var mat = sourceMesh.material;
  2754. var i;
  2755. if (!(mat instanceof FurMaterial)) {
  2756. throw "The material of the source mesh must be a Fur Material";
  2757. }
  2758. for (i = 1; i < quality; i++) {
  2759. var offsetFur = new BABYLON.FurMaterial(mat.name + i, sourceMesh.getScene());
  2760. sourceMesh.getScene().materials.pop();
  2761. BABYLON.Tags.EnableFor(offsetFur);
  2762. BABYLON.Tags.AddTagsTo(offsetFur, "furShellMaterial");
  2763. offsetFur.furLength = mat.furLength;
  2764. offsetFur.furAngle = mat.furAngle;
  2765. offsetFur.furGravity = mat.furGravity;
  2766. offsetFur.furSpacing = mat.furSpacing;
  2767. offsetFur.furSpeed = mat.furSpeed;
  2768. offsetFur.furColor = mat.furColor;
  2769. offsetFur.diffuseTexture = mat.diffuseTexture;
  2770. offsetFur.furOffset = i / quality;
  2771. offsetFur.furTexture = mat.furTexture;
  2772. offsetFur.highLevelFur = mat.highLevelFur;
  2773. offsetFur.furTime = mat.furTime;
  2774. offsetFur.furDensity = mat.furDensity;
  2775. var offsetMesh = sourceMesh.clone(sourceMesh.name + i);
  2776. offsetMesh.material = offsetFur;
  2777. offsetMesh.skeleton = sourceMesh.skeleton;
  2778. offsetMesh.position = BABYLON.Vector3.Zero();
  2779. meshes.push(offsetMesh);
  2780. }
  2781. for (i = 1; i < meshes.length; i++) {
  2782. meshes[i].parent = sourceMesh;
  2783. }
  2784. sourceMesh.material._meshes = meshes;
  2785. return meshes;
  2786. };
  2787. __decorate([
  2788. BABYLON.serializeAsTexture("diffuseTexture")
  2789. ], FurMaterial.prototype, "_diffuseTexture", void 0);
  2790. __decorate([
  2791. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2792. ], FurMaterial.prototype, "diffuseTexture", void 0);
  2793. __decorate([
  2794. BABYLON.serializeAsTexture("heightTexture")
  2795. ], FurMaterial.prototype, "_heightTexture", void 0);
  2796. __decorate([
  2797. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2798. ], FurMaterial.prototype, "heightTexture", void 0);
  2799. __decorate([
  2800. BABYLON.serializeAsColor3()
  2801. ], FurMaterial.prototype, "diffuseColor", void 0);
  2802. __decorate([
  2803. BABYLON.serialize()
  2804. ], FurMaterial.prototype, "furLength", void 0);
  2805. __decorate([
  2806. BABYLON.serialize()
  2807. ], FurMaterial.prototype, "furAngle", void 0);
  2808. __decorate([
  2809. BABYLON.serializeAsColor3()
  2810. ], FurMaterial.prototype, "furColor", void 0);
  2811. __decorate([
  2812. BABYLON.serialize()
  2813. ], FurMaterial.prototype, "furOffset", void 0);
  2814. __decorate([
  2815. BABYLON.serialize()
  2816. ], FurMaterial.prototype, "furSpacing", void 0);
  2817. __decorate([
  2818. BABYLON.serializeAsVector3()
  2819. ], FurMaterial.prototype, "furGravity", void 0);
  2820. __decorate([
  2821. BABYLON.serialize()
  2822. ], FurMaterial.prototype, "furSpeed", void 0);
  2823. __decorate([
  2824. BABYLON.serialize()
  2825. ], FurMaterial.prototype, "furDensity", void 0);
  2826. __decorate([
  2827. BABYLON.serialize()
  2828. ], FurMaterial.prototype, "furOcclusion", void 0);
  2829. __decorate([
  2830. BABYLON.serialize("disableLighting")
  2831. ], FurMaterial.prototype, "_disableLighting", void 0);
  2832. __decorate([
  2833. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  2834. ], FurMaterial.prototype, "disableLighting", void 0);
  2835. __decorate([
  2836. BABYLON.serialize("maxSimultaneousLights")
  2837. ], FurMaterial.prototype, "_maxSimultaneousLights", void 0);
  2838. __decorate([
  2839. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  2840. ], FurMaterial.prototype, "maxSimultaneousLights", void 0);
  2841. __decorate([
  2842. BABYLON.serialize()
  2843. ], FurMaterial.prototype, "highLevelFur", void 0);
  2844. __decorate([
  2845. BABYLON.serialize()
  2846. ], FurMaterial.prototype, "furTime", null);
  2847. return FurMaterial;
  2848. }(BABYLON.PushMaterial));
  2849. BABYLON.FurMaterial = FurMaterial;
  2850. })(BABYLON || (BABYLON = {}));
  2851. //# sourceMappingURL=babylon.furMaterial.js.map
  2852. 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";
  2853. 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}";
  2854. var BABYLON;
  2855. (function (BABYLON) {
  2856. var TerrainMaterialDefines = /** @class */ (function (_super) {
  2857. __extends(TerrainMaterialDefines, _super);
  2858. function TerrainMaterialDefines() {
  2859. var _this = _super.call(this) || this;
  2860. _this.DIFFUSE = false;
  2861. _this.BUMP = false;
  2862. _this.CLIPPLANE = false;
  2863. _this.CLIPPLANE2 = false;
  2864. _this.CLIPPLANE3 = false;
  2865. _this.CLIPPLANE4 = false;
  2866. _this.ALPHATEST = false;
  2867. _this.DEPTHPREPASS = false;
  2868. _this.POINTSIZE = false;
  2869. _this.FOG = false;
  2870. _this.SPECULARTERM = false;
  2871. _this.NORMAL = false;
  2872. _this.UV1 = false;
  2873. _this.UV2 = false;
  2874. _this.VERTEXCOLOR = false;
  2875. _this.VERTEXALPHA = false;
  2876. _this.NUM_BONE_INFLUENCERS = 0;
  2877. _this.BonesPerMesh = 0;
  2878. _this.INSTANCES = false;
  2879. _this.rebuild();
  2880. return _this;
  2881. }
  2882. return TerrainMaterialDefines;
  2883. }(BABYLON.MaterialDefines));
  2884. var TerrainMaterial = /** @class */ (function (_super) {
  2885. __extends(TerrainMaterial, _super);
  2886. function TerrainMaterial(name, scene) {
  2887. var _this = _super.call(this, name, scene) || this;
  2888. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  2889. _this.specularColor = new BABYLON.Color3(0, 0, 0);
  2890. _this.specularPower = 64;
  2891. _this._disableLighting = false;
  2892. _this._maxSimultaneousLights = 4;
  2893. return _this;
  2894. }
  2895. TerrainMaterial.prototype.needAlphaBlending = function () {
  2896. return (this.alpha < 1.0);
  2897. };
  2898. TerrainMaterial.prototype.needAlphaTesting = function () {
  2899. return false;
  2900. };
  2901. TerrainMaterial.prototype.getAlphaTestTexture = function () {
  2902. return null;
  2903. };
  2904. // Methods
  2905. TerrainMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  2906. if (this.isFrozen) {
  2907. if (this._wasPreviouslyReady && subMesh.effect) {
  2908. return true;
  2909. }
  2910. }
  2911. if (!subMesh._materialDefines) {
  2912. subMesh._materialDefines = new TerrainMaterialDefines();
  2913. }
  2914. var defines = subMesh._materialDefines;
  2915. var scene = this.getScene();
  2916. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  2917. if (this._renderId === scene.getRenderId()) {
  2918. return true;
  2919. }
  2920. }
  2921. var engine = scene.getEngine();
  2922. // Textures
  2923. if (scene.texturesEnabled) {
  2924. if (this.mixTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2925. if (!this.mixTexture.isReady()) {
  2926. return false;
  2927. }
  2928. else {
  2929. defines._needUVs = true;
  2930. defines.DIFFUSE = true;
  2931. }
  2932. }
  2933. if ((this.bumpTexture1 || this.bumpTexture2 || this.bumpTexture3) && BABYLON.StandardMaterial.BumpTextureEnabled) {
  2934. defines._needUVs = true;
  2935. defines._needNormals = true;
  2936. defines.BUMP = true;
  2937. }
  2938. }
  2939. // Misc.
  2940. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  2941. // Lights
  2942. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  2943. // Values that need to be evaluated on every frame
  2944. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  2945. // Attribs
  2946. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  2947. // Get correct effect
  2948. if (defines.isDirty) {
  2949. defines.markAsProcessed();
  2950. scene.resetCachedMaterial();
  2951. // Fallbacks
  2952. var fallbacks = new BABYLON.EffectFallbacks();
  2953. if (defines.FOG) {
  2954. fallbacks.addFallback(1, "FOG");
  2955. }
  2956. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  2957. if (defines.NUM_BONE_INFLUENCERS > 0) {
  2958. fallbacks.addCPUSkinningFallback(0, mesh);
  2959. }
  2960. //Attributes
  2961. var attribs = [BABYLON.VertexBuffer.PositionKind];
  2962. if (defines.NORMAL) {
  2963. attribs.push(BABYLON.VertexBuffer.NormalKind);
  2964. }
  2965. if (defines.UV1) {
  2966. attribs.push(BABYLON.VertexBuffer.UVKind);
  2967. }
  2968. if (defines.UV2) {
  2969. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  2970. }
  2971. if (defines.VERTEXCOLOR) {
  2972. attribs.push(BABYLON.VertexBuffer.ColorKind);
  2973. }
  2974. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  2975. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  2976. // Legacy browser patch
  2977. var shaderName = "terrain";
  2978. var join = defines.toString();
  2979. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  2980. "vFogInfos", "vFogColor", "pointSize",
  2981. "vTextureInfos",
  2982. "mBones",
  2983. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "textureMatrix",
  2984. "diffuse1Infos", "diffuse2Infos", "diffuse3Infos"
  2985. ];
  2986. var samplers = ["textureSampler", "diffuse1Sampler", "diffuse2Sampler", "diffuse3Sampler",
  2987. "bump1Sampler", "bump2Sampler", "bump3Sampler"
  2988. ];
  2989. var uniformBuffers = new Array();
  2990. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  2991. uniformsNames: uniforms,
  2992. uniformBuffersNames: uniformBuffers,
  2993. samplers: samplers,
  2994. defines: defines,
  2995. maxSimultaneousLights: this.maxSimultaneousLights
  2996. });
  2997. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  2998. attributes: attribs,
  2999. uniformsNames: uniforms,
  3000. uniformBuffersNames: uniformBuffers,
  3001. samplers: samplers,
  3002. defines: join,
  3003. fallbacks: fallbacks,
  3004. onCompiled: this.onCompiled,
  3005. onError: this.onError,
  3006. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  3007. }, engine), defines);
  3008. }
  3009. if (!subMesh.effect || !subMesh.effect.isReady()) {
  3010. return false;
  3011. }
  3012. this._renderId = scene.getRenderId();
  3013. this._wasPreviouslyReady = true;
  3014. return true;
  3015. };
  3016. TerrainMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  3017. var scene = this.getScene();
  3018. var defines = subMesh._materialDefines;
  3019. if (!defines) {
  3020. return;
  3021. }
  3022. var effect = subMesh.effect;
  3023. if (!effect) {
  3024. return;
  3025. }
  3026. this._activeEffect = effect;
  3027. // Matrices
  3028. this.bindOnlyWorldMatrix(world);
  3029. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  3030. // Bones
  3031. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  3032. if (this._mustRebind(scene, effect)) {
  3033. // Textures
  3034. if (this.mixTexture) {
  3035. this._activeEffect.setTexture("textureSampler", this._mixTexture);
  3036. this._activeEffect.setFloat2("vTextureInfos", this._mixTexture.coordinatesIndex, this._mixTexture.level);
  3037. this._activeEffect.setMatrix("textureMatrix", this._mixTexture.getTextureMatrix());
  3038. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  3039. if (this._diffuseTexture1) {
  3040. this._activeEffect.setTexture("diffuse1Sampler", this._diffuseTexture1);
  3041. this._activeEffect.setFloat2("diffuse1Infos", this._diffuseTexture1.uScale, this._diffuseTexture1.vScale);
  3042. }
  3043. if (this._diffuseTexture2) {
  3044. this._activeEffect.setTexture("diffuse2Sampler", this._diffuseTexture2);
  3045. this._activeEffect.setFloat2("diffuse2Infos", this._diffuseTexture2.uScale, this._diffuseTexture2.vScale);
  3046. }
  3047. if (this._diffuseTexture3) {
  3048. this._activeEffect.setTexture("diffuse3Sampler", this._diffuseTexture3);
  3049. this._activeEffect.setFloat2("diffuse3Infos", this._diffuseTexture3.uScale, this._diffuseTexture3.vScale);
  3050. }
  3051. }
  3052. if (BABYLON.StandardMaterial.BumpTextureEnabled && scene.getEngine().getCaps().standardDerivatives) {
  3053. if (this._bumpTexture1) {
  3054. this._activeEffect.setTexture("bump1Sampler", this._bumpTexture1);
  3055. }
  3056. if (this._bumpTexture2) {
  3057. this._activeEffect.setTexture("bump2Sampler", this._bumpTexture2);
  3058. }
  3059. if (this._bumpTexture3) {
  3060. this._activeEffect.setTexture("bump3Sampler", this._bumpTexture3);
  3061. }
  3062. }
  3063. }
  3064. // Clip plane
  3065. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  3066. // Point size
  3067. if (this.pointsCloud) {
  3068. this._activeEffect.setFloat("pointSize", this.pointSize);
  3069. }
  3070. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  3071. }
  3072. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  3073. if (defines.SPECULARTERM) {
  3074. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  3075. }
  3076. if (scene.lightsEnabled && !this.disableLighting) {
  3077. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  3078. }
  3079. // View
  3080. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  3081. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  3082. }
  3083. // Fog
  3084. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  3085. this._afterBind(mesh, this._activeEffect);
  3086. };
  3087. TerrainMaterial.prototype.getAnimatables = function () {
  3088. var results = [];
  3089. if (this.mixTexture && this.mixTexture.animations && this.mixTexture.animations.length > 0) {
  3090. results.push(this.mixTexture);
  3091. }
  3092. return results;
  3093. };
  3094. TerrainMaterial.prototype.getActiveTextures = function () {
  3095. var activeTextures = _super.prototype.getActiveTextures.call(this);
  3096. if (this._mixTexture) {
  3097. activeTextures.push(this._mixTexture);
  3098. }
  3099. if (this._diffuseTexture1) {
  3100. activeTextures.push(this._diffuseTexture1);
  3101. }
  3102. if (this._diffuseTexture2) {
  3103. activeTextures.push(this._diffuseTexture2);
  3104. }
  3105. if (this._diffuseTexture3) {
  3106. activeTextures.push(this._diffuseTexture3);
  3107. }
  3108. if (this._bumpTexture1) {
  3109. activeTextures.push(this._bumpTexture1);
  3110. }
  3111. if (this._bumpTexture2) {
  3112. activeTextures.push(this._bumpTexture2);
  3113. }
  3114. if (this._bumpTexture3) {
  3115. activeTextures.push(this._bumpTexture3);
  3116. }
  3117. return activeTextures;
  3118. };
  3119. TerrainMaterial.prototype.hasTexture = function (texture) {
  3120. if (_super.prototype.hasTexture.call(this, texture)) {
  3121. return true;
  3122. }
  3123. if (this._mixTexture === texture) {
  3124. return true;
  3125. }
  3126. if (this._diffuseTexture1 === texture) {
  3127. return true;
  3128. }
  3129. if (this._diffuseTexture2 === texture) {
  3130. return true;
  3131. }
  3132. if (this._diffuseTexture3 === texture) {
  3133. return true;
  3134. }
  3135. if (this._bumpTexture1 === texture) {
  3136. return true;
  3137. }
  3138. if (this._bumpTexture2 === texture) {
  3139. return true;
  3140. }
  3141. if (this._bumpTexture3 === texture) {
  3142. return true;
  3143. }
  3144. return false;
  3145. };
  3146. TerrainMaterial.prototype.dispose = function (forceDisposeEffect) {
  3147. if (this.mixTexture) {
  3148. this.mixTexture.dispose();
  3149. }
  3150. _super.prototype.dispose.call(this, forceDisposeEffect);
  3151. };
  3152. TerrainMaterial.prototype.clone = function (name) {
  3153. var _this = this;
  3154. return BABYLON.SerializationHelper.Clone(function () { return new TerrainMaterial(name, _this.getScene()); }, this);
  3155. };
  3156. TerrainMaterial.prototype.serialize = function () {
  3157. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  3158. serializationObject.customType = "BABYLON.TerrainMaterial";
  3159. return serializationObject;
  3160. };
  3161. TerrainMaterial.prototype.getClassName = function () {
  3162. return "TerrainMaterial";
  3163. };
  3164. // Statics
  3165. TerrainMaterial.Parse = function (source, scene, rootUrl) {
  3166. return BABYLON.SerializationHelper.Parse(function () { return new TerrainMaterial(source.name, scene); }, source, scene, rootUrl);
  3167. };
  3168. __decorate([
  3169. BABYLON.serializeAsTexture("mixTexture")
  3170. ], TerrainMaterial.prototype, "_mixTexture", void 0);
  3171. __decorate([
  3172. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3173. ], TerrainMaterial.prototype, "mixTexture", void 0);
  3174. __decorate([
  3175. BABYLON.serializeAsTexture("diffuseTexture1")
  3176. ], TerrainMaterial.prototype, "_diffuseTexture1", void 0);
  3177. __decorate([
  3178. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3179. ], TerrainMaterial.prototype, "diffuseTexture1", void 0);
  3180. __decorate([
  3181. BABYLON.serializeAsTexture("diffuseTexture2")
  3182. ], TerrainMaterial.prototype, "_diffuseTexture2", void 0);
  3183. __decorate([
  3184. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3185. ], TerrainMaterial.prototype, "diffuseTexture2", void 0);
  3186. __decorate([
  3187. BABYLON.serializeAsTexture("diffuseTexture3")
  3188. ], TerrainMaterial.prototype, "_diffuseTexture3", void 0);
  3189. __decorate([
  3190. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3191. ], TerrainMaterial.prototype, "diffuseTexture3", void 0);
  3192. __decorate([
  3193. BABYLON.serializeAsTexture("bumpTexture1")
  3194. ], TerrainMaterial.prototype, "_bumpTexture1", void 0);
  3195. __decorate([
  3196. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3197. ], TerrainMaterial.prototype, "bumpTexture1", void 0);
  3198. __decorate([
  3199. BABYLON.serializeAsTexture("bumpTexture2")
  3200. ], TerrainMaterial.prototype, "_bumpTexture2", void 0);
  3201. __decorate([
  3202. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3203. ], TerrainMaterial.prototype, "bumpTexture2", void 0);
  3204. __decorate([
  3205. BABYLON.serializeAsTexture("bumpTexture3")
  3206. ], TerrainMaterial.prototype, "_bumpTexture3", void 0);
  3207. __decorate([
  3208. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3209. ], TerrainMaterial.prototype, "bumpTexture3", void 0);
  3210. __decorate([
  3211. BABYLON.serializeAsColor3()
  3212. ], TerrainMaterial.prototype, "diffuseColor", void 0);
  3213. __decorate([
  3214. BABYLON.serializeAsColor3()
  3215. ], TerrainMaterial.prototype, "specularColor", void 0);
  3216. __decorate([
  3217. BABYLON.serialize()
  3218. ], TerrainMaterial.prototype, "specularPower", void 0);
  3219. __decorate([
  3220. BABYLON.serialize("disableLighting")
  3221. ], TerrainMaterial.prototype, "_disableLighting", void 0);
  3222. __decorate([
  3223. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3224. ], TerrainMaterial.prototype, "disableLighting", void 0);
  3225. __decorate([
  3226. BABYLON.serialize("maxSimultaneousLights")
  3227. ], TerrainMaterial.prototype, "_maxSimultaneousLights", void 0);
  3228. __decorate([
  3229. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3230. ], TerrainMaterial.prototype, "maxSimultaneousLights", void 0);
  3231. return TerrainMaterial;
  3232. }(BABYLON.PushMaterial));
  3233. BABYLON.TerrainMaterial = TerrainMaterial;
  3234. })(BABYLON || (BABYLON = {}));
  3235. //# sourceMappingURL=babylon.terrainMaterial.js.map
  3236. 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";
  3237. 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";
  3238. var BABYLON;
  3239. (function (BABYLON) {
  3240. var MixMaterialDefines = /** @class */ (function (_super) {
  3241. __extends(MixMaterialDefines, _super);
  3242. function MixMaterialDefines() {
  3243. var _this = _super.call(this) || this;
  3244. _this.DIFFUSE = false;
  3245. _this.CLIPPLANE = false;
  3246. _this.CLIPPLANE2 = false;
  3247. _this.CLIPPLANE3 = false;
  3248. _this.CLIPPLANE4 = false;
  3249. _this.ALPHATEST = false;
  3250. _this.DEPTHPREPASS = false;
  3251. _this.POINTSIZE = false;
  3252. _this.FOG = false;
  3253. _this.SPECULARTERM = false;
  3254. _this.NORMAL = false;
  3255. _this.UV1 = false;
  3256. _this.UV2 = false;
  3257. _this.VERTEXCOLOR = false;
  3258. _this.VERTEXALPHA = false;
  3259. _this.NUM_BONE_INFLUENCERS = 0;
  3260. _this.BonesPerMesh = 0;
  3261. _this.INSTANCES = false;
  3262. _this.MIXMAP2 = false;
  3263. _this.rebuild();
  3264. return _this;
  3265. }
  3266. return MixMaterialDefines;
  3267. }(BABYLON.MaterialDefines));
  3268. var MixMaterial = /** @class */ (function (_super) {
  3269. __extends(MixMaterial, _super);
  3270. function MixMaterial(name, scene) {
  3271. var _this = _super.call(this, name, scene) || this;
  3272. /**
  3273. * Uniforms
  3274. */
  3275. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  3276. _this.specularColor = new BABYLON.Color3(0, 0, 0);
  3277. _this.specularPower = 64;
  3278. _this._disableLighting = false;
  3279. _this._maxSimultaneousLights = 4;
  3280. return _this;
  3281. }
  3282. MixMaterial.prototype.needAlphaBlending = function () {
  3283. return (this.alpha < 1.0);
  3284. };
  3285. MixMaterial.prototype.needAlphaTesting = function () {
  3286. return false;
  3287. };
  3288. MixMaterial.prototype.getAlphaTestTexture = function () {
  3289. return null;
  3290. };
  3291. // Methods
  3292. MixMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  3293. if (this.isFrozen) {
  3294. if (this._wasPreviouslyReady && subMesh.effect) {
  3295. return true;
  3296. }
  3297. }
  3298. if (!subMesh._materialDefines) {
  3299. subMesh._materialDefines = new MixMaterialDefines();
  3300. }
  3301. var defines = subMesh._materialDefines;
  3302. var scene = this.getScene();
  3303. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  3304. if (this._renderId === scene.getRenderId()) {
  3305. return true;
  3306. }
  3307. }
  3308. var engine = scene.getEngine();
  3309. // Textures
  3310. if (scene.texturesEnabled) {
  3311. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  3312. if (this._mixTexture1) {
  3313. if (!this._mixTexture1.isReady()) {
  3314. return false;
  3315. }
  3316. else {
  3317. defines._needUVs = true;
  3318. defines.DIFFUSE = true;
  3319. }
  3320. }
  3321. if (this._mixTexture2) {
  3322. if (!this._mixTexture2.isReady()) {
  3323. return false;
  3324. }
  3325. else {
  3326. defines.MIXMAP2 = true;
  3327. }
  3328. }
  3329. }
  3330. }
  3331. // Misc.
  3332. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  3333. // Lights
  3334. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  3335. // Values that need to be evaluated on every frame
  3336. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  3337. // Attribs
  3338. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  3339. // Get correct effect
  3340. if (defines.isDirty) {
  3341. defines.markAsProcessed();
  3342. scene.resetCachedMaterial();
  3343. // Fallbacks
  3344. var fallbacks = new BABYLON.EffectFallbacks();
  3345. if (defines.FOG) {
  3346. fallbacks.addFallback(1, "FOG");
  3347. }
  3348. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  3349. if (defines.NUM_BONE_INFLUENCERS > 0) {
  3350. fallbacks.addCPUSkinningFallback(0, mesh);
  3351. }
  3352. //Attributes
  3353. var attribs = [BABYLON.VertexBuffer.PositionKind];
  3354. if (defines.NORMAL) {
  3355. attribs.push(BABYLON.VertexBuffer.NormalKind);
  3356. }
  3357. if (defines.UV1) {
  3358. attribs.push(BABYLON.VertexBuffer.UVKind);
  3359. }
  3360. if (defines.UV2) {
  3361. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  3362. }
  3363. if (defines.VERTEXCOLOR) {
  3364. attribs.push(BABYLON.VertexBuffer.ColorKind);
  3365. }
  3366. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  3367. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  3368. // Legacy browser patch
  3369. var shaderName = "mix";
  3370. var join = defines.toString();
  3371. var uniforms = [
  3372. "world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  3373. "vFogInfos", "vFogColor", "pointSize",
  3374. "vTextureInfos",
  3375. "mBones",
  3376. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "textureMatrix",
  3377. "diffuse1Infos", "diffuse2Infos", "diffuse3Infos", "diffuse4Infos",
  3378. "diffuse5Infos", "diffuse6Infos", "diffuse7Infos", "diffuse8Infos"
  3379. ];
  3380. var samplers = [
  3381. "mixMap1Sampler", "mixMap2Sampler",
  3382. "diffuse1Sampler", "diffuse2Sampler", "diffuse3Sampler", "diffuse4Sampler",
  3383. "diffuse5Sampler", "diffuse6Sampler", "diffuse7Sampler", "diffuse8Sampler"
  3384. ];
  3385. var uniformBuffers = new Array();
  3386. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  3387. uniformsNames: uniforms,
  3388. uniformBuffersNames: uniformBuffers,
  3389. samplers: samplers,
  3390. defines: defines,
  3391. maxSimultaneousLights: this.maxSimultaneousLights
  3392. });
  3393. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  3394. attributes: attribs,
  3395. uniformsNames: uniforms,
  3396. uniformBuffersNames: uniformBuffers,
  3397. samplers: samplers,
  3398. defines: join,
  3399. fallbacks: fallbacks,
  3400. onCompiled: this.onCompiled,
  3401. onError: this.onError,
  3402. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  3403. }, engine), defines);
  3404. }
  3405. if (!subMesh.effect || !subMesh.effect.isReady()) {
  3406. return false;
  3407. }
  3408. this._renderId = scene.getRenderId();
  3409. this._wasPreviouslyReady = true;
  3410. return true;
  3411. };
  3412. MixMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  3413. var scene = this.getScene();
  3414. var defines = subMesh._materialDefines;
  3415. if (!defines) {
  3416. return;
  3417. }
  3418. var effect = subMesh.effect;
  3419. if (!effect) {
  3420. return;
  3421. }
  3422. this._activeEffect = effect;
  3423. // Matrices
  3424. this.bindOnlyWorldMatrix(world);
  3425. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  3426. // Bones
  3427. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  3428. if (this._mustRebind(scene, effect)) {
  3429. // Textures
  3430. if (this._mixTexture1) {
  3431. this._activeEffect.setTexture("mixMap1Sampler", this._mixTexture1);
  3432. this._activeEffect.setFloat2("vTextureInfos", this._mixTexture1.coordinatesIndex, this._mixTexture1.level);
  3433. this._activeEffect.setMatrix("textureMatrix", this._mixTexture1.getTextureMatrix());
  3434. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  3435. if (this._diffuseTexture1) {
  3436. this._activeEffect.setTexture("diffuse1Sampler", this._diffuseTexture1);
  3437. this._activeEffect.setFloat2("diffuse1Infos", this._diffuseTexture1.uScale, this._diffuseTexture1.vScale);
  3438. }
  3439. if (this._diffuseTexture2) {
  3440. this._activeEffect.setTexture("diffuse2Sampler", this._diffuseTexture2);
  3441. this._activeEffect.setFloat2("diffuse2Infos", this._diffuseTexture2.uScale, this._diffuseTexture2.vScale);
  3442. }
  3443. if (this._diffuseTexture3) {
  3444. this._activeEffect.setTexture("diffuse3Sampler", this._diffuseTexture3);
  3445. this._activeEffect.setFloat2("diffuse3Infos", this._diffuseTexture3.uScale, this._diffuseTexture3.vScale);
  3446. }
  3447. if (this._diffuseTexture4) {
  3448. this._activeEffect.setTexture("diffuse4Sampler", this._diffuseTexture4);
  3449. this._activeEffect.setFloat2("diffuse4Infos", this._diffuseTexture4.uScale, this._diffuseTexture4.vScale);
  3450. }
  3451. }
  3452. }
  3453. if (this._mixTexture2) {
  3454. this._activeEffect.setTexture("mixMap2Sampler", this._mixTexture2);
  3455. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  3456. if (this._diffuseTexture5) {
  3457. this._activeEffect.setTexture("diffuse5Sampler", this._diffuseTexture5);
  3458. this._activeEffect.setFloat2("diffuse5Infos", this._diffuseTexture5.uScale, this._diffuseTexture5.vScale);
  3459. }
  3460. if (this._diffuseTexture6) {
  3461. this._activeEffect.setTexture("diffuse6Sampler", this._diffuseTexture6);
  3462. this._activeEffect.setFloat2("diffuse6Infos", this._diffuseTexture6.uScale, this._diffuseTexture6.vScale);
  3463. }
  3464. if (this._diffuseTexture7) {
  3465. this._activeEffect.setTexture("diffuse7Sampler", this._diffuseTexture7);
  3466. this._activeEffect.setFloat2("diffuse7Infos", this._diffuseTexture7.uScale, this._diffuseTexture7.vScale);
  3467. }
  3468. if (this._diffuseTexture8) {
  3469. this._activeEffect.setTexture("diffuse8Sampler", this._diffuseTexture8);
  3470. this._activeEffect.setFloat2("diffuse8Infos", this._diffuseTexture8.uScale, this._diffuseTexture8.vScale);
  3471. }
  3472. }
  3473. }
  3474. // Clip plane
  3475. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  3476. // Point size
  3477. if (this.pointsCloud) {
  3478. this._activeEffect.setFloat("pointSize", this.pointSize);
  3479. }
  3480. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  3481. }
  3482. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  3483. if (defines.SPECULARTERM) {
  3484. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  3485. }
  3486. if (scene.lightsEnabled && !this.disableLighting) {
  3487. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  3488. }
  3489. // View
  3490. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  3491. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  3492. }
  3493. // Fog
  3494. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  3495. this._afterBind(mesh, this._activeEffect);
  3496. };
  3497. MixMaterial.prototype.getAnimatables = function () {
  3498. var results = [];
  3499. if (this._mixTexture1 && this._mixTexture1.animations && this._mixTexture1.animations.length > 0) {
  3500. results.push(this._mixTexture1);
  3501. }
  3502. if (this._mixTexture2 && this._mixTexture2.animations && this._mixTexture2.animations.length > 0) {
  3503. results.push(this._mixTexture2);
  3504. }
  3505. return results;
  3506. };
  3507. MixMaterial.prototype.getActiveTextures = function () {
  3508. var activeTextures = _super.prototype.getActiveTextures.call(this);
  3509. // Mix map 1
  3510. if (this._mixTexture1) {
  3511. activeTextures.push(this._mixTexture1);
  3512. }
  3513. if (this._diffuseTexture1) {
  3514. activeTextures.push(this._diffuseTexture1);
  3515. }
  3516. if (this._diffuseTexture2) {
  3517. activeTextures.push(this._diffuseTexture2);
  3518. }
  3519. if (this._diffuseTexture3) {
  3520. activeTextures.push(this._diffuseTexture3);
  3521. }
  3522. if (this._diffuseTexture4) {
  3523. activeTextures.push(this._diffuseTexture4);
  3524. }
  3525. // Mix map 2
  3526. if (this._mixTexture2) {
  3527. activeTextures.push(this._mixTexture2);
  3528. }
  3529. if (this._diffuseTexture5) {
  3530. activeTextures.push(this._diffuseTexture5);
  3531. }
  3532. if (this._diffuseTexture6) {
  3533. activeTextures.push(this._diffuseTexture6);
  3534. }
  3535. if (this._diffuseTexture7) {
  3536. activeTextures.push(this._diffuseTexture7);
  3537. }
  3538. if (this._diffuseTexture8) {
  3539. activeTextures.push(this._diffuseTexture8);
  3540. }
  3541. return activeTextures;
  3542. };
  3543. MixMaterial.prototype.hasTexture = function (texture) {
  3544. if (_super.prototype.hasTexture.call(this, texture)) {
  3545. return true;
  3546. }
  3547. // Mix map 1
  3548. if (this._mixTexture1 === texture) {
  3549. return true;
  3550. }
  3551. if (this._diffuseTexture1 === texture) {
  3552. return true;
  3553. }
  3554. if (this._diffuseTexture2 === texture) {
  3555. return true;
  3556. }
  3557. if (this._diffuseTexture3 === texture) {
  3558. return true;
  3559. }
  3560. if (this._diffuseTexture4 === texture) {
  3561. return true;
  3562. }
  3563. // Mix map 2
  3564. if (this._mixTexture2 === texture) {
  3565. return true;
  3566. }
  3567. if (this._diffuseTexture5 === texture) {
  3568. return true;
  3569. }
  3570. if (this._diffuseTexture6 === texture) {
  3571. return true;
  3572. }
  3573. if (this._diffuseTexture7 === texture) {
  3574. return true;
  3575. }
  3576. if (this._diffuseTexture8 === texture) {
  3577. return true;
  3578. }
  3579. return false;
  3580. };
  3581. MixMaterial.prototype.dispose = function (forceDisposeEffect) {
  3582. if (this._mixTexture1) {
  3583. this._mixTexture1.dispose();
  3584. }
  3585. _super.prototype.dispose.call(this, forceDisposeEffect);
  3586. };
  3587. MixMaterial.prototype.clone = function (name) {
  3588. var _this = this;
  3589. return BABYLON.SerializationHelper.Clone(function () { return new MixMaterial(name, _this.getScene()); }, this);
  3590. };
  3591. MixMaterial.prototype.serialize = function () {
  3592. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  3593. serializationObject.customType = "BABYLON.MixMaterial";
  3594. return serializationObject;
  3595. };
  3596. MixMaterial.prototype.getClassName = function () {
  3597. return "MixMaterial";
  3598. };
  3599. // Statics
  3600. MixMaterial.Parse = function (source, scene, rootUrl) {
  3601. return BABYLON.SerializationHelper.Parse(function () { return new MixMaterial(source.name, scene); }, source, scene, rootUrl);
  3602. };
  3603. __decorate([
  3604. BABYLON.serializeAsTexture("mixTexture1")
  3605. ], MixMaterial.prototype, "_mixTexture1", void 0);
  3606. __decorate([
  3607. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3608. ], MixMaterial.prototype, "mixTexture1", void 0);
  3609. __decorate([
  3610. BABYLON.serializeAsTexture("mixTexture2")
  3611. ], MixMaterial.prototype, "_mixTexture2", void 0);
  3612. __decorate([
  3613. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3614. ], MixMaterial.prototype, "mixTexture2", void 0);
  3615. __decorate([
  3616. BABYLON.serializeAsTexture("diffuseTexture1")
  3617. ], MixMaterial.prototype, "_diffuseTexture1", void 0);
  3618. __decorate([
  3619. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3620. ], MixMaterial.prototype, "diffuseTexture1", void 0);
  3621. __decorate([
  3622. BABYLON.serializeAsTexture("diffuseTexture2")
  3623. ], MixMaterial.prototype, "_diffuseTexture2", void 0);
  3624. __decorate([
  3625. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3626. ], MixMaterial.prototype, "diffuseTexture2", void 0);
  3627. __decorate([
  3628. BABYLON.serializeAsTexture("diffuseTexture3")
  3629. ], MixMaterial.prototype, "_diffuseTexture3", void 0);
  3630. __decorate([
  3631. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3632. ], MixMaterial.prototype, "diffuseTexture3", void 0);
  3633. __decorate([
  3634. BABYLON.serializeAsTexture("diffuseTexture4")
  3635. ], MixMaterial.prototype, "_diffuseTexture4", void 0);
  3636. __decorate([
  3637. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3638. ], MixMaterial.prototype, "diffuseTexture4", void 0);
  3639. __decorate([
  3640. BABYLON.serializeAsTexture("diffuseTexture1")
  3641. ], MixMaterial.prototype, "_diffuseTexture5", void 0);
  3642. __decorate([
  3643. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3644. ], MixMaterial.prototype, "diffuseTexture5", void 0);
  3645. __decorate([
  3646. BABYLON.serializeAsTexture("diffuseTexture2")
  3647. ], MixMaterial.prototype, "_diffuseTexture6", void 0);
  3648. __decorate([
  3649. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3650. ], MixMaterial.prototype, "diffuseTexture6", void 0);
  3651. __decorate([
  3652. BABYLON.serializeAsTexture("diffuseTexture3")
  3653. ], MixMaterial.prototype, "_diffuseTexture7", void 0);
  3654. __decorate([
  3655. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3656. ], MixMaterial.prototype, "diffuseTexture7", void 0);
  3657. __decorate([
  3658. BABYLON.serializeAsTexture("diffuseTexture4")
  3659. ], MixMaterial.prototype, "_diffuseTexture8", void 0);
  3660. __decorate([
  3661. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3662. ], MixMaterial.prototype, "diffuseTexture8", void 0);
  3663. __decorate([
  3664. BABYLON.serializeAsColor3()
  3665. ], MixMaterial.prototype, "diffuseColor", void 0);
  3666. __decorate([
  3667. BABYLON.serializeAsColor3()
  3668. ], MixMaterial.prototype, "specularColor", void 0);
  3669. __decorate([
  3670. BABYLON.serialize()
  3671. ], MixMaterial.prototype, "specularPower", void 0);
  3672. __decorate([
  3673. BABYLON.serialize("disableLighting")
  3674. ], MixMaterial.prototype, "_disableLighting", void 0);
  3675. __decorate([
  3676. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3677. ], MixMaterial.prototype, "disableLighting", void 0);
  3678. __decorate([
  3679. BABYLON.serialize("maxSimultaneousLights")
  3680. ], MixMaterial.prototype, "_maxSimultaneousLights", void 0);
  3681. __decorate([
  3682. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3683. ], MixMaterial.prototype, "maxSimultaneousLights", void 0);
  3684. return MixMaterial;
  3685. }(BABYLON.PushMaterial));
  3686. BABYLON.MixMaterial = MixMaterial;
  3687. })(BABYLON || (BABYLON = {}));
  3688. //# sourceMappingURL=babylon.mixMaterial.js.map
  3689. 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";
  3690. 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";
  3691. var BABYLON;
  3692. (function (BABYLON) {
  3693. var TriPlanarMaterialDefines = /** @class */ (function (_super) {
  3694. __extends(TriPlanarMaterialDefines, _super);
  3695. function TriPlanarMaterialDefines() {
  3696. var _this = _super.call(this) || this;
  3697. _this.DIFFUSEX = false;
  3698. _this.DIFFUSEY = false;
  3699. _this.DIFFUSEZ = false;
  3700. _this.BUMPX = false;
  3701. _this.BUMPY = false;
  3702. _this.BUMPZ = false;
  3703. _this.CLIPPLANE = false;
  3704. _this.CLIPPLANE2 = false;
  3705. _this.CLIPPLANE3 = false;
  3706. _this.CLIPPLANE4 = false;
  3707. _this.ALPHATEST = false;
  3708. _this.DEPTHPREPASS = false;
  3709. _this.POINTSIZE = false;
  3710. _this.FOG = false;
  3711. _this.SPECULARTERM = false;
  3712. _this.NORMAL = false;
  3713. _this.VERTEXCOLOR = false;
  3714. _this.VERTEXALPHA = false;
  3715. _this.NUM_BONE_INFLUENCERS = 0;
  3716. _this.BonesPerMesh = 0;
  3717. _this.INSTANCES = false;
  3718. _this.rebuild();
  3719. return _this;
  3720. }
  3721. return TriPlanarMaterialDefines;
  3722. }(BABYLON.MaterialDefines));
  3723. var TriPlanarMaterial = /** @class */ (function (_super) {
  3724. __extends(TriPlanarMaterial, _super);
  3725. function TriPlanarMaterial(name, scene) {
  3726. var _this = _super.call(this, name, scene) || this;
  3727. _this.tileSize = 1;
  3728. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  3729. _this.specularColor = new BABYLON.Color3(0.2, 0.2, 0.2);
  3730. _this.specularPower = 64;
  3731. _this._disableLighting = false;
  3732. _this._maxSimultaneousLights = 4;
  3733. return _this;
  3734. }
  3735. TriPlanarMaterial.prototype.needAlphaBlending = function () {
  3736. return (this.alpha < 1.0);
  3737. };
  3738. TriPlanarMaterial.prototype.needAlphaTesting = function () {
  3739. return false;
  3740. };
  3741. TriPlanarMaterial.prototype.getAlphaTestTexture = function () {
  3742. return null;
  3743. };
  3744. // Methods
  3745. TriPlanarMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  3746. if (this.isFrozen) {
  3747. if (this._wasPreviouslyReady && subMesh.effect) {
  3748. return true;
  3749. }
  3750. }
  3751. if (!subMesh._materialDefines) {
  3752. subMesh._materialDefines = new TriPlanarMaterialDefines();
  3753. }
  3754. var defines = subMesh._materialDefines;
  3755. var scene = this.getScene();
  3756. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  3757. if (this._renderId === scene.getRenderId()) {
  3758. return true;
  3759. }
  3760. }
  3761. var engine = scene.getEngine();
  3762. // Textures
  3763. if (defines._areTexturesDirty) {
  3764. if (scene.texturesEnabled) {
  3765. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  3766. var textures = [this.diffuseTextureX, this.diffuseTextureY, this.diffuseTextureZ];
  3767. var textureDefines = ["DIFFUSEX", "DIFFUSEY", "DIFFUSEZ"];
  3768. for (var i = 0; i < textures.length; i++) {
  3769. if (textures[i]) {
  3770. if (!textures[i].isReady()) {
  3771. return false;
  3772. }
  3773. else {
  3774. defines[textureDefines[i]] = true;
  3775. }
  3776. }
  3777. }
  3778. }
  3779. if (BABYLON.StandardMaterial.BumpTextureEnabled) {
  3780. var textures = [this.normalTextureX, this.normalTextureY, this.normalTextureZ];
  3781. var textureDefines = ["BUMPX", "BUMPY", "BUMPZ"];
  3782. for (var i = 0; i < textures.length; i++) {
  3783. if (textures[i]) {
  3784. if (!textures[i].isReady()) {
  3785. return false;
  3786. }
  3787. else {
  3788. defines[textureDefines[i]] = true;
  3789. }
  3790. }
  3791. }
  3792. }
  3793. }
  3794. }
  3795. // Misc.
  3796. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  3797. // Lights
  3798. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  3799. // Values that need to be evaluated on every frame
  3800. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  3801. // Attribs
  3802. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  3803. // Get correct effect
  3804. if (defines.isDirty) {
  3805. defines.markAsProcessed();
  3806. scene.resetCachedMaterial();
  3807. // Fallbacks
  3808. var fallbacks = new BABYLON.EffectFallbacks();
  3809. if (defines.FOG) {
  3810. fallbacks.addFallback(1, "FOG");
  3811. }
  3812. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  3813. if (defines.NUM_BONE_INFLUENCERS > 0) {
  3814. fallbacks.addCPUSkinningFallback(0, mesh);
  3815. }
  3816. //Attributes
  3817. var attribs = [BABYLON.VertexBuffer.PositionKind];
  3818. if (defines.NORMAL) {
  3819. attribs.push(BABYLON.VertexBuffer.NormalKind);
  3820. }
  3821. if (defines.VERTEXCOLOR) {
  3822. attribs.push(BABYLON.VertexBuffer.ColorKind);
  3823. }
  3824. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  3825. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  3826. // Legacy browser patch
  3827. var shaderName = "triplanar";
  3828. var join = defines.toString();
  3829. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  3830. "vFogInfos", "vFogColor", "pointSize",
  3831. "mBones",
  3832. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4",
  3833. "tileSize"
  3834. ];
  3835. var samplers = ["diffuseSamplerX", "diffuseSamplerY", "diffuseSamplerZ",
  3836. "normalSamplerX", "normalSamplerY", "normalSamplerZ"
  3837. ];
  3838. var uniformBuffers = new Array();
  3839. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  3840. uniformsNames: uniforms,
  3841. uniformBuffersNames: uniformBuffers,
  3842. samplers: samplers,
  3843. defines: defines,
  3844. maxSimultaneousLights: this.maxSimultaneousLights
  3845. });
  3846. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  3847. attributes: attribs,
  3848. uniformsNames: uniforms,
  3849. uniformBuffersNames: uniformBuffers,
  3850. samplers: samplers,
  3851. defines: join,
  3852. fallbacks: fallbacks,
  3853. onCompiled: this.onCompiled,
  3854. onError: this.onError,
  3855. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  3856. }, engine), defines);
  3857. }
  3858. if (!subMesh.effect || !subMesh.effect.isReady()) {
  3859. return false;
  3860. }
  3861. this._renderId = scene.getRenderId();
  3862. this._wasPreviouslyReady = true;
  3863. return true;
  3864. };
  3865. TriPlanarMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  3866. var scene = this.getScene();
  3867. var defines = subMesh._materialDefines;
  3868. if (!defines) {
  3869. return;
  3870. }
  3871. var effect = subMesh.effect;
  3872. if (!effect) {
  3873. return;
  3874. }
  3875. this._activeEffect = effect;
  3876. // Matrices
  3877. this.bindOnlyWorldMatrix(world);
  3878. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  3879. // Bones
  3880. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  3881. this._activeEffect.setFloat("tileSize", this.tileSize);
  3882. if (scene.getCachedMaterial() !== this) {
  3883. // Textures
  3884. if (this.diffuseTextureX) {
  3885. this._activeEffect.setTexture("diffuseSamplerX", this.diffuseTextureX);
  3886. }
  3887. if (this.diffuseTextureY) {
  3888. this._activeEffect.setTexture("diffuseSamplerY", this.diffuseTextureY);
  3889. }
  3890. if (this.diffuseTextureZ) {
  3891. this._activeEffect.setTexture("diffuseSamplerZ", this.diffuseTextureZ);
  3892. }
  3893. if (this.normalTextureX) {
  3894. this._activeEffect.setTexture("normalSamplerX", this.normalTextureX);
  3895. }
  3896. if (this.normalTextureY) {
  3897. this._activeEffect.setTexture("normalSamplerY", this.normalTextureY);
  3898. }
  3899. if (this.normalTextureZ) {
  3900. this._activeEffect.setTexture("normalSamplerZ", this.normalTextureZ);
  3901. }
  3902. // Clip plane
  3903. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  3904. // Point size
  3905. if (this.pointsCloud) {
  3906. this._activeEffect.setFloat("pointSize", this.pointSize);
  3907. }
  3908. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  3909. }
  3910. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  3911. if (defines.SPECULARTERM) {
  3912. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  3913. }
  3914. if (scene.lightsEnabled && !this.disableLighting) {
  3915. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  3916. }
  3917. // View
  3918. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  3919. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  3920. }
  3921. // Fog
  3922. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  3923. this._afterBind(mesh, this._activeEffect);
  3924. };
  3925. TriPlanarMaterial.prototype.getAnimatables = function () {
  3926. var results = [];
  3927. if (this.mixTexture && this.mixTexture.animations && this.mixTexture.animations.length > 0) {
  3928. results.push(this.mixTexture);
  3929. }
  3930. return results;
  3931. };
  3932. TriPlanarMaterial.prototype.getActiveTextures = function () {
  3933. var activeTextures = _super.prototype.getActiveTextures.call(this);
  3934. if (this._diffuseTextureX) {
  3935. activeTextures.push(this._diffuseTextureX);
  3936. }
  3937. if (this._diffuseTextureY) {
  3938. activeTextures.push(this._diffuseTextureY);
  3939. }
  3940. if (this._diffuseTextureZ) {
  3941. activeTextures.push(this._diffuseTextureZ);
  3942. }
  3943. if (this._normalTextureX) {
  3944. activeTextures.push(this._normalTextureX);
  3945. }
  3946. if (this._normalTextureY) {
  3947. activeTextures.push(this._normalTextureY);
  3948. }
  3949. if (this._normalTextureZ) {
  3950. activeTextures.push(this._normalTextureZ);
  3951. }
  3952. return activeTextures;
  3953. };
  3954. TriPlanarMaterial.prototype.hasTexture = function (texture) {
  3955. if (_super.prototype.hasTexture.call(this, texture)) {
  3956. return true;
  3957. }
  3958. if (this._diffuseTextureX === texture) {
  3959. return true;
  3960. }
  3961. if (this._diffuseTextureY === texture) {
  3962. return true;
  3963. }
  3964. if (this._diffuseTextureZ === texture) {
  3965. return true;
  3966. }
  3967. if (this._normalTextureX === texture) {
  3968. return true;
  3969. }
  3970. if (this._normalTextureY === texture) {
  3971. return true;
  3972. }
  3973. if (this._normalTextureZ === texture) {
  3974. return true;
  3975. }
  3976. return false;
  3977. };
  3978. TriPlanarMaterial.prototype.dispose = function (forceDisposeEffect) {
  3979. if (this.mixTexture) {
  3980. this.mixTexture.dispose();
  3981. }
  3982. _super.prototype.dispose.call(this, forceDisposeEffect);
  3983. };
  3984. TriPlanarMaterial.prototype.clone = function (name) {
  3985. var _this = this;
  3986. return BABYLON.SerializationHelper.Clone(function () { return new TriPlanarMaterial(name, _this.getScene()); }, this);
  3987. };
  3988. TriPlanarMaterial.prototype.serialize = function () {
  3989. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  3990. serializationObject.customType = "BABYLON.TriPlanarMaterial";
  3991. return serializationObject;
  3992. };
  3993. TriPlanarMaterial.prototype.getClassName = function () {
  3994. return "TriPlanarMaterial";
  3995. };
  3996. // Statics
  3997. TriPlanarMaterial.Parse = function (source, scene, rootUrl) {
  3998. return BABYLON.SerializationHelper.Parse(function () { return new TriPlanarMaterial(source.name, scene); }, source, scene, rootUrl);
  3999. };
  4000. __decorate([
  4001. BABYLON.serializeAsTexture()
  4002. ], TriPlanarMaterial.prototype, "mixTexture", void 0);
  4003. __decorate([
  4004. BABYLON.serializeAsTexture("diffuseTextureX")
  4005. ], TriPlanarMaterial.prototype, "_diffuseTextureX", void 0);
  4006. __decorate([
  4007. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4008. ], TriPlanarMaterial.prototype, "diffuseTextureX", void 0);
  4009. __decorate([
  4010. BABYLON.serializeAsTexture("diffuseTexturY")
  4011. ], TriPlanarMaterial.prototype, "_diffuseTextureY", void 0);
  4012. __decorate([
  4013. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4014. ], TriPlanarMaterial.prototype, "diffuseTextureY", void 0);
  4015. __decorate([
  4016. BABYLON.serializeAsTexture("diffuseTextureZ")
  4017. ], TriPlanarMaterial.prototype, "_diffuseTextureZ", void 0);
  4018. __decorate([
  4019. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4020. ], TriPlanarMaterial.prototype, "diffuseTextureZ", void 0);
  4021. __decorate([
  4022. BABYLON.serializeAsTexture("normalTextureX")
  4023. ], TriPlanarMaterial.prototype, "_normalTextureX", void 0);
  4024. __decorate([
  4025. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4026. ], TriPlanarMaterial.prototype, "normalTextureX", void 0);
  4027. __decorate([
  4028. BABYLON.serializeAsTexture("normalTextureY")
  4029. ], TriPlanarMaterial.prototype, "_normalTextureY", void 0);
  4030. __decorate([
  4031. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4032. ], TriPlanarMaterial.prototype, "normalTextureY", void 0);
  4033. __decorate([
  4034. BABYLON.serializeAsTexture("normalTextureZ")
  4035. ], TriPlanarMaterial.prototype, "_normalTextureZ", void 0);
  4036. __decorate([
  4037. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4038. ], TriPlanarMaterial.prototype, "normalTextureZ", void 0);
  4039. __decorate([
  4040. BABYLON.serialize()
  4041. ], TriPlanarMaterial.prototype, "tileSize", void 0);
  4042. __decorate([
  4043. BABYLON.serializeAsColor3()
  4044. ], TriPlanarMaterial.prototype, "diffuseColor", void 0);
  4045. __decorate([
  4046. BABYLON.serializeAsColor3()
  4047. ], TriPlanarMaterial.prototype, "specularColor", void 0);
  4048. __decorate([
  4049. BABYLON.serialize()
  4050. ], TriPlanarMaterial.prototype, "specularPower", void 0);
  4051. __decorate([
  4052. BABYLON.serialize("disableLighting")
  4053. ], TriPlanarMaterial.prototype, "_disableLighting", void 0);
  4054. __decorate([
  4055. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  4056. ], TriPlanarMaterial.prototype, "disableLighting", void 0);
  4057. __decorate([
  4058. BABYLON.serialize("maxSimultaneousLights")
  4059. ], TriPlanarMaterial.prototype, "_maxSimultaneousLights", void 0);
  4060. __decorate([
  4061. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  4062. ], TriPlanarMaterial.prototype, "maxSimultaneousLights", void 0);
  4063. return TriPlanarMaterial;
  4064. }(BABYLON.PushMaterial));
  4065. BABYLON.TriPlanarMaterial = TriPlanarMaterial;
  4066. })(BABYLON || (BABYLON = {}));
  4067. //# sourceMappingURL=babylon.triPlanarMaterial.js.map
  4068. 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";
  4069. 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";
  4070. var BABYLON;
  4071. (function (BABYLON) {
  4072. var SkyMaterialDefines = /** @class */ (function (_super) {
  4073. __extends(SkyMaterialDefines, _super);
  4074. function SkyMaterialDefines() {
  4075. var _this = _super.call(this) || this;
  4076. _this.CLIPPLANE = false;
  4077. _this.CLIPPLANE2 = false;
  4078. _this.CLIPPLANE3 = false;
  4079. _this.CLIPPLANE4 = false;
  4080. _this.POINTSIZE = false;
  4081. _this.FOG = false;
  4082. _this.VERTEXCOLOR = false;
  4083. _this.VERTEXALPHA = false;
  4084. _this.rebuild();
  4085. return _this;
  4086. }
  4087. return SkyMaterialDefines;
  4088. }(BABYLON.MaterialDefines));
  4089. var SkyMaterial = /** @class */ (function (_super) {
  4090. __extends(SkyMaterial, _super);
  4091. function SkyMaterial(name, scene) {
  4092. var _this = _super.call(this, name, scene) || this;
  4093. // Public members
  4094. _this.luminance = 1.0;
  4095. _this.turbidity = 10.0;
  4096. _this.rayleigh = 2.0;
  4097. _this.mieCoefficient = 0.005;
  4098. _this.mieDirectionalG = 0.8;
  4099. _this.distance = 500;
  4100. _this.inclination = 0.49;
  4101. _this.azimuth = 0.25;
  4102. _this.sunPosition = new BABYLON.Vector3(0, 100, 0);
  4103. _this.useSunPosition = false;
  4104. // Private members
  4105. _this._cameraPosition = BABYLON.Vector3.Zero();
  4106. return _this;
  4107. }
  4108. SkyMaterial.prototype.needAlphaBlending = function () {
  4109. return (this.alpha < 1.0);
  4110. };
  4111. SkyMaterial.prototype.needAlphaTesting = function () {
  4112. return false;
  4113. };
  4114. SkyMaterial.prototype.getAlphaTestTexture = function () {
  4115. return null;
  4116. };
  4117. // Methods
  4118. SkyMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  4119. if (this.isFrozen) {
  4120. if (this._wasPreviouslyReady && subMesh.effect) {
  4121. return true;
  4122. }
  4123. }
  4124. if (!subMesh._materialDefines) {
  4125. subMesh._materialDefines = new SkyMaterialDefines();
  4126. }
  4127. var defines = subMesh._materialDefines;
  4128. var scene = this.getScene();
  4129. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  4130. if (this._renderId === scene.getRenderId()) {
  4131. return true;
  4132. }
  4133. }
  4134. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, false, defines);
  4135. // Attribs
  4136. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, false);
  4137. // Get correct effect
  4138. if (defines.isDirty) {
  4139. defines.markAsProcessed();
  4140. scene.resetCachedMaterial();
  4141. // Fallbacks
  4142. var fallbacks = new BABYLON.EffectFallbacks();
  4143. if (defines.FOG) {
  4144. fallbacks.addFallback(1, "FOG");
  4145. }
  4146. //Attributes
  4147. var attribs = [BABYLON.VertexBuffer.PositionKind];
  4148. if (defines.VERTEXCOLOR) {
  4149. attribs.push(BABYLON.VertexBuffer.ColorKind);
  4150. }
  4151. var shaderName = "sky";
  4152. var join = defines.toString();
  4153. subMesh.setEffect(scene.getEngine().createEffect(shaderName, attribs, ["world", "viewProjection", "view",
  4154. "vFogInfos", "vFogColor", "pointSize", "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4",
  4155. "luminance", "turbidity", "rayleigh", "mieCoefficient", "mieDirectionalG", "sunPosition",
  4156. "cameraPosition"
  4157. ], [], join, fallbacks, this.onCompiled, this.onError), defines);
  4158. }
  4159. if (!subMesh.effect || !subMesh.effect.isReady()) {
  4160. return false;
  4161. }
  4162. this._renderId = scene.getRenderId();
  4163. this._wasPreviouslyReady = true;
  4164. return true;
  4165. };
  4166. SkyMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  4167. var scene = this.getScene();
  4168. var defines = subMesh._materialDefines;
  4169. if (!defines) {
  4170. return;
  4171. }
  4172. var effect = subMesh.effect;
  4173. if (!effect) {
  4174. return;
  4175. }
  4176. this._activeEffect = effect;
  4177. // Matrices
  4178. this.bindOnlyWorldMatrix(world);
  4179. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  4180. if (this._mustRebind(scene, effect)) {
  4181. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  4182. // Point size
  4183. if (this.pointsCloud) {
  4184. this._activeEffect.setFloat("pointSize", this.pointSize);
  4185. }
  4186. }
  4187. // View
  4188. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  4189. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  4190. }
  4191. // Fog
  4192. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  4193. // Sky
  4194. var camera = scene.activeCamera;
  4195. if (camera) {
  4196. var cameraWorldMatrix = camera.getWorldMatrix();
  4197. this._cameraPosition.x = cameraWorldMatrix.m[12];
  4198. this._cameraPosition.y = cameraWorldMatrix.m[13];
  4199. this._cameraPosition.z = cameraWorldMatrix.m[14];
  4200. this._activeEffect.setVector3("cameraPosition", this._cameraPosition);
  4201. }
  4202. if (this.luminance > 0) {
  4203. this._activeEffect.setFloat("luminance", this.luminance);
  4204. }
  4205. this._activeEffect.setFloat("turbidity", this.turbidity);
  4206. this._activeEffect.setFloat("rayleigh", this.rayleigh);
  4207. this._activeEffect.setFloat("mieCoefficient", this.mieCoefficient);
  4208. this._activeEffect.setFloat("mieDirectionalG", this.mieDirectionalG);
  4209. if (!this.useSunPosition) {
  4210. var theta = Math.PI * (this.inclination - 0.5);
  4211. var phi = 2 * Math.PI * (this.azimuth - 0.5);
  4212. this.sunPosition.x = this.distance * Math.cos(phi);
  4213. this.sunPosition.y = this.distance * Math.sin(phi) * Math.sin(theta);
  4214. this.sunPosition.z = this.distance * Math.sin(phi) * Math.cos(theta);
  4215. }
  4216. this._activeEffect.setVector3("sunPosition", this.sunPosition);
  4217. this._afterBind(mesh, this._activeEffect);
  4218. };
  4219. SkyMaterial.prototype.getAnimatables = function () {
  4220. return [];
  4221. };
  4222. SkyMaterial.prototype.dispose = function (forceDisposeEffect) {
  4223. _super.prototype.dispose.call(this, forceDisposeEffect);
  4224. };
  4225. SkyMaterial.prototype.clone = function (name) {
  4226. var _this = this;
  4227. return BABYLON.SerializationHelper.Clone(function () { return new SkyMaterial(name, _this.getScene()); }, this);
  4228. };
  4229. SkyMaterial.prototype.serialize = function () {
  4230. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  4231. serializationObject.customType = "BABYLON.SkyMaterial";
  4232. return serializationObject;
  4233. };
  4234. SkyMaterial.prototype.getClassName = function () {
  4235. return "SkyMaterial";
  4236. };
  4237. // Statics
  4238. SkyMaterial.Parse = function (source, scene, rootUrl) {
  4239. return BABYLON.SerializationHelper.Parse(function () { return new SkyMaterial(source.name, scene); }, source, scene, rootUrl);
  4240. };
  4241. __decorate([
  4242. BABYLON.serialize()
  4243. ], SkyMaterial.prototype, "luminance", void 0);
  4244. __decorate([
  4245. BABYLON.serialize()
  4246. ], SkyMaterial.prototype, "turbidity", void 0);
  4247. __decorate([
  4248. BABYLON.serialize()
  4249. ], SkyMaterial.prototype, "rayleigh", void 0);
  4250. __decorate([
  4251. BABYLON.serialize()
  4252. ], SkyMaterial.prototype, "mieCoefficient", void 0);
  4253. __decorate([
  4254. BABYLON.serialize()
  4255. ], SkyMaterial.prototype, "mieDirectionalG", void 0);
  4256. __decorate([
  4257. BABYLON.serialize()
  4258. ], SkyMaterial.prototype, "distance", void 0);
  4259. __decorate([
  4260. BABYLON.serialize()
  4261. ], SkyMaterial.prototype, "inclination", void 0);
  4262. __decorate([
  4263. BABYLON.serialize()
  4264. ], SkyMaterial.prototype, "azimuth", void 0);
  4265. __decorate([
  4266. BABYLON.serializeAsVector3()
  4267. ], SkyMaterial.prototype, "sunPosition", void 0);
  4268. __decorate([
  4269. BABYLON.serialize()
  4270. ], SkyMaterial.prototype, "useSunPosition", void 0);
  4271. return SkyMaterial;
  4272. }(BABYLON.PushMaterial));
  4273. BABYLON.SkyMaterial = SkyMaterial;
  4274. })(BABYLON || (BABYLON = {}));
  4275. //# sourceMappingURL=babylon.skyMaterial.js.map
  4276. 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";
  4277. 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";
  4278. var BABYLON;
  4279. (function (BABYLON) {
  4280. var GridMaterialDefines = /** @class */ (function (_super) {
  4281. __extends(GridMaterialDefines, _super);
  4282. function GridMaterialDefines() {
  4283. var _this = _super.call(this) || this;
  4284. _this.TRANSPARENT = false;
  4285. _this.FOG = false;
  4286. _this.PREMULTIPLYALPHA = false;
  4287. _this.rebuild();
  4288. return _this;
  4289. }
  4290. return GridMaterialDefines;
  4291. }(BABYLON.MaterialDefines));
  4292. /**
  4293. * The grid materials allows you to wrap any shape with a grid.
  4294. * Colors are customizable.
  4295. */
  4296. var GridMaterial = /** @class */ (function (_super) {
  4297. __extends(GridMaterial, _super);
  4298. /**
  4299. * constructor
  4300. * @param name The name given to the material in order to identify it afterwards.
  4301. * @param scene The scene the material is used in.
  4302. */
  4303. function GridMaterial(name, scene) {
  4304. var _this = _super.call(this, name, scene) || this;
  4305. /**
  4306. * Main color of the grid (e.g. between lines)
  4307. */
  4308. _this.mainColor = BABYLON.Color3.Black();
  4309. /**
  4310. * Color of the grid lines.
  4311. */
  4312. _this.lineColor = BABYLON.Color3.Teal();
  4313. /**
  4314. * The scale of the grid compared to unit.
  4315. */
  4316. _this.gridRatio = 1.0;
  4317. /**
  4318. * Allows setting an offset for the grid lines.
  4319. */
  4320. _this.gridOffset = BABYLON.Vector3.Zero();
  4321. /**
  4322. * The frequency of thicker lines.
  4323. */
  4324. _this.majorUnitFrequency = 10;
  4325. /**
  4326. * The visibility of minor units in the grid.
  4327. */
  4328. _this.minorUnitVisibility = 0.33;
  4329. /**
  4330. * The grid opacity outside of the lines.
  4331. */
  4332. _this.opacity = 1.0;
  4333. /**
  4334. * Determine RBG output is premultiplied by alpha value.
  4335. */
  4336. _this.preMultiplyAlpha = false;
  4337. _this._gridControl = new BABYLON.Vector4(_this.gridRatio, _this.majorUnitFrequency, _this.minorUnitVisibility, _this.opacity);
  4338. return _this;
  4339. }
  4340. /**
  4341. * Returns wehter or not the grid requires alpha blending.
  4342. */
  4343. GridMaterial.prototype.needAlphaBlending = function () {
  4344. return this.opacity < 1.0;
  4345. };
  4346. GridMaterial.prototype.needAlphaBlendingForMesh = function (mesh) {
  4347. return this.needAlphaBlending();
  4348. };
  4349. GridMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  4350. if (this.isFrozen) {
  4351. if (this._wasPreviouslyReady && subMesh.effect) {
  4352. return true;
  4353. }
  4354. }
  4355. if (!subMesh._materialDefines) {
  4356. subMesh._materialDefines = new GridMaterialDefines();
  4357. }
  4358. var defines = subMesh._materialDefines;
  4359. var scene = this.getScene();
  4360. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  4361. if (this._renderId === scene.getRenderId()) {
  4362. return true;
  4363. }
  4364. }
  4365. if (defines.TRANSPARENT !== (this.opacity < 1.0)) {
  4366. defines.TRANSPARENT = !defines.TRANSPARENT;
  4367. defines.markAsUnprocessed();
  4368. }
  4369. if (defines.PREMULTIPLYALPHA != this.preMultiplyAlpha) {
  4370. defines.PREMULTIPLYALPHA = !defines.PREMULTIPLYALPHA;
  4371. defines.markAsUnprocessed();
  4372. }
  4373. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, false, this.fogEnabled, false, defines);
  4374. // Get correct effect
  4375. if (defines.isDirty) {
  4376. defines.markAsProcessed();
  4377. scene.resetCachedMaterial();
  4378. // Attributes
  4379. var attribs = [BABYLON.VertexBuffer.PositionKind, BABYLON.VertexBuffer.NormalKind];
  4380. // Defines
  4381. var join = defines.toString();
  4382. subMesh.setEffect(scene.getEngine().createEffect("grid", attribs, ["projection", "worldView", "mainColor", "lineColor", "gridControl", "gridOffset", "vFogInfos", "vFogColor", "world", "view"], [], join, undefined, this.onCompiled, this.onError), defines);
  4383. }
  4384. if (!subMesh.effect || !subMesh.effect.isReady()) {
  4385. return false;
  4386. }
  4387. this._renderId = scene.getRenderId();
  4388. this._wasPreviouslyReady = true;
  4389. return true;
  4390. };
  4391. GridMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  4392. var scene = this.getScene();
  4393. var defines = subMesh._materialDefines;
  4394. if (!defines) {
  4395. return;
  4396. }
  4397. var effect = subMesh.effect;
  4398. if (!effect) {
  4399. return;
  4400. }
  4401. this._activeEffect = effect;
  4402. // Matrices
  4403. this.bindOnlyWorldMatrix(world);
  4404. this._activeEffect.setMatrix("worldView", world.multiply(scene.getViewMatrix()));
  4405. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  4406. this._activeEffect.setMatrix("projection", scene.getProjectionMatrix());
  4407. // Uniforms
  4408. if (this._mustRebind(scene, effect)) {
  4409. this._activeEffect.setColor3("mainColor", this.mainColor);
  4410. this._activeEffect.setColor3("lineColor", this.lineColor);
  4411. this._activeEffect.setVector3("gridOffset", this.gridOffset);
  4412. this._gridControl.x = this.gridRatio;
  4413. this._gridControl.y = Math.round(this.majorUnitFrequency);
  4414. this._gridControl.z = this.minorUnitVisibility;
  4415. this._gridControl.w = this.opacity;
  4416. this._activeEffect.setVector4("gridControl", this._gridControl);
  4417. }
  4418. // Fog
  4419. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  4420. this._afterBind(mesh, this._activeEffect);
  4421. };
  4422. GridMaterial.prototype.dispose = function (forceDisposeEffect) {
  4423. _super.prototype.dispose.call(this, forceDisposeEffect);
  4424. };
  4425. GridMaterial.prototype.clone = function (name) {
  4426. var _this = this;
  4427. return BABYLON.SerializationHelper.Clone(function () { return new GridMaterial(name, _this.getScene()); }, this);
  4428. };
  4429. GridMaterial.prototype.serialize = function () {
  4430. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  4431. serializationObject.customType = "BABYLON.GridMaterial";
  4432. return serializationObject;
  4433. };
  4434. GridMaterial.prototype.getClassName = function () {
  4435. return "GridMaterial";
  4436. };
  4437. GridMaterial.Parse = function (source, scene, rootUrl) {
  4438. return BABYLON.SerializationHelper.Parse(function () { return new GridMaterial(source.name, scene); }, source, scene, rootUrl);
  4439. };
  4440. __decorate([
  4441. BABYLON.serializeAsColor3()
  4442. ], GridMaterial.prototype, "mainColor", void 0);
  4443. __decorate([
  4444. BABYLON.serializeAsColor3()
  4445. ], GridMaterial.prototype, "lineColor", void 0);
  4446. __decorate([
  4447. BABYLON.serialize()
  4448. ], GridMaterial.prototype, "gridRatio", void 0);
  4449. __decorate([
  4450. BABYLON.serializeAsColor3()
  4451. ], GridMaterial.prototype, "gridOffset", void 0);
  4452. __decorate([
  4453. BABYLON.serialize()
  4454. ], GridMaterial.prototype, "majorUnitFrequency", void 0);
  4455. __decorate([
  4456. BABYLON.serialize()
  4457. ], GridMaterial.prototype, "minorUnitVisibility", void 0);
  4458. __decorate([
  4459. BABYLON.serialize()
  4460. ], GridMaterial.prototype, "opacity", void 0);
  4461. __decorate([
  4462. BABYLON.serialize()
  4463. ], GridMaterial.prototype, "preMultiplyAlpha", void 0);
  4464. return GridMaterial;
  4465. }(BABYLON.PushMaterial));
  4466. BABYLON.GridMaterial = GridMaterial;
  4467. })(BABYLON || (BABYLON = {}));
  4468. //# sourceMappingURL=babylon.gridmaterial.js.map
  4469. 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}";
  4470. 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}";
  4471. var BABYLON;
  4472. (function (BABYLON) {
  4473. var CustomShaderStructure = /** @class */ (function () {
  4474. function CustomShaderStructure() {
  4475. }
  4476. return CustomShaderStructure;
  4477. }());
  4478. BABYLON.CustomShaderStructure = CustomShaderStructure;
  4479. var ShaderSpecialParts = /** @class */ (function () {
  4480. function ShaderSpecialParts() {
  4481. }
  4482. return ShaderSpecialParts;
  4483. }());
  4484. BABYLON.ShaderSpecialParts = ShaderSpecialParts;
  4485. var CustomMaterial = /** @class */ (function (_super) {
  4486. __extends(CustomMaterial, _super);
  4487. function CustomMaterial(name, scene) {
  4488. var _this = _super.call(this, name, scene) || this;
  4489. _this.CustomParts = new ShaderSpecialParts();
  4490. _this.customShaderNameResolve = _this.Builder;
  4491. _this.FragmentShader = BABYLON.Effect.ShadersStore["defaultPixelShader"];
  4492. _this.VertexShader = BABYLON.Effect.ShadersStore["defaultVertexShader"];
  4493. return _this;
  4494. }
  4495. CustomMaterial.prototype.AttachAfterBind = function (mesh, effect) {
  4496. for (var el in this._newUniformInstances) {
  4497. var ea = el.toString().split('-');
  4498. if (ea[0] == 'vec2') {
  4499. effect.setVector2(ea[1], this._newUniformInstances[el]);
  4500. }
  4501. else if (ea[0] == 'vec3') {
  4502. effect.setVector3(ea[1], this._newUniformInstances[el]);
  4503. }
  4504. else if (ea[0] == 'vec4') {
  4505. effect.setVector4(ea[1], this._newUniformInstances[el]);
  4506. }
  4507. else if (ea[0] == 'mat4') {
  4508. effect.setMatrix(ea[1], this._newUniformInstances[el]);
  4509. }
  4510. else if (ea[0] == 'float') {
  4511. effect.setFloat(ea[1], this._newUniformInstances[el]);
  4512. }
  4513. }
  4514. for (var el in this._newSamplerInstances) {
  4515. var ea = el.toString().split('-');
  4516. if (ea[0] == 'sampler2D' && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady()) {
  4517. effect.setTexture(ea[1], this._newSamplerInstances[el]);
  4518. }
  4519. }
  4520. };
  4521. CustomMaterial.prototype.ReviewUniform = function (name, arr) {
  4522. if (name == "uniform") {
  4523. for (var ind in this._newUniforms) {
  4524. if (this._customUniform[ind].indexOf('sampler') == -1) {
  4525. arr.push(this._newUniforms[ind]);
  4526. }
  4527. }
  4528. }
  4529. if (name == "sampler") {
  4530. for (var ind in this._newUniforms) {
  4531. if (this._customUniform[ind].indexOf('sampler') != -1) {
  4532. arr.push(this._newUniforms[ind]);
  4533. }
  4534. }
  4535. }
  4536. return arr;
  4537. };
  4538. CustomMaterial.prototype.Builder = function (shaderName, uniforms, uniformBuffers, samplers, defines) {
  4539. var _this = this;
  4540. if (this._isCreatedShader) {
  4541. return this._createdShaderName;
  4542. }
  4543. this._isCreatedShader = false;
  4544. CustomMaterial.ShaderIndexer++;
  4545. var name = "custom_" + CustomMaterial.ShaderIndexer;
  4546. this.ReviewUniform("uniform", uniforms);
  4547. this.ReviewUniform("sampler", samplers);
  4548. var fn_afterBind = this._afterBind.bind(this);
  4549. this._afterBind = function (m, e) {
  4550. if (!e) {
  4551. return;
  4552. }
  4553. _this.AttachAfterBind(m, e);
  4554. try {
  4555. fn_afterBind(m, e);
  4556. }
  4557. catch (e) { }
  4558. };
  4559. BABYLON.Effect.ShadersStore[name + "VertexShader"] = this.VertexShader
  4560. .replace('#define CUSTOM_VERTEX_BEGIN', (this.CustomParts.Vertex_Begin ? this.CustomParts.Vertex_Begin : ""))
  4561. .replace('#define CUSTOM_VERTEX_DEFINITIONS', (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Vertex_Definitions ? this.CustomParts.Vertex_Definitions : ""))
  4562. .replace('#define CUSTOM_VERTEX_MAIN_BEGIN', (this.CustomParts.Vertex_MainBegin ? this.CustomParts.Vertex_MainBegin : ""))
  4563. .replace('#define CUSTOM_VERTEX_UPDATE_POSITION', (this.CustomParts.Vertex_Before_PositionUpdated ? this.CustomParts.Vertex_Before_PositionUpdated : ""))
  4564. .replace('#define CUSTOM_VERTEX_UPDATE_NORMAL', (this.CustomParts.Vertex_Before_NormalUpdated ? this.CustomParts.Vertex_Before_NormalUpdated : ""));
  4565. // #define CUSTOM_VERTEX_MAIN_END
  4566. BABYLON.Effect.ShadersStore[name + "PixelShader"] = this.FragmentShader
  4567. .replace('#define CUSTOM_FRAGMENT_BEGIN', (this.CustomParts.Fragment_Begin ? this.CustomParts.Fragment_Begin : ""))
  4568. .replace('#define CUSTOM_FRAGMENT_MAIN_BEGIN', (this.CustomParts.Fragment_MainBegin ? this.CustomParts.Fragment_MainBegin : ""))
  4569. .replace('#define CUSTOM_FRAGMENT_DEFINITIONS', (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Fragment_Definitions ? this.CustomParts.Fragment_Definitions : ""))
  4570. .replace('#define CUSTOM_FRAGMENT_UPDATE_DIFFUSE', (this.CustomParts.Fragment_Custom_Diffuse ? this.CustomParts.Fragment_Custom_Diffuse : ""))
  4571. .replace('#define CUSTOM_FRAGMENT_UPDATE_ALPHA', (this.CustomParts.Fragment_Custom_Alpha ? this.CustomParts.Fragment_Custom_Alpha : ""))
  4572. .replace('#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR', (this.CustomParts.Fragment_Before_FragColor ? this.CustomParts.Fragment_Before_FragColor : ""));
  4573. // #define CUSTOM_FRAGMENT_BEFORE_LIGHTS
  4574. // #define CUSTOM_FRAGMENT_BEFORE_FOG
  4575. this._isCreatedShader = true;
  4576. this._createdShaderName = name;
  4577. return name;
  4578. };
  4579. CustomMaterial.prototype.AddUniform = function (name, kind, param) {
  4580. if (!this._customUniform) {
  4581. this._customUniform = new Array();
  4582. this._newUniforms = new Array();
  4583. this._newSamplerInstances = new Array();
  4584. this._newUniformInstances = new Array();
  4585. }
  4586. if (param) {
  4587. if (kind.indexOf("sampler") == -1) {
  4588. this._newUniformInstances[kind + "-" + name] = param;
  4589. }
  4590. else {
  4591. this._newUniformInstances[kind + "-" + name] = param;
  4592. }
  4593. }
  4594. this._customUniform.push("uniform " + kind + " " + name + ";");
  4595. this._newUniforms.push(name);
  4596. return this;
  4597. };
  4598. CustomMaterial.prototype.Fragment_Begin = function (shaderPart) {
  4599. this.CustomParts.Fragment_Begin = shaderPart;
  4600. return this;
  4601. };
  4602. CustomMaterial.prototype.Fragment_Definitions = function (shaderPart) {
  4603. this.CustomParts.Fragment_Definitions = shaderPart;
  4604. return this;
  4605. };
  4606. CustomMaterial.prototype.Fragment_MainBegin = function (shaderPart) {
  4607. this.CustomParts.Fragment_MainBegin = shaderPart;
  4608. return this;
  4609. };
  4610. CustomMaterial.prototype.Fragment_Custom_Diffuse = function (shaderPart) {
  4611. this.CustomParts.Fragment_Custom_Diffuse = shaderPart.replace("result", "diffuseColor");
  4612. return this;
  4613. };
  4614. CustomMaterial.prototype.Fragment_Custom_Alpha = function (shaderPart) {
  4615. this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace("result", "alpha");
  4616. return this;
  4617. };
  4618. CustomMaterial.prototype.Fragment_Before_FragColor = function (shaderPart) {
  4619. this.CustomParts.Fragment_Before_FragColor = shaderPart.replace("result", "color");
  4620. return this;
  4621. };
  4622. CustomMaterial.prototype.Vertex_Begin = function (shaderPart) {
  4623. this.CustomParts.Vertex_Begin = shaderPart;
  4624. return this;
  4625. };
  4626. CustomMaterial.prototype.Vertex_Definitions = function (shaderPart) {
  4627. this.CustomParts.Vertex_Definitions = shaderPart;
  4628. return this;
  4629. };
  4630. CustomMaterial.prototype.Vertex_MainBegin = function (shaderPart) {
  4631. this.CustomParts.Vertex_MainBegin = shaderPart;
  4632. return this;
  4633. };
  4634. CustomMaterial.prototype.Vertex_Before_PositionUpdated = function (shaderPart) {
  4635. this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace("result", "positionUpdated");
  4636. return this;
  4637. };
  4638. CustomMaterial.prototype.Vertex_Before_NormalUpdated = function (shaderPart) {
  4639. this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace("result", "normalUpdated");
  4640. return this;
  4641. };
  4642. CustomMaterial.ShaderIndexer = 1;
  4643. return CustomMaterial;
  4644. }(BABYLON.StandardMaterial));
  4645. BABYLON.CustomMaterial = CustomMaterial;
  4646. })(BABYLON || (BABYLON = {}));
  4647. //# sourceMappingURL=babylon.customMaterial.js.map
  4648. var BABYLON;
  4649. (function (BABYLON) {
  4650. var CellMaterialDefines = /** @class */ (function (_super) {
  4651. __extends(CellMaterialDefines, _super);
  4652. function CellMaterialDefines() {
  4653. var _this = _super.call(this) || this;
  4654. _this.DIFFUSE = false;
  4655. _this.CLIPPLANE = false;
  4656. _this.CLIPPLANE2 = false;
  4657. _this.CLIPPLANE3 = false;
  4658. _this.CLIPPLANE4 = false;
  4659. _this.ALPHATEST = false;
  4660. _this.POINTSIZE = false;
  4661. _this.FOG = false;
  4662. _this.NORMAL = false;
  4663. _this.UV1 = false;
  4664. _this.UV2 = false;
  4665. _this.VERTEXCOLOR = false;
  4666. _this.VERTEXALPHA = false;
  4667. _this.NUM_BONE_INFLUENCERS = 0;
  4668. _this.BonesPerMesh = 0;
  4669. _this.INSTANCES = false;
  4670. _this.NDOTL = true;
  4671. _this.CUSTOMUSERLIGHTING = true;
  4672. _this.CELLBASIC = true;
  4673. _this.DEPTHPREPASS = false;
  4674. _this.rebuild();
  4675. return _this;
  4676. }
  4677. return CellMaterialDefines;
  4678. }(BABYLON.MaterialDefines));
  4679. var CellMaterial = /** @class */ (function (_super) {
  4680. __extends(CellMaterial, _super);
  4681. function CellMaterial(name, scene) {
  4682. var _this = _super.call(this, name, scene) || this;
  4683. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  4684. _this._computeHighLevel = false;
  4685. _this._disableLighting = false;
  4686. _this._maxSimultaneousLights = 4;
  4687. return _this;
  4688. }
  4689. CellMaterial.prototype.needAlphaBlending = function () {
  4690. return (this.alpha < 1.0);
  4691. };
  4692. CellMaterial.prototype.needAlphaTesting = function () {
  4693. return false;
  4694. };
  4695. CellMaterial.prototype.getAlphaTestTexture = function () {
  4696. return null;
  4697. };
  4698. // Methods
  4699. CellMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  4700. if (this.isFrozen) {
  4701. if (this._wasPreviouslyReady && subMesh.effect) {
  4702. return true;
  4703. }
  4704. }
  4705. if (!subMesh._materialDefines) {
  4706. subMesh._materialDefines = new CellMaterialDefines();
  4707. }
  4708. var defines = subMesh._materialDefines;
  4709. var scene = this.getScene();
  4710. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  4711. if (this._renderId === scene.getRenderId()) {
  4712. return true;
  4713. }
  4714. }
  4715. var engine = scene.getEngine();
  4716. // Textures
  4717. if (defines._areTexturesDirty) {
  4718. defines._needUVs = false;
  4719. if (scene.texturesEnabled) {
  4720. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  4721. if (!this._diffuseTexture.isReady()) {
  4722. return false;
  4723. }
  4724. else {
  4725. defines._needUVs = true;
  4726. defines.DIFFUSE = true;
  4727. }
  4728. }
  4729. }
  4730. }
  4731. // High level
  4732. defines.CELLBASIC = !this.computeHighLevel;
  4733. // Misc.
  4734. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  4735. // Lights
  4736. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  4737. // Values that need to be evaluated on every frame
  4738. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  4739. // Attribs
  4740. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  4741. // Get correct effect
  4742. if (defines.isDirty) {
  4743. defines.markAsProcessed();
  4744. scene.resetCachedMaterial();
  4745. // Fallbacks
  4746. var fallbacks = new BABYLON.EffectFallbacks();
  4747. if (defines.FOG) {
  4748. fallbacks.addFallback(1, "FOG");
  4749. }
  4750. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  4751. if (defines.NUM_BONE_INFLUENCERS > 0) {
  4752. fallbacks.addCPUSkinningFallback(0, mesh);
  4753. }
  4754. //Attributes
  4755. var attribs = [BABYLON.VertexBuffer.PositionKind];
  4756. if (defines.NORMAL) {
  4757. attribs.push(BABYLON.VertexBuffer.NormalKind);
  4758. }
  4759. if (defines.UV1) {
  4760. attribs.push(BABYLON.VertexBuffer.UVKind);
  4761. }
  4762. if (defines.UV2) {
  4763. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  4764. }
  4765. if (defines.VERTEXCOLOR) {
  4766. attribs.push(BABYLON.VertexBuffer.ColorKind);
  4767. }
  4768. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  4769. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  4770. var shaderName = "cell";
  4771. var join = defines.toString();
  4772. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  4773. "vFogInfos", "vFogColor", "pointSize",
  4774. "vDiffuseInfos",
  4775. "mBones",
  4776. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix"
  4777. ];
  4778. var samplers = ["diffuseSampler"];
  4779. var uniformBuffers = new Array();
  4780. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  4781. uniformsNames: uniforms,
  4782. uniformBuffersNames: uniformBuffers,
  4783. samplers: samplers,
  4784. defines: defines,
  4785. maxSimultaneousLights: this.maxSimultaneousLights
  4786. });
  4787. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  4788. attributes: attribs,
  4789. uniformsNames: uniforms,
  4790. uniformBuffersNames: uniformBuffers,
  4791. samplers: samplers,
  4792. defines: join,
  4793. fallbacks: fallbacks,
  4794. onCompiled: this.onCompiled,
  4795. onError: this.onError,
  4796. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights - 1 }
  4797. }, engine), defines);
  4798. }
  4799. if (!subMesh.effect || !subMesh.effect.isReady()) {
  4800. return false;
  4801. }
  4802. this._renderId = scene.getRenderId();
  4803. this._wasPreviouslyReady = true;
  4804. return true;
  4805. };
  4806. CellMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  4807. var scene = this.getScene();
  4808. var defines = subMesh._materialDefines;
  4809. if (!defines) {
  4810. return;
  4811. }
  4812. var effect = subMesh.effect;
  4813. if (!effect) {
  4814. return;
  4815. }
  4816. this._activeEffect = effect;
  4817. // Matrices
  4818. this.bindOnlyWorldMatrix(world);
  4819. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  4820. // Bones
  4821. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  4822. if (this._mustRebind(scene, effect)) {
  4823. // Textures
  4824. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  4825. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  4826. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  4827. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  4828. }
  4829. // Clip plane
  4830. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  4831. // Point size
  4832. if (this.pointsCloud) {
  4833. this._activeEffect.setFloat("pointSize", this.pointSize);
  4834. }
  4835. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  4836. }
  4837. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  4838. // Lights
  4839. if (scene.lightsEnabled && !this.disableLighting) {
  4840. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this._maxSimultaneousLights);
  4841. }
  4842. // View
  4843. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  4844. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  4845. }
  4846. // Fog
  4847. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  4848. this._afterBind(mesh, this._activeEffect);
  4849. };
  4850. CellMaterial.prototype.getAnimatables = function () {
  4851. var results = [];
  4852. if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
  4853. results.push(this._diffuseTexture);
  4854. }
  4855. return results;
  4856. };
  4857. CellMaterial.prototype.getActiveTextures = function () {
  4858. var activeTextures = _super.prototype.getActiveTextures.call(this);
  4859. if (this._diffuseTexture) {
  4860. activeTextures.push(this._diffuseTexture);
  4861. }
  4862. return activeTextures;
  4863. };
  4864. CellMaterial.prototype.hasTexture = function (texture) {
  4865. if (_super.prototype.hasTexture.call(this, texture)) {
  4866. return true;
  4867. }
  4868. return this._diffuseTexture === texture;
  4869. };
  4870. CellMaterial.prototype.dispose = function (forceDisposeEffect) {
  4871. if (this._diffuseTexture) {
  4872. this._diffuseTexture.dispose();
  4873. }
  4874. _super.prototype.dispose.call(this, forceDisposeEffect);
  4875. };
  4876. CellMaterial.prototype.getClassName = function () {
  4877. return "CellMaterial";
  4878. };
  4879. CellMaterial.prototype.clone = function (name) {
  4880. var _this = this;
  4881. return BABYLON.SerializationHelper.Clone(function () { return new CellMaterial(name, _this.getScene()); }, this);
  4882. };
  4883. CellMaterial.prototype.serialize = function () {
  4884. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  4885. serializationObject.customType = "BABYLON.CellMaterial";
  4886. return serializationObject;
  4887. };
  4888. // Statics
  4889. CellMaterial.Parse = function (source, scene, rootUrl) {
  4890. return BABYLON.SerializationHelper.Parse(function () { return new CellMaterial(source.name, scene); }, source, scene, rootUrl);
  4891. };
  4892. __decorate([
  4893. BABYLON.serializeAsTexture("diffuseTexture")
  4894. ], CellMaterial.prototype, "_diffuseTexture", void 0);
  4895. __decorate([
  4896. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4897. ], CellMaterial.prototype, "diffuseTexture", void 0);
  4898. __decorate([
  4899. BABYLON.serializeAsColor3("diffuse")
  4900. ], CellMaterial.prototype, "diffuseColor", void 0);
  4901. __decorate([
  4902. BABYLON.serialize("computeHighLevel")
  4903. ], CellMaterial.prototype, "_computeHighLevel", void 0);
  4904. __decorate([
  4905. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4906. ], CellMaterial.prototype, "computeHighLevel", void 0);
  4907. __decorate([
  4908. BABYLON.serialize("disableLighting")
  4909. ], CellMaterial.prototype, "_disableLighting", void 0);
  4910. __decorate([
  4911. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  4912. ], CellMaterial.prototype, "disableLighting", void 0);
  4913. __decorate([
  4914. BABYLON.serialize("maxSimultaneousLights")
  4915. ], CellMaterial.prototype, "_maxSimultaneousLights", void 0);
  4916. __decorate([
  4917. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  4918. ], CellMaterial.prototype, "maxSimultaneousLights", void 0);
  4919. return CellMaterial;
  4920. }(BABYLON.PushMaterial));
  4921. BABYLON.CellMaterial = CellMaterial;
  4922. })(BABYLON || (BABYLON = {}));
  4923. //# sourceMappingURL=babylon.cellMaterial.js.map
  4924. 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";
  4925. 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}";
  4926. return BABYLON;
  4927. });