babylonjs.materials.js 283 KB

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