babylonjs.materials.js 253 KB

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