babylonjs.materials.js 254 KB

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