babylonjs.materials.js 281 KB

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