babylonjs.materials.js 315 KB

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