babylonjs.materials.js 255 KB

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