babylonjs.materials.js 455 KB

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