babylonjs.materials.js 338 KB

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