babylonjs.materials.js 280 KB

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