babylonjs.materials.js 254 KB

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