babylonjs.materials.js 389 KB

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