babylonjs.materials.js 254 KB

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