babylonjs.materials.js 456 KB

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