babylonjs.materials.js 287 KB

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