babylonjs.materials.js 501 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640
  1. var babylonDependency; try { babylonDependency = BABYLON || (typeof require !== 'undefined' && require("../babylon.max")); } catch (e) { babylonDependency = BABYLON || (typeof require !== 'undefined' && require("babylonjs")); }
  2. var BABYLON = babylonDependency;
  3. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  4. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  5. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  6. 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;
  7. return c > 3 && r && Object.defineProperty(target, key, r), r;
  8. };
  9. var __extends = (this && this.__extends) || (function () {
  10. var extendStatics = Object.setPrototypeOf ||
  11. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  12. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  13. return function (d, b) {
  14. extendStatics(d, b);
  15. function __() { this.constructor = d; }
  16. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  17. };
  18. })();
  19. var BABYLON;
  20. (function (BABYLON) {
  21. var ShadowOnlyMaterialDefines = /** @class */ (function (_super) {
  22. __extends(ShadowOnlyMaterialDefines, _super);
  23. function ShadowOnlyMaterialDefines() {
  24. var _this = _super.call(this) || this;
  25. _this.CLIPPLANE = false;
  26. _this.POINTSIZE = false;
  27. _this.FOG = false;
  28. _this.NORMAL = false;
  29. _this.NUM_BONE_INFLUENCERS = 0;
  30. _this.BonesPerMesh = 0;
  31. _this.INSTANCES = false;
  32. _this.rebuild();
  33. return _this;
  34. }
  35. return ShadowOnlyMaterialDefines;
  36. }(BABYLON.MaterialDefines));
  37. var ShadowOnlyMaterial = /** @class */ (function (_super) {
  38. __extends(ShadowOnlyMaterial, _super);
  39. function ShadowOnlyMaterial(name, scene) {
  40. return _super.call(this, name, scene) || this;
  41. }
  42. ShadowOnlyMaterial.prototype.needAlphaBlending = function () {
  43. return true;
  44. };
  45. ShadowOnlyMaterial.prototype.needAlphaTesting = function () {
  46. return false;
  47. };
  48. ShadowOnlyMaterial.prototype.getAlphaTestTexture = function () {
  49. return null;
  50. };
  51. Object.defineProperty(ShadowOnlyMaterial.prototype, "activeLight", {
  52. get: function () {
  53. return this._activeLight;
  54. },
  55. set: function (light) {
  56. this._activeLight = light;
  57. },
  58. enumerable: true,
  59. configurable: true
  60. });
  61. // Methods
  62. ShadowOnlyMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  63. if (this.isFrozen) {
  64. if (this._wasPreviouslyReady && subMesh.effect) {
  65. return true;
  66. }
  67. }
  68. if (!subMesh._materialDefines) {
  69. subMesh._materialDefines = new ShadowOnlyMaterialDefines();
  70. }
  71. var defines = subMesh._materialDefines;
  72. var scene = this.getScene();
  73. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  74. if (this._renderId === scene.getRenderId()) {
  75. return true;
  76. }
  77. }
  78. var engine = scene.getEngine();
  79. // Ensure that active light is the first shadow light
  80. if (this._activeLight) {
  81. for (var _i = 0, _a = mesh._lightSources; _i < _a.length; _i++) {
  82. var light = _a[_i];
  83. if (light.shadowEnabled) {
  84. if (this._activeLight === light) {
  85. break; // We are good
  86. }
  87. var lightPosition = mesh._lightSources.indexOf(this._activeLight);
  88. if (lightPosition !== -1) {
  89. mesh._lightSources.splice(lightPosition, 1);
  90. mesh._lightSources.splice(0, 0, this._activeLight);
  91. }
  92. break;
  93. }
  94. }
  95. }
  96. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  97. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  98. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);
  99. // Attribs
  100. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
  101. // Get correct effect
  102. if (defines.isDirty) {
  103. defines.markAsProcessed();
  104. scene.resetCachedMaterial();
  105. // Fallbacks
  106. var fallbacks = new BABYLON.EffectFallbacks();
  107. if (defines.FOG) {
  108. fallbacks.addFallback(1, "FOG");
  109. }
  110. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, 1);
  111. if (defines.NUM_BONE_INFLUENCERS > 0) {
  112. fallbacks.addCPUSkinningFallback(0, mesh);
  113. }
  114. //Attributes
  115. var attribs = [BABYLON.VertexBuffer.PositionKind];
  116. if (defines.NORMAL) {
  117. attribs.push(BABYLON.VertexBuffer.NormalKind);
  118. }
  119. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  120. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  121. var shaderName = "shadowOnly";
  122. var join = defines.toString();
  123. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType",
  124. "vFogInfos", "vFogColor", "pointSize", "alpha",
  125. "mBones",
  126. "vClipPlane"
  127. ];
  128. var samplers = new Array();
  129. var uniformBuffers = new Array();
  130. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  131. uniformsNames: uniforms,
  132. uniformBuffersNames: uniformBuffers,
  133. samplers: samplers,
  134. defines: defines,
  135. maxSimultaneousLights: 1
  136. });
  137. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  138. attributes: attribs,
  139. uniformsNames: uniforms,
  140. uniformBuffersNames: uniformBuffers,
  141. samplers: samplers,
  142. defines: join,
  143. fallbacks: fallbacks,
  144. onCompiled: this.onCompiled,
  145. onError: this.onError,
  146. indexParameters: { maxSimultaneousLights: 1 }
  147. }, engine), defines);
  148. }
  149. if (!subMesh.effect || !subMesh.effect.isReady()) {
  150. return false;
  151. }
  152. this._renderId = scene.getRenderId();
  153. this._wasPreviouslyReady = true;
  154. return true;
  155. };
  156. ShadowOnlyMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  157. var scene = this.getScene();
  158. var defines = subMesh._materialDefines;
  159. if (!defines) {
  160. return;
  161. }
  162. var effect = subMesh.effect;
  163. if (!effect) {
  164. return;
  165. }
  166. this._activeEffect = effect;
  167. // Matrices
  168. this.bindOnlyWorldMatrix(world);
  169. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  170. // Bones
  171. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  172. if (this._mustRebind(scene, effect)) {
  173. // Clip plane
  174. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  175. // Point size
  176. if (this.pointsCloud) {
  177. this._activeEffect.setFloat("pointSize", this.pointSize);
  178. }
  179. this._activeEffect.setFloat("alpha", this.alpha);
  180. this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  181. }
  182. // Lights
  183. if (scene.lightsEnabled) {
  184. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, 1);
  185. }
  186. // View
  187. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  188. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  189. }
  190. // Fog
  191. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  192. this._afterBind(mesh, this._activeEffect);
  193. };
  194. ShadowOnlyMaterial.prototype.clone = function (name) {
  195. var _this = this;
  196. return BABYLON.SerializationHelper.Clone(function () { return new ShadowOnlyMaterial(name, _this.getScene()); }, this);
  197. };
  198. ShadowOnlyMaterial.prototype.serialize = function () {
  199. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  200. serializationObject.customType = "BABYLON.ShadowOnlyMaterial";
  201. return serializationObject;
  202. };
  203. ShadowOnlyMaterial.prototype.getClassName = function () {
  204. return "ShadowOnlyMaterial";
  205. };
  206. // Statics
  207. ShadowOnlyMaterial.Parse = function (source, scene, rootUrl) {
  208. return BABYLON.SerializationHelper.Parse(function () { return new ShadowOnlyMaterial(source.name, scene); }, source, scene, rootUrl);
  209. };
  210. return ShadowOnlyMaterial;
  211. }(BABYLON.PushMaterial));
  212. BABYLON.ShadowOnlyMaterial = ShadowOnlyMaterial;
  213. })(BABYLON || (BABYLON = {}));
  214. //# sourceMappingURL=babylon.shadowOnlyMaterial.js.map
  215. 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";
  216. 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}";
  217. var BABYLON;
  218. (function (BABYLON) {
  219. var GradientMaterialDefines = /** @class */ (function (_super) {
  220. __extends(GradientMaterialDefines, _super);
  221. function GradientMaterialDefines() {
  222. var _this = _super.call(this) || this;
  223. _this.DIFFUSE = false;
  224. _this.CLIPPLANE = false;
  225. _this.ALPHATEST = false;
  226. _this.DEPTHPREPASS = false;
  227. _this.POINTSIZE = false;
  228. _this.FOG = false;
  229. _this.LIGHT0 = false;
  230. _this.LIGHT1 = false;
  231. _this.LIGHT2 = false;
  232. _this.LIGHT3 = false;
  233. _this.SPOTLIGHT0 = false;
  234. _this.SPOTLIGHT1 = false;
  235. _this.SPOTLIGHT2 = false;
  236. _this.SPOTLIGHT3 = false;
  237. _this.HEMILIGHT0 = false;
  238. _this.HEMILIGHT1 = false;
  239. _this.HEMILIGHT2 = false;
  240. _this.HEMILIGHT3 = false;
  241. _this.DIRLIGHT0 = false;
  242. _this.DIRLIGHT1 = false;
  243. _this.DIRLIGHT2 = false;
  244. _this.DIRLIGHT3 = false;
  245. _this.POINTLIGHT0 = false;
  246. _this.POINTLIGHT1 = false;
  247. _this.POINTLIGHT2 = false;
  248. _this.POINTLIGHT3 = false;
  249. _this.SHADOW0 = false;
  250. _this.SHADOW1 = false;
  251. _this.SHADOW2 = false;
  252. _this.SHADOW3 = false;
  253. _this.SHADOWS = false;
  254. _this.SHADOWESM0 = false;
  255. _this.SHADOWESM1 = false;
  256. _this.SHADOWESM2 = false;
  257. _this.SHADOWESM3 = false;
  258. _this.SHADOWPCF0 = false;
  259. _this.SHADOWPCF1 = false;
  260. _this.SHADOWPCF2 = false;
  261. _this.SHADOWPCF3 = false;
  262. _this.NORMAL = false;
  263. _this.UV1 = false;
  264. _this.UV2 = false;
  265. _this.VERTEXCOLOR = false;
  266. _this.VERTEXALPHA = false;
  267. _this.NUM_BONE_INFLUENCERS = 0;
  268. _this.BonesPerMesh = 0;
  269. _this.INSTANCES = false;
  270. _this.rebuild();
  271. return _this;
  272. }
  273. return GradientMaterialDefines;
  274. }(BABYLON.MaterialDefines));
  275. var GradientMaterial = /** @class */ (function (_super) {
  276. __extends(GradientMaterial, _super);
  277. function GradientMaterial(name, scene) {
  278. var _this = _super.call(this, name, scene) || this;
  279. _this._maxSimultaneousLights = 4;
  280. // The gradient top color, red by default
  281. _this.topColor = new BABYLON.Color3(1, 0, 0);
  282. _this.topColorAlpha = 1.0;
  283. // The gradient top color, blue by default
  284. _this.bottomColor = new BABYLON.Color3(0, 0, 1);
  285. _this.bottomColorAlpha = 1.0;
  286. // Gradient offset
  287. _this.offset = 0;
  288. _this.smoothness = 1.0;
  289. _this.disableLighting = false;
  290. _this._scaledDiffuse = new BABYLON.Color3();
  291. return _this;
  292. }
  293. GradientMaterial.prototype.needAlphaBlending = function () {
  294. return (this.alpha < 1.0 || this.topColorAlpha < 1.0 || this.bottomColorAlpha < 1.0);
  295. };
  296. GradientMaterial.prototype.needAlphaTesting = function () {
  297. return true;
  298. };
  299. GradientMaterial.prototype.getAlphaTestTexture = function () {
  300. return null;
  301. };
  302. // Methods
  303. GradientMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  304. if (this.isFrozen) {
  305. if (this._wasPreviouslyReady && subMesh.effect) {
  306. return true;
  307. }
  308. }
  309. if (!subMesh._materialDefines) {
  310. subMesh._materialDefines = new GradientMaterialDefines();
  311. }
  312. var defines = subMesh._materialDefines;
  313. var scene = this.getScene();
  314. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  315. if (this._renderId === scene.getRenderId()) {
  316. return true;
  317. }
  318. }
  319. var engine = scene.getEngine();
  320. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  321. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  322. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights);
  323. // Attribs
  324. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
  325. // Get correct effect
  326. if (defines.isDirty) {
  327. defines.markAsProcessed();
  328. scene.resetCachedMaterial();
  329. // Fallbacks
  330. var fallbacks = new BABYLON.EffectFallbacks();
  331. if (defines.FOG) {
  332. fallbacks.addFallback(1, "FOG");
  333. }
  334. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
  335. if (defines.NUM_BONE_INFLUENCERS > 0) {
  336. fallbacks.addCPUSkinningFallback(0, mesh);
  337. }
  338. //Attributes
  339. var attribs = [BABYLON.VertexBuffer.PositionKind];
  340. if (defines.NORMAL) {
  341. attribs.push(BABYLON.VertexBuffer.NormalKind);
  342. }
  343. if (defines.UV1) {
  344. attribs.push(BABYLON.VertexBuffer.UVKind);
  345. }
  346. if (defines.UV2) {
  347. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  348. }
  349. if (defines.VERTEXCOLOR) {
  350. attribs.push(BABYLON.VertexBuffer.ColorKind);
  351. }
  352. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  353. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  354. // Legacy browser patch
  355. var shaderName = "gradient";
  356. var join = defines.toString();
  357. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  358. "vFogInfos", "vFogColor", "pointSize",
  359. "vDiffuseInfos",
  360. "mBones",
  361. "vClipPlane", "diffuseMatrix",
  362. "topColor", "bottomColor", "offset", "smoothness"
  363. ];
  364. var samplers = ["diffuseSampler"];
  365. var uniformBuffers = new Array();
  366. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  367. uniformsNames: uniforms,
  368. uniformBuffersNames: uniformBuffers,
  369. samplers: samplers,
  370. defines: defines,
  371. maxSimultaneousLights: 4
  372. });
  373. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  374. attributes: attribs,
  375. uniformsNames: uniforms,
  376. uniformBuffersNames: uniformBuffers,
  377. samplers: samplers,
  378. defines: join,
  379. fallbacks: fallbacks,
  380. onCompiled: this.onCompiled,
  381. onError: this.onError,
  382. indexParameters: { maxSimultaneousLights: 4 }
  383. }, engine), defines);
  384. }
  385. if (!subMesh.effect || !subMesh.effect.isReady()) {
  386. return false;
  387. }
  388. this._renderId = scene.getRenderId();
  389. this._wasPreviouslyReady = true;
  390. return true;
  391. };
  392. GradientMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  393. var scene = this.getScene();
  394. var defines = subMesh._materialDefines;
  395. if (!defines) {
  396. return;
  397. }
  398. var effect = subMesh.effect;
  399. if (!effect) {
  400. return;
  401. }
  402. this._activeEffect = effect;
  403. // Matrices
  404. this.bindOnlyWorldMatrix(world);
  405. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  406. // Bones
  407. BABYLON.MaterialHelper.BindBonesParameters(mesh, effect);
  408. if (this._mustRebind(scene, effect)) {
  409. // Clip plane
  410. BABYLON.MaterialHelper.BindClipPlane(effect, scene);
  411. // Point size
  412. if (this.pointsCloud) {
  413. this._activeEffect.setFloat("pointSize", this.pointSize);
  414. }
  415. this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  416. }
  417. this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  418. if (scene.lightsEnabled && !this.disableLighting) {
  419. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines);
  420. }
  421. // View
  422. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  423. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  424. }
  425. // Fog
  426. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  427. this._activeEffect.setColor4("topColor", this.topColor, this.topColorAlpha);
  428. this._activeEffect.setColor4("bottomColor", this.bottomColor, this.bottomColorAlpha);
  429. this._activeEffect.setFloat("offset", this.offset);
  430. this._activeEffect.setFloat("smoothness", this.smoothness);
  431. this._afterBind(mesh, this._activeEffect);
  432. };
  433. GradientMaterial.prototype.getAnimatables = function () {
  434. return [];
  435. };
  436. GradientMaterial.prototype.dispose = function (forceDisposeEffect) {
  437. _super.prototype.dispose.call(this, forceDisposeEffect);
  438. };
  439. GradientMaterial.prototype.clone = function (name) {
  440. var _this = this;
  441. return BABYLON.SerializationHelper.Clone(function () { return new GradientMaterial(name, _this.getScene()); }, this);
  442. };
  443. GradientMaterial.prototype.serialize = function () {
  444. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  445. serializationObject.customType = "BABYLON.GradientMaterial";
  446. return serializationObject;
  447. };
  448. GradientMaterial.prototype.getClassName = function () {
  449. return "GradientMaterial";
  450. };
  451. // Statics
  452. GradientMaterial.Parse = function (source, scene, rootUrl) {
  453. return BABYLON.SerializationHelper.Parse(function () { return new GradientMaterial(source.name, scene); }, source, scene, rootUrl);
  454. };
  455. __decorate([
  456. BABYLON.serialize("maxSimultaneousLights")
  457. ], GradientMaterial.prototype, "_maxSimultaneousLights", void 0);
  458. __decorate([
  459. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  460. ], GradientMaterial.prototype, "maxSimultaneousLights", void 0);
  461. __decorate([
  462. BABYLON.serializeAsColor3()
  463. ], GradientMaterial.prototype, "topColor", void 0);
  464. __decorate([
  465. BABYLON.serialize()
  466. ], GradientMaterial.prototype, "topColorAlpha", void 0);
  467. __decorate([
  468. BABYLON.serializeAsColor3()
  469. ], GradientMaterial.prototype, "bottomColor", void 0);
  470. __decorate([
  471. BABYLON.serialize()
  472. ], GradientMaterial.prototype, "bottomColorAlpha", void 0);
  473. __decorate([
  474. BABYLON.serialize()
  475. ], GradientMaterial.prototype, "offset", void 0);
  476. __decorate([
  477. BABYLON.serialize()
  478. ], GradientMaterial.prototype, "smoothness", void 0);
  479. __decorate([
  480. BABYLON.serialize()
  481. ], GradientMaterial.prototype, "disableLighting", void 0);
  482. return GradientMaterial;
  483. }(BABYLON.PushMaterial));
  484. BABYLON.GradientMaterial = GradientMaterial;
  485. })(BABYLON || (BABYLON = {}));
  486. //# sourceMappingURL=babylon.gradientMaterial.js.map
  487. 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";
  488. 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";
  489. var BABYLON;
  490. (function (BABYLON) {
  491. var NormalMaterialDefines = /** @class */ (function (_super) {
  492. __extends(NormalMaterialDefines, _super);
  493. function NormalMaterialDefines() {
  494. var _this = _super.call(this) || this;
  495. _this.DIFFUSE = false;
  496. _this.CLIPPLANE = false;
  497. _this.ALPHATEST = false;
  498. _this.DEPTHPREPASS = false;
  499. _this.POINTSIZE = false;
  500. _this.FOG = false;
  501. _this.LIGHT0 = false;
  502. _this.LIGHT1 = false;
  503. _this.LIGHT2 = false;
  504. _this.LIGHT3 = false;
  505. _this.SPOTLIGHT0 = false;
  506. _this.SPOTLIGHT1 = false;
  507. _this.SPOTLIGHT2 = false;
  508. _this.SPOTLIGHT3 = false;
  509. _this.HEMILIGHT0 = false;
  510. _this.HEMILIGHT1 = false;
  511. _this.HEMILIGHT2 = false;
  512. _this.HEMILIGHT3 = false;
  513. _this.DIRLIGHT0 = false;
  514. _this.DIRLIGHT1 = false;
  515. _this.DIRLIGHT2 = false;
  516. _this.DIRLIGHT3 = false;
  517. _this.POINTLIGHT0 = false;
  518. _this.POINTLIGHT1 = false;
  519. _this.POINTLIGHT2 = false;
  520. _this.POINTLIGHT3 = false;
  521. _this.SHADOW0 = false;
  522. _this.SHADOW1 = false;
  523. _this.SHADOW2 = false;
  524. _this.SHADOW3 = false;
  525. _this.SHADOWS = false;
  526. _this.SHADOWESM0 = false;
  527. _this.SHADOWESM1 = false;
  528. _this.SHADOWESM2 = false;
  529. _this.SHADOWESM3 = false;
  530. _this.SHADOWPCF0 = false;
  531. _this.SHADOWPCF1 = false;
  532. _this.SHADOWPCF2 = false;
  533. _this.SHADOWPCF3 = false;
  534. _this.NORMAL = false;
  535. _this.UV1 = false;
  536. _this.UV2 = false;
  537. _this.VERTEXCOLOR = false;
  538. _this.VERTEXALPHA = false;
  539. _this.NUM_BONE_INFLUENCERS = 0;
  540. _this.BonesPerMesh = 0;
  541. _this.INSTANCES = false;
  542. _this.rebuild();
  543. return _this;
  544. }
  545. return NormalMaterialDefines;
  546. }(BABYLON.MaterialDefines));
  547. var NormalMaterial = /** @class */ (function (_super) {
  548. __extends(NormalMaterial, _super);
  549. function NormalMaterial(name, scene) {
  550. var _this = _super.call(this, name, scene) || this;
  551. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  552. _this._disableLighting = false;
  553. _this._maxSimultaneousLights = 4;
  554. return _this;
  555. }
  556. NormalMaterial.prototype.needAlphaBlending = function () {
  557. return (this.alpha < 1.0);
  558. };
  559. NormalMaterial.prototype.needAlphaTesting = function () {
  560. return false;
  561. };
  562. NormalMaterial.prototype.getAlphaTestTexture = function () {
  563. return null;
  564. };
  565. // Methods
  566. NormalMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  567. if (this.isFrozen) {
  568. if (this._wasPreviouslyReady && subMesh.effect) {
  569. return true;
  570. }
  571. }
  572. if (!subMesh._materialDefines) {
  573. subMesh._materialDefines = new NormalMaterialDefines();
  574. }
  575. var defines = subMesh._materialDefines;
  576. var scene = this.getScene();
  577. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  578. if (this._renderId === scene.getRenderId()) {
  579. return true;
  580. }
  581. }
  582. var engine = scene.getEngine();
  583. // Textures
  584. if (defines._areTexturesDirty) {
  585. defines._needUVs = false;
  586. if (scene.texturesEnabled) {
  587. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  588. if (!this._diffuseTexture.isReady()) {
  589. return false;
  590. }
  591. else {
  592. defines._needUVs = true;
  593. defines.DIFFUSE = true;
  594. }
  595. }
  596. }
  597. }
  598. // Misc.
  599. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  600. // Lights
  601. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  602. // Values that need to be evaluated on every frame
  603. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  604. // Attribs
  605. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  606. // Get correct effect
  607. if (defines.isDirty) {
  608. defines.markAsProcessed();
  609. scene.resetCachedMaterial();
  610. // Fallbacks
  611. var fallbacks = new BABYLON.EffectFallbacks();
  612. if (defines.FOG) {
  613. fallbacks.addFallback(1, "FOG");
  614. }
  615. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
  616. if (defines.NUM_BONE_INFLUENCERS > 0) {
  617. fallbacks.addCPUSkinningFallback(0, mesh);
  618. }
  619. //Attributes
  620. var attribs = [BABYLON.VertexBuffer.PositionKind];
  621. if (defines.NORMAL) {
  622. attribs.push(BABYLON.VertexBuffer.NormalKind);
  623. }
  624. if (defines.UV1) {
  625. attribs.push(BABYLON.VertexBuffer.UVKind);
  626. }
  627. if (defines.UV2) {
  628. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  629. }
  630. if (defines.VERTEXCOLOR) {
  631. attribs.push(BABYLON.VertexBuffer.ColorKind);
  632. }
  633. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  634. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  635. var shaderName = "normal";
  636. var join = defines.toString();
  637. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  638. "vFogInfos", "vFogColor", "pointSize",
  639. "vDiffuseInfos",
  640. "mBones",
  641. "vClipPlane", "diffuseMatrix"
  642. ];
  643. var samplers = ["diffuseSampler"];
  644. var uniformBuffers = new Array();
  645. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  646. uniformsNames: uniforms,
  647. uniformBuffersNames: uniformBuffers,
  648. samplers: samplers,
  649. defines: defines,
  650. maxSimultaneousLights: 4
  651. });
  652. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  653. attributes: attribs,
  654. uniformsNames: uniforms,
  655. uniformBuffersNames: uniformBuffers,
  656. samplers: samplers,
  657. defines: join,
  658. fallbacks: fallbacks,
  659. onCompiled: this.onCompiled,
  660. onError: this.onError,
  661. indexParameters: { maxSimultaneousLights: 4 }
  662. }, engine), defines);
  663. }
  664. if (!subMesh.effect || !subMesh.effect.isReady()) {
  665. return false;
  666. }
  667. this._renderId = scene.getRenderId();
  668. this._wasPreviouslyReady = true;
  669. return true;
  670. };
  671. NormalMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  672. var scene = this.getScene();
  673. var defines = subMesh._materialDefines;
  674. if (!defines) {
  675. return;
  676. }
  677. var effect = subMesh.effect;
  678. if (!effect) {
  679. return;
  680. }
  681. this._activeEffect = effect;
  682. // Matrices
  683. this.bindOnlyWorldMatrix(world);
  684. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  685. // Bones
  686. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  687. if (this._mustRebind(scene, effect)) {
  688. // Textures
  689. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  690. this._activeEffect.setTexture("diffuseSampler", this.diffuseTexture);
  691. this._activeEffect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
  692. this._activeEffect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
  693. }
  694. // Clip plane
  695. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  696. // Point size
  697. if (this.pointsCloud) {
  698. this._activeEffect.setFloat("pointSize", this.pointSize);
  699. }
  700. this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  701. }
  702. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  703. // Lights
  704. if (scene.lightsEnabled && !this.disableLighting) {
  705. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines);
  706. }
  707. // View
  708. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  709. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  710. }
  711. // Fog
  712. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  713. this._afterBind(mesh, this._activeEffect);
  714. };
  715. NormalMaterial.prototype.getAnimatables = function () {
  716. var results = [];
  717. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  718. results.push(this.diffuseTexture);
  719. }
  720. return results;
  721. };
  722. NormalMaterial.prototype.getActiveTextures = function () {
  723. var activeTextures = _super.prototype.getActiveTextures.call(this);
  724. if (this._diffuseTexture) {
  725. activeTextures.push(this._diffuseTexture);
  726. }
  727. return activeTextures;
  728. };
  729. NormalMaterial.prototype.hasTexture = function (texture) {
  730. if (_super.prototype.hasTexture.call(this, texture)) {
  731. return true;
  732. }
  733. if (this.diffuseTexture === texture) {
  734. return true;
  735. }
  736. return false;
  737. };
  738. NormalMaterial.prototype.dispose = function (forceDisposeEffect) {
  739. if (this.diffuseTexture) {
  740. this.diffuseTexture.dispose();
  741. }
  742. _super.prototype.dispose.call(this, forceDisposeEffect);
  743. };
  744. NormalMaterial.prototype.clone = function (name) {
  745. var _this = this;
  746. return BABYLON.SerializationHelper.Clone(function () { return new NormalMaterial(name, _this.getScene()); }, this);
  747. };
  748. NormalMaterial.prototype.serialize = function () {
  749. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  750. serializationObject.customType = "BABYLON.NormalMaterial";
  751. return serializationObject;
  752. };
  753. NormalMaterial.prototype.getClassName = function () {
  754. return "NormalMaterial";
  755. };
  756. // Statics
  757. NormalMaterial.Parse = function (source, scene, rootUrl) {
  758. return BABYLON.SerializationHelper.Parse(function () { return new NormalMaterial(source.name, scene); }, source, scene, rootUrl);
  759. };
  760. __decorate([
  761. BABYLON.serializeAsTexture("diffuseTexture")
  762. ], NormalMaterial.prototype, "_diffuseTexture", void 0);
  763. __decorate([
  764. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  765. ], NormalMaterial.prototype, "diffuseTexture", void 0);
  766. __decorate([
  767. BABYLON.serializeAsColor3()
  768. ], NormalMaterial.prototype, "diffuseColor", void 0);
  769. __decorate([
  770. BABYLON.serialize("disableLighting")
  771. ], NormalMaterial.prototype, "_disableLighting", void 0);
  772. __decorate([
  773. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  774. ], NormalMaterial.prototype, "disableLighting", void 0);
  775. __decorate([
  776. BABYLON.serialize("maxSimultaneousLights")
  777. ], NormalMaterial.prototype, "_maxSimultaneousLights", void 0);
  778. __decorate([
  779. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  780. ], NormalMaterial.prototype, "maxSimultaneousLights", void 0);
  781. return NormalMaterial;
  782. }(BABYLON.PushMaterial));
  783. BABYLON.NormalMaterial = NormalMaterial;
  784. })(BABYLON || (BABYLON = {}));
  785. //# sourceMappingURL=babylon.normalMaterial.js.map
  786. 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";
  787. 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}";
  788. var BABYLON;
  789. (function (BABYLON) {
  790. var LavaMaterialDefines = /** @class */ (function (_super) {
  791. __extends(LavaMaterialDefines, _super);
  792. function LavaMaterialDefines() {
  793. var _this = _super.call(this) || this;
  794. _this.DIFFUSE = false;
  795. _this.CLIPPLANE = false;
  796. _this.ALPHATEST = false;
  797. _this.DEPTHPREPASS = false;
  798. _this.POINTSIZE = false;
  799. _this.FOG = false;
  800. _this.LIGHT0 = false;
  801. _this.LIGHT1 = false;
  802. _this.LIGHT2 = false;
  803. _this.LIGHT3 = false;
  804. _this.SPOTLIGHT0 = false;
  805. _this.SPOTLIGHT1 = false;
  806. _this.SPOTLIGHT2 = false;
  807. _this.SPOTLIGHT3 = false;
  808. _this.HEMILIGHT0 = false;
  809. _this.HEMILIGHT1 = false;
  810. _this.HEMILIGHT2 = false;
  811. _this.HEMILIGHT3 = false;
  812. _this.DIRLIGHT0 = false;
  813. _this.DIRLIGHT1 = false;
  814. _this.DIRLIGHT2 = false;
  815. _this.DIRLIGHT3 = false;
  816. _this.POINTLIGHT0 = false;
  817. _this.POINTLIGHT1 = false;
  818. _this.POINTLIGHT2 = false;
  819. _this.POINTLIGHT3 = false;
  820. _this.SHADOW0 = false;
  821. _this.SHADOW1 = false;
  822. _this.SHADOW2 = false;
  823. _this.SHADOW3 = false;
  824. _this.SHADOWS = false;
  825. _this.SHADOWESM0 = false;
  826. _this.SHADOWESM1 = false;
  827. _this.SHADOWESM2 = false;
  828. _this.SHADOWESM3 = false;
  829. _this.SHADOWPCF0 = false;
  830. _this.SHADOWPCF1 = false;
  831. _this.SHADOWPCF2 = false;
  832. _this.SHADOWPCF3 = false;
  833. _this.NORMAL = false;
  834. _this.UV1 = false;
  835. _this.UV2 = false;
  836. _this.VERTEXCOLOR = false;
  837. _this.VERTEXALPHA = false;
  838. _this.NUM_BONE_INFLUENCERS = 0;
  839. _this.BonesPerMesh = 0;
  840. _this.INSTANCES = false;
  841. _this.rebuild();
  842. return _this;
  843. }
  844. return LavaMaterialDefines;
  845. }(BABYLON.MaterialDefines));
  846. var LavaMaterial = /** @class */ (function (_super) {
  847. __extends(LavaMaterial, _super);
  848. function LavaMaterial(name, scene) {
  849. var _this = _super.call(this, name, scene) || this;
  850. _this.speed = 1;
  851. _this.movingSpeed = 1;
  852. _this.lowFrequencySpeed = 1;
  853. _this.fogDensity = 0.15;
  854. _this._lastTime = 0;
  855. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  856. _this._disableLighting = false;
  857. _this._maxSimultaneousLights = 4;
  858. _this._scaledDiffuse = new BABYLON.Color3();
  859. return _this;
  860. }
  861. LavaMaterial.prototype.needAlphaBlending = function () {
  862. return (this.alpha < 1.0);
  863. };
  864. LavaMaterial.prototype.needAlphaTesting = function () {
  865. return false;
  866. };
  867. LavaMaterial.prototype.getAlphaTestTexture = function () {
  868. return null;
  869. };
  870. // Methods
  871. LavaMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  872. if (this.isFrozen) {
  873. if (this._wasPreviouslyReady && subMesh.effect) {
  874. return true;
  875. }
  876. }
  877. if (!subMesh._materialDefines) {
  878. subMesh._materialDefines = new LavaMaterialDefines();
  879. }
  880. var defines = subMesh._materialDefines;
  881. var scene = this.getScene();
  882. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  883. if (this._renderId === scene.getRenderId()) {
  884. return true;
  885. }
  886. }
  887. var engine = scene.getEngine();
  888. // Textures
  889. if (defines._areTexturesDirty) {
  890. defines._needUVs = false;
  891. if (scene.texturesEnabled) {
  892. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  893. if (!this._diffuseTexture.isReady()) {
  894. return false;
  895. }
  896. else {
  897. defines._needUVs = true;
  898. defines.DIFFUSE = true;
  899. }
  900. }
  901. }
  902. }
  903. // Misc.
  904. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  905. // Lights
  906. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  907. // Values that need to be evaluated on every frame
  908. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  909. // Attribs
  910. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  911. // Get correct effect
  912. if (defines.isDirty) {
  913. defines.markAsProcessed();
  914. scene.resetCachedMaterial();
  915. // Fallbacks
  916. var fallbacks = new BABYLON.EffectFallbacks();
  917. if (defines.FOG) {
  918. fallbacks.addFallback(1, "FOG");
  919. }
  920. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
  921. if (defines.NUM_BONE_INFLUENCERS > 0) {
  922. fallbacks.addCPUSkinningFallback(0, mesh);
  923. }
  924. //Attributes
  925. var attribs = [BABYLON.VertexBuffer.PositionKind];
  926. if (defines.NORMAL) {
  927. attribs.push(BABYLON.VertexBuffer.NormalKind);
  928. }
  929. if (defines.UV1) {
  930. attribs.push(BABYLON.VertexBuffer.UVKind);
  931. }
  932. if (defines.UV2) {
  933. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  934. }
  935. if (defines.VERTEXCOLOR) {
  936. attribs.push(BABYLON.VertexBuffer.ColorKind);
  937. }
  938. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  939. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  940. // Legacy browser patch
  941. var shaderName = "lava";
  942. var join = defines.toString();
  943. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  944. "vFogInfos", "vFogColor", "pointSize",
  945. "vDiffuseInfos",
  946. "mBones",
  947. "vClipPlane", "diffuseMatrix",
  948. "time", "speed", "movingSpeed",
  949. "fogColor", "fogDensity", "lowFrequencySpeed"
  950. ];
  951. var samplers = ["diffuseSampler",
  952. "noiseTexture"
  953. ];
  954. var uniformBuffers = new Array();
  955. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  956. uniformsNames: uniforms,
  957. uniformBuffersNames: uniformBuffers,
  958. samplers: samplers,
  959. defines: defines,
  960. maxSimultaneousLights: this.maxSimultaneousLights
  961. });
  962. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  963. attributes: attribs,
  964. uniformsNames: uniforms,
  965. uniformBuffersNames: uniformBuffers,
  966. samplers: samplers,
  967. defines: join,
  968. fallbacks: fallbacks,
  969. onCompiled: this.onCompiled,
  970. onError: this.onError,
  971. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  972. }, engine), defines);
  973. }
  974. if (!subMesh.effect || !subMesh.effect.isReady()) {
  975. return false;
  976. }
  977. this._renderId = scene.getRenderId();
  978. this._wasPreviouslyReady = true;
  979. return true;
  980. };
  981. LavaMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  982. var scene = this.getScene();
  983. var defines = subMesh._materialDefines;
  984. if (!defines) {
  985. return;
  986. }
  987. var effect = subMesh.effect;
  988. if (!effect) {
  989. return;
  990. }
  991. this._activeEffect = effect;
  992. // Matrices
  993. this.bindOnlyWorldMatrix(world);
  994. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  995. // Bones
  996. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  997. if (this._mustRebind(scene, effect)) {
  998. // Textures
  999. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  1000. this._activeEffect.setTexture("diffuseSampler", this.diffuseTexture);
  1001. this._activeEffect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
  1002. this._activeEffect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
  1003. }
  1004. if (this.noiseTexture) {
  1005. this._activeEffect.setTexture("noiseTexture", this.noiseTexture);
  1006. }
  1007. // Clip plane
  1008. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  1009. // Point size
  1010. if (this.pointsCloud) {
  1011. this._activeEffect.setFloat("pointSize", this.pointSize);
  1012. }
  1013. this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  1014. }
  1015. this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  1016. if (scene.lightsEnabled && !this.disableLighting) {
  1017. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines);
  1018. }
  1019. // View
  1020. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  1021. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  1022. }
  1023. // Fog
  1024. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  1025. this._lastTime += scene.getEngine().getDeltaTime();
  1026. this._activeEffect.setFloat("time", this._lastTime * this.speed / 1000);
  1027. if (!this.fogColor) {
  1028. this.fogColor = BABYLON.Color3.Black();
  1029. }
  1030. this._activeEffect.setColor3("fogColor", this.fogColor);
  1031. this._activeEffect.setFloat("fogDensity", this.fogDensity);
  1032. this._activeEffect.setFloat("lowFrequencySpeed", this.lowFrequencySpeed);
  1033. this._activeEffect.setFloat("movingSpeed", this.movingSpeed);
  1034. this._afterBind(mesh, this._activeEffect);
  1035. };
  1036. LavaMaterial.prototype.getAnimatables = function () {
  1037. var results = [];
  1038. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  1039. results.push(this.diffuseTexture);
  1040. }
  1041. if (this.noiseTexture && this.noiseTexture.animations && this.noiseTexture.animations.length > 0) {
  1042. results.push(this.noiseTexture);
  1043. }
  1044. return results;
  1045. };
  1046. LavaMaterial.prototype.getActiveTextures = function () {
  1047. var activeTextures = _super.prototype.getActiveTextures.call(this);
  1048. if (this._diffuseTexture) {
  1049. activeTextures.push(this._diffuseTexture);
  1050. }
  1051. return activeTextures;
  1052. };
  1053. LavaMaterial.prototype.hasTexture = function (texture) {
  1054. if (_super.prototype.hasTexture.call(this, texture)) {
  1055. return true;
  1056. }
  1057. if (this.diffuseTexture === texture) {
  1058. return true;
  1059. }
  1060. return false;
  1061. };
  1062. LavaMaterial.prototype.dispose = function (forceDisposeEffect) {
  1063. if (this.diffuseTexture) {
  1064. this.diffuseTexture.dispose();
  1065. }
  1066. if (this.noiseTexture) {
  1067. this.noiseTexture.dispose();
  1068. }
  1069. _super.prototype.dispose.call(this, forceDisposeEffect);
  1070. };
  1071. LavaMaterial.prototype.clone = function (name) {
  1072. var _this = this;
  1073. return BABYLON.SerializationHelper.Clone(function () { return new LavaMaterial(name, _this.getScene()); }, this);
  1074. };
  1075. LavaMaterial.prototype.serialize = function () {
  1076. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  1077. serializationObject.customType = "BABYLON.LavaMaterial";
  1078. return serializationObject;
  1079. };
  1080. LavaMaterial.prototype.getClassName = function () {
  1081. return "LavaMaterial";
  1082. };
  1083. // Statics
  1084. LavaMaterial.Parse = function (source, scene, rootUrl) {
  1085. return BABYLON.SerializationHelper.Parse(function () { return new LavaMaterial(source.name, scene); }, source, scene, rootUrl);
  1086. };
  1087. __decorate([
  1088. BABYLON.serializeAsTexture("diffuseTexture")
  1089. ], LavaMaterial.prototype, "_diffuseTexture", void 0);
  1090. __decorate([
  1091. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1092. ], LavaMaterial.prototype, "diffuseTexture", void 0);
  1093. __decorate([
  1094. BABYLON.serializeAsTexture()
  1095. ], LavaMaterial.prototype, "noiseTexture", void 0);
  1096. __decorate([
  1097. BABYLON.serializeAsColor3()
  1098. ], LavaMaterial.prototype, "fogColor", void 0);
  1099. __decorate([
  1100. BABYLON.serialize()
  1101. ], LavaMaterial.prototype, "speed", void 0);
  1102. __decorate([
  1103. BABYLON.serialize()
  1104. ], LavaMaterial.prototype, "movingSpeed", void 0);
  1105. __decorate([
  1106. BABYLON.serialize()
  1107. ], LavaMaterial.prototype, "lowFrequencySpeed", void 0);
  1108. __decorate([
  1109. BABYLON.serialize()
  1110. ], LavaMaterial.prototype, "fogDensity", void 0);
  1111. __decorate([
  1112. BABYLON.serializeAsColor3()
  1113. ], LavaMaterial.prototype, "diffuseColor", void 0);
  1114. __decorate([
  1115. BABYLON.serialize("disableLighting")
  1116. ], LavaMaterial.prototype, "_disableLighting", void 0);
  1117. __decorate([
  1118. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1119. ], LavaMaterial.prototype, "disableLighting", void 0);
  1120. __decorate([
  1121. BABYLON.serialize("maxSimultaneousLights")
  1122. ], LavaMaterial.prototype, "_maxSimultaneousLights", void 0);
  1123. __decorate([
  1124. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1125. ], LavaMaterial.prototype, "maxSimultaneousLights", void 0);
  1126. return LavaMaterial;
  1127. }(BABYLON.PushMaterial));
  1128. BABYLON.LavaMaterial = LavaMaterial;
  1129. })(BABYLON || (BABYLON = {}));
  1130. //# sourceMappingURL=babylon.lavaMaterial.js.map
  1131. 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}";
  1132. 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}";
  1133. var BABYLON;
  1134. (function (BABYLON) {
  1135. var SimpleMaterialDefines = /** @class */ (function (_super) {
  1136. __extends(SimpleMaterialDefines, _super);
  1137. function SimpleMaterialDefines() {
  1138. var _this = _super.call(this) || this;
  1139. _this.DIFFUSE = false;
  1140. _this.CLIPPLANE = false;
  1141. _this.ALPHATEST = false;
  1142. _this.DEPTHPREPASS = false;
  1143. _this.POINTSIZE = false;
  1144. _this.FOG = false;
  1145. _this.NORMAL = false;
  1146. _this.UV1 = false;
  1147. _this.UV2 = false;
  1148. _this.VERTEXCOLOR = false;
  1149. _this.VERTEXALPHA = false;
  1150. _this.NUM_BONE_INFLUENCERS = 0;
  1151. _this.BonesPerMesh = 0;
  1152. _this.INSTANCES = false;
  1153. _this.rebuild();
  1154. return _this;
  1155. }
  1156. return SimpleMaterialDefines;
  1157. }(BABYLON.MaterialDefines));
  1158. var SimpleMaterial = /** @class */ (function (_super) {
  1159. __extends(SimpleMaterial, _super);
  1160. function SimpleMaterial(name, scene) {
  1161. var _this = _super.call(this, name, scene) || this;
  1162. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  1163. _this._disableLighting = false;
  1164. _this._maxSimultaneousLights = 4;
  1165. return _this;
  1166. }
  1167. SimpleMaterial.prototype.needAlphaBlending = function () {
  1168. return (this.alpha < 1.0);
  1169. };
  1170. SimpleMaterial.prototype.needAlphaTesting = function () {
  1171. return false;
  1172. };
  1173. SimpleMaterial.prototype.getAlphaTestTexture = function () {
  1174. return null;
  1175. };
  1176. // Methods
  1177. SimpleMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  1178. if (this.isFrozen) {
  1179. if (this._wasPreviouslyReady && subMesh.effect) {
  1180. return true;
  1181. }
  1182. }
  1183. if (!subMesh._materialDefines) {
  1184. subMesh._materialDefines = new SimpleMaterialDefines();
  1185. }
  1186. var defines = subMesh._materialDefines;
  1187. var scene = this.getScene();
  1188. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  1189. if (this._renderId === scene.getRenderId()) {
  1190. return true;
  1191. }
  1192. }
  1193. var engine = scene.getEngine();
  1194. // Textures
  1195. if (defines._areTexturesDirty) {
  1196. defines._needUVs = false;
  1197. if (scene.texturesEnabled) {
  1198. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  1199. if (!this._diffuseTexture.isReady()) {
  1200. return false;
  1201. }
  1202. else {
  1203. defines._needUVs = true;
  1204. defines.DIFFUSE = true;
  1205. }
  1206. }
  1207. }
  1208. }
  1209. // Misc.
  1210. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  1211. // Lights
  1212. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  1213. // Values that need to be evaluated on every frame
  1214. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  1215. // Attribs
  1216. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  1217. // Get correct effect
  1218. if (defines.isDirty) {
  1219. defines.markAsProcessed();
  1220. scene.resetCachedMaterial();
  1221. // Fallbacks
  1222. var fallbacks = new BABYLON.EffectFallbacks();
  1223. if (defines.FOG) {
  1224. fallbacks.addFallback(1, "FOG");
  1225. }
  1226. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  1227. if (defines.NUM_BONE_INFLUENCERS > 0) {
  1228. fallbacks.addCPUSkinningFallback(0, mesh);
  1229. }
  1230. //Attributes
  1231. var attribs = [BABYLON.VertexBuffer.PositionKind];
  1232. if (defines.NORMAL) {
  1233. attribs.push(BABYLON.VertexBuffer.NormalKind);
  1234. }
  1235. if (defines.UV1) {
  1236. attribs.push(BABYLON.VertexBuffer.UVKind);
  1237. }
  1238. if (defines.UV2) {
  1239. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  1240. }
  1241. if (defines.VERTEXCOLOR) {
  1242. attribs.push(BABYLON.VertexBuffer.ColorKind);
  1243. }
  1244. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  1245. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  1246. var shaderName = "simple";
  1247. var join = defines.toString();
  1248. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  1249. "vFogInfos", "vFogColor", "pointSize",
  1250. "vDiffuseInfos",
  1251. "mBones",
  1252. "vClipPlane", "diffuseMatrix"
  1253. ];
  1254. var samplers = ["diffuseSampler"];
  1255. var uniformBuffers = new Array();
  1256. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  1257. uniformsNames: uniforms,
  1258. uniformBuffersNames: uniformBuffers,
  1259. samplers: samplers,
  1260. defines: defines,
  1261. maxSimultaneousLights: this.maxSimultaneousLights
  1262. });
  1263. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  1264. attributes: attribs,
  1265. uniformsNames: uniforms,
  1266. uniformBuffersNames: uniformBuffers,
  1267. samplers: samplers,
  1268. defines: join,
  1269. fallbacks: fallbacks,
  1270. onCompiled: this.onCompiled,
  1271. onError: this.onError,
  1272. indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights - 1 }
  1273. }, engine), defines);
  1274. }
  1275. if (!subMesh.effect || !subMesh.effect.isReady()) {
  1276. return false;
  1277. }
  1278. this._renderId = scene.getRenderId();
  1279. this._wasPreviouslyReady = true;
  1280. return true;
  1281. };
  1282. SimpleMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  1283. var scene = this.getScene();
  1284. var defines = subMesh._materialDefines;
  1285. if (!defines) {
  1286. return;
  1287. }
  1288. var effect = subMesh.effect;
  1289. if (!effect) {
  1290. return;
  1291. }
  1292. this._activeEffect = effect;
  1293. // Matrices
  1294. this.bindOnlyWorldMatrix(world);
  1295. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  1296. // Bones
  1297. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  1298. if (this._mustRebind(scene, effect)) {
  1299. // Textures
  1300. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  1301. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  1302. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  1303. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  1304. }
  1305. // Clip plane
  1306. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  1307. // Point size
  1308. if (this.pointsCloud) {
  1309. this._activeEffect.setFloat("pointSize", this.pointSize);
  1310. }
  1311. this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  1312. }
  1313. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  1314. // Lights
  1315. if (scene.lightsEnabled && !this.disableLighting) {
  1316. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  1317. }
  1318. // View
  1319. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  1320. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  1321. }
  1322. // Fog
  1323. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  1324. this._afterBind(mesh, this._activeEffect);
  1325. };
  1326. SimpleMaterial.prototype.getAnimatables = function () {
  1327. var results = [];
  1328. if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
  1329. results.push(this._diffuseTexture);
  1330. }
  1331. return results;
  1332. };
  1333. SimpleMaterial.prototype.getActiveTextures = function () {
  1334. var activeTextures = _super.prototype.getActiveTextures.call(this);
  1335. if (this._diffuseTexture) {
  1336. activeTextures.push(this._diffuseTexture);
  1337. }
  1338. return activeTextures;
  1339. };
  1340. SimpleMaterial.prototype.hasTexture = function (texture) {
  1341. if (_super.prototype.hasTexture.call(this, texture)) {
  1342. return true;
  1343. }
  1344. if (this.diffuseTexture === texture) {
  1345. return true;
  1346. }
  1347. return false;
  1348. };
  1349. SimpleMaterial.prototype.dispose = function (forceDisposeEffect) {
  1350. if (this._diffuseTexture) {
  1351. this._diffuseTexture.dispose();
  1352. }
  1353. _super.prototype.dispose.call(this, forceDisposeEffect);
  1354. };
  1355. SimpleMaterial.prototype.clone = function (name) {
  1356. var _this = this;
  1357. return BABYLON.SerializationHelper.Clone(function () { return new SimpleMaterial(name, _this.getScene()); }, this);
  1358. };
  1359. SimpleMaterial.prototype.serialize = function () {
  1360. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  1361. serializationObject.customType = "BABYLON.SimpleMaterial";
  1362. return serializationObject;
  1363. };
  1364. SimpleMaterial.prototype.getClassName = function () {
  1365. return "SimpleMaterial";
  1366. };
  1367. // Statics
  1368. SimpleMaterial.Parse = function (source, scene, rootUrl) {
  1369. return BABYLON.SerializationHelper.Parse(function () { return new SimpleMaterial(source.name, scene); }, source, scene, rootUrl);
  1370. };
  1371. __decorate([
  1372. BABYLON.serializeAsTexture("diffuseTexture")
  1373. ], SimpleMaterial.prototype, "_diffuseTexture", void 0);
  1374. __decorate([
  1375. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1376. ], SimpleMaterial.prototype, "diffuseTexture", void 0);
  1377. __decorate([
  1378. BABYLON.serializeAsColor3("diffuseColor")
  1379. ], SimpleMaterial.prototype, "diffuseColor", void 0);
  1380. __decorate([
  1381. BABYLON.serialize("disableLighting")
  1382. ], SimpleMaterial.prototype, "_disableLighting", void 0);
  1383. __decorate([
  1384. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1385. ], SimpleMaterial.prototype, "disableLighting", void 0);
  1386. __decorate([
  1387. BABYLON.serialize("maxSimultaneousLights")
  1388. ], SimpleMaterial.prototype, "_maxSimultaneousLights", void 0);
  1389. __decorate([
  1390. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1391. ], SimpleMaterial.prototype, "maxSimultaneousLights", void 0);
  1392. return SimpleMaterial;
  1393. }(BABYLON.PushMaterial));
  1394. BABYLON.SimpleMaterial = SimpleMaterial;
  1395. })(BABYLON || (BABYLON = {}));
  1396. //# sourceMappingURL=babylon.simpleMaterial.js.map
  1397. 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";
  1398. 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}";
  1399. var BABYLON;
  1400. (function (BABYLON) {
  1401. var WaterMaterialDefines = /** @class */ (function (_super) {
  1402. __extends(WaterMaterialDefines, _super);
  1403. function WaterMaterialDefines() {
  1404. var _this = _super.call(this) || this;
  1405. _this.BUMP = false;
  1406. _this.REFLECTION = false;
  1407. _this.CLIPPLANE = false;
  1408. _this.ALPHATEST = false;
  1409. _this.DEPTHPREPASS = false;
  1410. _this.POINTSIZE = false;
  1411. _this.FOG = false;
  1412. _this.NORMAL = false;
  1413. _this.UV1 = false;
  1414. _this.UV2 = false;
  1415. _this.VERTEXCOLOR = false;
  1416. _this.VERTEXALPHA = false;
  1417. _this.NUM_BONE_INFLUENCERS = 0;
  1418. _this.BonesPerMesh = 0;
  1419. _this.INSTANCES = false;
  1420. _this.SPECULARTERM = false;
  1421. _this.LOGARITHMICDEPTH = false;
  1422. _this.FRESNELSEPARATE = false;
  1423. _this.BUMPSUPERIMPOSE = false;
  1424. _this.BUMPAFFECTSREFLECTION = false;
  1425. _this.rebuild();
  1426. return _this;
  1427. }
  1428. return WaterMaterialDefines;
  1429. }(BABYLON.MaterialDefines));
  1430. var WaterMaterial = /** @class */ (function (_super) {
  1431. __extends(WaterMaterial, _super);
  1432. /**
  1433. * Constructor
  1434. */
  1435. function WaterMaterial(name, scene, renderTargetSize) {
  1436. if (renderTargetSize === void 0) { renderTargetSize = new BABYLON.Vector2(512, 512); }
  1437. var _this = _super.call(this, name, scene) || this;
  1438. _this.renderTargetSize = renderTargetSize;
  1439. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  1440. _this.specularColor = new BABYLON.Color3(0, 0, 0);
  1441. _this.specularPower = 64;
  1442. _this._disableLighting = false;
  1443. _this._maxSimultaneousLights = 4;
  1444. /**
  1445. * @param {number}: Represents the wind force
  1446. */
  1447. _this.windForce = 6;
  1448. /**
  1449. * @param {Vector2}: The direction of the wind in the plane (X, Z)
  1450. */
  1451. _this.windDirection = new BABYLON.Vector2(0, 1);
  1452. /**
  1453. * @param {number}: Wave height, represents the height of the waves
  1454. */
  1455. _this.waveHeight = 0.4;
  1456. /**
  1457. * @param {number}: Bump height, represents the bump height related to the bump map
  1458. */
  1459. _this.bumpHeight = 0.4;
  1460. /**
  1461. * @param {boolean}: Add a smaller moving bump to less steady waves.
  1462. */
  1463. _this._bumpSuperimpose = false;
  1464. /**
  1465. * @param {boolean}: Color refraction and reflection differently with .waterColor2 and .colorBlendFactor2. Non-linear (physically correct) fresnel.
  1466. */
  1467. _this._fresnelSeparate = false;
  1468. /**
  1469. * @param {boolean}: bump Waves modify the reflection.
  1470. */
  1471. _this._bumpAffectsReflection = false;
  1472. /**
  1473. * @param {number}: The water color blended with the refraction (near)
  1474. */
  1475. _this.waterColor = new BABYLON.Color3(0.1, 0.1, 0.6);
  1476. /**
  1477. * @param {number}: The blend factor related to the water color
  1478. */
  1479. _this.colorBlendFactor = 0.2;
  1480. /**
  1481. * @param {number}: The water color blended with the reflection (far)
  1482. */
  1483. _this.waterColor2 = new BABYLON.Color3(0.1, 0.1, 0.6);
  1484. /**
  1485. * @param {number}: The blend factor related to the water color (reflection, far)
  1486. */
  1487. _this.colorBlendFactor2 = 0.2;
  1488. /**
  1489. * @param {number}: Represents the maximum length of a wave
  1490. */
  1491. _this.waveLength = 0.1;
  1492. /**
  1493. * @param {number}: Defines the waves speed
  1494. */
  1495. _this.waveSpeed = 1.0;
  1496. _this._renderTargets = new BABYLON.SmartArray(16);
  1497. /*
  1498. * Private members
  1499. */
  1500. _this._mesh = null;
  1501. _this._reflectionTransform = BABYLON.Matrix.Zero();
  1502. _this._lastTime = 0;
  1503. _this._lastDeltaTime = 0;
  1504. _this._createRenderTargets(scene, renderTargetSize);
  1505. // Create render targets
  1506. _this.getRenderTargetTextures = function () {
  1507. _this._renderTargets.reset();
  1508. _this._renderTargets.push(_this._reflectionRTT);
  1509. _this._renderTargets.push(_this._refractionRTT);
  1510. return _this._renderTargets;
  1511. };
  1512. return _this;
  1513. }
  1514. Object.defineProperty(WaterMaterial.prototype, "useLogarithmicDepth", {
  1515. get: function () {
  1516. return this._useLogarithmicDepth;
  1517. },
  1518. set: function (value) {
  1519. this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;
  1520. this._markAllSubMeshesAsMiscDirty();
  1521. },
  1522. enumerable: true,
  1523. configurable: true
  1524. });
  1525. Object.defineProperty(WaterMaterial.prototype, "refractionTexture", {
  1526. // Get / Set
  1527. get: function () {
  1528. return this._refractionRTT;
  1529. },
  1530. enumerable: true,
  1531. configurable: true
  1532. });
  1533. Object.defineProperty(WaterMaterial.prototype, "reflectionTexture", {
  1534. get: function () {
  1535. return this._reflectionRTT;
  1536. },
  1537. enumerable: true,
  1538. configurable: true
  1539. });
  1540. // Methods
  1541. WaterMaterial.prototype.addToRenderList = function (node) {
  1542. if (this._refractionRTT.renderList) {
  1543. this._refractionRTT.renderList.push(node);
  1544. }
  1545. if (this._reflectionRTT.renderList) {
  1546. this._reflectionRTT.renderList.push(node);
  1547. }
  1548. };
  1549. WaterMaterial.prototype.enableRenderTargets = function (enable) {
  1550. var refreshRate = enable ? 1 : 0;
  1551. this._refractionRTT.refreshRate = refreshRate;
  1552. this._reflectionRTT.refreshRate = refreshRate;
  1553. };
  1554. WaterMaterial.prototype.getRenderList = function () {
  1555. return this._refractionRTT.renderList;
  1556. };
  1557. Object.defineProperty(WaterMaterial.prototype, "renderTargetsEnabled", {
  1558. get: function () {
  1559. return !(this._refractionRTT.refreshRate === 0);
  1560. },
  1561. enumerable: true,
  1562. configurable: true
  1563. });
  1564. WaterMaterial.prototype.needAlphaBlending = function () {
  1565. return (this.alpha < 1.0);
  1566. };
  1567. WaterMaterial.prototype.needAlphaTesting = function () {
  1568. return false;
  1569. };
  1570. WaterMaterial.prototype.getAlphaTestTexture = function () {
  1571. return null;
  1572. };
  1573. WaterMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  1574. if (this.isFrozen) {
  1575. if (this._wasPreviouslyReady && subMesh.effect) {
  1576. return true;
  1577. }
  1578. }
  1579. if (!subMesh._materialDefines) {
  1580. subMesh._materialDefines = new WaterMaterialDefines();
  1581. }
  1582. var defines = subMesh._materialDefines;
  1583. var scene = this.getScene();
  1584. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  1585. if (this._renderId === scene.getRenderId()) {
  1586. return true;
  1587. }
  1588. }
  1589. var engine = scene.getEngine();
  1590. // Textures
  1591. if (defines._areTexturesDirty) {
  1592. defines._needUVs = false;
  1593. if (scene.texturesEnabled) {
  1594. if (this.bumpTexture && BABYLON.StandardMaterial.BumpTextureEnabled) {
  1595. if (!this.bumpTexture.isReady()) {
  1596. return false;
  1597. }
  1598. else {
  1599. defines._needUVs = true;
  1600. defines.BUMP = true;
  1601. }
  1602. }
  1603. if (BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  1604. defines.REFLECTION = true;
  1605. }
  1606. }
  1607. }
  1608. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  1609. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
  1610. if (defines._areMiscDirty) {
  1611. if (this._fresnelSeparate) {
  1612. defines.FRESNELSEPARATE = true;
  1613. }
  1614. if (this._bumpSuperimpose) {
  1615. defines.BUMPSUPERIMPOSE = true;
  1616. }
  1617. if (this._bumpAffectsReflection) {
  1618. defines.BUMPAFFECTSREFLECTION = true;
  1619. }
  1620. }
  1621. // Lights
  1622. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);
  1623. // Attribs
  1624. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  1625. this._mesh = mesh;
  1626. // Get correct effect
  1627. if (defines.isDirty) {
  1628. defines.markAsProcessed();
  1629. scene.resetCachedMaterial();
  1630. // Fallbacks
  1631. var fallbacks = new BABYLON.EffectFallbacks();
  1632. if (defines.FOG) {
  1633. fallbacks.addFallback(1, "FOG");
  1634. }
  1635. if (defines.LOGARITHMICDEPTH) {
  1636. fallbacks.addFallback(0, "LOGARITHMICDEPTH");
  1637. }
  1638. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  1639. if (defines.NUM_BONE_INFLUENCERS > 0) {
  1640. fallbacks.addCPUSkinningFallback(0, mesh);
  1641. }
  1642. //Attributes
  1643. var attribs = [BABYLON.VertexBuffer.PositionKind];
  1644. if (defines.NORMAL) {
  1645. attribs.push(BABYLON.VertexBuffer.NormalKind);
  1646. }
  1647. if (defines.UV1) {
  1648. attribs.push(BABYLON.VertexBuffer.UVKind);
  1649. }
  1650. if (defines.UV2) {
  1651. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  1652. }
  1653. if (defines.VERTEXCOLOR) {
  1654. attribs.push(BABYLON.VertexBuffer.ColorKind);
  1655. }
  1656. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  1657. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  1658. // Legacy browser patch
  1659. var shaderName = "water";
  1660. var join = defines.toString();
  1661. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  1662. "vFogInfos", "vFogColor", "pointSize",
  1663. "vNormalInfos",
  1664. "mBones",
  1665. "vClipPlane", "normalMatrix",
  1666. "logarithmicDepthConstant",
  1667. // Water
  1668. "worldReflectionViewProjection", "windDirection", "waveLength", "time", "windForce",
  1669. "cameraPosition", "bumpHeight", "waveHeight", "waterColor", "waterColor2", "colorBlendFactor", "colorBlendFactor2", "waveSpeed"
  1670. ];
  1671. var samplers = ["normalSampler",
  1672. // Water
  1673. "refractionSampler", "reflectionSampler"
  1674. ];
  1675. var uniformBuffers = new Array();
  1676. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  1677. uniformsNames: uniforms,
  1678. uniformBuffersNames: uniformBuffers,
  1679. samplers: samplers,
  1680. defines: defines,
  1681. maxSimultaneousLights: this.maxSimultaneousLights
  1682. });
  1683. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  1684. attributes: attribs,
  1685. uniformsNames: uniforms,
  1686. uniformBuffersNames: uniformBuffers,
  1687. samplers: samplers,
  1688. defines: join,
  1689. fallbacks: fallbacks,
  1690. onCompiled: this.onCompiled,
  1691. onError: this.onError,
  1692. indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights }
  1693. }, engine), defines);
  1694. }
  1695. if (!subMesh.effect || !subMesh.effect.isReady()) {
  1696. return false;
  1697. }
  1698. this._renderId = scene.getRenderId();
  1699. this._wasPreviouslyReady = true;
  1700. return true;
  1701. };
  1702. WaterMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  1703. var scene = this.getScene();
  1704. var defines = subMesh._materialDefines;
  1705. if (!defines) {
  1706. return;
  1707. }
  1708. var effect = subMesh.effect;
  1709. if (!effect || !this._mesh) {
  1710. return;
  1711. }
  1712. this._activeEffect = effect;
  1713. // Matrices
  1714. this.bindOnlyWorldMatrix(world);
  1715. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  1716. // Bones
  1717. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  1718. if (this._mustRebind(scene, effect)) {
  1719. // Textures
  1720. if (this.bumpTexture && BABYLON.StandardMaterial.BumpTextureEnabled) {
  1721. this._activeEffect.setTexture("normalSampler", this.bumpTexture);
  1722. this._activeEffect.setFloat2("vNormalInfos", this.bumpTexture.coordinatesIndex, this.bumpTexture.level);
  1723. this._activeEffect.setMatrix("normalMatrix", this.bumpTexture.getTextureMatrix());
  1724. }
  1725. // Clip plane
  1726. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  1727. // Point size
  1728. if (this.pointsCloud) {
  1729. this._activeEffect.setFloat("pointSize", this.pointSize);
  1730. }
  1731. this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  1732. }
  1733. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  1734. if (defines.SPECULARTERM) {
  1735. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  1736. }
  1737. if (scene.lightsEnabled && !this.disableLighting) {
  1738. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  1739. }
  1740. // View
  1741. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  1742. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  1743. }
  1744. // Fog
  1745. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  1746. // Log. depth
  1747. BABYLON.MaterialHelper.BindLogDepth(defines, this._activeEffect, scene);
  1748. // Water
  1749. if (BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  1750. this._activeEffect.setTexture("refractionSampler", this._refractionRTT);
  1751. this._activeEffect.setTexture("reflectionSampler", this._reflectionRTT);
  1752. }
  1753. var wrvp = this._mesh.getWorldMatrix().multiply(this._reflectionTransform).multiply(scene.getProjectionMatrix());
  1754. // Add delta time. Prevent adding delta time if it hasn't changed.
  1755. var deltaTime = scene.getEngine().getDeltaTime();
  1756. if (deltaTime !== this._lastDeltaTime) {
  1757. this._lastDeltaTime = deltaTime;
  1758. this._lastTime += this._lastDeltaTime;
  1759. }
  1760. this._activeEffect.setMatrix("worldReflectionViewProjection", wrvp);
  1761. this._activeEffect.setVector2("windDirection", this.windDirection);
  1762. this._activeEffect.setFloat("waveLength", this.waveLength);
  1763. this._activeEffect.setFloat("time", this._lastTime / 100000);
  1764. this._activeEffect.setFloat("windForce", this.windForce);
  1765. this._activeEffect.setFloat("waveHeight", this.waveHeight);
  1766. this._activeEffect.setFloat("bumpHeight", this.bumpHeight);
  1767. this._activeEffect.setColor4("waterColor", this.waterColor, 1.0);
  1768. this._activeEffect.setFloat("colorBlendFactor", this.colorBlendFactor);
  1769. this._activeEffect.setColor4("waterColor2", this.waterColor2, 1.0);
  1770. this._activeEffect.setFloat("colorBlendFactor2", this.colorBlendFactor2);
  1771. this._activeEffect.setFloat("waveSpeed", this.waveSpeed);
  1772. this._afterBind(mesh, this._activeEffect);
  1773. };
  1774. WaterMaterial.prototype._createRenderTargets = function (scene, renderTargetSize) {
  1775. var _this = this;
  1776. // Render targets
  1777. this._refractionRTT = new BABYLON.RenderTargetTexture(name + "_refraction", { width: renderTargetSize.x, height: renderTargetSize.y }, scene, false, true);
  1778. this._refractionRTT.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
  1779. this._refractionRTT.wrapV = BABYLON.Texture.MIRROR_ADDRESSMODE;
  1780. this._refractionRTT.ignoreCameraViewport = true;
  1781. this._reflectionRTT = new BABYLON.RenderTargetTexture(name + "_reflection", { width: renderTargetSize.x, height: renderTargetSize.y }, scene, false, true);
  1782. this._reflectionRTT.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
  1783. this._reflectionRTT.wrapV = BABYLON.Texture.MIRROR_ADDRESSMODE;
  1784. this._reflectionRTT.ignoreCameraViewport = true;
  1785. var isVisible;
  1786. var clipPlane = null;
  1787. var savedViewMatrix;
  1788. var mirrorMatrix = BABYLON.Matrix.Zero();
  1789. this._refractionRTT.onBeforeRender = function () {
  1790. if (_this._mesh) {
  1791. isVisible = _this._mesh.isVisible;
  1792. _this._mesh.isVisible = false;
  1793. }
  1794. // Clip plane
  1795. clipPlane = scene.clipPlane;
  1796. var positiony = _this._mesh ? _this._mesh.position.y : 0.0;
  1797. scene.clipPlane = BABYLON.Plane.FromPositionAndNormal(new BABYLON.Vector3(0, positiony + 0.05, 0), new BABYLON.Vector3(0, 1, 0));
  1798. };
  1799. this._refractionRTT.onAfterRender = function () {
  1800. if (_this._mesh) {
  1801. _this._mesh.isVisible = isVisible;
  1802. }
  1803. // Clip plane
  1804. scene.clipPlane = clipPlane;
  1805. };
  1806. this._reflectionRTT.onBeforeRender = function () {
  1807. if (_this._mesh) {
  1808. isVisible = _this._mesh.isVisible;
  1809. _this._mesh.isVisible = false;
  1810. }
  1811. // Clip plane
  1812. clipPlane = scene.clipPlane;
  1813. var positiony = _this._mesh ? _this._mesh.position.y : 0.0;
  1814. scene.clipPlane = BABYLON.Plane.FromPositionAndNormal(new BABYLON.Vector3(0, positiony - 0.05, 0), new BABYLON.Vector3(0, -1, 0));
  1815. // Transform
  1816. BABYLON.Matrix.ReflectionToRef(scene.clipPlane, mirrorMatrix);
  1817. savedViewMatrix = scene.getViewMatrix();
  1818. mirrorMatrix.multiplyToRef(savedViewMatrix, _this._reflectionTransform);
  1819. scene.setTransformMatrix(_this._reflectionTransform, scene.getProjectionMatrix());
  1820. scene.getEngine().cullBackFaces = false;
  1821. scene._mirroredCameraPosition = BABYLON.Vector3.TransformCoordinates(scene.activeCamera.position, mirrorMatrix);
  1822. };
  1823. this._reflectionRTT.onAfterRender = function () {
  1824. if (_this._mesh) {
  1825. _this._mesh.isVisible = isVisible;
  1826. }
  1827. // Clip plane
  1828. scene.clipPlane = clipPlane;
  1829. // Transform
  1830. scene.setTransformMatrix(savedViewMatrix, scene.getProjectionMatrix());
  1831. scene.getEngine().cullBackFaces = true;
  1832. scene._mirroredCameraPosition = null;
  1833. };
  1834. };
  1835. WaterMaterial.prototype.getAnimatables = function () {
  1836. var results = [];
  1837. if (this.bumpTexture && this.bumpTexture.animations && this.bumpTexture.animations.length > 0) {
  1838. results.push(this.bumpTexture);
  1839. }
  1840. if (this._reflectionRTT && this._reflectionRTT.animations && this._reflectionRTT.animations.length > 0) {
  1841. results.push(this._reflectionRTT);
  1842. }
  1843. if (this._refractionRTT && this._refractionRTT.animations && this._refractionRTT.animations.length > 0) {
  1844. results.push(this._refractionRTT);
  1845. }
  1846. return results;
  1847. };
  1848. WaterMaterial.prototype.getActiveTextures = function () {
  1849. var activeTextures = _super.prototype.getActiveTextures.call(this);
  1850. if (this._bumpTexture) {
  1851. activeTextures.push(this._bumpTexture);
  1852. }
  1853. return activeTextures;
  1854. };
  1855. WaterMaterial.prototype.hasTexture = function (texture) {
  1856. if (_super.prototype.hasTexture.call(this, texture)) {
  1857. return true;
  1858. }
  1859. if (this._bumpTexture === texture) {
  1860. return true;
  1861. }
  1862. return false;
  1863. };
  1864. WaterMaterial.prototype.dispose = function (forceDisposeEffect) {
  1865. if (this.bumpTexture) {
  1866. this.bumpTexture.dispose();
  1867. }
  1868. var index = this.getScene().customRenderTargets.indexOf(this._refractionRTT);
  1869. if (index != -1) {
  1870. this.getScene().customRenderTargets.splice(index, 1);
  1871. }
  1872. index = -1;
  1873. index = this.getScene().customRenderTargets.indexOf(this._reflectionRTT);
  1874. if (index != -1) {
  1875. this.getScene().customRenderTargets.splice(index, 1);
  1876. }
  1877. if (this._reflectionRTT) {
  1878. this._reflectionRTT.dispose();
  1879. }
  1880. if (this._refractionRTT) {
  1881. this._refractionRTT.dispose();
  1882. }
  1883. _super.prototype.dispose.call(this, forceDisposeEffect);
  1884. };
  1885. WaterMaterial.prototype.clone = function (name) {
  1886. var _this = this;
  1887. return BABYLON.SerializationHelper.Clone(function () { return new WaterMaterial(name, _this.getScene()); }, this);
  1888. };
  1889. WaterMaterial.prototype.serialize = function () {
  1890. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  1891. serializationObject.customType = "BABYLON.WaterMaterial";
  1892. serializationObject.reflectionTexture.isRenderTarget = true;
  1893. serializationObject.refractionTexture.isRenderTarget = true;
  1894. return serializationObject;
  1895. };
  1896. WaterMaterial.prototype.getClassName = function () {
  1897. return "WaterMaterial";
  1898. };
  1899. // Statics
  1900. WaterMaterial.Parse = function (source, scene, rootUrl) {
  1901. return BABYLON.SerializationHelper.Parse(function () { return new WaterMaterial(source.name, scene); }, source, scene, rootUrl);
  1902. };
  1903. WaterMaterial.CreateDefaultMesh = function (name, scene) {
  1904. var mesh = BABYLON.Mesh.CreateGround(name, 512, 512, 32, scene, false);
  1905. return mesh;
  1906. };
  1907. __decorate([
  1908. BABYLON.serializeAsTexture("bumpTexture")
  1909. ], WaterMaterial.prototype, "_bumpTexture", void 0);
  1910. __decorate([
  1911. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1912. ], WaterMaterial.prototype, "bumpTexture", void 0);
  1913. __decorate([
  1914. BABYLON.serializeAsColor3()
  1915. ], WaterMaterial.prototype, "diffuseColor", void 0);
  1916. __decorate([
  1917. BABYLON.serializeAsColor3()
  1918. ], WaterMaterial.prototype, "specularColor", void 0);
  1919. __decorate([
  1920. BABYLON.serialize()
  1921. ], WaterMaterial.prototype, "specularPower", void 0);
  1922. __decorate([
  1923. BABYLON.serialize("disableLighting")
  1924. ], WaterMaterial.prototype, "_disableLighting", void 0);
  1925. __decorate([
  1926. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1927. ], WaterMaterial.prototype, "disableLighting", void 0);
  1928. __decorate([
  1929. BABYLON.serialize("maxSimultaneousLights")
  1930. ], WaterMaterial.prototype, "_maxSimultaneousLights", void 0);
  1931. __decorate([
  1932. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1933. ], WaterMaterial.prototype, "maxSimultaneousLights", void 0);
  1934. __decorate([
  1935. BABYLON.serialize()
  1936. ], WaterMaterial.prototype, "windForce", void 0);
  1937. __decorate([
  1938. BABYLON.serializeAsVector2()
  1939. ], WaterMaterial.prototype, "windDirection", void 0);
  1940. __decorate([
  1941. BABYLON.serialize()
  1942. ], WaterMaterial.prototype, "waveHeight", void 0);
  1943. __decorate([
  1944. BABYLON.serialize()
  1945. ], WaterMaterial.prototype, "bumpHeight", void 0);
  1946. __decorate([
  1947. BABYLON.serialize("bumpSuperimpose")
  1948. ], WaterMaterial.prototype, "_bumpSuperimpose", void 0);
  1949. __decorate([
  1950. BABYLON.expandToProperty("_markAllSubMeshesAsMiscDirty")
  1951. ], WaterMaterial.prototype, "bumpSuperimpose", void 0);
  1952. __decorate([
  1953. BABYLON.serialize("fresnelSeparate")
  1954. ], WaterMaterial.prototype, "_fresnelSeparate", void 0);
  1955. __decorate([
  1956. BABYLON.expandToProperty("_markAllSubMeshesAsMiscDirty")
  1957. ], WaterMaterial.prototype, "fresnelSeparate", void 0);
  1958. __decorate([
  1959. BABYLON.serialize("bumpAffectsReflection")
  1960. ], WaterMaterial.prototype, "_bumpAffectsReflection", void 0);
  1961. __decorate([
  1962. BABYLON.expandToProperty("_markAllSubMeshesAsMiscDirty")
  1963. ], WaterMaterial.prototype, "bumpAffectsReflection", void 0);
  1964. __decorate([
  1965. BABYLON.serializeAsColor3()
  1966. ], WaterMaterial.prototype, "waterColor", void 0);
  1967. __decorate([
  1968. BABYLON.serialize()
  1969. ], WaterMaterial.prototype, "colorBlendFactor", void 0);
  1970. __decorate([
  1971. BABYLON.serializeAsColor3()
  1972. ], WaterMaterial.prototype, "waterColor2", void 0);
  1973. __decorate([
  1974. BABYLON.serialize()
  1975. ], WaterMaterial.prototype, "colorBlendFactor2", void 0);
  1976. __decorate([
  1977. BABYLON.serialize()
  1978. ], WaterMaterial.prototype, "waveLength", void 0);
  1979. __decorate([
  1980. BABYLON.serialize()
  1981. ], WaterMaterial.prototype, "waveSpeed", void 0);
  1982. __decorate([
  1983. BABYLON.serialize()
  1984. ], WaterMaterial.prototype, "useLogarithmicDepth", null);
  1985. return WaterMaterial;
  1986. }(BABYLON.PushMaterial));
  1987. BABYLON.WaterMaterial = WaterMaterial;
  1988. })(BABYLON || (BABYLON = {}));
  1989. //# sourceMappingURL=babylon.waterMaterial.js.map
  1990. 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";
  1991. 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";
  1992. var BABYLON;
  1993. (function (BABYLON) {
  1994. var FireMaterialDefines = /** @class */ (function (_super) {
  1995. __extends(FireMaterialDefines, _super);
  1996. function FireMaterialDefines() {
  1997. var _this = _super.call(this) || this;
  1998. _this.DIFFUSE = false;
  1999. _this.CLIPPLANE = false;
  2000. _this.ALPHATEST = false;
  2001. _this.DEPTHPREPASS = false;
  2002. _this.POINTSIZE = false;
  2003. _this.FOG = false;
  2004. _this.UV1 = false;
  2005. _this.VERTEXCOLOR = false;
  2006. _this.VERTEXALPHA = false;
  2007. _this.BonesPerMesh = 0;
  2008. _this.NUM_BONE_INFLUENCERS = 0;
  2009. _this.INSTANCES = false;
  2010. _this.rebuild();
  2011. return _this;
  2012. }
  2013. return FireMaterialDefines;
  2014. }(BABYLON.MaterialDefines));
  2015. var FireMaterial = /** @class */ (function (_super) {
  2016. __extends(FireMaterial, _super);
  2017. function FireMaterial(name, scene) {
  2018. var _this = _super.call(this, name, scene) || this;
  2019. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  2020. _this.speed = 1.0;
  2021. _this._scaledDiffuse = new BABYLON.Color3();
  2022. _this._lastTime = 0;
  2023. return _this;
  2024. }
  2025. FireMaterial.prototype.needAlphaBlending = function () {
  2026. return false;
  2027. };
  2028. FireMaterial.prototype.needAlphaTesting = function () {
  2029. return true;
  2030. };
  2031. FireMaterial.prototype.getAlphaTestTexture = function () {
  2032. return null;
  2033. };
  2034. // Methods
  2035. FireMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  2036. if (this.isFrozen) {
  2037. if (this._wasPreviouslyReady && subMesh.effect) {
  2038. return true;
  2039. }
  2040. }
  2041. if (!subMesh._materialDefines) {
  2042. subMesh._materialDefines = new FireMaterialDefines();
  2043. }
  2044. var defines = subMesh._materialDefines;
  2045. var scene = this.getScene();
  2046. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  2047. if (this._renderId === scene.getRenderId()) {
  2048. return true;
  2049. }
  2050. }
  2051. var engine = scene.getEngine();
  2052. // Textures
  2053. if (defines._areTexturesDirty) {
  2054. defines._needUVs = false;
  2055. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2056. if (!this._diffuseTexture.isReady()) {
  2057. return false;
  2058. }
  2059. else {
  2060. defines._needUVs = true;
  2061. defines.DIFFUSE = true;
  2062. }
  2063. }
  2064. }
  2065. // Misc.
  2066. if (defines._areMiscDirty) {
  2067. defines.POINTSIZE = (this.pointsCloud || scene.forcePointsCloud);
  2068. defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled);
  2069. }
  2070. // Values that need to be evaluated on every frame
  2071. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  2072. // Attribs
  2073. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
  2074. // Get correct effect
  2075. if (defines.isDirty) {
  2076. defines.markAsProcessed();
  2077. scene.resetCachedMaterial();
  2078. // Fallbacks
  2079. var fallbacks = new BABYLON.EffectFallbacks();
  2080. if (defines.FOG) {
  2081. fallbacks.addFallback(1, "FOG");
  2082. }
  2083. if (defines.NUM_BONE_INFLUENCERS > 0) {
  2084. fallbacks.addCPUSkinningFallback(0, mesh);
  2085. }
  2086. //Attributes
  2087. var attribs = [BABYLON.VertexBuffer.PositionKind];
  2088. if (defines.UV1) {
  2089. attribs.push(BABYLON.VertexBuffer.UVKind);
  2090. }
  2091. if (defines.VERTEXCOLOR) {
  2092. attribs.push(BABYLON.VertexBuffer.ColorKind);
  2093. }
  2094. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  2095. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  2096. // Legacy browser patch
  2097. var shaderName = "fire";
  2098. var join = defines.toString();
  2099. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  2100. attributes: attribs,
  2101. uniformsNames: ["world", "view", "viewProjection", "vEyePosition",
  2102. "vFogInfos", "vFogColor", "pointSize",
  2103. "vDiffuseInfos",
  2104. "mBones",
  2105. "vClipPlane", "diffuseMatrix",
  2106. // Fire
  2107. "time", "speed"
  2108. ],
  2109. uniformBuffersNames: [],
  2110. samplers: ["diffuseSampler",
  2111. // Fire
  2112. "distortionSampler", "opacitySampler"
  2113. ],
  2114. defines: join,
  2115. fallbacks: fallbacks,
  2116. onCompiled: this.onCompiled,
  2117. onError: this.onError,
  2118. indexParameters: null,
  2119. maxSimultaneousLights: 4
  2120. }, engine), defines);
  2121. }
  2122. if (!subMesh.effect || !subMesh.effect.isReady()) {
  2123. return false;
  2124. }
  2125. this._renderId = scene.getRenderId();
  2126. this._wasPreviouslyReady = true;
  2127. return true;
  2128. };
  2129. FireMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  2130. var scene = this.getScene();
  2131. var defines = subMesh._materialDefines;
  2132. if (!defines) {
  2133. return;
  2134. }
  2135. var effect = subMesh.effect;
  2136. if (!effect) {
  2137. return;
  2138. }
  2139. this._activeEffect = effect;
  2140. // Matrices
  2141. this.bindOnlyWorldMatrix(world);
  2142. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  2143. // Bones
  2144. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  2145. if (this._mustRebind(scene, effect)) {
  2146. // Textures
  2147. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2148. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  2149. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  2150. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  2151. this._activeEffect.setTexture("distortionSampler", this._distortionTexture);
  2152. this._activeEffect.setTexture("opacitySampler", this._opacityTexture);
  2153. }
  2154. // Clip plane
  2155. if (scene.clipPlane) {
  2156. var clipPlane = scene.clipPlane;
  2157. this._activeEffect.setFloat4("vClipPlane", clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);
  2158. }
  2159. // Point size
  2160. if (this.pointsCloud) {
  2161. this._activeEffect.setFloat("pointSize", this.pointSize);
  2162. }
  2163. this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  2164. }
  2165. this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  2166. // View
  2167. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  2168. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  2169. }
  2170. // Fog
  2171. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  2172. // Time
  2173. this._lastTime += scene.getEngine().getDeltaTime();
  2174. this._activeEffect.setFloat("time", this._lastTime);
  2175. // Speed
  2176. this._activeEffect.setFloat("speed", this.speed);
  2177. this._afterBind(mesh, this._activeEffect);
  2178. };
  2179. FireMaterial.prototype.getAnimatables = function () {
  2180. var results = [];
  2181. if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
  2182. results.push(this._diffuseTexture);
  2183. }
  2184. if (this._distortionTexture && this._distortionTexture.animations && this._distortionTexture.animations.length > 0) {
  2185. results.push(this._distortionTexture);
  2186. }
  2187. if (this._opacityTexture && this._opacityTexture.animations && this._opacityTexture.animations.length > 0) {
  2188. results.push(this._opacityTexture);
  2189. }
  2190. return results;
  2191. };
  2192. FireMaterial.prototype.getActiveTextures = function () {
  2193. var activeTextures = _super.prototype.getActiveTextures.call(this);
  2194. if (this._diffuseTexture) {
  2195. activeTextures.push(this._diffuseTexture);
  2196. }
  2197. if (this._distortionTexture) {
  2198. activeTextures.push(this._distortionTexture);
  2199. }
  2200. if (this._opacityTexture) {
  2201. activeTextures.push(this._opacityTexture);
  2202. }
  2203. return activeTextures;
  2204. };
  2205. FireMaterial.prototype.hasTexture = function (texture) {
  2206. if (_super.prototype.hasTexture.call(this, texture)) {
  2207. return true;
  2208. }
  2209. if (this._diffuseTexture === texture) {
  2210. return true;
  2211. }
  2212. if (this._distortionTexture === texture) {
  2213. return true;
  2214. }
  2215. if (this._opacityTexture === texture) {
  2216. return true;
  2217. }
  2218. return false;
  2219. };
  2220. FireMaterial.prototype.getClassName = function () {
  2221. return "FireMaterial";
  2222. };
  2223. FireMaterial.prototype.dispose = function (forceDisposeEffect) {
  2224. if (this._diffuseTexture) {
  2225. this._diffuseTexture.dispose();
  2226. }
  2227. if (this._distortionTexture) {
  2228. this._distortionTexture.dispose();
  2229. }
  2230. _super.prototype.dispose.call(this, forceDisposeEffect);
  2231. };
  2232. FireMaterial.prototype.clone = function (name) {
  2233. var _this = this;
  2234. return BABYLON.SerializationHelper.Clone(function () { return new FireMaterial(name, _this.getScene()); }, this);
  2235. };
  2236. FireMaterial.prototype.serialize = function () {
  2237. var serializationObject = _super.prototype.serialize.call(this);
  2238. serializationObject.customType = "BABYLON.FireMaterial";
  2239. serializationObject.diffuseColor = this.diffuseColor.asArray();
  2240. serializationObject.speed = this.speed;
  2241. if (this._diffuseTexture) {
  2242. serializationObject._diffuseTexture = this._diffuseTexture.serialize();
  2243. }
  2244. if (this._distortionTexture) {
  2245. serializationObject._distortionTexture = this._distortionTexture.serialize();
  2246. }
  2247. if (this._opacityTexture) {
  2248. serializationObject._opacityTexture = this._opacityTexture.serialize();
  2249. }
  2250. return serializationObject;
  2251. };
  2252. FireMaterial.Parse = function (source, scene, rootUrl) {
  2253. var material = new FireMaterial(source.name, scene);
  2254. material.diffuseColor = BABYLON.Color3.FromArray(source.diffuseColor);
  2255. material.speed = source.speed;
  2256. material.alpha = source.alpha;
  2257. material.id = source.id;
  2258. BABYLON.Tags.AddTagsTo(material, source.tags);
  2259. material.backFaceCulling = source.backFaceCulling;
  2260. material.wireframe = source.wireframe;
  2261. if (source._diffuseTexture) {
  2262. material._diffuseTexture = BABYLON.Texture.Parse(source._diffuseTexture, scene, rootUrl);
  2263. }
  2264. if (source._distortionTexture) {
  2265. material._distortionTexture = BABYLON.Texture.Parse(source._distortionTexture, scene, rootUrl);
  2266. }
  2267. if (source._opacityTexture) {
  2268. material._opacityTexture = BABYLON.Texture.Parse(source._opacityTexture, scene, rootUrl);
  2269. }
  2270. if (source.checkReadyOnlyOnce) {
  2271. material.checkReadyOnlyOnce = source.checkReadyOnlyOnce;
  2272. }
  2273. return material;
  2274. };
  2275. __decorate([
  2276. BABYLON.serializeAsTexture("diffuseTexture")
  2277. ], FireMaterial.prototype, "_diffuseTexture", void 0);
  2278. __decorate([
  2279. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2280. ], FireMaterial.prototype, "diffuseTexture", void 0);
  2281. __decorate([
  2282. BABYLON.serializeAsTexture("distortionTexture")
  2283. ], FireMaterial.prototype, "_distortionTexture", void 0);
  2284. __decorate([
  2285. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2286. ], FireMaterial.prototype, "distortionTexture", void 0);
  2287. __decorate([
  2288. BABYLON.serializeAsTexture("opacityTexture")
  2289. ], FireMaterial.prototype, "_opacityTexture", void 0);
  2290. __decorate([
  2291. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2292. ], FireMaterial.prototype, "opacityTexture", void 0);
  2293. __decorate([
  2294. BABYLON.serialize("diffuseColor")
  2295. ], FireMaterial.prototype, "diffuseColor", void 0);
  2296. __decorate([
  2297. BABYLON.serialize()
  2298. ], FireMaterial.prototype, "speed", void 0);
  2299. return FireMaterial;
  2300. }(BABYLON.PushMaterial));
  2301. BABYLON.FireMaterial = FireMaterial;
  2302. })(BABYLON || (BABYLON = {}));
  2303. //# sourceMappingURL=babylon.fireMaterial.js.map
  2304. 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";
  2305. 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}";
  2306. var BABYLON;
  2307. (function (BABYLON) {
  2308. var FurMaterialDefines = /** @class */ (function (_super) {
  2309. __extends(FurMaterialDefines, _super);
  2310. function FurMaterialDefines() {
  2311. var _this = _super.call(this) || this;
  2312. _this.DIFFUSE = false;
  2313. _this.HEIGHTMAP = false;
  2314. _this.CLIPPLANE = false;
  2315. _this.ALPHATEST = false;
  2316. _this.DEPTHPREPASS = false;
  2317. _this.POINTSIZE = false;
  2318. _this.FOG = false;
  2319. _this.NORMAL = false;
  2320. _this.UV1 = false;
  2321. _this.UV2 = false;
  2322. _this.VERTEXCOLOR = false;
  2323. _this.VERTEXALPHA = false;
  2324. _this.NUM_BONE_INFLUENCERS = 0;
  2325. _this.BonesPerMesh = 0;
  2326. _this.INSTANCES = false;
  2327. _this.HIGHLEVEL = false;
  2328. _this.rebuild();
  2329. return _this;
  2330. }
  2331. return FurMaterialDefines;
  2332. }(BABYLON.MaterialDefines));
  2333. var FurMaterial = /** @class */ (function (_super) {
  2334. __extends(FurMaterial, _super);
  2335. function FurMaterial(name, scene) {
  2336. var _this = _super.call(this, name, scene) || this;
  2337. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  2338. _this.furLength = 1;
  2339. _this.furAngle = 0;
  2340. _this.furColor = new BABYLON.Color3(0.44, 0.21, 0.02);
  2341. _this.furOffset = 0.0;
  2342. _this.furSpacing = 12;
  2343. _this.furGravity = new BABYLON.Vector3(0, 0, 0);
  2344. _this.furSpeed = 100;
  2345. _this.furDensity = 20;
  2346. _this._disableLighting = false;
  2347. _this._maxSimultaneousLights = 4;
  2348. _this.highLevelFur = true;
  2349. _this._furTime = 0;
  2350. return _this;
  2351. }
  2352. Object.defineProperty(FurMaterial.prototype, "furTime", {
  2353. get: function () {
  2354. return this._furTime;
  2355. },
  2356. set: function (furTime) {
  2357. this._furTime = furTime;
  2358. },
  2359. enumerable: true,
  2360. configurable: true
  2361. });
  2362. FurMaterial.prototype.needAlphaBlending = function () {
  2363. return (this.alpha < 1.0);
  2364. };
  2365. FurMaterial.prototype.needAlphaTesting = function () {
  2366. return false;
  2367. };
  2368. FurMaterial.prototype.getAlphaTestTexture = function () {
  2369. return null;
  2370. };
  2371. FurMaterial.prototype.updateFur = function () {
  2372. for (var i = 1; i < this._meshes.length; i++) {
  2373. var offsetFur = this._meshes[i].material;
  2374. offsetFur.furLength = this.furLength;
  2375. offsetFur.furAngle = this.furAngle;
  2376. offsetFur.furGravity = this.furGravity;
  2377. offsetFur.furSpacing = this.furSpacing;
  2378. offsetFur.furSpeed = this.furSpeed;
  2379. offsetFur.furColor = this.furColor;
  2380. offsetFur.diffuseTexture = this.diffuseTexture;
  2381. offsetFur.furTexture = this.furTexture;
  2382. offsetFur.highLevelFur = this.highLevelFur;
  2383. offsetFur.furTime = this.furTime;
  2384. offsetFur.furDensity = this.furDensity;
  2385. }
  2386. };
  2387. // Methods
  2388. FurMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  2389. if (this.isFrozen) {
  2390. if (this._wasPreviouslyReady && subMesh.effect) {
  2391. return true;
  2392. }
  2393. }
  2394. if (!subMesh._materialDefines) {
  2395. subMesh._materialDefines = new FurMaterialDefines();
  2396. }
  2397. var defines = subMesh._materialDefines;
  2398. var scene = this.getScene();
  2399. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  2400. if (this._renderId === scene.getRenderId()) {
  2401. return true;
  2402. }
  2403. }
  2404. var engine = scene.getEngine();
  2405. // Textures
  2406. if (defines._areTexturesDirty) {
  2407. if (scene.texturesEnabled) {
  2408. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2409. if (!this.diffuseTexture.isReady()) {
  2410. return false;
  2411. }
  2412. else {
  2413. defines._needUVs = true;
  2414. defines.DIFFUSE = true;
  2415. }
  2416. }
  2417. if (this.heightTexture && engine.getCaps().maxVertexTextureImageUnits) {
  2418. if (!this.heightTexture.isReady()) {
  2419. return false;
  2420. }
  2421. else {
  2422. defines._needUVs = true;
  2423. defines.HEIGHTMAP = true;
  2424. }
  2425. }
  2426. }
  2427. }
  2428. // High level
  2429. if (this.highLevelFur !== defines.HIGHLEVEL) {
  2430. defines.HIGHLEVEL = true;
  2431. defines.markAsUnprocessed();
  2432. }
  2433. // Misc.
  2434. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  2435. // Lights
  2436. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  2437. // Values that need to be evaluated on every frame
  2438. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  2439. // Attribs
  2440. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  2441. // Get correct effect
  2442. if (defines.isDirty) {
  2443. defines.markAsProcessed();
  2444. scene.resetCachedMaterial();
  2445. // Fallbacks
  2446. var fallbacks = new BABYLON.EffectFallbacks();
  2447. if (defines.FOG) {
  2448. fallbacks.addFallback(1, "FOG");
  2449. }
  2450. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  2451. if (defines.NUM_BONE_INFLUENCERS > 0) {
  2452. fallbacks.addCPUSkinningFallback(0, mesh);
  2453. }
  2454. //Attributes
  2455. var attribs = [BABYLON.VertexBuffer.PositionKind];
  2456. if (defines.NORMAL) {
  2457. attribs.push(BABYLON.VertexBuffer.NormalKind);
  2458. }
  2459. if (defines.UV1) {
  2460. attribs.push(BABYLON.VertexBuffer.UVKind);
  2461. }
  2462. if (defines.UV2) {
  2463. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  2464. }
  2465. if (defines.VERTEXCOLOR) {
  2466. attribs.push(BABYLON.VertexBuffer.ColorKind);
  2467. }
  2468. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  2469. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  2470. // Legacy browser patch
  2471. var shaderName = "fur";
  2472. var join = defines.toString();
  2473. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  2474. "vFogInfos", "vFogColor", "pointSize",
  2475. "vDiffuseInfos",
  2476. "mBones",
  2477. "vClipPlane", "diffuseMatrix",
  2478. "furLength", "furAngle", "furColor", "furOffset", "furGravity", "furTime", "furSpacing", "furDensity"
  2479. ];
  2480. var samplers = ["diffuseSampler",
  2481. "heightTexture", "furTexture"
  2482. ];
  2483. var uniformBuffers = new Array();
  2484. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  2485. uniformsNames: uniforms,
  2486. uniformBuffersNames: uniformBuffers,
  2487. samplers: samplers,
  2488. defines: defines,
  2489. maxSimultaneousLights: this.maxSimultaneousLights
  2490. });
  2491. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  2492. attributes: attribs,
  2493. uniformsNames: uniforms,
  2494. uniformBuffersNames: uniformBuffers,
  2495. samplers: samplers,
  2496. defines: join,
  2497. fallbacks: fallbacks,
  2498. onCompiled: this.onCompiled,
  2499. onError: this.onError,
  2500. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  2501. }, engine), defines);
  2502. }
  2503. if (!subMesh.effect || !subMesh.effect.isReady()) {
  2504. return false;
  2505. }
  2506. this._renderId = scene.getRenderId();
  2507. this._wasPreviouslyReady = true;
  2508. return true;
  2509. };
  2510. FurMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  2511. var scene = this.getScene();
  2512. var defines = subMesh._materialDefines;
  2513. if (!defines) {
  2514. return;
  2515. }
  2516. var effect = subMesh.effect;
  2517. if (!effect) {
  2518. return;
  2519. }
  2520. this._activeEffect = effect;
  2521. // Matrices
  2522. this.bindOnlyWorldMatrix(world);
  2523. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  2524. // Bones
  2525. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  2526. if (scene.getCachedMaterial() !== this) {
  2527. // Textures
  2528. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2529. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  2530. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  2531. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  2532. }
  2533. if (this._heightTexture) {
  2534. this._activeEffect.setTexture("heightTexture", this._heightTexture);
  2535. }
  2536. // Clip plane
  2537. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  2538. // Point size
  2539. if (this.pointsCloud) {
  2540. this._activeEffect.setFloat("pointSize", this.pointSize);
  2541. }
  2542. this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  2543. }
  2544. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  2545. if (scene.lightsEnabled && !this.disableLighting) {
  2546. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  2547. }
  2548. // View
  2549. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  2550. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  2551. }
  2552. // Fog
  2553. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  2554. this._activeEffect.setFloat("furLength", this.furLength);
  2555. this._activeEffect.setFloat("furAngle", this.furAngle);
  2556. this._activeEffect.setColor4("furColor", this.furColor, 1.0);
  2557. if (this.highLevelFur) {
  2558. this._activeEffect.setVector3("furGravity", this.furGravity);
  2559. this._activeEffect.setFloat("furOffset", this.furOffset);
  2560. this._activeEffect.setFloat("furSpacing", this.furSpacing);
  2561. this._activeEffect.setFloat("furDensity", this.furDensity);
  2562. this._furTime += this.getScene().getEngine().getDeltaTime() / this.furSpeed;
  2563. this._activeEffect.setFloat("furTime", this._furTime);
  2564. this._activeEffect.setTexture("furTexture", this.furTexture);
  2565. }
  2566. this._afterBind(mesh, this._activeEffect);
  2567. };
  2568. FurMaterial.prototype.getAnimatables = function () {
  2569. var results = [];
  2570. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  2571. results.push(this.diffuseTexture);
  2572. }
  2573. if (this.heightTexture && this.heightTexture.animations && this.heightTexture.animations.length > 0) {
  2574. results.push(this.heightTexture);
  2575. }
  2576. return results;
  2577. };
  2578. FurMaterial.prototype.getActiveTextures = function () {
  2579. var activeTextures = _super.prototype.getActiveTextures.call(this);
  2580. if (this._diffuseTexture) {
  2581. activeTextures.push(this._diffuseTexture);
  2582. }
  2583. if (this._heightTexture) {
  2584. activeTextures.push(this._heightTexture);
  2585. }
  2586. return activeTextures;
  2587. };
  2588. FurMaterial.prototype.hasTexture = function (texture) {
  2589. if (_super.prototype.hasTexture.call(this, texture)) {
  2590. return true;
  2591. }
  2592. if (this.diffuseTexture === texture) {
  2593. return true;
  2594. }
  2595. if (this._heightTexture === texture) {
  2596. return true;
  2597. }
  2598. return false;
  2599. };
  2600. FurMaterial.prototype.dispose = function (forceDisposeEffect) {
  2601. if (this.diffuseTexture) {
  2602. this.diffuseTexture.dispose();
  2603. }
  2604. if (this._meshes) {
  2605. for (var i = 1; i < this._meshes.length; i++) {
  2606. var mat = this._meshes[i].material;
  2607. if (mat) {
  2608. mat.dispose(forceDisposeEffect);
  2609. }
  2610. this._meshes[i].dispose();
  2611. }
  2612. }
  2613. _super.prototype.dispose.call(this, forceDisposeEffect);
  2614. };
  2615. FurMaterial.prototype.clone = function (name) {
  2616. var _this = this;
  2617. return BABYLON.SerializationHelper.Clone(function () { return new FurMaterial(name, _this.getScene()); }, this);
  2618. };
  2619. FurMaterial.prototype.serialize = function () {
  2620. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  2621. serializationObject.customType = "BABYLON.FurMaterial";
  2622. if (this._meshes) {
  2623. serializationObject.sourceMeshName = this._meshes[0].name;
  2624. serializationObject.quality = this._meshes.length;
  2625. }
  2626. return serializationObject;
  2627. };
  2628. FurMaterial.prototype.getClassName = function () {
  2629. return "FurMaterial";
  2630. };
  2631. // Statics
  2632. FurMaterial.Parse = function (source, scene, rootUrl) {
  2633. var material = BABYLON.SerializationHelper.Parse(function () { return new FurMaterial(source.name, scene); }, source, scene, rootUrl);
  2634. if (source.sourceMeshName && material.highLevelFur) {
  2635. scene.executeWhenReady(function () {
  2636. var sourceMesh = scene.getMeshByName(source.sourceMeshName);
  2637. if (sourceMesh) {
  2638. var furTexture = FurMaterial.GenerateTexture("Fur Texture", scene);
  2639. material.furTexture = furTexture;
  2640. FurMaterial.FurifyMesh(sourceMesh, source.quality);
  2641. }
  2642. });
  2643. }
  2644. return material;
  2645. };
  2646. FurMaterial.GenerateTexture = function (name, scene) {
  2647. // Generate fur textures
  2648. var texture = new BABYLON.DynamicTexture("FurTexture " + name, 256, scene, true);
  2649. var context = texture.getContext();
  2650. for (var i = 0; i < 20000; ++i) {
  2651. context.fillStyle = "rgba(255, " + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", 1)";
  2652. context.fillRect((Math.random() * texture.getSize().width), (Math.random() * texture.getSize().height), 2, 2);
  2653. }
  2654. texture.update(false);
  2655. texture.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
  2656. texture.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
  2657. return texture;
  2658. };
  2659. // Creates and returns an array of meshes used as shells for the Fur Material
  2660. // that can be disposed later in your code
  2661. // The quality is in interval [0, 100]
  2662. FurMaterial.FurifyMesh = function (sourceMesh, quality) {
  2663. var meshes = [sourceMesh];
  2664. var mat = sourceMesh.material;
  2665. var i;
  2666. if (!(mat instanceof FurMaterial)) {
  2667. throw "The material of the source mesh must be a Fur Material";
  2668. }
  2669. for (i = 1; i < quality; i++) {
  2670. var offsetFur = new BABYLON.FurMaterial(mat.name + i, sourceMesh.getScene());
  2671. sourceMesh.getScene().materials.pop();
  2672. BABYLON.Tags.EnableFor(offsetFur);
  2673. BABYLON.Tags.AddTagsTo(offsetFur, "furShellMaterial");
  2674. offsetFur.furLength = mat.furLength;
  2675. offsetFur.furAngle = mat.furAngle;
  2676. offsetFur.furGravity = mat.furGravity;
  2677. offsetFur.furSpacing = mat.furSpacing;
  2678. offsetFur.furSpeed = mat.furSpeed;
  2679. offsetFur.furColor = mat.furColor;
  2680. offsetFur.diffuseTexture = mat.diffuseTexture;
  2681. offsetFur.furOffset = i / quality;
  2682. offsetFur.furTexture = mat.furTexture;
  2683. offsetFur.highLevelFur = mat.highLevelFur;
  2684. offsetFur.furTime = mat.furTime;
  2685. offsetFur.furDensity = mat.furDensity;
  2686. var offsetMesh = sourceMesh.clone(sourceMesh.name + i);
  2687. offsetMesh.material = offsetFur;
  2688. offsetMesh.skeleton = sourceMesh.skeleton;
  2689. offsetMesh.position = BABYLON.Vector3.Zero();
  2690. meshes.push(offsetMesh);
  2691. }
  2692. for (i = 1; i < meshes.length; i++) {
  2693. meshes[i].parent = sourceMesh;
  2694. }
  2695. sourceMesh.material._meshes = meshes;
  2696. return meshes;
  2697. };
  2698. __decorate([
  2699. BABYLON.serializeAsTexture("diffuseTexture")
  2700. ], FurMaterial.prototype, "_diffuseTexture", void 0);
  2701. __decorate([
  2702. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2703. ], FurMaterial.prototype, "diffuseTexture", void 0);
  2704. __decorate([
  2705. BABYLON.serializeAsTexture("heightTexture")
  2706. ], FurMaterial.prototype, "_heightTexture", void 0);
  2707. __decorate([
  2708. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2709. ], FurMaterial.prototype, "heightTexture", void 0);
  2710. __decorate([
  2711. BABYLON.serializeAsColor3()
  2712. ], FurMaterial.prototype, "diffuseColor", void 0);
  2713. __decorate([
  2714. BABYLON.serialize()
  2715. ], FurMaterial.prototype, "furLength", void 0);
  2716. __decorate([
  2717. BABYLON.serialize()
  2718. ], FurMaterial.prototype, "furAngle", void 0);
  2719. __decorate([
  2720. BABYLON.serializeAsColor3()
  2721. ], FurMaterial.prototype, "furColor", void 0);
  2722. __decorate([
  2723. BABYLON.serialize()
  2724. ], FurMaterial.prototype, "furOffset", void 0);
  2725. __decorate([
  2726. BABYLON.serialize()
  2727. ], FurMaterial.prototype, "furSpacing", void 0);
  2728. __decorate([
  2729. BABYLON.serializeAsVector3()
  2730. ], FurMaterial.prototype, "furGravity", void 0);
  2731. __decorate([
  2732. BABYLON.serialize()
  2733. ], FurMaterial.prototype, "furSpeed", void 0);
  2734. __decorate([
  2735. BABYLON.serialize()
  2736. ], FurMaterial.prototype, "furDensity", void 0);
  2737. __decorate([
  2738. BABYLON.serialize("disableLighting")
  2739. ], FurMaterial.prototype, "_disableLighting", void 0);
  2740. __decorate([
  2741. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  2742. ], FurMaterial.prototype, "disableLighting", void 0);
  2743. __decorate([
  2744. BABYLON.serialize("maxSimultaneousLights")
  2745. ], FurMaterial.prototype, "_maxSimultaneousLights", void 0);
  2746. __decorate([
  2747. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  2748. ], FurMaterial.prototype, "maxSimultaneousLights", void 0);
  2749. __decorate([
  2750. BABYLON.serialize()
  2751. ], FurMaterial.prototype, "highLevelFur", void 0);
  2752. __decorate([
  2753. BABYLON.serialize()
  2754. ], FurMaterial.prototype, "furTime", null);
  2755. return FurMaterial;
  2756. }(BABYLON.PushMaterial));
  2757. BABYLON.FurMaterial = FurMaterial;
  2758. })(BABYLON || (BABYLON = {}));
  2759. //# sourceMappingURL=babylon.furMaterial.js.map
  2760. 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";
  2761. 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}";
  2762. var BABYLON;
  2763. (function (BABYLON) {
  2764. var TerrainMaterialDefines = /** @class */ (function (_super) {
  2765. __extends(TerrainMaterialDefines, _super);
  2766. function TerrainMaterialDefines() {
  2767. var _this = _super.call(this) || this;
  2768. _this.DIFFUSE = false;
  2769. _this.BUMP = false;
  2770. _this.CLIPPLANE = false;
  2771. _this.ALPHATEST = false;
  2772. _this.DEPTHPREPASS = false;
  2773. _this.POINTSIZE = false;
  2774. _this.FOG = false;
  2775. _this.SPECULARTERM = false;
  2776. _this.NORMAL = false;
  2777. _this.UV1 = false;
  2778. _this.UV2 = false;
  2779. _this.VERTEXCOLOR = false;
  2780. _this.VERTEXALPHA = false;
  2781. _this.NUM_BONE_INFLUENCERS = 0;
  2782. _this.BonesPerMesh = 0;
  2783. _this.INSTANCES = false;
  2784. _this.rebuild();
  2785. return _this;
  2786. }
  2787. return TerrainMaterialDefines;
  2788. }(BABYLON.MaterialDefines));
  2789. var TerrainMaterial = /** @class */ (function (_super) {
  2790. __extends(TerrainMaterial, _super);
  2791. function TerrainMaterial(name, scene) {
  2792. var _this = _super.call(this, name, scene) || this;
  2793. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  2794. _this.specularColor = new BABYLON.Color3(0, 0, 0);
  2795. _this.specularPower = 64;
  2796. _this._disableLighting = false;
  2797. _this._maxSimultaneousLights = 4;
  2798. return _this;
  2799. }
  2800. TerrainMaterial.prototype.needAlphaBlending = function () {
  2801. return (this.alpha < 1.0);
  2802. };
  2803. TerrainMaterial.prototype.needAlphaTesting = function () {
  2804. return false;
  2805. };
  2806. TerrainMaterial.prototype.getAlphaTestTexture = function () {
  2807. return null;
  2808. };
  2809. // Methods
  2810. TerrainMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  2811. if (this.isFrozen) {
  2812. if (this._wasPreviouslyReady && subMesh.effect) {
  2813. return true;
  2814. }
  2815. }
  2816. if (!subMesh._materialDefines) {
  2817. subMesh._materialDefines = new TerrainMaterialDefines();
  2818. }
  2819. var defines = subMesh._materialDefines;
  2820. var scene = this.getScene();
  2821. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  2822. if (this._renderId === scene.getRenderId()) {
  2823. return true;
  2824. }
  2825. }
  2826. var engine = scene.getEngine();
  2827. // Textures
  2828. if (scene.texturesEnabled) {
  2829. if (this.mixTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2830. if (!this.mixTexture.isReady()) {
  2831. return false;
  2832. }
  2833. else {
  2834. defines._needUVs = true;
  2835. defines.DIFFUSE = true;
  2836. }
  2837. }
  2838. if ((this.bumpTexture1 || this.bumpTexture2 || this.bumpTexture3) && BABYLON.StandardMaterial.BumpTextureEnabled) {
  2839. defines._needUVs = true;
  2840. defines._needNormals = true;
  2841. defines.BUMP = true;
  2842. }
  2843. }
  2844. // Misc.
  2845. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  2846. // Lights
  2847. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  2848. // Values that need to be evaluated on every frame
  2849. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  2850. // Attribs
  2851. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  2852. // Get correct effect
  2853. if (defines.isDirty) {
  2854. defines.markAsProcessed();
  2855. scene.resetCachedMaterial();
  2856. // Fallbacks
  2857. var fallbacks = new BABYLON.EffectFallbacks();
  2858. if (defines.FOG) {
  2859. fallbacks.addFallback(1, "FOG");
  2860. }
  2861. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  2862. if (defines.NUM_BONE_INFLUENCERS > 0) {
  2863. fallbacks.addCPUSkinningFallback(0, mesh);
  2864. }
  2865. //Attributes
  2866. var attribs = [BABYLON.VertexBuffer.PositionKind];
  2867. if (defines.NORMAL) {
  2868. attribs.push(BABYLON.VertexBuffer.NormalKind);
  2869. }
  2870. if (defines.UV1) {
  2871. attribs.push(BABYLON.VertexBuffer.UVKind);
  2872. }
  2873. if (defines.UV2) {
  2874. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  2875. }
  2876. if (defines.VERTEXCOLOR) {
  2877. attribs.push(BABYLON.VertexBuffer.ColorKind);
  2878. }
  2879. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  2880. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  2881. // Legacy browser patch
  2882. var shaderName = "terrain";
  2883. var join = defines.toString();
  2884. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  2885. "vFogInfos", "vFogColor", "pointSize",
  2886. "vTextureInfos",
  2887. "mBones",
  2888. "vClipPlane", "textureMatrix",
  2889. "diffuse1Infos", "diffuse2Infos", "diffuse3Infos"
  2890. ];
  2891. var samplers = ["textureSampler", "diffuse1Sampler", "diffuse2Sampler", "diffuse3Sampler",
  2892. "bump1Sampler", "bump2Sampler", "bump3Sampler"
  2893. ];
  2894. var uniformBuffers = new Array();
  2895. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  2896. uniformsNames: uniforms,
  2897. uniformBuffersNames: uniformBuffers,
  2898. samplers: samplers,
  2899. defines: defines,
  2900. maxSimultaneousLights: this.maxSimultaneousLights
  2901. });
  2902. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  2903. attributes: attribs,
  2904. uniformsNames: uniforms,
  2905. uniformBuffersNames: uniformBuffers,
  2906. samplers: samplers,
  2907. defines: join,
  2908. fallbacks: fallbacks,
  2909. onCompiled: this.onCompiled,
  2910. onError: this.onError,
  2911. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  2912. }, engine), defines);
  2913. }
  2914. if (!subMesh.effect || !subMesh.effect.isReady()) {
  2915. return false;
  2916. }
  2917. this._renderId = scene.getRenderId();
  2918. this._wasPreviouslyReady = true;
  2919. return true;
  2920. };
  2921. TerrainMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  2922. var scene = this.getScene();
  2923. var defines = subMesh._materialDefines;
  2924. if (!defines) {
  2925. return;
  2926. }
  2927. var effect = subMesh.effect;
  2928. if (!effect) {
  2929. return;
  2930. }
  2931. this._activeEffect = effect;
  2932. // Matrices
  2933. this.bindOnlyWorldMatrix(world);
  2934. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  2935. // Bones
  2936. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  2937. if (this._mustRebind(scene, effect)) {
  2938. // Textures
  2939. if (this.mixTexture) {
  2940. this._activeEffect.setTexture("textureSampler", this._mixTexture);
  2941. this._activeEffect.setFloat2("vTextureInfos", this._mixTexture.coordinatesIndex, this._mixTexture.level);
  2942. this._activeEffect.setMatrix("textureMatrix", this._mixTexture.getTextureMatrix());
  2943. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2944. if (this._diffuseTexture1) {
  2945. this._activeEffect.setTexture("diffuse1Sampler", this._diffuseTexture1);
  2946. this._activeEffect.setFloat2("diffuse1Infos", this._diffuseTexture1.uScale, this._diffuseTexture1.vScale);
  2947. }
  2948. if (this._diffuseTexture2) {
  2949. this._activeEffect.setTexture("diffuse2Sampler", this._diffuseTexture2);
  2950. this._activeEffect.setFloat2("diffuse2Infos", this._diffuseTexture2.uScale, this._diffuseTexture2.vScale);
  2951. }
  2952. if (this._diffuseTexture3) {
  2953. this._activeEffect.setTexture("diffuse3Sampler", this._diffuseTexture3);
  2954. this._activeEffect.setFloat2("diffuse3Infos", this._diffuseTexture3.uScale, this._diffuseTexture3.vScale);
  2955. }
  2956. }
  2957. if (BABYLON.StandardMaterial.BumpTextureEnabled && scene.getEngine().getCaps().standardDerivatives) {
  2958. if (this._bumpTexture1) {
  2959. this._activeEffect.setTexture("bump1Sampler", this._bumpTexture1);
  2960. }
  2961. if (this._bumpTexture2) {
  2962. this._activeEffect.setTexture("bump2Sampler", this._bumpTexture2);
  2963. }
  2964. if (this._bumpTexture3) {
  2965. this._activeEffect.setTexture("bump3Sampler", this._bumpTexture3);
  2966. }
  2967. }
  2968. }
  2969. // Clip plane
  2970. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  2971. // Point size
  2972. if (this.pointsCloud) {
  2973. this._activeEffect.setFloat("pointSize", this.pointSize);
  2974. }
  2975. this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  2976. }
  2977. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  2978. if (defines.SPECULARTERM) {
  2979. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  2980. }
  2981. if (scene.lightsEnabled && !this.disableLighting) {
  2982. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  2983. }
  2984. // View
  2985. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  2986. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  2987. }
  2988. // Fog
  2989. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  2990. this._afterBind(mesh, this._activeEffect);
  2991. };
  2992. TerrainMaterial.prototype.getAnimatables = function () {
  2993. var results = [];
  2994. if (this.mixTexture && this.mixTexture.animations && this.mixTexture.animations.length > 0) {
  2995. results.push(this.mixTexture);
  2996. }
  2997. return results;
  2998. };
  2999. TerrainMaterial.prototype.getActiveTextures = function () {
  3000. var activeTextures = _super.prototype.getActiveTextures.call(this);
  3001. if (this._mixTexture) {
  3002. activeTextures.push(this._mixTexture);
  3003. }
  3004. if (this._diffuseTexture1) {
  3005. activeTextures.push(this._diffuseTexture1);
  3006. }
  3007. if (this._diffuseTexture2) {
  3008. activeTextures.push(this._diffuseTexture2);
  3009. }
  3010. if (this._diffuseTexture3) {
  3011. activeTextures.push(this._diffuseTexture3);
  3012. }
  3013. if (this._bumpTexture1) {
  3014. activeTextures.push(this._bumpTexture1);
  3015. }
  3016. if (this._bumpTexture2) {
  3017. activeTextures.push(this._bumpTexture2);
  3018. }
  3019. if (this._bumpTexture3) {
  3020. activeTextures.push(this._bumpTexture3);
  3021. }
  3022. return activeTextures;
  3023. };
  3024. TerrainMaterial.prototype.hasTexture = function (texture) {
  3025. if (_super.prototype.hasTexture.call(this, texture)) {
  3026. return true;
  3027. }
  3028. if (this._mixTexture === texture) {
  3029. return true;
  3030. }
  3031. if (this._diffuseTexture1 === texture) {
  3032. return true;
  3033. }
  3034. if (this._diffuseTexture2 === texture) {
  3035. return true;
  3036. }
  3037. if (this._diffuseTexture3 === texture) {
  3038. return true;
  3039. }
  3040. if (this._bumpTexture1 === texture) {
  3041. return true;
  3042. }
  3043. if (this._bumpTexture2 === texture) {
  3044. return true;
  3045. }
  3046. if (this._bumpTexture3 === texture) {
  3047. return true;
  3048. }
  3049. return false;
  3050. };
  3051. TerrainMaterial.prototype.dispose = function (forceDisposeEffect) {
  3052. if (this.mixTexture) {
  3053. this.mixTexture.dispose();
  3054. }
  3055. _super.prototype.dispose.call(this, forceDisposeEffect);
  3056. };
  3057. TerrainMaterial.prototype.clone = function (name) {
  3058. var _this = this;
  3059. return BABYLON.SerializationHelper.Clone(function () { return new TerrainMaterial(name, _this.getScene()); }, this);
  3060. };
  3061. TerrainMaterial.prototype.serialize = function () {
  3062. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  3063. serializationObject.customType = "BABYLON.TerrainMaterial";
  3064. return serializationObject;
  3065. };
  3066. TerrainMaterial.prototype.getClassName = function () {
  3067. return "TerrainMaterial";
  3068. };
  3069. // Statics
  3070. TerrainMaterial.Parse = function (source, scene, rootUrl) {
  3071. return BABYLON.SerializationHelper.Parse(function () { return new TerrainMaterial(source.name, scene); }, source, scene, rootUrl);
  3072. };
  3073. __decorate([
  3074. BABYLON.serializeAsTexture("mixTexture")
  3075. ], TerrainMaterial.prototype, "_mixTexture", void 0);
  3076. __decorate([
  3077. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3078. ], TerrainMaterial.prototype, "mixTexture", void 0);
  3079. __decorate([
  3080. BABYLON.serializeAsTexture("diffuseTexture1")
  3081. ], TerrainMaterial.prototype, "_diffuseTexture1", void 0);
  3082. __decorate([
  3083. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3084. ], TerrainMaterial.prototype, "diffuseTexture1", void 0);
  3085. __decorate([
  3086. BABYLON.serializeAsTexture("diffuseTexture2")
  3087. ], TerrainMaterial.prototype, "_diffuseTexture2", void 0);
  3088. __decorate([
  3089. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3090. ], TerrainMaterial.prototype, "diffuseTexture2", void 0);
  3091. __decorate([
  3092. BABYLON.serializeAsTexture("diffuseTexture3")
  3093. ], TerrainMaterial.prototype, "_diffuseTexture3", void 0);
  3094. __decorate([
  3095. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3096. ], TerrainMaterial.prototype, "diffuseTexture3", void 0);
  3097. __decorate([
  3098. BABYLON.serializeAsTexture("bumpTexture1")
  3099. ], TerrainMaterial.prototype, "_bumpTexture1", void 0);
  3100. __decorate([
  3101. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3102. ], TerrainMaterial.prototype, "bumpTexture1", void 0);
  3103. __decorate([
  3104. BABYLON.serializeAsTexture("bumpTexture2")
  3105. ], TerrainMaterial.prototype, "_bumpTexture2", void 0);
  3106. __decorate([
  3107. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3108. ], TerrainMaterial.prototype, "bumpTexture2", void 0);
  3109. __decorate([
  3110. BABYLON.serializeAsTexture("bumpTexture3")
  3111. ], TerrainMaterial.prototype, "_bumpTexture3", void 0);
  3112. __decorate([
  3113. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3114. ], TerrainMaterial.prototype, "bumpTexture3", void 0);
  3115. __decorate([
  3116. BABYLON.serializeAsColor3()
  3117. ], TerrainMaterial.prototype, "diffuseColor", void 0);
  3118. __decorate([
  3119. BABYLON.serializeAsColor3()
  3120. ], TerrainMaterial.prototype, "specularColor", void 0);
  3121. __decorate([
  3122. BABYLON.serialize()
  3123. ], TerrainMaterial.prototype, "specularPower", void 0);
  3124. __decorate([
  3125. BABYLON.serialize("disableLighting")
  3126. ], TerrainMaterial.prototype, "_disableLighting", void 0);
  3127. __decorate([
  3128. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3129. ], TerrainMaterial.prototype, "disableLighting", void 0);
  3130. __decorate([
  3131. BABYLON.serialize("maxSimultaneousLights")
  3132. ], TerrainMaterial.prototype, "_maxSimultaneousLights", void 0);
  3133. __decorate([
  3134. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3135. ], TerrainMaterial.prototype, "maxSimultaneousLights", void 0);
  3136. return TerrainMaterial;
  3137. }(BABYLON.PushMaterial));
  3138. BABYLON.TerrainMaterial = TerrainMaterial;
  3139. })(BABYLON || (BABYLON = {}));
  3140. //# sourceMappingURL=babylon.terrainMaterial.js.map
  3141. 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";
  3142. 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";
  3143. var BABYLON;
  3144. (function (BABYLON) {
  3145. var TriPlanarMaterialDefines = /** @class */ (function (_super) {
  3146. __extends(TriPlanarMaterialDefines, _super);
  3147. function TriPlanarMaterialDefines() {
  3148. var _this = _super.call(this) || this;
  3149. _this.DIFFUSEX = false;
  3150. _this.DIFFUSEY = false;
  3151. _this.DIFFUSEZ = false;
  3152. _this.BUMPX = false;
  3153. _this.BUMPY = false;
  3154. _this.BUMPZ = false;
  3155. _this.CLIPPLANE = false;
  3156. _this.ALPHATEST = false;
  3157. _this.DEPTHPREPASS = false;
  3158. _this.POINTSIZE = false;
  3159. _this.FOG = false;
  3160. _this.SPECULARTERM = false;
  3161. _this.NORMAL = false;
  3162. _this.VERTEXCOLOR = false;
  3163. _this.VERTEXALPHA = false;
  3164. _this.NUM_BONE_INFLUENCERS = 0;
  3165. _this.BonesPerMesh = 0;
  3166. _this.INSTANCES = false;
  3167. _this.rebuild();
  3168. return _this;
  3169. }
  3170. return TriPlanarMaterialDefines;
  3171. }(BABYLON.MaterialDefines));
  3172. var TriPlanarMaterial = /** @class */ (function (_super) {
  3173. __extends(TriPlanarMaterial, _super);
  3174. function TriPlanarMaterial(name, scene) {
  3175. var _this = _super.call(this, name, scene) || this;
  3176. _this.tileSize = 1;
  3177. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  3178. _this.specularColor = new BABYLON.Color3(0.2, 0.2, 0.2);
  3179. _this.specularPower = 64;
  3180. _this._disableLighting = false;
  3181. _this._maxSimultaneousLights = 4;
  3182. return _this;
  3183. }
  3184. TriPlanarMaterial.prototype.needAlphaBlending = function () {
  3185. return (this.alpha < 1.0);
  3186. };
  3187. TriPlanarMaterial.prototype.needAlphaTesting = function () {
  3188. return false;
  3189. };
  3190. TriPlanarMaterial.prototype.getAlphaTestTexture = function () {
  3191. return null;
  3192. };
  3193. // Methods
  3194. TriPlanarMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  3195. if (this.isFrozen) {
  3196. if (this._wasPreviouslyReady && subMesh.effect) {
  3197. return true;
  3198. }
  3199. }
  3200. if (!subMesh._materialDefines) {
  3201. subMesh._materialDefines = new TriPlanarMaterialDefines();
  3202. }
  3203. var defines = subMesh._materialDefines;
  3204. var scene = this.getScene();
  3205. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  3206. if (this._renderId === scene.getRenderId()) {
  3207. return true;
  3208. }
  3209. }
  3210. var engine = scene.getEngine();
  3211. // Textures
  3212. if (defines._areTexturesDirty) {
  3213. if (scene.texturesEnabled) {
  3214. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  3215. var textures = [this.diffuseTextureX, this.diffuseTextureY, this.diffuseTextureZ];
  3216. var textureDefines = ["DIFFUSEX", "DIFFUSEY", "DIFFUSEZ"];
  3217. for (var i = 0; i < textures.length; i++) {
  3218. if (textures[i]) {
  3219. if (!textures[i].isReady()) {
  3220. return false;
  3221. }
  3222. else {
  3223. defines[textureDefines[i]] = true;
  3224. }
  3225. }
  3226. }
  3227. }
  3228. if (BABYLON.StandardMaterial.BumpTextureEnabled) {
  3229. var textures = [this.normalTextureX, this.normalTextureY, this.normalTextureZ];
  3230. var textureDefines = ["BUMPX", "BUMPY", "BUMPZ"];
  3231. for (var i = 0; i < textures.length; i++) {
  3232. if (textures[i]) {
  3233. if (!textures[i].isReady()) {
  3234. return false;
  3235. }
  3236. else {
  3237. defines[textureDefines[i]] = true;
  3238. }
  3239. }
  3240. }
  3241. }
  3242. }
  3243. }
  3244. // Misc.
  3245. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  3246. // Lights
  3247. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  3248. // Values that need to be evaluated on every frame
  3249. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  3250. // Attribs
  3251. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  3252. // Get correct effect
  3253. if (defines.isDirty) {
  3254. defines.markAsProcessed();
  3255. scene.resetCachedMaterial();
  3256. // Fallbacks
  3257. var fallbacks = new BABYLON.EffectFallbacks();
  3258. if (defines.FOG) {
  3259. fallbacks.addFallback(1, "FOG");
  3260. }
  3261. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  3262. if (defines.NUM_BONE_INFLUENCERS > 0) {
  3263. fallbacks.addCPUSkinningFallback(0, mesh);
  3264. }
  3265. //Attributes
  3266. var attribs = [BABYLON.VertexBuffer.PositionKind];
  3267. if (defines.NORMAL) {
  3268. attribs.push(BABYLON.VertexBuffer.NormalKind);
  3269. }
  3270. if (defines.VERTEXCOLOR) {
  3271. attribs.push(BABYLON.VertexBuffer.ColorKind);
  3272. }
  3273. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  3274. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  3275. // Legacy browser patch
  3276. var shaderName = "triplanar";
  3277. var join = defines.toString();
  3278. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  3279. "vFogInfos", "vFogColor", "pointSize",
  3280. "mBones",
  3281. "vClipPlane",
  3282. "tileSize"
  3283. ];
  3284. var samplers = ["diffuseSamplerX", "diffuseSamplerY", "diffuseSamplerZ",
  3285. "normalSamplerX", "normalSamplerY", "normalSamplerZ"
  3286. ];
  3287. var uniformBuffers = new Array();
  3288. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  3289. uniformsNames: uniforms,
  3290. uniformBuffersNames: uniformBuffers,
  3291. samplers: samplers,
  3292. defines: defines,
  3293. maxSimultaneousLights: this.maxSimultaneousLights
  3294. });
  3295. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  3296. attributes: attribs,
  3297. uniformsNames: uniforms,
  3298. uniformBuffersNames: uniformBuffers,
  3299. samplers: samplers,
  3300. defines: join,
  3301. fallbacks: fallbacks,
  3302. onCompiled: this.onCompiled,
  3303. onError: this.onError,
  3304. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  3305. }, engine), defines);
  3306. }
  3307. if (!subMesh.effect || !subMesh.effect.isReady()) {
  3308. return false;
  3309. }
  3310. this._renderId = scene.getRenderId();
  3311. this._wasPreviouslyReady = true;
  3312. return true;
  3313. };
  3314. TriPlanarMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  3315. var scene = this.getScene();
  3316. var defines = subMesh._materialDefines;
  3317. if (!defines) {
  3318. return;
  3319. }
  3320. var effect = subMesh.effect;
  3321. if (!effect) {
  3322. return;
  3323. }
  3324. this._activeEffect = effect;
  3325. // Matrices
  3326. this.bindOnlyWorldMatrix(world);
  3327. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  3328. // Bones
  3329. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  3330. this._activeEffect.setFloat("tileSize", this.tileSize);
  3331. if (scene.getCachedMaterial() !== this) {
  3332. // Textures
  3333. if (this.diffuseTextureX) {
  3334. this._activeEffect.setTexture("diffuseSamplerX", this.diffuseTextureX);
  3335. }
  3336. if (this.diffuseTextureY) {
  3337. this._activeEffect.setTexture("diffuseSamplerY", this.diffuseTextureY);
  3338. }
  3339. if (this.diffuseTextureZ) {
  3340. this._activeEffect.setTexture("diffuseSamplerZ", this.diffuseTextureZ);
  3341. }
  3342. if (this.normalTextureX) {
  3343. this._activeEffect.setTexture("normalSamplerX", this.normalTextureX);
  3344. }
  3345. if (this.normalTextureY) {
  3346. this._activeEffect.setTexture("normalSamplerY", this.normalTextureY);
  3347. }
  3348. if (this.normalTextureZ) {
  3349. this._activeEffect.setTexture("normalSamplerZ", this.normalTextureZ);
  3350. }
  3351. // Clip plane
  3352. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  3353. // Point size
  3354. if (this.pointsCloud) {
  3355. this._activeEffect.setFloat("pointSize", this.pointSize);
  3356. }
  3357. this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  3358. }
  3359. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  3360. if (defines.SPECULARTERM) {
  3361. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  3362. }
  3363. if (scene.lightsEnabled && !this.disableLighting) {
  3364. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  3365. }
  3366. // View
  3367. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  3368. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  3369. }
  3370. // Fog
  3371. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  3372. this._afterBind(mesh, this._activeEffect);
  3373. };
  3374. TriPlanarMaterial.prototype.getAnimatables = function () {
  3375. var results = [];
  3376. if (this.mixTexture && this.mixTexture.animations && this.mixTexture.animations.length > 0) {
  3377. results.push(this.mixTexture);
  3378. }
  3379. return results;
  3380. };
  3381. TriPlanarMaterial.prototype.getActiveTextures = function () {
  3382. var activeTextures = _super.prototype.getActiveTextures.call(this);
  3383. if (this._diffuseTextureX) {
  3384. activeTextures.push(this._diffuseTextureX);
  3385. }
  3386. if (this._diffuseTextureY) {
  3387. activeTextures.push(this._diffuseTextureY);
  3388. }
  3389. if (this._diffuseTextureZ) {
  3390. activeTextures.push(this._diffuseTextureZ);
  3391. }
  3392. if (this._normalTextureX) {
  3393. activeTextures.push(this._normalTextureX);
  3394. }
  3395. if (this._normalTextureY) {
  3396. activeTextures.push(this._normalTextureY);
  3397. }
  3398. if (this._normalTextureZ) {
  3399. activeTextures.push(this._normalTextureZ);
  3400. }
  3401. return activeTextures;
  3402. };
  3403. TriPlanarMaterial.prototype.hasTexture = function (texture) {
  3404. if (_super.prototype.hasTexture.call(this, texture)) {
  3405. return true;
  3406. }
  3407. if (this._diffuseTextureX === texture) {
  3408. return true;
  3409. }
  3410. if (this._diffuseTextureY === texture) {
  3411. return true;
  3412. }
  3413. if (this._diffuseTextureZ === texture) {
  3414. return true;
  3415. }
  3416. if (this._normalTextureX === texture) {
  3417. return true;
  3418. }
  3419. if (this._normalTextureY === texture) {
  3420. return true;
  3421. }
  3422. if (this._normalTextureZ === texture) {
  3423. return true;
  3424. }
  3425. return false;
  3426. };
  3427. TriPlanarMaterial.prototype.dispose = function (forceDisposeEffect) {
  3428. if (this.mixTexture) {
  3429. this.mixTexture.dispose();
  3430. }
  3431. _super.prototype.dispose.call(this, forceDisposeEffect);
  3432. };
  3433. TriPlanarMaterial.prototype.clone = function (name) {
  3434. var _this = this;
  3435. return BABYLON.SerializationHelper.Clone(function () { return new TriPlanarMaterial(name, _this.getScene()); }, this);
  3436. };
  3437. TriPlanarMaterial.prototype.serialize = function () {
  3438. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  3439. serializationObject.customType = "BABYLON.TriPlanarMaterial";
  3440. return serializationObject;
  3441. };
  3442. TriPlanarMaterial.prototype.getClassName = function () {
  3443. return "TriPlanarMaterial";
  3444. };
  3445. // Statics
  3446. TriPlanarMaterial.Parse = function (source, scene, rootUrl) {
  3447. return BABYLON.SerializationHelper.Parse(function () { return new TriPlanarMaterial(source.name, scene); }, source, scene, rootUrl);
  3448. };
  3449. __decorate([
  3450. BABYLON.serializeAsTexture()
  3451. ], TriPlanarMaterial.prototype, "mixTexture", void 0);
  3452. __decorate([
  3453. BABYLON.serializeAsTexture("diffuseTextureX")
  3454. ], TriPlanarMaterial.prototype, "_diffuseTextureX", void 0);
  3455. __decorate([
  3456. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3457. ], TriPlanarMaterial.prototype, "diffuseTextureX", void 0);
  3458. __decorate([
  3459. BABYLON.serializeAsTexture("diffuseTexturY")
  3460. ], TriPlanarMaterial.prototype, "_diffuseTextureY", void 0);
  3461. __decorate([
  3462. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3463. ], TriPlanarMaterial.prototype, "diffuseTextureY", void 0);
  3464. __decorate([
  3465. BABYLON.serializeAsTexture("diffuseTextureZ")
  3466. ], TriPlanarMaterial.prototype, "_diffuseTextureZ", void 0);
  3467. __decorate([
  3468. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3469. ], TriPlanarMaterial.prototype, "diffuseTextureZ", void 0);
  3470. __decorate([
  3471. BABYLON.serializeAsTexture("normalTextureX")
  3472. ], TriPlanarMaterial.prototype, "_normalTextureX", void 0);
  3473. __decorate([
  3474. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3475. ], TriPlanarMaterial.prototype, "normalTextureX", void 0);
  3476. __decorate([
  3477. BABYLON.serializeAsTexture("normalTextureY")
  3478. ], TriPlanarMaterial.prototype, "_normalTextureY", void 0);
  3479. __decorate([
  3480. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3481. ], TriPlanarMaterial.prototype, "normalTextureY", void 0);
  3482. __decorate([
  3483. BABYLON.serializeAsTexture("normalTextureZ")
  3484. ], TriPlanarMaterial.prototype, "_normalTextureZ", void 0);
  3485. __decorate([
  3486. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3487. ], TriPlanarMaterial.prototype, "normalTextureZ", void 0);
  3488. __decorate([
  3489. BABYLON.serialize()
  3490. ], TriPlanarMaterial.prototype, "tileSize", void 0);
  3491. __decorate([
  3492. BABYLON.serializeAsColor3()
  3493. ], TriPlanarMaterial.prototype, "diffuseColor", void 0);
  3494. __decorate([
  3495. BABYLON.serializeAsColor3()
  3496. ], TriPlanarMaterial.prototype, "specularColor", void 0);
  3497. __decorate([
  3498. BABYLON.serialize()
  3499. ], TriPlanarMaterial.prototype, "specularPower", void 0);
  3500. __decorate([
  3501. BABYLON.serialize("disableLighting")
  3502. ], TriPlanarMaterial.prototype, "_disableLighting", void 0);
  3503. __decorate([
  3504. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3505. ], TriPlanarMaterial.prototype, "disableLighting", void 0);
  3506. __decorate([
  3507. BABYLON.serialize("maxSimultaneousLights")
  3508. ], TriPlanarMaterial.prototype, "_maxSimultaneousLights", void 0);
  3509. __decorate([
  3510. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3511. ], TriPlanarMaterial.prototype, "maxSimultaneousLights", void 0);
  3512. return TriPlanarMaterial;
  3513. }(BABYLON.PushMaterial));
  3514. BABYLON.TriPlanarMaterial = TriPlanarMaterial;
  3515. })(BABYLON || (BABYLON = {}));
  3516. //# sourceMappingURL=babylon.triPlanarMaterial.js.map
  3517. 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";
  3518. 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";
  3519. var BABYLON;
  3520. (function (BABYLON) {
  3521. var SkyMaterialDefines = /** @class */ (function (_super) {
  3522. __extends(SkyMaterialDefines, _super);
  3523. function SkyMaterialDefines() {
  3524. var _this = _super.call(this) || this;
  3525. _this.CLIPPLANE = false;
  3526. _this.POINTSIZE = false;
  3527. _this.FOG = false;
  3528. _this.VERTEXCOLOR = false;
  3529. _this.VERTEXALPHA = false;
  3530. _this.rebuild();
  3531. return _this;
  3532. }
  3533. return SkyMaterialDefines;
  3534. }(BABYLON.MaterialDefines));
  3535. var SkyMaterial = /** @class */ (function (_super) {
  3536. __extends(SkyMaterial, _super);
  3537. function SkyMaterial(name, scene) {
  3538. var _this = _super.call(this, name, scene) || this;
  3539. // Public members
  3540. _this.luminance = 1.0;
  3541. _this.turbidity = 10.0;
  3542. _this.rayleigh = 2.0;
  3543. _this.mieCoefficient = 0.005;
  3544. _this.mieDirectionalG = 0.8;
  3545. _this.distance = 500;
  3546. _this.inclination = 0.49;
  3547. _this.azimuth = 0.25;
  3548. _this.sunPosition = new BABYLON.Vector3(0, 100, 0);
  3549. _this.useSunPosition = false;
  3550. // Private members
  3551. _this._cameraPosition = BABYLON.Vector3.Zero();
  3552. return _this;
  3553. }
  3554. SkyMaterial.prototype.needAlphaBlending = function () {
  3555. return (this.alpha < 1.0);
  3556. };
  3557. SkyMaterial.prototype.needAlphaTesting = function () {
  3558. return false;
  3559. };
  3560. SkyMaterial.prototype.getAlphaTestTexture = function () {
  3561. return null;
  3562. };
  3563. // Methods
  3564. SkyMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  3565. if (this.isFrozen) {
  3566. if (this._wasPreviouslyReady && subMesh.effect) {
  3567. return true;
  3568. }
  3569. }
  3570. if (!subMesh._materialDefines) {
  3571. subMesh._materialDefines = new SkyMaterialDefines();
  3572. }
  3573. var defines = subMesh._materialDefines;
  3574. var scene = this.getScene();
  3575. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  3576. if (this._renderId === scene.getRenderId()) {
  3577. return true;
  3578. }
  3579. }
  3580. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  3581. // Attribs
  3582. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, false);
  3583. // Get correct effect
  3584. if (defines.isDirty) {
  3585. defines.markAsProcessed();
  3586. scene.resetCachedMaterial();
  3587. // Fallbacks
  3588. var fallbacks = new BABYLON.EffectFallbacks();
  3589. if (defines.FOG) {
  3590. fallbacks.addFallback(1, "FOG");
  3591. }
  3592. //Attributes
  3593. var attribs = [BABYLON.VertexBuffer.PositionKind];
  3594. if (defines.VERTEXCOLOR) {
  3595. attribs.push(BABYLON.VertexBuffer.ColorKind);
  3596. }
  3597. var shaderName = "sky";
  3598. var join = defines.toString();
  3599. subMesh.setEffect(scene.getEngine().createEffect(shaderName, attribs, ["world", "viewProjection", "view",
  3600. "vFogInfos", "vFogColor", "pointSize", "vClipPlane",
  3601. "luminance", "turbidity", "rayleigh", "mieCoefficient", "mieDirectionalG", "sunPosition",
  3602. "cameraPosition"
  3603. ], [], join, fallbacks, this.onCompiled, this.onError), defines);
  3604. }
  3605. if (!subMesh.effect || !subMesh.effect.isReady()) {
  3606. return false;
  3607. }
  3608. this._renderId = scene.getRenderId();
  3609. this._wasPreviouslyReady = true;
  3610. return true;
  3611. };
  3612. SkyMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  3613. var scene = this.getScene();
  3614. var defines = subMesh._materialDefines;
  3615. if (!defines) {
  3616. return;
  3617. }
  3618. var effect = subMesh.effect;
  3619. if (!effect) {
  3620. return;
  3621. }
  3622. this._activeEffect = effect;
  3623. // Matrices
  3624. this.bindOnlyWorldMatrix(world);
  3625. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  3626. if (this._mustRebind(scene, effect)) {
  3627. // Clip plane
  3628. if (scene.clipPlane) {
  3629. var clipPlane = scene.clipPlane;
  3630. this._activeEffect.setFloat4("vClipPlane", clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);
  3631. }
  3632. // Point size
  3633. if (this.pointsCloud) {
  3634. this._activeEffect.setFloat("pointSize", this.pointSize);
  3635. }
  3636. }
  3637. // View
  3638. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  3639. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  3640. }
  3641. // Fog
  3642. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  3643. // Sky
  3644. var camera = scene.activeCamera;
  3645. if (camera) {
  3646. var cameraWorldMatrix = camera.getWorldMatrix();
  3647. this._cameraPosition.x = cameraWorldMatrix.m[12];
  3648. this._cameraPosition.y = cameraWorldMatrix.m[13];
  3649. this._cameraPosition.z = cameraWorldMatrix.m[14];
  3650. this._activeEffect.setVector3("cameraPosition", this._cameraPosition);
  3651. }
  3652. if (this.luminance > 0) {
  3653. this._activeEffect.setFloat("luminance", this.luminance);
  3654. }
  3655. this._activeEffect.setFloat("turbidity", this.turbidity);
  3656. this._activeEffect.setFloat("rayleigh", this.rayleigh);
  3657. this._activeEffect.setFloat("mieCoefficient", this.mieCoefficient);
  3658. this._activeEffect.setFloat("mieDirectionalG", this.mieDirectionalG);
  3659. if (!this.useSunPosition) {
  3660. var theta = Math.PI * (this.inclination - 0.5);
  3661. var phi = 2 * Math.PI * (this.azimuth - 0.5);
  3662. this.sunPosition.x = this.distance * Math.cos(phi);
  3663. this.sunPosition.y = this.distance * Math.sin(phi) * Math.sin(theta);
  3664. this.sunPosition.z = this.distance * Math.sin(phi) * Math.cos(theta);
  3665. }
  3666. this._activeEffect.setVector3("sunPosition", this.sunPosition);
  3667. this._afterBind(mesh, this._activeEffect);
  3668. };
  3669. SkyMaterial.prototype.getAnimatables = function () {
  3670. return [];
  3671. };
  3672. SkyMaterial.prototype.dispose = function (forceDisposeEffect) {
  3673. _super.prototype.dispose.call(this, forceDisposeEffect);
  3674. };
  3675. SkyMaterial.prototype.clone = function (name) {
  3676. var _this = this;
  3677. return BABYLON.SerializationHelper.Clone(function () { return new SkyMaterial(name, _this.getScene()); }, this);
  3678. };
  3679. SkyMaterial.prototype.serialize = function () {
  3680. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  3681. serializationObject.customType = "BABYLON.SkyMaterial";
  3682. return serializationObject;
  3683. };
  3684. SkyMaterial.prototype.getClassName = function () {
  3685. return "SkyMaterial";
  3686. };
  3687. // Statics
  3688. SkyMaterial.Parse = function (source, scene, rootUrl) {
  3689. return BABYLON.SerializationHelper.Parse(function () { return new SkyMaterial(source.name, scene); }, source, scene, rootUrl);
  3690. };
  3691. __decorate([
  3692. BABYLON.serialize()
  3693. ], SkyMaterial.prototype, "luminance", void 0);
  3694. __decorate([
  3695. BABYLON.serialize()
  3696. ], SkyMaterial.prototype, "turbidity", void 0);
  3697. __decorate([
  3698. BABYLON.serialize()
  3699. ], SkyMaterial.prototype, "rayleigh", void 0);
  3700. __decorate([
  3701. BABYLON.serialize()
  3702. ], SkyMaterial.prototype, "mieCoefficient", void 0);
  3703. __decorate([
  3704. BABYLON.serialize()
  3705. ], SkyMaterial.prototype, "mieDirectionalG", void 0);
  3706. __decorate([
  3707. BABYLON.serialize()
  3708. ], SkyMaterial.prototype, "distance", void 0);
  3709. __decorate([
  3710. BABYLON.serialize()
  3711. ], SkyMaterial.prototype, "inclination", void 0);
  3712. __decorate([
  3713. BABYLON.serialize()
  3714. ], SkyMaterial.prototype, "azimuth", void 0);
  3715. __decorate([
  3716. BABYLON.serializeAsVector3()
  3717. ], SkyMaterial.prototype, "sunPosition", void 0);
  3718. __decorate([
  3719. BABYLON.serialize()
  3720. ], SkyMaterial.prototype, "useSunPosition", void 0);
  3721. return SkyMaterial;
  3722. }(BABYLON.PushMaterial));
  3723. BABYLON.SkyMaterial = SkyMaterial;
  3724. })(BABYLON || (BABYLON = {}));
  3725. //# sourceMappingURL=babylon.skyMaterial.js.map
  3726. 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";
  3727. 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}";
  3728. var BABYLON;
  3729. (function (BABYLON) {
  3730. var GridMaterialDefines = /** @class */ (function (_super) {
  3731. __extends(GridMaterialDefines, _super);
  3732. function GridMaterialDefines() {
  3733. var _this = _super.call(this) || this;
  3734. _this.TRANSPARENT = false;
  3735. _this.FOG = false;
  3736. _this.PREMULTIPLYALPHA = false;
  3737. _this.rebuild();
  3738. return _this;
  3739. }
  3740. return GridMaterialDefines;
  3741. }(BABYLON.MaterialDefines));
  3742. /**
  3743. * The grid materials allows you to wrap any shape with a grid.
  3744. * Colors are customizable.
  3745. */
  3746. var GridMaterial = /** @class */ (function (_super) {
  3747. __extends(GridMaterial, _super);
  3748. /**
  3749. * constructor
  3750. * @param name The name given to the material in order to identify it afterwards.
  3751. * @param scene The scene the material is used in.
  3752. */
  3753. function GridMaterial(name, scene) {
  3754. var _this = _super.call(this, name, scene) || this;
  3755. /**
  3756. * Main color of the grid (e.g. between lines)
  3757. */
  3758. _this.mainColor = BABYLON.Color3.Black();
  3759. /**
  3760. * Color of the grid lines.
  3761. */
  3762. _this.lineColor = BABYLON.Color3.Teal();
  3763. /**
  3764. * The scale of the grid compared to unit.
  3765. */
  3766. _this.gridRatio = 1.0;
  3767. /**
  3768. * Allows setting an offset for the grid lines.
  3769. */
  3770. _this.gridOffset = BABYLON.Vector3.Zero();
  3771. /**
  3772. * The frequency of thicker lines.
  3773. */
  3774. _this.majorUnitFrequency = 10;
  3775. /**
  3776. * The visibility of minor units in the grid.
  3777. */
  3778. _this.minorUnitVisibility = 0.33;
  3779. /**
  3780. * The grid opacity outside of the lines.
  3781. */
  3782. _this.opacity = 1.0;
  3783. /**
  3784. * Determine RBG output is premultiplied by alpha value.
  3785. */
  3786. _this.preMultiplyAlpha = false;
  3787. _this._gridControl = new BABYLON.Vector4(_this.gridRatio, _this.majorUnitFrequency, _this.minorUnitVisibility, _this.opacity);
  3788. return _this;
  3789. }
  3790. /**
  3791. * Returns wehter or not the grid requires alpha blending.
  3792. */
  3793. GridMaterial.prototype.needAlphaBlending = function () {
  3794. return this.opacity < 1.0;
  3795. };
  3796. GridMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  3797. if (this.isFrozen) {
  3798. if (this._wasPreviouslyReady && subMesh.effect) {
  3799. return true;
  3800. }
  3801. }
  3802. if (!subMesh._materialDefines) {
  3803. subMesh._materialDefines = new GridMaterialDefines();
  3804. }
  3805. var defines = subMesh._materialDefines;
  3806. var scene = this.getScene();
  3807. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  3808. if (this._renderId === scene.getRenderId()) {
  3809. return true;
  3810. }
  3811. }
  3812. if (defines.TRANSPARENT !== (this.opacity < 1.0)) {
  3813. defines.TRANSPARENT = !defines.TRANSPARENT;
  3814. defines.markAsUnprocessed();
  3815. }
  3816. if (defines.PREMULTIPLYALPHA != this.preMultiplyAlpha) {
  3817. defines.PREMULTIPLYALPHA = !defines.PREMULTIPLYALPHA;
  3818. defines.markAsUnprocessed();
  3819. }
  3820. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, false, this.fogEnabled, defines);
  3821. // Get correct effect
  3822. if (defines.isDirty) {
  3823. defines.markAsProcessed();
  3824. scene.resetCachedMaterial();
  3825. // Attributes
  3826. var attribs = [BABYLON.VertexBuffer.PositionKind, BABYLON.VertexBuffer.NormalKind];
  3827. // Defines
  3828. var join = defines.toString();
  3829. subMesh.setEffect(scene.getEngine().createEffect("grid", attribs, ["projection", "worldView", "mainColor", "lineColor", "gridControl", "gridOffset", "vFogInfos", "vFogColor", "world", "view"], [], join, undefined, this.onCompiled, this.onError), defines);
  3830. }
  3831. if (!subMesh.effect || !subMesh.effect.isReady()) {
  3832. return false;
  3833. }
  3834. this._renderId = scene.getRenderId();
  3835. this._wasPreviouslyReady = true;
  3836. return true;
  3837. };
  3838. GridMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  3839. var scene = this.getScene();
  3840. var defines = subMesh._materialDefines;
  3841. if (!defines) {
  3842. return;
  3843. }
  3844. var effect = subMesh.effect;
  3845. if (!effect) {
  3846. return;
  3847. }
  3848. this._activeEffect = effect;
  3849. // Matrices
  3850. this.bindOnlyWorldMatrix(world);
  3851. this._activeEffect.setMatrix("worldView", world.multiply(scene.getViewMatrix()));
  3852. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  3853. this._activeEffect.setMatrix("projection", scene.getProjectionMatrix());
  3854. // Uniforms
  3855. if (this._mustRebind(scene, effect)) {
  3856. this._activeEffect.setColor3("mainColor", this.mainColor);
  3857. this._activeEffect.setColor3("lineColor", this.lineColor);
  3858. this._activeEffect.setVector3("gridOffset", this.gridOffset);
  3859. this._gridControl.x = this.gridRatio;
  3860. this._gridControl.y = Math.round(this.majorUnitFrequency);
  3861. this._gridControl.z = this.minorUnitVisibility;
  3862. this._gridControl.w = this.opacity;
  3863. this._activeEffect.setVector4("gridControl", this._gridControl);
  3864. }
  3865. // Fog
  3866. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  3867. this._afterBind(mesh, this._activeEffect);
  3868. };
  3869. GridMaterial.prototype.dispose = function (forceDisposeEffect) {
  3870. _super.prototype.dispose.call(this, forceDisposeEffect);
  3871. };
  3872. GridMaterial.prototype.clone = function (name) {
  3873. var _this = this;
  3874. return BABYLON.SerializationHelper.Clone(function () { return new GridMaterial(name, _this.getScene()); }, this);
  3875. };
  3876. GridMaterial.prototype.serialize = function () {
  3877. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  3878. serializationObject.customType = "BABYLON.GridMaterial";
  3879. return serializationObject;
  3880. };
  3881. GridMaterial.prototype.getClassName = function () {
  3882. return "GridMaterial";
  3883. };
  3884. GridMaterial.Parse = function (source, scene, rootUrl) {
  3885. return BABYLON.SerializationHelper.Parse(function () { return new GridMaterial(source.name, scene); }, source, scene, rootUrl);
  3886. };
  3887. __decorate([
  3888. BABYLON.serializeAsColor3()
  3889. ], GridMaterial.prototype, "mainColor", void 0);
  3890. __decorate([
  3891. BABYLON.serializeAsColor3()
  3892. ], GridMaterial.prototype, "lineColor", void 0);
  3893. __decorate([
  3894. BABYLON.serialize()
  3895. ], GridMaterial.prototype, "gridRatio", void 0);
  3896. __decorate([
  3897. BABYLON.serializeAsColor3()
  3898. ], GridMaterial.prototype, "gridOffset", void 0);
  3899. __decorate([
  3900. BABYLON.serialize()
  3901. ], GridMaterial.prototype, "majorUnitFrequency", void 0);
  3902. __decorate([
  3903. BABYLON.serialize()
  3904. ], GridMaterial.prototype, "minorUnitVisibility", void 0);
  3905. __decorate([
  3906. BABYLON.serialize()
  3907. ], GridMaterial.prototype, "opacity", void 0);
  3908. __decorate([
  3909. BABYLON.serialize()
  3910. ], GridMaterial.prototype, "preMultiplyAlpha", void 0);
  3911. return GridMaterial;
  3912. }(BABYLON.PushMaterial));
  3913. BABYLON.GridMaterial = GridMaterial;
  3914. })(BABYLON || (BABYLON = {}));
  3915. //# sourceMappingURL=babylon.gridmaterial.js.map
  3916. 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}";
  3917. 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}";
  3918. var BABYLON;
  3919. (function (BABYLON) {
  3920. // old version of standard material updated every 3 months
  3921. var StandardMaterialDefines_OldVer = /** @class */ (function (_super) {
  3922. __extends(StandardMaterialDefines_OldVer, _super);
  3923. function StandardMaterialDefines_OldVer() {
  3924. var _this = _super.call(this) || this;
  3925. _this.DIFFUSE = false;
  3926. _this.AMBIENT = false;
  3927. _this.OPACITY = false;
  3928. _this.OPACITYRGB = false;
  3929. _this.REFLECTION = false;
  3930. _this.EMISSIVE = false;
  3931. _this.SPECULAR = false;
  3932. _this.BUMP = false;
  3933. _this.PARALLAX = false;
  3934. _this.PARALLAXOCCLUSION = false;
  3935. _this.SPECULAROVERALPHA = false;
  3936. _this.CLIPPLANE = false;
  3937. _this.ALPHATEST = false;
  3938. _this.ALPHAFROMDIFFUSE = false;
  3939. _this.POINTSIZE = false;
  3940. _this.FOG = false;
  3941. _this.SPECULARTERM = false;
  3942. _this.DIFFUSEFRESNEL = false;
  3943. _this.OPACITYFRESNEL = false;
  3944. _this.REFLECTIONFRESNEL = false;
  3945. _this.REFRACTIONFRESNEL = false;
  3946. _this.EMISSIVEFRESNEL = false;
  3947. _this.FRESNEL = false;
  3948. _this.NORMAL = false;
  3949. _this.UV1 = false;
  3950. _this.UV2 = false;
  3951. _this.VERTEXCOLOR = false;
  3952. _this.VERTEXALPHA = false;
  3953. _this.NUM_BONE_INFLUENCERS = 0;
  3954. _this.BonesPerMesh = 0;
  3955. _this.INSTANCES = false;
  3956. _this.GLOSSINESS = false;
  3957. _this.ROUGHNESS = false;
  3958. _this.EMISSIVEASILLUMINATION = false;
  3959. _this.LINKEMISSIVEWITHDIFFUSE = false;
  3960. _this.REFLECTIONFRESNELFROMSPECULAR = false;
  3961. _this.LIGHTMAP = false;
  3962. _this.USELIGHTMAPASSHADOWMAP = false;
  3963. _this.REFLECTIONMAP_3D = false;
  3964. _this.REFLECTIONMAP_SPHERICAL = false;
  3965. _this.REFLECTIONMAP_PLANAR = false;
  3966. _this.REFLECTIONMAP_CUBIC = false;
  3967. _this.REFLECTIONMAP_PROJECTION = false;
  3968. _this.REFLECTIONMAP_SKYBOX = false;
  3969. _this.REFLECTIONMAP_EXPLICIT = false;
  3970. _this.REFLECTIONMAP_EQUIRECTANGULAR = false;
  3971. _this.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;
  3972. _this.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;
  3973. _this.INVERTCUBICMAP = false;
  3974. _this.LOGARITHMICDEPTH = false;
  3975. _this.REFRACTION = false;
  3976. _this.REFRACTIONMAP_3D = false;
  3977. _this.REFLECTIONOVERALPHA = false;
  3978. _this.TWOSIDEDLIGHTING = false;
  3979. _this.SHADOWFLOAT = false;
  3980. _this.MORPHTARGETS = false;
  3981. _this.MORPHTARGETS_NORMAL = false;
  3982. _this.MORPHTARGETS_TANGENT = false;
  3983. _this.NUM_MORPH_INFLUENCERS = 0;
  3984. _this.IMAGEPROCESSING = false;
  3985. _this.VIGNETTE = false;
  3986. _this.VIGNETTEBLENDMODEMULTIPLY = false;
  3987. _this.VIGNETTEBLENDMODEOPAQUE = false;
  3988. _this.TONEMAPPING = false;
  3989. _this.CONTRAST = false;
  3990. _this.COLORCURVES = false;
  3991. _this.COLORGRADING = false;
  3992. _this.COLORGRADING3D = false;
  3993. _this.SAMPLER3DGREENDEPTH = false;
  3994. _this.SAMPLER3DBGRMAP = false;
  3995. _this.IMAGEPROCESSINGPOSTPROCESS = false;
  3996. _this.EXPOSURE = false;
  3997. _this.rebuild();
  3998. return _this;
  3999. }
  4000. StandardMaterialDefines_OldVer.prototype.setReflectionMode = function (modeToEnable) {
  4001. var modes = [
  4002. "REFLECTIONMAP_CUBIC", "REFLECTIONMAP_EXPLICIT", "REFLECTIONMAP_PLANAR",
  4003. "REFLECTIONMAP_PROJECTION", "REFLECTIONMAP_PROJECTION", "REFLECTIONMAP_SKYBOX",
  4004. "REFLECTIONMAP_SPHERICAL", "REFLECTIONMAP_EQUIRECTANGULAR", "REFLECTIONMAP_EQUIRECTANGULAR_FIXED",
  4005. "REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED"
  4006. ];
  4007. for (var _i = 0, modes_1 = modes; _i < modes_1.length; _i++) {
  4008. var mode = modes_1[_i];
  4009. this[mode] = (mode === modeToEnable);
  4010. }
  4011. };
  4012. return StandardMaterialDefines_OldVer;
  4013. }(BABYLON.MaterialDefines));
  4014. BABYLON.StandardMaterialDefines_OldVer = StandardMaterialDefines_OldVer;
  4015. var StandardMaterial_OldVer = /** @class */ (function (_super) {
  4016. __extends(StandardMaterial_OldVer, _super);
  4017. function StandardMaterial_OldVer(name, scene) {
  4018. var _this = _super.call(this, name, scene) || this;
  4019. _this.ambientColor = new BABYLON.Color3(0, 0, 0);
  4020. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  4021. _this.specularColor = new BABYLON.Color3(1, 1, 1);
  4022. _this.emissiveColor = new BABYLON.Color3(0, 0, 0);
  4023. _this.specularPower = 64;
  4024. _this._useAlphaFromDiffuseTexture = false;
  4025. _this._useEmissiveAsIllumination = false;
  4026. _this._linkEmissiveWithDiffuse = false;
  4027. _this._useSpecularOverAlpha = false;
  4028. _this._useReflectionOverAlpha = false;
  4029. _this._disableLighting = false;
  4030. _this._useParallax = false;
  4031. _this._useParallaxOcclusion = false;
  4032. _this.parallaxScaleBias = 0.05;
  4033. _this._roughness = 0;
  4034. _this.indexOfRefraction = 0.98;
  4035. _this.invertRefractionY = true;
  4036. _this._useLightmapAsShadowmap = false;
  4037. _this._useReflectionFresnelFromSpecular = false;
  4038. _this._useGlossinessFromSpecularMapAlpha = false;
  4039. _this._maxSimultaneousLights = 4;
  4040. /**
  4041. * If sets to true, x component of normal map value will invert (x = 1.0 - x).
  4042. */
  4043. _this._invertNormalMapX = false;
  4044. /**
  4045. * If sets to true, y component of normal map value will invert (y = 1.0 - y).
  4046. */
  4047. _this._invertNormalMapY = false;
  4048. /**
  4049. * If sets to true and backfaceCulling is false, normals will be flipped on the backside.
  4050. */
  4051. _this._twoSidedLighting = false;
  4052. _this._renderTargets = new BABYLON.SmartArray(16);
  4053. _this._worldViewProjectionMatrix = BABYLON.Matrix.Zero();
  4054. _this._globalAmbientColor = new BABYLON.Color3(0, 0, 0);
  4055. // Setup the default processing configuration to the scene.
  4056. _this._attachImageProcessingConfiguration(null);
  4057. _this.getRenderTargetTextures = function () {
  4058. _this._renderTargets.reset();
  4059. if (StandardMaterial_OldVer.ReflectionTextureEnabled && _this._reflectionTexture && _this._reflectionTexture.isRenderTarget) {
  4060. _this._renderTargets.push(_this._reflectionTexture);
  4061. }
  4062. if (StandardMaterial_OldVer.RefractionTextureEnabled && _this._refractionTexture && _this._refractionTexture.isRenderTarget) {
  4063. _this._renderTargets.push(_this._refractionTexture);
  4064. }
  4065. return _this._renderTargets;
  4066. };
  4067. return _this;
  4068. }
  4069. Object.defineProperty(StandardMaterial_OldVer.prototype, "imageProcessingConfiguration", {
  4070. /**
  4071. * Gets the image processing configuration used either in this material.
  4072. */
  4073. get: function () {
  4074. return this._imageProcessingConfiguration;
  4075. },
  4076. /**
  4077. * Sets the Default image processing configuration used either in the this material.
  4078. *
  4079. * If sets to null, the scene one is in use.
  4080. */
  4081. set: function (value) {
  4082. this._attachImageProcessingConfiguration(value);
  4083. // Ensure the effect will be rebuilt.
  4084. this._markAllSubMeshesAsTexturesDirty();
  4085. },
  4086. enumerable: true,
  4087. configurable: true
  4088. });
  4089. /**
  4090. * Attaches a new image processing configuration to the Standard Material.
  4091. * @param configuration
  4092. */
  4093. StandardMaterial_OldVer.prototype._attachImageProcessingConfiguration = function (configuration) {
  4094. var _this = this;
  4095. if (configuration === this._imageProcessingConfiguration) {
  4096. return;
  4097. }
  4098. // Detaches observer.
  4099. if (this._imageProcessingConfiguration && this._imageProcessingObserver) {
  4100. this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);
  4101. }
  4102. // Pick the scene configuration if needed.
  4103. if (!configuration) {
  4104. this._imageProcessingConfiguration = this.getScene().imageProcessingConfiguration;
  4105. }
  4106. else {
  4107. this._imageProcessingConfiguration = configuration;
  4108. }
  4109. // Attaches observer.
  4110. this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(function (conf) {
  4111. _this._markAllSubMeshesAsImageProcessingDirty();
  4112. });
  4113. };
  4114. Object.defineProperty(StandardMaterial_OldVer.prototype, "cameraColorCurvesEnabled", {
  4115. /**
  4116. * Gets wether the color curves effect is enabled.
  4117. */
  4118. get: function () {
  4119. return this.imageProcessingConfiguration.colorCurvesEnabled;
  4120. },
  4121. /**
  4122. * Sets wether the color curves effect is enabled.
  4123. */
  4124. set: function (value) {
  4125. this.imageProcessingConfiguration.colorCurvesEnabled = value;
  4126. },
  4127. enumerable: true,
  4128. configurable: true
  4129. });
  4130. Object.defineProperty(StandardMaterial_OldVer.prototype, "cameraColorGradingEnabled", {
  4131. /**
  4132. * Gets wether the color grading effect is enabled.
  4133. */
  4134. get: function () {
  4135. return this.imageProcessingConfiguration.colorGradingEnabled;
  4136. },
  4137. /**
  4138. * Gets wether the color grading effect is enabled.
  4139. */
  4140. set: function (value) {
  4141. this.imageProcessingConfiguration.colorGradingEnabled = value;
  4142. },
  4143. enumerable: true,
  4144. configurable: true
  4145. });
  4146. Object.defineProperty(StandardMaterial_OldVer.prototype, "cameraToneMappingEnabled", {
  4147. /**
  4148. * Gets wether tonemapping is enabled or not.
  4149. */
  4150. get: function () {
  4151. return this._imageProcessingConfiguration.toneMappingEnabled;
  4152. },
  4153. /**
  4154. * Sets wether tonemapping is enabled or not
  4155. */
  4156. set: function (value) {
  4157. this._imageProcessingConfiguration.toneMappingEnabled = value;
  4158. },
  4159. enumerable: true,
  4160. configurable: true
  4161. });
  4162. ;
  4163. ;
  4164. Object.defineProperty(StandardMaterial_OldVer.prototype, "cameraExposure", {
  4165. /**
  4166. * The camera exposure used on this material.
  4167. * This property is here and not in the camera to allow controlling exposure without full screen post process.
  4168. * This corresponds to a photographic exposure.
  4169. */
  4170. get: function () {
  4171. return this._imageProcessingConfiguration.exposure;
  4172. },
  4173. /**
  4174. * The camera exposure used on this material.
  4175. * This property is here and not in the camera to allow controlling exposure without full screen post process.
  4176. * This corresponds to a photographic exposure.
  4177. */
  4178. set: function (value) {
  4179. this._imageProcessingConfiguration.exposure = value;
  4180. },
  4181. enumerable: true,
  4182. configurable: true
  4183. });
  4184. ;
  4185. ;
  4186. Object.defineProperty(StandardMaterial_OldVer.prototype, "cameraContrast", {
  4187. /**
  4188. * Gets The camera contrast used on this material.
  4189. */
  4190. get: function () {
  4191. return this._imageProcessingConfiguration.contrast;
  4192. },
  4193. /**
  4194. * Sets The camera contrast used on this material.
  4195. */
  4196. set: function (value) {
  4197. this._imageProcessingConfiguration.contrast = value;
  4198. },
  4199. enumerable: true,
  4200. configurable: true
  4201. });
  4202. Object.defineProperty(StandardMaterial_OldVer.prototype, "cameraColorGradingTexture", {
  4203. /**
  4204. * Gets the Color Grading 2D Lookup Texture.
  4205. */
  4206. get: function () {
  4207. return this._imageProcessingConfiguration.colorGradingTexture;
  4208. },
  4209. /**
  4210. * Sets the Color Grading 2D Lookup Texture.
  4211. */
  4212. set: function (value) {
  4213. this._imageProcessingConfiguration.colorGradingTexture = value;
  4214. },
  4215. enumerable: true,
  4216. configurable: true
  4217. });
  4218. StandardMaterial_OldVer.prototype.getClassName = function () {
  4219. return "StandardMaterial_OldVer";
  4220. };
  4221. Object.defineProperty(StandardMaterial_OldVer.prototype, "useLogarithmicDepth", {
  4222. get: function () {
  4223. return this._useLogarithmicDepth;
  4224. },
  4225. set: function (value) {
  4226. this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;
  4227. this._markAllSubMeshesAsMiscDirty();
  4228. },
  4229. enumerable: true,
  4230. configurable: true
  4231. });
  4232. StandardMaterial_OldVer.prototype.needAlphaBlending = function () {
  4233. return (this.alpha < 1.0) || (this._opacityTexture != null) || this._shouldUseAlphaFromDiffuseTexture() || this._opacityFresnelParameters && this._opacityFresnelParameters.isEnabled;
  4234. };
  4235. StandardMaterial_OldVer.prototype.needAlphaTesting = function () {
  4236. return this._diffuseTexture != null && this._diffuseTexture.hasAlpha;
  4237. };
  4238. StandardMaterial_OldVer.prototype._shouldUseAlphaFromDiffuseTexture = function () {
  4239. return this._diffuseTexture != null && this._diffuseTexture.hasAlpha && this._useAlphaFromDiffuseTexture;
  4240. };
  4241. StandardMaterial_OldVer.prototype.getAlphaTestTexture = function () {
  4242. return this._diffuseTexture;
  4243. };
  4244. /**
  4245. * Child classes can use it to update shaders
  4246. */
  4247. StandardMaterial_OldVer.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  4248. if (this.isFrozen) {
  4249. if (this._wasPreviouslyReady && subMesh.effect) {
  4250. return true;
  4251. }
  4252. }
  4253. if (!subMesh._materialDefines) {
  4254. subMesh._materialDefines = new StandardMaterialDefines_OldVer();
  4255. }
  4256. var scene = this.getScene();
  4257. var defines = subMesh._materialDefines;
  4258. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  4259. if (defines._renderId === scene.getRenderId()) {
  4260. return true;
  4261. }
  4262. }
  4263. var engine = scene.getEngine();
  4264. // Lights
  4265. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);
  4266. // Textures
  4267. if (defines._areTexturesDirty) {
  4268. defines._needUVs = false;
  4269. if (scene.texturesEnabled) {
  4270. if (this._diffuseTexture && StandardMaterial_OldVer.DiffuseTextureEnabled) {
  4271. if (!this._diffuseTexture.isReadyOrNotBlocking()) {
  4272. return false;
  4273. }
  4274. else {
  4275. defines._needUVs = true;
  4276. defines.DIFFUSE = true;
  4277. }
  4278. }
  4279. else {
  4280. defines.DIFFUSE = false;
  4281. }
  4282. if (this._ambientTexture && StandardMaterial_OldVer.AmbientTextureEnabled) {
  4283. if (!this._ambientTexture.isReadyOrNotBlocking()) {
  4284. return false;
  4285. }
  4286. else {
  4287. defines._needUVs = true;
  4288. defines.AMBIENT = true;
  4289. }
  4290. }
  4291. else {
  4292. defines.AMBIENT = false;
  4293. }
  4294. if (this._opacityTexture && StandardMaterial_OldVer.OpacityTextureEnabled) {
  4295. if (!this._opacityTexture.isReadyOrNotBlocking()) {
  4296. return false;
  4297. }
  4298. else {
  4299. defines._needUVs = true;
  4300. defines.OPACITY = true;
  4301. defines.OPACITYRGB = this._opacityTexture.getAlphaFromRGB;
  4302. }
  4303. }
  4304. else {
  4305. defines.OPACITY = false;
  4306. }
  4307. if (this._reflectionTexture && StandardMaterial_OldVer.ReflectionTextureEnabled) {
  4308. if (!this._reflectionTexture.isReadyOrNotBlocking()) {
  4309. return false;
  4310. }
  4311. else {
  4312. defines._needNormals = true;
  4313. defines.REFLECTION = true;
  4314. defines.ROUGHNESS = (this._roughness > 0);
  4315. defines.REFLECTIONOVERALPHA = this._useReflectionOverAlpha;
  4316. defines.INVERTCUBICMAP = (this._reflectionTexture.coordinatesMode === BABYLON.Texture.INVCUBIC_MODE);
  4317. defines.REFLECTIONMAP_3D = this._reflectionTexture.isCube;
  4318. switch (this._reflectionTexture.coordinatesMode) {
  4319. case BABYLON.Texture.CUBIC_MODE:
  4320. case BABYLON.Texture.INVCUBIC_MODE:
  4321. defines.setReflectionMode("REFLECTIONMAP_CUBIC");
  4322. break;
  4323. case BABYLON.Texture.EXPLICIT_MODE:
  4324. defines.setReflectionMode("REFLECTIONMAP_EXPLICIT");
  4325. break;
  4326. case BABYLON.Texture.PLANAR_MODE:
  4327. defines.setReflectionMode("REFLECTIONMAP_PLANAR");
  4328. break;
  4329. case BABYLON.Texture.PROJECTION_MODE:
  4330. defines.setReflectionMode("REFLECTIONMAP_PROJECTION");
  4331. break;
  4332. case BABYLON.Texture.SKYBOX_MODE:
  4333. defines.setReflectionMode("REFLECTIONMAP_SKYBOX");
  4334. break;
  4335. case BABYLON.Texture.SPHERICAL_MODE:
  4336. defines.setReflectionMode("REFLECTIONMAP_SPHERICAL");
  4337. break;
  4338. case BABYLON.Texture.EQUIRECTANGULAR_MODE:
  4339. defines.setReflectionMode("REFLECTIONMAP_EQUIRECTANGULAR");
  4340. break;
  4341. case BABYLON.Texture.FIXED_EQUIRECTANGULAR_MODE:
  4342. defines.setReflectionMode("REFLECTIONMAP_EQUIRECTANGULAR_FIXED");
  4343. break;
  4344. case BABYLON.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:
  4345. defines.setReflectionMode("REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED");
  4346. break;
  4347. }
  4348. }
  4349. }
  4350. else {
  4351. defines.REFLECTION = false;
  4352. }
  4353. if (this._emissiveTexture && StandardMaterial_OldVer.EmissiveTextureEnabled) {
  4354. if (!this._emissiveTexture.isReadyOrNotBlocking()) {
  4355. return false;
  4356. }
  4357. else {
  4358. defines._needUVs = true;
  4359. defines.EMISSIVE = true;
  4360. }
  4361. }
  4362. else {
  4363. defines.EMISSIVE = false;
  4364. }
  4365. if (this._lightmapTexture && StandardMaterial_OldVer.LightmapTextureEnabled) {
  4366. if (!this._lightmapTexture.isReadyOrNotBlocking()) {
  4367. return false;
  4368. }
  4369. else {
  4370. defines._needUVs = true;
  4371. defines.LIGHTMAP = true;
  4372. defines.USELIGHTMAPASSHADOWMAP = this._useLightmapAsShadowmap;
  4373. }
  4374. }
  4375. else {
  4376. defines.LIGHTMAP = false;
  4377. }
  4378. if (this._specularTexture && StandardMaterial_OldVer.SpecularTextureEnabled) {
  4379. if (!this._specularTexture.isReadyOrNotBlocking()) {
  4380. return false;
  4381. }
  4382. else {
  4383. defines._needUVs = true;
  4384. defines.SPECULAR = true;
  4385. defines.GLOSSINESS = this._useGlossinessFromSpecularMapAlpha;
  4386. }
  4387. }
  4388. else {
  4389. defines.SPECULAR = false;
  4390. }
  4391. if (scene.getEngine().getCaps().standardDerivatives && this._bumpTexture && StandardMaterial_OldVer.BumpTextureEnabled) {
  4392. // Bump texure can not be not blocking.
  4393. if (!this._bumpTexture.isReady()) {
  4394. return false;
  4395. }
  4396. else {
  4397. defines._needUVs = true;
  4398. defines.BUMP = true;
  4399. defines.PARALLAX = this._useParallax;
  4400. defines.PARALLAXOCCLUSION = this._useParallaxOcclusion;
  4401. }
  4402. }
  4403. else {
  4404. defines.BUMP = false;
  4405. }
  4406. if (this._refractionTexture && StandardMaterial_OldVer.RefractionTextureEnabled) {
  4407. if (!this._refractionTexture.isReadyOrNotBlocking()) {
  4408. return false;
  4409. }
  4410. else {
  4411. defines._needUVs = true;
  4412. defines.REFRACTION = true;
  4413. defines.REFRACTIONMAP_3D = this._refractionTexture.isCube;
  4414. }
  4415. }
  4416. else {
  4417. defines.REFRACTION = false;
  4418. }
  4419. defines.TWOSIDEDLIGHTING = !this._backFaceCulling && this._twoSidedLighting;
  4420. }
  4421. else {
  4422. defines.DIFFUSE = false;
  4423. defines.AMBIENT = false;
  4424. defines.OPACITY = false;
  4425. defines.REFLECTION = false;
  4426. defines.EMISSIVE = false;
  4427. defines.LIGHTMAP = false;
  4428. defines.BUMP = false;
  4429. defines.REFRACTION = false;
  4430. }
  4431. defines.ALPHAFROMDIFFUSE = this._shouldUseAlphaFromDiffuseTexture();
  4432. defines.EMISSIVEASILLUMINATION = this._useEmissiveAsIllumination;
  4433. defines.LINKEMISSIVEWITHDIFFUSE = this._linkEmissiveWithDiffuse;
  4434. defines.SPECULAROVERALPHA = this._useSpecularOverAlpha;
  4435. }
  4436. if (defines._areImageProcessingDirty) {
  4437. if (!this._imageProcessingConfiguration.isReady()) {
  4438. return false;
  4439. }
  4440. this._imageProcessingConfiguration.prepareDefines(defines);
  4441. }
  4442. if (defines._areFresnelDirty) {
  4443. if (StandardMaterial_OldVer.FresnelEnabled) {
  4444. // Fresnel
  4445. if (this._diffuseFresnelParameters || this._opacityFresnelParameters ||
  4446. this._emissiveFresnelParameters || this._refractionFresnelParameters ||
  4447. this._reflectionFresnelParameters) {
  4448. defines.DIFFUSEFRESNEL = (this._diffuseFresnelParameters && this._diffuseFresnelParameters.isEnabled);
  4449. defines.OPACITYFRESNEL = (this._opacityFresnelParameters && this._opacityFresnelParameters.isEnabled);
  4450. defines.REFLECTIONFRESNEL = (this._reflectionFresnelParameters && this._reflectionFresnelParameters.isEnabled);
  4451. defines.REFLECTIONFRESNELFROMSPECULAR = this._useReflectionFresnelFromSpecular;
  4452. defines.REFRACTIONFRESNEL = (this._refractionFresnelParameters && this._refractionFresnelParameters.isEnabled);
  4453. defines.EMISSIVEFRESNEL = (this._emissiveFresnelParameters && this._emissiveFresnelParameters.isEnabled);
  4454. defines._needNormals = true;
  4455. defines.FRESNEL = true;
  4456. }
  4457. }
  4458. else {
  4459. defines.FRESNEL = false;
  4460. }
  4461. }
  4462. // Misc.
  4463. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
  4464. // Attribs
  4465. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
  4466. // Values that need to be evaluated on every frame
  4467. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  4468. // Get correct effect
  4469. if (defines.isDirty) {
  4470. defines.markAsProcessed();
  4471. scene.resetCachedMaterial();
  4472. // Fallbacks
  4473. var fallbacks = new BABYLON.EffectFallbacks();
  4474. if (defines.REFLECTION) {
  4475. fallbacks.addFallback(0, "REFLECTION");
  4476. }
  4477. if (defines.SPECULAR) {
  4478. fallbacks.addFallback(0, "SPECULAR");
  4479. }
  4480. if (defines.BUMP) {
  4481. fallbacks.addFallback(0, "BUMP");
  4482. }
  4483. if (defines.PARALLAX) {
  4484. fallbacks.addFallback(1, "PARALLAX");
  4485. }
  4486. if (defines.PARALLAXOCCLUSION) {
  4487. fallbacks.addFallback(0, "PARALLAXOCCLUSION");
  4488. }
  4489. if (defines.SPECULAROVERALPHA) {
  4490. fallbacks.addFallback(0, "SPECULAROVERALPHA");
  4491. }
  4492. if (defines.FOG) {
  4493. fallbacks.addFallback(1, "FOG");
  4494. }
  4495. if (defines.POINTSIZE) {
  4496. fallbacks.addFallback(0, "POINTSIZE");
  4497. }
  4498. if (defines.LOGARITHMICDEPTH) {
  4499. fallbacks.addFallback(0, "LOGARITHMICDEPTH");
  4500. }
  4501. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this._maxSimultaneousLights);
  4502. if (defines.SPECULARTERM) {
  4503. fallbacks.addFallback(0, "SPECULARTERM");
  4504. }
  4505. if (defines.DIFFUSEFRESNEL) {
  4506. fallbacks.addFallback(1, "DIFFUSEFRESNEL");
  4507. }
  4508. if (defines.OPACITYFRESNEL) {
  4509. fallbacks.addFallback(2, "OPACITYFRESNEL");
  4510. }
  4511. if (defines.REFLECTIONFRESNEL) {
  4512. fallbacks.addFallback(3, "REFLECTIONFRESNEL");
  4513. }
  4514. if (defines.EMISSIVEFRESNEL) {
  4515. fallbacks.addFallback(4, "EMISSIVEFRESNEL");
  4516. }
  4517. if (defines.FRESNEL) {
  4518. fallbacks.addFallback(4, "FRESNEL");
  4519. }
  4520. //Attributes
  4521. var attribs = [BABYLON.VertexBuffer.PositionKind];
  4522. if (defines.NORMAL) {
  4523. attribs.push(BABYLON.VertexBuffer.NormalKind);
  4524. }
  4525. if (defines.UV1) {
  4526. attribs.push(BABYLON.VertexBuffer.UVKind);
  4527. }
  4528. if (defines.UV2) {
  4529. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  4530. }
  4531. if (defines.VERTEXCOLOR) {
  4532. attribs.push(BABYLON.VertexBuffer.ColorKind);
  4533. }
  4534. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  4535. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  4536. BABYLON.MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, defines);
  4537. var shaderName = "default";
  4538. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vDiffuseColor", "vSpecularColor", "vEmissiveColor",
  4539. "vFogInfos", "vFogColor", "pointSize",
  4540. "vDiffuseInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vEmissiveInfos", "vSpecularInfos", "vBumpInfos", "vLightmapInfos", "vRefractionInfos",
  4541. "mBones",
  4542. "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
  4543. "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor", "refractionLeftColor", "refractionRightColor",
  4544. "logarithmicDepthConstant", "vTangentSpaceParams"
  4545. ];
  4546. var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"];
  4547. var uniformBuffers = ["Material", "Scene"];
  4548. BABYLON.ImageProcessingConfiguration.PrepareUniforms(uniforms, defines);
  4549. BABYLON.ImageProcessingConfiguration.PrepareSamplers(samplers, defines);
  4550. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  4551. uniformsNames: uniforms,
  4552. uniformBuffersNames: uniformBuffers,
  4553. samplers: samplers,
  4554. defines: defines,
  4555. maxSimultaneousLights: this._maxSimultaneousLights
  4556. });
  4557. if (this.customShaderNameResolve) {
  4558. shaderName = this.customShaderNameResolve(shaderName, uniforms, uniformBuffers, samplers, defines);
  4559. }
  4560. var join = defines.toString();
  4561. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  4562. attributes: attribs,
  4563. uniformsNames: uniforms,
  4564. uniformBuffersNames: uniformBuffers,
  4565. samplers: samplers,
  4566. defines: join,
  4567. fallbacks: fallbacks,
  4568. onCompiled: this.onCompiled,
  4569. onError: this.onError,
  4570. indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights, maxSimultaneousMorphTargets: defines.NUM_MORPH_INFLUENCERS }
  4571. }, engine), defines);
  4572. this.buildUniformLayout();
  4573. }
  4574. if (!subMesh.effect || !subMesh.effect.isReady()) {
  4575. return false;
  4576. }
  4577. defines._renderId = scene.getRenderId();
  4578. this._wasPreviouslyReady = true;
  4579. return true;
  4580. };
  4581. StandardMaterial_OldVer.prototype.buildUniformLayout = function () {
  4582. // Order is important !
  4583. this._uniformBuffer.addUniform("diffuseLeftColor", 4);
  4584. this._uniformBuffer.addUniform("diffuseRightColor", 4);
  4585. this._uniformBuffer.addUniform("opacityParts", 4);
  4586. this._uniformBuffer.addUniform("reflectionLeftColor", 4);
  4587. this._uniformBuffer.addUniform("reflectionRightColor", 4);
  4588. this._uniformBuffer.addUniform("refractionLeftColor", 4);
  4589. this._uniformBuffer.addUniform("refractionRightColor", 4);
  4590. this._uniformBuffer.addUniform("emissiveLeftColor", 4);
  4591. this._uniformBuffer.addUniform("emissiveRightColor", 4);
  4592. this._uniformBuffer.addUniform("vDiffuseInfos", 2);
  4593. this._uniformBuffer.addUniform("vAmbientInfos", 2);
  4594. this._uniformBuffer.addUniform("vOpacityInfos", 2);
  4595. this._uniformBuffer.addUniform("vReflectionInfos", 2);
  4596. this._uniformBuffer.addUniform("vEmissiveInfos", 2);
  4597. this._uniformBuffer.addUniform("vLightmapInfos", 2);
  4598. this._uniformBuffer.addUniform("vSpecularInfos", 2);
  4599. this._uniformBuffer.addUniform("vBumpInfos", 3);
  4600. this._uniformBuffer.addUniform("diffuseMatrix", 16);
  4601. this._uniformBuffer.addUniform("ambientMatrix", 16);
  4602. this._uniformBuffer.addUniform("opacityMatrix", 16);
  4603. this._uniformBuffer.addUniform("reflectionMatrix", 16);
  4604. this._uniformBuffer.addUniform("emissiveMatrix", 16);
  4605. this._uniformBuffer.addUniform("lightmapMatrix", 16);
  4606. this._uniformBuffer.addUniform("specularMatrix", 16);
  4607. this._uniformBuffer.addUniform("bumpMatrix", 16);
  4608. this._uniformBuffer.addUniform("vTangentSpaceParams", 2);
  4609. this._uniformBuffer.addUniform("refractionMatrix", 16);
  4610. this._uniformBuffer.addUniform("vRefractionInfos", 4);
  4611. this._uniformBuffer.addUniform("vSpecularColor", 4);
  4612. this._uniformBuffer.addUniform("vEmissiveColor", 3);
  4613. this._uniformBuffer.addUniform("vDiffuseColor", 4);
  4614. this._uniformBuffer.addUniform("pointSize", 1);
  4615. this._uniformBuffer.create();
  4616. };
  4617. StandardMaterial_OldVer.prototype.unbind = function () {
  4618. if (this._activeEffect) {
  4619. if (this._reflectionTexture && this._reflectionTexture.isRenderTarget) {
  4620. this._activeEffect.setTexture("reflection2DSampler", null);
  4621. }
  4622. if (this._refractionTexture && this._refractionTexture.isRenderTarget) {
  4623. this._activeEffect.setTexture("refraction2DSampler", null);
  4624. }
  4625. }
  4626. _super.prototype.unbind.call(this);
  4627. };
  4628. StandardMaterial_OldVer.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  4629. var scene = this.getScene();
  4630. var defines = subMesh._materialDefines;
  4631. if (!defines) {
  4632. return;
  4633. }
  4634. var effect = subMesh.effect;
  4635. if (!effect) {
  4636. return;
  4637. }
  4638. this._activeEffect = effect;
  4639. // Matrices
  4640. this.bindOnlyWorldMatrix(world);
  4641. // Bones
  4642. BABYLON.MaterialHelper.BindBonesParameters(mesh, effect);
  4643. if (this._mustRebind(scene, effect, mesh.visibility)) {
  4644. this._uniformBuffer.bindToEffect(effect, "Material");
  4645. this.bindViewProjection(effect);
  4646. if (!this._uniformBuffer.useUbo || !this.isFrozen || !this._uniformBuffer.isSync) {
  4647. if (StandardMaterial_OldVer.FresnelEnabled && defines.FRESNEL) {
  4648. // Fresnel
  4649. if (this.diffuseFresnelParameters && this.diffuseFresnelParameters.isEnabled) {
  4650. this._uniformBuffer.updateColor4("diffuseLeftColor", this.diffuseFresnelParameters.leftColor, this.diffuseFresnelParameters.power);
  4651. this._uniformBuffer.updateColor4("diffuseRightColor", this.diffuseFresnelParameters.rightColor, this.diffuseFresnelParameters.bias);
  4652. }
  4653. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {
  4654. this._uniformBuffer.updateColor4("opacityParts", new BABYLON.Color3(this.opacityFresnelParameters.leftColor.toLuminance(), this.opacityFresnelParameters.rightColor.toLuminance(), this.opacityFresnelParameters.bias), this.opacityFresnelParameters.power);
  4655. }
  4656. if (this.reflectionFresnelParameters && this.reflectionFresnelParameters.isEnabled) {
  4657. this._uniformBuffer.updateColor4("reflectionLeftColor", this.reflectionFresnelParameters.leftColor, this.reflectionFresnelParameters.power);
  4658. this._uniformBuffer.updateColor4("reflectionRightColor", this.reflectionFresnelParameters.rightColor, this.reflectionFresnelParameters.bias);
  4659. }
  4660. if (this.refractionFresnelParameters && this.refractionFresnelParameters.isEnabled) {
  4661. this._uniformBuffer.updateColor4("refractionLeftColor", this.refractionFresnelParameters.leftColor, this.refractionFresnelParameters.power);
  4662. this._uniformBuffer.updateColor4("refractionRightColor", this.refractionFresnelParameters.rightColor, this.refractionFresnelParameters.bias);
  4663. }
  4664. if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  4665. this._uniformBuffer.updateColor4("emissiveLeftColor", this.emissiveFresnelParameters.leftColor, this.emissiveFresnelParameters.power);
  4666. this._uniformBuffer.updateColor4("emissiveRightColor", this.emissiveFresnelParameters.rightColor, this.emissiveFresnelParameters.bias);
  4667. }
  4668. }
  4669. // Textures
  4670. if (scene.texturesEnabled) {
  4671. if (this._diffuseTexture && StandardMaterial_OldVer.DiffuseTextureEnabled) {
  4672. this._uniformBuffer.updateFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  4673. this._uniformBuffer.updateMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  4674. }
  4675. if (this._ambientTexture && StandardMaterial_OldVer.AmbientTextureEnabled) {
  4676. this._uniformBuffer.updateFloat2("vAmbientInfos", this._ambientTexture.coordinatesIndex, this._ambientTexture.level);
  4677. this._uniformBuffer.updateMatrix("ambientMatrix", this._ambientTexture.getTextureMatrix());
  4678. }
  4679. if (this._opacityTexture && StandardMaterial_OldVer.OpacityTextureEnabled) {
  4680. this._uniformBuffer.updateFloat2("vOpacityInfos", this._opacityTexture.coordinatesIndex, this._opacityTexture.level);
  4681. this._uniformBuffer.updateMatrix("opacityMatrix", this._opacityTexture.getTextureMatrix());
  4682. }
  4683. if (this._reflectionTexture && StandardMaterial_OldVer.ReflectionTextureEnabled) {
  4684. this._uniformBuffer.updateFloat2("vReflectionInfos", this._reflectionTexture.level, this.roughness);
  4685. this._uniformBuffer.updateMatrix("reflectionMatrix", this._reflectionTexture.getReflectionTextureMatrix());
  4686. }
  4687. if (this._emissiveTexture && StandardMaterial_OldVer.EmissiveTextureEnabled) {
  4688. this._uniformBuffer.updateFloat2("vEmissiveInfos", this._emissiveTexture.coordinatesIndex, this._emissiveTexture.level);
  4689. this._uniformBuffer.updateMatrix("emissiveMatrix", this._emissiveTexture.getTextureMatrix());
  4690. }
  4691. if (this._lightmapTexture && StandardMaterial_OldVer.LightmapTextureEnabled) {
  4692. this._uniformBuffer.updateFloat2("vLightmapInfos", this._lightmapTexture.coordinatesIndex, this._lightmapTexture.level);
  4693. this._uniformBuffer.updateMatrix("lightmapMatrix", this._lightmapTexture.getTextureMatrix());
  4694. }
  4695. if (this._specularTexture && StandardMaterial_OldVer.SpecularTextureEnabled) {
  4696. this._uniformBuffer.updateFloat2("vSpecularInfos", this._specularTexture.coordinatesIndex, this._specularTexture.level);
  4697. this._uniformBuffer.updateMatrix("specularMatrix", this._specularTexture.getTextureMatrix());
  4698. }
  4699. if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial_OldVer.BumpTextureEnabled) {
  4700. this._uniformBuffer.updateFloat3("vBumpInfos", this._bumpTexture.coordinatesIndex, 1.0 / this._bumpTexture.level, this.parallaxScaleBias);
  4701. this._uniformBuffer.updateMatrix("bumpMatrix", this._bumpTexture.getTextureMatrix());
  4702. if (scene._mirroredCameraPosition) {
  4703. this._uniformBuffer.updateFloat2("vTangentSpaceParams", this._invertNormalMapX ? 1.0 : -1.0, this._invertNormalMapY ? 1.0 : -1.0);
  4704. }
  4705. else {
  4706. this._uniformBuffer.updateFloat2("vTangentSpaceParams", this._invertNormalMapX ? -1.0 : 1.0, this._invertNormalMapY ? -1.0 : 1.0);
  4707. }
  4708. }
  4709. if (this._refractionTexture && StandardMaterial_OldVer.RefractionTextureEnabled) {
  4710. var depth = 1.0;
  4711. if (!this._refractionTexture.isCube) {
  4712. this._uniformBuffer.updateMatrix("refractionMatrix", this._refractionTexture.getReflectionTextureMatrix());
  4713. if (this._refractionTexture.depth) {
  4714. depth = this._refractionTexture.depth;
  4715. }
  4716. }
  4717. this._uniformBuffer.updateFloat4("vRefractionInfos", this._refractionTexture.level, this.indexOfRefraction, depth, this.invertRefractionY ? -1 : 1);
  4718. }
  4719. }
  4720. // Point size
  4721. if (this.pointsCloud) {
  4722. this._uniformBuffer.updateFloat("pointSize", this.pointSize);
  4723. }
  4724. if (defines.SPECULARTERM) {
  4725. this._uniformBuffer.updateColor4("vSpecularColor", this.specularColor, this.specularPower);
  4726. }
  4727. this._uniformBuffer.updateColor3("vEmissiveColor", this.emissiveColor);
  4728. // Diffuse
  4729. this._uniformBuffer.updateColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  4730. }
  4731. // Textures
  4732. if (scene.texturesEnabled) {
  4733. if (this._diffuseTexture && StandardMaterial_OldVer.DiffuseTextureEnabled) {
  4734. effect.setTexture("diffuseSampler", this._diffuseTexture);
  4735. }
  4736. if (this._ambientTexture && StandardMaterial_OldVer.AmbientTextureEnabled) {
  4737. effect.setTexture("ambientSampler", this._ambientTexture);
  4738. }
  4739. if (this._opacityTexture && StandardMaterial_OldVer.OpacityTextureEnabled) {
  4740. effect.setTexture("opacitySampler", this._opacityTexture);
  4741. }
  4742. if (this._reflectionTexture && StandardMaterial_OldVer.ReflectionTextureEnabled) {
  4743. if (this._reflectionTexture.isCube) {
  4744. effect.setTexture("reflectionCubeSampler", this._reflectionTexture);
  4745. }
  4746. else {
  4747. effect.setTexture("reflection2DSampler", this._reflectionTexture);
  4748. }
  4749. }
  4750. if (this._emissiveTexture && StandardMaterial_OldVer.EmissiveTextureEnabled) {
  4751. effect.setTexture("emissiveSampler", this._emissiveTexture);
  4752. }
  4753. if (this._lightmapTexture && StandardMaterial_OldVer.LightmapTextureEnabled) {
  4754. effect.setTexture("lightmapSampler", this._lightmapTexture);
  4755. }
  4756. if (this._specularTexture && StandardMaterial_OldVer.SpecularTextureEnabled) {
  4757. effect.setTexture("specularSampler", this._specularTexture);
  4758. }
  4759. if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial_OldVer.BumpTextureEnabled) {
  4760. effect.setTexture("bumpSampler", this._bumpTexture);
  4761. }
  4762. if (this._refractionTexture && StandardMaterial_OldVer.RefractionTextureEnabled) {
  4763. var depth = 1.0;
  4764. if (this._refractionTexture.isCube) {
  4765. effect.setTexture("refractionCubeSampler", this._refractionTexture);
  4766. }
  4767. else {
  4768. effect.setTexture("refraction2DSampler", this._refractionTexture);
  4769. }
  4770. }
  4771. }
  4772. // Clip plane
  4773. BABYLON.MaterialHelper.BindClipPlane(effect, scene);
  4774. // Colors
  4775. scene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
  4776. effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  4777. effect.setColor3("vAmbientColor", this._globalAmbientColor);
  4778. }
  4779. if (this._mustRebind(scene, effect) || !this.isFrozen) {
  4780. // Lights
  4781. if (scene.lightsEnabled && !this._disableLighting) {
  4782. BABYLON.MaterialHelper.BindLights(scene, mesh, effect, defines, this._maxSimultaneousLights);
  4783. }
  4784. // View
  4785. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE || this._reflectionTexture || this._refractionTexture) {
  4786. this.bindView(effect);
  4787. }
  4788. // Fog
  4789. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, effect);
  4790. // Morph targets
  4791. if (defines.NUM_MORPH_INFLUENCERS) {
  4792. BABYLON.MaterialHelper.BindMorphTargetParameters(mesh, effect);
  4793. }
  4794. // Log. depth
  4795. BABYLON.MaterialHelper.BindLogDepth(defines, effect, scene);
  4796. // image processing
  4797. this._imageProcessingConfiguration.bind(this._activeEffect);
  4798. }
  4799. this._uniformBuffer.update();
  4800. this._afterBind(mesh, this._activeEffect);
  4801. };
  4802. StandardMaterial_OldVer.prototype.getAnimatables = function () {
  4803. var results = [];
  4804. if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
  4805. results.push(this._diffuseTexture);
  4806. }
  4807. if (this._ambientTexture && this._ambientTexture.animations && this._ambientTexture.animations.length > 0) {
  4808. results.push(this._ambientTexture);
  4809. }
  4810. if (this._opacityTexture && this._opacityTexture.animations && this._opacityTexture.animations.length > 0) {
  4811. results.push(this._opacityTexture);
  4812. }
  4813. if (this._reflectionTexture && this._reflectionTexture.animations && this._reflectionTexture.animations.length > 0) {
  4814. results.push(this._reflectionTexture);
  4815. }
  4816. if (this._emissiveTexture && this._emissiveTexture.animations && this._emissiveTexture.animations.length > 0) {
  4817. results.push(this._emissiveTexture);
  4818. }
  4819. if (this._specularTexture && this._specularTexture.animations && this._specularTexture.animations.length > 0) {
  4820. results.push(this._specularTexture);
  4821. }
  4822. if (this._bumpTexture && this._bumpTexture.animations && this._bumpTexture.animations.length > 0) {
  4823. results.push(this._bumpTexture);
  4824. }
  4825. if (this._lightmapTexture && this._lightmapTexture.animations && this._lightmapTexture.animations.length > 0) {
  4826. results.push(this._lightmapTexture);
  4827. }
  4828. if (this._refractionTexture && this._refractionTexture.animations && this._refractionTexture.animations.length > 0) {
  4829. results.push(this._refractionTexture);
  4830. }
  4831. return results;
  4832. };
  4833. StandardMaterial_OldVer.prototype.getActiveTextures = function () {
  4834. var activeTextures = _super.prototype.getActiveTextures.call(this);
  4835. if (this._diffuseTexture) {
  4836. activeTextures.push(this._diffuseTexture);
  4837. }
  4838. if (this._ambientTexture) {
  4839. activeTextures.push(this._ambientTexture);
  4840. }
  4841. if (this._opacityTexture) {
  4842. activeTextures.push(this._opacityTexture);
  4843. }
  4844. if (this._reflectionTexture) {
  4845. activeTextures.push(this._reflectionTexture);
  4846. }
  4847. if (this._emissiveTexture) {
  4848. activeTextures.push(this._emissiveTexture);
  4849. }
  4850. if (this._specularTexture) {
  4851. activeTextures.push(this._specularTexture);
  4852. }
  4853. if (this._bumpTexture) {
  4854. activeTextures.push(this._bumpTexture);
  4855. }
  4856. if (this._lightmapTexture) {
  4857. activeTextures.push(this._lightmapTexture);
  4858. }
  4859. if (this._refractionTexture) {
  4860. activeTextures.push(this._refractionTexture);
  4861. }
  4862. return activeTextures;
  4863. };
  4864. StandardMaterial_OldVer.prototype.dispose = function (forceDisposeEffect, forceDisposeTextures) {
  4865. if (forceDisposeTextures) {
  4866. if (this._diffuseTexture) {
  4867. this._diffuseTexture.dispose();
  4868. }
  4869. if (this._ambientTexture) {
  4870. this._ambientTexture.dispose();
  4871. }
  4872. if (this._opacityTexture) {
  4873. this._opacityTexture.dispose();
  4874. }
  4875. if (this._reflectionTexture) {
  4876. this._reflectionTexture.dispose();
  4877. }
  4878. if (this._emissiveTexture) {
  4879. this._emissiveTexture.dispose();
  4880. }
  4881. if (this._specularTexture) {
  4882. this._specularTexture.dispose();
  4883. }
  4884. if (this._bumpTexture) {
  4885. this._bumpTexture.dispose();
  4886. }
  4887. if (this._lightmapTexture) {
  4888. this._lightmapTexture.dispose();
  4889. }
  4890. if (this._refractionTexture) {
  4891. this._refractionTexture.dispose();
  4892. }
  4893. }
  4894. if (this._imageProcessingConfiguration && this._imageProcessingObserver) {
  4895. this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);
  4896. }
  4897. _super.prototype.dispose.call(this, forceDisposeEffect, forceDisposeTextures);
  4898. };
  4899. StandardMaterial_OldVer.prototype.clone = function (name) {
  4900. var _this = this;
  4901. var result = BABYLON.SerializationHelper.Clone(function () { return new StandardMaterial_OldVer(name, _this.getScene()); }, this);
  4902. result.name = name;
  4903. result.id = name;
  4904. return result;
  4905. };
  4906. StandardMaterial_OldVer.prototype.serialize = function () {
  4907. return BABYLON.SerializationHelper.Serialize(this);
  4908. };
  4909. // Statics
  4910. StandardMaterial_OldVer.Parse = function (source, scene, rootUrl) {
  4911. return BABYLON.SerializationHelper.Parse(function () { return new StandardMaterial_OldVer(source.name, scene); }, source, scene, rootUrl);
  4912. };
  4913. Object.defineProperty(StandardMaterial_OldVer, "DiffuseTextureEnabled", {
  4914. get: function () {
  4915. return StandardMaterial_OldVer._DiffuseTextureEnabled;
  4916. },
  4917. set: function (value) {
  4918. if (StandardMaterial_OldVer._DiffuseTextureEnabled === value) {
  4919. return;
  4920. }
  4921. StandardMaterial_OldVer._DiffuseTextureEnabled = value;
  4922. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  4923. },
  4924. enumerable: true,
  4925. configurable: true
  4926. });
  4927. Object.defineProperty(StandardMaterial_OldVer, "AmbientTextureEnabled", {
  4928. get: function () {
  4929. return StandardMaterial_OldVer._AmbientTextureEnabled;
  4930. },
  4931. set: function (value) {
  4932. if (StandardMaterial_OldVer._AmbientTextureEnabled === value) {
  4933. return;
  4934. }
  4935. StandardMaterial_OldVer._AmbientTextureEnabled = value;
  4936. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  4937. },
  4938. enumerable: true,
  4939. configurable: true
  4940. });
  4941. Object.defineProperty(StandardMaterial_OldVer, "OpacityTextureEnabled", {
  4942. get: function () {
  4943. return StandardMaterial_OldVer._OpacityTextureEnabled;
  4944. },
  4945. set: function (value) {
  4946. if (StandardMaterial_OldVer._OpacityTextureEnabled === value) {
  4947. return;
  4948. }
  4949. StandardMaterial_OldVer._OpacityTextureEnabled = value;
  4950. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  4951. },
  4952. enumerable: true,
  4953. configurable: true
  4954. });
  4955. Object.defineProperty(StandardMaterial_OldVer, "ReflectionTextureEnabled", {
  4956. get: function () {
  4957. return StandardMaterial_OldVer._ReflectionTextureEnabled;
  4958. },
  4959. set: function (value) {
  4960. if (StandardMaterial_OldVer._ReflectionTextureEnabled === value) {
  4961. return;
  4962. }
  4963. StandardMaterial_OldVer._ReflectionTextureEnabled = value;
  4964. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  4965. },
  4966. enumerable: true,
  4967. configurable: true
  4968. });
  4969. Object.defineProperty(StandardMaterial_OldVer, "EmissiveTextureEnabled", {
  4970. get: function () {
  4971. return StandardMaterial_OldVer._EmissiveTextureEnabled;
  4972. },
  4973. set: function (value) {
  4974. if (StandardMaterial_OldVer._EmissiveTextureEnabled === value) {
  4975. return;
  4976. }
  4977. StandardMaterial_OldVer._EmissiveTextureEnabled = value;
  4978. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  4979. },
  4980. enumerable: true,
  4981. configurable: true
  4982. });
  4983. Object.defineProperty(StandardMaterial_OldVer, "SpecularTextureEnabled", {
  4984. get: function () {
  4985. return StandardMaterial_OldVer._SpecularTextureEnabled;
  4986. },
  4987. set: function (value) {
  4988. if (StandardMaterial_OldVer._SpecularTextureEnabled === value) {
  4989. return;
  4990. }
  4991. StandardMaterial_OldVer._SpecularTextureEnabled = value;
  4992. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  4993. },
  4994. enumerable: true,
  4995. configurable: true
  4996. });
  4997. Object.defineProperty(StandardMaterial_OldVer, "BumpTextureEnabled", {
  4998. get: function () {
  4999. return StandardMaterial_OldVer._BumpTextureEnabled;
  5000. },
  5001. set: function (value) {
  5002. if (StandardMaterial_OldVer._BumpTextureEnabled === value) {
  5003. return;
  5004. }
  5005. StandardMaterial_OldVer._BumpTextureEnabled = value;
  5006. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  5007. },
  5008. enumerable: true,
  5009. configurable: true
  5010. });
  5011. Object.defineProperty(StandardMaterial_OldVer, "LightmapTextureEnabled", {
  5012. get: function () {
  5013. return StandardMaterial_OldVer._LightmapTextureEnabled;
  5014. },
  5015. set: function (value) {
  5016. if (StandardMaterial_OldVer._LightmapTextureEnabled === value) {
  5017. return;
  5018. }
  5019. StandardMaterial_OldVer._LightmapTextureEnabled = value;
  5020. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  5021. },
  5022. enumerable: true,
  5023. configurable: true
  5024. });
  5025. Object.defineProperty(StandardMaterial_OldVer, "RefractionTextureEnabled", {
  5026. get: function () {
  5027. return StandardMaterial_OldVer._RefractionTextureEnabled;
  5028. },
  5029. set: function (value) {
  5030. if (StandardMaterial_OldVer._RefractionTextureEnabled === value) {
  5031. return;
  5032. }
  5033. StandardMaterial_OldVer._RefractionTextureEnabled = value;
  5034. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  5035. },
  5036. enumerable: true,
  5037. configurable: true
  5038. });
  5039. Object.defineProperty(StandardMaterial_OldVer, "ColorGradingTextureEnabled", {
  5040. get: function () {
  5041. return StandardMaterial_OldVer._ColorGradingTextureEnabled;
  5042. },
  5043. set: function (value) {
  5044. if (StandardMaterial_OldVer._ColorGradingTextureEnabled === value) {
  5045. return;
  5046. }
  5047. StandardMaterial_OldVer._ColorGradingTextureEnabled = value;
  5048. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  5049. },
  5050. enumerable: true,
  5051. configurable: true
  5052. });
  5053. Object.defineProperty(StandardMaterial_OldVer, "FresnelEnabled", {
  5054. get: function () {
  5055. return StandardMaterial_OldVer._FresnelEnabled;
  5056. },
  5057. set: function (value) {
  5058. if (StandardMaterial_OldVer._FresnelEnabled === value) {
  5059. return;
  5060. }
  5061. StandardMaterial_OldVer._FresnelEnabled = value;
  5062. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.FresnelDirtyFlag);
  5063. },
  5064. enumerable: true,
  5065. configurable: true
  5066. });
  5067. // Flags used to enable or disable a type of texture for all Standard Materials
  5068. StandardMaterial_OldVer._DiffuseTextureEnabled = true;
  5069. StandardMaterial_OldVer._AmbientTextureEnabled = true;
  5070. StandardMaterial_OldVer._OpacityTextureEnabled = true;
  5071. StandardMaterial_OldVer._ReflectionTextureEnabled = true;
  5072. StandardMaterial_OldVer._EmissiveTextureEnabled = true;
  5073. StandardMaterial_OldVer._SpecularTextureEnabled = true;
  5074. StandardMaterial_OldVer._BumpTextureEnabled = true;
  5075. StandardMaterial_OldVer._LightmapTextureEnabled = true;
  5076. StandardMaterial_OldVer._RefractionTextureEnabled = true;
  5077. StandardMaterial_OldVer._ColorGradingTextureEnabled = true;
  5078. StandardMaterial_OldVer._FresnelEnabled = true;
  5079. __decorate([
  5080. BABYLON.serializeAsTexture("diffuseTexture")
  5081. ], StandardMaterial_OldVer.prototype, "_diffuseTexture", void 0);
  5082. __decorate([
  5083. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5084. ], StandardMaterial_OldVer.prototype, "diffuseTexture", void 0);
  5085. __decorate([
  5086. BABYLON.serializeAsTexture("ambientTexture")
  5087. ], StandardMaterial_OldVer.prototype, "_ambientTexture", void 0);
  5088. __decorate([
  5089. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5090. ], StandardMaterial_OldVer.prototype, "ambientTexture", void 0);
  5091. __decorate([
  5092. BABYLON.serializeAsTexture("opacityTexture")
  5093. ], StandardMaterial_OldVer.prototype, "_opacityTexture", void 0);
  5094. __decorate([
  5095. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5096. ], StandardMaterial_OldVer.prototype, "opacityTexture", void 0);
  5097. __decorate([
  5098. BABYLON.serializeAsTexture("reflectionTexture")
  5099. ], StandardMaterial_OldVer.prototype, "_reflectionTexture", void 0);
  5100. __decorate([
  5101. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5102. ], StandardMaterial_OldVer.prototype, "reflectionTexture", void 0);
  5103. __decorate([
  5104. BABYLON.serializeAsTexture("emissiveTexture")
  5105. ], StandardMaterial_OldVer.prototype, "_emissiveTexture", void 0);
  5106. __decorate([
  5107. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5108. ], StandardMaterial_OldVer.prototype, "emissiveTexture", void 0);
  5109. __decorate([
  5110. BABYLON.serializeAsTexture("specularTexture")
  5111. ], StandardMaterial_OldVer.prototype, "_specularTexture", void 0);
  5112. __decorate([
  5113. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5114. ], StandardMaterial_OldVer.prototype, "specularTexture", void 0);
  5115. __decorate([
  5116. BABYLON.serializeAsTexture("bumpTexture")
  5117. ], StandardMaterial_OldVer.prototype, "_bumpTexture", void 0);
  5118. __decorate([
  5119. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5120. ], StandardMaterial_OldVer.prototype, "bumpTexture", void 0);
  5121. __decorate([
  5122. BABYLON.serializeAsTexture("lightmapTexture")
  5123. ], StandardMaterial_OldVer.prototype, "_lightmapTexture", void 0);
  5124. __decorate([
  5125. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5126. ], StandardMaterial_OldVer.prototype, "lightmapTexture", void 0);
  5127. __decorate([
  5128. BABYLON.serializeAsTexture("refractionTexture")
  5129. ], StandardMaterial_OldVer.prototype, "_refractionTexture", void 0);
  5130. __decorate([
  5131. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5132. ], StandardMaterial_OldVer.prototype, "refractionTexture", void 0);
  5133. __decorate([
  5134. BABYLON.serializeAsColor3("ambient")
  5135. ], StandardMaterial_OldVer.prototype, "ambientColor", void 0);
  5136. __decorate([
  5137. BABYLON.serializeAsColor3("diffuse")
  5138. ], StandardMaterial_OldVer.prototype, "diffuseColor", void 0);
  5139. __decorate([
  5140. BABYLON.serializeAsColor3("specular")
  5141. ], StandardMaterial_OldVer.prototype, "specularColor", void 0);
  5142. __decorate([
  5143. BABYLON.serializeAsColor3("emissive")
  5144. ], StandardMaterial_OldVer.prototype, "emissiveColor", void 0);
  5145. __decorate([
  5146. BABYLON.serialize()
  5147. ], StandardMaterial_OldVer.prototype, "specularPower", void 0);
  5148. __decorate([
  5149. BABYLON.serialize("useAlphaFromDiffuseTexture")
  5150. ], StandardMaterial_OldVer.prototype, "_useAlphaFromDiffuseTexture", void 0);
  5151. __decorate([
  5152. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5153. ], StandardMaterial_OldVer.prototype, "useAlphaFromDiffuseTexture", void 0);
  5154. __decorate([
  5155. BABYLON.serialize("useEmissiveAsIllumination")
  5156. ], StandardMaterial_OldVer.prototype, "_useEmissiveAsIllumination", void 0);
  5157. __decorate([
  5158. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5159. ], StandardMaterial_OldVer.prototype, "useEmissiveAsIllumination", void 0);
  5160. __decorate([
  5161. BABYLON.serialize("linkEmissiveWithDiffuse")
  5162. ], StandardMaterial_OldVer.prototype, "_linkEmissiveWithDiffuse", void 0);
  5163. __decorate([
  5164. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5165. ], StandardMaterial_OldVer.prototype, "linkEmissiveWithDiffuse", void 0);
  5166. __decorate([
  5167. BABYLON.serialize("useSpecularOverAlpha")
  5168. ], StandardMaterial_OldVer.prototype, "_useSpecularOverAlpha", void 0);
  5169. __decorate([
  5170. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5171. ], StandardMaterial_OldVer.prototype, "useSpecularOverAlpha", void 0);
  5172. __decorate([
  5173. BABYLON.serialize("useReflectionOverAlpha")
  5174. ], StandardMaterial_OldVer.prototype, "_useReflectionOverAlpha", void 0);
  5175. __decorate([
  5176. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5177. ], StandardMaterial_OldVer.prototype, "useReflectionOverAlpha", void 0);
  5178. __decorate([
  5179. BABYLON.serialize("disableLighting")
  5180. ], StandardMaterial_OldVer.prototype, "_disableLighting", void 0);
  5181. __decorate([
  5182. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  5183. ], StandardMaterial_OldVer.prototype, "disableLighting", void 0);
  5184. __decorate([
  5185. BABYLON.serialize("useParallax")
  5186. ], StandardMaterial_OldVer.prototype, "_useParallax", void 0);
  5187. __decorate([
  5188. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5189. ], StandardMaterial_OldVer.prototype, "useParallax", void 0);
  5190. __decorate([
  5191. BABYLON.serialize("useParallaxOcclusion")
  5192. ], StandardMaterial_OldVer.prototype, "_useParallaxOcclusion", void 0);
  5193. __decorate([
  5194. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5195. ], StandardMaterial_OldVer.prototype, "useParallaxOcclusion", void 0);
  5196. __decorate([
  5197. BABYLON.serialize()
  5198. ], StandardMaterial_OldVer.prototype, "parallaxScaleBias", void 0);
  5199. __decorate([
  5200. BABYLON.serialize("roughness")
  5201. ], StandardMaterial_OldVer.prototype, "_roughness", void 0);
  5202. __decorate([
  5203. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5204. ], StandardMaterial_OldVer.prototype, "roughness", void 0);
  5205. __decorate([
  5206. BABYLON.serialize()
  5207. ], StandardMaterial_OldVer.prototype, "indexOfRefraction", void 0);
  5208. __decorate([
  5209. BABYLON.serialize()
  5210. ], StandardMaterial_OldVer.prototype, "invertRefractionY", void 0);
  5211. __decorate([
  5212. BABYLON.serialize("useLightmapAsShadowmap")
  5213. ], StandardMaterial_OldVer.prototype, "_useLightmapAsShadowmap", void 0);
  5214. __decorate([
  5215. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5216. ], StandardMaterial_OldVer.prototype, "useLightmapAsShadowmap", void 0);
  5217. __decorate([
  5218. BABYLON.serializeAsFresnelParameters("diffuseFresnelParameters")
  5219. ], StandardMaterial_OldVer.prototype, "_diffuseFresnelParameters", void 0);
  5220. __decorate([
  5221. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  5222. ], StandardMaterial_OldVer.prototype, "diffuseFresnelParameters", void 0);
  5223. __decorate([
  5224. BABYLON.serializeAsFresnelParameters("opacityFresnelParameters")
  5225. ], StandardMaterial_OldVer.prototype, "_opacityFresnelParameters", void 0);
  5226. __decorate([
  5227. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  5228. ], StandardMaterial_OldVer.prototype, "opacityFresnelParameters", void 0);
  5229. __decorate([
  5230. BABYLON.serializeAsFresnelParameters("reflectionFresnelParameters")
  5231. ], StandardMaterial_OldVer.prototype, "_reflectionFresnelParameters", void 0);
  5232. __decorate([
  5233. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  5234. ], StandardMaterial_OldVer.prototype, "reflectionFresnelParameters", void 0);
  5235. __decorate([
  5236. BABYLON.serializeAsFresnelParameters("refractionFresnelParameters")
  5237. ], StandardMaterial_OldVer.prototype, "_refractionFresnelParameters", void 0);
  5238. __decorate([
  5239. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  5240. ], StandardMaterial_OldVer.prototype, "refractionFresnelParameters", void 0);
  5241. __decorate([
  5242. BABYLON.serializeAsFresnelParameters("emissiveFresnelParameters")
  5243. ], StandardMaterial_OldVer.prototype, "_emissiveFresnelParameters", void 0);
  5244. __decorate([
  5245. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  5246. ], StandardMaterial_OldVer.prototype, "emissiveFresnelParameters", void 0);
  5247. __decorate([
  5248. BABYLON.serialize("useReflectionFresnelFromSpecular")
  5249. ], StandardMaterial_OldVer.prototype, "_useReflectionFresnelFromSpecular", void 0);
  5250. __decorate([
  5251. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  5252. ], StandardMaterial_OldVer.prototype, "useReflectionFresnelFromSpecular", void 0);
  5253. __decorate([
  5254. BABYLON.serialize("useGlossinessFromSpecularMapAlpha")
  5255. ], StandardMaterial_OldVer.prototype, "_useGlossinessFromSpecularMapAlpha", void 0);
  5256. __decorate([
  5257. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5258. ], StandardMaterial_OldVer.prototype, "useGlossinessFromSpecularMapAlpha", void 0);
  5259. __decorate([
  5260. BABYLON.serialize("maxSimultaneousLights")
  5261. ], StandardMaterial_OldVer.prototype, "_maxSimultaneousLights", void 0);
  5262. __decorate([
  5263. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  5264. ], StandardMaterial_OldVer.prototype, "maxSimultaneousLights", void 0);
  5265. __decorate([
  5266. BABYLON.serialize("invertNormalMapX")
  5267. ], StandardMaterial_OldVer.prototype, "_invertNormalMapX", void 0);
  5268. __decorate([
  5269. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5270. ], StandardMaterial_OldVer.prototype, "invertNormalMapX", void 0);
  5271. __decorate([
  5272. BABYLON.serialize("invertNormalMapY")
  5273. ], StandardMaterial_OldVer.prototype, "_invertNormalMapY", void 0);
  5274. __decorate([
  5275. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5276. ], StandardMaterial_OldVer.prototype, "invertNormalMapY", void 0);
  5277. __decorate([
  5278. BABYLON.serialize("twoSidedLighting")
  5279. ], StandardMaterial_OldVer.prototype, "_twoSidedLighting", void 0);
  5280. __decorate([
  5281. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5282. ], StandardMaterial_OldVer.prototype, "twoSidedLighting", void 0);
  5283. __decorate([
  5284. BABYLON.serialize()
  5285. ], StandardMaterial_OldVer.prototype, "useLogarithmicDepth", null);
  5286. return StandardMaterial_OldVer;
  5287. }(BABYLON.PushMaterial));
  5288. BABYLON.StandardMaterial_OldVer = StandardMaterial_OldVer;
  5289. var CustomShaderStructure = /** @class */ (function () {
  5290. function CustomShaderStructure() {
  5291. }
  5292. return CustomShaderStructure;
  5293. }());
  5294. BABYLON.CustomShaderStructure = CustomShaderStructure;
  5295. var ShaderSpecialParts = /** @class */ (function () {
  5296. function ShaderSpecialParts() {
  5297. }
  5298. return ShaderSpecialParts;
  5299. }());
  5300. BABYLON.ShaderSpecialParts = ShaderSpecialParts;
  5301. var ShaderForVer3_0 = /** @class */ (function (_super) {
  5302. __extends(ShaderForVer3_0, _super);
  5303. function ShaderForVer3_0() {
  5304. var _this = _super.call(this) || this;
  5305. _this.VertexStore = "";
  5306. _this.FragmentStore = "#include<__decl__defaultFragment>\n\
  5307. #[Fragment_Begin]\n\
  5308. #extension GL_OES_standard_derivatives : enable\n\
  5309. #ifdef LOGARITHMICDEPTH\n\
  5310. #extension GL_EXT_frag_depth : enable\n\
  5311. #endif\n\
  5312. \n\
  5313. #define RECIPROCAL_PI2 0.15915494\n\
  5314. uniform vec3 vEyePosition;\n\
  5315. uniform vec3 vAmbientColor;\n\
  5316. \n\
  5317. varying vec3 vPositionW;\n\
  5318. #ifdef NORMAL\n\
  5319. varying vec3 vNormalW_helper;\n\
  5320. varying vec3 localNormal;\n\
  5321. varying vec3 localPosition;\n\
  5322. vec3 vNormalW;\n\
  5323. #endif\n\
  5324. #ifdef VERTEXCOLOR\n\
  5325. varying vec4 vColor;\n\
  5326. #endif\n\
  5327. \n\
  5328. #include<helperFunctions>\n\
  5329. \n\
  5330. #include<__decl__lightFragment>[0..maxSimultaneousLights]\n\
  5331. #include<lightsFragmentFunctions>\n\
  5332. #include<shadowsFragmentFunctions>\n\
  5333. \n\
  5334. #ifdef DIFFUSE\n\
  5335. varying vec2 vDiffuseUV;\n\
  5336. uniform sampler2D diffuseSampler;\n\
  5337. #endif\n\
  5338. #ifdef AMBIENT\n\
  5339. varying vec2 vAmbientUV;\n\
  5340. uniform sampler2D ambientSampler;\n\
  5341. #endif\n\
  5342. #ifdef OPACITY\n\
  5343. varying vec2 vOpacityUV;\n\
  5344. uniform sampler2D opacitySampler;\n\
  5345. #endif\n\
  5346. #ifdef EMISSIVE\n\
  5347. varying vec2 vEmissiveUV;\n\
  5348. uniform sampler2D emissiveSampler;\n\
  5349. #endif\n\
  5350. #ifdef LIGHTMAP\n\
  5351. varying vec2 vLightmapUV;\n\
  5352. uniform sampler2D lightmapSampler;\n\
  5353. #endif\n\
  5354. #ifdef REFRACTION\n\
  5355. #ifdef REFRACTIONMAP_3D\n\
  5356. uniform samplerCube refractionCubeSampler;\n\
  5357. #else\n\
  5358. uniform sampler2D refraction2DSampler;\n\
  5359. #endif\n\
  5360. #endif\n\
  5361. #if defined(SPECULAR) && defined(SPECULARTERM)\n\
  5362. varying vec2 vSpecularUV;\n\
  5363. uniform sampler2D specularSampler;\n\
  5364. #endif\n\
  5365. \n\
  5366. #include<fresnelFunction>\n\
  5367. \n\
  5368. #ifdef REFLECTION\n\
  5369. #ifdef REFLECTIONMAP_3D\n\
  5370. uniform samplerCube reflectionCubeSampler;\n\
  5371. #else\n\
  5372. uniform sampler2D reflection2DSampler;\n\
  5373. #endif\n\
  5374. #ifdef REFLECTIONMAP_SKYBOX\n\
  5375. varying vec3 vPositionUVW;\n\
  5376. #else\n\
  5377. #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\n\
  5378. varying vec3 vDirectionW;\n\
  5379. #endif\n\
  5380. #endif\n\
  5381. #include<reflectionFunction>\n\
  5382. #endif\n\
  5383. #include<imageProcessingDeclaration>\n\
  5384. #include<imageProcessingFunctions>\n\
  5385. \n\
  5386. #include<bumpFragmentFunctions>\n\
  5387. #include<clipPlaneFragmentDeclaration>\n\
  5388. #include<logDepthDeclaration>\n\
  5389. #include<fogFragmentDeclaration>\n\
  5390. \n\
  5391. #[Fragment_Definitions]\n\
  5392. \n\
  5393. void main(void) {\n\
  5394. \n\
  5395. vNormalW = vNormalW_helper;\n\
  5396. #[Fragment_MainBegin]\n\
  5397. \n\
  5398. #include<clipPlaneFragment>\n\
  5399. vec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\
  5400. \n\
  5401. vec4 baseColor=vec4(1.,1.,1.,1.);\n\
  5402. vec3 diffuseColor=vDiffuseColor.rgb;\n\
  5403. #[Fragment_Custom_Diffuse]\n\
  5404. \n\
  5405. float alpha=vDiffuseColor.a;\n\
  5406. #[Fragment_Custom_Alpha]\n\
  5407. \n\
  5408. #ifdef NORMAL\n\
  5409. vec3 normalW=normalize(vNormalW);\n\
  5410. #else\n\
  5411. vec3 normalW=vec3(1.0,1.0,1.0);\n\
  5412. #endif\n\
  5413. #include<bumpFragment>\n\
  5414. #ifdef TWOSIDEDLIGHTING\n\
  5415. normalW=gl_FrontFacing ? normalW : -normalW;\n\
  5416. #endif\n\
  5417. #ifdef DIFFUSE\n\
  5418. baseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);\n\
  5419. #ifdef ALPHATEST\n\
  5420. if (baseColor.a<0.4)\n\
  5421. discard;\n\
  5422. #endif\n\
  5423. #ifdef ALPHAFROMDIFFUSE\n\
  5424. alpha*=baseColor.a;\n\
  5425. #endif\n\
  5426. baseColor.rgb*=vDiffuseInfos.y;\n\
  5427. #endif\n\
  5428. #ifdef VERTEXCOLOR\n\
  5429. baseColor.rgb*=vColor.rgb;\n\
  5430. #endif\n\
  5431. \n\
  5432. vec3 baseAmbientColor=vec3(1.,1.,1.);\n\
  5433. #ifdef AMBIENT\n\
  5434. baseAmbientColor=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n\
  5435. #endif\n\
  5436. \n\
  5437. #ifdef SPECULARTERM\n\
  5438. float glossiness=vSpecularColor.a;\n\
  5439. vec3 specularColor=vSpecularColor.rgb;\n\
  5440. #ifdef SPECULAR\n\
  5441. vec4 specularMapColor=texture2D(specularSampler,vSpecularUV+uvOffset);\n\
  5442. specularColor=specularMapColor.rgb;\n\
  5443. #ifdef GLOSSINESS\n\
  5444. glossiness=glossiness*specularMapColor.a;\n\
  5445. #endif\n\
  5446. #endif\n\
  5447. #else\n\
  5448. float glossiness=0.;\n\
  5449. #endif\n\
  5450. \n\
  5451. vec3 diffuseBase=vec3(0.,0.,0.);\n\
  5452. lightingInfo info;\n\
  5453. #ifdef SPECULARTERM\n\
  5454. vec3 specularBase=vec3(0.,0.,0.);\n\
  5455. #endif\n\
  5456. float shadow=1.;\n\
  5457. #ifdef LIGHTMAP\n\
  5458. vec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;\n\
  5459. #endif\n\
  5460. #include<lightFragment>[0..maxSimultaneousLights]\n\
  5461. \n\
  5462. vec3 refractionColor=vec3(0.,0.,0.);\n\
  5463. #ifdef REFRACTION\n\
  5464. vec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));\n\
  5465. #ifdef REFRACTIONMAP_3D\n\
  5466. refractionVector.y=refractionVector.y*vRefractionInfos.w;\n\
  5467. if (dot(refractionVector,viewDirectionW)<1.0)\n\
  5468. {\n\
  5469. refractionColor=textureCube(refractionCubeSampler,refractionVector).rgb*vRefractionInfos.x;\n\
  5470. }\n\
  5471. #else\n\
  5472. vec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\n\
  5473. vec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;\n\
  5474. refractionCoords.y=1.0-refractionCoords.y;\n\
  5475. refractionColor=texture2D(refraction2DSampler,refractionCoords).rgb*vRefractionInfos.x;\n\
  5476. #endif\n\
  5477. #endif\n\
  5478. \n\
  5479. vec3 reflectionColor=vec3(0.,0.,0.);\n\
  5480. #ifdef REFLECTION\n\
  5481. vec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n\
  5482. #ifdef REFLECTIONMAP_3D\n\
  5483. #ifdef ROUGHNESS\n\
  5484. float bias=vReflectionInfos.y;\n\
  5485. #ifdef SPECULARTERM\n\
  5486. #ifdef SPECULAR\n\
  5487. #ifdef GLOSSINESS\n\
  5488. bias*=(1.0-specularMapColor.a);\n\
  5489. #endif\n\
  5490. #endif\n\
  5491. #endif\n\
  5492. reflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW,bias).rgb*vReflectionInfos.x;\n\
  5493. #else\n\
  5494. reflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW).rgb*vReflectionInfos.x;\n\
  5495. #endif\n\
  5496. #else\n\
  5497. vec2 coords=vReflectionUVW.xy;\n\
  5498. #ifdef REFLECTIONMAP_PROJECTION\n\
  5499. coords/=vReflectionUVW.z;\n\
  5500. #endif\n\
  5501. coords.y=1.0-coords.y;\n\
  5502. reflectionColor=texture2D(reflection2DSampler,coords).rgb*vReflectionInfos.x;\n\
  5503. #endif\n\
  5504. #ifdef REFLECTIONFRESNEL\n\
  5505. float reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);\n\
  5506. #ifdef REFLECTIONFRESNELFROMSPECULAR\n\
  5507. #ifdef SPECULARTERM\n\
  5508. reflectionColor*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n\
  5509. #else\n\
  5510. reflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n\
  5511. #endif\n\
  5512. #else\n\
  5513. reflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n\
  5514. #endif\n\
  5515. #endif\n\
  5516. #endif\n\
  5517. #ifdef REFRACTIONFRESNEL\n\
  5518. float refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);\n\
  5519. refractionColor*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;\n\
  5520. #endif\n\
  5521. #ifdef OPACITY\n\
  5522. vec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n\
  5523. #ifdef OPACITYRGB\n\
  5524. opacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\n\
  5525. alpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n\
  5526. #else\n\
  5527. alpha*=opacityMap.a*vOpacityInfos.y;\n\
  5528. #endif\n\
  5529. #endif\n\
  5530. #ifdef VERTEXALPHA\n\
  5531. alpha*=vColor.a;\n\
  5532. #endif\n\
  5533. #ifdef OPACITYFRESNEL\n\
  5534. float opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);\n\
  5535. alpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n\
  5536. #endif\n\
  5537. \n\
  5538. vec3 emissiveColor=vEmissiveColor;\n\
  5539. #ifdef EMISSIVE\n\
  5540. emissiveColor+=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb*vEmissiveInfos.y;\n\
  5541. #endif\n\
  5542. #ifdef EMISSIVEFRESNEL\n\
  5543. float emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);\n\
  5544. emissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n\
  5545. #endif\n\
  5546. \n\
  5547. #ifdef DIFFUSEFRESNEL\n\
  5548. float diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);\n\
  5549. diffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;\n\
  5550. #endif\n\
  5551. \n\
  5552. #ifdef EMISSIVEASILLUMINATION\n\
  5553. vec3 finalDiffuse=clamp(diffuseBase*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n\
  5554. #else\n\
  5555. #ifdef LINKEMISSIVEWITHDIFFUSE\n\
  5556. vec3 finalDiffuse=clamp((diffuseBase+emissiveColor)*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n\
  5557. #else\n\
  5558. vec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n\
  5559. #endif\n\
  5560. #endif\n\
  5561. #ifdef SPECULARTERM\n\
  5562. vec3 finalSpecular=specularBase*specularColor;\n\
  5563. #ifdef SPECULAROVERALPHA\n\
  5564. alpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);\n\
  5565. #endif\n\
  5566. #else\n\
  5567. vec3 finalSpecular=vec3(0.0);\n\
  5568. #endif\n\
  5569. #ifdef REFLECTIONOVERALPHA\n\
  5570. alpha=clamp(alpha+dot(reflectionColor,vec3(0.3,0.59,0.11)),0.,1.);\n\
  5571. #endif\n\
  5572. \n\
  5573. #ifdef EMISSIVEASILLUMINATION\n\
  5574. vec4 color=vec4(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+emissiveColor+refractionColor,0.0,1.0),alpha);\n\
  5575. #else\n\
  5576. vec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+refractionColor,alpha);\n\
  5577. #endif\n\
  5578. \n\
  5579. #ifdef LIGHTMAP\n\
  5580. #ifndef LIGHTMAPEXCLUDED\n\
  5581. #ifdef USELIGHTMAPASSHADOWMAP\n\
  5582. color.rgb*=lightmapColor;\n\
  5583. #else\n\
  5584. color.rgb+=lightmapColor;\n\
  5585. #endif\n\
  5586. #endif\n\
  5587. #endif\n\
  5588. #include<logDepthFragment>\n\
  5589. #include<fogFragment>\n\
  5590. \n\
  5591. // Apply image processing if relevant. As this applies in linear space, \n\
  5592. // We first move from gamma to linear.\n\
  5593. #ifdef IMAGEPROCESSINGPOSTPROCESS\n\
  5594. color.rgb = toLinearSpace(color.rgb);\n\
  5595. #else\n\
  5596. #ifdef IMAGEPROCESSING\n\
  5597. color.rgb = toLinearSpace(color.rgb);\n\
  5598. color = applyImageProcessing(color);\n\
  5599. #endif\n\
  5600. #endif\n\
  5601. \n\
  5602. #[Fragment_Before_FragColor]\n\
  5603. gl_FragColor=color;\n\
  5604. }";
  5605. _this.VertexStore = "#include<__decl__defaultVertex>\n\
  5606. \n\
  5607. #[Vertex_Begin]\n\
  5608. \n\
  5609. attribute vec3 position;\n\
  5610. #ifdef NORMAL\n\
  5611. attribute vec3 normal;\n\
  5612. #endif\n\
  5613. #ifdef TANGENT\n\
  5614. attribute vec4 tangent;\n\
  5615. #endif\n\
  5616. #ifdef UV1\n\
  5617. attribute vec2 uv;\n\
  5618. #endif\n\
  5619. #ifdef UV2\n\
  5620. attribute vec2 uv2;\n\
  5621. #endif\n\
  5622. #ifdef VERTEXCOLOR\n\
  5623. attribute vec4 color;\n\
  5624. #endif\n\
  5625. #include<bonesDeclaration>\n\
  5626. \n\
  5627. #include<instancesDeclaration>\n\
  5628. #ifdef DIFFUSE\n\
  5629. varying vec2 vDiffuseUV;\n\
  5630. #endif\n\
  5631. #ifdef AMBIENT\n\
  5632. varying vec2 vAmbientUV;\n\
  5633. #endif\n\
  5634. #ifdef OPACITY\n\
  5635. varying vec2 vOpacityUV;\n\
  5636. #endif\n\
  5637. #ifdef EMISSIVE\n\
  5638. varying vec2 vEmissiveUV;\n\
  5639. #endif\n\
  5640. #ifdef LIGHTMAP\n\
  5641. varying vec2 vLightmapUV;\n\
  5642. #endif\n\
  5643. #if defined(SPECULAR) && defined(SPECULARTERM)\n\
  5644. varying vec2 vSpecularUV;\n\
  5645. #endif\n\
  5646. #ifdef BUMP\n\
  5647. varying vec2 vBumpUV;\n\
  5648. #endif\n\
  5649. \n\
  5650. varying vec3 localPosition;\n\
  5651. varying vec3 vPositionW;\n\
  5652. #ifdef NORMAL\n\
  5653. varying vec3 vNormalW_helper;\n\
  5654. varying vec3 localNormal;\n\
  5655. #endif\n\
  5656. #ifdef VERTEXCOLOR\n\
  5657. varying vec4 vColor;\n\
  5658. #endif\n\
  5659. #include<bumpVertexDeclaration>\n\
  5660. #include<clipPlaneVertexDeclaration>\n\
  5661. #include<fogVertexDeclaration>\n\
  5662. #include<__decl__lightFragment>[0..maxSimultaneousLights]\n\
  5663. #include<morphTargetsVertexGlobalDeclaration>\n\
  5664. #include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]\n\
  5665. #ifdef REFLECTIONMAP_SKYBOX\n\
  5666. varying vec3 vPositionUVW;\n\
  5667. #endif\n\
  5668. #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\n\
  5669. varying vec3 vDirectionW;\n\
  5670. #endif\n\
  5671. #include<logDepthDeclaration>\n\
  5672. \n\
  5673. #[Vertex_Definitions]\n\
  5674. \n\
  5675. void main(void) {\n\
  5676. \n\
  5677. #[Vertex_MainBegin]\n\
  5678. \n\
  5679. vec3 positionUpdated=position;\n\
  5680. #ifdef NORMAL \n\
  5681. vec3 normalUpdated=normal;\n\
  5682. #endif\n\
  5683. #ifdef TANGENT\n\
  5684. vec4 tangentUpdated=tangent;\n\
  5685. #endif\n\
  5686. #include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]\n\
  5687. #ifdef REFLECTIONMAP_SKYBOX\n\
  5688. vPositionUVW=positionUpdated;\n\
  5689. #endif \n\
  5690. #include<instancesVertex>\n\
  5691. #include<bonesVertex>\n\
  5692. \n\
  5693. localPosition = positionUpdated;\n\
  5694. #[Vertex_Before_PositionUpdated]\n\
  5695. \n\
  5696. gl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\n\
  5697. vec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\n\
  5698. vPositionW=vec3(worldPos);\n\
  5699. #ifdef NORMAL\n\
  5700. \n\
  5701. #[Vertex_Before_NormalUpdated]\n\
  5702. \n\
  5703. localNormal = normalUpdated;\n\
  5704. vNormalW_helper=normalize(vec3(finalWorld*vec4(normalUpdated,0.0)));\n\
  5705. #endif\n\
  5706. #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\n\
  5707. vDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));\n\
  5708. #endif\n\
  5709. \n\
  5710. #ifndef UV1\n\
  5711. vec2 uv=vec2(0.,0.);\n\
  5712. #endif\n\
  5713. #ifndef UV2\n\
  5714. vec2 uv2=vec2(0.,0.);\n\
  5715. #endif\n\
  5716. #ifdef DIFFUSE\n\
  5717. if (vDiffuseInfos.x == 0.)\n\
  5718. {\n\
  5719. vDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n\
  5720. }\n\
  5721. else\n\
  5722. {\n\
  5723. vDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n\
  5724. }\n\
  5725. #endif\n\
  5726. #ifdef AMBIENT\n\
  5727. if (vAmbientInfos.x == 0.)\n\
  5728. {\n\
  5729. vAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n\
  5730. }\n\
  5731. else\n\
  5732. {\n\
  5733. vAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n\
  5734. }\n\
  5735. #endif\n\
  5736. #ifdef OPACITY\n\
  5737. if (vOpacityInfos.x == 0.)\n\
  5738. {\n\
  5739. vOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n\
  5740. }\n\
  5741. else\n\
  5742. {\n\
  5743. vOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n\
  5744. }\n\
  5745. #endif\n\
  5746. #ifdef EMISSIVE\n\
  5747. if (vEmissiveInfos.x == 0.)\n\
  5748. {\n\
  5749. vEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n\
  5750. }\n\
  5751. else\n\
  5752. {\n\
  5753. vEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n\
  5754. }\n\
  5755. #endif\n\
  5756. #ifdef LIGHTMAP\n\
  5757. if (vLightmapInfos.x == 0.)\n\
  5758. {\n\
  5759. vLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n\
  5760. }\n\
  5761. else\n\
  5762. {\n\
  5763. vLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n\
  5764. }\n\
  5765. #endif\n\
  5766. #if defined(SPECULAR) && defined(SPECULARTERM)\n\
  5767. if (vSpecularInfos.x == 0.)\n\
  5768. {\n\
  5769. vSpecularUV=vec2(specularMatrix*vec4(uv,1.0,0.0));\n\
  5770. }\n\
  5771. else\n\
  5772. {\n\
  5773. vSpecularUV=vec2(specularMatrix*vec4(uv2,1.0,0.0));\n\
  5774. }\n\
  5775. #endif\n\
  5776. #ifdef BUMP\n\
  5777. if (vBumpInfos.x == 0.)\n\
  5778. {\n\
  5779. vBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n\
  5780. }\n\
  5781. else\n\
  5782. {\n\
  5783. vBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n\
  5784. }\n\
  5785. #endif\n\
  5786. #include<bumpVertex>\n\
  5787. #include<clipPlaneVertex>\n\
  5788. #include<fogVertex>\n\
  5789. #include<shadowsVertex>[0..maxSimultaneousLights]\n\
  5790. #ifdef VERTEXCOLOR\n\
  5791. \n\
  5792. vColor=color;\n\
  5793. #endif\n\
  5794. #include<pointCloudVertex>\n\
  5795. #include<logDepthVertex>\n\
  5796. }";
  5797. return _this;
  5798. }
  5799. return ShaderForVer3_0;
  5800. }(CustomShaderStructure));
  5801. BABYLON.ShaderForVer3_0 = ShaderForVer3_0;
  5802. var StandardShaderVersions = /** @class */ (function () {
  5803. function StandardShaderVersions() {
  5804. }
  5805. StandardShaderVersions.Ver3_0 = "3.0.0";
  5806. return StandardShaderVersions;
  5807. }());
  5808. BABYLON.StandardShaderVersions = StandardShaderVersions;
  5809. var CustomMaterial = /** @class */ (function (_super) {
  5810. __extends(CustomMaterial, _super);
  5811. function CustomMaterial(name, scene) {
  5812. var _this = _super.call(this, name, scene) || this;
  5813. _this.CustomParts = new ShaderSpecialParts();
  5814. _this.customShaderNameResolve = _this.Builder;
  5815. _this.SelectVersion("3.0.0");
  5816. return _this;
  5817. }
  5818. CustomMaterial.prototype.AttachAfterBind = function (mesh, effect) {
  5819. for (var el in this._newUniformInstances) {
  5820. var ea = el.toString().split('-');
  5821. if (ea[0] == 'vec2')
  5822. effect.setVector2(ea[1], this._newUniformInstances[el]);
  5823. else if (ea[0] == 'vec3')
  5824. effect.setVector3(ea[1], this._newUniformInstances[el]);
  5825. else if (ea[0] == 'vec4')
  5826. effect.setVector4(ea[1], this._newUniformInstances[el]);
  5827. else if (ea[0] == 'mat4')
  5828. effect.setMatrix(ea[1], this._newUniformInstances[el]);
  5829. else if (ea[0] == 'float')
  5830. effect.setFloat(ea[1], this._newUniformInstances[el]);
  5831. }
  5832. for (var el in this._newSamplerInstances) {
  5833. var ea = el.toString().split('-');
  5834. if (ea[0] == 'sampler2D' && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady())
  5835. effect.setTexture(ea[1], this._newSamplerInstances[el]);
  5836. }
  5837. };
  5838. CustomMaterial.prototype.ReviewUniform = function (name, arr) {
  5839. if (name == "uniform") {
  5840. for (var ind in this._newUniforms)
  5841. if (this._customUniform[ind].indexOf('sampler') == -1)
  5842. arr.push(this._newUniforms[ind]);
  5843. }
  5844. if (name == "sampler") {
  5845. for (var ind in this._newUniforms)
  5846. if (this._customUniform[ind].indexOf('sampler') != -1)
  5847. arr.push(this._newUniforms[ind]);
  5848. }
  5849. return arr;
  5850. };
  5851. CustomMaterial.prototype.Builder = function (shaderName, uniforms, uniformBuffers, samplers, defines) {
  5852. var _this = this;
  5853. if (this._isCreatedShader)
  5854. return this._createdShaderName;
  5855. this._isCreatedShader = false;
  5856. CustomMaterial.ShaderIndexer++;
  5857. var name = "custom_" + CustomMaterial.ShaderIndexer;
  5858. this.ReviewUniform("uniform", uniforms);
  5859. this.ReviewUniform("sampler", samplers);
  5860. var fn_afterBind = this._afterBind;
  5861. this._afterBind = function (m, e) {
  5862. if (!e) {
  5863. return;
  5864. }
  5865. _this.AttachAfterBind(m, e);
  5866. try {
  5867. fn_afterBind(m, e);
  5868. }
  5869. catch (e) { }
  5870. ;
  5871. };
  5872. BABYLON.Effect.ShadersStore[name + "VertexShader"] = this.ShaderVersion.VertexStore
  5873. .replace('#[Vertex_Begin]', (this.CustomParts.Vertex_Begin ? this.CustomParts.Vertex_Begin : ""))
  5874. .replace('#[Vertex_Definitions]', (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Vertex_Definitions ? this.CustomParts.Vertex_Definitions : ""))
  5875. .replace('#[Vertex_MainBegin]', (this.CustomParts.Vertex_MainBegin ? this.CustomParts.Vertex_MainBegin : ""))
  5876. .replace('#[Vertex_Before_PositionUpdated]', (this.CustomParts.Vertex_Before_PositionUpdated ? this.CustomParts.Vertex_Before_PositionUpdated : ""))
  5877. .replace('#[Vertex_Before_NormalUpdated]', (this.CustomParts.Vertex_Before_NormalUpdated ? this.CustomParts.Vertex_Before_NormalUpdated : ""));
  5878. BABYLON.Effect.ShadersStore[name + "PixelShader"] = this.ShaderVersion.FragmentStore
  5879. .replace('#[Fragment_Begin]', (this.CustomParts.Fragment_Begin ? this.CustomParts.Fragment_Begin : ""))
  5880. .replace('#[Fragment_MainBegin]', (this.CustomParts.Fragment_MainBegin ? this.CustomParts.Fragment_MainBegin : ""))
  5881. .replace('#[Fragment_Definitions]', (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Fragment_Definitions ? this.CustomParts.Fragment_Definitions : ""))
  5882. .replace('#[Fragment_Custom_Diffuse]', (this.CustomParts.Fragment_Custom_Diffuse ? this.CustomParts.Fragment_Custom_Diffuse : ""))
  5883. .replace('#[Fragment_Custom_Alpha]', (this.CustomParts.Fragment_Custom_Alpha ? this.CustomParts.Fragment_Custom_Alpha : ""))
  5884. .replace('#[Fragment_Before_FragColor]', (this.CustomParts.Fragment_Before_FragColor ? this.CustomParts.Fragment_Before_FragColor : ""));
  5885. this._isCreatedShader = true;
  5886. this._createdShaderName = name;
  5887. return name;
  5888. };
  5889. CustomMaterial.prototype.SelectVersion = function (ver) {
  5890. switch (ver) {
  5891. case "3.0.0":
  5892. this.ShaderVersion = new ShaderForVer3_0();
  5893. break;
  5894. }
  5895. };
  5896. CustomMaterial.prototype.AddUniform = function (name, kind, param) {
  5897. if (!this._customUniform) {
  5898. this._customUniform = new Array();
  5899. this._newUniforms = new Array();
  5900. this._newSamplerInstances = new Array();
  5901. this._newUniformInstances = new Array();
  5902. }
  5903. if (param) {
  5904. if (kind.indexOf("sampler") == -1) {
  5905. this._newUniformInstances[kind + "-" + name] = param;
  5906. }
  5907. else {
  5908. this._newUniformInstances[kind + "-" + name] = param;
  5909. }
  5910. }
  5911. this._customUniform.push("uniform " + kind + " " + name + ";");
  5912. this._newUniforms.push(name);
  5913. return this;
  5914. };
  5915. CustomMaterial.prototype.Fragment_Begin = function (shaderPart) {
  5916. this.CustomParts.Fragment_Begin = shaderPart;
  5917. return this;
  5918. };
  5919. CustomMaterial.prototype.Fragment_Definitions = function (shaderPart) {
  5920. this.CustomParts.Fragment_Definitions = shaderPart;
  5921. return this;
  5922. };
  5923. CustomMaterial.prototype.Fragment_MainBegin = function (shaderPart) {
  5924. this.CustomParts.Fragment_MainBegin = shaderPart;
  5925. return this;
  5926. };
  5927. CustomMaterial.prototype.Fragment_Custom_Diffuse = function (shaderPart) {
  5928. this.CustomParts.Fragment_Custom_Diffuse = shaderPart.replace("result", "diffuseColor");
  5929. return this;
  5930. };
  5931. CustomMaterial.prototype.Fragment_Custom_Alpha = function (shaderPart) {
  5932. this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace("result", "alpha");
  5933. return this;
  5934. };
  5935. CustomMaterial.prototype.Fragment_Before_FragColor = function (shaderPart) {
  5936. this.CustomParts.Fragment_Before_FragColor = shaderPart.replace("result", "color");
  5937. return this;
  5938. };
  5939. CustomMaterial.prototype.Vertex_Begin = function (shaderPart) {
  5940. this.CustomParts.Vertex_Begin = shaderPart;
  5941. return this;
  5942. };
  5943. CustomMaterial.prototype.Vertex_Definitions = function (shaderPart) {
  5944. this.CustomParts.Vertex_Definitions = shaderPart;
  5945. return this;
  5946. };
  5947. CustomMaterial.prototype.Vertex_MainBegin = function (shaderPart) {
  5948. this.CustomParts.Vertex_MainBegin = shaderPart;
  5949. return this;
  5950. };
  5951. CustomMaterial.prototype.Vertex_Before_PositionUpdated = function (shaderPart) {
  5952. this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace("result", "positionUpdated");
  5953. return this;
  5954. };
  5955. CustomMaterial.prototype.Vertex_Before_NormalUpdated = function (shaderPart) {
  5956. this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace("result", "normalUpdated");
  5957. return this;
  5958. };
  5959. CustomMaterial.ShaderIndexer = 1;
  5960. return CustomMaterial;
  5961. }(StandardMaterial_OldVer));
  5962. BABYLON.CustomMaterial = CustomMaterial;
  5963. })(BABYLON || (BABYLON = {}));
  5964. //# sourceMappingURL=babylon.customMaterial.js.map
  5965. var BABYLON;
  5966. (function (BABYLON) {
  5967. var CellMaterialDefines = /** @class */ (function (_super) {
  5968. __extends(CellMaterialDefines, _super);
  5969. function CellMaterialDefines() {
  5970. var _this = _super.call(this) || this;
  5971. _this.DIFFUSE = false;
  5972. _this.CLIPPLANE = false;
  5973. _this.ALPHATEST = false;
  5974. _this.POINTSIZE = false;
  5975. _this.FOG = false;
  5976. _this.NORMAL = false;
  5977. _this.UV1 = false;
  5978. _this.UV2 = false;
  5979. _this.VERTEXCOLOR = false;
  5980. _this.VERTEXALPHA = false;
  5981. _this.NUM_BONE_INFLUENCERS = 0;
  5982. _this.BonesPerMesh = 0;
  5983. _this.INSTANCES = false;
  5984. _this.NDOTL = true;
  5985. _this.CUSTOMUSERLIGHTING = true;
  5986. _this.CELLBASIC = true;
  5987. _this.DEPTHPREPASS = false;
  5988. _this.rebuild();
  5989. return _this;
  5990. }
  5991. return CellMaterialDefines;
  5992. }(BABYLON.MaterialDefines));
  5993. var CellMaterial = /** @class */ (function (_super) {
  5994. __extends(CellMaterial, _super);
  5995. function CellMaterial(name, scene) {
  5996. var _this = _super.call(this, name, scene) || this;
  5997. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  5998. _this._computeHighLevel = false;
  5999. _this._disableLighting = false;
  6000. _this._maxSimultaneousLights = 4;
  6001. return _this;
  6002. }
  6003. CellMaterial.prototype.needAlphaBlending = function () {
  6004. return (this.alpha < 1.0);
  6005. };
  6006. CellMaterial.prototype.needAlphaTesting = function () {
  6007. return false;
  6008. };
  6009. CellMaterial.prototype.getAlphaTestTexture = function () {
  6010. return null;
  6011. };
  6012. // Methods
  6013. CellMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  6014. if (this.isFrozen) {
  6015. if (this._wasPreviouslyReady && subMesh.effect) {
  6016. return true;
  6017. }
  6018. }
  6019. if (!subMesh._materialDefines) {
  6020. subMesh._materialDefines = new CellMaterialDefines();
  6021. }
  6022. var defines = subMesh._materialDefines;
  6023. var scene = this.getScene();
  6024. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  6025. if (this._renderId === scene.getRenderId()) {
  6026. return true;
  6027. }
  6028. }
  6029. var engine = scene.getEngine();
  6030. // Textures
  6031. if (defines._areTexturesDirty) {
  6032. defines._needUVs = false;
  6033. if (scene.texturesEnabled) {
  6034. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  6035. if (!this._diffuseTexture.isReady()) {
  6036. return false;
  6037. }
  6038. else {
  6039. defines._needUVs = true;
  6040. defines.DIFFUSE = true;
  6041. }
  6042. }
  6043. }
  6044. }
  6045. // High level
  6046. defines.CELLBASIC = !this.computeHighLevel;
  6047. // Misc.
  6048. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  6049. // Lights
  6050. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  6051. // Values that need to be evaluated on every frame
  6052. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  6053. // Attribs
  6054. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  6055. // Get correct effect
  6056. if (defines.isDirty) {
  6057. defines.markAsProcessed();
  6058. scene.resetCachedMaterial();
  6059. // Fallbacks
  6060. var fallbacks = new BABYLON.EffectFallbacks();
  6061. if (defines.FOG) {
  6062. fallbacks.addFallback(1, "FOG");
  6063. }
  6064. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  6065. if (defines.NUM_BONE_INFLUENCERS > 0) {
  6066. fallbacks.addCPUSkinningFallback(0, mesh);
  6067. }
  6068. //Attributes
  6069. var attribs = [BABYLON.VertexBuffer.PositionKind];
  6070. if (defines.NORMAL) {
  6071. attribs.push(BABYLON.VertexBuffer.NormalKind);
  6072. }
  6073. if (defines.UV1) {
  6074. attribs.push(BABYLON.VertexBuffer.UVKind);
  6075. }
  6076. if (defines.UV2) {
  6077. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  6078. }
  6079. if (defines.VERTEXCOLOR) {
  6080. attribs.push(BABYLON.VertexBuffer.ColorKind);
  6081. }
  6082. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  6083. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  6084. var shaderName = "cell";
  6085. var join = defines.toString();
  6086. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  6087. "vFogInfos", "vFogColor", "pointSize",
  6088. "vDiffuseInfos",
  6089. "mBones",
  6090. "vClipPlane", "diffuseMatrix"
  6091. ];
  6092. var samplers = ["diffuseSampler"];
  6093. var uniformBuffers = new Array();
  6094. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  6095. uniformsNames: uniforms,
  6096. uniformBuffersNames: uniformBuffers,
  6097. samplers: samplers,
  6098. defines: defines,
  6099. maxSimultaneousLights: this.maxSimultaneousLights
  6100. });
  6101. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  6102. attributes: attribs,
  6103. uniformsNames: uniforms,
  6104. uniformBuffersNames: uniformBuffers,
  6105. samplers: samplers,
  6106. defines: join,
  6107. fallbacks: fallbacks,
  6108. onCompiled: this.onCompiled,
  6109. onError: this.onError,
  6110. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights - 1 }
  6111. }, engine), defines);
  6112. }
  6113. if (!subMesh.effect || !subMesh.effect.isReady()) {
  6114. return false;
  6115. }
  6116. this._renderId = scene.getRenderId();
  6117. this._wasPreviouslyReady = true;
  6118. return true;
  6119. };
  6120. CellMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  6121. var scene = this.getScene();
  6122. var defines = subMesh._materialDefines;
  6123. if (!defines) {
  6124. return;
  6125. }
  6126. var effect = subMesh.effect;
  6127. if (!effect) {
  6128. return;
  6129. }
  6130. this._activeEffect = effect;
  6131. // Matrices
  6132. this.bindOnlyWorldMatrix(world);
  6133. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  6134. // Bones
  6135. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  6136. if (this._mustRebind(scene, effect)) {
  6137. // Textures
  6138. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  6139. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  6140. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  6141. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  6142. }
  6143. // Clip plane
  6144. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  6145. // Point size
  6146. if (this.pointsCloud) {
  6147. this._activeEffect.setFloat("pointSize", this.pointSize);
  6148. }
  6149. this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  6150. }
  6151. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  6152. // Lights
  6153. if (scene.lightsEnabled && !this.disableLighting) {
  6154. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this._maxSimultaneousLights);
  6155. }
  6156. // View
  6157. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  6158. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  6159. }
  6160. // Fog
  6161. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  6162. this._afterBind(mesh, this._activeEffect);
  6163. };
  6164. CellMaterial.prototype.getAnimatables = function () {
  6165. var results = [];
  6166. if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
  6167. results.push(this._diffuseTexture);
  6168. }
  6169. return results;
  6170. };
  6171. CellMaterial.prototype.getActiveTextures = function () {
  6172. var activeTextures = _super.prototype.getActiveTextures.call(this);
  6173. if (this._diffuseTexture) {
  6174. activeTextures.push(this._diffuseTexture);
  6175. }
  6176. return activeTextures;
  6177. };
  6178. CellMaterial.prototype.hasTexture = function (texture) {
  6179. if (_super.prototype.hasTexture.call(this, texture)) {
  6180. return true;
  6181. }
  6182. return this._diffuseTexture === texture;
  6183. };
  6184. CellMaterial.prototype.dispose = function (forceDisposeEffect) {
  6185. if (this._diffuseTexture) {
  6186. this._diffuseTexture.dispose();
  6187. }
  6188. _super.prototype.dispose.call(this, forceDisposeEffect);
  6189. };
  6190. CellMaterial.prototype.getClassName = function () {
  6191. return "CellMaterial";
  6192. };
  6193. CellMaterial.prototype.clone = function (name) {
  6194. var _this = this;
  6195. return BABYLON.SerializationHelper.Clone(function () { return new CellMaterial(name, _this.getScene()); }, this);
  6196. };
  6197. CellMaterial.prototype.serialize = function () {
  6198. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  6199. serializationObject.customType = "BABYLON.CellMaterial";
  6200. return serializationObject;
  6201. };
  6202. // Statics
  6203. CellMaterial.Parse = function (source, scene, rootUrl) {
  6204. return BABYLON.SerializationHelper.Parse(function () { return new CellMaterial(source.name, scene); }, source, scene, rootUrl);
  6205. };
  6206. __decorate([
  6207. BABYLON.serializeAsTexture("diffuseTexture")
  6208. ], CellMaterial.prototype, "_diffuseTexture", void 0);
  6209. __decorate([
  6210. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  6211. ], CellMaterial.prototype, "diffuseTexture", void 0);
  6212. __decorate([
  6213. BABYLON.serializeAsColor3("diffuseColor")
  6214. ], CellMaterial.prototype, "diffuseColor", void 0);
  6215. __decorate([
  6216. BABYLON.serialize("computeHighLevel")
  6217. ], CellMaterial.prototype, "_computeHighLevel", void 0);
  6218. __decorate([
  6219. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  6220. ], CellMaterial.prototype, "computeHighLevel", void 0);
  6221. __decorate([
  6222. BABYLON.serialize("disableLighting")
  6223. ], CellMaterial.prototype, "_disableLighting", void 0);
  6224. __decorate([
  6225. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  6226. ], CellMaterial.prototype, "disableLighting", void 0);
  6227. __decorate([
  6228. BABYLON.serialize("maxSimultaneousLights")
  6229. ], CellMaterial.prototype, "_maxSimultaneousLights", void 0);
  6230. __decorate([
  6231. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  6232. ], CellMaterial.prototype, "maxSimultaneousLights", void 0);
  6233. return CellMaterial;
  6234. }(BABYLON.PushMaterial));
  6235. BABYLON.CellMaterial = CellMaterial;
  6236. })(BABYLON || (BABYLON = {}));
  6237. //# sourceMappingURL=babylon.cellMaterial.js.map
  6238. 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";
  6239. 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}";
  6240. var BABYLON;
  6241. (function (BABYLON) {
  6242. var LegacyPBRMaterialDefines = /** @class */ (function (_super) {
  6243. __extends(LegacyPBRMaterialDefines, _super);
  6244. function LegacyPBRMaterialDefines() {
  6245. var _this = _super.call(this) || this;
  6246. _this.ALBEDO = false;
  6247. _this.AMBIENT = false;
  6248. _this.AMBIENTINGRAYSCALE = false;
  6249. _this.OPACITY = false;
  6250. _this.OPACITYRGB = false;
  6251. _this.REFLECTION = false;
  6252. _this.EMISSIVE = false;
  6253. _this.REFLECTIVITY = false;
  6254. _this.BUMP = false;
  6255. _this.PARALLAX = false;
  6256. _this.PARALLAXOCCLUSION = false;
  6257. _this.SPECULAROVERALPHA = false;
  6258. _this.CLIPPLANE = false;
  6259. _this.ALPHATEST = false;
  6260. _this.ALPHAFROMALBEDO = false;
  6261. _this.POINTSIZE = false;
  6262. _this.FOG = false;
  6263. _this.SPECULARTERM = false;
  6264. _this.OPACITYFRESNEL = false;
  6265. _this.EMISSIVEFRESNEL = false;
  6266. _this.FRESNEL = false;
  6267. _this.NORMAL = false;
  6268. _this.TANGENT = false;
  6269. _this.UV1 = false;
  6270. _this.UV2 = false;
  6271. _this.VERTEXCOLOR = false;
  6272. _this.VERTEXALPHA = false;
  6273. _this.NUM_BONE_INFLUENCERS = 0;
  6274. _this.BonesPerMesh = 0;
  6275. _this.INSTANCES = false;
  6276. _this.MICROSURFACEFROMREFLECTIVITYMAP = false;
  6277. _this.MICROSURFACEAUTOMATIC = false;
  6278. _this.EMISSIVEASILLUMINATION = false;
  6279. _this.LINKEMISSIVEWITHALBEDO = false;
  6280. _this.LIGHTMAP = false;
  6281. _this.USELIGHTMAPASSHADOWMAP = false;
  6282. _this.REFLECTIONMAP_3D = false;
  6283. _this.REFLECTIONMAP_SPHERICAL = false;
  6284. _this.REFLECTIONMAP_PLANAR = false;
  6285. _this.REFLECTIONMAP_CUBIC = false;
  6286. _this.REFLECTIONMAP_PROJECTION = false;
  6287. _this.REFLECTIONMAP_SKYBOX = false;
  6288. _this.REFLECTIONMAP_EXPLICIT = false;
  6289. _this.REFLECTIONMAP_EQUIRECTANGULAR = false;
  6290. _this.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;
  6291. _this.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;
  6292. _this.INVERTCUBICMAP = false;
  6293. _this.LOGARITHMICDEPTH = false;
  6294. _this.CAMERATONEMAP = false;
  6295. _this.CAMERACONTRAST = false;
  6296. _this.CAMERACOLORGRADING = false;
  6297. _this.CAMERACOLORCURVES = false;
  6298. _this.OVERLOADEDVALUES = false;
  6299. _this.OVERLOADEDSHADOWVALUES = false;
  6300. _this.USESPHERICALFROMREFLECTIONMAP = false;
  6301. _this.REFRACTION = false;
  6302. _this.REFRACTIONMAP_3D = false;
  6303. _this.LINKREFRACTIONTOTRANSPARENCY = false;
  6304. _this.REFRACTIONMAPINLINEARSPACE = false;
  6305. _this.LODBASEDMICROSFURACE = false;
  6306. _this.USEPHYSICALLIGHTFALLOFF = false;
  6307. _this.RADIANCEOVERALPHA = false;
  6308. _this.USEPMREMREFLECTION = false;
  6309. _this.USEPMREMREFRACTION = false;
  6310. _this.TWOSIDEDLIGHTING = false;
  6311. _this.SHADOWFLOAT = false;
  6312. _this.METALLICWORKFLOW = false;
  6313. _this.METALLICMAP = false;
  6314. _this.ROUGHNESSSTOREINMETALMAPALPHA = false;
  6315. _this.ROUGHNESSSTOREINMETALMAPGREEN = false;
  6316. _this.METALLNESSSTOREINMETALMAPBLUE = false;
  6317. _this.AOSTOREINMETALMAPRED = false;
  6318. _this.MICROSURFACEMAP = false;
  6319. _this.MORPHTARGETS = false;
  6320. _this.MORPHTARGETS_NORMAL = false;
  6321. _this.MORPHTARGETS_TANGENT = false;
  6322. _this.NUM_MORPH_INFLUENCERS = 0;
  6323. _this.rebuild();
  6324. return _this;
  6325. }
  6326. return LegacyPBRMaterialDefines;
  6327. }(BABYLON.MaterialDefines));
  6328. /**
  6329. * The Physically based material of BJS.
  6330. *
  6331. * This offers the main features of a standard PBR material.
  6332. * For more information, please refer to the documentation :
  6333. * http://doc.babylonjs.com/extensions/Physically_Based_Rendering
  6334. */
  6335. var LegacyPBRMaterial = /** @class */ (function (_super) {
  6336. __extends(LegacyPBRMaterial, _super);
  6337. /**
  6338. * Instantiates a new PBRMaterial instance.
  6339. *
  6340. * @param name The material name
  6341. * @param scene The scene the material will be use in.
  6342. */
  6343. function LegacyPBRMaterial(name, scene) {
  6344. var _this = _super.call(this, name, scene) || this;
  6345. /**
  6346. * Intensity of the direct lights e.g. the four lights available in your scene.
  6347. * This impacts both the direct diffuse and specular highlights.
  6348. */
  6349. _this.directIntensity = 1.0;
  6350. /**
  6351. * Intensity of the emissive part of the material.
  6352. * This helps controlling the emissive effect without modifying the emissive color.
  6353. */
  6354. _this.emissiveIntensity = 1.0;
  6355. /**
  6356. * Intensity of the environment e.g. how much the environment will light the object
  6357. * either through harmonics for rough material or through the refelction for shiny ones.
  6358. */
  6359. _this.environmentIntensity = 1.0;
  6360. /**
  6361. * This is a special control allowing the reduction of the specular highlights coming from the
  6362. * four lights of the scene. Those highlights may not be needed in full environment lighting.
  6363. */
  6364. _this.specularIntensity = 1.0;
  6365. _this._lightingInfos = new BABYLON.Vector4(_this.directIntensity, _this.emissiveIntensity, _this.environmentIntensity, _this.specularIntensity);
  6366. /**
  6367. * Debug Control allowing disabling the bump map on this material.
  6368. */
  6369. _this.disableBumpMap = false;
  6370. /**
  6371. * Debug Control helping enforcing or dropping the darkness of shadows.
  6372. * 1.0 means the shadows have their normal darkness, 0.0 means the shadows are not visible.
  6373. */
  6374. _this.overloadedShadowIntensity = 1.0;
  6375. /**
  6376. * Debug Control helping dropping the shading effect coming from the diffuse lighting.
  6377. * 1.0 means the shade have their normal impact, 0.0 means no shading at all.
  6378. */
  6379. _this.overloadedShadeIntensity = 1.0;
  6380. _this._overloadedShadowInfos = new BABYLON.Vector4(_this.overloadedShadowIntensity, _this.overloadedShadeIntensity, 0.0, 0.0);
  6381. /**
  6382. * The camera exposure used on this material.
  6383. * This property is here and not in the camera to allow controlling exposure without full screen post process.
  6384. * This corresponds to a photographic exposure.
  6385. */
  6386. _this.cameraExposure = 1.0;
  6387. /**
  6388. * The camera contrast used on this material.
  6389. * This property is here and not in the camera to allow controlling contrast without full screen post process.
  6390. */
  6391. _this.cameraContrast = 1.0;
  6392. /**
  6393. * Color Grading 2D Lookup Texture.
  6394. * This allows special effects like sepia, black and white to sixties rendering style.
  6395. */
  6396. _this.cameraColorGradingTexture = null;
  6397. /**
  6398. * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
  6399. * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
  6400. * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;
  6401. * corresponding to low luminance, medium luminance, and high luminance areas respectively.
  6402. */
  6403. _this.cameraColorCurves = null;
  6404. _this._cameraInfos = new BABYLON.Vector4(1.0, 1.0, 0.0, 0.0);
  6405. _this._microsurfaceTextureLods = new BABYLON.Vector2(0.0, 0.0);
  6406. /**
  6407. * Debug Control allowing to overload the ambient color.
  6408. * This as to be use with the overloadedAmbientIntensity parameter.
  6409. */
  6410. _this.overloadedAmbient = BABYLON.Color3.White();
  6411. /**
  6412. * Debug Control indicating how much the overloaded ambient color is used against the default one.
  6413. */
  6414. _this.overloadedAmbientIntensity = 0.0;
  6415. /**
  6416. * Debug Control allowing to overload the albedo color.
  6417. * This as to be use with the overloadedAlbedoIntensity parameter.
  6418. */
  6419. _this.overloadedAlbedo = BABYLON.Color3.White();
  6420. /**
  6421. * Debug Control indicating how much the overloaded albedo color is used against the default one.
  6422. */
  6423. _this.overloadedAlbedoIntensity = 0.0;
  6424. /**
  6425. * Debug Control allowing to overload the reflectivity color.
  6426. * This as to be use with the overloadedReflectivityIntensity parameter.
  6427. */
  6428. _this.overloadedReflectivity = new BABYLON.Color3(0.0, 0.0, 0.0);
  6429. /**
  6430. * Debug Control indicating how much the overloaded reflectivity color is used against the default one.
  6431. */
  6432. _this.overloadedReflectivityIntensity = 0.0;
  6433. /**
  6434. * Debug Control allowing to overload the emissive color.
  6435. * This as to be use with the overloadedEmissiveIntensity parameter.
  6436. */
  6437. _this.overloadedEmissive = BABYLON.Color3.White();
  6438. /**
  6439. * Debug Control indicating how much the overloaded emissive color is used against the default one.
  6440. */
  6441. _this.overloadedEmissiveIntensity = 0.0;
  6442. _this._overloadedIntensity = new BABYLON.Vector4(_this.overloadedAmbientIntensity, _this.overloadedAlbedoIntensity, _this.overloadedReflectivityIntensity, _this.overloadedEmissiveIntensity);
  6443. /**
  6444. * Debug Control allowing to overload the reflection color.
  6445. * This as to be use with the overloadedReflectionIntensity parameter.
  6446. */
  6447. _this.overloadedReflection = BABYLON.Color3.White();
  6448. /**
  6449. * Debug Control indicating how much the overloaded reflection color is used against the default one.
  6450. */
  6451. _this.overloadedReflectionIntensity = 0.0;
  6452. /**
  6453. * Debug Control allowing to overload the microsurface.
  6454. * This as to be use with the overloadedMicroSurfaceIntensity parameter.
  6455. */
  6456. _this.overloadedMicroSurface = 0.0;
  6457. /**
  6458. * Debug Control indicating how much the overloaded microsurface is used against the default one.
  6459. */
  6460. _this.overloadedMicroSurfaceIntensity = 0.0;
  6461. _this._overloadedMicroSurface = new BABYLON.Vector3(_this.overloadedMicroSurface, _this.overloadedMicroSurfaceIntensity, _this.overloadedReflectionIntensity);
  6462. /**
  6463. * AKA Occlusion Texture Intensity in other nomenclature.
  6464. */
  6465. _this.ambientTextureStrength = 1.0;
  6466. _this.ambientColor = new BABYLON.Color3(0, 0, 0);
  6467. /**
  6468. * AKA Diffuse Color in other nomenclature.
  6469. */
  6470. _this.albedoColor = new BABYLON.Color3(1, 1, 1);
  6471. /**
  6472. * AKA Specular Color in other nomenclature.
  6473. */
  6474. _this.reflectivityColor = new BABYLON.Color3(1, 1, 1);
  6475. _this.reflectionColor = new BABYLON.Color3(0.0, 0.0, 0.0);
  6476. _this.emissiveColor = new BABYLON.Color3(0, 0, 0);
  6477. /**
  6478. * AKA Glossiness in other nomenclature.
  6479. */
  6480. _this.microSurface = 0.9;
  6481. /**
  6482. * source material index of refraction (IOR)' / 'destination material IOR.
  6483. */
  6484. _this.indexOfRefraction = 0.66;
  6485. /**
  6486. * Controls if refraction needs to be inverted on Y. This could be usefull for procedural texture.
  6487. */
  6488. _this.invertRefractionY = false;
  6489. /**
  6490. * This parameters will make the material used its opacity to control how much it is refracting aginst not.
  6491. * Materials half opaque for instance using refraction could benefit from this control.
  6492. */
  6493. _this.linkRefractionWithTransparency = false;
  6494. /**
  6495. * The emissive and albedo are linked to never be more than one (Energy conservation).
  6496. */
  6497. _this.linkEmissiveWithAlbedo = false;
  6498. _this.useLightmapAsShadowmap = false;
  6499. /**
  6500. * In this mode, the emissive informtaion will always be added to the lighting once.
  6501. * A light for instance can be thought as emissive.
  6502. */
  6503. _this.useEmissiveAsIllumination = false;
  6504. /**
  6505. * Secifies that the alpha is coming form the albedo channel alpha channel.
  6506. */
  6507. _this.useAlphaFromAlbedoTexture = false;
  6508. /**
  6509. * Specifies that the material will keeps the specular highlights over a transparent surface (only the most limunous ones).
  6510. * A car glass is a good exemple of that. When sun reflects on it you can not see what is behind.
  6511. */
  6512. _this.useSpecularOverAlpha = true;
  6513. /**
  6514. * Specifies if the reflectivity texture contains the glossiness information in its alpha channel.
  6515. */
  6516. _this.useMicroSurfaceFromReflectivityMapAlpha = false;
  6517. /**
  6518. * Specifies if the metallic texture contains the roughness information in its alpha channel.
  6519. */
  6520. _this.useRoughnessFromMetallicTextureAlpha = true;
  6521. /**
  6522. * Specifies if the metallic texture contains the roughness information in its green channel.
  6523. */
  6524. _this.useRoughnessFromMetallicTextureGreen = false;
  6525. /**
  6526. * Specifies if the metallic texture contains the metallness information in its blue channel.
  6527. */
  6528. _this.useMetallnessFromMetallicTextureBlue = false;
  6529. /**
  6530. * Specifies if the metallic texture contains the ambient occlusion information in its red channel.
  6531. */
  6532. _this.useAmbientOcclusionFromMetallicTextureRed = false;
  6533. /**
  6534. * Specifies if the ambient texture contains the ambient occlusion information in its red channel only.
  6535. */
  6536. _this.useAmbientInGrayScale = false;
  6537. /**
  6538. * In case the reflectivity map does not contain the microsurface information in its alpha channel,
  6539. * The material will try to infer what glossiness each pixel should be.
  6540. */
  6541. _this.useAutoMicroSurfaceFromReflectivityMap = false;
  6542. /**
  6543. * Allows to work with scalar in linear mode. This is definitely a matter of preferences and tools used during
  6544. * the creation of the material.
  6545. */
  6546. _this.useScalarInLinearSpace = false;
  6547. /**
  6548. * BJS is using an harcoded light falloff based on a manually sets up range.
  6549. * In PBR, one way to represents the fallof is to use the inverse squared root algorythm.
  6550. * This parameter can help you switch back to the BJS mode in order to create scenes using both materials.
  6551. */
  6552. _this.usePhysicalLightFalloff = true;
  6553. /**
  6554. * Specifies that the material will keeps the reflection highlights over a transparent surface (only the most limunous ones).
  6555. * A car glass is a good exemple of that. When the street lights reflects on it you can not see what is behind.
  6556. */
  6557. _this.useRadianceOverAlpha = true;
  6558. /**
  6559. * Allows using the bump map in parallax mode.
  6560. */
  6561. _this.useParallax = false;
  6562. /**
  6563. * Allows using the bump map in parallax occlusion mode.
  6564. */
  6565. _this.useParallaxOcclusion = false;
  6566. /**
  6567. * Controls the scale bias of the parallax mode.
  6568. */
  6569. _this.parallaxScaleBias = 0.05;
  6570. /**
  6571. * If sets to true, disables all the lights affecting the material.
  6572. */
  6573. _this.disableLighting = false;
  6574. /**
  6575. * Number of Simultaneous lights allowed on the material.
  6576. */
  6577. _this.maxSimultaneousLights = 4;
  6578. /**
  6579. * If sets to true, x component of normal map value will invert (x = 1.0 - x).
  6580. */
  6581. _this.invertNormalMapX = false;
  6582. /**
  6583. * If sets to true, y component of normal map value will invert (y = 1.0 - y).
  6584. */
  6585. _this.invertNormalMapY = false;
  6586. /**
  6587. * If sets to true and backfaceCulling is false, normals will be flipped on the backside.
  6588. */
  6589. _this.twoSidedLighting = false;
  6590. _this._renderTargets = new BABYLON.SmartArray(16);
  6591. _this._globalAmbientColor = new BABYLON.Color3(0, 0, 0);
  6592. _this._tempColor = new BABYLON.Color3();
  6593. _this._defines = new LegacyPBRMaterialDefines();
  6594. _this._cachedDefines = new LegacyPBRMaterialDefines();
  6595. _this._myScene = null;
  6596. _this._cachedDefines.BonesPerMesh = -1;
  6597. _this.getRenderTargetTextures = function () {
  6598. _this._renderTargets.reset();
  6599. if (BABYLON.StandardMaterial.ReflectionTextureEnabled && _this.reflectionTexture && _this.reflectionTexture.isRenderTarget) {
  6600. _this._renderTargets.push(_this.reflectionTexture);
  6601. }
  6602. if (BABYLON.StandardMaterial.RefractionTextureEnabled && _this.refractionTexture && _this.refractionTexture.isRenderTarget) {
  6603. _this._renderTargets.push(_this.refractionTexture);
  6604. }
  6605. return _this._renderTargets;
  6606. };
  6607. return _this;
  6608. }
  6609. LegacyPBRMaterial.prototype.getClassName = function () {
  6610. return "LegacyPBRMaterial";
  6611. };
  6612. Object.defineProperty(LegacyPBRMaterial.prototype, "useLogarithmicDepth", {
  6613. get: function () {
  6614. return this._useLogarithmicDepth;
  6615. },
  6616. set: function (value) {
  6617. this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;
  6618. },
  6619. enumerable: true,
  6620. configurable: true
  6621. });
  6622. LegacyPBRMaterial.prototype.needAlphaBlending = function () {
  6623. if (this.linkRefractionWithTransparency) {
  6624. return false;
  6625. }
  6626. return (this.alpha < 1.0) || (this.opacityTexture != null) || this._shouldUseAlphaFromAlbedoTexture() || this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled;
  6627. };
  6628. LegacyPBRMaterial.prototype.needAlphaTesting = function () {
  6629. if (this.linkRefractionWithTransparency) {
  6630. return false;
  6631. }
  6632. return this.albedoTexture != null && this.albedoTexture.hasAlpha;
  6633. };
  6634. LegacyPBRMaterial.prototype._shouldUseAlphaFromAlbedoTexture = function () {
  6635. return this.albedoTexture != null && this.albedoTexture.hasAlpha && this.useAlphaFromAlbedoTexture;
  6636. };
  6637. LegacyPBRMaterial.prototype.getAlphaTestTexture = function () {
  6638. return this.albedoTexture;
  6639. };
  6640. LegacyPBRMaterial.prototype._checkCache = function (scene, mesh, useInstances) {
  6641. if (!mesh) {
  6642. return true;
  6643. }
  6644. if (this._defines.INSTANCES !== useInstances) {
  6645. return false;
  6646. }
  6647. return false;
  6648. };
  6649. LegacyPBRMaterial.prototype.convertColorToLinearSpaceToRef = function (color, ref) {
  6650. LegacyPBRMaterial.convertColorToLinearSpaceToRef(color, ref, this.useScalarInLinearSpace);
  6651. };
  6652. LegacyPBRMaterial.convertColorToLinearSpaceToRef = function (color, ref, useScalarInLinear) {
  6653. if (!useScalarInLinear) {
  6654. color.toLinearSpaceToRef(ref);
  6655. }
  6656. else {
  6657. ref.r = color.r;
  6658. ref.g = color.g;
  6659. ref.b = color.b;
  6660. }
  6661. };
  6662. LegacyPBRMaterial.BindLights = function (scene, mesh, effect, defines, useScalarInLinearSpace, maxSimultaneousLights, usePhysicalLightFalloff) {
  6663. var lightIndex = 0;
  6664. for (var _i = 0, _a = mesh._lightSources; _i < _a.length; _i++) {
  6665. var light = _a[_i];
  6666. var useUbo = light._uniformBuffer.useUbo;
  6667. light._uniformBuffer.bindToEffect(effect, "Light" + lightIndex);
  6668. BABYLON.MaterialHelper.BindLightProperties(light, effect, lightIndex);
  6669. // GAMMA CORRECTION.
  6670. this.convertColorToLinearSpaceToRef(light.diffuse, LegacyPBRMaterial._scaledAlbedo, useScalarInLinearSpace);
  6671. LegacyPBRMaterial._scaledAlbedo.scaleToRef(light.intensity, LegacyPBRMaterial._scaledAlbedo);
  6672. light._uniformBuffer.updateColor4(useUbo ? "vLightDiffuse" : "vLightDiffuse" + lightIndex, LegacyPBRMaterial._scaledAlbedo, usePhysicalLightFalloff ? light.radius : light.range);
  6673. if (defines["SPECULARTERM"]) {
  6674. this.convertColorToLinearSpaceToRef(light.specular, LegacyPBRMaterial._scaledReflectivity, useScalarInLinearSpace);
  6675. LegacyPBRMaterial._scaledReflectivity.scaleToRef(light.intensity, LegacyPBRMaterial._scaledReflectivity);
  6676. light._uniformBuffer.updateColor3(useUbo ? "vLightSpecular" : "vLightSpecular" + lightIndex, LegacyPBRMaterial._scaledReflectivity);
  6677. }
  6678. // Shadows
  6679. if (scene.shadowsEnabled) {
  6680. BABYLON.MaterialHelper.BindLightShadow(light, scene, mesh, lightIndex + "", effect);
  6681. }
  6682. light._uniformBuffer.update();
  6683. lightIndex++;
  6684. if (lightIndex === maxSimultaneousLights)
  6685. break;
  6686. }
  6687. };
  6688. LegacyPBRMaterial.prototype.isReady = function (mesh, useInstances) {
  6689. var _this = this;
  6690. if (mesh === void 0) { mesh = null; }
  6691. if (this.isFrozen) {
  6692. if (this._wasPreviouslyReady) {
  6693. return true;
  6694. }
  6695. }
  6696. var scene = this.getScene();
  6697. var engine = scene.getEngine();
  6698. var needUVs = false;
  6699. this._defines.reset();
  6700. if (scene.lightsEnabled && !this.disableLighting && mesh) {
  6701. BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights);
  6702. }
  6703. if (!this.checkReadyOnEveryCall && mesh) {
  6704. if (this._renderId === scene.getRenderId()) {
  6705. if (this._checkCache(scene, mesh, useInstances)) {
  6706. return true;
  6707. }
  6708. }
  6709. }
  6710. if (scene.texturesEnabled) {
  6711. if (scene.getEngine().getCaps().textureLOD) {
  6712. this._defines.LODBASEDMICROSFURACE = true;
  6713. }
  6714. if (this.albedoTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  6715. if (!this.albedoTexture.isReady()) {
  6716. return false;
  6717. }
  6718. needUVs = true;
  6719. this._defines.ALBEDO = true;
  6720. }
  6721. if (this.ambientTexture && BABYLON.StandardMaterial.AmbientTextureEnabled) {
  6722. if (!this.ambientTexture.isReady()) {
  6723. return false;
  6724. }
  6725. needUVs = true;
  6726. this._defines.AMBIENT = true;
  6727. this._defines.AMBIENTINGRAYSCALE = this.useAmbientInGrayScale;
  6728. }
  6729. if (this.opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
  6730. if (!this.opacityTexture.isReady()) {
  6731. return false;
  6732. }
  6733. needUVs = true;
  6734. this._defines.OPACITY = true;
  6735. if (this.opacityTexture.getAlphaFromRGB) {
  6736. this._defines.OPACITYRGB = true;
  6737. }
  6738. }
  6739. if (this.reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  6740. if (!this.reflectionTexture.isReady()) {
  6741. return false;
  6742. }
  6743. this._defines.REFLECTION = true;
  6744. if (this.reflectionTexture.coordinatesMode === BABYLON.Texture.INVCUBIC_MODE) {
  6745. this._defines.INVERTCUBICMAP = true;
  6746. }
  6747. this._defines.REFLECTIONMAP_3D = this.reflectionTexture.isCube;
  6748. switch (this.reflectionTexture.coordinatesMode) {
  6749. case BABYLON.Texture.CUBIC_MODE:
  6750. case BABYLON.Texture.INVCUBIC_MODE:
  6751. this._defines.REFLECTIONMAP_CUBIC = true;
  6752. break;
  6753. case BABYLON.Texture.EXPLICIT_MODE:
  6754. this._defines.REFLECTIONMAP_EXPLICIT = true;
  6755. break;
  6756. case BABYLON.Texture.PLANAR_MODE:
  6757. this._defines.REFLECTIONMAP_PLANAR = true;
  6758. break;
  6759. case BABYLON.Texture.PROJECTION_MODE:
  6760. this._defines.REFLECTIONMAP_PROJECTION = true;
  6761. break;
  6762. case BABYLON.Texture.SKYBOX_MODE:
  6763. this._defines.REFLECTIONMAP_SKYBOX = true;
  6764. break;
  6765. case BABYLON.Texture.SPHERICAL_MODE:
  6766. this._defines.REFLECTIONMAP_SPHERICAL = true;
  6767. break;
  6768. case BABYLON.Texture.EQUIRECTANGULAR_MODE:
  6769. this._defines.REFLECTIONMAP_EQUIRECTANGULAR = true;
  6770. break;
  6771. case BABYLON.Texture.FIXED_EQUIRECTANGULAR_MODE:
  6772. this._defines.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = true;
  6773. break;
  6774. case BABYLON.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:
  6775. this._defines.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = true;
  6776. break;
  6777. }
  6778. if (this.reflectionTexture instanceof BABYLON.HDRCubeTexture && this.reflectionTexture) {
  6779. this._defines.USESPHERICALFROMREFLECTIONMAP = true;
  6780. if (this.reflectionTexture.isPMREM) {
  6781. this._defines.USEPMREMREFLECTION = true;
  6782. }
  6783. }
  6784. }
  6785. if (this.lightmapTexture && BABYLON.StandardMaterial.LightmapTextureEnabled) {
  6786. if (!this.lightmapTexture.isReady()) {
  6787. return false;
  6788. }
  6789. needUVs = true;
  6790. this._defines.LIGHTMAP = true;
  6791. this._defines.USELIGHTMAPASSHADOWMAP = this.useLightmapAsShadowmap;
  6792. }
  6793. if (this.emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
  6794. if (!this.emissiveTexture.isReady()) {
  6795. return false;
  6796. }
  6797. needUVs = true;
  6798. this._defines.EMISSIVE = true;
  6799. }
  6800. if (BABYLON.StandardMaterial.SpecularTextureEnabled) {
  6801. if (this.metallicTexture) {
  6802. if (!this.metallicTexture.isReady()) {
  6803. return false;
  6804. }
  6805. needUVs = true;
  6806. this._defines.METALLICWORKFLOW = true;
  6807. this._defines.METALLICMAP = true;
  6808. this._defines.ROUGHNESSSTOREINMETALMAPALPHA = this.useRoughnessFromMetallicTextureAlpha;
  6809. this._defines.ROUGHNESSSTOREINMETALMAPGREEN = !this.useRoughnessFromMetallicTextureAlpha && this.useRoughnessFromMetallicTextureGreen;
  6810. this._defines.METALLNESSSTOREINMETALMAPBLUE = this.useMetallnessFromMetallicTextureBlue;
  6811. this._defines.AOSTOREINMETALMAPRED = this.useAmbientOcclusionFromMetallicTextureRed;
  6812. }
  6813. else if (this.reflectivityTexture) {
  6814. if (!this.reflectivityTexture.isReady()) {
  6815. return false;
  6816. }
  6817. needUVs = true;
  6818. this._defines.REFLECTIVITY = true;
  6819. this._defines.MICROSURFACEFROMREFLECTIVITYMAP = this.useMicroSurfaceFromReflectivityMapAlpha;
  6820. this._defines.MICROSURFACEAUTOMATIC = this.useAutoMicroSurfaceFromReflectivityMap;
  6821. }
  6822. if (this.microSurfaceTexture) {
  6823. if (!this.microSurfaceTexture.isReady()) {
  6824. return false;
  6825. }
  6826. needUVs = true;
  6827. this._defines.MICROSURFACEMAP = true;
  6828. }
  6829. }
  6830. if (scene.getEngine().getCaps().standardDerivatives && this.bumpTexture && BABYLON.StandardMaterial.BumpTextureEnabled && !this.disableBumpMap) {
  6831. if (!this.bumpTexture.isReady()) {
  6832. return false;
  6833. }
  6834. needUVs = true;
  6835. this._defines.BUMP = true;
  6836. if (this.useParallax && this.albedoTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  6837. this._defines.PARALLAX = true;
  6838. if (this.useParallaxOcclusion) {
  6839. this._defines.PARALLAXOCCLUSION = true;
  6840. }
  6841. }
  6842. }
  6843. if (this.refractionTexture && BABYLON.StandardMaterial.RefractionTextureEnabled) {
  6844. if (!this.refractionTexture.isReady()) {
  6845. return false;
  6846. }
  6847. needUVs = true;
  6848. this._defines.REFRACTION = true;
  6849. this._defines.REFRACTIONMAP_3D = this.refractionTexture.isCube;
  6850. if (this.linkRefractionWithTransparency) {
  6851. this._defines.LINKREFRACTIONTOTRANSPARENCY = true;
  6852. }
  6853. if (this.refractionTexture instanceof BABYLON.HDRCubeTexture) {
  6854. this._defines.REFRACTIONMAPINLINEARSPACE = true;
  6855. if (this.refractionTexture.isPMREM) {
  6856. this._defines.USEPMREMREFRACTION = true;
  6857. }
  6858. }
  6859. }
  6860. if (this.cameraColorGradingTexture && BABYLON.StandardMaterial.ColorGradingTextureEnabled) {
  6861. if (!this.cameraColorGradingTexture.isReady()) {
  6862. return false;
  6863. }
  6864. this._defines.CAMERACOLORGRADING = true;
  6865. }
  6866. if (!this.backFaceCulling && this.twoSidedLighting) {
  6867. this._defines.TWOSIDEDLIGHTING = true;
  6868. }
  6869. }
  6870. // Effect
  6871. if (scene.clipPlane) {
  6872. this._defines.CLIPPLANE = true;
  6873. }
  6874. if (engine.getAlphaTesting()) {
  6875. this._defines.ALPHATEST = true;
  6876. }
  6877. if (this._shouldUseAlphaFromAlbedoTexture()) {
  6878. this._defines.ALPHAFROMALBEDO = true;
  6879. }
  6880. if (this.useEmissiveAsIllumination) {
  6881. this._defines.EMISSIVEASILLUMINATION = true;
  6882. }
  6883. if (this.linkEmissiveWithAlbedo) {
  6884. this._defines.LINKEMISSIVEWITHALBEDO = true;
  6885. }
  6886. if (this.useLogarithmicDepth) {
  6887. this._defines.LOGARITHMICDEPTH = true;
  6888. }
  6889. if (this.cameraContrast != 1) {
  6890. this._defines.CAMERACONTRAST = true;
  6891. }
  6892. if (this.cameraExposure != 1) {
  6893. this._defines.CAMERATONEMAP = true;
  6894. }
  6895. if (this.cameraColorCurves) {
  6896. this._defines.CAMERACOLORCURVES = true;
  6897. }
  6898. if (this.overloadedShadeIntensity != 1 ||
  6899. this.overloadedShadowIntensity != 1) {
  6900. this._defines.OVERLOADEDSHADOWVALUES = true;
  6901. }
  6902. if (this.overloadedMicroSurfaceIntensity > 0 ||
  6903. this.overloadedEmissiveIntensity > 0 ||
  6904. this.overloadedReflectivityIntensity > 0 ||
  6905. this.overloadedAlbedoIntensity > 0 ||
  6906. this.overloadedAmbientIntensity > 0 ||
  6907. this.overloadedReflectionIntensity > 0) {
  6908. this._defines.OVERLOADEDVALUES = true;
  6909. }
  6910. // Point size
  6911. if (this.pointsCloud || scene.forcePointsCloud) {
  6912. this._defines.POINTSIZE = true;
  6913. }
  6914. // Fog
  6915. if (scene.fogEnabled && mesh && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled) {
  6916. this._defines.FOG = true;
  6917. }
  6918. if (BABYLON.StandardMaterial.FresnelEnabled) {
  6919. // Fresnel
  6920. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled ||
  6921. this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  6922. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {
  6923. this._defines.OPACITYFRESNEL = true;
  6924. }
  6925. if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  6926. this._defines.EMISSIVEFRESNEL = true;
  6927. }
  6928. this._defines.FRESNEL = true;
  6929. }
  6930. }
  6931. if (this._defines.SPECULARTERM && this.useSpecularOverAlpha) {
  6932. this._defines.SPECULAROVERALPHA = true;
  6933. }
  6934. if (this.usePhysicalLightFalloff) {
  6935. this._defines.USEPHYSICALLIGHTFALLOFF = true;
  6936. }
  6937. if (this.useRadianceOverAlpha) {
  6938. this._defines.RADIANCEOVERALPHA = true;
  6939. }
  6940. if ((this.metallic !== undefined && this.metallic !== null) || (this.roughness !== undefined && this.roughness !== null)) {
  6941. this._defines.METALLICWORKFLOW = true;
  6942. }
  6943. // Attribs
  6944. if (mesh) {
  6945. if (!scene.getEngine().getCaps().standardDerivatives && !mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  6946. mesh.createNormals(true);
  6947. BABYLON.Tools.Warn("PBRMaterial: Normals have been created for the mesh: " + mesh.name);
  6948. }
  6949. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  6950. this._defines.NORMAL = true;
  6951. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.TangentKind)) {
  6952. this._defines.TANGENT = true;
  6953. }
  6954. }
  6955. if (needUVs) {
  6956. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  6957. this._defines.UV1 = true;
  6958. }
  6959. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
  6960. this._defines.UV2 = true;
  6961. }
  6962. }
  6963. if (mesh.useVertexColors && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
  6964. this._defines.VERTEXCOLOR = true;
  6965. if (mesh.hasVertexAlpha) {
  6966. this._defines.VERTEXALPHA = true;
  6967. }
  6968. }
  6969. if (mesh.useBones && mesh.computeBonesUsingShaders) {
  6970. this._defines.NUM_BONE_INFLUENCERS = mesh.numBoneInfluencers;
  6971. this._defines.BonesPerMesh = (mesh.skeleton ? mesh.skeleton.bones.length + 1 : 0);
  6972. }
  6973. // Instances
  6974. if (useInstances) {
  6975. this._defines.INSTANCES = true;
  6976. }
  6977. var manager = mesh.morphTargetManager;
  6978. if (manager) {
  6979. this._defines.MORPHTARGETS_TANGENT = manager.supportsTangents && this._defines.TANGENT;
  6980. this._defines.MORPHTARGETS_NORMAL = manager.supportsNormals && this._defines.NORMAL;
  6981. this._defines.MORPHTARGETS = (manager.numInfluencers > 0);
  6982. this._defines.NUM_MORPH_INFLUENCERS = manager.numInfluencers;
  6983. }
  6984. }
  6985. // Get correct effect
  6986. if (!this._defines.isEqual(this._cachedDefines)) {
  6987. this._defines.cloneTo(this._cachedDefines);
  6988. scene.resetCachedMaterial();
  6989. // Fallbacks
  6990. var fallbacks = new BABYLON.EffectFallbacks();
  6991. if (this._defines.REFLECTION) {
  6992. fallbacks.addFallback(0, "REFLECTION");
  6993. }
  6994. if (this._defines.REFRACTION) {
  6995. fallbacks.addFallback(0, "REFRACTION");
  6996. }
  6997. if (this._defines.REFLECTIVITY) {
  6998. fallbacks.addFallback(0, "REFLECTIVITY");
  6999. }
  7000. if (this._defines.BUMP) {
  7001. fallbacks.addFallback(0, "BUMP");
  7002. }
  7003. if (this._defines.PARALLAX) {
  7004. fallbacks.addFallback(1, "PARALLAX");
  7005. }
  7006. if (this._defines.PARALLAXOCCLUSION) {
  7007. fallbacks.addFallback(0, "PARALLAXOCCLUSION");
  7008. }
  7009. if (this._defines.SPECULAROVERALPHA) {
  7010. fallbacks.addFallback(0, "SPECULAROVERALPHA");
  7011. }
  7012. if (this._defines.FOG) {
  7013. fallbacks.addFallback(1, "FOG");
  7014. }
  7015. if (this._defines.POINTSIZE) {
  7016. fallbacks.addFallback(0, "POINTSIZE");
  7017. }
  7018. if (this._defines.LOGARITHMICDEPTH) {
  7019. fallbacks.addFallback(0, "LOGARITHMICDEPTH");
  7020. }
  7021. BABYLON.MaterialHelper.HandleFallbacksForShadows(this._defines, fallbacks, this.maxSimultaneousLights);
  7022. if (this._defines.SPECULARTERM) {
  7023. fallbacks.addFallback(0, "SPECULARTERM");
  7024. }
  7025. if (this._defines.OPACITYFRESNEL) {
  7026. fallbacks.addFallback(1, "OPACITYFRESNEL");
  7027. }
  7028. if (this._defines.EMISSIVEFRESNEL) {
  7029. fallbacks.addFallback(2, "EMISSIVEFRESNEL");
  7030. }
  7031. if (this._defines.FRESNEL) {
  7032. fallbacks.addFallback(3, "FRESNEL");
  7033. }
  7034. if (this._defines.NUM_BONE_INFLUENCERS > 0) {
  7035. fallbacks.addCPUSkinningFallback(0, mesh);
  7036. }
  7037. //Attributes
  7038. var attribs = [BABYLON.VertexBuffer.PositionKind];
  7039. if (this._defines.NORMAL) {
  7040. attribs.push(BABYLON.VertexBuffer.NormalKind);
  7041. }
  7042. if (this._defines.TANGENT) {
  7043. attribs.push(BABYLON.VertexBuffer.TangentKind);
  7044. }
  7045. if (this._defines.UV1) {
  7046. attribs.push(BABYLON.VertexBuffer.UVKind);
  7047. }
  7048. if (this._defines.UV2) {
  7049. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  7050. }
  7051. if (this._defines.VERTEXCOLOR) {
  7052. attribs.push(BABYLON.VertexBuffer.ColorKind);
  7053. }
  7054. if (mesh) {
  7055. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
  7056. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
  7057. BABYLON.MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, this._defines);
  7058. }
  7059. // Legacy browser patch
  7060. var join = this._defines.toString();
  7061. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vAlbedoColor", "vReflectivityColor", "vEmissiveColor", "vReflectionColor",
  7062. "vFogInfos", "vFogColor", "pointSize",
  7063. "vAlbedoInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vEmissiveInfos", "vReflectivityInfos", "vMicroSurfaceSamplerInfos", "vBumpInfos", "vLightmapInfos", "vRefractionInfos",
  7064. "mBones",
  7065. "vClipPlane", "albedoMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "reflectivityMatrix", "microSurfaceSamplerMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
  7066. "opacityParts", "emissiveLeftColor", "emissiveRightColor",
  7067. "vLightingIntensity", "vOverloadedShadowIntensity", "vOverloadedIntensity", "vOverloadedAlbedo", "vOverloadedReflection", "vOverloadedReflectivity", "vOverloadedEmissive", "vOverloadedMicroSurface",
  7068. "logarithmicDepthConstant",
  7069. "vSphericalX", "vSphericalY", "vSphericalZ",
  7070. "vSphericalXX", "vSphericalYY", "vSphericalZZ",
  7071. "vSphericalXY", "vSphericalYZ", "vSphericalZX",
  7072. "vMicrosurfaceTextureLods",
  7073. "vCameraInfos", "vTangentSpaceParams"
  7074. ];
  7075. var samplers = ["albedoSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "reflectivitySampler", "microSurfaceSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"];
  7076. var uniformBuffers = ["Material", "Scene"];
  7077. if (this._defines.CAMERACOLORCURVES) {
  7078. BABYLON.ColorCurves.PrepareUniforms(uniforms);
  7079. }
  7080. if (this._defines.CAMERACOLORGRADING) {
  7081. uniforms.push("vCameraColorGradingInfos", "vCameraColorGradingScaleOffset");
  7082. samplers.push("cameraColorGrading2DSampler");
  7083. }
  7084. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  7085. uniformsNames: uniforms,
  7086. uniformBuffersNames: uniformBuffers,
  7087. samplers: samplers,
  7088. defines: this._defines,
  7089. maxSimultaneousLights: this.maxSimultaneousLights
  7090. });
  7091. var onCompiled = function (effect) {
  7092. if (_this.onCompiled) {
  7093. _this.onCompiled(effect);
  7094. }
  7095. _this.bindSceneUniformBuffer(effect, scene.getSceneUniformBuffer());
  7096. };
  7097. this._effect = scene.getEngine().createEffect("legacyPbr", {
  7098. attributes: attribs,
  7099. uniformsNames: uniforms,
  7100. uniformBuffersNames: uniformBuffers,
  7101. samplers: samplers,
  7102. defines: join,
  7103. fallbacks: fallbacks,
  7104. onCompiled: onCompiled,
  7105. onError: this.onError,
  7106. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights, maxSimultaneousMorphTargets: this._defines.NUM_MORPH_INFLUENCERS }
  7107. }, engine);
  7108. this.buildUniformLayout();
  7109. }
  7110. if (!this._effect || !this._effect.isReady()) {
  7111. return false;
  7112. }
  7113. this._renderId = scene.getRenderId();
  7114. this._wasPreviouslyReady = true;
  7115. return true;
  7116. };
  7117. LegacyPBRMaterial.prototype.buildUniformLayout = function () {
  7118. // Order is important !
  7119. this._uniformBuffer.addUniform("vAlbedoInfos", 2);
  7120. this._uniformBuffer.addUniform("vAmbientInfos", 3);
  7121. this._uniformBuffer.addUniform("vOpacityInfos", 2);
  7122. this._uniformBuffer.addUniform("vEmissiveInfos", 2);
  7123. this._uniformBuffer.addUniform("vLightmapInfos", 2);
  7124. this._uniformBuffer.addUniform("vReflectivityInfos", 3);
  7125. this._uniformBuffer.addUniform("vMicroSurfaceSamplerInfos", 2);
  7126. this._uniformBuffer.addUniform("vRefractionInfos", 4);
  7127. this._uniformBuffer.addUniform("vReflectionInfos", 2);
  7128. this._uniformBuffer.addUniform("vBumpInfos", 3);
  7129. this._uniformBuffer.addUniform("albedoMatrix", 16);
  7130. this._uniformBuffer.addUniform("ambientMatrix", 16);
  7131. this._uniformBuffer.addUniform("opacityMatrix", 16);
  7132. this._uniformBuffer.addUniform("emissiveMatrix", 16);
  7133. this._uniformBuffer.addUniform("lightmapMatrix", 16);
  7134. this._uniformBuffer.addUniform("reflectivityMatrix", 16);
  7135. this._uniformBuffer.addUniform("microSurfaceSamplerMatrix", 16);
  7136. this._uniformBuffer.addUniform("bumpMatrix", 16);
  7137. this._uniformBuffer.addUniform("vTangentSpaceParams", 2);
  7138. this._uniformBuffer.addUniform("refractionMatrix", 16);
  7139. this._uniformBuffer.addUniform("reflectionMatrix", 16);
  7140. this._uniformBuffer.addUniform("vReflectionColor", 3);
  7141. this._uniformBuffer.addUniform("vAlbedoColor", 4);
  7142. this._uniformBuffer.addUniform("vLightingIntensity", 4);
  7143. this._uniformBuffer.addUniform("vMicrosurfaceTextureLods", 2);
  7144. this._uniformBuffer.addUniform("vReflectivityColor", 4);
  7145. this._uniformBuffer.addUniform("vEmissiveColor", 3);
  7146. this._uniformBuffer.addUniform("opacityParts", 4);
  7147. this._uniformBuffer.addUniform("emissiveLeftColor", 4);
  7148. this._uniformBuffer.addUniform("emissiveRightColor", 4);
  7149. this._uniformBuffer.addUniform("vOverloadedIntensity", 4);
  7150. this._uniformBuffer.addUniform("vOverloadedAmbient", 3);
  7151. this._uniformBuffer.addUniform("vOverloadedAlbedo", 3);
  7152. this._uniformBuffer.addUniform("vOverloadedReflectivity", 3);
  7153. this._uniformBuffer.addUniform("vOverloadedEmissive", 3);
  7154. this._uniformBuffer.addUniform("vOverloadedReflection", 3);
  7155. this._uniformBuffer.addUniform("vOverloadedMicroSurface", 3);
  7156. this._uniformBuffer.addUniform("vOverloadedShadowIntensity", 4);
  7157. this._uniformBuffer.addUniform("pointSize", 1);
  7158. this._uniformBuffer.create();
  7159. };
  7160. LegacyPBRMaterial.prototype.unbind = function () {
  7161. if (this.reflectionTexture && this.reflectionTexture.isRenderTarget) {
  7162. this._uniformBuffer.setTexture("reflection2DSampler", null);
  7163. }
  7164. if (this.refractionTexture && this.refractionTexture.isRenderTarget) {
  7165. this._uniformBuffer.setTexture("refraction2DSampler", null);
  7166. }
  7167. _super.prototype.unbind.call(this);
  7168. };
  7169. LegacyPBRMaterial.prototype.bindOnlyWorldMatrix = function (world) {
  7170. if (this._effect) {
  7171. this._effect.setMatrix("world", world);
  7172. }
  7173. };
  7174. LegacyPBRMaterial.prototype.bind = function (world, mesh) {
  7175. this._myScene = this.getScene();
  7176. var effect = this._effect;
  7177. if (!effect) {
  7178. return;
  7179. }
  7180. // Matrices
  7181. this.bindOnlyWorldMatrix(world);
  7182. // Bones
  7183. BABYLON.MaterialHelper.BindBonesParameters(mesh, effect);
  7184. if (this._myScene.getCachedMaterial() !== this) {
  7185. this._uniformBuffer.bindToEffect(effect, "Material");
  7186. this.bindViewProjection(effect);
  7187. if (!this._uniformBuffer.useUbo || !this.isFrozen || !this._uniformBuffer.isSync) {
  7188. // Fresnel
  7189. if (BABYLON.StandardMaterial.FresnelEnabled) {
  7190. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {
  7191. this._uniformBuffer.updateColor4("opacityParts", new BABYLON.Color3(this.opacityFresnelParameters.leftColor.toLuminance(), this.opacityFresnelParameters.rightColor.toLuminance(), this.opacityFresnelParameters.bias), this.opacityFresnelParameters.power);
  7192. }
  7193. if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  7194. this._uniformBuffer.updateColor4("emissiveLeftColor", this.emissiveFresnelParameters.leftColor, this.emissiveFresnelParameters.power);
  7195. this._uniformBuffer.updateColor4("emissiveRightColor", this.emissiveFresnelParameters.rightColor, this.emissiveFresnelParameters.bias);
  7196. }
  7197. }
  7198. // Texture uniforms
  7199. if (this._myScene.texturesEnabled) {
  7200. if (this.albedoTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  7201. this._uniformBuffer.updateFloat2("vAlbedoInfos", this.albedoTexture.coordinatesIndex, this.albedoTexture.level);
  7202. this._uniformBuffer.updateMatrix("albedoMatrix", this.albedoTexture.getTextureMatrix());
  7203. }
  7204. if (this.ambientTexture && BABYLON.StandardMaterial.AmbientTextureEnabled) {
  7205. this._uniformBuffer.updateFloat3("vAmbientInfos", this.ambientTexture.coordinatesIndex, this.ambientTexture.level, this.ambientTextureStrength);
  7206. this._uniformBuffer.updateMatrix("ambientMatrix", this.ambientTexture.getTextureMatrix());
  7207. }
  7208. if (this.opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
  7209. this._uniformBuffer.updateFloat2("vOpacityInfos", this.opacityTexture.coordinatesIndex, this.opacityTexture.level);
  7210. this._uniformBuffer.updateMatrix("opacityMatrix", this.opacityTexture.getTextureMatrix());
  7211. }
  7212. if (this.reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  7213. this._microsurfaceTextureLods.x = Math.round(Math.log(this.reflectionTexture.getSize().width) * Math.LOG2E);
  7214. this._uniformBuffer.updateMatrix("reflectionMatrix", this.reflectionTexture.getReflectionTextureMatrix());
  7215. this._uniformBuffer.updateFloat2("vReflectionInfos", this.reflectionTexture.level, 0);
  7216. if (this._defines.USESPHERICALFROMREFLECTIONMAP) {
  7217. var polynomials = this.reflectionTexture.sphericalPolynomial;
  7218. if (polynomials) {
  7219. effect.setFloat3("vSphericalX", polynomials.x.x, polynomials.x.y, polynomials.x.z);
  7220. effect.setFloat3("vSphericalY", polynomials.y.x, polynomials.y.y, polynomials.y.z);
  7221. effect.setFloat3("vSphericalZ", polynomials.z.x, polynomials.z.y, polynomials.z.z);
  7222. effect.setFloat3("vSphericalXX_ZZ", polynomials.xx.x - polynomials.zz.x, polynomials.xx.y - polynomials.zz.y, polynomials.xx.z - polynomials.zz.z);
  7223. effect.setFloat3("vSphericalYY_ZZ", polynomials.yy.x - polynomials.zz.x, polynomials.yy.y - polynomials.zz.y, polynomials.yy.z - polynomials.zz.z);
  7224. effect.setFloat3("vSphericalZZ", polynomials.zz.x, polynomials.zz.y, polynomials.zz.z);
  7225. effect.setFloat3("vSphericalXY", polynomials.xy.x, polynomials.xy.y, polynomials.xy.z);
  7226. effect.setFloat3("vSphericalYZ", polynomials.yz.x, polynomials.yz.y, polynomials.yz.z);
  7227. effect.setFloat3("vSphericalZX", polynomials.zx.x, polynomials.zx.y, polynomials.zx.z);
  7228. }
  7229. }
  7230. }
  7231. if (this.emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
  7232. this._uniformBuffer.updateFloat2("vEmissiveInfos", this.emissiveTexture.coordinatesIndex, this.emissiveTexture.level);
  7233. this._uniformBuffer.updateMatrix("emissiveMatrix", this.emissiveTexture.getTextureMatrix());
  7234. }
  7235. if (this.lightmapTexture && BABYLON.StandardMaterial.LightmapTextureEnabled) {
  7236. this._uniformBuffer.updateFloat2("vLightmapInfos", this.lightmapTexture.coordinatesIndex, this.lightmapTexture.level);
  7237. this._uniformBuffer.updateMatrix("lightmapMatrix", this.lightmapTexture.getTextureMatrix());
  7238. }
  7239. if (BABYLON.StandardMaterial.SpecularTextureEnabled) {
  7240. if (this.metallicTexture) {
  7241. this._uniformBuffer.updateFloat3("vReflectivityInfos", this.metallicTexture.coordinatesIndex, this.metallicTexture.level, this.ambientTextureStrength);
  7242. this._uniformBuffer.updateMatrix("reflectivityMatrix", this.metallicTexture.getTextureMatrix());
  7243. }
  7244. else if (this.reflectivityTexture) {
  7245. this._uniformBuffer.updateFloat3("vReflectivityInfos", this.reflectivityTexture.coordinatesIndex, this.reflectivityTexture.level, 1.0);
  7246. this._uniformBuffer.updateMatrix("reflectivityMatrix", this.reflectivityTexture.getTextureMatrix());
  7247. }
  7248. if (this.microSurfaceTexture) {
  7249. this._uniformBuffer.updateFloat2("vMicroSurfaceSamplerInfos", this.microSurfaceTexture.coordinatesIndex, this.microSurfaceTexture.level);
  7250. this._uniformBuffer.updateMatrix("microSurfaceSamplerMatrix", this.microSurfaceTexture.getTextureMatrix());
  7251. }
  7252. }
  7253. if (this.bumpTexture && this._myScene.getEngine().getCaps().standardDerivatives && BABYLON.StandardMaterial.BumpTextureEnabled && !this.disableBumpMap) {
  7254. this._uniformBuffer.updateFloat3("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level, this.parallaxScaleBias);
  7255. this._uniformBuffer.updateMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
  7256. if (this._myScene._mirroredCameraPosition) {
  7257. this._uniformBuffer.updateFloat2("vTangentSpaceParams", this.invertNormalMapX ? 1.0 : -1.0, this.invertNormalMapY ? 1.0 : -1.0);
  7258. }
  7259. else {
  7260. this._uniformBuffer.updateFloat2("vTangentSpaceParams", this.invertNormalMapX ? -1.0 : 1.0, this.invertNormalMapY ? -1.0 : 1.0);
  7261. }
  7262. }
  7263. if (this.refractionTexture && BABYLON.StandardMaterial.RefractionTextureEnabled) {
  7264. this._microsurfaceTextureLods.y = Math.round(Math.log(this.refractionTexture.getSize().width) * Math.LOG2E);
  7265. var depth = 1.0;
  7266. if (!this.refractionTexture.isCube) {
  7267. this._uniformBuffer.updateMatrix("refractionMatrix", this.refractionTexture.getReflectionTextureMatrix());
  7268. if (this.refractionTexture.depth) {
  7269. depth = this.refractionTexture.depth;
  7270. }
  7271. }
  7272. this._uniformBuffer.updateFloat4("vRefractionInfos", this.refractionTexture.level, this.indexOfRefraction, depth, this.invertRefractionY ? -1 : 1);
  7273. }
  7274. if ((this.reflectionTexture || this.refractionTexture)) {
  7275. this._uniformBuffer.updateFloat2("vMicrosurfaceTextureLods", this._microsurfaceTextureLods.x, this._microsurfaceTextureLods.y);
  7276. }
  7277. }
  7278. // Point size
  7279. if (this.pointsCloud) {
  7280. this._uniformBuffer.updateFloat("pointSize", this.pointSize);
  7281. }
  7282. // Colors
  7283. if (this._defines.METALLICWORKFLOW) {
  7284. LegacyPBRMaterial._scaledReflectivity.r = (this.metallic === undefined || this.metallic === null) ? 1 : this.metallic;
  7285. LegacyPBRMaterial._scaledReflectivity.g = (this.roughness === undefined || this.roughness === null) ? 1 : this.roughness;
  7286. this._uniformBuffer.updateColor4("vReflectivityColor", LegacyPBRMaterial._scaledReflectivity, 0);
  7287. }
  7288. else {
  7289. // GAMMA CORRECTION.
  7290. this.convertColorToLinearSpaceToRef(this.reflectivityColor, LegacyPBRMaterial._scaledReflectivity);
  7291. this._uniformBuffer.updateColor4("vReflectivityColor", LegacyPBRMaterial._scaledReflectivity, this.microSurface);
  7292. }
  7293. // GAMMA CORRECTION.
  7294. this.convertColorToLinearSpaceToRef(this.emissiveColor, LegacyPBRMaterial._scaledEmissive);
  7295. this._uniformBuffer.updateColor3("vEmissiveColor", LegacyPBRMaterial._scaledEmissive);
  7296. // GAMMA CORRECTION.
  7297. this.convertColorToLinearSpaceToRef(this.reflectionColor, LegacyPBRMaterial._scaledReflection);
  7298. this._uniformBuffer.updateColor3("vReflectionColor", LegacyPBRMaterial._scaledReflection);
  7299. // GAMMA CORRECTION.
  7300. this.convertColorToLinearSpaceToRef(this.albedoColor, LegacyPBRMaterial._scaledAlbedo);
  7301. if (mesh) {
  7302. this._uniformBuffer.updateColor4("vAlbedoColor", LegacyPBRMaterial._scaledAlbedo, this.alpha * mesh.visibility);
  7303. }
  7304. // Misc
  7305. this._lightingInfos.x = this.directIntensity;
  7306. this._lightingInfos.y = this.emissiveIntensity;
  7307. this._lightingInfos.z = this.environmentIntensity;
  7308. this._lightingInfos.w = this.specularIntensity;
  7309. this._uniformBuffer.updateVector4("vLightingIntensity", this._lightingInfos);
  7310. // Overloaded params
  7311. this._overloadedShadowInfos.x = this.overloadedShadowIntensity;
  7312. this._overloadedShadowInfos.y = this.overloadedShadeIntensity;
  7313. this._uniformBuffer.updateVector4("vOverloadedShadowIntensity", this._overloadedShadowInfos);
  7314. this._overloadedIntensity.x = this.overloadedAmbientIntensity;
  7315. this._overloadedIntensity.y = this.overloadedAlbedoIntensity;
  7316. this._overloadedIntensity.z = this.overloadedReflectivityIntensity;
  7317. this._overloadedIntensity.w = this.overloadedEmissiveIntensity;
  7318. this._uniformBuffer.updateVector4("vOverloadedIntensity", this._overloadedIntensity);
  7319. this._uniformBuffer.updateColor3("vOverloadedAmbient", this.overloadedAmbient);
  7320. this.convertColorToLinearSpaceToRef(this.overloadedAlbedo, this._tempColor);
  7321. this._uniformBuffer.updateColor3("vOverloadedAlbedo", this._tempColor);
  7322. this.convertColorToLinearSpaceToRef(this.overloadedReflectivity, this._tempColor);
  7323. this._uniformBuffer.updateColor3("vOverloadedReflectivity", this._tempColor);
  7324. this.convertColorToLinearSpaceToRef(this.overloadedEmissive, this._tempColor);
  7325. this._uniformBuffer.updateColor3("vOverloadedEmissive", this._tempColor);
  7326. this.convertColorToLinearSpaceToRef(this.overloadedReflection, this._tempColor);
  7327. this._uniformBuffer.updateColor3("vOverloadedReflection", this._tempColor);
  7328. this._overloadedMicroSurface.x = this.overloadedMicroSurface;
  7329. this._overloadedMicroSurface.y = this.overloadedMicroSurfaceIntensity;
  7330. this._overloadedMicroSurface.z = this.overloadedReflectionIntensity;
  7331. this._uniformBuffer.updateVector3("vOverloadedMicroSurface", this._overloadedMicroSurface);
  7332. }
  7333. // Textures
  7334. if (this._myScene.texturesEnabled) {
  7335. if (this.albedoTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  7336. this._uniformBuffer.setTexture("albedoSampler", this.albedoTexture);
  7337. }
  7338. if (this.ambientTexture && BABYLON.StandardMaterial.AmbientTextureEnabled) {
  7339. this._uniformBuffer.setTexture("ambientSampler", this.ambientTexture);
  7340. }
  7341. if (this.opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
  7342. this._uniformBuffer.setTexture("opacitySampler", this.opacityTexture);
  7343. }
  7344. if (this.reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  7345. if (this.reflectionTexture.isCube) {
  7346. this._uniformBuffer.setTexture("reflectionCubeSampler", this.reflectionTexture);
  7347. }
  7348. else {
  7349. this._uniformBuffer.setTexture("reflection2DSampler", this.reflectionTexture);
  7350. }
  7351. }
  7352. if (this.emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
  7353. this._uniformBuffer.setTexture("emissiveSampler", this.emissiveTexture);
  7354. }
  7355. if (this.lightmapTexture && BABYLON.StandardMaterial.LightmapTextureEnabled) {
  7356. this._uniformBuffer.setTexture("lightmapSampler", this.lightmapTexture);
  7357. }
  7358. if (BABYLON.StandardMaterial.SpecularTextureEnabled) {
  7359. if (this.metallicTexture) {
  7360. this._uniformBuffer.setTexture("reflectivitySampler", this.metallicTexture);
  7361. }
  7362. else if (this.reflectivityTexture) {
  7363. this._uniformBuffer.setTexture("reflectivitySampler", this.reflectivityTexture);
  7364. }
  7365. if (this.microSurfaceTexture) {
  7366. this._uniformBuffer.setTexture("microSurfaceSampler", this.microSurfaceTexture);
  7367. }
  7368. }
  7369. if (this.bumpTexture && this._myScene.getEngine().getCaps().standardDerivatives && BABYLON.StandardMaterial.BumpTextureEnabled && !this.disableBumpMap) {
  7370. this._uniformBuffer.setTexture("bumpSampler", this.bumpTexture);
  7371. }
  7372. if (this.refractionTexture && BABYLON.StandardMaterial.RefractionTextureEnabled) {
  7373. if (this.refractionTexture.isCube) {
  7374. this._uniformBuffer.setTexture("refractionCubeSampler", this.refractionTexture);
  7375. }
  7376. else {
  7377. this._uniformBuffer.setTexture("refraction2DSampler", this.refractionTexture);
  7378. }
  7379. }
  7380. if (this.cameraColorGradingTexture && BABYLON.StandardMaterial.ColorGradingTextureEnabled) {
  7381. effect.setTexture("cameraColorGrading2DSampler", this.cameraColorGradingTexture);
  7382. var x = this.cameraColorGradingTexture.level; // Texture Level
  7383. var y = this.cameraColorGradingTexture.getSize().height; // Texture Size example with 8
  7384. var z = y - 1.0; // SizeMinusOne 8 - 1
  7385. var w = 1 / y; // Space of 1 slice 1 / 8
  7386. effect.setFloat4("vCameraColorGradingInfos", x, y, z, w);
  7387. var slicePixelSizeU = w / y; // Space of 1 pixel in U direction, e.g. 1/64
  7388. var slicePixelSizeV = w; // Space of 1 pixel in V direction, e.g. 1/8 // Space of 1 pixel in V direction, e.g. 1/8
  7389. var x2 = z * slicePixelSizeU; // Extent of lookup range in U for a single slice so that range corresponds to (size-1) texels, for example 7/64
  7390. var y2 = z / y; // Extent of lookup range in V for a single slice so that range corresponds to (size-1) texels, for example 7/8
  7391. var z2 = 0.5 * slicePixelSizeU; // Offset of lookup range in U to align sample position with texel centre, for example 0.5/64
  7392. var w2 = 0.5 * slicePixelSizeV; // Offset of lookup range in V to align sample position with texel centre, for example 0.5/8
  7393. effect.setFloat4("vCameraColorGradingScaleOffset", x2, y2, z2, w2);
  7394. }
  7395. }
  7396. // Clip plane
  7397. BABYLON.MaterialHelper.BindClipPlane(effect, this._myScene);
  7398. // Colors
  7399. this._myScene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
  7400. effect.setVector3("vEyePosition", this._myScene._mirroredCameraPosition ? this._myScene._mirroredCameraPosition : this._myScene.activeCamera.position);
  7401. effect.setColor3("vAmbientColor", this._globalAmbientColor);
  7402. }
  7403. if (mesh && (this._myScene.getCachedMaterial() !== this || !this.isFrozen)) {
  7404. // Lights
  7405. if (this._myScene.lightsEnabled && !this.disableLighting) {
  7406. LegacyPBRMaterial.BindLights(this._myScene, mesh, effect, this._defines, this.useScalarInLinearSpace, this.maxSimultaneousLights, this.usePhysicalLightFalloff);
  7407. }
  7408. // View
  7409. if (this._myScene.fogEnabled && mesh.applyFog && this._myScene.fogMode !== BABYLON.Scene.FOGMODE_NONE || this.reflectionTexture) {
  7410. this.bindView(effect);
  7411. }
  7412. // Fog
  7413. BABYLON.MaterialHelper.BindFogParameters(this._myScene, mesh, effect);
  7414. // Morph targets
  7415. if (this._defines.NUM_MORPH_INFLUENCERS) {
  7416. BABYLON.MaterialHelper.BindMorphTargetParameters(mesh, effect);
  7417. }
  7418. this._cameraInfos.x = this.cameraExposure;
  7419. this._cameraInfos.y = this.cameraContrast;
  7420. effect.setVector4("vCameraInfos", this._cameraInfos);
  7421. if (this.cameraColorCurves) {
  7422. BABYLON.ColorCurves.Bind(this.cameraColorCurves, effect);
  7423. }
  7424. // Log. depth
  7425. BABYLON.MaterialHelper.BindLogDepth(this._defines, effect, this._myScene);
  7426. }
  7427. this._uniformBuffer.update();
  7428. this._afterBind(mesh);
  7429. this._myScene = null;
  7430. };
  7431. LegacyPBRMaterial.prototype.getAnimatables = function () {
  7432. var results = [];
  7433. if (this.albedoTexture && this.albedoTexture.animations && this.albedoTexture.animations.length > 0) {
  7434. results.push(this.albedoTexture);
  7435. }
  7436. if (this.ambientTexture && this.ambientTexture.animations && this.ambientTexture.animations.length > 0) {
  7437. results.push(this.ambientTexture);
  7438. }
  7439. if (this.opacityTexture && this.opacityTexture.animations && this.opacityTexture.animations.length > 0) {
  7440. results.push(this.opacityTexture);
  7441. }
  7442. if (this.reflectionTexture && this.reflectionTexture.animations && this.reflectionTexture.animations.length > 0) {
  7443. results.push(this.reflectionTexture);
  7444. }
  7445. if (this.emissiveTexture && this.emissiveTexture.animations && this.emissiveTexture.animations.length > 0) {
  7446. results.push(this.emissiveTexture);
  7447. }
  7448. if (this.metallicTexture && this.metallicTexture.animations && this.metallicTexture.animations.length > 0) {
  7449. results.push(this.metallicTexture);
  7450. }
  7451. else if (this.reflectivityTexture && this.reflectivityTexture.animations && this.reflectivityTexture.animations.length > 0) {
  7452. results.push(this.reflectivityTexture);
  7453. }
  7454. if (this.bumpTexture && this.bumpTexture.animations && this.bumpTexture.animations.length > 0) {
  7455. results.push(this.bumpTexture);
  7456. }
  7457. if (this.lightmapTexture && this.lightmapTexture.animations && this.lightmapTexture.animations.length > 0) {
  7458. results.push(this.lightmapTexture);
  7459. }
  7460. if (this.refractionTexture && this.refractionTexture.animations && this.refractionTexture.animations.length > 0) {
  7461. results.push(this.refractionTexture);
  7462. }
  7463. if (this.cameraColorGradingTexture && this.cameraColorGradingTexture.animations && this.cameraColorGradingTexture.animations.length > 0) {
  7464. results.push(this.cameraColorGradingTexture);
  7465. }
  7466. return results;
  7467. };
  7468. LegacyPBRMaterial.prototype.dispose = function (forceDisposeEffect, forceDisposeTextures) {
  7469. if (forceDisposeTextures) {
  7470. if (this.albedoTexture) {
  7471. this.albedoTexture.dispose();
  7472. }
  7473. if (this.ambientTexture) {
  7474. this.ambientTexture.dispose();
  7475. }
  7476. if (this.opacityTexture) {
  7477. this.opacityTexture.dispose();
  7478. }
  7479. if (this.reflectionTexture) {
  7480. this.reflectionTexture.dispose();
  7481. }
  7482. if (this.emissiveTexture) {
  7483. this.emissiveTexture.dispose();
  7484. }
  7485. if (this.metallicTexture) {
  7486. this.metallicTexture.dispose();
  7487. }
  7488. if (this.reflectivityTexture) {
  7489. this.reflectivityTexture.dispose();
  7490. }
  7491. if (this.bumpTexture) {
  7492. this.bumpTexture.dispose();
  7493. }
  7494. if (this.lightmapTexture) {
  7495. this.lightmapTexture.dispose();
  7496. }
  7497. if (this.refractionTexture) {
  7498. this.refractionTexture.dispose();
  7499. }
  7500. if (this.cameraColorGradingTexture) {
  7501. this.cameraColorGradingTexture.dispose();
  7502. }
  7503. }
  7504. this._renderTargets.dispose();
  7505. _super.prototype.dispose.call(this, forceDisposeEffect, forceDisposeTextures);
  7506. };
  7507. LegacyPBRMaterial.prototype.clone = function (name) {
  7508. var _this = this;
  7509. return BABYLON.SerializationHelper.Clone(function () { return new LegacyPBRMaterial(name, _this.getScene()); }, this);
  7510. };
  7511. LegacyPBRMaterial.prototype.serialize = function () {
  7512. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  7513. serializationObject.customType = "BABYLON.LegacyPBRMaterial";
  7514. return serializationObject;
  7515. };
  7516. // Statics
  7517. LegacyPBRMaterial.Parse = function (source, scene, rootUrl) {
  7518. return BABYLON.SerializationHelper.Parse(function () { return new LegacyPBRMaterial(source.name, scene); }, source, scene, rootUrl);
  7519. };
  7520. LegacyPBRMaterial._scaledAlbedo = new BABYLON.Color3();
  7521. LegacyPBRMaterial._scaledReflectivity = new BABYLON.Color3();
  7522. LegacyPBRMaterial._scaledEmissive = new BABYLON.Color3();
  7523. LegacyPBRMaterial._scaledReflection = new BABYLON.Color3();
  7524. __decorate([
  7525. BABYLON.serialize()
  7526. ], LegacyPBRMaterial.prototype, "directIntensity", void 0);
  7527. __decorate([
  7528. BABYLON.serialize()
  7529. ], LegacyPBRMaterial.prototype, "emissiveIntensity", void 0);
  7530. __decorate([
  7531. BABYLON.serialize()
  7532. ], LegacyPBRMaterial.prototype, "environmentIntensity", void 0);
  7533. __decorate([
  7534. BABYLON.serialize()
  7535. ], LegacyPBRMaterial.prototype, "specularIntensity", void 0);
  7536. __decorate([
  7537. BABYLON.serialize()
  7538. ], LegacyPBRMaterial.prototype, "disableBumpMap", void 0);
  7539. __decorate([
  7540. BABYLON.serialize()
  7541. ], LegacyPBRMaterial.prototype, "overloadedShadowIntensity", void 0);
  7542. __decorate([
  7543. BABYLON.serialize()
  7544. ], LegacyPBRMaterial.prototype, "overloadedShadeIntensity", void 0);
  7545. __decorate([
  7546. BABYLON.serialize()
  7547. ], LegacyPBRMaterial.prototype, "cameraExposure", void 0);
  7548. __decorate([
  7549. BABYLON.serialize()
  7550. ], LegacyPBRMaterial.prototype, "cameraContrast", void 0);
  7551. __decorate([
  7552. BABYLON.serializeAsTexture()
  7553. ], LegacyPBRMaterial.prototype, "cameraColorGradingTexture", void 0);
  7554. __decorate([
  7555. BABYLON.serializeAsColorCurves()
  7556. ], LegacyPBRMaterial.prototype, "cameraColorCurves", void 0);
  7557. __decorate([
  7558. BABYLON.serializeAsColor3()
  7559. ], LegacyPBRMaterial.prototype, "overloadedAmbient", void 0);
  7560. __decorate([
  7561. BABYLON.serialize()
  7562. ], LegacyPBRMaterial.prototype, "overloadedAmbientIntensity", void 0);
  7563. __decorate([
  7564. BABYLON.serializeAsColor3()
  7565. ], LegacyPBRMaterial.prototype, "overloadedAlbedo", void 0);
  7566. __decorate([
  7567. BABYLON.serialize()
  7568. ], LegacyPBRMaterial.prototype, "overloadedAlbedoIntensity", void 0);
  7569. __decorate([
  7570. BABYLON.serializeAsColor3()
  7571. ], LegacyPBRMaterial.prototype, "overloadedReflectivity", void 0);
  7572. __decorate([
  7573. BABYLON.serialize()
  7574. ], LegacyPBRMaterial.prototype, "overloadedReflectivityIntensity", void 0);
  7575. __decorate([
  7576. BABYLON.serializeAsColor3()
  7577. ], LegacyPBRMaterial.prototype, "overloadedEmissive", void 0);
  7578. __decorate([
  7579. BABYLON.serialize()
  7580. ], LegacyPBRMaterial.prototype, "overloadedEmissiveIntensity", void 0);
  7581. __decorate([
  7582. BABYLON.serializeAsColor3()
  7583. ], LegacyPBRMaterial.prototype, "overloadedReflection", void 0);
  7584. __decorate([
  7585. BABYLON.serialize()
  7586. ], LegacyPBRMaterial.prototype, "overloadedReflectionIntensity", void 0);
  7587. __decorate([
  7588. BABYLON.serialize()
  7589. ], LegacyPBRMaterial.prototype, "overloadedMicroSurface", void 0);
  7590. __decorate([
  7591. BABYLON.serialize()
  7592. ], LegacyPBRMaterial.prototype, "overloadedMicroSurfaceIntensity", void 0);
  7593. __decorate([
  7594. BABYLON.serializeAsTexture()
  7595. ], LegacyPBRMaterial.prototype, "albedoTexture", void 0);
  7596. __decorate([
  7597. BABYLON.serializeAsTexture()
  7598. ], LegacyPBRMaterial.prototype, "ambientTexture", void 0);
  7599. __decorate([
  7600. BABYLON.serialize()
  7601. ], LegacyPBRMaterial.prototype, "ambientTextureStrength", void 0);
  7602. __decorate([
  7603. BABYLON.serializeAsTexture()
  7604. ], LegacyPBRMaterial.prototype, "opacityTexture", void 0);
  7605. __decorate([
  7606. BABYLON.serializeAsTexture()
  7607. ], LegacyPBRMaterial.prototype, "reflectionTexture", void 0);
  7608. __decorate([
  7609. BABYLON.serializeAsTexture()
  7610. ], LegacyPBRMaterial.prototype, "emissiveTexture", void 0);
  7611. __decorate([
  7612. BABYLON.serializeAsTexture()
  7613. ], LegacyPBRMaterial.prototype, "reflectivityTexture", void 0);
  7614. __decorate([
  7615. BABYLON.serializeAsTexture()
  7616. ], LegacyPBRMaterial.prototype, "metallicTexture", void 0);
  7617. __decorate([
  7618. BABYLON.serialize()
  7619. ], LegacyPBRMaterial.prototype, "metallic", void 0);
  7620. __decorate([
  7621. BABYLON.serialize()
  7622. ], LegacyPBRMaterial.prototype, "roughness", void 0);
  7623. __decorate([
  7624. BABYLON.serializeAsTexture()
  7625. ], LegacyPBRMaterial.prototype, "microSurfaceTexture", void 0);
  7626. __decorate([
  7627. BABYLON.serializeAsTexture()
  7628. ], LegacyPBRMaterial.prototype, "bumpTexture", void 0);
  7629. __decorate([
  7630. BABYLON.serializeAsTexture()
  7631. ], LegacyPBRMaterial.prototype, "lightmapTexture", void 0);
  7632. __decorate([
  7633. BABYLON.serializeAsTexture()
  7634. ], LegacyPBRMaterial.prototype, "refractionTexture", void 0);
  7635. __decorate([
  7636. BABYLON.serializeAsColor3("ambient")
  7637. ], LegacyPBRMaterial.prototype, "ambientColor", void 0);
  7638. __decorate([
  7639. BABYLON.serializeAsColor3("albedo")
  7640. ], LegacyPBRMaterial.prototype, "albedoColor", void 0);
  7641. __decorate([
  7642. BABYLON.serializeAsColor3("reflectivity")
  7643. ], LegacyPBRMaterial.prototype, "reflectivityColor", void 0);
  7644. __decorate([
  7645. BABYLON.serializeAsColor3("reflection")
  7646. ], LegacyPBRMaterial.prototype, "reflectionColor", void 0);
  7647. __decorate([
  7648. BABYLON.serializeAsColor3("emissive")
  7649. ], LegacyPBRMaterial.prototype, "emissiveColor", void 0);
  7650. __decorate([
  7651. BABYLON.serialize()
  7652. ], LegacyPBRMaterial.prototype, "microSurface", void 0);
  7653. __decorate([
  7654. BABYLON.serialize()
  7655. ], LegacyPBRMaterial.prototype, "indexOfRefraction", void 0);
  7656. __decorate([
  7657. BABYLON.serialize()
  7658. ], LegacyPBRMaterial.prototype, "invertRefractionY", void 0);
  7659. __decorate([
  7660. BABYLON.serializeAsFresnelParameters()
  7661. ], LegacyPBRMaterial.prototype, "opacityFresnelParameters", void 0);
  7662. __decorate([
  7663. BABYLON.serializeAsFresnelParameters()
  7664. ], LegacyPBRMaterial.prototype, "emissiveFresnelParameters", void 0);
  7665. __decorate([
  7666. BABYLON.serialize()
  7667. ], LegacyPBRMaterial.prototype, "linkRefractionWithTransparency", void 0);
  7668. __decorate([
  7669. BABYLON.serialize()
  7670. ], LegacyPBRMaterial.prototype, "linkEmissiveWithAlbedo", void 0);
  7671. __decorate([
  7672. BABYLON.serialize()
  7673. ], LegacyPBRMaterial.prototype, "useLightmapAsShadowmap", void 0);
  7674. __decorate([
  7675. BABYLON.serialize()
  7676. ], LegacyPBRMaterial.prototype, "useEmissiveAsIllumination", void 0);
  7677. __decorate([
  7678. BABYLON.serialize()
  7679. ], LegacyPBRMaterial.prototype, "useAlphaFromAlbedoTexture", void 0);
  7680. __decorate([
  7681. BABYLON.serialize()
  7682. ], LegacyPBRMaterial.prototype, "useSpecularOverAlpha", void 0);
  7683. __decorate([
  7684. BABYLON.serialize()
  7685. ], LegacyPBRMaterial.prototype, "useMicroSurfaceFromReflectivityMapAlpha", void 0);
  7686. __decorate([
  7687. BABYLON.serialize()
  7688. ], LegacyPBRMaterial.prototype, "useRoughnessFromMetallicTextureAlpha", void 0);
  7689. __decorate([
  7690. BABYLON.serialize()
  7691. ], LegacyPBRMaterial.prototype, "useRoughnessFromMetallicTextureGreen", void 0);
  7692. __decorate([
  7693. BABYLON.serialize()
  7694. ], LegacyPBRMaterial.prototype, "useMetallnessFromMetallicTextureBlue", void 0);
  7695. __decorate([
  7696. BABYLON.serialize()
  7697. ], LegacyPBRMaterial.prototype, "useAmbientOcclusionFromMetallicTextureRed", void 0);
  7698. __decorate([
  7699. BABYLON.serialize()
  7700. ], LegacyPBRMaterial.prototype, "useAmbientInGrayScale", void 0);
  7701. __decorate([
  7702. BABYLON.serialize()
  7703. ], LegacyPBRMaterial.prototype, "useAutoMicroSurfaceFromReflectivityMap", void 0);
  7704. __decorate([
  7705. BABYLON.serialize()
  7706. ], LegacyPBRMaterial.prototype, "useScalarInLinearSpace", void 0);
  7707. __decorate([
  7708. BABYLON.serialize()
  7709. ], LegacyPBRMaterial.prototype, "usePhysicalLightFalloff", void 0);
  7710. __decorate([
  7711. BABYLON.serialize()
  7712. ], LegacyPBRMaterial.prototype, "useRadianceOverAlpha", void 0);
  7713. __decorate([
  7714. BABYLON.serialize()
  7715. ], LegacyPBRMaterial.prototype, "useParallax", void 0);
  7716. __decorate([
  7717. BABYLON.serialize()
  7718. ], LegacyPBRMaterial.prototype, "useParallaxOcclusion", void 0);
  7719. __decorate([
  7720. BABYLON.serialize()
  7721. ], LegacyPBRMaterial.prototype, "parallaxScaleBias", void 0);
  7722. __decorate([
  7723. BABYLON.serialize()
  7724. ], LegacyPBRMaterial.prototype, "disableLighting", void 0);
  7725. __decorate([
  7726. BABYLON.serialize()
  7727. ], LegacyPBRMaterial.prototype, "maxSimultaneousLights", void 0);
  7728. __decorate([
  7729. BABYLON.serialize()
  7730. ], LegacyPBRMaterial.prototype, "invertNormalMapX", void 0);
  7731. __decorate([
  7732. BABYLON.serialize()
  7733. ], LegacyPBRMaterial.prototype, "invertNormalMapY", void 0);
  7734. __decorate([
  7735. BABYLON.serialize()
  7736. ], LegacyPBRMaterial.prototype, "twoSidedLighting", void 0);
  7737. __decorate([
  7738. BABYLON.serialize()
  7739. ], LegacyPBRMaterial.prototype, "useLogarithmicDepth", null);
  7740. return LegacyPBRMaterial;
  7741. }(BABYLON.Material));
  7742. BABYLON.LegacyPBRMaterial = LegacyPBRMaterial;
  7743. })(BABYLON || (BABYLON = {}));
  7744. //# sourceMappingURL=babylon.legacyPBRMaterial.js.map
  7745. BABYLON.Effect.ShadersStore['legacyPbrVertexShader'] = "precision highp float;\n#include<__decl__legacyPbrVertex>\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\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>\n#ifdef ALBEDO\nvarying vec2 vAlbedoUV;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\n#endif\n#ifdef OPACITY\nvarying vec2 vOpacityUV;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\n#endif\n#ifdef LIGHTMAP\nvarying vec2 vLightmapUV;\n#endif\n#if defined(REFLECTIVITY) || defined(METALLICWORKFLOW) \nvarying vec2 vReflectivityUV;\n#endif\n#ifdef MICROSURFACEMAP\nvarying vec2 vMicroSurfaceSamplerUV;\n#endif\n#ifdef BUMP\nvarying vec2 vBumpUV;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<bumpVertexDeclaration>\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<morphTargetsVertexGlobalDeclaration>\n#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include<logDepthDeclaration>\nvoid main(void) {\nvec3 positionUpdated=position;\n#ifdef NORMAL\nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif \n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normalUpdated,0.0)));\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,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 ALBEDO\nif (vAlbedoInfos.x == 0.)\n{\nvAlbedoUV=vec2(albedoMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAlbedoUV=vec2(albedoMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef AMBIENT\nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef OPACITY\nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef EMISSIVE\nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef LIGHTMAP\nif (vLightmapInfos.x == 0.)\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(REFLECTIVITY) || defined(METALLICWORKFLOW) \nif (vReflectivityInfos.x == 0.)\n{\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef MICROSURFACEMAP\nif (vMicroSurfaceSamplerInfos.x == 0.)\n{\nvMicroSurfaceSamplerUV=vec2(microSurfaceSamplerMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvMicroSurfaceSamplerUV=vec2(microSurfaceSamplerMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef BUMP\nif (vBumpInfos.x == 0.)\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<bumpVertex>\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#include<logDepthVertex>\n}";
  7746. BABYLON.Effect.ShadersStore['legacyPbrPixelShader'] = "#if defined(BUMP)|| !defined(NORMAL)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef LODBASEDMICROSFURACE\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nprecision highp float;\n#include<__decl__legacyPbrFragment>\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\nuniform vec4 vCameraInfos;\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 ALBEDO\nvarying vec2 vAlbedoUV;\nuniform sampler2D albedoSampler;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform sampler2D ambientSampler;\n#endif\n#ifdef OPACITY \nvarying vec2 vOpacityUV;\nuniform sampler2D opacitySampler;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\nvarying vec2 vLightmapUV;\nuniform sampler2D lightmapSampler;\n#endif\n#if defined(REFLECTIVITY) || defined(METALLICWORKFLOW) \nvarying vec2 vReflectivityUV;\nuniform sampler2D reflectivitySampler;\n#endif\n#ifdef MICROSURFACEMAP\nvarying vec2 vMicroSurfaceSamplerUV;\nuniform sampler2D microSurfaceSampler;\n#endif\n\n#include<fresnelFunction>\n\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\n#endif\n#endif\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n#ifdef CAMERACOLORGRADING\n#include<legacyColorGradingDefinition>\n#endif\n#ifdef CAMERACOLORCURVES\n#include<legacyColorCurvesDefinition>\n#endif\n\n#include<shadowsFragmentFunctions>\n#include<legacyPbrFunctions>\n#ifdef CAMERACOLORGRADING\n#include<legacyColorGrading>\n#endif\n#ifdef CAMERACOLORCURVES\n#include<legacyColorCurves>\n#endif\n#include<legacyPbrLightFunctions>\n#include<bumpFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\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=normalize(cross(dFdx(vPositionW),dFdy(vPositionW)));\n#endif\n#include<bumpFragment>\n#ifdef TWOSIDEDLIGHTING\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n\nvec4 surfaceAlbedo=vec4(1.,1.,1.,1.);\nvec3 surfaceAlbedoContribution=vAlbedoColor.rgb;\n\nfloat alpha=vAlbedoColor.a;\n#ifdef ALBEDO\nsurfaceAlbedo=texture2D(albedoSampler,vAlbedoUV+uvOffset);\nsurfaceAlbedo=vec4(toLinearSpace(surfaceAlbedo.rgb),surfaceAlbedo.a);\n#ifndef LINKREFRACTIONTOTRANSPARENCY\n#ifdef ALPHATEST\nif (surfaceAlbedo.a<0.4)\ndiscard;\n#endif\n#endif\n#ifdef ALPHAFROMALBEDO\nalpha*=surfaceAlbedo.a;\n#endif\nsurfaceAlbedo.rgb*=vAlbedoInfos.y;\n#else\n\nsurfaceAlbedo.rgb=surfaceAlbedoContribution;\nsurfaceAlbedoContribution=vec3(1.,1.,1.);\n#endif\n#ifdef VERTEXCOLOR\nsurfaceAlbedo.rgb*=vColor.rgb;\n#endif\n#ifdef OVERLOADEDVALUES\nsurfaceAlbedo.rgb=mix(surfaceAlbedo.rgb,vOverloadedAlbedo,vOverloadedIntensity.y);\n#endif\n\nvec3 ambientOcclusionColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nvec3 ambientOcclusionColorMap=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n#ifdef AMBIENTINGRAYSCALE \nambientOcclusionColorMap=vec3(ambientOcclusionColorMap.r,ambientOcclusionColorMap.r,ambientOcclusionColorMap.r);\n#endif\nambientOcclusionColor=mix(ambientOcclusionColor,ambientOcclusionColorMap,vAmbientInfos.z);\n#ifdef OVERLOADEDVALUES\nambientOcclusionColor.rgb=mix(ambientOcclusionColor.rgb,vOverloadedAmbient,vOverloadedIntensity.x);\n#endif\n#endif\n\nfloat microSurface=vReflectivityColor.a;\nvec3 surfaceReflectivityColor=vReflectivityColor.rgb;\n#ifdef REFLECTIVITY\nvec4 surfaceReflectivityColorMap=texture2D(reflectivitySampler,vReflectivityUV+uvOffset);\nsurfaceReflectivityColor=surfaceReflectivityColorMap.rgb;\nsurfaceReflectivityColor=toLinearSpace(surfaceReflectivityColor);\nsurfaceReflectivityColor*=vReflectivityInfos.y;\n#ifdef OVERLOADEDVALUES\nsurfaceReflectivityColor=mix(surfaceReflectivityColor,vOverloadedReflectivity,vOverloadedIntensity.z);\n#endif\n#ifdef MICROSURFACEFROMREFLECTIVITYMAP\nmicroSurface=surfaceReflectivityColorMap.a*vReflectivityInfos.z;\n#else\n#ifdef MICROSURFACEAUTOMATIC\nmicroSurface=computeDefaultMicroSurface(microSurface,surfaceReflectivityColor);\n#endif\n#endif\n#else\n#ifdef OVERLOADEDVALUES\nsurfaceReflectivityColor=mix(surfaceReflectivityColor,vOverloadedReflectivity,vOverloadedIntensity.z);\n#endif\n#endif\n#ifdef METALLICWORKFLOW\nvec2 metallicRoughness=surfaceReflectivityColor.rg;\n#ifdef METALLICMAP\nvec4 surfaceMetallicColorMap=texture2D(reflectivitySampler,vReflectivityUV+uvOffset);\n#ifdef AOSTOREINMETALMAPRED \nvec3 aoStoreInMetalMap=vec3(surfaceMetallicColorMap.r,surfaceMetallicColorMap.r,surfaceMetallicColorMap.r);\nambientOcclusionColor=mix(ambientOcclusionColor,aoStoreInMetalMap,vReflectivityInfos.z);\n#endif\n#ifdef METALLNESSSTOREINMETALMAPBLUE\nmetallicRoughness.r*=surfaceMetallicColorMap.b;\n#else\nmetallicRoughness.r*=surfaceMetallicColorMap.r;\n#endif\n#ifdef ROUGHNESSSTOREINMETALMAPALPHA\nmetallicRoughness.g*=surfaceMetallicColorMap.a;\n#else\n#ifdef ROUGHNESSSTOREINMETALMAPGREEN\nmetallicRoughness.g*=surfaceMetallicColorMap.g;\n#endif\n#endif\n#endif\n#ifdef MICROSURFACEMAP\nvec4 microSurfaceTexel=texture2D(microSurfaceSampler,vMicroSurfaceSamplerUV+uvOffset)*vMicroSurfaceSamplerInfos.y;\nmetallicRoughness.g*=microSurfaceTexel.r;\n#endif\n\nmicroSurface=1.0-metallicRoughness.g;\n\nvec3 baseColor=surfaceAlbedo.rgb;\n\n\nconst vec3 DefaultSpecularReflectanceDielectric=vec3(0.04,0.04,0.04);\n\nsurfaceAlbedo.rgb=mix(baseColor.rgb*(1.0-DefaultSpecularReflectanceDielectric.r),vec3(0.,0.,0.),metallicRoughness.r);\n\nsurfaceReflectivityColor=mix(DefaultSpecularReflectanceDielectric,baseColor,metallicRoughness.r);\n#ifdef OVERLOADEDVALUES\nsurfaceReflectivityColor=mix(surfaceReflectivityColor,vOverloadedReflectivity,vOverloadedIntensity.z);\n#endif\n#else\n#ifdef MICROSURFACEMAP\nvec4 microSurfaceTexel=texture2D(microSurfaceSampler,vMicroSurfaceSamplerUV+uvOffset)*vMicroSurfaceSamplerInfos.y;\nmicroSurface=microSurfaceTexel.r;\n#endif\n#endif\n#ifdef OVERLOADEDVALUES\nmicroSurface=mix(microSurface,vOverloadedMicroSurface.x,vOverloadedMicroSurface.y);\n#endif\n\nfloat NdotV=max(0.00000000001,dot(normalW,viewDirectionW));\n\nmicroSurface=clamp(microSurface,0.,1.)*0.98;\n\nfloat roughness=clamp(1.-microSurface,0.000001,1.0);\n\nvec3 lightDiffuseContribution=vec3(0.,0.,0.);\n#ifdef OVERLOADEDSHADOWVALUES\nvec3 shadowedOnlyLightDiffuseContribution=vec3(1.,1.,1.);\n#endif\n#ifdef SPECULARTERM\nvec3 lightSpecularContribution=vec3(0.,0.,0.);\n#endif\nfloat notShadowLevel=1.; \n#ifdef LIGHTMAP\nvec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;\n#endif\nfloat NdotL=-1.;\nlightingInfo info;\n\nfloat reflectance=max(max(surfaceReflectivityColor.r,surfaceReflectivityColor.g),surfaceReflectivityColor.b);\n\n\nfloat reflectance90=clamp(reflectance*25.0,0.0,1.0);\nvec3 specularEnvironmentR0=surfaceReflectivityColor.rgb;\nvec3 specularEnvironmentR90=vec3(1.0,1.0,1.0)*reflectance90;\n#include<legacyPbrLightFunctionsCall>[0..maxSimultaneousLights]\n#ifdef SPECULARTERM\nlightSpecularContribution*=vLightingIntensity.w;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\nalpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef OPACITYFRESNEL\nfloat opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);\nalpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n#endif\n\nvec3 surfaceRefractionColor=vec3(0.,0.,0.);\n\n#ifdef LODBASEDMICROSFURACE\nfloat alphaG=convertRoughnessToAverageSlope(roughness);\n#endif\n#ifdef REFRACTION\nvec3 refractionVector=refract(-viewDirectionW,normalW,vRefractionInfos.y);\n#ifdef LODBASEDMICROSFURACE\n#ifdef USEPMREMREFRACTION\nfloat lodRefraction=getMipMapIndexFromAverageSlopeWithPMREM(vMicrosurfaceTextureLods.y,alphaG);\n#else\nfloat lodRefraction=getMipMapIndexFromAverageSlope(vMicrosurfaceTextureLods.y,alphaG);\n#endif\n#else\nfloat biasRefraction=(vMicrosurfaceTextureLods.y+2.)*(1.0-microSurface);\n#endif\n#ifdef REFRACTIONMAP_3D\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;\nif (dot(refractionVector,viewDirectionW)<1.0)\n{\n#ifdef LODBASEDMICROSFURACE\n#ifdef USEPMREMREFRACTION\n\nif ((vMicrosurfaceTextureLods.y-lodRefraction)>4.0)\n{\n\nfloat scaleRefraction=1.-exp2(lodRefraction)/exp2(vMicrosurfaceTextureLods.y); \nfloat maxRefraction=max(max(abs(refractionVector.x),abs(refractionVector.y)),abs(refractionVector.z));\nif (abs(refractionVector.x) != maxRefraction) refractionVector.x*=scaleRefraction;\nif (abs(refractionVector.y) != maxRefraction) refractionVector.y*=scaleRefraction;\nif (abs(refractionVector.z) != maxRefraction) refractionVector.z*=scaleRefraction;\n}\n#endif\nsurfaceRefractionColor=textureCubeLodEXT(refractionCubeSampler,refractionVector,lodRefraction).rgb*vRefractionInfos.x;\n#else\nsurfaceRefractionColor=textureCube(refractionCubeSampler,refractionVector,biasRefraction).rgb*vRefractionInfos.x;\n#endif\n}\n#ifndef REFRACTIONMAPINLINEARSPACE\nsurfaceRefractionColor=toLinearSpace(surfaceRefractionColor.rgb);\n#endif\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\nvec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;\nrefractionCoords.y=1.0-refractionCoords.y;\n#ifdef LODBASEDMICROSFURACE\nsurfaceRefractionColor=texture2DLodEXT(refraction2DSampler,refractionCoords,lodRefraction).rgb*vRefractionInfos.x;\n#else\nsurfaceRefractionColor=texture2D(refraction2DSampler,refractionCoords,biasRefraction).rgb*vRefractionInfos.x;\n#endif \nsurfaceRefractionColor=toLinearSpace(surfaceRefractionColor.rgb);\n#endif\n#endif\n\nvec3 environmentRadiance=vReflectionColor.rgb;\nvec3 environmentIrradiance=vReflectionColor.rgb;\n#ifdef REFLECTION\nvec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef LODBASEDMICROSFURACE\n#ifdef USEPMREMREFLECTION\nfloat lodReflection=getMipMapIndexFromAverageSlopeWithPMREM(vMicrosurfaceTextureLods.x,alphaG);\n#else\nfloat lodReflection=getMipMapIndexFromAverageSlope(vMicrosurfaceTextureLods.x,alphaG);\n#endif\n#else\nfloat biasReflection=(vMicrosurfaceTextureLods.x+2.)*(1.0-microSurface);\n#endif\n#ifdef REFLECTIONMAP_3D\n#ifdef LODBASEDMICROSFURACE\n#ifdef USEPMREMREFLECTION\n\nif ((vMicrosurfaceTextureLods.y-lodReflection)>4.0)\n{\n\nfloat scaleReflection=1.-exp2(lodReflection)/exp2(vMicrosurfaceTextureLods.x); \nfloat maxReflection=max(max(abs(vReflectionUVW.x),abs(vReflectionUVW.y)),abs(vReflectionUVW.z));\nif (abs(vReflectionUVW.x) != maxReflection) vReflectionUVW.x*=scaleReflection;\nif (abs(vReflectionUVW.y) != maxReflection) vReflectionUVW.y*=scaleReflection;\nif (abs(vReflectionUVW.z) != maxReflection) vReflectionUVW.z*=scaleReflection;\n}\n#endif\nenvironmentRadiance=textureCubeLodEXT(reflectionCubeSampler,vReflectionUVW,lodReflection).rgb*vReflectionInfos.x;\n#else\nenvironmentRadiance=textureCube(reflectionCubeSampler,vReflectionUVW,biasReflection).rgb*vReflectionInfos.x;\n#endif\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#ifndef REFLECTIONMAP_SKYBOX\nvec3 normalEnvironmentSpace=(reflectionMatrix*vec4(normalW,1)).xyz;\nenvironmentIrradiance=EnvironmentIrradiance(normalEnvironmentSpace);\n#endif\n#else\nenvironmentRadiance=toLinearSpace(environmentRadiance.rgb);\nenvironmentIrradiance=textureCube(reflectionCubeSampler,normalW,20.).rgb*vReflectionInfos.x;\nenvironmentIrradiance=toLinearSpace(environmentIrradiance.rgb);\nenvironmentIrradiance*=0.2; \n#endif\n#else\nvec2 coords=vReflectionUVW.xy;\n#ifdef REFLECTIONMAP_PROJECTION\ncoords/=vReflectionUVW.z;\n#endif\ncoords.y=1.0-coords.y;\n#ifdef LODBASEDMICROSFURACE\nenvironmentRadiance=texture2DLodEXT(reflection2DSampler,coords,lodReflection).rgb*vReflectionInfos.x;\n#else\nenvironmentRadiance=texture2D(reflection2DSampler,coords,biasReflection).rgb*vReflectionInfos.x;\n#endif\nenvironmentRadiance=toLinearSpace(environmentRadiance.rgb);\nenvironmentIrradiance=texture2D(reflection2DSampler,coords,20.).rgb*vReflectionInfos.x;\nenvironmentIrradiance=toLinearSpace(environmentIrradiance.rgb);\n#endif\n#endif\n#ifdef OVERLOADEDVALUES\nenvironmentIrradiance=mix(environmentIrradiance,vOverloadedReflection,vOverloadedMicroSurface.z);\nenvironmentRadiance=mix(environmentRadiance,vOverloadedReflection,vOverloadedMicroSurface.z);\n#endif\nenvironmentRadiance*=vLightingIntensity.z;\nenvironmentIrradiance*=vLightingIntensity.z;\n\nvec3 specularEnvironmentReflectance=FresnelSchlickEnvironmentGGX(clamp(NdotV,0.,1.),specularEnvironmentR0,specularEnvironmentR90,sqrt(microSurface));\n\nvec3 refractance=vec3(0.0,0.0,0.0);\n#ifdef REFRACTION\nvec3 transmission=vec3(1.0,1.0,1.0);\n#ifdef LINKREFRACTIONTOTRANSPARENCY\n\ntransmission*=(1.0-alpha);\n\n\nvec3 mixedAlbedo=surfaceAlbedoContribution.rgb*surfaceAlbedo.rgb;\nfloat maxChannel=max(max(mixedAlbedo.r,mixedAlbedo.g),mixedAlbedo.b);\nvec3 tint=clamp(maxChannel*mixedAlbedo,0.0,1.0);\n\nsurfaceAlbedoContribution*=alpha;\n\nenvironmentIrradiance*=alpha;\n\nsurfaceRefractionColor*=tint;\n\nalpha=1.0;\n#endif\n\nvec3 bounceSpecularEnvironmentReflectance=(2.0*specularEnvironmentReflectance)/(1.0+specularEnvironmentReflectance);\nspecularEnvironmentReflectance=mix(bounceSpecularEnvironmentReflectance,specularEnvironmentReflectance,alpha);\n\ntransmission*=1.0-specularEnvironmentReflectance;\n\nrefractance=surfaceRefractionColor*transmission;\n#endif\n\nsurfaceAlbedo.rgb=(1.-reflectance)*surfaceAlbedo.rgb;\nrefractance*=vLightingIntensity.z;\nenvironmentRadiance*=specularEnvironmentReflectance;\n\nvec3 surfaceEmissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nvec3 emissiveColorTex=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb;\nsurfaceEmissiveColor=toLinearSpace(emissiveColorTex.rgb)*surfaceEmissiveColor*vEmissiveInfos.y;\n#endif\n#ifdef OVERLOADEDVALUES\nsurfaceEmissiveColor=mix(surfaceEmissiveColor,vOverloadedEmissive,vOverloadedIntensity.w);\n#endif\n#ifdef EMISSIVEFRESNEL\nfloat emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);\nsurfaceEmissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec3 finalDiffuse=lightDiffuseContribution*surfaceAlbedoContribution;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=shadowedOnlyLightDiffuseContribution*surfaceAlbedoContribution;\n#endif\n#else\n#ifdef LINKEMISSIVEWITHALBEDO\nvec3 finalDiffuse=(lightDiffuseContribution+surfaceEmissiveColor)*surfaceAlbedoContribution;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=(shadowedOnlyLightDiffuseContribution+surfaceEmissiveColor)*surfaceAlbedoContribution;\n#endif\n#else\nvec3 finalDiffuse=lightDiffuseContribution*surfaceAlbedoContribution+surfaceEmissiveColor;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=shadowedOnlyLightDiffuseContribution*surfaceAlbedoContribution+surfaceEmissiveColor;\n#endif\n#endif\n#endif\nfinalDiffuse.rgb+=vAmbientColor;\nfinalDiffuse*=surfaceAlbedo.rgb;\nfinalDiffuse=max(finalDiffuse,0.0);\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution+=vAmbientColor;\nshadowedOnlyLightDiffuseContribution*=surfaceAlbedo.rgb;\nshadowedOnlyLightDiffuseContribution=max(shadowedOnlyLightDiffuseContribution,0.0);\nfinalDiffuse=mix(finalDiffuse,shadowedOnlyLightDiffuseContribution,(1.0-vOverloadedShadowIntensity.y));\n#endif\nfinalDiffuse=(finalDiffuse*vLightingIntensity.x+surfaceAlbedo.rgb*environmentIrradiance)*ambientOcclusionColor;\n#ifdef SPECULARTERM\nvec3 finalSpecular=lightSpecularContribution*surfaceReflectivityColor;\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+getLuminance(finalSpecular),0.,1.);\n#endif\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef RADIANCEOVERALPHA\nalpha=clamp(alpha+getLuminance(environmentRadiance),0.,1.);\n#endif\n\n\nvec4 finalColor=vec4(finalDiffuse+finalSpecular*vLightingIntensity.x+environmentRadiance+refractance,alpha);\n#ifdef EMISSIVEASILLUMINATION\nfinalColor.rgb+=(surfaceEmissiveColor*vLightingIntensity.y);\n#endif\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\nfinalColor.rgb*=lightmapColor;\n#else\nfinalColor.rgb+=lightmapColor;\n#endif\n#endif\n#endif\nfinalColor=max(finalColor,0.0);\n#ifdef CAMERATONEMAP\nfinalColor.rgb=toneMaps(finalColor.rgb);\n#endif\nfinalColor.rgb=toGammaSpace(finalColor.rgb);\n#include<logDepthFragment>\n#include<fogFragment>(color,finalColor)\n#ifdef CAMERACONTRAST\nfinalColor=contrasts(finalColor);\n#endif\nfinalColor.rgb=clamp(finalColor.rgb,0.,1.);\n#ifdef CAMERACOLORGRADING\nfinalColor=colorGrades(finalColor);\n#endif\n#ifdef CAMERACOLORCURVES\nfinalColor.rgb=applyColorCurves(finalColor.rgb);\n#endif\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\ngl_FragColor=finalColor;\n}";
  7747. BABYLON.Effect.IncludesShadersStore['legacyPbrFragmentDeclaration'] = "uniform vec3 vReflectionColor;\nuniform vec4 vAlbedoColor;\n\nuniform vec4 vLightingIntensity;\n#ifdef OVERLOADEDVALUES\nuniform vec4 vOverloadedIntensity;\nuniform vec3 vOverloadedAmbient;\nuniform vec3 vOverloadedAlbedo;\nuniform vec3 vOverloadedReflectivity;\nuniform vec3 vOverloadedEmissive;\nuniform vec3 vOverloadedReflection;\nuniform vec3 vOverloadedMicroSurface;\n#endif\n#ifdef OVERLOADEDSHADOWVALUES\nuniform vec4 vOverloadedShadowIntensity;\n#endif\n#if defined(REFLECTION) || defined(REFRACTION)\nuniform vec2 vMicrosurfaceTextureLods;\n#endif\nuniform vec4 vReflectivityColor;\nuniform vec3 vEmissiveColor;\n\n#ifdef ALBEDO\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nuniform vec3 vAmbientInfos;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform vec2 vTangentSpaceParams;\n#endif\n#ifdef OPACITY \nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\n#endif\n#if defined(REFLECTIVITY) || defined(METALLICWORKFLOW) \nuniform vec3 vReflectivityInfos;\n#endif\n#ifdef MICROSURFACEMAP\nuniform vec2 vMicroSurfaceSamplerInfos;\n#endif\n#ifdef OPACITYFRESNEL\nuniform vec4 opacityParts;\n#endif\n#ifdef EMISSIVEFRESNEL\nuniform vec4 emissiveLeftColor;\nuniform vec4 emissiveRightColor;\n#endif\n\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\n#endif\n\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\n#ifdef REFRACTIONMAP_3D\n#else\nuniform mat4 refractionMatrix;\n#endif\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\n#ifdef REFLECTIONMAP_SKYBOX\n#else\n#if defined(REFLECTIONMAP_PLANAR) || defined(REFLECTIONMAP_CUBIC) || defined(REFLECTIONMAP_PROJECTION)\nuniform mat4 reflectionMatrix;\n#endif\n#endif\n#endif";
  7748. BABYLON.Effect.IncludesShadersStore['legacyPbrFunctions'] = "\n#define RECIPROCAL_PI2 0.15915494\n#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\n\nconst float kPi=3.1415926535897932384626433832795;\nconst float kRougnhessToAlphaScale=0.1;\nconst float kRougnhessToAlphaOffset=0.29248125;\nfloat Square(float value)\n{\nreturn value*value;\n}\nfloat convertRoughnessToAverageSlope(float roughness)\n{\n\nconst float kMinimumVariance=0.0005;\nfloat alphaG=Square(roughness)+kMinimumVariance;\nreturn alphaG;\n}\n\nfloat getMipMapIndexFromAverageSlope(float maxMipLevel,float alpha)\n{\n\n\n\n\n\n\n\nfloat mip=kRougnhessToAlphaOffset+maxMipLevel+(maxMipLevel*kRougnhessToAlphaScale*log2(alpha));\nreturn clamp(mip,0.,maxMipLevel);\n}\nfloat getMipMapIndexFromAverageSlopeWithPMREM(float maxMipLevel,float alphaG)\n{\nfloat specularPower=clamp(2./alphaG-2.,0.000001,2048.);\n\nreturn clamp(- 0.5*log2(specularPower)+5.5,0.,maxMipLevel);\n}\n\nfloat smithVisibilityG1_TrowbridgeReitzGGX(float dot,float alphaG)\n{\nfloat tanSquared=(1.0-dot*dot)/(dot*dot);\nreturn 2.0/(1.0+sqrt(1.0+alphaG*alphaG*tanSquared));\n}\nfloat smithVisibilityG_TrowbridgeReitzGGX_Walter(float NdotL,float NdotV,float alphaG)\n{\nreturn smithVisibilityG1_TrowbridgeReitzGGX(NdotL,alphaG)*smithVisibilityG1_TrowbridgeReitzGGX(NdotV,alphaG);\n}\n\n\nfloat normalDistributionFunction_TrowbridgeReitzGGX(float NdotH,float alphaG)\n{\n\n\n\nfloat a2=Square(alphaG);\nfloat d=NdotH*NdotH*(a2-1.0)+1.0;\nreturn a2/(kPi*d*d);\n}\nvec3 fresnelSchlickGGX(float VdotH,vec3 reflectance0,vec3 reflectance90)\n{\nreturn reflectance0+(reflectance90-reflectance0)*pow(clamp(1.0-VdotH,0.,1.),5.0);\n}\nvec3 FresnelSchlickEnvironmentGGX(float VdotN,vec3 reflectance0,vec3 reflectance90,float smoothness)\n{\n\nfloat weight=mix(FRESNEL_MAXIMUM_ON_ROUGH,1.0,smoothness);\nreturn reflectance0+weight*(reflectance90-reflectance0)*pow(clamp(1.0-VdotN,0.,1.),5.0);\n}\n\nvec3 computeSpecularTerm(float NdotH,float NdotL,float NdotV,float VdotH,float roughness,vec3 specularColor,vec3 reflectance90)\n{\nfloat alphaG=convertRoughnessToAverageSlope(roughness);\nfloat distribution=normalDistributionFunction_TrowbridgeReitzGGX(NdotH,alphaG);\nfloat visibility=smithVisibilityG_TrowbridgeReitzGGX_Walter(NdotL,NdotV,alphaG);\nvisibility/=(4.0*NdotL*NdotV); \nvec3 fresnel=fresnelSchlickGGX(VdotH,specularColor,reflectance90);\nfloat specTerm=max(0.,visibility*distribution)*NdotL;\nreturn fresnel*specTerm*kPi; \n}\nfloat computeDiffuseTerm(float NdotL,float NdotV,float VdotH,float roughness)\n{\n\n\nfloat diffuseFresnelNV=pow(clamp(1.0-NdotL,0.000001,1.),5.0);\nfloat diffuseFresnelNL=pow(clamp(1.0-NdotV,0.000001,1.),5.0);\nfloat diffuseFresnel90=0.5+2.0*VdotH*VdotH*roughness;\nfloat diffuseFresnelTerm =\n(1.0+(diffuseFresnel90-1.0)*diffuseFresnelNL) *\n(1.0+(diffuseFresnel90-1.0)*diffuseFresnelNV);\nreturn diffuseFresnelTerm*NdotL;\n\n\n}\nfloat adjustRoughnessFromLightProperties(float roughness,float lightRadius,float lightDistance)\n{\n#ifdef USEPHYSICALLIGHTFALLOFF\n\nfloat lightRoughness=lightRadius/lightDistance;\n\nfloat totalRoughness=clamp(lightRoughness+roughness,0.,1.);\nreturn totalRoughness;\n#else\nreturn roughness;\n#endif\n}\nfloat computeDefaultMicroSurface(float microSurface,vec3 reflectivityColor)\n{\nfloat kReflectivityNoAlphaWorkflow_SmoothnessMax=0.95;\nfloat reflectivityLuminance=getLuminance(reflectivityColor);\nfloat reflectivityLuma=sqrt(reflectivityLuminance);\nmicroSurface=reflectivityLuma*kReflectivityNoAlphaWorkflow_SmoothnessMax;\nreturn microSurface;\n}\n#ifdef CAMERATONEMAP\nvec3 toneMaps(vec3 color)\n{\ncolor=max(color,0.0);\n\ncolor.rgb=color.rgb*vCameraInfos.x;\nfloat tuning=1.5; \n\n\nvec3 tonemapped=1.0-exp2(-color.rgb*tuning); \ncolor.rgb=mix(color.rgb,tonemapped,1.0);\nreturn color;\n}\n#endif\n#ifdef CAMERACONTRAST\nvec4 contrasts(vec4 color)\n{\ncolor=clamp(color,0.0,1.0);\nvec3 resultHighContrast=color.rgb*color.rgb*(3.0-2.0*color.rgb);\nfloat contrast=vCameraInfos.y;\nif (contrast<1.0)\n{\n\ncolor.rgb=mix(vec3(0.5,0.5,0.5),color.rgb,contrast);\n}\nelse\n{\n\ncolor.rgb=mix(color.rgb,resultHighContrast,contrast-1.0);\n}\nreturn color;\n}\n#endif\n#ifdef USESPHERICALFROMREFLECTIONMAP\nuniform vec3 vSphericalX;\nuniform vec3 vSphericalY;\nuniform vec3 vSphericalZ;\nuniform vec3 vSphericalXX;\nuniform vec3 vSphericalYY;\nuniform vec3 vSphericalZZ;\nuniform vec3 vSphericalXY;\nuniform vec3 vSphericalYZ;\nuniform vec3 vSphericalZX;\nvec3 EnvironmentIrradiance(vec3 normal)\n{\n\n\n\nvec3 result =\nvSphericalX*normal.x +\nvSphericalY*normal.y +\nvSphericalZ*normal.z +\nvSphericalXX*normal.x*normal.x +\nvSphericalYY*normal.y*normal.y +\nvSphericalZZ*normal.z*normal.z +\nvSphericalYZ*normal.y*normal.z +\nvSphericalZX*normal.z*normal.x +\nvSphericalXY*normal.x*normal.y;\nreturn result.rgb;\n}\n#endif";
  7749. BABYLON.Effect.IncludesShadersStore['legacyPbrLightFunctions'] = "\nstruct lightingInfo\n{\nvec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n};\nfloat computeDistanceLightFalloff(vec3 lightOffset,float lightDistanceSquared,float range)\n{ \n#ifdef USEPHYSICALLIGHTFALLOFF\nfloat lightDistanceFalloff=1.0/((lightDistanceSquared+0.0001));\n#else\nfloat lightDistanceFalloff=max(0.,1.0-length(lightOffset)/range);\n#endif\nreturn lightDistanceFalloff;\n}\nfloat computeDirectionalLightFalloff(vec3 lightDirection,vec3 directionToLightCenterW,float lightAngle,float exponent)\n{\nfloat falloff=0.0;\n#ifdef USEPHYSICALLIGHTFALLOFF\nfloat cosHalfAngle=cos(lightAngle*0.5);\nconst float kMinusLog2ConeAngleIntensityRatio=6.64385618977; \n\n\n\n\n\nfloat concentrationKappa=kMinusLog2ConeAngleIntensityRatio/(1.0-cosHalfAngle);\n\n\nvec4 lightDirectionSpreadSG=vec4(-lightDirection*concentrationKappa,-concentrationKappa);\nfalloff=exp2(dot(vec4(directionToLightCenterW,1.0),lightDirectionSpreadSG));\n#else\nfloat cosAngle=max(0.000000000000001,dot(-lightDirection,directionToLightCenterW));\nif (cosAngle>=lightAngle)\n{\nfalloff=max(0.,pow(cosAngle,exponent));\n}\n#endif\nreturn falloff;\n}\nlightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float rangeRadius,float roughness,float NdotV,vec3 reflectance90,out float NdotL) {\nlightingInfo result;\nvec3 lightDirection;\nfloat attenuation=1.0;\nfloat lightDistance;\n\nif (lightData.w == 0.)\n{\nvec3 lightOffset=lightData.xyz-vPositionW;\nfloat lightDistanceSquared=dot(lightOffset,lightOffset);\nattenuation=computeDistanceLightFalloff(lightOffset,lightDistanceSquared,rangeRadius);\nlightDistance=sqrt(lightDistanceSquared);\nlightDirection=normalize(lightOffset);\n}\n\nelse\n{\nlightDistance=length(-lightData.xyz);\nlightDirection=normalize(-lightData.xyz);\n}\n\nroughness=adjustRoughnessFromLightProperties(roughness,rangeRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW+lightDirection);\nNdotL=max(0.00000000001,dot(vNormal,lightDirection));\nfloat VdotH=clamp(0.00000000001,1.0,dot(viewDirectionW,H));\nfloat diffuseTerm=computeDiffuseTerm(NdotL,NdotV,VdotH,roughness);\nresult.diffuse=diffuseTerm*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nfloat NdotH=max(0.00000000001,dot(vNormal,H));\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,specularColor,reflectance90);\nresult.specular=specTerm*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float rangeRadius,float roughness,float NdotV,vec3 reflectance90,out float NdotL) {\nlightingInfo result;\nvec3 lightOffset=lightData.xyz-vPositionW;\nvec3 directionToLightCenterW=normalize(lightOffset);\n\nfloat lightDistanceSquared=dot(lightOffset,lightOffset);\nfloat attenuation=computeDistanceLightFalloff(lightOffset,lightDistanceSquared,rangeRadius);\n\nfloat directionalAttenuation=computeDirectionalLightFalloff(lightDirection.xyz,directionToLightCenterW,lightDirection.w,lightData.w);\nattenuation*=directionalAttenuation;\n\nfloat lightDistance=sqrt(lightDistanceSquared);\nroughness=adjustRoughnessFromLightProperties(roughness,rangeRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW+directionToLightCenterW);\nNdotL=max(0.00000000001,dot(vNormal,directionToLightCenterW));\nfloat VdotH=clamp(dot(viewDirectionW,H),0.00000000001,1.0);\nfloat diffuseTerm=computeDiffuseTerm(NdotL,NdotV,VdotH,roughness);\nresult.diffuse=diffuseTerm*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nfloat NdotH=max(0.00000000001,dot(vNormal,H));\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,specularColor,reflectance90);\nresult.specular=specTerm*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float roughness,float NdotV,vec3 reflectance90,out float NdotL) {\nlightingInfo result;\n\n\n\nNdotL=dot(vNormal,lightData.xyz)*0.5+0.5;\nresult.diffuse=mix(groundColor,diffuseColor,NdotL);\n#ifdef SPECULARTERM\n\nvec3 lightVectorW=normalize(lightData.xyz);\nvec3 H=normalize(viewDirectionW+lightVectorW);\nfloat NdotH=max(0.00000000001,dot(vNormal,H));\nNdotL=max(0.00000000001,NdotL);\nfloat VdotH=clamp(0.00000000001,1.0,dot(viewDirectionW,H));\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,specularColor,reflectance90);\nresult.specular=specTerm;\n#endif\nreturn result;\n}";
  7750. BABYLON.Effect.IncludesShadersStore['legacyPbrLightFunctionsCall'] = "#ifdef LIGHT{X}\n#if defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X}) && defined(LIGHTMAPNOSPECULAR{X})\n\n#else\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR90,NdotL);\n#endif\n#ifdef HEMILIGHT{X}\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightGround,roughness,NdotV,specularEnvironmentR90,NdotL);\n#endif\n#if defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR90,NdotL);\n#endif\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWESM{X}\n#if defined(SHADOWCUBE{X})\nnotShadowLevel=computeShadowWithESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nnotShadowLevel=computeShadowWithESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,0.0);\n#endif\n#else\n#ifdef SHADOWPCF{X}\n#if defined(SHADOWCUBE{X})\nnotShadowLevel=computeShadowWithPCFCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nnotShadowLevel=computeShadowWithPCF(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,0.0);\n#endif\n#else\n#if defined(SHADOWCUBE{X})\nnotShadowLevel=computeShadowCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nnotShadowLevel=computeShadow(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,0.0);\n#endif\n#endif\n#endif\n#else\nnotShadowLevel=1.;\n#endif\n#if defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X})\nlightDiffuseContribution+=lightmapColor*notShadowLevel;\n#ifdef SPECULARTERM\n#ifndef LIGHTMAPNOSPECULAR{X}\nlightSpecularContribution+=info.specular*notShadowLevel*lightmapColor;\n#endif\n#endif\n#else\nlightDiffuseContribution+=info.diffuse*notShadowLevel;\n#ifdef OVERLOADEDSHADOWVALUES\nif (NdotL<0.000000000011)\n{\nnotShadowLevel=1.;\n}\nshadowedOnlyLightDiffuseContribution*=notShadowLevel;\n#endif\n#ifdef SPECULARTERM\nlightSpecularContribution+=info.specular*notShadowLevel;\n#endif\n#endif\n#endif";
  7751. BABYLON.Effect.IncludesShadersStore['legacyPbrUboDeclaration'] = "layout(std140,column_major) uniform;\nuniform Material\n{\nuniform vec2 vAlbedoInfos;\nuniform vec3 vAmbientInfos;\nuniform vec2 vOpacityInfos;\nuniform vec2 vEmissiveInfos;\nuniform vec2 vLightmapInfos;\nuniform vec3 vReflectivityInfos;\nuniform vec2 vMicroSurfaceSamplerInfos;\nuniform vec4 vRefractionInfos;\nuniform vec2 vReflectionInfos;\nuniform vec3 vBumpInfos;\nuniform mat4 albedoMatrix;\nuniform mat4 ambientMatrix;\nuniform mat4 opacityMatrix;\nuniform mat4 emissiveMatrix;\nuniform mat4 lightmapMatrix;\nuniform mat4 reflectivityMatrix;\nuniform mat4 microSurfaceSamplerMatrix;\nuniform mat4 bumpMatrix;\nuniform vec2 vTangentSpaceParams;\nuniform mat4 refractionMatrix;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionColor;\nuniform vec4 vAlbedoColor;\nuniform vec4 vLightingIntensity;\nuniform vec2 vMicrosurfaceTextureLods;\nuniform vec4 vReflectivityColor;\nuniform vec3 vEmissiveColor;\nuniform vec4 opacityParts;\nuniform vec4 emissiveLeftColor;\nuniform vec4 emissiveRightColor;\nuniform vec4 vOverloadedIntensity;\nuniform vec3 vOverloadedAmbient;\nuniform vec3 vOverloadedAlbedo;\nuniform vec3 vOverloadedReflectivity;\nuniform vec3 vOverloadedEmissive;\nuniform vec3 vOverloadedReflection;\nuniform vec3 vOverloadedMicroSurface;\nuniform vec4 vOverloadedShadowIntensity;\nuniform float pointSize;\n};\nuniform Scene {\nmat4 viewProjection;\nmat4 view;\n};";
  7752. BABYLON.Effect.IncludesShadersStore['legacyPbrVertexDeclaration'] = "uniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef ALBEDO\nuniform mat4 albedoMatrix;\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;\nuniform vec3 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\nuniform mat4 lightmapMatrix;\n#endif\n#if defined(REFLECTIVITY) || defined(METALLICWORKFLOW) \nuniform vec3 vReflectivityInfos;\nuniform mat4 reflectivityMatrix;\n#endif\n#ifdef MICROSURFACEMAP\nuniform vec2 vMicroSurfaceSamplerInfos;\nuniform mat4 microSurfaceSamplerMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n";
  7753. BABYLON.Effect.IncludesShadersStore['legacyColorCurves'] = "const vec3 HDTVRec709_RGBLuminanceCoefficients=vec3(0.2126,0.7152,0.0722);\nvec3 applyColorCurves(vec3 original) {\nvec3 result=original;\n\n\n\nfloat luma=dot(result.rgb,HDTVRec709_RGBLuminanceCoefficients);\nvec2 curveMix=clamp(vec2(luma*3.0-1.5,luma*-3.0+1.5),vec2(0.0,0.0),vec2(1.0,1.0));\nvec4 colorCurve=vCameraColorCurveNeutral+curveMix.x*vCameraColorCurvePositive-curveMix.y*vCameraColorCurveNegative;\nresult.rgb*=colorCurve.rgb;\nresult.rgb=mix(vec3(luma,luma,luma),result.rgb,colorCurve.a);\nreturn result;\n}";
  7754. BABYLON.Effect.IncludesShadersStore['legacyColorCurvesDefinition'] = "uniform vec4 vCameraColorCurveNeutral;\nuniform vec4 vCameraColorCurvePositive;\nuniform vec4 vCameraColorCurveNegative;";
  7755. BABYLON.Effect.IncludesShadersStore['legacyColorGrading'] = "vec4 colorGrades(vec4 color) \n{ \n\nfloat sliceContinuous=color.z*vCameraColorGradingInfos.z;\nfloat sliceInteger=floor(sliceContinuous);\n\n\nfloat sliceFraction=sliceContinuous-sliceInteger; \n\nvec2 sliceUV=color.xy*vCameraColorGradingScaleOffset.xy+vCameraColorGradingScaleOffset.zw;\n\n\nsliceUV.x+=sliceInteger*vCameraColorGradingInfos.w;\nvec4 slice0Color=texture2D(cameraColorGrading2DSampler,sliceUV);\nsliceUV.x+=vCameraColorGradingInfos.w;\nvec4 slice1Color=texture2D(cameraColorGrading2DSampler,sliceUV);\nvec3 result=mix(slice0Color.rgb,slice1Color.rgb,sliceFraction);\ncolor.rgb=mix(color.rgb,result,vCameraColorGradingInfos.x);\nreturn color;\n}";
  7756. BABYLON.Effect.IncludesShadersStore['legacyColorGradingDefinition'] = "uniform sampler2D cameraColorGrading2DSampler;\nuniform vec4 vCameraColorGradingInfos;\nuniform vec4 vCameraColorGradingScaleOffset;";
  7757. var BABYLON;
  7758. (function (BABYLON) {
  7759. /**
  7760. * Background material defines definition.
  7761. */
  7762. var BackgroundMaterialDefines = /** @class */ (function (_super) {
  7763. __extends(BackgroundMaterialDefines, _super);
  7764. /**
  7765. * Constructor of the defines.
  7766. */
  7767. function BackgroundMaterialDefines() {
  7768. var _this = _super.call(this) || this;
  7769. /**
  7770. * True if the opacity texture is in use.
  7771. */
  7772. _this.OPACITY = false;
  7773. /**
  7774. * The direct UV channel to use.
  7775. */
  7776. _this.OPACITYDIRECTUV = 0;
  7777. /**
  7778. * True if the opacity texture is used in gray scale.
  7779. */
  7780. _this.OPACITYRGB = false;
  7781. /**
  7782. * True if the environment texture is in use.
  7783. */
  7784. _this.ENVIRONMENT = false;
  7785. /**
  7786. * True if the environment is defined in gamma space.
  7787. */
  7788. _this.GAMMAENVIRONMENT = false;
  7789. /**
  7790. * True if the environment texture does not contain background dedicated data.
  7791. * The material will fallback to use the luminance of the background.
  7792. */
  7793. _this.RGBENVIRONMENT = false;
  7794. /**
  7795. * True if an extra blur needs to be added in the environment.
  7796. */
  7797. _this.ENVIRONMENTBLUR = false;
  7798. /**
  7799. * False if the current Webgl implementation does not support the texture lod extension.
  7800. */
  7801. _this.TEXTURELODSUPPORT = false;
  7802. /**
  7803. * True if you want the material to fade to the environment color at grazing angle.
  7804. */
  7805. _this.OPACITYFRESNEL = false;
  7806. /**
  7807. * True if you want the shadow being generated from the diffuse color of the light.
  7808. * It is actually using 1 - diffuse to adpat the color to the color not reflected
  7809. * by the target.
  7810. */
  7811. _this.SHADOWFROMLIGHTCOLOR = false;
  7812. // Image Processing Configuration.
  7813. _this.IMAGEPROCESSING = false;
  7814. _this.VIGNETTE = false;
  7815. _this.VIGNETTEBLENDMODEMULTIPLY = false;
  7816. _this.VIGNETTEBLENDMODEOPAQUE = false;
  7817. _this.TONEMAPPING = false;
  7818. _this.CONTRAST = false;
  7819. _this.COLORCURVES = false;
  7820. _this.COLORGRADING = false;
  7821. _this.COLORGRADING3D = false;
  7822. _this.SAMPLER3DGREENDEPTH = false;
  7823. _this.SAMPLER3DBGRMAP = false;
  7824. _this.IMAGEPROCESSINGPOSTPROCESS = false;
  7825. _this.EXPOSURE = false;
  7826. // Default BJS.
  7827. _this.MAINUV1 = false;
  7828. _this.MAINUV2 = false;
  7829. _this.UV1 = false;
  7830. _this.UV2 = false;
  7831. _this.CLIPPLANE = false;
  7832. _this.POINTSIZE = false;
  7833. _this.FOG = false;
  7834. _this.NORMAL = false;
  7835. _this.NUM_BONE_INFLUENCERS = 0;
  7836. _this.BonesPerMesh = 0;
  7837. _this.INSTANCES = false;
  7838. _this.SHADOWFLOAT = false;
  7839. _this.rebuild();
  7840. return _this;
  7841. }
  7842. return BackgroundMaterialDefines;
  7843. }(BABYLON.MaterialDefines));
  7844. /**
  7845. * Background material
  7846. */
  7847. var BackgroundMaterial = /** @class */ (function (_super) {
  7848. __extends(BackgroundMaterial, _super);
  7849. /**
  7850. * constructor
  7851. * @param name The name of the material
  7852. * @param scene The scene to add the material to
  7853. */
  7854. function BackgroundMaterial(name, scene) {
  7855. var _this = _super.call(this, name, scene) || this;
  7856. _this.primaryColor = BABYLON.Color3.White();
  7857. _this.primaryLevel = 1;
  7858. _this.secondaryColor = BABYLON.Color3.Gray();
  7859. _this.secondaryLevel = 1;
  7860. _this.thirdColor = BABYLON.Color3.Black();
  7861. _this.thirdLevel = 1;
  7862. _this.environmentTexture = null;
  7863. _this.opacityTexture = null;
  7864. _this.environmentBlur = 0;
  7865. _this.lightChannelsInTexture = false;
  7866. /**
  7867. * Specify the list of lights casting shadow on the material.
  7868. * All scene shadow lights will be included if null.
  7869. */
  7870. _this._shadowLights = null;
  7871. _this.shadowLights = null;
  7872. _this.shadowBlurScale = 1;
  7873. _this.shadowLevel = 0;
  7874. _this.opacityFresnel = true;
  7875. /**
  7876. * Keep track of the image processing observer to allow dispose and replace.
  7877. */
  7878. _this._imageProcessingObserver = null;
  7879. /**
  7880. * Number of Simultaneous lights allowed on the material.
  7881. */
  7882. _this._maxSimultaneousLights = 4;
  7883. // Temp values kept as cache in the material.
  7884. _this._renderTargets = new BABYLON.SmartArray(16);
  7885. // Setup the default processing configuration to the scene.
  7886. _this._attachImageProcessingConfiguration(null);
  7887. _this.getRenderTargetTextures = function () {
  7888. _this._renderTargets.reset();
  7889. if (_this._opacityTexture && _this._opacityTexture.isRenderTarget) {
  7890. _this._renderTargets.push(_this._opacityTexture);
  7891. }
  7892. if (_this._environmentTexture && _this._environmentTexture.isRenderTarget) {
  7893. _this._renderTargets.push(_this._environmentTexture);
  7894. }
  7895. return _this._renderTargets;
  7896. };
  7897. return _this;
  7898. }
  7899. /**
  7900. * Attaches a new image processing configuration to the PBR Material.
  7901. * @param configuration (if null the scene configuration will be use)
  7902. */
  7903. BackgroundMaterial.prototype._attachImageProcessingConfiguration = function (configuration) {
  7904. var _this = this;
  7905. if (configuration === this._imageProcessingConfiguration) {
  7906. return;
  7907. }
  7908. // Detaches observer.
  7909. if (this._imageProcessingConfiguration && this._imageProcessingObserver) {
  7910. this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);
  7911. }
  7912. // Pick the scene configuration if needed.
  7913. if (!configuration) {
  7914. this._imageProcessingConfiguration = this.getScene().imageProcessingConfiguration;
  7915. }
  7916. else {
  7917. this._imageProcessingConfiguration = configuration;
  7918. }
  7919. // Attaches observer.
  7920. this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(function (conf) {
  7921. _this._markAllSubMeshesAsImageProcessingDirty();
  7922. });
  7923. };
  7924. Object.defineProperty(BackgroundMaterial.prototype, "imageProcessingConfiguration", {
  7925. /**
  7926. * Gets the image processing configuration used either in this material.
  7927. */
  7928. get: function () {
  7929. return this._imageProcessingConfiguration;
  7930. },
  7931. /**
  7932. * Sets the Default image processing configuration used either in the this material.
  7933. *
  7934. * If sets to null, the scene one is in use.
  7935. */
  7936. set: function (value) {
  7937. this._attachImageProcessingConfiguration(value);
  7938. // Ensure the effect will be rebuilt.
  7939. this._markAllSubMeshesAsTexturesDirty();
  7940. },
  7941. enumerable: true,
  7942. configurable: true
  7943. });
  7944. Object.defineProperty(BackgroundMaterial.prototype, "cameraColorCurvesEnabled", {
  7945. /**
  7946. * Gets wether the color curves effect is enabled.
  7947. */
  7948. get: function () {
  7949. return this.imageProcessingConfiguration.colorCurvesEnabled;
  7950. },
  7951. /**
  7952. * Sets wether the color curves effect is enabled.
  7953. */
  7954. set: function (value) {
  7955. this.imageProcessingConfiguration.colorCurvesEnabled = value;
  7956. },
  7957. enumerable: true,
  7958. configurable: true
  7959. });
  7960. Object.defineProperty(BackgroundMaterial.prototype, "cameraColorGradingEnabled", {
  7961. /**
  7962. * Gets wether the color grading effect is enabled.
  7963. */
  7964. get: function () {
  7965. return this.imageProcessingConfiguration.colorGradingEnabled;
  7966. },
  7967. /**
  7968. * Gets wether the color grading effect is enabled.
  7969. */
  7970. set: function (value) {
  7971. this.imageProcessingConfiguration.colorGradingEnabled = value;
  7972. },
  7973. enumerable: true,
  7974. configurable: true
  7975. });
  7976. Object.defineProperty(BackgroundMaterial.prototype, "cameraToneMappingEnabled", {
  7977. /**
  7978. * Gets wether tonemapping is enabled or not.
  7979. */
  7980. get: function () {
  7981. return this._imageProcessingConfiguration.toneMappingEnabled;
  7982. },
  7983. /**
  7984. * Sets wether tonemapping is enabled or not
  7985. */
  7986. set: function (value) {
  7987. this._imageProcessingConfiguration.toneMappingEnabled = value;
  7988. },
  7989. enumerable: true,
  7990. configurable: true
  7991. });
  7992. ;
  7993. ;
  7994. Object.defineProperty(BackgroundMaterial.prototype, "cameraExposure", {
  7995. /**
  7996. * The camera exposure used on this material.
  7997. * This property is here and not in the camera to allow controlling exposure without full screen post process.
  7998. * This corresponds to a photographic exposure.
  7999. */
  8000. get: function () {
  8001. return this._imageProcessingConfiguration.exposure;
  8002. },
  8003. /**
  8004. * The camera exposure used on this material.
  8005. * This property is here and not in the camera to allow controlling exposure without full screen post process.
  8006. * This corresponds to a photographic exposure.
  8007. */
  8008. set: function (value) {
  8009. this._imageProcessingConfiguration.exposure = value;
  8010. },
  8011. enumerable: true,
  8012. configurable: true
  8013. });
  8014. ;
  8015. ;
  8016. Object.defineProperty(BackgroundMaterial.prototype, "cameraContrast", {
  8017. /**
  8018. * Gets The camera contrast used on this material.
  8019. */
  8020. get: function () {
  8021. return this._imageProcessingConfiguration.contrast;
  8022. },
  8023. /**
  8024. * Sets The camera contrast used on this material.
  8025. */
  8026. set: function (value) {
  8027. this._imageProcessingConfiguration.contrast = value;
  8028. },
  8029. enumerable: true,
  8030. configurable: true
  8031. });
  8032. Object.defineProperty(BackgroundMaterial.prototype, "cameraColorGradingTexture", {
  8033. /**
  8034. * Gets the Color Grading 2D Lookup Texture.
  8035. */
  8036. get: function () {
  8037. return this._imageProcessingConfiguration.colorGradingTexture;
  8038. },
  8039. /**
  8040. * Sets the Color Grading 2D Lookup Texture.
  8041. */
  8042. set: function (value) {
  8043. this.imageProcessingConfiguration.colorGradingTexture = value;
  8044. },
  8045. enumerable: true,
  8046. configurable: true
  8047. });
  8048. Object.defineProperty(BackgroundMaterial.prototype, "cameraColorCurves", {
  8049. /**
  8050. * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
  8051. * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
  8052. * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;
  8053. * corresponding to low luminance, medium luminance, and high luminance areas respectively.
  8054. */
  8055. get: function () {
  8056. return this.imageProcessingConfiguration.colorCurves;
  8057. },
  8058. /**
  8059. * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
  8060. * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
  8061. * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;
  8062. * corresponding to low luminance, medium luminance, and high luminance areas respectively.
  8063. */
  8064. set: function (value) {
  8065. this.imageProcessingConfiguration.colorCurves = value;
  8066. },
  8067. enumerable: true,
  8068. configurable: true
  8069. });
  8070. /**
  8071. * The entire material has been created in order to prevent overdraw.
  8072. * @returns false
  8073. */
  8074. BackgroundMaterial.prototype.needAlphaTesting = function () {
  8075. return false;
  8076. };
  8077. /**
  8078. * The entire material has been created in order to prevent overdraw.
  8079. * @returns false
  8080. */
  8081. BackgroundMaterial.prototype.needAlphaBlending = function () {
  8082. return false;
  8083. };
  8084. /**
  8085. * Gets the environment texture to use in the material.
  8086. * @returns the texture
  8087. */
  8088. BackgroundMaterial.prototype._getEnvironmentTexture = function () {
  8089. if (this._environmentTexture) {
  8090. return this._environmentTexture;
  8091. }
  8092. return this.getScene().environmentTexture;
  8093. };
  8094. /**
  8095. * Checks wether the material is ready to be rendered for a given mesh.
  8096. * @param mesh The mesh to render
  8097. * @param subMesh The submesh to check against
  8098. * @param useInstances Specify wether or not the material is used with instances
  8099. */
  8100. BackgroundMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  8101. var _this = this;
  8102. if (useInstances === void 0) { useInstances = false; }
  8103. if (subMesh.effect && this.isFrozen) {
  8104. if (this._wasPreviouslyReady) {
  8105. return true;
  8106. }
  8107. }
  8108. if (!subMesh._materialDefines) {
  8109. subMesh._materialDefines = new BackgroundMaterialDefines();
  8110. }
  8111. var scene = this.getScene();
  8112. var defines = subMesh._materialDefines;
  8113. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  8114. if (defines._renderId === scene.getRenderId()) {
  8115. return true;
  8116. }
  8117. }
  8118. var engine = scene.getEngine();
  8119. // Lights
  8120. BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights);
  8121. defines._needNormals = true;
  8122. // Textures
  8123. if (defines._areTexturesDirty) {
  8124. defines._needUVs = false;
  8125. if (scene.texturesEnabled) {
  8126. if (scene.getEngine().getCaps().textureLOD) {
  8127. defines.TEXTURELODSUPPORT = true;
  8128. }
  8129. if (this._opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
  8130. if (!this._opacityTexture.isReadyOrNotBlocking()) {
  8131. return false;
  8132. }
  8133. BABYLON.MaterialHelper.PrepareDefinesForMergedUV(this._opacityTexture, defines, "OPACITY");
  8134. defines.OPACITYRGB = this._opacityTexture.getAlphaFromRGB;
  8135. defines.OPACITYFRESNEL = this._opacityFresnel;
  8136. }
  8137. else {
  8138. defines.OPACITY = false;
  8139. defines.OPACITYRGB = false;
  8140. defines.OPACITYFRESNEL = false;
  8141. }
  8142. var environmentTexture = this._getEnvironmentTexture();
  8143. if (environmentTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  8144. if (!environmentTexture.isReadyOrNotBlocking()) {
  8145. return false;
  8146. }
  8147. BABYLON.MaterialHelper.PrepareDefinesForMergedUV(environmentTexture, defines, "ENVIRONMENT");
  8148. defines.GAMMAENVIRONMENT = environmentTexture.gammaSpace;
  8149. defines.ENVIRONMENTBLUR = this._environmentBlur > 0;
  8150. defines.RGBENVIRONMENT = !this.lightChannelsInTexture;
  8151. }
  8152. else {
  8153. defines.ENVIRONMENT = false;
  8154. defines.GAMMAENVIRONMENT = false;
  8155. defines.RGBENVIRONMENT = false;
  8156. }
  8157. }
  8158. }
  8159. if (defines._areImageProcessingDirty) {
  8160. if (!this._imageProcessingConfiguration.isReady()) {
  8161. return false;
  8162. }
  8163. this._imageProcessingConfiguration.prepareDefines(defines);
  8164. }
  8165. // Misc.
  8166. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  8167. // Values that need to be evaluated on every frame
  8168. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances, false);
  8169. // Attribs
  8170. if (BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true, false)) {
  8171. if (mesh) {
  8172. if (!scene.getEngine().getCaps().standardDerivatives && !mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  8173. mesh.createNormals(true);
  8174. BABYLON.Tools.Warn("BackgroundMaterial: Normals have been created for the mesh: " + mesh.name);
  8175. }
  8176. }
  8177. }
  8178. // Get correct effect
  8179. if (defines.isDirty) {
  8180. defines.markAsProcessed();
  8181. scene.resetCachedMaterial();
  8182. // Fallbacks
  8183. var fallbacks = new BABYLON.EffectFallbacks();
  8184. if (defines.FOG) {
  8185. fallbacks.addFallback(0, "FOG");
  8186. }
  8187. if (defines.POINTSIZE) {
  8188. fallbacks.addFallback(1, "POINTSIZE");
  8189. }
  8190. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this._maxSimultaneousLights);
  8191. if (defines.NUM_BONE_INFLUENCERS > 0) {
  8192. fallbacks.addCPUSkinningFallback(0, mesh);
  8193. }
  8194. //Attributes
  8195. var attribs = [BABYLON.VertexBuffer.PositionKind];
  8196. if (defines.NORMAL) {
  8197. attribs.push(BABYLON.VertexBuffer.NormalKind);
  8198. }
  8199. if (defines.UV1) {
  8200. attribs.push(BABYLON.VertexBuffer.UVKind);
  8201. }
  8202. if (defines.UV2) {
  8203. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  8204. }
  8205. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  8206. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  8207. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType",
  8208. "vFogInfos", "vFogColor", "pointSize",
  8209. "vClipPlane", "mBones",
  8210. "vPrimaryColor", "vSecondaryColor", "vThirdColor",
  8211. "vEnvironmentInfo", "environmentMatrix", "vEnvironmentMicrosurfaceInfos",
  8212. "shadowLevel",
  8213. "vOpacityInfo", "opacityMatrix",
  8214. ];
  8215. var samplers = ["opacitySampler", "environmentSampler", "environmentSamplerLow", "environmentSamplerHigh"];
  8216. var uniformBuffers = ["Material", "Scene"];
  8217. BABYLON.ImageProcessingConfiguration.PrepareUniforms(uniforms, defines);
  8218. BABYLON.ImageProcessingConfiguration.PrepareSamplers(samplers, defines);
  8219. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  8220. uniformsNames: uniforms,
  8221. uniformBuffersNames: uniformBuffers,
  8222. samplers: samplers,
  8223. defines: defines,
  8224. maxSimultaneousLights: this._maxSimultaneousLights
  8225. });
  8226. var onCompiled = function (effect) {
  8227. if (_this.onCompiled) {
  8228. _this.onCompiled(effect);
  8229. }
  8230. _this.bindSceneUniformBuffer(effect, scene.getSceneUniformBuffer());
  8231. };
  8232. var join = defines.toString();
  8233. subMesh.setEffect(scene.getEngine().createEffect("background", {
  8234. attributes: attribs,
  8235. uniformsNames: uniforms,
  8236. uniformBuffersNames: uniformBuffers,
  8237. samplers: samplers,
  8238. defines: join,
  8239. fallbacks: fallbacks,
  8240. onCompiled: onCompiled,
  8241. onError: this.onError,
  8242. indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights }
  8243. }, engine), defines);
  8244. this.buildUniformLayout();
  8245. }
  8246. if (!subMesh.effect || !subMesh.effect.isReady()) {
  8247. return false;
  8248. }
  8249. defines._renderId = scene.getRenderId();
  8250. this._wasPreviouslyReady = true;
  8251. return true;
  8252. };
  8253. /**
  8254. * Build the uniform buffer used in the material.
  8255. */
  8256. BackgroundMaterial.prototype.buildUniformLayout = function () {
  8257. // Order is important !
  8258. this._uniformBuffer.addUniform("vPrimaryColor", 4);
  8259. this._uniformBuffer.addUniform("vSecondaryColor", 4);
  8260. this._uniformBuffer.addUniform("vThirdColor", 4);
  8261. this._uniformBuffer.addUniform("vOpacityInfo", 2);
  8262. this._uniformBuffer.addUniform("vEnvironmentInfo", 2);
  8263. this._uniformBuffer.addUniform("opacityMatrix", 16);
  8264. this._uniformBuffer.addUniform("environmentMatrix", 16);
  8265. this._uniformBuffer.addUniform("vEnvironmentMicrosurfaceInfos", 3);
  8266. this._uniformBuffer.addUniform("pointSize", 1);
  8267. this._uniformBuffer.addUniform("shadowLevel", 1);
  8268. this._uniformBuffer.create();
  8269. };
  8270. /**
  8271. * Unbind the material.
  8272. */
  8273. BackgroundMaterial.prototype.unbind = function () {
  8274. if (this._opacityTexture && this._opacityTexture.isRenderTarget) {
  8275. this._uniformBuffer.setTexture("opacitySampler", null);
  8276. }
  8277. if (this._environmentTexture && this._environmentTexture.isRenderTarget) {
  8278. this._uniformBuffer.setTexture("environmentSampler", null);
  8279. }
  8280. _super.prototype.unbind.call(this);
  8281. };
  8282. /**
  8283. * Bind only the world matrix to the material.
  8284. * @param world The world matrix to bind.
  8285. */
  8286. BackgroundMaterial.prototype.bindOnlyWorldMatrix = function (world) {
  8287. this._activeEffect.setMatrix("world", world);
  8288. };
  8289. /**
  8290. * Bind the material for a dedicated submeh (every used meshes will be considered opaque).
  8291. * @param world The world matrix to bind.
  8292. * @param subMesh The submesh to bind for.
  8293. */
  8294. BackgroundMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  8295. var scene = this.getScene();
  8296. var defines = subMesh._materialDefines;
  8297. if (!defines) {
  8298. return;
  8299. }
  8300. var effect = subMesh.effect;
  8301. if (!effect) {
  8302. return;
  8303. }
  8304. this._activeEffect = effect;
  8305. // Matrices
  8306. this.bindOnlyWorldMatrix(world);
  8307. // Bones
  8308. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  8309. var mustRebind = this._mustRebind(scene, effect, mesh.visibility);
  8310. if (mustRebind) {
  8311. this._uniformBuffer.bindToEffect(effect, "Material");
  8312. this.bindViewProjection(effect);
  8313. var environmentTexture = this._getEnvironmentTexture();
  8314. if (!this._uniformBuffer.useUbo || !this.isFrozen || !this._uniformBuffer.isSync) {
  8315. // Texture uniforms
  8316. if (scene.texturesEnabled) {
  8317. if (this._opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
  8318. this._uniformBuffer.updateFloat2("vOpacityInfo", this._opacityTexture.coordinatesIndex, this._opacityTexture.level);
  8319. BABYLON.MaterialHelper.BindTextureMatrix(this._opacityTexture, this._uniformBuffer, "opacity");
  8320. }
  8321. if (environmentTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  8322. this._uniformBuffer.updateMatrix("environmentMatrix", environmentTexture.getReflectionTextureMatrix());
  8323. this._uniformBuffer.updateFloat2("vEnvironmentInfo", environmentTexture.level, this._environmentBlur);
  8324. this._uniformBuffer.updateFloat3("vEnvironmentMicrosurfaceInfos", environmentTexture.getSize().width, environmentTexture.lodGenerationScale, environmentTexture.lodGenerationOffset);
  8325. }
  8326. }
  8327. if (this.shadowLevel > 0) {
  8328. this._uniformBuffer.updateFloat("shadowLevel", this.shadowLevel);
  8329. }
  8330. // Point size
  8331. if (this.pointsCloud) {
  8332. this._uniformBuffer.updateFloat("pointSize", this.pointSize);
  8333. }
  8334. this._uniformBuffer.updateColor4("vPrimaryColor", this._primaryColor, this._primaryLevel);
  8335. this._uniformBuffer.updateColor4("vSecondaryColor", this._secondaryColor, this._secondaryLevel);
  8336. this._uniformBuffer.updateColor4("vThirdColor", this._thirdColor, this._thirdLevel);
  8337. }
  8338. // Textures
  8339. if (scene.texturesEnabled) {
  8340. if (this._opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
  8341. this._uniformBuffer.setTexture("opacitySampler", this._opacityTexture);
  8342. }
  8343. if (environmentTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  8344. if (defines.ENVIRONMENTBLUR && defines.TEXTURELODSUPPORT) {
  8345. this._uniformBuffer.setTexture("environmentSampler", environmentTexture);
  8346. }
  8347. else if (!defines.ENVIRONMENTBLUR) {
  8348. this._uniformBuffer.setTexture("environmentSampler", environmentTexture);
  8349. }
  8350. else {
  8351. this._uniformBuffer.setTexture("environmentSampler", environmentTexture._lodTextureMid || environmentTexture);
  8352. this._uniformBuffer.setTexture("environmentSamplerLow", environmentTexture._lodTextureLow || environmentTexture);
  8353. this._uniformBuffer.setTexture("environmentSamplerHigh", environmentTexture._lodTextureHigh || environmentTexture);
  8354. }
  8355. }
  8356. }
  8357. // Clip plane
  8358. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  8359. var eyePosition = scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.globalPosition;
  8360. // var invertNormal = (scene.useRightHandedSystem === (scene._mirroredCameraPosition != null));
  8361. effect.setFloat3("vEyePosition", eyePosition.x, eyePosition.y, eyePosition.z);
  8362. }
  8363. if (mustRebind || !this.isFrozen) {
  8364. if (scene.lightsEnabled) {
  8365. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this._maxSimultaneousLights, false);
  8366. }
  8367. // View
  8368. this.bindView(effect);
  8369. // Fog
  8370. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  8371. // image processing
  8372. this._imageProcessingConfiguration.bind(this._activeEffect);
  8373. }
  8374. this._uniformBuffer.update();
  8375. this._afterBind(mesh);
  8376. };
  8377. /**
  8378. * Dispose the material.
  8379. * @forceDisposeEffect Force disposal of the associated effect.
  8380. * @forceDisposeTextures Force disposal of the associated textures.
  8381. */
  8382. BackgroundMaterial.prototype.dispose = function (forceDisposeEffect, forceDisposeTextures) {
  8383. if (forceDisposeEffect === void 0) { forceDisposeEffect = false; }
  8384. if (forceDisposeTextures === void 0) { forceDisposeTextures = false; }
  8385. if (forceDisposeTextures) {
  8386. if (this.opacityTexture) {
  8387. this.opacityTexture.dispose();
  8388. }
  8389. if (this.environmentTexture) {
  8390. this.environmentTexture.dispose();
  8391. }
  8392. }
  8393. this._renderTargets.dispose();
  8394. if (this._imageProcessingConfiguration && this._imageProcessingObserver) {
  8395. this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);
  8396. }
  8397. _super.prototype.dispose.call(this, forceDisposeEffect);
  8398. };
  8399. /**
  8400. * Clones the material.
  8401. * @name The cloned name.
  8402. * @returns The cloned material.
  8403. */
  8404. BackgroundMaterial.prototype.clone = function (name) {
  8405. var _this = this;
  8406. return BABYLON.SerializationHelper.Clone(function () { return new BackgroundMaterial(name, _this.getScene()); }, this);
  8407. };
  8408. /**
  8409. * Serializes the current material to its JSON representation.
  8410. * @returns The JSON representation.
  8411. */
  8412. BackgroundMaterial.prototype.serialize = function () {
  8413. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  8414. serializationObject.customType = "BABYLON.BackgroundMaterial";
  8415. return serializationObject;
  8416. };
  8417. /**
  8418. * Gets the class name of the material
  8419. * @returns "BackgroundMaterial"
  8420. */
  8421. BackgroundMaterial.prototype.getClassName = function () {
  8422. return "BackgroundMaterial";
  8423. };
  8424. /**
  8425. * Parse a JSON input to create back a background material.
  8426. * @param source
  8427. * @param scene
  8428. * @param rootUrl
  8429. * @returns the instantiated BackgroundMaterial.
  8430. */
  8431. BackgroundMaterial.Parse = function (source, scene, rootUrl) {
  8432. return BABYLON.SerializationHelper.Parse(function () { return new BackgroundMaterial(source.name, scene); }, source, scene, rootUrl);
  8433. };
  8434. __decorate([
  8435. BABYLON.serializeAsColor3()
  8436. ], BackgroundMaterial.prototype, "_primaryColor", void 0);
  8437. __decorate([
  8438. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  8439. ], BackgroundMaterial.prototype, "primaryColor", void 0);
  8440. __decorate([
  8441. BABYLON.serialize()
  8442. ], BackgroundMaterial.prototype, "_primaryLevel", void 0);
  8443. __decorate([
  8444. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  8445. ], BackgroundMaterial.prototype, "primaryLevel", void 0);
  8446. __decorate([
  8447. BABYLON.serializeAsColor3()
  8448. ], BackgroundMaterial.prototype, "_secondaryColor", void 0);
  8449. __decorate([
  8450. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  8451. ], BackgroundMaterial.prototype, "secondaryColor", void 0);
  8452. __decorate([
  8453. BABYLON.serialize()
  8454. ], BackgroundMaterial.prototype, "_secondaryLevel", void 0);
  8455. __decorate([
  8456. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  8457. ], BackgroundMaterial.prototype, "secondaryLevel", void 0);
  8458. __decorate([
  8459. BABYLON.serializeAsColor3()
  8460. ], BackgroundMaterial.prototype, "_thirdColor", void 0);
  8461. __decorate([
  8462. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  8463. ], BackgroundMaterial.prototype, "thirdColor", void 0);
  8464. __decorate([
  8465. BABYLON.serialize()
  8466. ], BackgroundMaterial.prototype, "_thirdLevel", void 0);
  8467. __decorate([
  8468. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  8469. ], BackgroundMaterial.prototype, "thirdLevel", void 0);
  8470. __decorate([
  8471. BABYLON.serializeAsTexture()
  8472. ], BackgroundMaterial.prototype, "_environmentTexture", void 0);
  8473. __decorate([
  8474. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  8475. ], BackgroundMaterial.prototype, "environmentTexture", void 0);
  8476. __decorate([
  8477. BABYLON.serializeAsTexture()
  8478. ], BackgroundMaterial.prototype, "_opacityTexture", void 0);
  8479. __decorate([
  8480. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  8481. ], BackgroundMaterial.prototype, "opacityTexture", void 0);
  8482. __decorate([
  8483. BABYLON.serialize()
  8484. ], BackgroundMaterial.prototype, "_environmentBlur", void 0);
  8485. __decorate([
  8486. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  8487. ], BackgroundMaterial.prototype, "environmentBlur", void 0);
  8488. __decorate([
  8489. BABYLON.serialize()
  8490. ], BackgroundMaterial.prototype, "_lightChannelsInTexture", void 0);
  8491. __decorate([
  8492. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  8493. ], BackgroundMaterial.prototype, "lightChannelsInTexture", void 0);
  8494. __decorate([
  8495. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  8496. ], BackgroundMaterial.prototype, "shadowLights", void 0);
  8497. __decorate([
  8498. BABYLON.serialize()
  8499. ], BackgroundMaterial.prototype, "_shadowBlurScale", void 0);
  8500. __decorate([
  8501. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  8502. ], BackgroundMaterial.prototype, "shadowBlurScale", void 0);
  8503. __decorate([
  8504. BABYLON.serialize()
  8505. ], BackgroundMaterial.prototype, "_shadowLevel", void 0);
  8506. __decorate([
  8507. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  8508. ], BackgroundMaterial.prototype, "shadowLevel", void 0);
  8509. __decorate([
  8510. BABYLON.serialize()
  8511. ], BackgroundMaterial.prototype, "_opacityFresnel", void 0);
  8512. __decorate([
  8513. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  8514. ], BackgroundMaterial.prototype, "opacityFresnel", void 0);
  8515. __decorate([
  8516. BABYLON.serializeAsImageProcessingConfiguration()
  8517. ], BackgroundMaterial.prototype, "_imageProcessingConfiguration", void 0);
  8518. return BackgroundMaterial;
  8519. }(BABYLON.PushMaterial));
  8520. BABYLON.BackgroundMaterial = BackgroundMaterial;
  8521. })(BABYLON || (BABYLON = {}));
  8522. //# sourceMappingURL=babylon.backgroundMaterial.js.map
  8523. BABYLON.Effect.ShadersStore['backgroundVertexShader'] = "precision highp float;\n#include<__decl__backgroundVertex>\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2; \n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nvarying vec2 vOpacityUV;\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\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normal);\n#endif\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uv;\n#endif \n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0 \nif (vOpacityInfo.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  8524. BABYLON.Effect.ShadersStore['backgroundPixelShader'] = "#ifdef TEXTURELODSUPPORT\n#extension GL_EXT_shader_texture_lod : enable\n#endif\nprecision highp float;\n#include<__decl__backgroundFragment>\n\nuniform vec3 vEyePosition;\n\nvarying vec3 vPositionW;\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif \n#ifdef MAINUV2 \nvarying vec2 vMainUV2; \n#endif \n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef OPACITY\n#if OPACITYDIRECTUV == 1\n#define vOpacityUV vMainUV1\n#elif OPACITYDIRECTUV == 2\n#define vOpacityUV vMainUV2\n#else\nvarying vec2 vOpacityUV;\n#endif\nuniform sampler2D opacitySampler;\n#endif\n\n#ifdef ENVIRONMENT\n#define sampleEnvironment(s,c) textureCube(s,c)\nuniform samplerCube environmentSampler;\n#ifdef ENVIRONMENTBLUR\n#ifdef TEXTURELODSUPPORT\n#define sampleEnvironmentLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube environmentSamplerLow;\nuniform samplerCube environmentSamplerHigh;\n#endif\n#endif\n#endif\n\n#ifndef FROMLINEARSPACE\n#define FROMLINEARSPACE;\n#endif\n\n#ifndef SHADOWONLY\n#define SHADOWONLY;\n#endif\n#include<imageProcessingDeclaration>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<helperFunctions>\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<imageProcessingFunctions>\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(0.0,1.0,0.0);\n#endif\n\nfloat shadow=1.;\n#include<lightFragment>[0..maxSimultaneousLights]\n\n#ifdef ENVIRONMENT\nvec3 environmentColor=vec3(0.,0.,0.);\n\nvec3 environmentCoords=(vPositionW.xyz-vEyePosition.xyz);\n#ifdef INVERTCUBICMAP\nenvironmentCoords.y=1.0-environmentCoords.y;\n#endif\n\nenvironmentCoords=vec3(environmentMatrix*vec4(environmentCoords,0));\n#ifdef ENVIRONMENTBLUR\nfloat environmentLOD=vEnvironmentInfo.y;\n#ifdef TEXTURELODSUPPORT\n\nenvironmentLOD=environmentLOD*log2(vEnvironmentMicrosurfaceInfos.x)*vEnvironmentMicrosurfaceInfos.y+vEnvironmentMicrosurfaceInfos.z;\nenvironmentColor=sampleEnvironmentLod(environmentSampler,environmentCoords,environmentLOD).rgb;\n#else\nfloat lodEnvironmentNormalized=clamp(environmentLOD,0.,1.);\nfloat lodEnvironmentNormalizedDoubled=lodEnvironmentNormalized*2.0;\nvec3 environmentSpecularMid=sampleEnvironment(environmentSampler,environmentCoords).rgb;\nif(lodEnvironmentNormalizedDoubled<1.0){\nenvironmentColor=mix(\nsampleEnvironment(environmentSamplerHigh,environmentCoords).rgb,\nenvironmentSpecularMid,\nlodEnvironmentNormalizedDoubled\n);\n} else {\nenvironmentColor=mix(\nenvironmentSpecularMid,\nsampleEnvironment(environmentSamplerLow,environmentCoords).rgb,\nlodEnvironmentNormalizedDoubled-1.0\n);\n}\n#endif\n#else\nenvironmentColor=sampleEnvironment(environmentSampler,environmentCoords).rgb;\n#endif\n#ifdef GAMMAENVIRONMENT\nenvironmentColor=toLinearSpace(environmentColor.rgb);\n#endif\n\nenvironmentColor*=vEnvironmentInfo.x;\n\n#ifdef OPACITY\nvec3 reflectEnvironmentColor=vec3(0.,0.,0.);\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV);\n#ifdef OPACITYRGB\nfloat environmentMix=getLuminance(opacityMap.rgb);\n#else\nfloat environmentMix=opacityMap.a;\n#endif\nenvironmentMix*=vOpacityInfo.y;\n#ifdef OPACITYFRESNEL\n\nfloat viewAngleToFloor=dot(normalW,normalize(vEyePosition));\n\nconst float startAngle=0.1;\nfloat fadeFactor=clamp(viewAngleToFloor/startAngle,0.0,1.0);\nenvironmentMix*=fadeFactor*fadeFactor;\nshadow=mix(1.,shadow,environmentMix);\n#endif\n\nvec3 viewDir=vPositionW.xyz-vEyePosition.xyz;\nvec3 reflectEnvironmentCoords=reflect(viewDir,normalW);\n#ifdef INVERTCUBICMAP\nreflectEnvironmentCoords.y=1.0-reflectEnvironmentCoords.y;\n#endif\n\nreflectEnvironmentCoords=vec3(environmentMatrix*vec4(reflectEnvironmentCoords,0));\n#ifdef ENVIRONMENTBLUR\n#ifdef TEXTURELODSUPPORT\n\nreflectEnvironmentColor=sampleEnvironmentLod(environmentSampler,reflectEnvironmentCoords,environmentLOD).rgb;\n#else\nvec3 reflectEnvironmentSpecularMid=sampleEnvironment(environmentSampler,reflectEnvironmentCoords).rgb;\nif(lodEnvironmentNormalizedDoubled<1.0){\nreflectEnvironmentColor=mix(\nsampleEnvironment(environmentSamplerHigh,reflectEnvironmentCoords).rgb,\nenvironmentSpecularMid,\nlodEnvironmentNormalizedDoubled\n);\n} else {\nreflectEnvironmentColor=mix(\nenvironmentSpecularMid,\nsampleEnvironment(environmentSamplerLow,reflectEnvironmentCoords).rgb,\nlodEnvironmentNormalizedDoubled-1.0\n);\n}\n#endif\n#else\nreflectEnvironmentColor=sampleEnvironment(environmentSampler,reflectEnvironmentCoords).rgb;\n#endif\n#ifdef GAMMAENVIRONMENT\nreflectEnvironmentColor=toLinearSpace(reflectEnvironmentColor.rgb);\n#endif\n\nreflectEnvironmentColor*=vEnvironmentInfo.x;\n\nenvironmentColor=mix(environmentColor,reflectEnvironmentColor,environmentMix);\n#endif\n#else\nvec3 environmentColor=vec3(1.,1.,1.);\n#endif\n\n#ifdef RGBENVIRONMENT\nenvironmentColor=vec3(1.,1.,1.)*getLuminance(environmentColor);\n#endif\n\nvec3 colorBase=environmentColor.r*vPrimaryColor.rgb*vPrimaryColor.a;\ncolorBase+=environmentColor.g*vSecondaryColor.rgb*vSecondaryColor.a;\ncolorBase+=environmentColor.b*vThirdColor.rgb*vThirdColor.a;\ncolorBase=mix(colorBase*shadowLevel,colorBase,shadow);\nvec4 color=vec4(colorBase,1.0);\n#include<fogFragment>\n#ifdef IMAGEPROCESSINGPOSTPROCESS\n\n\ncolor.rgb=clamp(color.rgb,0.,30.0);\n#else\n\ncolor=applyImageProcessing(color);\n#endif\ngl_FragColor=color;\n}";
  8525. BABYLON.Effect.IncludesShadersStore['backgroundFragmentDeclaration'] = " uniform vec4 vPrimaryColor;\nuniform vec4 vSecondaryColor;\nuniform vec4 vThirdColor;\nuniform float shadowLevel;\n#ifdef OPACITY\nuniform vec2 vOpacityInfo;\n#endif\n#ifdef ENVIRONMENT\nuniform vec2 vEnvironmentInfo;\nuniform mat4 environmentMatrix;\nuniform vec3 vEnvironmentMicrosurfaceInfos;\n#endif";
  8526. BABYLON.Effect.IncludesShadersStore['backgroundUboDeclaration'] = "layout(std140,column_major) uniform;\nuniform Material\n{\nuniform vec4 vPrimaryColor;\nuniform vec4 vSecondaryColor;\nuniform vec4 vThirdColor;\nuniform vec2 vOpacityInfo;\nuniform vec2 vEnvironmentInfo;\nuniform mat4 opacityMatrix;\nuniform mat4 environmentMatrix;\nuniform vec3 vEnvironmentMicrosurfaceInfos;\nuniform float pointSize;\nuniform float shadowLevel;\n};\nuniform Scene {\nmat4 viewProjection;\nmat4 view;\n};";
  8527. BABYLON.Effect.IncludesShadersStore['backgroundVertexDeclaration'] = "uniform mat4 view;\nuniform mat4 viewProjection;\nuniform float shadowLevel;\n#ifdef OPACITY\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfo;\n#endif\n#ifdef ENVIRONMENT\nuniform vec2 vEnvironmentInfo;\nuniform mat4 environmentMatrix;\nuniform vec3 vEnvionmentMicrosurfaceInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif";
  8528. (function universalModuleDefinition(root, factory) {
  8529. if (root && root["BABYLON"]) {
  8530. return;
  8531. }
  8532. if(typeof exports === 'object' && typeof module === 'object')
  8533. module.exports = factory();
  8534. else if(typeof define === 'function' && define.amd)
  8535. define([], factory);
  8536. else if(typeof exports === 'object')
  8537. exports["BJSMaterials"] = factory();
  8538. else {
  8539. root["BABYLON"] = factory();
  8540. }
  8541. })(this, function() {
  8542. return BABYLON;
  8543. });