babylonjs.materials.js 254 KB

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