babylonjs.materials.js 338 KB

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