babylonjs.materials.js 315 KB

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