babylonjs.materials.js 282 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008
  1. (function universalModuleDefinition(root, factory) {
  2. var amdDependencies = [];
  3. var BABYLON = root.BABYLON || this.BABYLON;
  4. if(typeof exports === 'object' && typeof module === 'object') {
  5. BABYLON = BABYLON || require("babylonjs");
  6. module.exports = factory(BABYLON);
  7. } else if(typeof define === 'function' && define.amd) {
  8. amdDependencies.push("babylonjs");
  9. define("babylonjs-materials", amdDependencies, factory);
  10. } else if(typeof exports === 'object') {
  11. BABYLON = BABYLON || require("babylonjs");
  12. exports["babylonjs-materials"] = factory(BABYLON);
  13. } else {
  14. root["BABYLON"] = factory(BABYLON);
  15. }
  16. })(this, function(BABYLON) {
  17. BABYLON = BABYLON || this.BABYLON;
  18. var __decorate=this&&this.__decorate||function(e,t,r,c){var o,f=arguments.length,n=f<3?t:null===c?c=Object.getOwnPropertyDescriptor(t,r):c;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,c);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(n=(f<3?o(n):f>3?o(t,r,n):o(t,r))||n);return f>3&&n&&Object.defineProperty(t,r,n),n};
  19. var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o}||function(t,o){for(var n in o)o.hasOwnProperty(n)&&(t[n]=o[n])};return function(o,n){function r(){this.constructor=o}t(o,n),o.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();
  20. var BABYLON;
  21. (function (BABYLON) {
  22. var ShadowOnlyMaterialDefines = /** @class */ (function (_super) {
  23. __extends(ShadowOnlyMaterialDefines, _super);
  24. function ShadowOnlyMaterialDefines() {
  25. var _this = _super.call(this) || this;
  26. _this.CLIPPLANE = false;
  27. _this.CLIPPLANE2 = false;
  28. _this.CLIPPLANE3 = false;
  29. _this.CLIPPLANE4 = false;
  30. _this.POINTSIZE = false;
  31. _this.FOG = false;
  32. _this.NORMAL = false;
  33. _this.NUM_BONE_INFLUENCERS = 0;
  34. _this.BonesPerMesh = 0;
  35. _this.INSTANCES = false;
  36. _this.rebuild();
  37. return _this;
  38. }
  39. return ShadowOnlyMaterialDefines;
  40. }(BABYLON.MaterialDefines));
  41. var ShadowOnlyMaterial = /** @class */ (function (_super) {
  42. __extends(ShadowOnlyMaterial, _super);
  43. function ShadowOnlyMaterial(name, scene) {
  44. var _this = _super.call(this, name, scene) || this;
  45. _this.shadowColor = BABYLON.Color3.Black();
  46. return _this;
  47. }
  48. ShadowOnlyMaterial.prototype.needAlphaBlending = function () {
  49. return true;
  50. };
  51. ShadowOnlyMaterial.prototype.needAlphaTesting = function () {
  52. return false;
  53. };
  54. ShadowOnlyMaterial.prototype.getAlphaTestTexture = function () {
  55. return null;
  56. };
  57. Object.defineProperty(ShadowOnlyMaterial.prototype, "activeLight", {
  58. get: function () {
  59. return this._activeLight;
  60. },
  61. set: function (light) {
  62. this._activeLight = light;
  63. },
  64. enumerable: true,
  65. configurable: true
  66. });
  67. // Methods
  68. ShadowOnlyMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  69. if (this.isFrozen) {
  70. if (this._wasPreviouslyReady && subMesh.effect) {
  71. return true;
  72. }
  73. }
  74. if (!subMesh._materialDefines) {
  75. subMesh._materialDefines = new ShadowOnlyMaterialDefines();
  76. }
  77. var defines = subMesh._materialDefines;
  78. var scene = this.getScene();
  79. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  80. if (this._renderId === scene.getRenderId()) {
  81. return true;
  82. }
  83. }
  84. var engine = scene.getEngine();
  85. // Ensure that active light is the first shadow light
  86. if (this._activeLight) {
  87. for (var _i = 0, _a = mesh._lightSources; _i < _a.length; _i++) {
  88. var light = _a[_i];
  89. if (light.shadowEnabled) {
  90. if (this._activeLight === light) {
  91. break; // We are good
  92. }
  93. var lightPosition = mesh._lightSources.indexOf(this._activeLight);
  94. if (lightPosition !== -1) {
  95. mesh._lightSources.splice(lightPosition, 1);
  96. mesh._lightSources.splice(0, 0, this._activeLight);
  97. }
  98. break;
  99. }
  100. }
  101. }
  102. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  103. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  104. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);
  105. // Attribs
  106. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
  107. // Get correct effect
  108. if (defines.isDirty) {
  109. defines.markAsProcessed();
  110. scene.resetCachedMaterial();
  111. // Fallbacks
  112. var fallbacks = new BABYLON.EffectFallbacks();
  113. if (defines.FOG) {
  114. fallbacks.addFallback(1, "FOG");
  115. }
  116. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, 1);
  117. if (defines.NUM_BONE_INFLUENCERS > 0) {
  118. fallbacks.addCPUSkinningFallback(0, mesh);
  119. }
  120. //Attributes
  121. var attribs = [BABYLON.VertexBuffer.PositionKind];
  122. if (defines.NORMAL) {
  123. attribs.push(BABYLON.VertexBuffer.NormalKind);
  124. }
  125. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  126. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  127. var shaderName = "shadowOnly";
  128. var join = defines.toString();
  129. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType",
  130. "vFogInfos", "vFogColor", "pointSize", "alpha", "shadowColor",
  131. "mBones",
  132. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4"
  133. ];
  134. var samplers = new Array();
  135. var uniformBuffers = new Array();
  136. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  137. uniformsNames: uniforms,
  138. uniformBuffersNames: uniformBuffers,
  139. samplers: samplers,
  140. defines: defines,
  141. maxSimultaneousLights: 1
  142. });
  143. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  144. attributes: attribs,
  145. uniformsNames: uniforms,
  146. uniformBuffersNames: uniformBuffers,
  147. samplers: samplers,
  148. defines: join,
  149. fallbacks: fallbacks,
  150. onCompiled: this.onCompiled,
  151. onError: this.onError,
  152. indexParameters: { maxSimultaneousLights: 1 }
  153. }, engine), defines);
  154. }
  155. if (!subMesh.effect || !subMesh.effect.isReady()) {
  156. return false;
  157. }
  158. this._renderId = scene.getRenderId();
  159. this._wasPreviouslyReady = true;
  160. return true;
  161. };
  162. ShadowOnlyMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  163. var scene = this.getScene();
  164. var defines = subMesh._materialDefines;
  165. if (!defines) {
  166. return;
  167. }
  168. var effect = subMesh.effect;
  169. if (!effect) {
  170. return;
  171. }
  172. this._activeEffect = effect;
  173. // Matrices
  174. this.bindOnlyWorldMatrix(world);
  175. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  176. // Bones
  177. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  178. if (this._mustRebind(scene, effect)) {
  179. // Clip plane
  180. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  181. // Point size
  182. if (this.pointsCloud) {
  183. this._activeEffect.setFloat("pointSize", this.pointSize);
  184. }
  185. this._activeEffect.setFloat("alpha", this.alpha);
  186. this._activeEffect.setColor3("shadowColor", this.shadowColor);
  187. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  188. }
  189. // Lights
  190. if (scene.lightsEnabled) {
  191. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, 1);
  192. }
  193. // View
  194. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  195. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  196. }
  197. // Fog
  198. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  199. this._afterBind(mesh, this._activeEffect);
  200. };
  201. ShadowOnlyMaterial.prototype.clone = function (name) {
  202. var _this = this;
  203. return BABYLON.SerializationHelper.Clone(function () { return new ShadowOnlyMaterial(name, _this.getScene()); }, this);
  204. };
  205. ShadowOnlyMaterial.prototype.serialize = function () {
  206. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  207. serializationObject.customType = "BABYLON.ShadowOnlyMaterial";
  208. return serializationObject;
  209. };
  210. ShadowOnlyMaterial.prototype.getClassName = function () {
  211. return "ShadowOnlyMaterial";
  212. };
  213. // Statics
  214. ShadowOnlyMaterial.Parse = function (source, scene, rootUrl) {
  215. return BABYLON.SerializationHelper.Parse(function () { return new ShadowOnlyMaterial(source.name, scene); }, source, scene, rootUrl);
  216. };
  217. return ShadowOnlyMaterial;
  218. }(BABYLON.PushMaterial));
  219. BABYLON.ShadowOnlyMaterial = ShadowOnlyMaterial;
  220. })(BABYLON || (BABYLON = {}));
  221. //# sourceMappingURL=babylon.shadowOnlyMaterial.js.map
  222. BABYLON.Effect.ShadersStore['shadowOnlyVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  223. BABYLON.Effect.ShadersStore['shadowOnlyPixelShader'] = "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}";
  224. var BABYLON;
  225. (function (BABYLON) {
  226. var GradientMaterialDefines = /** @class */ (function (_super) {
  227. __extends(GradientMaterialDefines, _super);
  228. function GradientMaterialDefines() {
  229. var _this = _super.call(this) || this;
  230. _this.DIFFUSE = false;
  231. _this.CLIPPLANE = false;
  232. _this.CLIPPLANE2 = false;
  233. _this.CLIPPLANE3 = false;
  234. _this.CLIPPLANE4 = false;
  235. _this.ALPHATEST = false;
  236. _this.DEPTHPREPASS = false;
  237. _this.POINTSIZE = false;
  238. _this.FOG = false;
  239. _this.LIGHT0 = false;
  240. _this.LIGHT1 = false;
  241. _this.LIGHT2 = false;
  242. _this.LIGHT3 = false;
  243. _this.SPOTLIGHT0 = false;
  244. _this.SPOTLIGHT1 = false;
  245. _this.SPOTLIGHT2 = false;
  246. _this.SPOTLIGHT3 = false;
  247. _this.HEMILIGHT0 = false;
  248. _this.HEMILIGHT1 = false;
  249. _this.HEMILIGHT2 = false;
  250. _this.HEMILIGHT3 = false;
  251. _this.DIRLIGHT0 = false;
  252. _this.DIRLIGHT1 = false;
  253. _this.DIRLIGHT2 = false;
  254. _this.DIRLIGHT3 = false;
  255. _this.POINTLIGHT0 = false;
  256. _this.POINTLIGHT1 = false;
  257. _this.POINTLIGHT2 = false;
  258. _this.POINTLIGHT3 = false;
  259. _this.SHADOW0 = false;
  260. _this.SHADOW1 = false;
  261. _this.SHADOW2 = false;
  262. _this.SHADOW3 = false;
  263. _this.SHADOWS = false;
  264. _this.SHADOWESM0 = false;
  265. _this.SHADOWESM1 = false;
  266. _this.SHADOWESM2 = false;
  267. _this.SHADOWESM3 = false;
  268. _this.SHADOWPOISSON0 = false;
  269. _this.SHADOWPOISSON1 = false;
  270. _this.SHADOWPOISSON2 = false;
  271. _this.SHADOWPOISSON3 = false;
  272. _this.SHADOWPCF0 = false;
  273. _this.SHADOWPCF1 = false;
  274. _this.SHADOWPCF2 = false;
  275. _this.SHADOWPCF3 = false;
  276. _this.SHADOWPCSS0 = false;
  277. _this.SHADOWPCSS1 = false;
  278. _this.SHADOWPCSS2 = false;
  279. _this.SHADOWPCSS3 = false;
  280. _this.NORMAL = false;
  281. _this.UV1 = false;
  282. _this.UV2 = false;
  283. _this.VERTEXCOLOR = false;
  284. _this.VERTEXALPHA = false;
  285. _this.NUM_BONE_INFLUENCERS = 0;
  286. _this.BonesPerMesh = 0;
  287. _this.INSTANCES = false;
  288. _this.rebuild();
  289. return _this;
  290. }
  291. return GradientMaterialDefines;
  292. }(BABYLON.MaterialDefines));
  293. var GradientMaterial = /** @class */ (function (_super) {
  294. __extends(GradientMaterial, _super);
  295. function GradientMaterial(name, scene) {
  296. var _this = _super.call(this, name, scene) || this;
  297. _this._maxSimultaneousLights = 4;
  298. // The gradient top color, red by default
  299. _this.topColor = new BABYLON.Color3(1, 0, 0);
  300. _this.topColorAlpha = 1.0;
  301. // The gradient top color, blue by default
  302. _this.bottomColor = new BABYLON.Color3(0, 0, 1);
  303. _this.bottomColorAlpha = 1.0;
  304. // Gradient offset
  305. _this.offset = 0;
  306. _this.scale = 1.0;
  307. _this.smoothness = 1.0;
  308. _this.disableLighting = false;
  309. _this._scaledDiffuse = new BABYLON.Color3();
  310. return _this;
  311. }
  312. GradientMaterial.prototype.needAlphaBlending = function () {
  313. return (this.alpha < 1.0 || this.topColorAlpha < 1.0 || this.bottomColorAlpha < 1.0);
  314. };
  315. GradientMaterial.prototype.needAlphaTesting = function () {
  316. return true;
  317. };
  318. GradientMaterial.prototype.getAlphaTestTexture = function () {
  319. return null;
  320. };
  321. // Methods
  322. GradientMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  323. if (this.isFrozen) {
  324. if (this._wasPreviouslyReady && subMesh.effect) {
  325. return true;
  326. }
  327. }
  328. if (!subMesh._materialDefines) {
  329. subMesh._materialDefines = new GradientMaterialDefines();
  330. }
  331. var defines = subMesh._materialDefines;
  332. var scene = this.getScene();
  333. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  334. if (this._renderId === scene.getRenderId()) {
  335. return true;
  336. }
  337. }
  338. var engine = scene.getEngine();
  339. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  340. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  341. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights);
  342. // Attribs
  343. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
  344. // Get correct effect
  345. if (defines.isDirty) {
  346. defines.markAsProcessed();
  347. scene.resetCachedMaterial();
  348. // Fallbacks
  349. var fallbacks = new BABYLON.EffectFallbacks();
  350. if (defines.FOG) {
  351. fallbacks.addFallback(1, "FOG");
  352. }
  353. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
  354. if (defines.NUM_BONE_INFLUENCERS > 0) {
  355. fallbacks.addCPUSkinningFallback(0, mesh);
  356. }
  357. //Attributes
  358. var attribs = [BABYLON.VertexBuffer.PositionKind];
  359. if (defines.NORMAL) {
  360. attribs.push(BABYLON.VertexBuffer.NormalKind);
  361. }
  362. if (defines.UV1) {
  363. attribs.push(BABYLON.VertexBuffer.UVKind);
  364. }
  365. if (defines.UV2) {
  366. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  367. }
  368. if (defines.VERTEXCOLOR) {
  369. attribs.push(BABYLON.VertexBuffer.ColorKind);
  370. }
  371. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  372. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  373. // Legacy browser patch
  374. var shaderName = "gradient";
  375. var join = defines.toString();
  376. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  377. "vFogInfos", "vFogColor", "pointSize",
  378. "vDiffuseInfos",
  379. "mBones",
  380. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix",
  381. "topColor", "bottomColor", "offset", "smoothness", "scale"
  382. ];
  383. var samplers = ["diffuseSampler"];
  384. var uniformBuffers = new Array();
  385. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  386. uniformsNames: uniforms,
  387. uniformBuffersNames: uniformBuffers,
  388. samplers: samplers,
  389. defines: defines,
  390. maxSimultaneousLights: 4
  391. });
  392. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  393. attributes: attribs,
  394. uniformsNames: uniforms,
  395. uniformBuffersNames: uniformBuffers,
  396. samplers: samplers,
  397. defines: join,
  398. fallbacks: fallbacks,
  399. onCompiled: this.onCompiled,
  400. onError: this.onError,
  401. indexParameters: { maxSimultaneousLights: 4 }
  402. }, engine), defines);
  403. }
  404. if (!subMesh.effect || !subMesh.effect.isReady()) {
  405. return false;
  406. }
  407. this._renderId = scene.getRenderId();
  408. this._wasPreviouslyReady = true;
  409. return true;
  410. };
  411. GradientMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  412. var scene = this.getScene();
  413. var defines = subMesh._materialDefines;
  414. if (!defines) {
  415. return;
  416. }
  417. var effect = subMesh.effect;
  418. if (!effect) {
  419. return;
  420. }
  421. this._activeEffect = effect;
  422. // Matrices
  423. this.bindOnlyWorldMatrix(world);
  424. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  425. // Bones
  426. BABYLON.MaterialHelper.BindBonesParameters(mesh, effect);
  427. if (this._mustRebind(scene, effect)) {
  428. // Clip plane
  429. BABYLON.MaterialHelper.BindClipPlane(effect, scene);
  430. // Point size
  431. if (this.pointsCloud) {
  432. this._activeEffect.setFloat("pointSize", this.pointSize);
  433. }
  434. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  435. }
  436. this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  437. if (scene.lightsEnabled && !this.disableLighting) {
  438. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines);
  439. }
  440. // View
  441. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  442. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  443. }
  444. // Fog
  445. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  446. this._activeEffect.setColor4("topColor", this.topColor, this.topColorAlpha);
  447. this._activeEffect.setColor4("bottomColor", this.bottomColor, this.bottomColorAlpha);
  448. this._activeEffect.setFloat("offset", this.offset);
  449. this._activeEffect.setFloat("scale", this.scale);
  450. this._activeEffect.setFloat("smoothness", this.smoothness);
  451. this._afterBind(mesh, this._activeEffect);
  452. };
  453. GradientMaterial.prototype.getAnimatables = function () {
  454. return [];
  455. };
  456. GradientMaterial.prototype.dispose = function (forceDisposeEffect) {
  457. _super.prototype.dispose.call(this, forceDisposeEffect);
  458. };
  459. GradientMaterial.prototype.clone = function (name) {
  460. var _this = this;
  461. return BABYLON.SerializationHelper.Clone(function () { return new GradientMaterial(name, _this.getScene()); }, this);
  462. };
  463. GradientMaterial.prototype.serialize = function () {
  464. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  465. serializationObject.customType = "BABYLON.GradientMaterial";
  466. return serializationObject;
  467. };
  468. GradientMaterial.prototype.getClassName = function () {
  469. return "GradientMaterial";
  470. };
  471. // Statics
  472. GradientMaterial.Parse = function (source, scene, rootUrl) {
  473. return BABYLON.SerializationHelper.Parse(function () { return new GradientMaterial(source.name, scene); }, source, scene, rootUrl);
  474. };
  475. __decorate([
  476. BABYLON.serialize("maxSimultaneousLights")
  477. ], GradientMaterial.prototype, "_maxSimultaneousLights", void 0);
  478. __decorate([
  479. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  480. ], GradientMaterial.prototype, "maxSimultaneousLights", void 0);
  481. __decorate([
  482. BABYLON.serializeAsColor3()
  483. ], GradientMaterial.prototype, "topColor", void 0);
  484. __decorate([
  485. BABYLON.serialize()
  486. ], GradientMaterial.prototype, "topColorAlpha", void 0);
  487. __decorate([
  488. BABYLON.serializeAsColor3()
  489. ], GradientMaterial.prototype, "bottomColor", void 0);
  490. __decorate([
  491. BABYLON.serialize()
  492. ], GradientMaterial.prototype, "bottomColorAlpha", void 0);
  493. __decorate([
  494. BABYLON.serialize()
  495. ], GradientMaterial.prototype, "offset", void 0);
  496. __decorate([
  497. BABYLON.serialize()
  498. ], GradientMaterial.prototype, "scale", void 0);
  499. __decorate([
  500. BABYLON.serialize()
  501. ], GradientMaterial.prototype, "smoothness", void 0);
  502. __decorate([
  503. BABYLON.serialize()
  504. ], GradientMaterial.prototype, "disableLighting", void 0);
  505. return GradientMaterial;
  506. }(BABYLON.PushMaterial));
  507. BABYLON.GradientMaterial = GradientMaterial;
  508. })(BABYLON || (BABYLON = {}));
  509. //# sourceMappingURL=babylon.gradientMaterial.js.map
  510. BABYLON.Effect.ShadersStore['gradientVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\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";
  511. BABYLON.Effect.ShadersStore['gradientPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nuniform vec4 topColor;\nuniform vec4 bottomColor;\nuniform float offset;\nuniform float 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";
  512. var BABYLON;
  513. (function (BABYLON) {
  514. var NormalMaterialDefines = /** @class */ (function (_super) {
  515. __extends(NormalMaterialDefines, _super);
  516. function NormalMaterialDefines() {
  517. var _this = _super.call(this) || this;
  518. _this.DIFFUSE = false;
  519. _this.CLIPPLANE = false;
  520. _this.CLIPPLANE2 = false;
  521. _this.CLIPPLANE3 = false;
  522. _this.CLIPPLANE4 = false;
  523. _this.ALPHATEST = false;
  524. _this.DEPTHPREPASS = false;
  525. _this.POINTSIZE = false;
  526. _this.FOG = false;
  527. _this.LIGHT0 = false;
  528. _this.LIGHT1 = false;
  529. _this.LIGHT2 = false;
  530. _this.LIGHT3 = false;
  531. _this.SPOTLIGHT0 = false;
  532. _this.SPOTLIGHT1 = false;
  533. _this.SPOTLIGHT2 = false;
  534. _this.SPOTLIGHT3 = false;
  535. _this.HEMILIGHT0 = false;
  536. _this.HEMILIGHT1 = false;
  537. _this.HEMILIGHT2 = false;
  538. _this.HEMILIGHT3 = false;
  539. _this.DIRLIGHT0 = false;
  540. _this.DIRLIGHT1 = false;
  541. _this.DIRLIGHT2 = false;
  542. _this.DIRLIGHT3 = false;
  543. _this.POINTLIGHT0 = false;
  544. _this.POINTLIGHT1 = false;
  545. _this.POINTLIGHT2 = false;
  546. _this.POINTLIGHT3 = false;
  547. _this.SHADOW0 = false;
  548. _this.SHADOW1 = false;
  549. _this.SHADOW2 = false;
  550. _this.SHADOW3 = false;
  551. _this.SHADOWS = false;
  552. _this.SHADOWESM0 = false;
  553. _this.SHADOWESM1 = false;
  554. _this.SHADOWESM2 = false;
  555. _this.SHADOWESM3 = false;
  556. _this.SHADOWPOISSON0 = false;
  557. _this.SHADOWPOISSON1 = false;
  558. _this.SHADOWPOISSON2 = false;
  559. _this.SHADOWPOISSON3 = false;
  560. _this.SHADOWPCF0 = false;
  561. _this.SHADOWPCF1 = false;
  562. _this.SHADOWPCF2 = false;
  563. _this.SHADOWPCF3 = false;
  564. _this.SHADOWPCSS0 = false;
  565. _this.SHADOWPCSS1 = false;
  566. _this.SHADOWPCSS2 = false;
  567. _this.SHADOWPCSS3 = false;
  568. _this.NORMAL = false;
  569. _this.UV1 = false;
  570. _this.UV2 = false;
  571. _this.VERTEXCOLOR = false;
  572. _this.VERTEXALPHA = false;
  573. _this.NUM_BONE_INFLUENCERS = 0;
  574. _this.BonesPerMesh = 0;
  575. _this.INSTANCES = false;
  576. _this.rebuild();
  577. return _this;
  578. }
  579. return NormalMaterialDefines;
  580. }(BABYLON.MaterialDefines));
  581. var NormalMaterial = /** @class */ (function (_super) {
  582. __extends(NormalMaterial, _super);
  583. function NormalMaterial(name, scene) {
  584. var _this = _super.call(this, name, scene) || this;
  585. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  586. _this._disableLighting = false;
  587. _this._maxSimultaneousLights = 4;
  588. return _this;
  589. }
  590. NormalMaterial.prototype.needAlphaBlending = function () {
  591. return (this.alpha < 1.0);
  592. };
  593. NormalMaterial.prototype.needAlphaTesting = function () {
  594. return false;
  595. };
  596. NormalMaterial.prototype.getAlphaTestTexture = function () {
  597. return null;
  598. };
  599. // Methods
  600. NormalMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  601. if (this.isFrozen) {
  602. if (this._wasPreviouslyReady && subMesh.effect) {
  603. return true;
  604. }
  605. }
  606. if (!subMesh._materialDefines) {
  607. subMesh._materialDefines = new NormalMaterialDefines();
  608. }
  609. var defines = subMesh._materialDefines;
  610. var scene = this.getScene();
  611. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  612. if (this._renderId === scene.getRenderId()) {
  613. return true;
  614. }
  615. }
  616. var engine = scene.getEngine();
  617. // Textures
  618. if (defines._areTexturesDirty) {
  619. defines._needUVs = false;
  620. if (scene.texturesEnabled) {
  621. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  622. if (!this._diffuseTexture.isReady()) {
  623. return false;
  624. }
  625. else {
  626. defines._needUVs = true;
  627. defines.DIFFUSE = true;
  628. }
  629. }
  630. }
  631. }
  632. // Misc.
  633. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  634. // Lights
  635. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  636. // Values that need to be evaluated on every frame
  637. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  638. // Attribs
  639. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  640. // Get correct effect
  641. if (defines.isDirty) {
  642. defines.markAsProcessed();
  643. scene.resetCachedMaterial();
  644. // Fallbacks
  645. var fallbacks = new BABYLON.EffectFallbacks();
  646. if (defines.FOG) {
  647. fallbacks.addFallback(1, "FOG");
  648. }
  649. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
  650. if (defines.NUM_BONE_INFLUENCERS > 0) {
  651. fallbacks.addCPUSkinningFallback(0, mesh);
  652. }
  653. //Attributes
  654. var attribs = [BABYLON.VertexBuffer.PositionKind];
  655. if (defines.NORMAL) {
  656. attribs.push(BABYLON.VertexBuffer.NormalKind);
  657. }
  658. if (defines.UV1) {
  659. attribs.push(BABYLON.VertexBuffer.UVKind);
  660. }
  661. if (defines.UV2) {
  662. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  663. }
  664. if (defines.VERTEXCOLOR) {
  665. attribs.push(BABYLON.VertexBuffer.ColorKind);
  666. }
  667. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  668. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  669. var shaderName = "normal";
  670. var join = defines.toString();
  671. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  672. "vFogInfos", "vFogColor", "pointSize",
  673. "vDiffuseInfos",
  674. "mBones",
  675. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix"
  676. ];
  677. var samplers = ["diffuseSampler"];
  678. var uniformBuffers = new Array();
  679. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  680. uniformsNames: uniforms,
  681. uniformBuffersNames: uniformBuffers,
  682. samplers: samplers,
  683. defines: defines,
  684. maxSimultaneousLights: 4
  685. });
  686. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  687. attributes: attribs,
  688. uniformsNames: uniforms,
  689. uniformBuffersNames: uniformBuffers,
  690. samplers: samplers,
  691. defines: join,
  692. fallbacks: fallbacks,
  693. onCompiled: this.onCompiled,
  694. onError: this.onError,
  695. indexParameters: { maxSimultaneousLights: 4 }
  696. }, engine), defines);
  697. }
  698. if (!subMesh.effect || !subMesh.effect.isReady()) {
  699. return false;
  700. }
  701. this._renderId = scene.getRenderId();
  702. this._wasPreviouslyReady = true;
  703. return true;
  704. };
  705. NormalMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  706. var scene = this.getScene();
  707. var defines = subMesh._materialDefines;
  708. if (!defines) {
  709. return;
  710. }
  711. var effect = subMesh.effect;
  712. if (!effect) {
  713. return;
  714. }
  715. this._activeEffect = effect;
  716. // Matrices
  717. this.bindOnlyWorldMatrix(world);
  718. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  719. // Bones
  720. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  721. if (this._mustRebind(scene, effect)) {
  722. // Textures
  723. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  724. this._activeEffect.setTexture("diffuseSampler", this.diffuseTexture);
  725. this._activeEffect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
  726. this._activeEffect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
  727. }
  728. // Clip plane
  729. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  730. // Point size
  731. if (this.pointsCloud) {
  732. this._activeEffect.setFloat("pointSize", this.pointSize);
  733. }
  734. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  735. }
  736. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  737. // Lights
  738. if (scene.lightsEnabled && !this.disableLighting) {
  739. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines);
  740. }
  741. // View
  742. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  743. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  744. }
  745. // Fog
  746. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  747. this._afterBind(mesh, this._activeEffect);
  748. };
  749. NormalMaterial.prototype.getAnimatables = function () {
  750. var results = [];
  751. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  752. results.push(this.diffuseTexture);
  753. }
  754. return results;
  755. };
  756. NormalMaterial.prototype.getActiveTextures = function () {
  757. var activeTextures = _super.prototype.getActiveTextures.call(this);
  758. if (this._diffuseTexture) {
  759. activeTextures.push(this._diffuseTexture);
  760. }
  761. return activeTextures;
  762. };
  763. NormalMaterial.prototype.hasTexture = function (texture) {
  764. if (_super.prototype.hasTexture.call(this, texture)) {
  765. return true;
  766. }
  767. if (this.diffuseTexture === texture) {
  768. return true;
  769. }
  770. return false;
  771. };
  772. NormalMaterial.prototype.dispose = function (forceDisposeEffect) {
  773. if (this.diffuseTexture) {
  774. this.diffuseTexture.dispose();
  775. }
  776. _super.prototype.dispose.call(this, forceDisposeEffect);
  777. };
  778. NormalMaterial.prototype.clone = function (name) {
  779. var _this = this;
  780. return BABYLON.SerializationHelper.Clone(function () { return new NormalMaterial(name, _this.getScene()); }, this);
  781. };
  782. NormalMaterial.prototype.serialize = function () {
  783. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  784. serializationObject.customType = "BABYLON.NormalMaterial";
  785. return serializationObject;
  786. };
  787. NormalMaterial.prototype.getClassName = function () {
  788. return "NormalMaterial";
  789. };
  790. // Statics
  791. NormalMaterial.Parse = function (source, scene, rootUrl) {
  792. return BABYLON.SerializationHelper.Parse(function () { return new NormalMaterial(source.name, scene); }, source, scene, rootUrl);
  793. };
  794. __decorate([
  795. BABYLON.serializeAsTexture("diffuseTexture")
  796. ], NormalMaterial.prototype, "_diffuseTexture", void 0);
  797. __decorate([
  798. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  799. ], NormalMaterial.prototype, "diffuseTexture", void 0);
  800. __decorate([
  801. BABYLON.serializeAsColor3()
  802. ], NormalMaterial.prototype, "diffuseColor", void 0);
  803. __decorate([
  804. BABYLON.serialize("disableLighting")
  805. ], NormalMaterial.prototype, "_disableLighting", void 0);
  806. __decorate([
  807. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  808. ], NormalMaterial.prototype, "disableLighting", void 0);
  809. __decorate([
  810. BABYLON.serialize("maxSimultaneousLights")
  811. ], NormalMaterial.prototype, "_maxSimultaneousLights", void 0);
  812. __decorate([
  813. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  814. ], NormalMaterial.prototype, "maxSimultaneousLights", void 0);
  815. return NormalMaterial;
  816. }(BABYLON.PushMaterial));
  817. BABYLON.NormalMaterial = NormalMaterial;
  818. })(BABYLON || (BABYLON = {}));
  819. //# sourceMappingURL=babylon.normalMaterial.js.map
  820. BABYLON.Effect.ShadersStore['normalVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  821. BABYLON.Effect.ShadersStore['normalPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0]\n#include<__decl__lightFragment>[1]\n#include<__decl__lightFragment>[2]\n#include<__decl__lightFragment>[3]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef NORMAL\nbaseColor=mix(baseColor,vec4(vNormalW,1.0),0.5);\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#include<lightFragment>[0]\n#include<lightFragment>[1]\n#include<lightFragment>[2]\n#include<lightFragment>[3]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
  822. var BABYLON;
  823. (function (BABYLON) {
  824. var LavaMaterialDefines = /** @class */ (function (_super) {
  825. __extends(LavaMaterialDefines, _super);
  826. function LavaMaterialDefines() {
  827. var _this = _super.call(this) || this;
  828. _this.DIFFUSE = false;
  829. _this.CLIPPLANE = false;
  830. _this.CLIPPLANE2 = false;
  831. _this.CLIPPLANE3 = false;
  832. _this.CLIPPLANE4 = false;
  833. _this.ALPHATEST = false;
  834. _this.DEPTHPREPASS = false;
  835. _this.POINTSIZE = false;
  836. _this.FOG = false;
  837. _this.LIGHT0 = false;
  838. _this.LIGHT1 = false;
  839. _this.LIGHT2 = false;
  840. _this.LIGHT3 = false;
  841. _this.SPOTLIGHT0 = false;
  842. _this.SPOTLIGHT1 = false;
  843. _this.SPOTLIGHT2 = false;
  844. _this.SPOTLIGHT3 = false;
  845. _this.HEMILIGHT0 = false;
  846. _this.HEMILIGHT1 = false;
  847. _this.HEMILIGHT2 = false;
  848. _this.HEMILIGHT3 = false;
  849. _this.DIRLIGHT0 = false;
  850. _this.DIRLIGHT1 = false;
  851. _this.DIRLIGHT2 = false;
  852. _this.DIRLIGHT3 = false;
  853. _this.POINTLIGHT0 = false;
  854. _this.POINTLIGHT1 = false;
  855. _this.POINTLIGHT2 = false;
  856. _this.POINTLIGHT3 = false;
  857. _this.SHADOW0 = false;
  858. _this.SHADOW1 = false;
  859. _this.SHADOW2 = false;
  860. _this.SHADOW3 = false;
  861. _this.SHADOWS = false;
  862. _this.SHADOWESM0 = false;
  863. _this.SHADOWESM1 = false;
  864. _this.SHADOWESM2 = false;
  865. _this.SHADOWESM3 = false;
  866. _this.SHADOWPOISSON0 = false;
  867. _this.SHADOWPOISSON1 = false;
  868. _this.SHADOWPOISSON2 = false;
  869. _this.SHADOWPOISSON3 = false;
  870. _this.SHADOWPCF0 = false;
  871. _this.SHADOWPCF1 = false;
  872. _this.SHADOWPCF2 = false;
  873. _this.SHADOWPCF3 = false;
  874. _this.SHADOWPCSS0 = false;
  875. _this.SHADOWPCSS1 = false;
  876. _this.SHADOWPCSS2 = false;
  877. _this.SHADOWPCSS3 = false;
  878. _this.NORMAL = false;
  879. _this.UV1 = false;
  880. _this.UV2 = false;
  881. _this.VERTEXCOLOR = false;
  882. _this.VERTEXALPHA = false;
  883. _this.NUM_BONE_INFLUENCERS = 0;
  884. _this.BonesPerMesh = 0;
  885. _this.INSTANCES = false;
  886. _this.rebuild();
  887. return _this;
  888. }
  889. return LavaMaterialDefines;
  890. }(BABYLON.MaterialDefines));
  891. var LavaMaterial = /** @class */ (function (_super) {
  892. __extends(LavaMaterial, _super);
  893. function LavaMaterial(name, scene) {
  894. var _this = _super.call(this, name, scene) || this;
  895. _this.speed = 1;
  896. _this.movingSpeed = 1;
  897. _this.lowFrequencySpeed = 1;
  898. _this.fogDensity = 0.15;
  899. _this._lastTime = 0;
  900. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  901. _this._disableLighting = false;
  902. _this._maxSimultaneousLights = 4;
  903. _this._scaledDiffuse = new BABYLON.Color3();
  904. return _this;
  905. }
  906. LavaMaterial.prototype.needAlphaBlending = function () {
  907. return (this.alpha < 1.0);
  908. };
  909. LavaMaterial.prototype.needAlphaTesting = function () {
  910. return false;
  911. };
  912. LavaMaterial.prototype.getAlphaTestTexture = function () {
  913. return null;
  914. };
  915. // Methods
  916. LavaMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  917. if (this.isFrozen) {
  918. if (this._wasPreviouslyReady && subMesh.effect) {
  919. return true;
  920. }
  921. }
  922. if (!subMesh._materialDefines) {
  923. subMesh._materialDefines = new LavaMaterialDefines();
  924. }
  925. var defines = subMesh._materialDefines;
  926. var scene = this.getScene();
  927. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  928. if (this._renderId === scene.getRenderId()) {
  929. return true;
  930. }
  931. }
  932. var engine = scene.getEngine();
  933. // Textures
  934. if (defines._areTexturesDirty) {
  935. defines._needUVs = false;
  936. if (scene.texturesEnabled) {
  937. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  938. if (!this._diffuseTexture.isReady()) {
  939. return false;
  940. }
  941. else {
  942. defines._needUVs = true;
  943. defines.DIFFUSE = true;
  944. }
  945. }
  946. }
  947. }
  948. // Misc.
  949. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  950. // Lights
  951. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  952. // Values that need to be evaluated on every frame
  953. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  954. // Attribs
  955. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  956. // Get correct effect
  957. if (defines.isDirty) {
  958. defines.markAsProcessed();
  959. scene.resetCachedMaterial();
  960. // Fallbacks
  961. var fallbacks = new BABYLON.EffectFallbacks();
  962. if (defines.FOG) {
  963. fallbacks.addFallback(1, "FOG");
  964. }
  965. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
  966. if (defines.NUM_BONE_INFLUENCERS > 0) {
  967. fallbacks.addCPUSkinningFallback(0, mesh);
  968. }
  969. //Attributes
  970. var attribs = [BABYLON.VertexBuffer.PositionKind];
  971. if (defines.NORMAL) {
  972. attribs.push(BABYLON.VertexBuffer.NormalKind);
  973. }
  974. if (defines.UV1) {
  975. attribs.push(BABYLON.VertexBuffer.UVKind);
  976. }
  977. if (defines.UV2) {
  978. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  979. }
  980. if (defines.VERTEXCOLOR) {
  981. attribs.push(BABYLON.VertexBuffer.ColorKind);
  982. }
  983. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  984. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  985. // Legacy browser patch
  986. var shaderName = "lava";
  987. var join = defines.toString();
  988. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  989. "vFogInfos", "vFogColor", "pointSize",
  990. "vDiffuseInfos",
  991. "mBones",
  992. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix",
  993. "time", "speed", "movingSpeed",
  994. "fogColor", "fogDensity", "lowFrequencySpeed"
  995. ];
  996. var samplers = ["diffuseSampler",
  997. "noiseTexture"
  998. ];
  999. var uniformBuffers = new Array();
  1000. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  1001. uniformsNames: uniforms,
  1002. uniformBuffersNames: uniformBuffers,
  1003. samplers: samplers,
  1004. defines: defines,
  1005. maxSimultaneousLights: this.maxSimultaneousLights
  1006. });
  1007. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  1008. attributes: attribs,
  1009. uniformsNames: uniforms,
  1010. uniformBuffersNames: uniformBuffers,
  1011. samplers: samplers,
  1012. defines: join,
  1013. fallbacks: fallbacks,
  1014. onCompiled: this.onCompiled,
  1015. onError: this.onError,
  1016. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  1017. }, engine), defines);
  1018. }
  1019. if (!subMesh.effect || !subMesh.effect.isReady()) {
  1020. return false;
  1021. }
  1022. this._renderId = scene.getRenderId();
  1023. this._wasPreviouslyReady = true;
  1024. return true;
  1025. };
  1026. LavaMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  1027. var scene = this.getScene();
  1028. var defines = subMesh._materialDefines;
  1029. if (!defines) {
  1030. return;
  1031. }
  1032. var effect = subMesh.effect;
  1033. if (!effect) {
  1034. return;
  1035. }
  1036. this._activeEffect = effect;
  1037. // Matrices
  1038. this.bindOnlyWorldMatrix(world);
  1039. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  1040. // Bones
  1041. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  1042. if (this._mustRebind(scene, effect)) {
  1043. // Textures
  1044. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  1045. this._activeEffect.setTexture("diffuseSampler", this.diffuseTexture);
  1046. this._activeEffect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
  1047. this._activeEffect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
  1048. }
  1049. if (this.noiseTexture) {
  1050. this._activeEffect.setTexture("noiseTexture", this.noiseTexture);
  1051. }
  1052. // Clip plane
  1053. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  1054. // Point size
  1055. if (this.pointsCloud) {
  1056. this._activeEffect.setFloat("pointSize", this.pointSize);
  1057. }
  1058. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  1059. }
  1060. this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  1061. if (scene.lightsEnabled && !this.disableLighting) {
  1062. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines);
  1063. }
  1064. // View
  1065. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  1066. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  1067. }
  1068. // Fog
  1069. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  1070. this._lastTime += scene.getEngine().getDeltaTime();
  1071. this._activeEffect.setFloat("time", this._lastTime * this.speed / 1000);
  1072. if (!this.fogColor) {
  1073. this.fogColor = BABYLON.Color3.Black();
  1074. }
  1075. this._activeEffect.setColor3("fogColor", this.fogColor);
  1076. this._activeEffect.setFloat("fogDensity", this.fogDensity);
  1077. this._activeEffect.setFloat("lowFrequencySpeed", this.lowFrequencySpeed);
  1078. this._activeEffect.setFloat("movingSpeed", this.movingSpeed);
  1079. this._afterBind(mesh, this._activeEffect);
  1080. };
  1081. LavaMaterial.prototype.getAnimatables = function () {
  1082. var results = [];
  1083. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  1084. results.push(this.diffuseTexture);
  1085. }
  1086. if (this.noiseTexture && this.noiseTexture.animations && this.noiseTexture.animations.length > 0) {
  1087. results.push(this.noiseTexture);
  1088. }
  1089. return results;
  1090. };
  1091. LavaMaterial.prototype.getActiveTextures = function () {
  1092. var activeTextures = _super.prototype.getActiveTextures.call(this);
  1093. if (this._diffuseTexture) {
  1094. activeTextures.push(this._diffuseTexture);
  1095. }
  1096. return activeTextures;
  1097. };
  1098. LavaMaterial.prototype.hasTexture = function (texture) {
  1099. if (_super.prototype.hasTexture.call(this, texture)) {
  1100. return true;
  1101. }
  1102. if (this.diffuseTexture === texture) {
  1103. return true;
  1104. }
  1105. return false;
  1106. };
  1107. LavaMaterial.prototype.dispose = function (forceDisposeEffect) {
  1108. if (this.diffuseTexture) {
  1109. this.diffuseTexture.dispose();
  1110. }
  1111. if (this.noiseTexture) {
  1112. this.noiseTexture.dispose();
  1113. }
  1114. _super.prototype.dispose.call(this, forceDisposeEffect);
  1115. };
  1116. LavaMaterial.prototype.clone = function (name) {
  1117. var _this = this;
  1118. return BABYLON.SerializationHelper.Clone(function () { return new LavaMaterial(name, _this.getScene()); }, this);
  1119. };
  1120. LavaMaterial.prototype.serialize = function () {
  1121. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  1122. serializationObject.customType = "BABYLON.LavaMaterial";
  1123. return serializationObject;
  1124. };
  1125. LavaMaterial.prototype.getClassName = function () {
  1126. return "LavaMaterial";
  1127. };
  1128. // Statics
  1129. LavaMaterial.Parse = function (source, scene, rootUrl) {
  1130. return BABYLON.SerializationHelper.Parse(function () { return new LavaMaterial(source.name, scene); }, source, scene, rootUrl);
  1131. };
  1132. __decorate([
  1133. BABYLON.serializeAsTexture("diffuseTexture")
  1134. ], LavaMaterial.prototype, "_diffuseTexture", void 0);
  1135. __decorate([
  1136. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1137. ], LavaMaterial.prototype, "diffuseTexture", void 0);
  1138. __decorate([
  1139. BABYLON.serializeAsTexture()
  1140. ], LavaMaterial.prototype, "noiseTexture", void 0);
  1141. __decorate([
  1142. BABYLON.serializeAsColor3()
  1143. ], LavaMaterial.prototype, "fogColor", void 0);
  1144. __decorate([
  1145. BABYLON.serialize()
  1146. ], LavaMaterial.prototype, "speed", void 0);
  1147. __decorate([
  1148. BABYLON.serialize()
  1149. ], LavaMaterial.prototype, "movingSpeed", void 0);
  1150. __decorate([
  1151. BABYLON.serialize()
  1152. ], LavaMaterial.prototype, "lowFrequencySpeed", void 0);
  1153. __decorate([
  1154. BABYLON.serialize()
  1155. ], LavaMaterial.prototype, "fogDensity", void 0);
  1156. __decorate([
  1157. BABYLON.serializeAsColor3()
  1158. ], LavaMaterial.prototype, "diffuseColor", void 0);
  1159. __decorate([
  1160. BABYLON.serialize("disableLighting")
  1161. ], LavaMaterial.prototype, "_disableLighting", void 0);
  1162. __decorate([
  1163. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1164. ], LavaMaterial.prototype, "disableLighting", void 0);
  1165. __decorate([
  1166. BABYLON.serialize("maxSimultaneousLights")
  1167. ], LavaMaterial.prototype, "_maxSimultaneousLights", void 0);
  1168. __decorate([
  1169. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1170. ], LavaMaterial.prototype, "maxSimultaneousLights", void 0);
  1171. return LavaMaterial;
  1172. }(BABYLON.PushMaterial));
  1173. BABYLON.LavaMaterial = LavaMaterial;
  1174. })(BABYLON || (BABYLON = {}));
  1175. //# sourceMappingURL=babylon.lavaMaterial.js.map
  1176. BABYLON.Effect.ShadersStore['lavaVertexShader'] = "precision highp float;\n\nuniform float time;\nuniform float lowFrequencySpeed;\n\nvarying float noise;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n\n\nvec3 mod289(vec3 x)\n{\nreturn x-floor(x*(1.0/289.0))*289.0;\n}\nvec4 mod289(vec4 x)\n{\nreturn x-floor(x*(1.0/289.0))*289.0;\n}\nvec4 permute(vec4 x)\n{\nreturn mod289(((x*34.0)+1.0)*x);\n}\nvec4 taylorInvSqrt(vec4 r)\n{\nreturn 1.79284291400159-0.85373472095314*r;\n}\nvec3 fade(vec3 t) {\nreturn t*t*t*(t*(t*6.0-15.0)+10.0);\n}\n\nfloat pnoise(vec3 P,vec3 rep)\n{\nvec3 Pi0=mod(floor(P),rep); \nvec3 Pi1=mod(Pi0+vec3(1.0),rep); \nPi0=mod289(Pi0);\nPi1=mod289(Pi1);\nvec3 Pf0=fract(P); \nvec3 Pf1=Pf0-vec3(1.0); \nvec4 ix=vec4(Pi0.x,Pi1.x,Pi0.x,Pi1.x);\nvec4 iy=vec4(Pi0.yy,Pi1.yy);\nvec4 iz0=Pi0.zzzz;\nvec4 iz1=Pi1.zzzz;\nvec4 ixy=permute(permute(ix)+iy);\nvec4 ixy0=permute(ixy+iz0);\nvec4 ixy1=permute(ixy+iz1);\nvec4 gx0=ixy0*(1.0/7.0);\nvec4 gy0=fract(floor(gx0)*(1.0/7.0))-0.5;\ngx0=fract(gx0);\nvec4 gz0=vec4(0.5)-abs(gx0)-abs(gy0);\nvec4 sz0=step(gz0,vec4(0.0));\ngx0-=sz0*(step(0.0,gx0)-0.5);\ngy0-=sz0*(step(0.0,gy0)-0.5);\nvec4 gx1=ixy1*(1.0/7.0);\nvec4 gy1=fract(floor(gx1)*(1.0/7.0))-0.5;\ngx1=fract(gx1);\nvec4 gz1=vec4(0.5)-abs(gx1)-abs(gy1);\nvec4 sz1=step(gz1,vec4(0.0));\ngx1-=sz1*(step(0.0,gx1)-0.5);\ngy1-=sz1*(step(0.0,gy1)-0.5);\nvec3 g000=vec3(gx0.x,gy0.x,gz0.x);\nvec3 g100=vec3(gx0.y,gy0.y,gz0.y);\nvec3 g010=vec3(gx0.z,gy0.z,gz0.z);\nvec3 g110=vec3(gx0.w,gy0.w,gz0.w);\nvec3 g001=vec3(gx1.x,gy1.x,gz1.x);\nvec3 g101=vec3(gx1.y,gy1.y,gz1.y);\nvec3 g011=vec3(gx1.z,gy1.z,gz1.z);\nvec3 g111=vec3(gx1.w,gy1.w,gz1.w);\nvec4 norm0=taylorInvSqrt(vec4(dot(g000,g000),dot(g010,g010),dot(g100,g100),dot(g110,g110)));\ng000*=norm0.x;\ng010*=norm0.y;\ng100*=norm0.z;\ng110*=norm0.w;\nvec4 norm1=taylorInvSqrt(vec4(dot(g001,g001),dot(g011,g011),dot(g101,g101),dot(g111,g111)));\ng001*=norm1.x;\ng011*=norm1.y;\ng101*=norm1.z;\ng111*=norm1.w;\nfloat n000=dot(g000,Pf0);\nfloat n100=dot(g100,vec3(Pf1.x,Pf0.yz));\nfloat n010=dot(g010,vec3(Pf0.x,Pf1.y,Pf0.z));\nfloat n110=dot(g110,vec3(Pf1.xy,Pf0.z));\nfloat n001=dot(g001,vec3(Pf0.xy,Pf1.z));\nfloat n101=dot(g101,vec3(Pf1.x,Pf0.y,Pf1.z));\nfloat n011=dot(g011,vec3(Pf0.x,Pf1.yz));\nfloat n111=dot(g111,Pf1);\nvec3 fade_xyz=fade(Pf0);\nvec4 n_z=mix(vec4(n000,n100,n010,n110),vec4(n001,n101,n011,n111),fade_xyz.z);\nvec2 n_yz=mix(n_z.xy,n_z.zw,fade_xyz.y);\nfloat n_xyz=mix(n_yz.x,n_yz.y,fade_xyz.x);\nreturn 2.2*n_xyz;\n}\n\nfloat turbulence( vec3 p ) {\nfloat w=100.0;\nfloat t=-.5;\nfor (float f=1.0 ; f<=10.0 ; f++ ){\nfloat power=pow( 2.0,f );\nt+=abs( pnoise( vec3( power*p ),vec3( 10.0,10.0,10.0 ) )/power );\n}\nreturn t;\n}\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\n#ifdef NORMAL\n\nnoise=10.0*-.10*turbulence( .5*normal+time*1.15 );\n\nfloat b=lowFrequencySpeed*5.0*pnoise( 0.05*position +vec3(time*1.025),vec3( 100.0 ) );\n\nfloat displacement =-1.5*noise+b;\n\nvec3 newPosition=position+normal*displacement;\ngl_Position=viewProjection*finalWorld*vec4( newPosition,1.0 );\nvec4 worldPos=finalWorld*vec4(newPosition,1.0);\nvPositionW=vec3(worldPos);\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}";
  1177. BABYLON.Effect.ShadersStore['lavaPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nvarying vec3 vPositionW;\n\nuniform float time;\nuniform float speed;\nuniform float movingSpeed;\nuniform vec3 fogColor;\nuniform sampler2D noiseTexture;\nuniform float fogDensity;\n\nvarying float noise;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0]\n#include<__decl__lightFragment>[1]\n#include<__decl__lightFragment>[2]\n#include<__decl__lightFragment>[3]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nfloat random( vec3 scale,float seed ){\nreturn fract( sin( dot( gl_FragCoord.xyz+seed,scale ) )*43758.5453+seed ) ;\n}\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\n\nvec4 noiseTex=texture2D( noiseTexture,vDiffuseUV );\nvec2 T1=vDiffuseUV+vec2( 1.5,-1.5 )*time*0.02;\nvec2 T2=vDiffuseUV+vec2( -0.5,2.0 )*time*0.01*speed;\nT1.x+=noiseTex.x*2.0;\nT1.y+=noiseTex.y*2.0;\nT2.x-=noiseTex.y*0.2+time*0.001*movingSpeed;\nT2.y+=noiseTex.z*0.2+time*0.002*movingSpeed;\nfloat p=texture2D( noiseTexture,T1*3.0 ).a;\nvec4 lavaColor=texture2D( diffuseSampler,T2*4.0);\nvec4 temp=lavaColor*( vec4( p,p,p,p )*2. )+( lavaColor*lavaColor-0.1 );\nbaseColor=temp;\nfloat depth=gl_FragCoord.z*4.0;\nconst float LOG2=1.442695;\nfloat fogFactor=exp2(-fogDensity*fogDensity*depth*depth*LOG2 );\nfogFactor=1.0-clamp( fogFactor,0.0,1.0 );\nbaseColor=mix( baseColor,vec4( fogColor,baseColor.w ),fogFactor );\ndiffuseColor=baseColor.rgb;\n\n\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#include<lightFragment>[0]\n#include<lightFragment>[1]\n#include<lightFragment>[2]\n#include<lightFragment>[3]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
  1178. var BABYLON;
  1179. (function (BABYLON) {
  1180. var SimpleMaterialDefines = /** @class */ (function (_super) {
  1181. __extends(SimpleMaterialDefines, _super);
  1182. function SimpleMaterialDefines() {
  1183. var _this = _super.call(this) || this;
  1184. _this.DIFFUSE = false;
  1185. _this.CLIPPLANE = false;
  1186. _this.CLIPPLANE2 = false;
  1187. _this.CLIPPLANE3 = false;
  1188. _this.CLIPPLANE4 = false;
  1189. _this.ALPHATEST = false;
  1190. _this.DEPTHPREPASS = false;
  1191. _this.POINTSIZE = false;
  1192. _this.FOG = false;
  1193. _this.NORMAL = false;
  1194. _this.UV1 = false;
  1195. _this.UV2 = false;
  1196. _this.VERTEXCOLOR = false;
  1197. _this.VERTEXALPHA = false;
  1198. _this.NUM_BONE_INFLUENCERS = 0;
  1199. _this.BonesPerMesh = 0;
  1200. _this.INSTANCES = false;
  1201. _this.rebuild();
  1202. return _this;
  1203. }
  1204. return SimpleMaterialDefines;
  1205. }(BABYLON.MaterialDefines));
  1206. var SimpleMaterial = /** @class */ (function (_super) {
  1207. __extends(SimpleMaterial, _super);
  1208. function SimpleMaterial(name, scene) {
  1209. var _this = _super.call(this, name, scene) || this;
  1210. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  1211. _this._disableLighting = false;
  1212. _this._maxSimultaneousLights = 4;
  1213. return _this;
  1214. }
  1215. SimpleMaterial.prototype.needAlphaBlending = function () {
  1216. return (this.alpha < 1.0);
  1217. };
  1218. SimpleMaterial.prototype.needAlphaTesting = function () {
  1219. return false;
  1220. };
  1221. SimpleMaterial.prototype.getAlphaTestTexture = function () {
  1222. return null;
  1223. };
  1224. // Methods
  1225. SimpleMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  1226. if (this.isFrozen) {
  1227. if (this._wasPreviouslyReady && subMesh.effect) {
  1228. return true;
  1229. }
  1230. }
  1231. if (!subMesh._materialDefines) {
  1232. subMesh._materialDefines = new SimpleMaterialDefines();
  1233. }
  1234. var defines = subMesh._materialDefines;
  1235. var scene = this.getScene();
  1236. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  1237. if (this._renderId === scene.getRenderId()) {
  1238. return true;
  1239. }
  1240. }
  1241. var engine = scene.getEngine();
  1242. // Textures
  1243. if (defines._areTexturesDirty) {
  1244. defines._needUVs = false;
  1245. if (scene.texturesEnabled) {
  1246. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  1247. if (!this._diffuseTexture.isReady()) {
  1248. return false;
  1249. }
  1250. else {
  1251. defines._needUVs = true;
  1252. defines.DIFFUSE = true;
  1253. }
  1254. }
  1255. }
  1256. }
  1257. // Misc.
  1258. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  1259. // Lights
  1260. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  1261. // Values that need to be evaluated on every frame
  1262. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  1263. // Attribs
  1264. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  1265. // Get correct effect
  1266. if (defines.isDirty) {
  1267. defines.markAsProcessed();
  1268. scene.resetCachedMaterial();
  1269. // Fallbacks
  1270. var fallbacks = new BABYLON.EffectFallbacks();
  1271. if (defines.FOG) {
  1272. fallbacks.addFallback(1, "FOG");
  1273. }
  1274. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  1275. if (defines.NUM_BONE_INFLUENCERS > 0) {
  1276. fallbacks.addCPUSkinningFallback(0, mesh);
  1277. }
  1278. //Attributes
  1279. var attribs = [BABYLON.VertexBuffer.PositionKind];
  1280. if (defines.NORMAL) {
  1281. attribs.push(BABYLON.VertexBuffer.NormalKind);
  1282. }
  1283. if (defines.UV1) {
  1284. attribs.push(BABYLON.VertexBuffer.UVKind);
  1285. }
  1286. if (defines.UV2) {
  1287. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  1288. }
  1289. if (defines.VERTEXCOLOR) {
  1290. attribs.push(BABYLON.VertexBuffer.ColorKind);
  1291. }
  1292. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  1293. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  1294. var shaderName = "simple";
  1295. var join = defines.toString();
  1296. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  1297. "vFogInfos", "vFogColor", "pointSize",
  1298. "vDiffuseInfos",
  1299. "mBones",
  1300. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix"
  1301. ];
  1302. var samplers = ["diffuseSampler"];
  1303. var uniformBuffers = new Array();
  1304. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  1305. uniformsNames: uniforms,
  1306. uniformBuffersNames: uniformBuffers,
  1307. samplers: samplers,
  1308. defines: defines,
  1309. maxSimultaneousLights: this.maxSimultaneousLights
  1310. });
  1311. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  1312. attributes: attribs,
  1313. uniformsNames: uniforms,
  1314. uniformBuffersNames: uniformBuffers,
  1315. samplers: samplers,
  1316. defines: join,
  1317. fallbacks: fallbacks,
  1318. onCompiled: this.onCompiled,
  1319. onError: this.onError,
  1320. indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights - 1 }
  1321. }, engine), defines);
  1322. }
  1323. if (!subMesh.effect || !subMesh.effect.isReady()) {
  1324. return false;
  1325. }
  1326. this._renderId = scene.getRenderId();
  1327. this._wasPreviouslyReady = true;
  1328. return true;
  1329. };
  1330. SimpleMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  1331. var scene = this.getScene();
  1332. var defines = subMesh._materialDefines;
  1333. if (!defines) {
  1334. return;
  1335. }
  1336. var effect = subMesh.effect;
  1337. if (!effect) {
  1338. return;
  1339. }
  1340. this._activeEffect = effect;
  1341. // Matrices
  1342. this.bindOnlyWorldMatrix(world);
  1343. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  1344. // Bones
  1345. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  1346. if (this._mustRebind(scene, effect)) {
  1347. // Textures
  1348. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  1349. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  1350. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  1351. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  1352. }
  1353. // Clip plane
  1354. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  1355. // Point size
  1356. if (this.pointsCloud) {
  1357. this._activeEffect.setFloat("pointSize", this.pointSize);
  1358. }
  1359. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  1360. }
  1361. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  1362. // Lights
  1363. if (scene.lightsEnabled && !this.disableLighting) {
  1364. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  1365. }
  1366. // View
  1367. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  1368. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  1369. }
  1370. // Fog
  1371. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  1372. this._afterBind(mesh, this._activeEffect);
  1373. };
  1374. SimpleMaterial.prototype.getAnimatables = function () {
  1375. var results = [];
  1376. if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
  1377. results.push(this._diffuseTexture);
  1378. }
  1379. return results;
  1380. };
  1381. SimpleMaterial.prototype.getActiveTextures = function () {
  1382. var activeTextures = _super.prototype.getActiveTextures.call(this);
  1383. if (this._diffuseTexture) {
  1384. activeTextures.push(this._diffuseTexture);
  1385. }
  1386. return activeTextures;
  1387. };
  1388. SimpleMaterial.prototype.hasTexture = function (texture) {
  1389. if (_super.prototype.hasTexture.call(this, texture)) {
  1390. return true;
  1391. }
  1392. if (this.diffuseTexture === texture) {
  1393. return true;
  1394. }
  1395. return false;
  1396. };
  1397. SimpleMaterial.prototype.dispose = function (forceDisposeEffect) {
  1398. if (this._diffuseTexture) {
  1399. this._diffuseTexture.dispose();
  1400. }
  1401. _super.prototype.dispose.call(this, forceDisposeEffect);
  1402. };
  1403. SimpleMaterial.prototype.clone = function (name) {
  1404. var _this = this;
  1405. return BABYLON.SerializationHelper.Clone(function () { return new SimpleMaterial(name, _this.getScene()); }, this);
  1406. };
  1407. SimpleMaterial.prototype.serialize = function () {
  1408. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  1409. serializationObject.customType = "BABYLON.SimpleMaterial";
  1410. return serializationObject;
  1411. };
  1412. SimpleMaterial.prototype.getClassName = function () {
  1413. return "SimpleMaterial";
  1414. };
  1415. // Statics
  1416. SimpleMaterial.Parse = function (source, scene, rootUrl) {
  1417. return BABYLON.SerializationHelper.Parse(function () { return new SimpleMaterial(source.name, scene); }, source, scene, rootUrl);
  1418. };
  1419. __decorate([
  1420. BABYLON.serializeAsTexture("diffuseTexture")
  1421. ], SimpleMaterial.prototype, "_diffuseTexture", void 0);
  1422. __decorate([
  1423. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1424. ], SimpleMaterial.prototype, "diffuseTexture", void 0);
  1425. __decorate([
  1426. BABYLON.serializeAsColor3("diffuse")
  1427. ], SimpleMaterial.prototype, "diffuseColor", void 0);
  1428. __decorate([
  1429. BABYLON.serialize("disableLighting")
  1430. ], SimpleMaterial.prototype, "_disableLighting", void 0);
  1431. __decorate([
  1432. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1433. ], SimpleMaterial.prototype, "disableLighting", void 0);
  1434. __decorate([
  1435. BABYLON.serialize("maxSimultaneousLights")
  1436. ], SimpleMaterial.prototype, "_maxSimultaneousLights", void 0);
  1437. __decorate([
  1438. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1439. ], SimpleMaterial.prototype, "maxSimultaneousLights", void 0);
  1440. return SimpleMaterial;
  1441. }(BABYLON.PushMaterial));
  1442. BABYLON.SimpleMaterial = SimpleMaterial;
  1443. })(BABYLON || (BABYLON = {}));
  1444. //# sourceMappingURL=babylon.simpleMaterial.js.map
  1445. BABYLON.Effect.ShadersStore['simpleVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  1446. BABYLON.Effect.ShadersStore['simplePixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif \n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
  1447. var BABYLON;
  1448. (function (BABYLON) {
  1449. var WaterMaterialDefines = /** @class */ (function (_super) {
  1450. __extends(WaterMaterialDefines, _super);
  1451. function WaterMaterialDefines() {
  1452. var _this = _super.call(this) || this;
  1453. _this.BUMP = false;
  1454. _this.REFLECTION = false;
  1455. _this.CLIPPLANE = false;
  1456. _this.CLIPPLANE2 = false;
  1457. _this.CLIPPLANE3 = false;
  1458. _this.CLIPPLANE4 = false;
  1459. _this.ALPHATEST = false;
  1460. _this.DEPTHPREPASS = false;
  1461. _this.POINTSIZE = false;
  1462. _this.FOG = false;
  1463. _this.NORMAL = false;
  1464. _this.UV1 = false;
  1465. _this.UV2 = false;
  1466. _this.VERTEXCOLOR = false;
  1467. _this.VERTEXALPHA = false;
  1468. _this.NUM_BONE_INFLUENCERS = 0;
  1469. _this.BonesPerMesh = 0;
  1470. _this.INSTANCES = false;
  1471. _this.SPECULARTERM = false;
  1472. _this.LOGARITHMICDEPTH = false;
  1473. _this.FRESNELSEPARATE = false;
  1474. _this.BUMPSUPERIMPOSE = false;
  1475. _this.BUMPAFFECTSREFLECTION = false;
  1476. _this.rebuild();
  1477. return _this;
  1478. }
  1479. return WaterMaterialDefines;
  1480. }(BABYLON.MaterialDefines));
  1481. var WaterMaterial = /** @class */ (function (_super) {
  1482. __extends(WaterMaterial, _super);
  1483. /**
  1484. * Constructor
  1485. */
  1486. function WaterMaterial(name, scene, renderTargetSize) {
  1487. if (renderTargetSize === void 0) { renderTargetSize = new BABYLON.Vector2(512, 512); }
  1488. var _this = _super.call(this, name, scene) || this;
  1489. _this.renderTargetSize = renderTargetSize;
  1490. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  1491. _this.specularColor = new BABYLON.Color3(0, 0, 0);
  1492. _this.specularPower = 64;
  1493. _this._disableLighting = false;
  1494. _this._maxSimultaneousLights = 4;
  1495. /**
  1496. * @param {number}: Represents the wind force
  1497. */
  1498. _this.windForce = 6;
  1499. /**
  1500. * @param {Vector2}: The direction of the wind in the plane (X, Z)
  1501. */
  1502. _this.windDirection = new BABYLON.Vector2(0, 1);
  1503. /**
  1504. * @param {number}: Wave height, represents the height of the waves
  1505. */
  1506. _this.waveHeight = 0.4;
  1507. /**
  1508. * @param {number}: Bump height, represents the bump height related to the bump map
  1509. */
  1510. _this.bumpHeight = 0.4;
  1511. /**
  1512. * @param {boolean}: Add a smaller moving bump to less steady waves.
  1513. */
  1514. _this._bumpSuperimpose = false;
  1515. /**
  1516. * @param {boolean}: Color refraction and reflection differently with .waterColor2 and .colorBlendFactor2. Non-linear (physically correct) fresnel.
  1517. */
  1518. _this._fresnelSeparate = false;
  1519. /**
  1520. * @param {boolean}: bump Waves modify the reflection.
  1521. */
  1522. _this._bumpAffectsReflection = false;
  1523. /**
  1524. * @param {number}: The water color blended with the refraction (near)
  1525. */
  1526. _this.waterColor = new BABYLON.Color3(0.1, 0.1, 0.6);
  1527. /**
  1528. * @param {number}: The blend factor related to the water color
  1529. */
  1530. _this.colorBlendFactor = 0.2;
  1531. /**
  1532. * @param {number}: The water color blended with the reflection (far)
  1533. */
  1534. _this.waterColor2 = new BABYLON.Color3(0.1, 0.1, 0.6);
  1535. /**
  1536. * @param {number}: The blend factor related to the water color (reflection, far)
  1537. */
  1538. _this.colorBlendFactor2 = 0.2;
  1539. /**
  1540. * @param {number}: Represents the maximum length of a wave
  1541. */
  1542. _this.waveLength = 0.1;
  1543. /**
  1544. * @param {number}: Defines the waves speed
  1545. */
  1546. _this.waveSpeed = 1.0;
  1547. _this._renderTargets = new BABYLON.SmartArray(16);
  1548. /*
  1549. * Private members
  1550. */
  1551. _this._mesh = null;
  1552. _this._reflectionTransform = BABYLON.Matrix.Zero();
  1553. _this._lastTime = 0;
  1554. _this._lastDeltaTime = 0;
  1555. _this._createRenderTargets(scene, renderTargetSize);
  1556. // Create render targets
  1557. _this.getRenderTargetTextures = function () {
  1558. _this._renderTargets.reset();
  1559. _this._renderTargets.push(_this._reflectionRTT);
  1560. _this._renderTargets.push(_this._refractionRTT);
  1561. return _this._renderTargets;
  1562. };
  1563. return _this;
  1564. }
  1565. Object.defineProperty(WaterMaterial.prototype, "useLogarithmicDepth", {
  1566. get: function () {
  1567. return this._useLogarithmicDepth;
  1568. },
  1569. set: function (value) {
  1570. this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;
  1571. this._markAllSubMeshesAsMiscDirty();
  1572. },
  1573. enumerable: true,
  1574. configurable: true
  1575. });
  1576. Object.defineProperty(WaterMaterial.prototype, "refractionTexture", {
  1577. // Get / Set
  1578. get: function () {
  1579. return this._refractionRTT;
  1580. },
  1581. enumerable: true,
  1582. configurable: true
  1583. });
  1584. Object.defineProperty(WaterMaterial.prototype, "reflectionTexture", {
  1585. get: function () {
  1586. return this._reflectionRTT;
  1587. },
  1588. enumerable: true,
  1589. configurable: true
  1590. });
  1591. // Methods
  1592. WaterMaterial.prototype.addToRenderList = function (node) {
  1593. if (this._refractionRTT && this._refractionRTT.renderList) {
  1594. this._refractionRTT.renderList.push(node);
  1595. }
  1596. if (this._reflectionRTT && this._reflectionRTT.renderList) {
  1597. this._reflectionRTT.renderList.push(node);
  1598. }
  1599. };
  1600. WaterMaterial.prototype.enableRenderTargets = function (enable) {
  1601. var refreshRate = enable ? 1 : 0;
  1602. if (this._refractionRTT) {
  1603. this._refractionRTT.refreshRate = refreshRate;
  1604. }
  1605. if (this._reflectionRTT) {
  1606. this._reflectionRTT.refreshRate = refreshRate;
  1607. }
  1608. };
  1609. WaterMaterial.prototype.getRenderList = function () {
  1610. return this._refractionRTT ? this._refractionRTT.renderList : [];
  1611. };
  1612. Object.defineProperty(WaterMaterial.prototype, "renderTargetsEnabled", {
  1613. get: function () {
  1614. return !(this._refractionRTT && this._refractionRTT.refreshRate === 0);
  1615. },
  1616. enumerable: true,
  1617. configurable: true
  1618. });
  1619. WaterMaterial.prototype.needAlphaBlending = function () {
  1620. return (this.alpha < 1.0);
  1621. };
  1622. WaterMaterial.prototype.needAlphaTesting = function () {
  1623. return false;
  1624. };
  1625. WaterMaterial.prototype.getAlphaTestTexture = function () {
  1626. return null;
  1627. };
  1628. WaterMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  1629. if (this.isFrozen) {
  1630. if (this._wasPreviouslyReady && subMesh.effect) {
  1631. return true;
  1632. }
  1633. }
  1634. if (!subMesh._materialDefines) {
  1635. subMesh._materialDefines = new WaterMaterialDefines();
  1636. }
  1637. var defines = subMesh._materialDefines;
  1638. var scene = this.getScene();
  1639. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  1640. if (this._renderId === scene.getRenderId()) {
  1641. return true;
  1642. }
  1643. }
  1644. var engine = scene.getEngine();
  1645. // Textures
  1646. if (defines._areTexturesDirty) {
  1647. defines._needUVs = false;
  1648. if (scene.texturesEnabled) {
  1649. if (this.bumpTexture && BABYLON.StandardMaterial.BumpTextureEnabled) {
  1650. if (!this.bumpTexture.isReady()) {
  1651. return false;
  1652. }
  1653. else {
  1654. defines._needUVs = true;
  1655. defines.BUMP = true;
  1656. }
  1657. }
  1658. if (BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  1659. defines.REFLECTION = true;
  1660. }
  1661. }
  1662. }
  1663. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  1664. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  1665. if (defines._areMiscDirty) {
  1666. if (this._fresnelSeparate) {
  1667. defines.FRESNELSEPARATE = true;
  1668. }
  1669. if (this._bumpSuperimpose) {
  1670. defines.BUMPSUPERIMPOSE = true;
  1671. }
  1672. if (this._bumpAffectsReflection) {
  1673. defines.BUMPAFFECTSREFLECTION = true;
  1674. }
  1675. }
  1676. // Lights
  1677. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);
  1678. // Attribs
  1679. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  1680. // Configure this
  1681. this._mesh = mesh;
  1682. if (this._waitingRenderList) {
  1683. for (var i = 0; i < this._waitingRenderList.length; i++) {
  1684. this.addToRenderList(scene.getNodeByID(this._waitingRenderList[i]));
  1685. }
  1686. this._waitingRenderList = null;
  1687. }
  1688. // Get correct effect
  1689. if (defines.isDirty) {
  1690. defines.markAsProcessed();
  1691. scene.resetCachedMaterial();
  1692. // Fallbacks
  1693. var fallbacks = new BABYLON.EffectFallbacks();
  1694. if (defines.FOG) {
  1695. fallbacks.addFallback(1, "FOG");
  1696. }
  1697. if (defines.LOGARITHMICDEPTH) {
  1698. fallbacks.addFallback(0, "LOGARITHMICDEPTH");
  1699. }
  1700. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  1701. if (defines.NUM_BONE_INFLUENCERS > 0) {
  1702. fallbacks.addCPUSkinningFallback(0, mesh);
  1703. }
  1704. //Attributes
  1705. var attribs = [BABYLON.VertexBuffer.PositionKind];
  1706. if (defines.NORMAL) {
  1707. attribs.push(BABYLON.VertexBuffer.NormalKind);
  1708. }
  1709. if (defines.UV1) {
  1710. attribs.push(BABYLON.VertexBuffer.UVKind);
  1711. }
  1712. if (defines.UV2) {
  1713. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  1714. }
  1715. if (defines.VERTEXCOLOR) {
  1716. attribs.push(BABYLON.VertexBuffer.ColorKind);
  1717. }
  1718. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  1719. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  1720. // Legacy browser patch
  1721. var shaderName = "water";
  1722. var join = defines.toString();
  1723. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  1724. "vFogInfos", "vFogColor", "pointSize",
  1725. "vNormalInfos",
  1726. "mBones",
  1727. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "normalMatrix",
  1728. "logarithmicDepthConstant",
  1729. // Water
  1730. "worldReflectionViewProjection", "windDirection", "waveLength", "time", "windForce",
  1731. "cameraPosition", "bumpHeight", "waveHeight", "waterColor", "waterColor2", "colorBlendFactor", "colorBlendFactor2", "waveSpeed"
  1732. ];
  1733. var samplers = ["normalSampler",
  1734. // Water
  1735. "refractionSampler", "reflectionSampler"
  1736. ];
  1737. var uniformBuffers = new Array();
  1738. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  1739. uniformsNames: uniforms,
  1740. uniformBuffersNames: uniformBuffers,
  1741. samplers: samplers,
  1742. defines: defines,
  1743. maxSimultaneousLights: this.maxSimultaneousLights
  1744. });
  1745. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  1746. attributes: attribs,
  1747. uniformsNames: uniforms,
  1748. uniformBuffersNames: uniformBuffers,
  1749. samplers: samplers,
  1750. defines: join,
  1751. fallbacks: fallbacks,
  1752. onCompiled: this.onCompiled,
  1753. onError: this.onError,
  1754. indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights }
  1755. }, engine), defines);
  1756. }
  1757. if (!subMesh.effect || !subMesh.effect.isReady()) {
  1758. return false;
  1759. }
  1760. this._renderId = scene.getRenderId();
  1761. this._wasPreviouslyReady = true;
  1762. return true;
  1763. };
  1764. WaterMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  1765. var scene = this.getScene();
  1766. var defines = subMesh._materialDefines;
  1767. if (!defines) {
  1768. return;
  1769. }
  1770. var effect = subMesh.effect;
  1771. if (!effect || !this._mesh) {
  1772. return;
  1773. }
  1774. this._activeEffect = effect;
  1775. // Matrices
  1776. this.bindOnlyWorldMatrix(world);
  1777. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  1778. // Bones
  1779. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  1780. if (this._mustRebind(scene, effect)) {
  1781. // Textures
  1782. if (this.bumpTexture && BABYLON.StandardMaterial.BumpTextureEnabled) {
  1783. this._activeEffect.setTexture("normalSampler", this.bumpTexture);
  1784. this._activeEffect.setFloat2("vNormalInfos", this.bumpTexture.coordinatesIndex, this.bumpTexture.level);
  1785. this._activeEffect.setMatrix("normalMatrix", this.bumpTexture.getTextureMatrix());
  1786. }
  1787. // Clip plane
  1788. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  1789. // Point size
  1790. if (this.pointsCloud) {
  1791. this._activeEffect.setFloat("pointSize", this.pointSize);
  1792. }
  1793. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  1794. }
  1795. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  1796. if (defines.SPECULARTERM) {
  1797. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  1798. }
  1799. if (scene.lightsEnabled && !this.disableLighting) {
  1800. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  1801. }
  1802. // View
  1803. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  1804. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  1805. }
  1806. // Fog
  1807. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  1808. // Log. depth
  1809. BABYLON.MaterialHelper.BindLogDepth(defines, this._activeEffect, scene);
  1810. // Water
  1811. if (BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  1812. this._activeEffect.setTexture("refractionSampler", this._refractionRTT);
  1813. this._activeEffect.setTexture("reflectionSampler", this._reflectionRTT);
  1814. }
  1815. var wrvp = this._mesh.getWorldMatrix().multiply(this._reflectionTransform).multiply(scene.getProjectionMatrix());
  1816. // Add delta time. Prevent adding delta time if it hasn't changed.
  1817. var deltaTime = scene.getEngine().getDeltaTime();
  1818. if (deltaTime !== this._lastDeltaTime) {
  1819. this._lastDeltaTime = deltaTime;
  1820. this._lastTime += this._lastDeltaTime;
  1821. }
  1822. this._activeEffect.setMatrix("worldReflectionViewProjection", wrvp);
  1823. this._activeEffect.setVector2("windDirection", this.windDirection);
  1824. this._activeEffect.setFloat("waveLength", this.waveLength);
  1825. this._activeEffect.setFloat("time", this._lastTime / 100000);
  1826. this._activeEffect.setFloat("windForce", this.windForce);
  1827. this._activeEffect.setFloat("waveHeight", this.waveHeight);
  1828. this._activeEffect.setFloat("bumpHeight", this.bumpHeight);
  1829. this._activeEffect.setColor4("waterColor", this.waterColor, 1.0);
  1830. this._activeEffect.setFloat("colorBlendFactor", this.colorBlendFactor);
  1831. this._activeEffect.setColor4("waterColor2", this.waterColor2, 1.0);
  1832. this._activeEffect.setFloat("colorBlendFactor2", this.colorBlendFactor2);
  1833. this._activeEffect.setFloat("waveSpeed", this.waveSpeed);
  1834. this._afterBind(mesh, this._activeEffect);
  1835. };
  1836. WaterMaterial.prototype._createRenderTargets = function (scene, renderTargetSize) {
  1837. var _this = this;
  1838. // Render targets
  1839. this._refractionRTT = new BABYLON.RenderTargetTexture(name + "_refraction", { width: renderTargetSize.x, height: renderTargetSize.y }, scene, false, true);
  1840. this._refractionRTT.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
  1841. this._refractionRTT.wrapV = BABYLON.Texture.MIRROR_ADDRESSMODE;
  1842. this._refractionRTT.ignoreCameraViewport = true;
  1843. this._reflectionRTT = new BABYLON.RenderTargetTexture(name + "_reflection", { width: renderTargetSize.x, height: renderTargetSize.y }, scene, false, true);
  1844. this._reflectionRTT.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
  1845. this._reflectionRTT.wrapV = BABYLON.Texture.MIRROR_ADDRESSMODE;
  1846. this._reflectionRTT.ignoreCameraViewport = true;
  1847. var isVisible;
  1848. var clipPlane = null;
  1849. var savedViewMatrix;
  1850. var mirrorMatrix = BABYLON.Matrix.Zero();
  1851. this._refractionRTT.onBeforeRender = function () {
  1852. if (_this._mesh) {
  1853. isVisible = _this._mesh.isVisible;
  1854. _this._mesh.isVisible = false;
  1855. }
  1856. // Clip plane
  1857. clipPlane = scene.clipPlane;
  1858. var positiony = _this._mesh ? _this._mesh.position.y : 0.0;
  1859. scene.clipPlane = BABYLON.Plane.FromPositionAndNormal(new BABYLON.Vector3(0, positiony + 0.05, 0), new BABYLON.Vector3(0, 1, 0));
  1860. };
  1861. this._refractionRTT.onAfterRender = function () {
  1862. if (_this._mesh) {
  1863. _this._mesh.isVisible = isVisible;
  1864. }
  1865. // Clip plane
  1866. scene.clipPlane = clipPlane;
  1867. };
  1868. this._reflectionRTT.onBeforeRender = function () {
  1869. if (_this._mesh) {
  1870. isVisible = _this._mesh.isVisible;
  1871. _this._mesh.isVisible = false;
  1872. }
  1873. // Clip plane
  1874. clipPlane = scene.clipPlane;
  1875. var positiony = _this._mesh ? _this._mesh.position.y : 0.0;
  1876. scene.clipPlane = BABYLON.Plane.FromPositionAndNormal(new BABYLON.Vector3(0, positiony - 0.05, 0), new BABYLON.Vector3(0, -1, 0));
  1877. // Transform
  1878. BABYLON.Matrix.ReflectionToRef(scene.clipPlane, mirrorMatrix);
  1879. savedViewMatrix = scene.getViewMatrix();
  1880. mirrorMatrix.multiplyToRef(savedViewMatrix, _this._reflectionTransform);
  1881. scene.setTransformMatrix(_this._reflectionTransform, scene.getProjectionMatrix());
  1882. scene.getEngine().cullBackFaces = false;
  1883. scene._mirroredCameraPosition = BABYLON.Vector3.TransformCoordinates(scene.activeCamera.position, mirrorMatrix);
  1884. };
  1885. this._reflectionRTT.onAfterRender = function () {
  1886. if (_this._mesh) {
  1887. _this._mesh.isVisible = isVisible;
  1888. }
  1889. // Clip plane
  1890. scene.clipPlane = clipPlane;
  1891. // Transform
  1892. scene.setTransformMatrix(savedViewMatrix, scene.getProjectionMatrix());
  1893. scene.getEngine().cullBackFaces = true;
  1894. scene._mirroredCameraPosition = null;
  1895. };
  1896. };
  1897. WaterMaterial.prototype.getAnimatables = function () {
  1898. var results = [];
  1899. if (this.bumpTexture && this.bumpTexture.animations && this.bumpTexture.animations.length > 0) {
  1900. results.push(this.bumpTexture);
  1901. }
  1902. if (this._reflectionRTT && this._reflectionRTT.animations && this._reflectionRTT.animations.length > 0) {
  1903. results.push(this._reflectionRTT);
  1904. }
  1905. if (this._refractionRTT && this._refractionRTT.animations && this._refractionRTT.animations.length > 0) {
  1906. results.push(this._refractionRTT);
  1907. }
  1908. return results;
  1909. };
  1910. WaterMaterial.prototype.getActiveTextures = function () {
  1911. var activeTextures = _super.prototype.getActiveTextures.call(this);
  1912. if (this._bumpTexture) {
  1913. activeTextures.push(this._bumpTexture);
  1914. }
  1915. return activeTextures;
  1916. };
  1917. WaterMaterial.prototype.hasTexture = function (texture) {
  1918. if (_super.prototype.hasTexture.call(this, texture)) {
  1919. return true;
  1920. }
  1921. if (this._bumpTexture === texture) {
  1922. return true;
  1923. }
  1924. return false;
  1925. };
  1926. WaterMaterial.prototype.dispose = function (forceDisposeEffect) {
  1927. if (this.bumpTexture) {
  1928. this.bumpTexture.dispose();
  1929. }
  1930. var index = this.getScene().customRenderTargets.indexOf(this._refractionRTT);
  1931. if (index != -1) {
  1932. this.getScene().customRenderTargets.splice(index, 1);
  1933. }
  1934. index = -1;
  1935. index = this.getScene().customRenderTargets.indexOf(this._reflectionRTT);
  1936. if (index != -1) {
  1937. this.getScene().customRenderTargets.splice(index, 1);
  1938. }
  1939. if (this._reflectionRTT) {
  1940. this._reflectionRTT.dispose();
  1941. }
  1942. if (this._refractionRTT) {
  1943. this._refractionRTT.dispose();
  1944. }
  1945. _super.prototype.dispose.call(this, forceDisposeEffect);
  1946. };
  1947. WaterMaterial.prototype.clone = function (name) {
  1948. var _this = this;
  1949. return BABYLON.SerializationHelper.Clone(function () { return new WaterMaterial(name, _this.getScene()); }, this);
  1950. };
  1951. WaterMaterial.prototype.serialize = function () {
  1952. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  1953. serializationObject.customType = "BABYLON.WaterMaterial";
  1954. serializationObject.renderList = [];
  1955. if (this._refractionRTT && this._refractionRTT.renderList) {
  1956. for (var i = 0; i < this._refractionRTT.renderList.length; i++) {
  1957. serializationObject.renderList.push(this._refractionRTT.renderList[i].id);
  1958. }
  1959. }
  1960. return serializationObject;
  1961. };
  1962. WaterMaterial.prototype.getClassName = function () {
  1963. return "WaterMaterial";
  1964. };
  1965. // Statics
  1966. WaterMaterial.Parse = function (source, scene, rootUrl) {
  1967. var mat = BABYLON.SerializationHelper.Parse(function () { return new WaterMaterial(source.name, scene); }, source, scene, rootUrl);
  1968. mat._waitingRenderList = source.renderList;
  1969. return mat;
  1970. };
  1971. WaterMaterial.CreateDefaultMesh = function (name, scene) {
  1972. var mesh = BABYLON.Mesh.CreateGround(name, 512, 512, 32, scene, false);
  1973. return mesh;
  1974. };
  1975. __decorate([
  1976. BABYLON.serializeAsTexture("bumpTexture")
  1977. ], WaterMaterial.prototype, "_bumpTexture", void 0);
  1978. __decorate([
  1979. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1980. ], WaterMaterial.prototype, "bumpTexture", void 0);
  1981. __decorate([
  1982. BABYLON.serializeAsColor3()
  1983. ], WaterMaterial.prototype, "diffuseColor", void 0);
  1984. __decorate([
  1985. BABYLON.serializeAsColor3()
  1986. ], WaterMaterial.prototype, "specularColor", void 0);
  1987. __decorate([
  1988. BABYLON.serialize()
  1989. ], WaterMaterial.prototype, "specularPower", void 0);
  1990. __decorate([
  1991. BABYLON.serialize("disableLighting")
  1992. ], WaterMaterial.prototype, "_disableLighting", void 0);
  1993. __decorate([
  1994. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1995. ], WaterMaterial.prototype, "disableLighting", void 0);
  1996. __decorate([
  1997. BABYLON.serialize("maxSimultaneousLights")
  1998. ], WaterMaterial.prototype, "_maxSimultaneousLights", void 0);
  1999. __decorate([
  2000. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  2001. ], WaterMaterial.prototype, "maxSimultaneousLights", void 0);
  2002. __decorate([
  2003. BABYLON.serialize()
  2004. ], WaterMaterial.prototype, "windForce", void 0);
  2005. __decorate([
  2006. BABYLON.serializeAsVector2()
  2007. ], WaterMaterial.prototype, "windDirection", void 0);
  2008. __decorate([
  2009. BABYLON.serialize()
  2010. ], WaterMaterial.prototype, "waveHeight", void 0);
  2011. __decorate([
  2012. BABYLON.serialize()
  2013. ], WaterMaterial.prototype, "bumpHeight", void 0);
  2014. __decorate([
  2015. BABYLON.serialize("bumpSuperimpose")
  2016. ], WaterMaterial.prototype, "_bumpSuperimpose", void 0);
  2017. __decorate([
  2018. BABYLON.expandToProperty("_markAllSubMeshesAsMiscDirty")
  2019. ], WaterMaterial.prototype, "bumpSuperimpose", void 0);
  2020. __decorate([
  2021. BABYLON.serialize("fresnelSeparate")
  2022. ], WaterMaterial.prototype, "_fresnelSeparate", void 0);
  2023. __decorate([
  2024. BABYLON.expandToProperty("_markAllSubMeshesAsMiscDirty")
  2025. ], WaterMaterial.prototype, "fresnelSeparate", void 0);
  2026. __decorate([
  2027. BABYLON.serialize("bumpAffectsReflection")
  2028. ], WaterMaterial.prototype, "_bumpAffectsReflection", void 0);
  2029. __decorate([
  2030. BABYLON.expandToProperty("_markAllSubMeshesAsMiscDirty")
  2031. ], WaterMaterial.prototype, "bumpAffectsReflection", void 0);
  2032. __decorate([
  2033. BABYLON.serializeAsColor3()
  2034. ], WaterMaterial.prototype, "waterColor", void 0);
  2035. __decorate([
  2036. BABYLON.serialize()
  2037. ], WaterMaterial.prototype, "colorBlendFactor", void 0);
  2038. __decorate([
  2039. BABYLON.serializeAsColor3()
  2040. ], WaterMaterial.prototype, "waterColor2", void 0);
  2041. __decorate([
  2042. BABYLON.serialize()
  2043. ], WaterMaterial.prototype, "colorBlendFactor2", void 0);
  2044. __decorate([
  2045. BABYLON.serialize()
  2046. ], WaterMaterial.prototype, "waveLength", void 0);
  2047. __decorate([
  2048. BABYLON.serialize()
  2049. ], WaterMaterial.prototype, "waveSpeed", void 0);
  2050. __decorate([
  2051. BABYLON.serialize()
  2052. ], WaterMaterial.prototype, "useLogarithmicDepth", null);
  2053. return WaterMaterial;
  2054. }(BABYLON.PushMaterial));
  2055. BABYLON.WaterMaterial = WaterMaterial;
  2056. })(BABYLON || (BABYLON = {}));
  2057. //# sourceMappingURL=babylon.waterMaterial.js.map
  2058. BABYLON.Effect.ShadersStore['waterVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef BUMP\nvarying vec2 vNormalUV;\n#ifdef BUMPSUPERIMPOSE\nvarying vec2 vNormalUV2;\n#endif\nuniform mat4 normalMatrix;\nuniform vec2 vNormalInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<logDepthDeclaration>\n\nuniform mat4 worldReflectionViewProjection;\nuniform vec2 windDirection;\nuniform float waveLength;\nuniform float time;\nuniform float windForce;\nuniform float waveHeight;\nuniform float waveSpeed;\n\nvarying vec3 vPosition;\nvarying vec3 vRefractionMapTexCoord;\nvarying vec3 vReflectionMapTexCoord;\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef BUMP\nif (vNormalInfos.x == 0.)\n{\nvNormalUV=vec2(normalMatrix*vec4((uv*1.0)/waveLength+time*windForce*windDirection,1.0,0.0));\n#ifdef BUMPSUPERIMPOSE\nvNormalUV2=vec2(normalMatrix*vec4((uv*0.721)/waveLength+time*1.2*windForce*windDirection,1.0,0.0));\n#endif\n}\nelse\n{\nvNormalUV=vec2(normalMatrix*vec4((uv2*1.0)/waveLength+time*windForce*windDirection ,1.0,0.0));\n#ifdef BUMPSUPERIMPOSE\nvNormalUV2=vec2(normalMatrix*vec4((uv2*0.721)/waveLength+time*1.2*windForce*windDirection ,1.0,0.0));\n#endif\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\nvec3 p=position;\nfloat newY=(sin(((p.x/0.05)+time*waveSpeed))*waveHeight*windDirection.x*5.0)\n+(cos(((p.z/0.05)+time*waveSpeed))*waveHeight*windDirection.y*5.0);\np.y+=abs(newY);\ngl_Position=viewProjection*finalWorld*vec4(p,1.0);\n#ifdef REFLECTION\nworldPos=viewProjection*finalWorld*vec4(p,1.0);\n\nvPosition=position;\nvRefractionMapTexCoord.x=0.5*(worldPos.w+worldPos.x);\nvRefractionMapTexCoord.y=0.5*(worldPos.w+worldPos.y);\nvRefractionMapTexCoord.z=worldPos.w;\nworldPos=worldReflectionViewProjection*vec4(position,1.0);\nvReflectionMapTexCoord.x=0.5*(worldPos.w+worldPos.x);\nvReflectionMapTexCoord.y=0.5*(worldPos.w+worldPos.y);\nvReflectionMapTexCoord.z=worldPos.w;\n#endif\n#include<logDepthVertex>\n}\n";
  2059. BABYLON.Effect.ShadersStore['waterPixelShader'] = "#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nprecision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef BUMP\nvarying vec2 vNormalUV;\nvarying vec2 vNormalUV2;\nuniform sampler2D normalSampler;\nuniform vec2 vNormalInfos;\n#endif\nuniform sampler2D refractionSampler;\nuniform sampler2D reflectionSampler;\n\nconst float LOG2=1.442695;\nuniform vec3 cameraPosition;\nuniform vec4 waterColor;\nuniform float colorBlendFactor;\nuniform vec4 waterColor2;\nuniform float colorBlendFactor2;\nuniform float bumpHeight;\nuniform float time;\n\nvarying vec3 vRefractionMapTexCoord;\nvarying vec3 vReflectionMapTexCoord;\nvarying vec3 vPosition;\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef BUMP\n#ifdef BUMPSUPERIMPOSE\nbaseColor=0.6*texture2D(normalSampler,vNormalUV)+0.4*texture2D(normalSampler,vec2(vNormalUV2.x,vNormalUV2.y));\n#else\nbaseColor=texture2D(normalSampler,vNormalUV);\n#endif\nvec3 bumpColor=baseColor.rgb;\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\nbaseColor.rgb*=vNormalInfos.y;\n#else\nvec3 bumpColor=vec3(1.0);\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec2 perturbation=bumpHeight*(baseColor.rg-0.5);\n#ifdef BUMPAFFECTSREFLECTION\nvec3 normalW=normalize(vNormalW+vec3(perturbation.x*8.0,0.0,perturbation.y*8.0));\nif (normalW.y<0.0) {\nnormalW.y=-normalW.y;\n}\n#else\nvec3 normalW=normalize(vNormalW);\n#endif\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\nvec2 perturbation=bumpHeight*(vec2(1.0,1.0)-0.5);\n#endif\n#ifdef FRESNELSEPARATE\n#ifdef REFLECTION\n\nvec3 eyeVector=normalize(vEyePosition-vPosition);\nvec2 projectedRefractionTexCoords=clamp(vRefractionMapTexCoord.xy/vRefractionMapTexCoord.z+perturbation*0.5,0.0,1.0);\nvec4 refractiveColor=texture2D(refractionSampler,projectedRefractionTexCoords);\nvec2 projectedReflectionTexCoords=clamp(vec2(\nvReflectionMapTexCoord.x/vReflectionMapTexCoord.z+perturbation.x*0.3,\nvReflectionMapTexCoord.y/vReflectionMapTexCoord.z+perturbation.y\n),0.0,1.0);\nvec4 reflectiveColor=texture2D(reflectionSampler,projectedReflectionTexCoords);\nvec3 upVector=vec3(0.0,1.0,0.0);\nfloat fresnelTerm=clamp(abs(pow(dot(eyeVector,upVector),3.0)),0.05,0.65);\nfloat IfresnelTerm=1.0-fresnelTerm;\nrefractiveColor=colorBlendFactor*waterColor+(1.0-colorBlendFactor)*refractiveColor;\nreflectiveColor=IfresnelTerm*colorBlendFactor2*waterColor+(1.0-colorBlendFactor2*IfresnelTerm)*reflectiveColor;\nvec4 combinedColor=refractiveColor*fresnelTerm+reflectiveColor*IfresnelTerm;\nbaseColor=combinedColor;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularBase=vec3(0.,0.,0.);\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\nvec3 finalDiffuse=clamp(baseColor.rgb,0.0,1.0);\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#else \n#ifdef REFLECTION\n\nvec3 eyeVector=normalize(vEyePosition-vPosition);\nvec2 projectedRefractionTexCoords=clamp(vRefractionMapTexCoord.xy/vRefractionMapTexCoord.z+perturbation,0.0,1.0);\nvec4 refractiveColor=texture2D(refractionSampler,projectedRefractionTexCoords);\nvec2 projectedReflectionTexCoords=clamp(vReflectionMapTexCoord.xy/vReflectionMapTexCoord.z+perturbation,0.0,1.0);\nvec4 reflectiveColor=texture2D(reflectionSampler,projectedReflectionTexCoords);\nvec3 upVector=vec3(0.0,1.0,0.0);\nfloat fresnelTerm=max(dot(eyeVector,upVector),0.0);\nvec4 combinedColor=refractiveColor*fresnelTerm+reflectiveColor*(1.0-fresnelTerm);\nbaseColor=colorBlendFactor*waterColor+(1.0-colorBlendFactor)*combinedColor;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularBase=vec3(0.,0.,0.);\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\nvec3 finalDiffuse=clamp(baseColor.rgb,0.0,1.0);\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#endif\n\nvec4 color=vec4(finalDiffuse+finalSpecular,alpha);\n#include<logDepthFragment>\n#include<fogFragment>\ngl_FragColor=color;\n}\n";
  2060. var BABYLON;
  2061. (function (BABYLON) {
  2062. var FireMaterialDefines = /** @class */ (function (_super) {
  2063. __extends(FireMaterialDefines, _super);
  2064. function FireMaterialDefines() {
  2065. var _this = _super.call(this) || this;
  2066. _this.DIFFUSE = false;
  2067. _this.CLIPPLANE = false;
  2068. _this.CLIPPLANE2 = false;
  2069. _this.CLIPPLANE3 = false;
  2070. _this.CLIPPLANE4 = false;
  2071. _this.ALPHATEST = false;
  2072. _this.DEPTHPREPASS = false;
  2073. _this.POINTSIZE = false;
  2074. _this.FOG = false;
  2075. _this.UV1 = false;
  2076. _this.VERTEXCOLOR = false;
  2077. _this.VERTEXALPHA = false;
  2078. _this.BonesPerMesh = 0;
  2079. _this.NUM_BONE_INFLUENCERS = 0;
  2080. _this.INSTANCES = false;
  2081. _this.rebuild();
  2082. return _this;
  2083. }
  2084. return FireMaterialDefines;
  2085. }(BABYLON.MaterialDefines));
  2086. var FireMaterial = /** @class */ (function (_super) {
  2087. __extends(FireMaterial, _super);
  2088. function FireMaterial(name, scene) {
  2089. var _this = _super.call(this, name, scene) || this;
  2090. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  2091. _this.speed = 1.0;
  2092. _this._scaledDiffuse = new BABYLON.Color3();
  2093. _this._lastTime = 0;
  2094. return _this;
  2095. }
  2096. FireMaterial.prototype.needAlphaBlending = function () {
  2097. return false;
  2098. };
  2099. FireMaterial.prototype.needAlphaTesting = function () {
  2100. return true;
  2101. };
  2102. FireMaterial.prototype.getAlphaTestTexture = function () {
  2103. return null;
  2104. };
  2105. // Methods
  2106. FireMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  2107. if (this.isFrozen) {
  2108. if (this._wasPreviouslyReady && subMesh.effect) {
  2109. return true;
  2110. }
  2111. }
  2112. if (!subMesh._materialDefines) {
  2113. subMesh._materialDefines = new FireMaterialDefines();
  2114. }
  2115. var defines = subMesh._materialDefines;
  2116. var scene = this.getScene();
  2117. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  2118. if (this._renderId === scene.getRenderId()) {
  2119. return true;
  2120. }
  2121. }
  2122. var engine = scene.getEngine();
  2123. // Textures
  2124. if (defines._areTexturesDirty) {
  2125. defines._needUVs = false;
  2126. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2127. if (!this._diffuseTexture.isReady()) {
  2128. return false;
  2129. }
  2130. else {
  2131. defines._needUVs = true;
  2132. defines.DIFFUSE = true;
  2133. }
  2134. }
  2135. }
  2136. defines.ALPHATEST = this._opacityTexture ? true : false;
  2137. // Misc.
  2138. if (defines._areMiscDirty) {
  2139. defines.POINTSIZE = (this.pointsCloud || scene.forcePointsCloud);
  2140. defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled);
  2141. }
  2142. // Values that need to be evaluated on every frame
  2143. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  2144. // Attribs
  2145. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
  2146. // Get correct effect
  2147. if (defines.isDirty) {
  2148. defines.markAsProcessed();
  2149. scene.resetCachedMaterial();
  2150. // Fallbacks
  2151. var fallbacks = new BABYLON.EffectFallbacks();
  2152. if (defines.FOG) {
  2153. fallbacks.addFallback(1, "FOG");
  2154. }
  2155. if (defines.NUM_BONE_INFLUENCERS > 0) {
  2156. fallbacks.addCPUSkinningFallback(0, mesh);
  2157. }
  2158. //Attributes
  2159. var attribs = [BABYLON.VertexBuffer.PositionKind];
  2160. if (defines.UV1) {
  2161. attribs.push(BABYLON.VertexBuffer.UVKind);
  2162. }
  2163. if (defines.VERTEXCOLOR) {
  2164. attribs.push(BABYLON.VertexBuffer.ColorKind);
  2165. }
  2166. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  2167. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  2168. // Legacy browser patch
  2169. var shaderName = "fire";
  2170. var join = defines.toString();
  2171. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  2172. attributes: attribs,
  2173. uniformsNames: ["world", "view", "viewProjection", "vEyePosition",
  2174. "vFogInfos", "vFogColor", "pointSize",
  2175. "vDiffuseInfos",
  2176. "mBones",
  2177. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix",
  2178. // Fire
  2179. "time", "speed"
  2180. ],
  2181. uniformBuffersNames: [],
  2182. samplers: ["diffuseSampler",
  2183. // Fire
  2184. "distortionSampler", "opacitySampler"
  2185. ],
  2186. defines: join,
  2187. fallbacks: fallbacks,
  2188. onCompiled: this.onCompiled,
  2189. onError: this.onError,
  2190. indexParameters: null,
  2191. maxSimultaneousLights: 4,
  2192. transformFeedbackVaryings: null
  2193. }, engine), defines);
  2194. }
  2195. if (!subMesh.effect || !subMesh.effect.isReady()) {
  2196. return false;
  2197. }
  2198. this._renderId = scene.getRenderId();
  2199. this._wasPreviouslyReady = true;
  2200. return true;
  2201. };
  2202. FireMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  2203. var scene = this.getScene();
  2204. var defines = subMesh._materialDefines;
  2205. if (!defines) {
  2206. return;
  2207. }
  2208. var effect = subMesh.effect;
  2209. if (!effect) {
  2210. return;
  2211. }
  2212. this._activeEffect = effect;
  2213. // Matrices
  2214. this.bindOnlyWorldMatrix(world);
  2215. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  2216. // Bones
  2217. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  2218. if (this._mustRebind(scene, effect)) {
  2219. // Textures
  2220. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2221. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  2222. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  2223. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  2224. this._activeEffect.setTexture("distortionSampler", this._distortionTexture);
  2225. this._activeEffect.setTexture("opacitySampler", this._opacityTexture);
  2226. }
  2227. // Clip plane
  2228. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  2229. // Point size
  2230. if (this.pointsCloud) {
  2231. this._activeEffect.setFloat("pointSize", this.pointSize);
  2232. }
  2233. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  2234. }
  2235. this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  2236. // View
  2237. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  2238. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  2239. }
  2240. // Fog
  2241. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  2242. // Time
  2243. this._lastTime += scene.getEngine().getDeltaTime();
  2244. this._activeEffect.setFloat("time", this._lastTime);
  2245. // Speed
  2246. this._activeEffect.setFloat("speed", this.speed);
  2247. this._afterBind(mesh, this._activeEffect);
  2248. };
  2249. FireMaterial.prototype.getAnimatables = function () {
  2250. var results = [];
  2251. if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
  2252. results.push(this._diffuseTexture);
  2253. }
  2254. if (this._distortionTexture && this._distortionTexture.animations && this._distortionTexture.animations.length > 0) {
  2255. results.push(this._distortionTexture);
  2256. }
  2257. if (this._opacityTexture && this._opacityTexture.animations && this._opacityTexture.animations.length > 0) {
  2258. results.push(this._opacityTexture);
  2259. }
  2260. return results;
  2261. };
  2262. FireMaterial.prototype.getActiveTextures = function () {
  2263. var activeTextures = _super.prototype.getActiveTextures.call(this);
  2264. if (this._diffuseTexture) {
  2265. activeTextures.push(this._diffuseTexture);
  2266. }
  2267. if (this._distortionTexture) {
  2268. activeTextures.push(this._distortionTexture);
  2269. }
  2270. if (this._opacityTexture) {
  2271. activeTextures.push(this._opacityTexture);
  2272. }
  2273. return activeTextures;
  2274. };
  2275. FireMaterial.prototype.hasTexture = function (texture) {
  2276. if (_super.prototype.hasTexture.call(this, texture)) {
  2277. return true;
  2278. }
  2279. if (this._diffuseTexture === texture) {
  2280. return true;
  2281. }
  2282. if (this._distortionTexture === texture) {
  2283. return true;
  2284. }
  2285. if (this._opacityTexture === texture) {
  2286. return true;
  2287. }
  2288. return false;
  2289. };
  2290. FireMaterial.prototype.getClassName = function () {
  2291. return "FireMaterial";
  2292. };
  2293. FireMaterial.prototype.dispose = function (forceDisposeEffect) {
  2294. if (this._diffuseTexture) {
  2295. this._diffuseTexture.dispose();
  2296. }
  2297. if (this._distortionTexture) {
  2298. this._distortionTexture.dispose();
  2299. }
  2300. _super.prototype.dispose.call(this, forceDisposeEffect);
  2301. };
  2302. FireMaterial.prototype.clone = function (name) {
  2303. var _this = this;
  2304. return BABYLON.SerializationHelper.Clone(function () { return new FireMaterial(name, _this.getScene()); }, this);
  2305. };
  2306. FireMaterial.prototype.serialize = function () {
  2307. var serializationObject = _super.prototype.serialize.call(this);
  2308. serializationObject.customType = "BABYLON.FireMaterial";
  2309. serializationObject.diffuseColor = this.diffuseColor.asArray();
  2310. serializationObject.speed = this.speed;
  2311. if (this._diffuseTexture) {
  2312. serializationObject._diffuseTexture = this._diffuseTexture.serialize();
  2313. }
  2314. if (this._distortionTexture) {
  2315. serializationObject._distortionTexture = this._distortionTexture.serialize();
  2316. }
  2317. if (this._opacityTexture) {
  2318. serializationObject._opacityTexture = this._opacityTexture.serialize();
  2319. }
  2320. return serializationObject;
  2321. };
  2322. FireMaterial.Parse = function (source, scene, rootUrl) {
  2323. var material = new FireMaterial(source.name, scene);
  2324. material.diffuseColor = BABYLON.Color3.FromArray(source.diffuseColor);
  2325. material.speed = source.speed;
  2326. material.alpha = source.alpha;
  2327. material.id = source.id;
  2328. BABYLON.Tags.AddTagsTo(material, source.tags);
  2329. material.backFaceCulling = source.backFaceCulling;
  2330. material.wireframe = source.wireframe;
  2331. if (source._diffuseTexture) {
  2332. material._diffuseTexture = BABYLON.Texture.Parse(source._diffuseTexture, scene, rootUrl);
  2333. }
  2334. if (source._distortionTexture) {
  2335. material._distortionTexture = BABYLON.Texture.Parse(source._distortionTexture, scene, rootUrl);
  2336. }
  2337. if (source._opacityTexture) {
  2338. material._opacityTexture = BABYLON.Texture.Parse(source._opacityTexture, scene, rootUrl);
  2339. }
  2340. if (source.checkReadyOnlyOnce) {
  2341. material.checkReadyOnlyOnce = source.checkReadyOnlyOnce;
  2342. }
  2343. return material;
  2344. };
  2345. __decorate([
  2346. BABYLON.serializeAsTexture("diffuseTexture")
  2347. ], FireMaterial.prototype, "_diffuseTexture", void 0);
  2348. __decorate([
  2349. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2350. ], FireMaterial.prototype, "diffuseTexture", void 0);
  2351. __decorate([
  2352. BABYLON.serializeAsTexture("distortionTexture")
  2353. ], FireMaterial.prototype, "_distortionTexture", void 0);
  2354. __decorate([
  2355. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2356. ], FireMaterial.prototype, "distortionTexture", void 0);
  2357. __decorate([
  2358. BABYLON.serializeAsTexture("opacityTexture")
  2359. ], FireMaterial.prototype, "_opacityTexture", void 0);
  2360. __decorate([
  2361. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2362. ], FireMaterial.prototype, "opacityTexture", void 0);
  2363. __decorate([
  2364. BABYLON.serializeAsColor3("diffuse")
  2365. ], FireMaterial.prototype, "diffuseColor", void 0);
  2366. __decorate([
  2367. BABYLON.serialize()
  2368. ], FireMaterial.prototype, "speed", void 0);
  2369. return FireMaterial;
  2370. }(BABYLON.PushMaterial));
  2371. BABYLON.FireMaterial = FireMaterial;
  2372. })(BABYLON || (BABYLON = {}));
  2373. //# sourceMappingURL=babylon.fireMaterial.js.map
  2374. BABYLON.Effect.ShadersStore['fireVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n\nuniform float time;\nuniform float speed;\n#ifdef DIFFUSE\nvarying vec2 vDistortionCoords1;\nvarying vec2 vDistortionCoords2;\nvarying vec2 vDistortionCoords3;\n#endif\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n\n#ifdef DIFFUSE\nvDiffuseUV=uv;\nvDiffuseUV.y-=0.2;\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n#ifdef DIFFUSE\n\nvec3 layerSpeed=vec3(-0.2,-0.52,-0.1)*speed;\nvDistortionCoords1.x=uv.x;\nvDistortionCoords1.y=uv.y+layerSpeed.x*time/1000.0;\nvDistortionCoords2.x=uv.x;\nvDistortionCoords2.y=uv.y+layerSpeed.y*time/1000.0;\nvDistortionCoords3.x=uv.x;\nvDistortionCoords3.y=uv.y+layerSpeed.z*time/1000.0;\n#endif\n}\n";
  2375. BABYLON.Effect.ShadersStore['firePixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n\nuniform sampler2D distortionSampler;\nuniform sampler2D opacitySampler;\n#ifdef DIFFUSE\nvarying vec2 vDistortionCoords1;\nvarying vec2 vDistortionCoords2;\nvarying vec2 vDistortionCoords3;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvec4 bx2(vec4 x)\n{\nreturn vec4(2.0)*x-vec4(1.0);\n}\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\n\nfloat alpha=1.0;\n#ifdef DIFFUSE\n\nconst float distortionAmount0=0.092;\nconst float distortionAmount1=0.092;\nconst float distortionAmount2=0.092;\nvec2 heightAttenuation=vec2(0.3,0.39);\nvec4 noise0=texture2D(distortionSampler,vDistortionCoords1);\nvec4 noise1=texture2D(distortionSampler,vDistortionCoords2);\nvec4 noise2=texture2D(distortionSampler,vDistortionCoords3);\nvec4 noiseSum=bx2(noise0)*distortionAmount0+bx2(noise1)*distortionAmount1+bx2(noise2)*distortionAmount2;\nvec4 perturbedBaseCoords=vec4(vDiffuseUV,0.0,1.0)+noiseSum*(vDiffuseUV.y*heightAttenuation.x+heightAttenuation.y);\nvec4 opacityColor=texture2D(opacitySampler,perturbedBaseCoords.xy);\n#ifdef ALPHATEST\nif (opacityColor.r<0.1)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor=texture2D(diffuseSampler,perturbedBaseCoords.xy)*2.0;\nbaseColor*=opacityColor;\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 diffuseBase=vec3(1.0,1.0,1.0);\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n\nvec4 color=vec4(baseColor.rgb,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
  2376. var BABYLON;
  2377. (function (BABYLON) {
  2378. var FurMaterialDefines = /** @class */ (function (_super) {
  2379. __extends(FurMaterialDefines, _super);
  2380. function FurMaterialDefines() {
  2381. var _this = _super.call(this) || this;
  2382. _this.DIFFUSE = false;
  2383. _this.HEIGHTMAP = false;
  2384. _this.CLIPPLANE = false;
  2385. _this.CLIPPLANE2 = false;
  2386. _this.CLIPPLANE3 = false;
  2387. _this.CLIPPLANE4 = false;
  2388. _this.ALPHATEST = false;
  2389. _this.DEPTHPREPASS = false;
  2390. _this.POINTSIZE = false;
  2391. _this.FOG = false;
  2392. _this.NORMAL = false;
  2393. _this.UV1 = false;
  2394. _this.UV2 = false;
  2395. _this.VERTEXCOLOR = false;
  2396. _this.VERTEXALPHA = false;
  2397. _this.NUM_BONE_INFLUENCERS = 0;
  2398. _this.BonesPerMesh = 0;
  2399. _this.INSTANCES = false;
  2400. _this.HIGHLEVEL = false;
  2401. _this.rebuild();
  2402. return _this;
  2403. }
  2404. return FurMaterialDefines;
  2405. }(BABYLON.MaterialDefines));
  2406. var FurMaterial = /** @class */ (function (_super) {
  2407. __extends(FurMaterial, _super);
  2408. function FurMaterial(name, scene) {
  2409. var _this = _super.call(this, name, scene) || this;
  2410. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  2411. _this.furLength = 1;
  2412. _this.furAngle = 0;
  2413. _this.furColor = new BABYLON.Color3(0.44, 0.21, 0.02);
  2414. _this.furOffset = 0.0;
  2415. _this.furSpacing = 12;
  2416. _this.furGravity = new BABYLON.Vector3(0, 0, 0);
  2417. _this.furSpeed = 100;
  2418. _this.furDensity = 20;
  2419. _this.furOcclusion = 0.0;
  2420. _this._disableLighting = false;
  2421. _this._maxSimultaneousLights = 4;
  2422. _this.highLevelFur = true;
  2423. _this._furTime = 0;
  2424. return _this;
  2425. }
  2426. Object.defineProperty(FurMaterial.prototype, "furTime", {
  2427. get: function () {
  2428. return this._furTime;
  2429. },
  2430. set: function (furTime) {
  2431. this._furTime = furTime;
  2432. },
  2433. enumerable: true,
  2434. configurable: true
  2435. });
  2436. FurMaterial.prototype.needAlphaBlending = function () {
  2437. return (this.alpha < 1.0);
  2438. };
  2439. FurMaterial.prototype.needAlphaTesting = function () {
  2440. return false;
  2441. };
  2442. FurMaterial.prototype.getAlphaTestTexture = function () {
  2443. return null;
  2444. };
  2445. FurMaterial.prototype.updateFur = function () {
  2446. for (var i = 1; i < this._meshes.length; i++) {
  2447. var offsetFur = this._meshes[i].material;
  2448. offsetFur.furLength = this.furLength;
  2449. offsetFur.furAngle = this.furAngle;
  2450. offsetFur.furGravity = this.furGravity;
  2451. offsetFur.furSpacing = this.furSpacing;
  2452. offsetFur.furSpeed = this.furSpeed;
  2453. offsetFur.furColor = this.furColor;
  2454. offsetFur.diffuseTexture = this.diffuseTexture;
  2455. offsetFur.furTexture = this.furTexture;
  2456. offsetFur.highLevelFur = this.highLevelFur;
  2457. offsetFur.furTime = this.furTime;
  2458. offsetFur.furDensity = this.furDensity;
  2459. }
  2460. };
  2461. // Methods
  2462. FurMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  2463. if (this.isFrozen) {
  2464. if (this._wasPreviouslyReady && subMesh.effect) {
  2465. return true;
  2466. }
  2467. }
  2468. if (!subMesh._materialDefines) {
  2469. subMesh._materialDefines = new FurMaterialDefines();
  2470. }
  2471. var defines = subMesh._materialDefines;
  2472. var scene = this.getScene();
  2473. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  2474. if (this._renderId === scene.getRenderId()) {
  2475. return true;
  2476. }
  2477. }
  2478. var engine = scene.getEngine();
  2479. // Textures
  2480. if (defines._areTexturesDirty) {
  2481. if (scene.texturesEnabled) {
  2482. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2483. if (!this.diffuseTexture.isReady()) {
  2484. return false;
  2485. }
  2486. else {
  2487. defines._needUVs = true;
  2488. defines.DIFFUSE = true;
  2489. }
  2490. }
  2491. if (this.heightTexture && engine.getCaps().maxVertexTextureImageUnits) {
  2492. if (!this.heightTexture.isReady()) {
  2493. return false;
  2494. }
  2495. else {
  2496. defines._needUVs = true;
  2497. defines.HEIGHTMAP = true;
  2498. }
  2499. }
  2500. }
  2501. }
  2502. // High level
  2503. if (this.highLevelFur !== defines.HIGHLEVEL) {
  2504. defines.HIGHLEVEL = true;
  2505. defines.markAsUnprocessed();
  2506. }
  2507. // Misc.
  2508. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  2509. // Lights
  2510. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  2511. // Values that need to be evaluated on every frame
  2512. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  2513. // Attribs
  2514. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  2515. // Get correct effect
  2516. if (defines.isDirty) {
  2517. defines.markAsProcessed();
  2518. scene.resetCachedMaterial();
  2519. // Fallbacks
  2520. var fallbacks = new BABYLON.EffectFallbacks();
  2521. if (defines.FOG) {
  2522. fallbacks.addFallback(1, "FOG");
  2523. }
  2524. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  2525. if (defines.NUM_BONE_INFLUENCERS > 0) {
  2526. fallbacks.addCPUSkinningFallback(0, mesh);
  2527. }
  2528. //Attributes
  2529. var attribs = [BABYLON.VertexBuffer.PositionKind];
  2530. if (defines.NORMAL) {
  2531. attribs.push(BABYLON.VertexBuffer.NormalKind);
  2532. }
  2533. if (defines.UV1) {
  2534. attribs.push(BABYLON.VertexBuffer.UVKind);
  2535. }
  2536. if (defines.UV2) {
  2537. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  2538. }
  2539. if (defines.VERTEXCOLOR) {
  2540. attribs.push(BABYLON.VertexBuffer.ColorKind);
  2541. }
  2542. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  2543. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  2544. // Legacy browser patch
  2545. var shaderName = "fur";
  2546. var join = defines.toString();
  2547. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  2548. "vFogInfos", "vFogColor", "pointSize",
  2549. "vDiffuseInfos",
  2550. "mBones",
  2551. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix",
  2552. "furLength", "furAngle", "furColor", "furOffset", "furGravity", "furTime", "furSpacing", "furDensity", "furOcclusion"
  2553. ];
  2554. var samplers = ["diffuseSampler",
  2555. "heightTexture", "furTexture"
  2556. ];
  2557. var uniformBuffers = new Array();
  2558. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  2559. uniformsNames: uniforms,
  2560. uniformBuffersNames: uniformBuffers,
  2561. samplers: samplers,
  2562. defines: defines,
  2563. maxSimultaneousLights: this.maxSimultaneousLights
  2564. });
  2565. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  2566. attributes: attribs,
  2567. uniformsNames: uniforms,
  2568. uniformBuffersNames: uniformBuffers,
  2569. samplers: samplers,
  2570. defines: join,
  2571. fallbacks: fallbacks,
  2572. onCompiled: this.onCompiled,
  2573. onError: this.onError,
  2574. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  2575. }, engine), defines);
  2576. }
  2577. if (!subMesh.effect || !subMesh.effect.isReady()) {
  2578. return false;
  2579. }
  2580. this._renderId = scene.getRenderId();
  2581. this._wasPreviouslyReady = true;
  2582. return true;
  2583. };
  2584. FurMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  2585. var scene = this.getScene();
  2586. var defines = subMesh._materialDefines;
  2587. if (!defines) {
  2588. return;
  2589. }
  2590. var effect = subMesh.effect;
  2591. if (!effect) {
  2592. return;
  2593. }
  2594. this._activeEffect = effect;
  2595. // Matrices
  2596. this.bindOnlyWorldMatrix(world);
  2597. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  2598. // Bones
  2599. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  2600. if (scene.getCachedMaterial() !== this) {
  2601. // Textures
  2602. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2603. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  2604. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  2605. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  2606. }
  2607. if (this._heightTexture) {
  2608. this._activeEffect.setTexture("heightTexture", this._heightTexture);
  2609. }
  2610. // Clip plane
  2611. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  2612. // Point size
  2613. if (this.pointsCloud) {
  2614. this._activeEffect.setFloat("pointSize", this.pointSize);
  2615. }
  2616. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  2617. }
  2618. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  2619. if (scene.lightsEnabled && !this.disableLighting) {
  2620. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  2621. }
  2622. // View
  2623. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  2624. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  2625. }
  2626. // Fog
  2627. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  2628. this._activeEffect.setFloat("furLength", this.furLength);
  2629. this._activeEffect.setFloat("furAngle", this.furAngle);
  2630. this._activeEffect.setColor4("furColor", this.furColor, 1.0);
  2631. if (this.highLevelFur) {
  2632. this._activeEffect.setVector3("furGravity", this.furGravity);
  2633. this._activeEffect.setFloat("furOffset", this.furOffset);
  2634. this._activeEffect.setFloat("furSpacing", this.furSpacing);
  2635. this._activeEffect.setFloat("furDensity", this.furDensity);
  2636. this._activeEffect.setFloat("furOcclusion", this.furOcclusion);
  2637. this._furTime += this.getScene().getEngine().getDeltaTime() / this.furSpeed;
  2638. this._activeEffect.setFloat("furTime", this._furTime);
  2639. this._activeEffect.setTexture("furTexture", this.furTexture);
  2640. }
  2641. this._afterBind(mesh, this._activeEffect);
  2642. };
  2643. FurMaterial.prototype.getAnimatables = function () {
  2644. var results = [];
  2645. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  2646. results.push(this.diffuseTexture);
  2647. }
  2648. if (this.heightTexture && this.heightTexture.animations && this.heightTexture.animations.length > 0) {
  2649. results.push(this.heightTexture);
  2650. }
  2651. return results;
  2652. };
  2653. FurMaterial.prototype.getActiveTextures = function () {
  2654. var activeTextures = _super.prototype.getActiveTextures.call(this);
  2655. if (this._diffuseTexture) {
  2656. activeTextures.push(this._diffuseTexture);
  2657. }
  2658. if (this._heightTexture) {
  2659. activeTextures.push(this._heightTexture);
  2660. }
  2661. return activeTextures;
  2662. };
  2663. FurMaterial.prototype.hasTexture = function (texture) {
  2664. if (_super.prototype.hasTexture.call(this, texture)) {
  2665. return true;
  2666. }
  2667. if (this.diffuseTexture === texture) {
  2668. return true;
  2669. }
  2670. if (this._heightTexture === texture) {
  2671. return true;
  2672. }
  2673. return false;
  2674. };
  2675. FurMaterial.prototype.dispose = function (forceDisposeEffect) {
  2676. if (this.diffuseTexture) {
  2677. this.diffuseTexture.dispose();
  2678. }
  2679. if (this._meshes) {
  2680. for (var i = 1; i < this._meshes.length; i++) {
  2681. var mat = this._meshes[i].material;
  2682. if (mat) {
  2683. mat.dispose(forceDisposeEffect);
  2684. }
  2685. this._meshes[i].dispose();
  2686. }
  2687. }
  2688. _super.prototype.dispose.call(this, forceDisposeEffect);
  2689. };
  2690. FurMaterial.prototype.clone = function (name) {
  2691. var _this = this;
  2692. return BABYLON.SerializationHelper.Clone(function () { return new FurMaterial(name, _this.getScene()); }, this);
  2693. };
  2694. FurMaterial.prototype.serialize = function () {
  2695. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  2696. serializationObject.customType = "BABYLON.FurMaterial";
  2697. if (this._meshes) {
  2698. serializationObject.sourceMeshName = this._meshes[0].name;
  2699. serializationObject.quality = this._meshes.length;
  2700. }
  2701. return serializationObject;
  2702. };
  2703. FurMaterial.prototype.getClassName = function () {
  2704. return "FurMaterial";
  2705. };
  2706. // Statics
  2707. FurMaterial.Parse = function (source, scene, rootUrl) {
  2708. var material = BABYLON.SerializationHelper.Parse(function () { return new FurMaterial(source.name, scene); }, source, scene, rootUrl);
  2709. if (source.sourceMeshName && material.highLevelFur) {
  2710. scene.executeWhenReady(function () {
  2711. var sourceMesh = scene.getMeshByName(source.sourceMeshName);
  2712. if (sourceMesh) {
  2713. var furTexture = FurMaterial.GenerateTexture("Fur Texture", scene);
  2714. material.furTexture = furTexture;
  2715. FurMaterial.FurifyMesh(sourceMesh, source.quality);
  2716. }
  2717. });
  2718. }
  2719. return material;
  2720. };
  2721. FurMaterial.GenerateTexture = function (name, scene) {
  2722. // Generate fur textures
  2723. var texture = new BABYLON.DynamicTexture("FurTexture " + name, 256, scene, true);
  2724. var context = texture.getContext();
  2725. for (var i = 0; i < 20000; ++i) {
  2726. context.fillStyle = "rgba(255, " + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", 1)";
  2727. context.fillRect((Math.random() * texture.getSize().width), (Math.random() * texture.getSize().height), 2, 2);
  2728. }
  2729. texture.update(false);
  2730. texture.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
  2731. texture.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
  2732. return texture;
  2733. };
  2734. // Creates and returns an array of meshes used as shells for the Fur Material
  2735. // that can be disposed later in your code
  2736. // The quality is in interval [0, 100]
  2737. FurMaterial.FurifyMesh = function (sourceMesh, quality) {
  2738. var meshes = [sourceMesh];
  2739. var mat = sourceMesh.material;
  2740. var i;
  2741. if (!(mat instanceof FurMaterial)) {
  2742. throw "The material of the source mesh must be a Fur Material";
  2743. }
  2744. for (i = 1; i < quality; i++) {
  2745. var offsetFur = new BABYLON.FurMaterial(mat.name + i, sourceMesh.getScene());
  2746. sourceMesh.getScene().materials.pop();
  2747. BABYLON.Tags.EnableFor(offsetFur);
  2748. BABYLON.Tags.AddTagsTo(offsetFur, "furShellMaterial");
  2749. offsetFur.furLength = mat.furLength;
  2750. offsetFur.furAngle = mat.furAngle;
  2751. offsetFur.furGravity = mat.furGravity;
  2752. offsetFur.furSpacing = mat.furSpacing;
  2753. offsetFur.furSpeed = mat.furSpeed;
  2754. offsetFur.furColor = mat.furColor;
  2755. offsetFur.diffuseTexture = mat.diffuseTexture;
  2756. offsetFur.furOffset = i / quality;
  2757. offsetFur.furTexture = mat.furTexture;
  2758. offsetFur.highLevelFur = mat.highLevelFur;
  2759. offsetFur.furTime = mat.furTime;
  2760. offsetFur.furDensity = mat.furDensity;
  2761. var offsetMesh = sourceMesh.clone(sourceMesh.name + i);
  2762. offsetMesh.material = offsetFur;
  2763. offsetMesh.skeleton = sourceMesh.skeleton;
  2764. offsetMesh.position = BABYLON.Vector3.Zero();
  2765. meshes.push(offsetMesh);
  2766. }
  2767. for (i = 1; i < meshes.length; i++) {
  2768. meshes[i].parent = sourceMesh;
  2769. }
  2770. sourceMesh.material._meshes = meshes;
  2771. return meshes;
  2772. };
  2773. __decorate([
  2774. BABYLON.serializeAsTexture("diffuseTexture")
  2775. ], FurMaterial.prototype, "_diffuseTexture", void 0);
  2776. __decorate([
  2777. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2778. ], FurMaterial.prototype, "diffuseTexture", void 0);
  2779. __decorate([
  2780. BABYLON.serializeAsTexture("heightTexture")
  2781. ], FurMaterial.prototype, "_heightTexture", void 0);
  2782. __decorate([
  2783. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2784. ], FurMaterial.prototype, "heightTexture", void 0);
  2785. __decorate([
  2786. BABYLON.serializeAsColor3()
  2787. ], FurMaterial.prototype, "diffuseColor", void 0);
  2788. __decorate([
  2789. BABYLON.serialize()
  2790. ], FurMaterial.prototype, "furLength", void 0);
  2791. __decorate([
  2792. BABYLON.serialize()
  2793. ], FurMaterial.prototype, "furAngle", void 0);
  2794. __decorate([
  2795. BABYLON.serializeAsColor3()
  2796. ], FurMaterial.prototype, "furColor", void 0);
  2797. __decorate([
  2798. BABYLON.serialize()
  2799. ], FurMaterial.prototype, "furOffset", void 0);
  2800. __decorate([
  2801. BABYLON.serialize()
  2802. ], FurMaterial.prototype, "furSpacing", void 0);
  2803. __decorate([
  2804. BABYLON.serializeAsVector3()
  2805. ], FurMaterial.prototype, "furGravity", void 0);
  2806. __decorate([
  2807. BABYLON.serialize()
  2808. ], FurMaterial.prototype, "furSpeed", void 0);
  2809. __decorate([
  2810. BABYLON.serialize()
  2811. ], FurMaterial.prototype, "furDensity", void 0);
  2812. __decorate([
  2813. BABYLON.serialize()
  2814. ], FurMaterial.prototype, "furOcclusion", void 0);
  2815. __decorate([
  2816. BABYLON.serialize("disableLighting")
  2817. ], FurMaterial.prototype, "_disableLighting", void 0);
  2818. __decorate([
  2819. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  2820. ], FurMaterial.prototype, "disableLighting", void 0);
  2821. __decorate([
  2822. BABYLON.serialize("maxSimultaneousLights")
  2823. ], FurMaterial.prototype, "_maxSimultaneousLights", void 0);
  2824. __decorate([
  2825. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  2826. ], FurMaterial.prototype, "maxSimultaneousLights", void 0);
  2827. __decorate([
  2828. BABYLON.serialize()
  2829. ], FurMaterial.prototype, "highLevelFur", void 0);
  2830. __decorate([
  2831. BABYLON.serialize()
  2832. ], FurMaterial.prototype, "furTime", null);
  2833. return FurMaterial;
  2834. }(BABYLON.PushMaterial));
  2835. BABYLON.FurMaterial = FurMaterial;
  2836. })(BABYLON || (BABYLON = {}));
  2837. //# sourceMappingURL=babylon.furMaterial.js.map
  2838. BABYLON.Effect.ShadersStore['furVertexShader'] = "precision highp float;\n\nattribute vec3 position;\nattribute vec3 normal;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\nuniform float furLength;\nuniform float furAngle;\n#ifdef HIGHLEVEL\nuniform float furOffset;\nuniform vec3 furGravity;\nuniform float furTime;\nuniform float furSpacing;\nuniform float furDensity;\n#endif\n#ifdef HEIGHTMAP\nuniform sampler2D heightTexture;\n#endif\n#ifdef HIGHLEVEL\nvarying vec2 vFurUV;\n#endif\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\nvarying float vfur_length;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nfloat Rand(vec3 rv) {\nfloat x=dot(rv,vec3(12.9898,78.233,24.65487));\nreturn fract(sin(x)*43758.5453);\n}\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\n\nfloat r=Rand(position);\n#ifdef HEIGHTMAP\n#if __VERSION__>100\nvfur_length=furLength*texture(heightTexture,uv).x;\n#else\nvfur_length=furLength*texture2D(heightTexture,uv).r;\n#endif\n#else \nvfur_length=(furLength*r);\n#endif\nvec3 tangent1=vec3(normal.y,-normal.x,0);\nvec3 tangent2=vec3(-normal.z,0,normal.x);\nr=Rand(tangent1*r);\nfloat J=(2.0+4.0*r);\nr=Rand(tangent2*r);\nfloat K=(2.0+2.0*r);\ntangent1=tangent1*J+tangent2*K;\ntangent1=normalize(tangent1);\nvec3 newPosition=position+normal*vfur_length*cos(furAngle)+tangent1*vfur_length*sin(furAngle);\n#ifdef HIGHLEVEL\n\nvec3 forceDirection=vec3(0.0,0.0,0.0);\nforceDirection.x=sin(furTime+position.x*0.05)*0.2;\nforceDirection.y=cos(furTime*0.7+position.y*0.04)*0.2;\nforceDirection.z=sin(furTime*0.7+position.z*0.04)*0.2;\nvec3 displacement=vec3(0.0,0.0,0.0);\ndisplacement=furGravity+forceDirection;\nfloat displacementFactor=pow(furOffset,3.0);\nvec3 aNormal=normal;\naNormal.xyz+=displacement*displacementFactor;\nnewPosition=vec3(newPosition.x,newPosition.y,newPosition.z)+(normalize(aNormal)*furOffset*furSpacing);\n#endif\n#ifdef NORMAL\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";
  2839. BABYLON.Effect.ShadersStore['furPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nuniform vec4 furColor;\nuniform float furLength;\nvarying vec3 vPositionW;\nvarying float vfur_length;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n\n#ifdef HIGHLEVEL\nuniform float furOffset;\nuniform 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}";
  2840. var BABYLON;
  2841. (function (BABYLON) {
  2842. var TerrainMaterialDefines = /** @class */ (function (_super) {
  2843. __extends(TerrainMaterialDefines, _super);
  2844. function TerrainMaterialDefines() {
  2845. var _this = _super.call(this) || this;
  2846. _this.DIFFUSE = false;
  2847. _this.BUMP = false;
  2848. _this.CLIPPLANE = false;
  2849. _this.CLIPPLANE2 = false;
  2850. _this.CLIPPLANE3 = false;
  2851. _this.CLIPPLANE4 = false;
  2852. _this.ALPHATEST = false;
  2853. _this.DEPTHPREPASS = false;
  2854. _this.POINTSIZE = false;
  2855. _this.FOG = false;
  2856. _this.SPECULARTERM = false;
  2857. _this.NORMAL = false;
  2858. _this.UV1 = false;
  2859. _this.UV2 = false;
  2860. _this.VERTEXCOLOR = false;
  2861. _this.VERTEXALPHA = false;
  2862. _this.NUM_BONE_INFLUENCERS = 0;
  2863. _this.BonesPerMesh = 0;
  2864. _this.INSTANCES = false;
  2865. _this.rebuild();
  2866. return _this;
  2867. }
  2868. return TerrainMaterialDefines;
  2869. }(BABYLON.MaterialDefines));
  2870. var TerrainMaterial = /** @class */ (function (_super) {
  2871. __extends(TerrainMaterial, _super);
  2872. function TerrainMaterial(name, scene) {
  2873. var _this = _super.call(this, name, scene) || this;
  2874. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  2875. _this.specularColor = new BABYLON.Color3(0, 0, 0);
  2876. _this.specularPower = 64;
  2877. _this._disableLighting = false;
  2878. _this._maxSimultaneousLights = 4;
  2879. return _this;
  2880. }
  2881. TerrainMaterial.prototype.needAlphaBlending = function () {
  2882. return (this.alpha < 1.0);
  2883. };
  2884. TerrainMaterial.prototype.needAlphaTesting = function () {
  2885. return false;
  2886. };
  2887. TerrainMaterial.prototype.getAlphaTestTexture = function () {
  2888. return null;
  2889. };
  2890. // Methods
  2891. TerrainMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  2892. if (this.isFrozen) {
  2893. if (this._wasPreviouslyReady && subMesh.effect) {
  2894. return true;
  2895. }
  2896. }
  2897. if (!subMesh._materialDefines) {
  2898. subMesh._materialDefines = new TerrainMaterialDefines();
  2899. }
  2900. var defines = subMesh._materialDefines;
  2901. var scene = this.getScene();
  2902. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  2903. if (this._renderId === scene.getRenderId()) {
  2904. return true;
  2905. }
  2906. }
  2907. var engine = scene.getEngine();
  2908. // Textures
  2909. if (scene.texturesEnabled) {
  2910. if (this.mixTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2911. if (!this.mixTexture.isReady()) {
  2912. return false;
  2913. }
  2914. else {
  2915. defines._needUVs = true;
  2916. defines.DIFFUSE = true;
  2917. }
  2918. }
  2919. if ((this.bumpTexture1 || this.bumpTexture2 || this.bumpTexture3) && BABYLON.StandardMaterial.BumpTextureEnabled) {
  2920. defines._needUVs = true;
  2921. defines._needNormals = true;
  2922. defines.BUMP = true;
  2923. }
  2924. }
  2925. // Misc.
  2926. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  2927. // Lights
  2928. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  2929. // Values that need to be evaluated on every frame
  2930. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  2931. // Attribs
  2932. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  2933. // Get correct effect
  2934. if (defines.isDirty) {
  2935. defines.markAsProcessed();
  2936. scene.resetCachedMaterial();
  2937. // Fallbacks
  2938. var fallbacks = new BABYLON.EffectFallbacks();
  2939. if (defines.FOG) {
  2940. fallbacks.addFallback(1, "FOG");
  2941. }
  2942. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  2943. if (defines.NUM_BONE_INFLUENCERS > 0) {
  2944. fallbacks.addCPUSkinningFallback(0, mesh);
  2945. }
  2946. //Attributes
  2947. var attribs = [BABYLON.VertexBuffer.PositionKind];
  2948. if (defines.NORMAL) {
  2949. attribs.push(BABYLON.VertexBuffer.NormalKind);
  2950. }
  2951. if (defines.UV1) {
  2952. attribs.push(BABYLON.VertexBuffer.UVKind);
  2953. }
  2954. if (defines.UV2) {
  2955. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  2956. }
  2957. if (defines.VERTEXCOLOR) {
  2958. attribs.push(BABYLON.VertexBuffer.ColorKind);
  2959. }
  2960. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  2961. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  2962. // Legacy browser patch
  2963. var shaderName = "terrain";
  2964. var join = defines.toString();
  2965. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  2966. "vFogInfos", "vFogColor", "pointSize",
  2967. "vTextureInfos",
  2968. "mBones",
  2969. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "textureMatrix",
  2970. "diffuse1Infos", "diffuse2Infos", "diffuse3Infos"
  2971. ];
  2972. var samplers = ["textureSampler", "diffuse1Sampler", "diffuse2Sampler", "diffuse3Sampler",
  2973. "bump1Sampler", "bump2Sampler", "bump3Sampler"
  2974. ];
  2975. var uniformBuffers = new Array();
  2976. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  2977. uniformsNames: uniforms,
  2978. uniformBuffersNames: uniformBuffers,
  2979. samplers: samplers,
  2980. defines: defines,
  2981. maxSimultaneousLights: this.maxSimultaneousLights
  2982. });
  2983. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  2984. attributes: attribs,
  2985. uniformsNames: uniforms,
  2986. uniformBuffersNames: uniformBuffers,
  2987. samplers: samplers,
  2988. defines: join,
  2989. fallbacks: fallbacks,
  2990. onCompiled: this.onCompiled,
  2991. onError: this.onError,
  2992. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  2993. }, engine), defines);
  2994. }
  2995. if (!subMesh.effect || !subMesh.effect.isReady()) {
  2996. return false;
  2997. }
  2998. this._renderId = scene.getRenderId();
  2999. this._wasPreviouslyReady = true;
  3000. return true;
  3001. };
  3002. TerrainMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  3003. var scene = this.getScene();
  3004. var defines = subMesh._materialDefines;
  3005. if (!defines) {
  3006. return;
  3007. }
  3008. var effect = subMesh.effect;
  3009. if (!effect) {
  3010. return;
  3011. }
  3012. this._activeEffect = effect;
  3013. // Matrices
  3014. this.bindOnlyWorldMatrix(world);
  3015. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  3016. // Bones
  3017. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  3018. if (this._mustRebind(scene, effect)) {
  3019. // Textures
  3020. if (this.mixTexture) {
  3021. this._activeEffect.setTexture("textureSampler", this._mixTexture);
  3022. this._activeEffect.setFloat2("vTextureInfos", this._mixTexture.coordinatesIndex, this._mixTexture.level);
  3023. this._activeEffect.setMatrix("textureMatrix", this._mixTexture.getTextureMatrix());
  3024. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  3025. if (this._diffuseTexture1) {
  3026. this._activeEffect.setTexture("diffuse1Sampler", this._diffuseTexture1);
  3027. this._activeEffect.setFloat2("diffuse1Infos", this._diffuseTexture1.uScale, this._diffuseTexture1.vScale);
  3028. }
  3029. if (this._diffuseTexture2) {
  3030. this._activeEffect.setTexture("diffuse2Sampler", this._diffuseTexture2);
  3031. this._activeEffect.setFloat2("diffuse2Infos", this._diffuseTexture2.uScale, this._diffuseTexture2.vScale);
  3032. }
  3033. if (this._diffuseTexture3) {
  3034. this._activeEffect.setTexture("diffuse3Sampler", this._diffuseTexture3);
  3035. this._activeEffect.setFloat2("diffuse3Infos", this._diffuseTexture3.uScale, this._diffuseTexture3.vScale);
  3036. }
  3037. }
  3038. if (BABYLON.StandardMaterial.BumpTextureEnabled && scene.getEngine().getCaps().standardDerivatives) {
  3039. if (this._bumpTexture1) {
  3040. this._activeEffect.setTexture("bump1Sampler", this._bumpTexture1);
  3041. }
  3042. if (this._bumpTexture2) {
  3043. this._activeEffect.setTexture("bump2Sampler", this._bumpTexture2);
  3044. }
  3045. if (this._bumpTexture3) {
  3046. this._activeEffect.setTexture("bump3Sampler", this._bumpTexture3);
  3047. }
  3048. }
  3049. }
  3050. // Clip plane
  3051. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  3052. // Point size
  3053. if (this.pointsCloud) {
  3054. this._activeEffect.setFloat("pointSize", this.pointSize);
  3055. }
  3056. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  3057. }
  3058. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  3059. if (defines.SPECULARTERM) {
  3060. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  3061. }
  3062. if (scene.lightsEnabled && !this.disableLighting) {
  3063. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  3064. }
  3065. // View
  3066. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  3067. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  3068. }
  3069. // Fog
  3070. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  3071. this._afterBind(mesh, this._activeEffect);
  3072. };
  3073. TerrainMaterial.prototype.getAnimatables = function () {
  3074. var results = [];
  3075. if (this.mixTexture && this.mixTexture.animations && this.mixTexture.animations.length > 0) {
  3076. results.push(this.mixTexture);
  3077. }
  3078. return results;
  3079. };
  3080. TerrainMaterial.prototype.getActiveTextures = function () {
  3081. var activeTextures = _super.prototype.getActiveTextures.call(this);
  3082. if (this._mixTexture) {
  3083. activeTextures.push(this._mixTexture);
  3084. }
  3085. if (this._diffuseTexture1) {
  3086. activeTextures.push(this._diffuseTexture1);
  3087. }
  3088. if (this._diffuseTexture2) {
  3089. activeTextures.push(this._diffuseTexture2);
  3090. }
  3091. if (this._diffuseTexture3) {
  3092. activeTextures.push(this._diffuseTexture3);
  3093. }
  3094. if (this._bumpTexture1) {
  3095. activeTextures.push(this._bumpTexture1);
  3096. }
  3097. if (this._bumpTexture2) {
  3098. activeTextures.push(this._bumpTexture2);
  3099. }
  3100. if (this._bumpTexture3) {
  3101. activeTextures.push(this._bumpTexture3);
  3102. }
  3103. return activeTextures;
  3104. };
  3105. TerrainMaterial.prototype.hasTexture = function (texture) {
  3106. if (_super.prototype.hasTexture.call(this, texture)) {
  3107. return true;
  3108. }
  3109. if (this._mixTexture === texture) {
  3110. return true;
  3111. }
  3112. if (this._diffuseTexture1 === texture) {
  3113. return true;
  3114. }
  3115. if (this._diffuseTexture2 === texture) {
  3116. return true;
  3117. }
  3118. if (this._diffuseTexture3 === texture) {
  3119. return true;
  3120. }
  3121. if (this._bumpTexture1 === texture) {
  3122. return true;
  3123. }
  3124. if (this._bumpTexture2 === texture) {
  3125. return true;
  3126. }
  3127. if (this._bumpTexture3 === texture) {
  3128. return true;
  3129. }
  3130. return false;
  3131. };
  3132. TerrainMaterial.prototype.dispose = function (forceDisposeEffect) {
  3133. if (this.mixTexture) {
  3134. this.mixTexture.dispose();
  3135. }
  3136. _super.prototype.dispose.call(this, forceDisposeEffect);
  3137. };
  3138. TerrainMaterial.prototype.clone = function (name) {
  3139. var _this = this;
  3140. return BABYLON.SerializationHelper.Clone(function () { return new TerrainMaterial(name, _this.getScene()); }, this);
  3141. };
  3142. TerrainMaterial.prototype.serialize = function () {
  3143. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  3144. serializationObject.customType = "BABYLON.TerrainMaterial";
  3145. return serializationObject;
  3146. };
  3147. TerrainMaterial.prototype.getClassName = function () {
  3148. return "TerrainMaterial";
  3149. };
  3150. // Statics
  3151. TerrainMaterial.Parse = function (source, scene, rootUrl) {
  3152. return BABYLON.SerializationHelper.Parse(function () { return new TerrainMaterial(source.name, scene); }, source, scene, rootUrl);
  3153. };
  3154. __decorate([
  3155. BABYLON.serializeAsTexture("mixTexture")
  3156. ], TerrainMaterial.prototype, "_mixTexture", void 0);
  3157. __decorate([
  3158. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3159. ], TerrainMaterial.prototype, "mixTexture", void 0);
  3160. __decorate([
  3161. BABYLON.serializeAsTexture("diffuseTexture1")
  3162. ], TerrainMaterial.prototype, "_diffuseTexture1", void 0);
  3163. __decorate([
  3164. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3165. ], TerrainMaterial.prototype, "diffuseTexture1", void 0);
  3166. __decorate([
  3167. BABYLON.serializeAsTexture("diffuseTexture2")
  3168. ], TerrainMaterial.prototype, "_diffuseTexture2", void 0);
  3169. __decorate([
  3170. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3171. ], TerrainMaterial.prototype, "diffuseTexture2", void 0);
  3172. __decorate([
  3173. BABYLON.serializeAsTexture("diffuseTexture3")
  3174. ], TerrainMaterial.prototype, "_diffuseTexture3", void 0);
  3175. __decorate([
  3176. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3177. ], TerrainMaterial.prototype, "diffuseTexture3", void 0);
  3178. __decorate([
  3179. BABYLON.serializeAsTexture("bumpTexture1")
  3180. ], TerrainMaterial.prototype, "_bumpTexture1", void 0);
  3181. __decorate([
  3182. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3183. ], TerrainMaterial.prototype, "bumpTexture1", void 0);
  3184. __decorate([
  3185. BABYLON.serializeAsTexture("bumpTexture2")
  3186. ], TerrainMaterial.prototype, "_bumpTexture2", void 0);
  3187. __decorate([
  3188. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3189. ], TerrainMaterial.prototype, "bumpTexture2", void 0);
  3190. __decorate([
  3191. BABYLON.serializeAsTexture("bumpTexture3")
  3192. ], TerrainMaterial.prototype, "_bumpTexture3", void 0);
  3193. __decorate([
  3194. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3195. ], TerrainMaterial.prototype, "bumpTexture3", void 0);
  3196. __decorate([
  3197. BABYLON.serializeAsColor3()
  3198. ], TerrainMaterial.prototype, "diffuseColor", void 0);
  3199. __decorate([
  3200. BABYLON.serializeAsColor3()
  3201. ], TerrainMaterial.prototype, "specularColor", void 0);
  3202. __decorate([
  3203. BABYLON.serialize()
  3204. ], TerrainMaterial.prototype, "specularPower", void 0);
  3205. __decorate([
  3206. BABYLON.serialize("disableLighting")
  3207. ], TerrainMaterial.prototype, "_disableLighting", void 0);
  3208. __decorate([
  3209. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3210. ], TerrainMaterial.prototype, "disableLighting", void 0);
  3211. __decorate([
  3212. BABYLON.serialize("maxSimultaneousLights")
  3213. ], TerrainMaterial.prototype, "_maxSimultaneousLights", void 0);
  3214. __decorate([
  3215. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3216. ], TerrainMaterial.prototype, "maxSimultaneousLights", void 0);
  3217. return TerrainMaterial;
  3218. }(BABYLON.PushMaterial));
  3219. BABYLON.TerrainMaterial = TerrainMaterial;
  3220. })(BABYLON || (BABYLON = {}));
  3221. //# sourceMappingURL=babylon.terrainMaterial.js.map
  3222. BABYLON.Effect.ShadersStore['terrainVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vTextureUV;\nuniform mat4 textureMatrix;\nuniform vec2 vTextureInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vTextureInfos.x == 0.)\n{\nvTextureUV=vec2(textureMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvTextureUV=vec2(textureMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#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";
  3223. BABYLON.Effect.ShadersStore['terrainPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef DIFFUSE\nvarying vec2 vTextureUV;\nuniform sampler2D textureSampler;\nuniform vec2 vTextureInfos;\nuniform sampler2D diffuse1Sampler;\nuniform sampler2D diffuse2Sampler;\nuniform sampler2D diffuse3Sampler;\nuniform vec2 diffuse1Infos;\nuniform vec2 diffuse2Infos;\nuniform vec2 diffuse3Infos;\n#endif\n#ifdef BUMP\nuniform sampler2D bump1Sampler;\nuniform sampler2D bump2Sampler;\nuniform sampler2D bump3Sampler;\n#endif\n\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\n\n#ifdef BUMP\n#extension GL_OES_standard_derivatives : enable\n\nmat3 cotangent_frame(vec3 normal,vec3 p,vec2 uv)\n{\n\nvec3 dp1=dFdx(p);\nvec3 dp2=dFdy(p);\nvec2 duv1=dFdx(uv);\nvec2 duv2=dFdy(uv);\n\nvec3 dp2perp=cross(dp2,normal);\nvec3 dp1perp=cross(normal,dp1);\nvec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;\nvec3 binormal=dp2perp*duv1.y+dp1perp*duv2.y;\n\nfloat invmax=inversesqrt(max(dot(tangent,tangent),dot(binormal,binormal)));\nreturn mat3(tangent*invmax,binormal*invmax,normal);\n}\nvec3 perturbNormal(vec3 viewDir,vec3 mixColor)\n{ \nvec3 bump1Color=texture2D(bump1Sampler,vTextureUV*diffuse1Infos).xyz;\nvec3 bump2Color=texture2D(bump2Sampler,vTextureUV*diffuse2Infos).xyz;\nvec3 bump3Color=texture2D(bump3Sampler,vTextureUV*diffuse3Infos).xyz;\nbump1Color.rgb*=mixColor.r;\nbump2Color.rgb=mix(bump1Color.rgb,bump2Color.rgb,mixColor.g);\nvec3 map=mix(bump2Color.rgb,bump3Color.rgb,mixColor.b);\nmap=map*255./127.-128./127.;\nmat3 TBN=cotangent_frame(vNormalW*vTextureInfos.y,-viewDir,vTextureUV);\nreturn normalize(TBN*map);\n}\n#endif\nvoid main(void) {\n\n#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";
  3224. var BABYLON;
  3225. (function (BABYLON) {
  3226. var MixMaterialDefines = /** @class */ (function (_super) {
  3227. __extends(MixMaterialDefines, _super);
  3228. function MixMaterialDefines() {
  3229. var _this = _super.call(this) || this;
  3230. _this.DIFFUSE = false;
  3231. _this.CLIPPLANE = false;
  3232. _this.CLIPPLANE2 = false;
  3233. _this.CLIPPLANE3 = false;
  3234. _this.CLIPPLANE4 = false;
  3235. _this.ALPHATEST = false;
  3236. _this.DEPTHPREPASS = false;
  3237. _this.POINTSIZE = false;
  3238. _this.FOG = false;
  3239. _this.SPECULARTERM = false;
  3240. _this.NORMAL = false;
  3241. _this.UV1 = false;
  3242. _this.UV2 = false;
  3243. _this.VERTEXCOLOR = false;
  3244. _this.VERTEXALPHA = false;
  3245. _this.NUM_BONE_INFLUENCERS = 0;
  3246. _this.BonesPerMesh = 0;
  3247. _this.INSTANCES = false;
  3248. _this.MIXMAP2 = false;
  3249. _this.rebuild();
  3250. return _this;
  3251. }
  3252. return MixMaterialDefines;
  3253. }(BABYLON.MaterialDefines));
  3254. var MixMaterial = /** @class */ (function (_super) {
  3255. __extends(MixMaterial, _super);
  3256. function MixMaterial(name, scene) {
  3257. var _this = _super.call(this, name, scene) || this;
  3258. /**
  3259. * Uniforms
  3260. */
  3261. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  3262. _this.specularColor = new BABYLON.Color3(0, 0, 0);
  3263. _this.specularPower = 64;
  3264. _this._disableLighting = false;
  3265. _this._maxSimultaneousLights = 4;
  3266. return _this;
  3267. }
  3268. MixMaterial.prototype.needAlphaBlending = function () {
  3269. return (this.alpha < 1.0);
  3270. };
  3271. MixMaterial.prototype.needAlphaTesting = function () {
  3272. return false;
  3273. };
  3274. MixMaterial.prototype.getAlphaTestTexture = function () {
  3275. return null;
  3276. };
  3277. // Methods
  3278. MixMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  3279. if (this.isFrozen) {
  3280. if (this._wasPreviouslyReady && subMesh.effect) {
  3281. return true;
  3282. }
  3283. }
  3284. if (!subMesh._materialDefines) {
  3285. subMesh._materialDefines = new MixMaterialDefines();
  3286. }
  3287. var defines = subMesh._materialDefines;
  3288. var scene = this.getScene();
  3289. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  3290. if (this._renderId === scene.getRenderId()) {
  3291. return true;
  3292. }
  3293. }
  3294. var engine = scene.getEngine();
  3295. // Textures
  3296. if (scene.texturesEnabled) {
  3297. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  3298. if (this._mixTexture1) {
  3299. if (!this._mixTexture1.isReady()) {
  3300. return false;
  3301. }
  3302. else {
  3303. defines._needUVs = true;
  3304. defines.DIFFUSE = true;
  3305. }
  3306. }
  3307. if (this._mixTexture2) {
  3308. if (!this._mixTexture2.isReady()) {
  3309. return false;
  3310. }
  3311. else {
  3312. defines.MIXMAP2 = true;
  3313. }
  3314. }
  3315. }
  3316. }
  3317. // Misc.
  3318. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  3319. // Lights
  3320. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  3321. // Values that need to be evaluated on every frame
  3322. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  3323. // Attribs
  3324. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  3325. // Get correct effect
  3326. if (defines.isDirty) {
  3327. defines.markAsProcessed();
  3328. scene.resetCachedMaterial();
  3329. // Fallbacks
  3330. var fallbacks = new BABYLON.EffectFallbacks();
  3331. if (defines.FOG) {
  3332. fallbacks.addFallback(1, "FOG");
  3333. }
  3334. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  3335. if (defines.NUM_BONE_INFLUENCERS > 0) {
  3336. fallbacks.addCPUSkinningFallback(0, mesh);
  3337. }
  3338. //Attributes
  3339. var attribs = [BABYLON.VertexBuffer.PositionKind];
  3340. if (defines.NORMAL) {
  3341. attribs.push(BABYLON.VertexBuffer.NormalKind);
  3342. }
  3343. if (defines.UV1) {
  3344. attribs.push(BABYLON.VertexBuffer.UVKind);
  3345. }
  3346. if (defines.UV2) {
  3347. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  3348. }
  3349. if (defines.VERTEXCOLOR) {
  3350. attribs.push(BABYLON.VertexBuffer.ColorKind);
  3351. }
  3352. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  3353. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  3354. // Legacy browser patch
  3355. var shaderName = "mix";
  3356. var join = defines.toString();
  3357. var uniforms = [
  3358. "world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  3359. "vFogInfos", "vFogColor", "pointSize",
  3360. "vTextureInfos",
  3361. "mBones",
  3362. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "textureMatrix",
  3363. "diffuse1Infos", "diffuse2Infos", "diffuse3Infos", "diffuse4Infos",
  3364. "diffuse5Infos", "diffuse6Infos", "diffuse7Infos", "diffuse8Infos"
  3365. ];
  3366. var samplers = [
  3367. "mixMap1Sampler", "mixMap2Sampler",
  3368. "diffuse1Sampler", "diffuse2Sampler", "diffuse3Sampler", "diffuse4Sampler",
  3369. "diffuse5Sampler", "diffuse6Sampler", "diffuse7Sampler", "diffuse8Sampler"
  3370. ];
  3371. var uniformBuffers = new Array();
  3372. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  3373. uniformsNames: uniforms,
  3374. uniformBuffersNames: uniformBuffers,
  3375. samplers: samplers,
  3376. defines: defines,
  3377. maxSimultaneousLights: this.maxSimultaneousLights
  3378. });
  3379. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  3380. attributes: attribs,
  3381. uniformsNames: uniforms,
  3382. uniformBuffersNames: uniformBuffers,
  3383. samplers: samplers,
  3384. defines: join,
  3385. fallbacks: fallbacks,
  3386. onCompiled: this.onCompiled,
  3387. onError: this.onError,
  3388. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  3389. }, engine), defines);
  3390. }
  3391. if (!subMesh.effect || !subMesh.effect.isReady()) {
  3392. return false;
  3393. }
  3394. this._renderId = scene.getRenderId();
  3395. this._wasPreviouslyReady = true;
  3396. return true;
  3397. };
  3398. MixMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  3399. var scene = this.getScene();
  3400. var defines = subMesh._materialDefines;
  3401. if (!defines) {
  3402. return;
  3403. }
  3404. var effect = subMesh.effect;
  3405. if (!effect) {
  3406. return;
  3407. }
  3408. this._activeEffect = effect;
  3409. // Matrices
  3410. this.bindOnlyWorldMatrix(world);
  3411. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  3412. // Bones
  3413. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  3414. if (this._mustRebind(scene, effect)) {
  3415. // Textures
  3416. if (this._mixTexture1) {
  3417. this._activeEffect.setTexture("mixMap1Sampler", this._mixTexture1);
  3418. this._activeEffect.setFloat2("vTextureInfos", this._mixTexture1.coordinatesIndex, this._mixTexture1.level);
  3419. this._activeEffect.setMatrix("textureMatrix", this._mixTexture1.getTextureMatrix());
  3420. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  3421. if (this._diffuseTexture1) {
  3422. this._activeEffect.setTexture("diffuse1Sampler", this._diffuseTexture1);
  3423. this._activeEffect.setFloat2("diffuse1Infos", this._diffuseTexture1.uScale, this._diffuseTexture1.vScale);
  3424. }
  3425. if (this._diffuseTexture2) {
  3426. this._activeEffect.setTexture("diffuse2Sampler", this._diffuseTexture2);
  3427. this._activeEffect.setFloat2("diffuse2Infos", this._diffuseTexture2.uScale, this._diffuseTexture2.vScale);
  3428. }
  3429. if (this._diffuseTexture3) {
  3430. this._activeEffect.setTexture("diffuse3Sampler", this._diffuseTexture3);
  3431. this._activeEffect.setFloat2("diffuse3Infos", this._diffuseTexture3.uScale, this._diffuseTexture3.vScale);
  3432. }
  3433. if (this._diffuseTexture4) {
  3434. this._activeEffect.setTexture("diffuse4Sampler", this._diffuseTexture4);
  3435. this._activeEffect.setFloat2("diffuse4Infos", this._diffuseTexture4.uScale, this._diffuseTexture4.vScale);
  3436. }
  3437. }
  3438. }
  3439. if (this._mixTexture2) {
  3440. this._activeEffect.setTexture("mixMap2Sampler", this._mixTexture2);
  3441. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  3442. if (this._diffuseTexture5) {
  3443. this._activeEffect.setTexture("diffuse5Sampler", this._diffuseTexture5);
  3444. this._activeEffect.setFloat2("diffuse5Infos", this._diffuseTexture5.uScale, this._diffuseTexture5.vScale);
  3445. }
  3446. if (this._diffuseTexture6) {
  3447. this._activeEffect.setTexture("diffuse6Sampler", this._diffuseTexture6);
  3448. this._activeEffect.setFloat2("diffuse6Infos", this._diffuseTexture6.uScale, this._diffuseTexture6.vScale);
  3449. }
  3450. if (this._diffuseTexture7) {
  3451. this._activeEffect.setTexture("diffuse7Sampler", this._diffuseTexture7);
  3452. this._activeEffect.setFloat2("diffuse7Infos", this._diffuseTexture7.uScale, this._diffuseTexture7.vScale);
  3453. }
  3454. if (this._diffuseTexture8) {
  3455. this._activeEffect.setTexture("diffuse8Sampler", this._diffuseTexture8);
  3456. this._activeEffect.setFloat2("diffuse8Infos", this._diffuseTexture8.uScale, this._diffuseTexture8.vScale);
  3457. }
  3458. }
  3459. }
  3460. // Clip plane
  3461. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  3462. // Point size
  3463. if (this.pointsCloud) {
  3464. this._activeEffect.setFloat("pointSize", this.pointSize);
  3465. }
  3466. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  3467. }
  3468. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  3469. if (defines.SPECULARTERM) {
  3470. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  3471. }
  3472. if (scene.lightsEnabled && !this.disableLighting) {
  3473. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  3474. }
  3475. // View
  3476. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  3477. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  3478. }
  3479. // Fog
  3480. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  3481. this._afterBind(mesh, this._activeEffect);
  3482. };
  3483. MixMaterial.prototype.getAnimatables = function () {
  3484. var results = [];
  3485. if (this._mixTexture1 && this._mixTexture1.animations && this._mixTexture1.animations.length > 0) {
  3486. results.push(this._mixTexture1);
  3487. }
  3488. if (this._mixTexture2 && this._mixTexture2.animations && this._mixTexture2.animations.length > 0) {
  3489. results.push(this._mixTexture2);
  3490. }
  3491. return results;
  3492. };
  3493. MixMaterial.prototype.getActiveTextures = function () {
  3494. var activeTextures = _super.prototype.getActiveTextures.call(this);
  3495. // Mix map 1
  3496. if (this._mixTexture1) {
  3497. activeTextures.push(this._mixTexture1);
  3498. }
  3499. if (this._diffuseTexture1) {
  3500. activeTextures.push(this._diffuseTexture1);
  3501. }
  3502. if (this._diffuseTexture2) {
  3503. activeTextures.push(this._diffuseTexture2);
  3504. }
  3505. if (this._diffuseTexture3) {
  3506. activeTextures.push(this._diffuseTexture3);
  3507. }
  3508. if (this._diffuseTexture4) {
  3509. activeTextures.push(this._diffuseTexture4);
  3510. }
  3511. // Mix map 2
  3512. if (this._mixTexture2) {
  3513. activeTextures.push(this._mixTexture2);
  3514. }
  3515. if (this._diffuseTexture5) {
  3516. activeTextures.push(this._diffuseTexture5);
  3517. }
  3518. if (this._diffuseTexture6) {
  3519. activeTextures.push(this._diffuseTexture6);
  3520. }
  3521. if (this._diffuseTexture7) {
  3522. activeTextures.push(this._diffuseTexture7);
  3523. }
  3524. if (this._diffuseTexture8) {
  3525. activeTextures.push(this._diffuseTexture8);
  3526. }
  3527. return activeTextures;
  3528. };
  3529. MixMaterial.prototype.hasTexture = function (texture) {
  3530. if (_super.prototype.hasTexture.call(this, texture)) {
  3531. return true;
  3532. }
  3533. // Mix map 1
  3534. if (this._mixTexture1 === texture) {
  3535. return true;
  3536. }
  3537. if (this._diffuseTexture1 === texture) {
  3538. return true;
  3539. }
  3540. if (this._diffuseTexture2 === texture) {
  3541. return true;
  3542. }
  3543. if (this._diffuseTexture3 === texture) {
  3544. return true;
  3545. }
  3546. if (this._diffuseTexture4 === texture) {
  3547. return true;
  3548. }
  3549. // Mix map 2
  3550. if (this._mixTexture2 === texture) {
  3551. return true;
  3552. }
  3553. if (this._diffuseTexture5 === texture) {
  3554. return true;
  3555. }
  3556. if (this._diffuseTexture6 === texture) {
  3557. return true;
  3558. }
  3559. if (this._diffuseTexture7 === texture) {
  3560. return true;
  3561. }
  3562. if (this._diffuseTexture8 === texture) {
  3563. return true;
  3564. }
  3565. return false;
  3566. };
  3567. MixMaterial.prototype.dispose = function (forceDisposeEffect) {
  3568. if (this._mixTexture1) {
  3569. this._mixTexture1.dispose();
  3570. }
  3571. _super.prototype.dispose.call(this, forceDisposeEffect);
  3572. };
  3573. MixMaterial.prototype.clone = function (name) {
  3574. var _this = this;
  3575. return BABYLON.SerializationHelper.Clone(function () { return new MixMaterial(name, _this.getScene()); }, this);
  3576. };
  3577. MixMaterial.prototype.serialize = function () {
  3578. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  3579. serializationObject.customType = "BABYLON.MixMaterial";
  3580. return serializationObject;
  3581. };
  3582. MixMaterial.prototype.getClassName = function () {
  3583. return "MixMaterial";
  3584. };
  3585. // Statics
  3586. MixMaterial.Parse = function (source, scene, rootUrl) {
  3587. return BABYLON.SerializationHelper.Parse(function () { return new MixMaterial(source.name, scene); }, source, scene, rootUrl);
  3588. };
  3589. __decorate([
  3590. BABYLON.serializeAsTexture("mixTexture1")
  3591. ], MixMaterial.prototype, "_mixTexture1", void 0);
  3592. __decorate([
  3593. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3594. ], MixMaterial.prototype, "mixTexture1", void 0);
  3595. __decorate([
  3596. BABYLON.serializeAsTexture("mixTexture2")
  3597. ], MixMaterial.prototype, "_mixTexture2", void 0);
  3598. __decorate([
  3599. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3600. ], MixMaterial.prototype, "mixTexture2", void 0);
  3601. __decorate([
  3602. BABYLON.serializeAsTexture("diffuseTexture1")
  3603. ], MixMaterial.prototype, "_diffuseTexture1", void 0);
  3604. __decorate([
  3605. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3606. ], MixMaterial.prototype, "diffuseTexture1", void 0);
  3607. __decorate([
  3608. BABYLON.serializeAsTexture("diffuseTexture2")
  3609. ], MixMaterial.prototype, "_diffuseTexture2", void 0);
  3610. __decorate([
  3611. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3612. ], MixMaterial.prototype, "diffuseTexture2", void 0);
  3613. __decorate([
  3614. BABYLON.serializeAsTexture("diffuseTexture3")
  3615. ], MixMaterial.prototype, "_diffuseTexture3", void 0);
  3616. __decorate([
  3617. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3618. ], MixMaterial.prototype, "diffuseTexture3", void 0);
  3619. __decorate([
  3620. BABYLON.serializeAsTexture("diffuseTexture4")
  3621. ], MixMaterial.prototype, "_diffuseTexture4", void 0);
  3622. __decorate([
  3623. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3624. ], MixMaterial.prototype, "diffuseTexture4", void 0);
  3625. __decorate([
  3626. BABYLON.serializeAsTexture("diffuseTexture1")
  3627. ], MixMaterial.prototype, "_diffuseTexture5", void 0);
  3628. __decorate([
  3629. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3630. ], MixMaterial.prototype, "diffuseTexture5", void 0);
  3631. __decorate([
  3632. BABYLON.serializeAsTexture("diffuseTexture2")
  3633. ], MixMaterial.prototype, "_diffuseTexture6", void 0);
  3634. __decorate([
  3635. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3636. ], MixMaterial.prototype, "diffuseTexture6", void 0);
  3637. __decorate([
  3638. BABYLON.serializeAsTexture("diffuseTexture3")
  3639. ], MixMaterial.prototype, "_diffuseTexture7", void 0);
  3640. __decorate([
  3641. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3642. ], MixMaterial.prototype, "diffuseTexture7", void 0);
  3643. __decorate([
  3644. BABYLON.serializeAsTexture("diffuseTexture4")
  3645. ], MixMaterial.prototype, "_diffuseTexture8", void 0);
  3646. __decorate([
  3647. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3648. ], MixMaterial.prototype, "diffuseTexture8", void 0);
  3649. __decorate([
  3650. BABYLON.serializeAsColor3()
  3651. ], MixMaterial.prototype, "diffuseColor", void 0);
  3652. __decorate([
  3653. BABYLON.serializeAsColor3()
  3654. ], MixMaterial.prototype, "specularColor", void 0);
  3655. __decorate([
  3656. BABYLON.serialize()
  3657. ], MixMaterial.prototype, "specularPower", void 0);
  3658. __decorate([
  3659. BABYLON.serialize("disableLighting")
  3660. ], MixMaterial.prototype, "_disableLighting", void 0);
  3661. __decorate([
  3662. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3663. ], MixMaterial.prototype, "disableLighting", void 0);
  3664. __decorate([
  3665. BABYLON.serialize("maxSimultaneousLights")
  3666. ], MixMaterial.prototype, "_maxSimultaneousLights", void 0);
  3667. __decorate([
  3668. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3669. ], MixMaterial.prototype, "maxSimultaneousLights", void 0);
  3670. return MixMaterial;
  3671. }(BABYLON.PushMaterial));
  3672. BABYLON.MixMaterial = MixMaterial;
  3673. })(BABYLON || (BABYLON = {}));
  3674. //# sourceMappingURL=babylon.mixMaterial.js.map
  3675. BABYLON.Effect.ShadersStore['mixVertexShader'] = "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";
  3676. BABYLON.Effect.ShadersStore['mixPixelShader'] = "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";
  3677. var BABYLON;
  3678. (function (BABYLON) {
  3679. var TriPlanarMaterialDefines = /** @class */ (function (_super) {
  3680. __extends(TriPlanarMaterialDefines, _super);
  3681. function TriPlanarMaterialDefines() {
  3682. var _this = _super.call(this) || this;
  3683. _this.DIFFUSEX = false;
  3684. _this.DIFFUSEY = false;
  3685. _this.DIFFUSEZ = false;
  3686. _this.BUMPX = false;
  3687. _this.BUMPY = false;
  3688. _this.BUMPZ = false;
  3689. _this.CLIPPLANE = false;
  3690. _this.CLIPPLANE2 = false;
  3691. _this.CLIPPLANE3 = false;
  3692. _this.CLIPPLANE4 = false;
  3693. _this.ALPHATEST = false;
  3694. _this.DEPTHPREPASS = false;
  3695. _this.POINTSIZE = false;
  3696. _this.FOG = false;
  3697. _this.SPECULARTERM = false;
  3698. _this.NORMAL = false;
  3699. _this.VERTEXCOLOR = false;
  3700. _this.VERTEXALPHA = false;
  3701. _this.NUM_BONE_INFLUENCERS = 0;
  3702. _this.BonesPerMesh = 0;
  3703. _this.INSTANCES = false;
  3704. _this.rebuild();
  3705. return _this;
  3706. }
  3707. return TriPlanarMaterialDefines;
  3708. }(BABYLON.MaterialDefines));
  3709. var TriPlanarMaterial = /** @class */ (function (_super) {
  3710. __extends(TriPlanarMaterial, _super);
  3711. function TriPlanarMaterial(name, scene) {
  3712. var _this = _super.call(this, name, scene) || this;
  3713. _this.tileSize = 1;
  3714. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  3715. _this.specularColor = new BABYLON.Color3(0.2, 0.2, 0.2);
  3716. _this.specularPower = 64;
  3717. _this._disableLighting = false;
  3718. _this._maxSimultaneousLights = 4;
  3719. return _this;
  3720. }
  3721. TriPlanarMaterial.prototype.needAlphaBlending = function () {
  3722. return (this.alpha < 1.0);
  3723. };
  3724. TriPlanarMaterial.prototype.needAlphaTesting = function () {
  3725. return false;
  3726. };
  3727. TriPlanarMaterial.prototype.getAlphaTestTexture = function () {
  3728. return null;
  3729. };
  3730. // Methods
  3731. TriPlanarMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  3732. if (this.isFrozen) {
  3733. if (this._wasPreviouslyReady && subMesh.effect) {
  3734. return true;
  3735. }
  3736. }
  3737. if (!subMesh._materialDefines) {
  3738. subMesh._materialDefines = new TriPlanarMaterialDefines();
  3739. }
  3740. var defines = subMesh._materialDefines;
  3741. var scene = this.getScene();
  3742. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  3743. if (this._renderId === scene.getRenderId()) {
  3744. return true;
  3745. }
  3746. }
  3747. var engine = scene.getEngine();
  3748. // Textures
  3749. if (defines._areTexturesDirty) {
  3750. if (scene.texturesEnabled) {
  3751. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  3752. var textures = [this.diffuseTextureX, this.diffuseTextureY, this.diffuseTextureZ];
  3753. var textureDefines = ["DIFFUSEX", "DIFFUSEY", "DIFFUSEZ"];
  3754. for (var i = 0; i < textures.length; i++) {
  3755. if (textures[i]) {
  3756. if (!textures[i].isReady()) {
  3757. return false;
  3758. }
  3759. else {
  3760. defines[textureDefines[i]] = true;
  3761. }
  3762. }
  3763. }
  3764. }
  3765. if (BABYLON.StandardMaterial.BumpTextureEnabled) {
  3766. var textures = [this.normalTextureX, this.normalTextureY, this.normalTextureZ];
  3767. var textureDefines = ["BUMPX", "BUMPY", "BUMPZ"];
  3768. for (var i = 0; i < textures.length; i++) {
  3769. if (textures[i]) {
  3770. if (!textures[i].isReady()) {
  3771. return false;
  3772. }
  3773. else {
  3774. defines[textureDefines[i]] = true;
  3775. }
  3776. }
  3777. }
  3778. }
  3779. }
  3780. }
  3781. // Misc.
  3782. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  3783. // Lights
  3784. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  3785. // Values that need to be evaluated on every frame
  3786. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  3787. // Attribs
  3788. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  3789. // Get correct effect
  3790. if (defines.isDirty) {
  3791. defines.markAsProcessed();
  3792. scene.resetCachedMaterial();
  3793. // Fallbacks
  3794. var fallbacks = new BABYLON.EffectFallbacks();
  3795. if (defines.FOG) {
  3796. fallbacks.addFallback(1, "FOG");
  3797. }
  3798. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  3799. if (defines.NUM_BONE_INFLUENCERS > 0) {
  3800. fallbacks.addCPUSkinningFallback(0, mesh);
  3801. }
  3802. //Attributes
  3803. var attribs = [BABYLON.VertexBuffer.PositionKind];
  3804. if (defines.NORMAL) {
  3805. attribs.push(BABYLON.VertexBuffer.NormalKind);
  3806. }
  3807. if (defines.VERTEXCOLOR) {
  3808. attribs.push(BABYLON.VertexBuffer.ColorKind);
  3809. }
  3810. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  3811. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  3812. // Legacy browser patch
  3813. var shaderName = "triplanar";
  3814. var join = defines.toString();
  3815. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  3816. "vFogInfos", "vFogColor", "pointSize",
  3817. "mBones",
  3818. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4",
  3819. "tileSize"
  3820. ];
  3821. var samplers = ["diffuseSamplerX", "diffuseSamplerY", "diffuseSamplerZ",
  3822. "normalSamplerX", "normalSamplerY", "normalSamplerZ"
  3823. ];
  3824. var uniformBuffers = new Array();
  3825. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  3826. uniformsNames: uniforms,
  3827. uniformBuffersNames: uniformBuffers,
  3828. samplers: samplers,
  3829. defines: defines,
  3830. maxSimultaneousLights: this.maxSimultaneousLights
  3831. });
  3832. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  3833. attributes: attribs,
  3834. uniformsNames: uniforms,
  3835. uniformBuffersNames: uniformBuffers,
  3836. samplers: samplers,
  3837. defines: join,
  3838. fallbacks: fallbacks,
  3839. onCompiled: this.onCompiled,
  3840. onError: this.onError,
  3841. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  3842. }, engine), defines);
  3843. }
  3844. if (!subMesh.effect || !subMesh.effect.isReady()) {
  3845. return false;
  3846. }
  3847. this._renderId = scene.getRenderId();
  3848. this._wasPreviouslyReady = true;
  3849. return true;
  3850. };
  3851. TriPlanarMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  3852. var scene = this.getScene();
  3853. var defines = subMesh._materialDefines;
  3854. if (!defines) {
  3855. return;
  3856. }
  3857. var effect = subMesh.effect;
  3858. if (!effect) {
  3859. return;
  3860. }
  3861. this._activeEffect = effect;
  3862. // Matrices
  3863. this.bindOnlyWorldMatrix(world);
  3864. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  3865. // Bones
  3866. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  3867. this._activeEffect.setFloat("tileSize", this.tileSize);
  3868. if (scene.getCachedMaterial() !== this) {
  3869. // Textures
  3870. if (this.diffuseTextureX) {
  3871. this._activeEffect.setTexture("diffuseSamplerX", this.diffuseTextureX);
  3872. }
  3873. if (this.diffuseTextureY) {
  3874. this._activeEffect.setTexture("diffuseSamplerY", this.diffuseTextureY);
  3875. }
  3876. if (this.diffuseTextureZ) {
  3877. this._activeEffect.setTexture("diffuseSamplerZ", this.diffuseTextureZ);
  3878. }
  3879. if (this.normalTextureX) {
  3880. this._activeEffect.setTexture("normalSamplerX", this.normalTextureX);
  3881. }
  3882. if (this.normalTextureY) {
  3883. this._activeEffect.setTexture("normalSamplerY", this.normalTextureY);
  3884. }
  3885. if (this.normalTextureZ) {
  3886. this._activeEffect.setTexture("normalSamplerZ", this.normalTextureZ);
  3887. }
  3888. // Clip plane
  3889. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  3890. // Point size
  3891. if (this.pointsCloud) {
  3892. this._activeEffect.setFloat("pointSize", this.pointSize);
  3893. }
  3894. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  3895. }
  3896. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  3897. if (defines.SPECULARTERM) {
  3898. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  3899. }
  3900. if (scene.lightsEnabled && !this.disableLighting) {
  3901. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  3902. }
  3903. // View
  3904. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  3905. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  3906. }
  3907. // Fog
  3908. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  3909. this._afterBind(mesh, this._activeEffect);
  3910. };
  3911. TriPlanarMaterial.prototype.getAnimatables = function () {
  3912. var results = [];
  3913. if (this.mixTexture && this.mixTexture.animations && this.mixTexture.animations.length > 0) {
  3914. results.push(this.mixTexture);
  3915. }
  3916. return results;
  3917. };
  3918. TriPlanarMaterial.prototype.getActiveTextures = function () {
  3919. var activeTextures = _super.prototype.getActiveTextures.call(this);
  3920. if (this._diffuseTextureX) {
  3921. activeTextures.push(this._diffuseTextureX);
  3922. }
  3923. if (this._diffuseTextureY) {
  3924. activeTextures.push(this._diffuseTextureY);
  3925. }
  3926. if (this._diffuseTextureZ) {
  3927. activeTextures.push(this._diffuseTextureZ);
  3928. }
  3929. if (this._normalTextureX) {
  3930. activeTextures.push(this._normalTextureX);
  3931. }
  3932. if (this._normalTextureY) {
  3933. activeTextures.push(this._normalTextureY);
  3934. }
  3935. if (this._normalTextureZ) {
  3936. activeTextures.push(this._normalTextureZ);
  3937. }
  3938. return activeTextures;
  3939. };
  3940. TriPlanarMaterial.prototype.hasTexture = function (texture) {
  3941. if (_super.prototype.hasTexture.call(this, texture)) {
  3942. return true;
  3943. }
  3944. if (this._diffuseTextureX === texture) {
  3945. return true;
  3946. }
  3947. if (this._diffuseTextureY === texture) {
  3948. return true;
  3949. }
  3950. if (this._diffuseTextureZ === texture) {
  3951. return true;
  3952. }
  3953. if (this._normalTextureX === texture) {
  3954. return true;
  3955. }
  3956. if (this._normalTextureY === texture) {
  3957. return true;
  3958. }
  3959. if (this._normalTextureZ === texture) {
  3960. return true;
  3961. }
  3962. return false;
  3963. };
  3964. TriPlanarMaterial.prototype.dispose = function (forceDisposeEffect) {
  3965. if (this.mixTexture) {
  3966. this.mixTexture.dispose();
  3967. }
  3968. _super.prototype.dispose.call(this, forceDisposeEffect);
  3969. };
  3970. TriPlanarMaterial.prototype.clone = function (name) {
  3971. var _this = this;
  3972. return BABYLON.SerializationHelper.Clone(function () { return new TriPlanarMaterial(name, _this.getScene()); }, this);
  3973. };
  3974. TriPlanarMaterial.prototype.serialize = function () {
  3975. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  3976. serializationObject.customType = "BABYLON.TriPlanarMaterial";
  3977. return serializationObject;
  3978. };
  3979. TriPlanarMaterial.prototype.getClassName = function () {
  3980. return "TriPlanarMaterial";
  3981. };
  3982. // Statics
  3983. TriPlanarMaterial.Parse = function (source, scene, rootUrl) {
  3984. return BABYLON.SerializationHelper.Parse(function () { return new TriPlanarMaterial(source.name, scene); }, source, scene, rootUrl);
  3985. };
  3986. __decorate([
  3987. BABYLON.serializeAsTexture()
  3988. ], TriPlanarMaterial.prototype, "mixTexture", void 0);
  3989. __decorate([
  3990. BABYLON.serializeAsTexture("diffuseTextureX")
  3991. ], TriPlanarMaterial.prototype, "_diffuseTextureX", void 0);
  3992. __decorate([
  3993. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3994. ], TriPlanarMaterial.prototype, "diffuseTextureX", void 0);
  3995. __decorate([
  3996. BABYLON.serializeAsTexture("diffuseTexturY")
  3997. ], TriPlanarMaterial.prototype, "_diffuseTextureY", void 0);
  3998. __decorate([
  3999. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4000. ], TriPlanarMaterial.prototype, "diffuseTextureY", void 0);
  4001. __decorate([
  4002. BABYLON.serializeAsTexture("diffuseTextureZ")
  4003. ], TriPlanarMaterial.prototype, "_diffuseTextureZ", void 0);
  4004. __decorate([
  4005. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4006. ], TriPlanarMaterial.prototype, "diffuseTextureZ", void 0);
  4007. __decorate([
  4008. BABYLON.serializeAsTexture("normalTextureX")
  4009. ], TriPlanarMaterial.prototype, "_normalTextureX", void 0);
  4010. __decorate([
  4011. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4012. ], TriPlanarMaterial.prototype, "normalTextureX", void 0);
  4013. __decorate([
  4014. BABYLON.serializeAsTexture("normalTextureY")
  4015. ], TriPlanarMaterial.prototype, "_normalTextureY", void 0);
  4016. __decorate([
  4017. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4018. ], TriPlanarMaterial.prototype, "normalTextureY", void 0);
  4019. __decorate([
  4020. BABYLON.serializeAsTexture("normalTextureZ")
  4021. ], TriPlanarMaterial.prototype, "_normalTextureZ", void 0);
  4022. __decorate([
  4023. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4024. ], TriPlanarMaterial.prototype, "normalTextureZ", void 0);
  4025. __decorate([
  4026. BABYLON.serialize()
  4027. ], TriPlanarMaterial.prototype, "tileSize", void 0);
  4028. __decorate([
  4029. BABYLON.serializeAsColor3()
  4030. ], TriPlanarMaterial.prototype, "diffuseColor", void 0);
  4031. __decorate([
  4032. BABYLON.serializeAsColor3()
  4033. ], TriPlanarMaterial.prototype, "specularColor", void 0);
  4034. __decorate([
  4035. BABYLON.serialize()
  4036. ], TriPlanarMaterial.prototype, "specularPower", void 0);
  4037. __decorate([
  4038. BABYLON.serialize("disableLighting")
  4039. ], TriPlanarMaterial.prototype, "_disableLighting", void 0);
  4040. __decorate([
  4041. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  4042. ], TriPlanarMaterial.prototype, "disableLighting", void 0);
  4043. __decorate([
  4044. BABYLON.serialize("maxSimultaneousLights")
  4045. ], TriPlanarMaterial.prototype, "_maxSimultaneousLights", void 0);
  4046. __decorate([
  4047. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  4048. ], TriPlanarMaterial.prototype, "maxSimultaneousLights", void 0);
  4049. return TriPlanarMaterial;
  4050. }(BABYLON.PushMaterial));
  4051. BABYLON.TriPlanarMaterial = TriPlanarMaterial;
  4052. })(BABYLON || (BABYLON = {}));
  4053. //# sourceMappingURL=babylon.triPlanarMaterial.js.map
  4054. BABYLON.Effect.ShadersStore['triplanarVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSEX\nvarying vec2 vTextureUVX;\n#endif\n#ifdef DIFFUSEY\nvarying vec2 vTextureUVY;\n#endif\n#ifdef DIFFUSEZ\nvarying vec2 vTextureUVZ;\n#endif\nuniform float tileSize;\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying mat3 tangentSpace;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void)\n{\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef DIFFUSEX\nvTextureUVX=worldPos.zy/tileSize;\n#endif\n#ifdef DIFFUSEY\nvTextureUVY=worldPos.xz/tileSize;\n#endif\n#ifdef DIFFUSEZ\nvTextureUVZ=worldPos.xy/tileSize;\n#endif\n#ifdef NORMAL\n\nvec3 xtan=vec3(0,0,1);\nvec3 xbin=vec3(0,1,0);\nvec3 ytan=vec3(1,0,0);\nvec3 ybin=vec3(0,0,1);\nvec3 ztan=vec3(1,0,0);\nvec3 zbin=vec3(0,1,0);\nvec3 normalizedNormal=normalize(normal);\nnormalizedNormal*=normalizedNormal;\nvec3 worldBinormal=normalize(xbin*normalizedNormal.x+ybin*normalizedNormal.y+zbin*normalizedNormal.z);\nvec3 worldTangent=normalize(xtan*normalizedNormal.x+ytan*normalizedNormal.y+ztan*normalizedNormal.z);\nworldTangent=(world*vec4(worldTangent,1.0)).xyz;\nworldBinormal=(world*vec4(worldBinormal,1.0)).xyz;\nvec3 worldNormal=normalize(cross(worldTangent,worldBinormal));\ntangentSpace[0]=worldTangent;\ntangentSpace[1]=worldBinormal;\ntangentSpace[2]=worldNormal;\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  4055. BABYLON.Effect.ShadersStore['triplanarPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef DIFFUSEX\nvarying vec2 vTextureUVX;\nuniform sampler2D diffuseSamplerX;\n#ifdef BUMPX\nuniform sampler2D normalSamplerX;\n#endif\n#endif\n#ifdef DIFFUSEY\nvarying vec2 vTextureUVY;\nuniform sampler2D diffuseSamplerY;\n#ifdef BUMPY\nuniform sampler2D normalSamplerY;\n#endif\n#endif\n#ifdef DIFFUSEZ\nvarying vec2 vTextureUVZ;\nuniform sampler2D diffuseSamplerZ;\n#ifdef BUMPZ\nuniform sampler2D normalSamplerZ;\n#endif\n#endif\n#ifdef NORMAL\nvarying mat3 tangentSpace;\n#endif\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<fogFragmentDeclaration>\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(0.,0.,0.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n\n#ifdef NORMAL\nvec3 normalW=tangentSpace[2];\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\nvec4 baseNormal=vec4(0.0,0.0,0.0,1.0);\nnormalW*=normalW;\n#ifdef DIFFUSEX\nbaseColor+=texture2D(diffuseSamplerX,vTextureUVX)*normalW.x;\n#ifdef BUMPX\nbaseNormal+=texture2D(normalSamplerX,vTextureUVX)*normalW.x;\n#endif\n#endif\n#ifdef DIFFUSEY\nbaseColor+=texture2D(diffuseSamplerY,vTextureUVY)*normalW.y;\n#ifdef BUMPY\nbaseNormal+=texture2D(normalSamplerY,vTextureUVY)*normalW.y;\n#endif\n#endif\n#ifdef DIFFUSEZ\nbaseColor+=texture2D(diffuseSamplerZ,vTextureUVZ)*normalW.z;\n#ifdef BUMPZ\nbaseNormal+=texture2D(normalSamplerZ,vTextureUVZ)*normalW.z;\n#endif\n#endif\n#ifdef NORMAL\nnormalW=normalize((2.0*baseNormal.xyz-1.0)*tangentSpace);\n#endif\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularBase=vec3(0.,0.,0.);\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse+finalSpecular,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}\n";
  4056. var BABYLON;
  4057. (function (BABYLON) {
  4058. var SkyMaterialDefines = /** @class */ (function (_super) {
  4059. __extends(SkyMaterialDefines, _super);
  4060. function SkyMaterialDefines() {
  4061. var _this = _super.call(this) || this;
  4062. _this.CLIPPLANE = false;
  4063. _this.CLIPPLANE2 = false;
  4064. _this.CLIPPLANE3 = false;
  4065. _this.CLIPPLANE4 = false;
  4066. _this.POINTSIZE = false;
  4067. _this.FOG = false;
  4068. _this.VERTEXCOLOR = false;
  4069. _this.VERTEXALPHA = false;
  4070. _this.rebuild();
  4071. return _this;
  4072. }
  4073. return SkyMaterialDefines;
  4074. }(BABYLON.MaterialDefines));
  4075. var SkyMaterial = /** @class */ (function (_super) {
  4076. __extends(SkyMaterial, _super);
  4077. function SkyMaterial(name, scene) {
  4078. var _this = _super.call(this, name, scene) || this;
  4079. // Public members
  4080. _this.luminance = 1.0;
  4081. _this.turbidity = 10.0;
  4082. _this.rayleigh = 2.0;
  4083. _this.mieCoefficient = 0.005;
  4084. _this.mieDirectionalG = 0.8;
  4085. _this.distance = 500;
  4086. _this.inclination = 0.49;
  4087. _this.azimuth = 0.25;
  4088. _this.sunPosition = new BABYLON.Vector3(0, 100, 0);
  4089. _this.useSunPosition = false;
  4090. // Private members
  4091. _this._cameraPosition = BABYLON.Vector3.Zero();
  4092. return _this;
  4093. }
  4094. SkyMaterial.prototype.needAlphaBlending = function () {
  4095. return (this.alpha < 1.0);
  4096. };
  4097. SkyMaterial.prototype.needAlphaTesting = function () {
  4098. return false;
  4099. };
  4100. SkyMaterial.prototype.getAlphaTestTexture = function () {
  4101. return null;
  4102. };
  4103. // Methods
  4104. SkyMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  4105. if (this.isFrozen) {
  4106. if (this._wasPreviouslyReady && subMesh.effect) {
  4107. return true;
  4108. }
  4109. }
  4110. if (!subMesh._materialDefines) {
  4111. subMesh._materialDefines = new SkyMaterialDefines();
  4112. }
  4113. var defines = subMesh._materialDefines;
  4114. var scene = this.getScene();
  4115. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  4116. if (this._renderId === scene.getRenderId()) {
  4117. return true;
  4118. }
  4119. }
  4120. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, false, defines);
  4121. // Attribs
  4122. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, false);
  4123. // Get correct effect
  4124. if (defines.isDirty) {
  4125. defines.markAsProcessed();
  4126. scene.resetCachedMaterial();
  4127. // Fallbacks
  4128. var fallbacks = new BABYLON.EffectFallbacks();
  4129. if (defines.FOG) {
  4130. fallbacks.addFallback(1, "FOG");
  4131. }
  4132. //Attributes
  4133. var attribs = [BABYLON.VertexBuffer.PositionKind];
  4134. if (defines.VERTEXCOLOR) {
  4135. attribs.push(BABYLON.VertexBuffer.ColorKind);
  4136. }
  4137. var shaderName = "sky";
  4138. var join = defines.toString();
  4139. subMesh.setEffect(scene.getEngine().createEffect(shaderName, attribs, ["world", "viewProjection", "view",
  4140. "vFogInfos", "vFogColor", "pointSize", "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4",
  4141. "luminance", "turbidity", "rayleigh", "mieCoefficient", "mieDirectionalG", "sunPosition",
  4142. "cameraPosition"
  4143. ], [], join, fallbacks, this.onCompiled, this.onError), defines);
  4144. }
  4145. if (!subMesh.effect || !subMesh.effect.isReady()) {
  4146. return false;
  4147. }
  4148. this._renderId = scene.getRenderId();
  4149. this._wasPreviouslyReady = true;
  4150. return true;
  4151. };
  4152. SkyMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  4153. var scene = this.getScene();
  4154. var defines = subMesh._materialDefines;
  4155. if (!defines) {
  4156. return;
  4157. }
  4158. var effect = subMesh.effect;
  4159. if (!effect) {
  4160. return;
  4161. }
  4162. this._activeEffect = effect;
  4163. // Matrices
  4164. this.bindOnlyWorldMatrix(world);
  4165. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  4166. if (this._mustRebind(scene, effect)) {
  4167. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  4168. // Point size
  4169. if (this.pointsCloud) {
  4170. this._activeEffect.setFloat("pointSize", this.pointSize);
  4171. }
  4172. }
  4173. // View
  4174. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  4175. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  4176. }
  4177. // Fog
  4178. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  4179. // Sky
  4180. var camera = scene.activeCamera;
  4181. if (camera) {
  4182. var cameraWorldMatrix = camera.getWorldMatrix();
  4183. this._cameraPosition.x = cameraWorldMatrix.m[12];
  4184. this._cameraPosition.y = cameraWorldMatrix.m[13];
  4185. this._cameraPosition.z = cameraWorldMatrix.m[14];
  4186. this._activeEffect.setVector3("cameraPosition", this._cameraPosition);
  4187. }
  4188. if (this.luminance > 0) {
  4189. this._activeEffect.setFloat("luminance", this.luminance);
  4190. }
  4191. this._activeEffect.setFloat("turbidity", this.turbidity);
  4192. this._activeEffect.setFloat("rayleigh", this.rayleigh);
  4193. this._activeEffect.setFloat("mieCoefficient", this.mieCoefficient);
  4194. this._activeEffect.setFloat("mieDirectionalG", this.mieDirectionalG);
  4195. if (!this.useSunPosition) {
  4196. var theta = Math.PI * (this.inclination - 0.5);
  4197. var phi = 2 * Math.PI * (this.azimuth - 0.5);
  4198. this.sunPosition.x = this.distance * Math.cos(phi);
  4199. this.sunPosition.y = this.distance * Math.sin(phi) * Math.sin(theta);
  4200. this.sunPosition.z = this.distance * Math.sin(phi) * Math.cos(theta);
  4201. }
  4202. this._activeEffect.setVector3("sunPosition", this.sunPosition);
  4203. this._afterBind(mesh, this._activeEffect);
  4204. };
  4205. SkyMaterial.prototype.getAnimatables = function () {
  4206. return [];
  4207. };
  4208. SkyMaterial.prototype.dispose = function (forceDisposeEffect) {
  4209. _super.prototype.dispose.call(this, forceDisposeEffect);
  4210. };
  4211. SkyMaterial.prototype.clone = function (name) {
  4212. var _this = this;
  4213. return BABYLON.SerializationHelper.Clone(function () { return new SkyMaterial(name, _this.getScene()); }, this);
  4214. };
  4215. SkyMaterial.prototype.serialize = function () {
  4216. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  4217. serializationObject.customType = "BABYLON.SkyMaterial";
  4218. return serializationObject;
  4219. };
  4220. SkyMaterial.prototype.getClassName = function () {
  4221. return "SkyMaterial";
  4222. };
  4223. // Statics
  4224. SkyMaterial.Parse = function (source, scene, rootUrl) {
  4225. return BABYLON.SerializationHelper.Parse(function () { return new SkyMaterial(source.name, scene); }, source, scene, rootUrl);
  4226. };
  4227. __decorate([
  4228. BABYLON.serialize()
  4229. ], SkyMaterial.prototype, "luminance", void 0);
  4230. __decorate([
  4231. BABYLON.serialize()
  4232. ], SkyMaterial.prototype, "turbidity", void 0);
  4233. __decorate([
  4234. BABYLON.serialize()
  4235. ], SkyMaterial.prototype, "rayleigh", void 0);
  4236. __decorate([
  4237. BABYLON.serialize()
  4238. ], SkyMaterial.prototype, "mieCoefficient", void 0);
  4239. __decorate([
  4240. BABYLON.serialize()
  4241. ], SkyMaterial.prototype, "mieDirectionalG", void 0);
  4242. __decorate([
  4243. BABYLON.serialize()
  4244. ], SkyMaterial.prototype, "distance", void 0);
  4245. __decorate([
  4246. BABYLON.serialize()
  4247. ], SkyMaterial.prototype, "inclination", void 0);
  4248. __decorate([
  4249. BABYLON.serialize()
  4250. ], SkyMaterial.prototype, "azimuth", void 0);
  4251. __decorate([
  4252. BABYLON.serializeAsVector3()
  4253. ], SkyMaterial.prototype, "sunPosition", void 0);
  4254. __decorate([
  4255. BABYLON.serialize()
  4256. ], SkyMaterial.prototype, "useSunPosition", void 0);
  4257. return SkyMaterial;
  4258. }(BABYLON.PushMaterial));
  4259. BABYLON.SkyMaterial = SkyMaterial;
  4260. })(BABYLON || (BABYLON = {}));
  4261. //# sourceMappingURL=babylon.skyMaterial.js.map
  4262. BABYLON.Effect.ShadersStore['skyVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\nvoid main(void) {\ngl_Position=viewProjection*world*vec4(position,1.0);\nvec4 worldPos=world*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  4263. BABYLON.Effect.ShadersStore['skyPixelShader'] = "precision highp float;\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\nuniform vec3 cameraPosition;\nuniform float luminance;\nuniform float turbidity;\nuniform float rayleigh;\nuniform float mieCoefficient;\nuniform float mieDirectionalG;\nuniform vec3 sunPosition;\n\n#include<fogFragmentDeclaration>\n\nconst float e=2.71828182845904523536028747135266249775724709369995957;\nconst float pi=3.141592653589793238462643383279502884197169;\nconst float n=1.0003;\nconst float N=2.545E25;\nconst float pn=0.035;\nconst vec3 lambda=vec3(680E-9,550E-9,450E-9);\nconst vec3 K=vec3(0.686,0.678,0.666);\nconst float v=4.0;\nconst float rayleighZenithLength=8.4E3;\nconst float mieZenithLength=1.25E3;\nconst vec3 up=vec3(0.0,1.0,0.0);\nconst float EE=1000.0;\nconst float sunAngularDiameterCos=0.999956676946448443553574619906976478926848692873900859324;\nconst float cutoffAngle=pi/1.95;\nconst float steepness=1.5;\nvec3 totalRayleigh(vec3 lambda)\n{\nreturn (8.0*pow(pi,3.0)*pow(pow(n,2.0)-1.0,2.0)*(6.0+3.0*pn))/(3.0*N*pow(lambda,vec3(4.0))*(6.0-7.0*pn));\n}\nvec3 simplifiedRayleigh()\n{\nreturn 0.0005/vec3(94,40,18);\n}\nfloat rayleighPhase(float cosTheta)\n{ \nreturn (3.0/(16.0*pi))*(1.0+pow(cosTheta,2.0));\n}\nvec3 totalMie(vec3 lambda,vec3 K,float T)\n{\nfloat c=(0.2*T )*10E-18;\nreturn 0.434*c*pi*pow((2.0*pi)/lambda,vec3(v-2.0))*K;\n}\nfloat hgPhase(float cosTheta,float g)\n{\nreturn (1.0/(4.0*pi))*((1.0-pow(g,2.0))/pow(1.0-2.0*g*cosTheta+pow(g,2.0),1.5));\n}\nfloat sunIntensity(float zenithAngleCos)\n{\nreturn EE*max(0.0,1.0-exp((-(cutoffAngle-acos(zenithAngleCos))/steepness)));\n}\nfloat A=0.15;\nfloat B=0.50;\nfloat C=0.10;\nfloat D=0.20;\nfloat EEE=0.02;\nfloat F=0.30;\nfloat W=1000.0;\nvec3 Uncharted2Tonemap(vec3 x)\n{\nreturn ((x*(A*x+C*B)+D*EEE)/(x*(A*x+B)+D*F))-EEE/F;\n}\nvoid main(void) {\n\n#include<clipPlaneFragment>\n\nfloat sunfade=1.0-clamp(1.0-exp((sunPosition.y/450000.0)),0.0,1.0);\nfloat rayleighCoefficient=rayleigh-(1.0*(1.0-sunfade));\nvec3 sunDirection=normalize(sunPosition);\nfloat sunE=sunIntensity(dot(sunDirection,up));\nvec3 betaR=simplifiedRayleigh()*rayleighCoefficient;\nvec3 betaM=totalMie(lambda,K,turbidity)*mieCoefficient;\nfloat zenithAngle=acos(max(0.0,dot(up,normalize(vPositionW-cameraPosition))));\nfloat sR=rayleighZenithLength/(cos(zenithAngle)+0.15*pow(93.885-((zenithAngle*180.0)/pi),-1.253));\nfloat sM=mieZenithLength/(cos(zenithAngle)+0.15*pow(93.885-((zenithAngle*180.0)/pi),-1.253));\nvec3 Fex=exp(-(betaR*sR+betaM*sM));\nfloat cosTheta=dot(normalize(vPositionW-cameraPosition),sunDirection);\nfloat rPhase=rayleighPhase(cosTheta*0.5+0.5);\nvec3 betaRTheta=betaR*rPhase;\nfloat mPhase=hgPhase(cosTheta,mieDirectionalG);\nvec3 betaMTheta=betaM*mPhase;\nvec3 Lin=pow(sunE*((betaRTheta+betaMTheta)/(betaR+betaM))*(1.0-Fex),vec3(1.5));\nLin*=mix(vec3(1.0),pow(sunE*((betaRTheta+betaMTheta)/(betaR+betaM))*Fex,vec3(1.0/2.0)),clamp(pow(1.0-dot(up,sunDirection),5.0),0.0,1.0));\nvec3 direction=normalize(vPositionW-cameraPosition);\nfloat theta=acos(direction.y);\nfloat phi=atan(direction.z,direction.x);\nvec2 uv=vec2(phi,theta)/vec2(2.0*pi,pi)+vec2(0.5,0.0);\nvec3 L0=vec3(0.1)*Fex;\nfloat sundisk=smoothstep(sunAngularDiameterCos,sunAngularDiameterCos+0.00002,cosTheta);\nL0+=(sunE*19000.0*Fex)*sundisk;\nvec3 whiteScale=1.0/Uncharted2Tonemap(vec3(W));\nvec3 texColor=(Lin+L0); \ntexColor*=0.04 ;\ntexColor+=vec3(0.0,0.001,0.0025)*0.3;\nfloat g_fMaxLuminance=1.0;\nfloat fLumScaled=0.1/luminance; \nfloat fLumCompressed=(fLumScaled*(1.0+(fLumScaled/(g_fMaxLuminance*g_fMaxLuminance))))/(1.0+fLumScaled); \nfloat ExposureBias=fLumCompressed;\nvec3 curr=Uncharted2Tonemap((log2(2.0/pow(luminance,4.0)))*texColor);\n\n\n\nvec3 retColor=curr*whiteScale;\n\n\nfloat alpha=1.0;\n#ifdef VERTEXCOLOR\nretColor.rgb*=vColor.rgb;\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n\nvec4 color=clamp(vec4(retColor.rgb,alpha),0.0,1.0);\n\n#include<fogFragment>\ngl_FragColor=color;\n}\n";
  4264. var BABYLON;
  4265. (function (BABYLON) {
  4266. var GridMaterialDefines = /** @class */ (function (_super) {
  4267. __extends(GridMaterialDefines, _super);
  4268. function GridMaterialDefines() {
  4269. var _this = _super.call(this) || this;
  4270. _this.TRANSPARENT = false;
  4271. _this.FOG = false;
  4272. _this.PREMULTIPLYALPHA = false;
  4273. _this.rebuild();
  4274. return _this;
  4275. }
  4276. return GridMaterialDefines;
  4277. }(BABYLON.MaterialDefines));
  4278. /**
  4279. * The grid materials allows you to wrap any shape with a grid.
  4280. * Colors are customizable.
  4281. */
  4282. var GridMaterial = /** @class */ (function (_super) {
  4283. __extends(GridMaterial, _super);
  4284. /**
  4285. * constructor
  4286. * @param name The name given to the material in order to identify it afterwards.
  4287. * @param scene The scene the material is used in.
  4288. */
  4289. function GridMaterial(name, scene) {
  4290. var _this = _super.call(this, name, scene) || this;
  4291. /**
  4292. * Main color of the grid (e.g. between lines)
  4293. */
  4294. _this.mainColor = BABYLON.Color3.Black();
  4295. /**
  4296. * Color of the grid lines.
  4297. */
  4298. _this.lineColor = BABYLON.Color3.Teal();
  4299. /**
  4300. * The scale of the grid compared to unit.
  4301. */
  4302. _this.gridRatio = 1.0;
  4303. /**
  4304. * Allows setting an offset for the grid lines.
  4305. */
  4306. _this.gridOffset = BABYLON.Vector3.Zero();
  4307. /**
  4308. * The frequency of thicker lines.
  4309. */
  4310. _this.majorUnitFrequency = 10;
  4311. /**
  4312. * The visibility of minor units in the grid.
  4313. */
  4314. _this.minorUnitVisibility = 0.33;
  4315. /**
  4316. * The grid opacity outside of the lines.
  4317. */
  4318. _this.opacity = 1.0;
  4319. /**
  4320. * Determine RBG output is premultiplied by alpha value.
  4321. */
  4322. _this.preMultiplyAlpha = false;
  4323. _this._gridControl = new BABYLON.Vector4(_this.gridRatio, _this.majorUnitFrequency, _this.minorUnitVisibility, _this.opacity);
  4324. return _this;
  4325. }
  4326. /**
  4327. * Returns wehter or not the grid requires alpha blending.
  4328. */
  4329. GridMaterial.prototype.needAlphaBlending = function () {
  4330. return this.opacity < 1.0;
  4331. };
  4332. GridMaterial.prototype.needAlphaBlendingForMesh = function (mesh) {
  4333. return this.needAlphaBlending();
  4334. };
  4335. GridMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  4336. if (this.isFrozen) {
  4337. if (this._wasPreviouslyReady && subMesh.effect) {
  4338. return true;
  4339. }
  4340. }
  4341. if (!subMesh._materialDefines) {
  4342. subMesh._materialDefines = new GridMaterialDefines();
  4343. }
  4344. var defines = subMesh._materialDefines;
  4345. var scene = this.getScene();
  4346. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  4347. if (this._renderId === scene.getRenderId()) {
  4348. return true;
  4349. }
  4350. }
  4351. if (defines.TRANSPARENT !== (this.opacity < 1.0)) {
  4352. defines.TRANSPARENT = !defines.TRANSPARENT;
  4353. defines.markAsUnprocessed();
  4354. }
  4355. if (defines.PREMULTIPLYALPHA != this.preMultiplyAlpha) {
  4356. defines.PREMULTIPLYALPHA = !defines.PREMULTIPLYALPHA;
  4357. defines.markAsUnprocessed();
  4358. }
  4359. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, false, this.fogEnabled, false, defines);
  4360. // Get correct effect
  4361. if (defines.isDirty) {
  4362. defines.markAsProcessed();
  4363. scene.resetCachedMaterial();
  4364. // Attributes
  4365. var attribs = [BABYLON.VertexBuffer.PositionKind, BABYLON.VertexBuffer.NormalKind];
  4366. // Defines
  4367. var join = defines.toString();
  4368. subMesh.setEffect(scene.getEngine().createEffect("grid", attribs, ["projection", "worldView", "mainColor", "lineColor", "gridControl", "gridOffset", "vFogInfos", "vFogColor", "world", "view"], [], join, undefined, this.onCompiled, this.onError), defines);
  4369. }
  4370. if (!subMesh.effect || !subMesh.effect.isReady()) {
  4371. return false;
  4372. }
  4373. this._renderId = scene.getRenderId();
  4374. this._wasPreviouslyReady = true;
  4375. return true;
  4376. };
  4377. GridMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  4378. var scene = this.getScene();
  4379. var defines = subMesh._materialDefines;
  4380. if (!defines) {
  4381. return;
  4382. }
  4383. var effect = subMesh.effect;
  4384. if (!effect) {
  4385. return;
  4386. }
  4387. this._activeEffect = effect;
  4388. // Matrices
  4389. this.bindOnlyWorldMatrix(world);
  4390. this._activeEffect.setMatrix("worldView", world.multiply(scene.getViewMatrix()));
  4391. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  4392. this._activeEffect.setMatrix("projection", scene.getProjectionMatrix());
  4393. // Uniforms
  4394. if (this._mustRebind(scene, effect)) {
  4395. this._activeEffect.setColor3("mainColor", this.mainColor);
  4396. this._activeEffect.setColor3("lineColor", this.lineColor);
  4397. this._activeEffect.setVector3("gridOffset", this.gridOffset);
  4398. this._gridControl.x = this.gridRatio;
  4399. this._gridControl.y = Math.round(this.majorUnitFrequency);
  4400. this._gridControl.z = this.minorUnitVisibility;
  4401. this._gridControl.w = this.opacity;
  4402. this._activeEffect.setVector4("gridControl", this._gridControl);
  4403. }
  4404. // Fog
  4405. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  4406. this._afterBind(mesh, this._activeEffect);
  4407. };
  4408. GridMaterial.prototype.dispose = function (forceDisposeEffect) {
  4409. _super.prototype.dispose.call(this, forceDisposeEffect);
  4410. };
  4411. GridMaterial.prototype.clone = function (name) {
  4412. var _this = this;
  4413. return BABYLON.SerializationHelper.Clone(function () { return new GridMaterial(name, _this.getScene()); }, this);
  4414. };
  4415. GridMaterial.prototype.serialize = function () {
  4416. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  4417. serializationObject.customType = "BABYLON.GridMaterial";
  4418. return serializationObject;
  4419. };
  4420. GridMaterial.prototype.getClassName = function () {
  4421. return "GridMaterial";
  4422. };
  4423. GridMaterial.Parse = function (source, scene, rootUrl) {
  4424. return BABYLON.SerializationHelper.Parse(function () { return new GridMaterial(source.name, scene); }, source, scene, rootUrl);
  4425. };
  4426. __decorate([
  4427. BABYLON.serializeAsColor3()
  4428. ], GridMaterial.prototype, "mainColor", void 0);
  4429. __decorate([
  4430. BABYLON.serializeAsColor3()
  4431. ], GridMaterial.prototype, "lineColor", void 0);
  4432. __decorate([
  4433. BABYLON.serialize()
  4434. ], GridMaterial.prototype, "gridRatio", void 0);
  4435. __decorate([
  4436. BABYLON.serializeAsColor3()
  4437. ], GridMaterial.prototype, "gridOffset", void 0);
  4438. __decorate([
  4439. BABYLON.serialize()
  4440. ], GridMaterial.prototype, "majorUnitFrequency", void 0);
  4441. __decorate([
  4442. BABYLON.serialize()
  4443. ], GridMaterial.prototype, "minorUnitVisibility", void 0);
  4444. __decorate([
  4445. BABYLON.serialize()
  4446. ], GridMaterial.prototype, "opacity", void 0);
  4447. __decorate([
  4448. BABYLON.serialize()
  4449. ], GridMaterial.prototype, "preMultiplyAlpha", void 0);
  4450. return GridMaterial;
  4451. }(BABYLON.PushMaterial));
  4452. BABYLON.GridMaterial = GridMaterial;
  4453. })(BABYLON || (BABYLON = {}));
  4454. //# sourceMappingURL=babylon.gridmaterial.js.map
  4455. BABYLON.Effect.ShadersStore['gridVertexShader'] = "precision highp float;\n\nattribute vec3 position;\nattribute vec3 normal;\n\nuniform mat4 projection;\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 worldView;\n\n#ifdef TRANSPARENT\nvarying vec4 vCameraSpacePosition;\n#endif\nvarying vec3 vPosition;\nvarying vec3 vNormal;\n#include<fogVertexDeclaration>\nvoid main(void) {\n#ifdef FOG\nvec4 worldPos=world*vec4(position,1.0);\n#endif\n#include<fogVertex>\nvec4 cameraSpacePosition=worldView*vec4(position,1.0);\ngl_Position=projection*cameraSpacePosition;\n#ifdef TRANSPARENT\nvCameraSpacePosition=cameraSpacePosition;\n#endif\nvPosition=position;\nvNormal=normal;\n}";
  4456. BABYLON.Effect.ShadersStore['gridPixelShader'] = "#extension GL_OES_standard_derivatives : enable\n#define SQRT2 1.41421356\n#define PI 3.14159\nprecision highp float;\nuniform vec3 mainColor;\nuniform vec3 lineColor;\nuniform vec4 gridControl;\nuniform vec3 gridOffset;\n\n#ifdef TRANSPARENT\nvarying vec4 vCameraSpacePosition;\n#endif\nvarying vec3 vPosition;\nvarying vec3 vNormal;\n#include<fogFragmentDeclaration>\nfloat getVisibility(float position) {\n\nfloat majorGridFrequency=gridControl.y;\nif (floor(position+0.5) == floor(position/majorGridFrequency+0.5)*majorGridFrequency)\n{\nreturn 1.0;\n} \nreturn gridControl.z;\n}\nfloat getAnisotropicAttenuation(float differentialLength) {\nconst float maxNumberOfLines=10.0;\nreturn clamp(1.0/(differentialLength+1.0)-1.0/maxNumberOfLines,0.0,1.0);\n}\nfloat isPointOnLine(float position,float differentialLength) {\nfloat fractionPartOfPosition=position-floor(position+0.5); \nfractionPartOfPosition/=differentialLength; \nfractionPartOfPosition=clamp(fractionPartOfPosition,-1.,1.);\nfloat result=0.5+0.5*cos(fractionPartOfPosition*PI); \nreturn result; \n}\nfloat contributionOnAxis(float position) {\nfloat differentialLength=length(vec2(dFdx(position),dFdy(position)));\ndifferentialLength*=SQRT2; \n\nfloat result=isPointOnLine(position,differentialLength);\n\nfloat visibility=getVisibility(position);\nresult*=visibility;\n\nfloat anisotropicAttenuation=getAnisotropicAttenuation(differentialLength);\nresult*=anisotropicAttenuation;\nreturn result;\n}\nfloat normalImpactOnAxis(float x) {\nfloat normalImpact=clamp(1.0-3.0*abs(x*x*x),0.0,1.0);\nreturn normalImpact;\n}\nvoid main(void) {\n\nfloat gridRatio=gridControl.x;\nvec3 gridPos=(vPosition+gridOffset)/gridRatio;\n\nfloat x=contributionOnAxis(gridPos.x);\nfloat y=contributionOnAxis(gridPos.y);\nfloat z=contributionOnAxis(gridPos.z);\n\nvec3 normal=normalize(vNormal);\nx*=normalImpactOnAxis(normal.x);\ny*=normalImpactOnAxis(normal.y);\nz*=normalImpactOnAxis(normal.z);\n\nfloat grid=clamp(x+y+z,0.,1.);\n\nvec3 color=mix(mainColor,lineColor,grid);\n#ifdef FOG\n#include<fogFragment>\n#endif\n#ifdef TRANSPARENT\nfloat distanceToFragment=length(vCameraSpacePosition.xyz);\nfloat cameraPassThrough=clamp(distanceToFragment-0.25,0.0,1.0);\nfloat opacity=clamp(grid,0.08,cameraPassThrough*gridControl.w*grid);\ngl_FragColor=vec4(color.rgb,opacity);\n#ifdef PREMULTIPLYALPHA\ngl_FragColor.rgb*=opacity;\n#endif\n#else\n\ngl_FragColor=vec4(color.rgb,1.0);\n#endif\n}";
  4457. var BABYLON;
  4458. (function (BABYLON) {
  4459. var CustomShaderStructure = /** @class */ (function () {
  4460. function CustomShaderStructure() {
  4461. }
  4462. return CustomShaderStructure;
  4463. }());
  4464. BABYLON.CustomShaderStructure = CustomShaderStructure;
  4465. var ShaderSpecialParts = /** @class */ (function () {
  4466. function ShaderSpecialParts() {
  4467. }
  4468. return ShaderSpecialParts;
  4469. }());
  4470. BABYLON.ShaderSpecialParts = ShaderSpecialParts;
  4471. var CustomMaterial = /** @class */ (function (_super) {
  4472. __extends(CustomMaterial, _super);
  4473. function CustomMaterial(name, scene) {
  4474. var _this = _super.call(this, name, scene) || this;
  4475. _this.CustomParts = new ShaderSpecialParts();
  4476. _this.customShaderNameResolve = _this.Builder;
  4477. _this.FragmentShader = BABYLON.Effect.ShadersStore["defaultPixelShader"];
  4478. _this.VertexShader = BABYLON.Effect.ShadersStore["defaultVertexShader"];
  4479. return _this;
  4480. }
  4481. CustomMaterial.prototype.AttachAfterBind = function (mesh, effect) {
  4482. for (var el in this._newUniformInstances) {
  4483. var ea = el.toString().split('-');
  4484. if (ea[0] == 'vec2') {
  4485. effect.setVector2(ea[1], this._newUniformInstances[el]);
  4486. }
  4487. else if (ea[0] == 'vec3') {
  4488. effect.setVector3(ea[1], this._newUniformInstances[el]);
  4489. }
  4490. else if (ea[0] == 'vec4') {
  4491. effect.setVector4(ea[1], this._newUniformInstances[el]);
  4492. }
  4493. else if (ea[0] == 'mat4') {
  4494. effect.setMatrix(ea[1], this._newUniformInstances[el]);
  4495. }
  4496. else if (ea[0] == 'float') {
  4497. effect.setFloat(ea[1], this._newUniformInstances[el]);
  4498. }
  4499. }
  4500. for (var el in this._newSamplerInstances) {
  4501. var ea = el.toString().split('-');
  4502. if (ea[0] == 'sampler2D' && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady()) {
  4503. effect.setTexture(ea[1], this._newSamplerInstances[el]);
  4504. }
  4505. }
  4506. };
  4507. CustomMaterial.prototype.ReviewUniform = function (name, arr) {
  4508. if (name == "uniform") {
  4509. for (var ind in this._newUniforms) {
  4510. if (this._customUniform[ind].indexOf('sampler') == -1) {
  4511. arr.push(this._newUniforms[ind]);
  4512. }
  4513. }
  4514. }
  4515. if (name == "sampler") {
  4516. for (var ind in this._newUniforms) {
  4517. if (this._customUniform[ind].indexOf('sampler') != -1) {
  4518. arr.push(this._newUniforms[ind]);
  4519. }
  4520. }
  4521. }
  4522. return arr;
  4523. };
  4524. CustomMaterial.prototype.Builder = function (shaderName, uniforms, uniformBuffers, samplers, defines) {
  4525. var _this = this;
  4526. if (this._isCreatedShader) {
  4527. return this._createdShaderName;
  4528. }
  4529. this._isCreatedShader = false;
  4530. CustomMaterial.ShaderIndexer++;
  4531. var name = "custom_" + CustomMaterial.ShaderIndexer;
  4532. this.ReviewUniform("uniform", uniforms);
  4533. this.ReviewUniform("sampler", samplers);
  4534. var fn_afterBind = this._afterBind.bind(this);
  4535. this._afterBind = function (m, e) {
  4536. if (!e) {
  4537. return;
  4538. }
  4539. _this.AttachAfterBind(m, e);
  4540. try {
  4541. fn_afterBind(m, e);
  4542. }
  4543. catch (e) { }
  4544. };
  4545. BABYLON.Effect.ShadersStore[name + "VertexShader"] = this.VertexShader
  4546. .replace('#define CUSTOM_VERTEX_BEGIN', (this.CustomParts.Vertex_Begin ? this.CustomParts.Vertex_Begin : ""))
  4547. .replace('#define CUSTOM_VERTEX_DEFINITIONS', (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Vertex_Definitions ? this.CustomParts.Vertex_Definitions : ""))
  4548. .replace('#define CUSTOM_VERTEX_MAIN_BEGIN', (this.CustomParts.Vertex_MainBegin ? this.CustomParts.Vertex_MainBegin : ""))
  4549. .replace('#define CUSTOM_VERTEX_UPDATE_POSITION', (this.CustomParts.Vertex_Before_PositionUpdated ? this.CustomParts.Vertex_Before_PositionUpdated : ""))
  4550. .replace('#define CUSTOM_VERTEX_UPDATE_NORMAL', (this.CustomParts.Vertex_Before_NormalUpdated ? this.CustomParts.Vertex_Before_NormalUpdated : ""));
  4551. // #define CUSTOM_VERTEX_MAIN_END
  4552. BABYLON.Effect.ShadersStore[name + "PixelShader"] = this.FragmentShader
  4553. .replace('#define CUSTOM_FRAGMENT_BEGIN', (this.CustomParts.Fragment_Begin ? this.CustomParts.Fragment_Begin : ""))
  4554. .replace('#define CUSTOM_FRAGMENT_MAIN_BEGIN', (this.CustomParts.Fragment_MainBegin ? this.CustomParts.Fragment_MainBegin : ""))
  4555. .replace('#define CUSTOM_FRAGMENT_DEFINITIONS', (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Fragment_Definitions ? this.CustomParts.Fragment_Definitions : ""))
  4556. .replace('#define CUSTOM_FRAGMENT_UPDATE_DIFFUSE', (this.CustomParts.Fragment_Custom_Diffuse ? this.CustomParts.Fragment_Custom_Diffuse : ""))
  4557. .replace('#define CUSTOM_FRAGMENT_UPDATE_ALPHA', (this.CustomParts.Fragment_Custom_Alpha ? this.CustomParts.Fragment_Custom_Alpha : ""))
  4558. .replace('#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR', (this.CustomParts.Fragment_Before_FragColor ? this.CustomParts.Fragment_Before_FragColor : ""));
  4559. // #define CUSTOM_FRAGMENT_BEFORE_LIGHTS
  4560. // #define CUSTOM_FRAGMENT_BEFORE_FOG
  4561. this._isCreatedShader = true;
  4562. this._createdShaderName = name;
  4563. return name;
  4564. };
  4565. CustomMaterial.prototype.AddUniform = function (name, kind, param) {
  4566. if (!this._customUniform) {
  4567. this._customUniform = new Array();
  4568. this._newUniforms = new Array();
  4569. this._newSamplerInstances = new Array();
  4570. this._newUniformInstances = new Array();
  4571. }
  4572. if (param) {
  4573. if (kind.indexOf("sampler") == -1) {
  4574. this._newUniformInstances[kind + "-" + name] = param;
  4575. }
  4576. else {
  4577. this._newUniformInstances[kind + "-" + name] = param;
  4578. }
  4579. }
  4580. this._customUniform.push("uniform " + kind + " " + name + ";");
  4581. this._newUniforms.push(name);
  4582. return this;
  4583. };
  4584. CustomMaterial.prototype.Fragment_Begin = function (shaderPart) {
  4585. this.CustomParts.Fragment_Begin = shaderPart;
  4586. return this;
  4587. };
  4588. CustomMaterial.prototype.Fragment_Definitions = function (shaderPart) {
  4589. this.CustomParts.Fragment_Definitions = shaderPart;
  4590. return this;
  4591. };
  4592. CustomMaterial.prototype.Fragment_MainBegin = function (shaderPart) {
  4593. this.CustomParts.Fragment_MainBegin = shaderPart;
  4594. return this;
  4595. };
  4596. CustomMaterial.prototype.Fragment_Custom_Diffuse = function (shaderPart) {
  4597. this.CustomParts.Fragment_Custom_Diffuse = shaderPart.replace("result", "diffuseColor");
  4598. return this;
  4599. };
  4600. CustomMaterial.prototype.Fragment_Custom_Alpha = function (shaderPart) {
  4601. this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace("result", "alpha");
  4602. return this;
  4603. };
  4604. CustomMaterial.prototype.Fragment_Before_FragColor = function (shaderPart) {
  4605. this.CustomParts.Fragment_Before_FragColor = shaderPart.replace("result", "color");
  4606. return this;
  4607. };
  4608. CustomMaterial.prototype.Vertex_Begin = function (shaderPart) {
  4609. this.CustomParts.Vertex_Begin = shaderPart;
  4610. return this;
  4611. };
  4612. CustomMaterial.prototype.Vertex_Definitions = function (shaderPart) {
  4613. this.CustomParts.Vertex_Definitions = shaderPart;
  4614. return this;
  4615. };
  4616. CustomMaterial.prototype.Vertex_MainBegin = function (shaderPart) {
  4617. this.CustomParts.Vertex_MainBegin = shaderPart;
  4618. return this;
  4619. };
  4620. CustomMaterial.prototype.Vertex_Before_PositionUpdated = function (shaderPart) {
  4621. this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace("result", "positionUpdated");
  4622. return this;
  4623. };
  4624. CustomMaterial.prototype.Vertex_Before_NormalUpdated = function (shaderPart) {
  4625. this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace("result", "normalUpdated");
  4626. return this;
  4627. };
  4628. CustomMaterial.ShaderIndexer = 1;
  4629. return CustomMaterial;
  4630. }(BABYLON.StandardMaterial));
  4631. BABYLON.CustomMaterial = CustomMaterial;
  4632. })(BABYLON || (BABYLON = {}));
  4633. //# sourceMappingURL=babylon.customMaterial.js.map
  4634. var BABYLON;
  4635. (function (BABYLON) {
  4636. var CellMaterialDefines = /** @class */ (function (_super) {
  4637. __extends(CellMaterialDefines, _super);
  4638. function CellMaterialDefines() {
  4639. var _this = _super.call(this) || this;
  4640. _this.DIFFUSE = false;
  4641. _this.CLIPPLANE = false;
  4642. _this.CLIPPLANE2 = false;
  4643. _this.CLIPPLANE3 = false;
  4644. _this.CLIPPLANE4 = false;
  4645. _this.ALPHATEST = false;
  4646. _this.POINTSIZE = false;
  4647. _this.FOG = false;
  4648. _this.NORMAL = false;
  4649. _this.UV1 = false;
  4650. _this.UV2 = false;
  4651. _this.VERTEXCOLOR = false;
  4652. _this.VERTEXALPHA = false;
  4653. _this.NUM_BONE_INFLUENCERS = 0;
  4654. _this.BonesPerMesh = 0;
  4655. _this.INSTANCES = false;
  4656. _this.NDOTL = true;
  4657. _this.CUSTOMUSERLIGHTING = true;
  4658. _this.CELLBASIC = true;
  4659. _this.DEPTHPREPASS = false;
  4660. _this.rebuild();
  4661. return _this;
  4662. }
  4663. return CellMaterialDefines;
  4664. }(BABYLON.MaterialDefines));
  4665. var CellMaterial = /** @class */ (function (_super) {
  4666. __extends(CellMaterial, _super);
  4667. function CellMaterial(name, scene) {
  4668. var _this = _super.call(this, name, scene) || this;
  4669. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  4670. _this._computeHighLevel = false;
  4671. _this._disableLighting = false;
  4672. _this._maxSimultaneousLights = 4;
  4673. return _this;
  4674. }
  4675. CellMaterial.prototype.needAlphaBlending = function () {
  4676. return (this.alpha < 1.0);
  4677. };
  4678. CellMaterial.prototype.needAlphaTesting = function () {
  4679. return false;
  4680. };
  4681. CellMaterial.prototype.getAlphaTestTexture = function () {
  4682. return null;
  4683. };
  4684. // Methods
  4685. CellMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  4686. if (this.isFrozen) {
  4687. if (this._wasPreviouslyReady && subMesh.effect) {
  4688. return true;
  4689. }
  4690. }
  4691. if (!subMesh._materialDefines) {
  4692. subMesh._materialDefines = new CellMaterialDefines();
  4693. }
  4694. var defines = subMesh._materialDefines;
  4695. var scene = this.getScene();
  4696. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  4697. if (this._renderId === scene.getRenderId()) {
  4698. return true;
  4699. }
  4700. }
  4701. var engine = scene.getEngine();
  4702. // Textures
  4703. if (defines._areTexturesDirty) {
  4704. defines._needUVs = false;
  4705. if (scene.texturesEnabled) {
  4706. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  4707. if (!this._diffuseTexture.isReady()) {
  4708. return false;
  4709. }
  4710. else {
  4711. defines._needUVs = true;
  4712. defines.DIFFUSE = true;
  4713. }
  4714. }
  4715. }
  4716. }
  4717. // High level
  4718. defines.CELLBASIC = !this.computeHighLevel;
  4719. // Misc.
  4720. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  4721. // Lights
  4722. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  4723. // Values that need to be evaluated on every frame
  4724. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  4725. // Attribs
  4726. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  4727. // Get correct effect
  4728. if (defines.isDirty) {
  4729. defines.markAsProcessed();
  4730. scene.resetCachedMaterial();
  4731. // Fallbacks
  4732. var fallbacks = new BABYLON.EffectFallbacks();
  4733. if (defines.FOG) {
  4734. fallbacks.addFallback(1, "FOG");
  4735. }
  4736. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  4737. if (defines.NUM_BONE_INFLUENCERS > 0) {
  4738. fallbacks.addCPUSkinningFallback(0, mesh);
  4739. }
  4740. //Attributes
  4741. var attribs = [BABYLON.VertexBuffer.PositionKind];
  4742. if (defines.NORMAL) {
  4743. attribs.push(BABYLON.VertexBuffer.NormalKind);
  4744. }
  4745. if (defines.UV1) {
  4746. attribs.push(BABYLON.VertexBuffer.UVKind);
  4747. }
  4748. if (defines.UV2) {
  4749. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  4750. }
  4751. if (defines.VERTEXCOLOR) {
  4752. attribs.push(BABYLON.VertexBuffer.ColorKind);
  4753. }
  4754. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  4755. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  4756. var shaderName = "cell";
  4757. var join = defines.toString();
  4758. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  4759. "vFogInfos", "vFogColor", "pointSize",
  4760. "vDiffuseInfos",
  4761. "mBones",
  4762. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix"
  4763. ];
  4764. var samplers = ["diffuseSampler"];
  4765. var uniformBuffers = new Array();
  4766. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  4767. uniformsNames: uniforms,
  4768. uniformBuffersNames: uniformBuffers,
  4769. samplers: samplers,
  4770. defines: defines,
  4771. maxSimultaneousLights: this.maxSimultaneousLights
  4772. });
  4773. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  4774. attributes: attribs,
  4775. uniformsNames: uniforms,
  4776. uniformBuffersNames: uniformBuffers,
  4777. samplers: samplers,
  4778. defines: join,
  4779. fallbacks: fallbacks,
  4780. onCompiled: this.onCompiled,
  4781. onError: this.onError,
  4782. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights - 1 }
  4783. }, engine), defines);
  4784. }
  4785. if (!subMesh.effect || !subMesh.effect.isReady()) {
  4786. return false;
  4787. }
  4788. this._renderId = scene.getRenderId();
  4789. this._wasPreviouslyReady = true;
  4790. return true;
  4791. };
  4792. CellMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  4793. var scene = this.getScene();
  4794. var defines = subMesh._materialDefines;
  4795. if (!defines) {
  4796. return;
  4797. }
  4798. var effect = subMesh.effect;
  4799. if (!effect) {
  4800. return;
  4801. }
  4802. this._activeEffect = effect;
  4803. // Matrices
  4804. this.bindOnlyWorldMatrix(world);
  4805. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  4806. // Bones
  4807. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  4808. if (this._mustRebind(scene, effect)) {
  4809. // Textures
  4810. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  4811. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  4812. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  4813. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  4814. }
  4815. // Clip plane
  4816. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  4817. // Point size
  4818. if (this.pointsCloud) {
  4819. this._activeEffect.setFloat("pointSize", this.pointSize);
  4820. }
  4821. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  4822. }
  4823. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  4824. // Lights
  4825. if (scene.lightsEnabled && !this.disableLighting) {
  4826. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this._maxSimultaneousLights);
  4827. }
  4828. // View
  4829. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  4830. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  4831. }
  4832. // Fog
  4833. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  4834. this._afterBind(mesh, this._activeEffect);
  4835. };
  4836. CellMaterial.prototype.getAnimatables = function () {
  4837. var results = [];
  4838. if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
  4839. results.push(this._diffuseTexture);
  4840. }
  4841. return results;
  4842. };
  4843. CellMaterial.prototype.getActiveTextures = function () {
  4844. var activeTextures = _super.prototype.getActiveTextures.call(this);
  4845. if (this._diffuseTexture) {
  4846. activeTextures.push(this._diffuseTexture);
  4847. }
  4848. return activeTextures;
  4849. };
  4850. CellMaterial.prototype.hasTexture = function (texture) {
  4851. if (_super.prototype.hasTexture.call(this, texture)) {
  4852. return true;
  4853. }
  4854. return this._diffuseTexture === texture;
  4855. };
  4856. CellMaterial.prototype.dispose = function (forceDisposeEffect) {
  4857. if (this._diffuseTexture) {
  4858. this._diffuseTexture.dispose();
  4859. }
  4860. _super.prototype.dispose.call(this, forceDisposeEffect);
  4861. };
  4862. CellMaterial.prototype.getClassName = function () {
  4863. return "CellMaterial";
  4864. };
  4865. CellMaterial.prototype.clone = function (name) {
  4866. var _this = this;
  4867. return BABYLON.SerializationHelper.Clone(function () { return new CellMaterial(name, _this.getScene()); }, this);
  4868. };
  4869. CellMaterial.prototype.serialize = function () {
  4870. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  4871. serializationObject.customType = "BABYLON.CellMaterial";
  4872. return serializationObject;
  4873. };
  4874. // Statics
  4875. CellMaterial.Parse = function (source, scene, rootUrl) {
  4876. return BABYLON.SerializationHelper.Parse(function () { return new CellMaterial(source.name, scene); }, source, scene, rootUrl);
  4877. };
  4878. __decorate([
  4879. BABYLON.serializeAsTexture("diffuseTexture")
  4880. ], CellMaterial.prototype, "_diffuseTexture", void 0);
  4881. __decorate([
  4882. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4883. ], CellMaterial.prototype, "diffuseTexture", void 0);
  4884. __decorate([
  4885. BABYLON.serializeAsColor3("diffuse")
  4886. ], CellMaterial.prototype, "diffuseColor", void 0);
  4887. __decorate([
  4888. BABYLON.serialize("computeHighLevel")
  4889. ], CellMaterial.prototype, "_computeHighLevel", void 0);
  4890. __decorate([
  4891. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  4892. ], CellMaterial.prototype, "computeHighLevel", void 0);
  4893. __decorate([
  4894. BABYLON.serialize("disableLighting")
  4895. ], CellMaterial.prototype, "_disableLighting", void 0);
  4896. __decorate([
  4897. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  4898. ], CellMaterial.prototype, "disableLighting", void 0);
  4899. __decorate([
  4900. BABYLON.serialize("maxSimultaneousLights")
  4901. ], CellMaterial.prototype, "_maxSimultaneousLights", void 0);
  4902. __decorate([
  4903. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  4904. ], CellMaterial.prototype, "maxSimultaneousLights", void 0);
  4905. return CellMaterial;
  4906. }(BABYLON.PushMaterial));
  4907. BABYLON.CellMaterial = CellMaterial;
  4908. })(BABYLON || (BABYLON = {}));
  4909. //# sourceMappingURL=babylon.cellMaterial.js.map
  4910. BABYLON.Effect.ShadersStore['cellVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  4911. BABYLON.Effect.ShadersStore['cellPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\n\nvec3 computeCustomDiffuseLighting(lightingInfo info,vec3 diffuseBase,float shadow)\n{\ndiffuseBase=info.diffuse*shadow;\n#ifdef CELLBASIC\nfloat level=1.0;\nif (info.ndl<0.5)\nlevel=0.5;\ndiffuseBase.rgb*vec3(level,level,level);\n#else\nfloat ToonThresholds[4];\nToonThresholds[0]=0.95;\nToonThresholds[1]=0.5;\nToonThresholds[2]=0.2;\nToonThresholds[3]=0.03;\nfloat ToonBrightnessLevels[5];\nToonBrightnessLevels[0]=1.0;\nToonBrightnessLevels[1]=0.8;\nToonBrightnessLevels[2]=0.6;\nToonBrightnessLevels[3]=0.35;\nToonBrightnessLevels[4]=0.2;\nif (info.ndl>ToonThresholds[0])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[0];\n}\nelse if (info.ndl>ToonThresholds[1])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[1];\n}\nelse if (info.ndl>ToonThresholds[2])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[2];\n}\nelse if (info.ndl>ToonThresholds[3])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[3];\n}\nelse\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[4];\n}\n#endif\nreturn max(diffuseBase,vec3(0.2));\n}\nvoid main(void)\n{\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nlightingInfo info;\nvec3 diffuseBase=vec3(0.,0.,0.);\nfloat shadow=1.;\nfloat glossiness=0.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif \n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
  4912. return BABYLON;
  4913. });