babylonjs.materials.js 280 KB

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