babylonjs.materials.js 336 KB

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