babylonjs.materials.js 384 KB

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