babylon.mixMaterial.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("babylonjs"));
  4. else if(typeof define === 'function' && define.amd)
  5. define("babylonjs-materials", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-materials"] = factory(require("babylonjs"));
  8. else
  9. root["MATLIB"] = factory(root["BABYLON"]);
  10. })(window, function(__WEBPACK_EXTERNAL_MODULE_babylonjs__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = "./legacy/legacy-mix.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../node_modules/webpack/buildin/global.js":
  99. /*!*************************************************!*\
  100. !*** ../node_modules/webpack/buildin/global.js ***!
  101. \*************************************************/
  102. /*! no static exports found */
  103. /***/ (function(module, exports) {
  104. var g;
  105. // This works in non-strict mode
  106. g = (function() {
  107. return this;
  108. })();
  109. try {
  110. // This works if eval is allowed (see CSP)
  111. g = g || Function("return this")() || (1, eval)("this");
  112. } catch (e) {
  113. // This works if the window reference is available
  114. if (typeof window === "object") g = window;
  115. }
  116. // g can still be undefined, but nothing to do about it...
  117. // We return undefined, instead of nothing here, so it's
  118. // easier to handle this case. if(!global) { ...}
  119. module.exports = g;
  120. /***/ }),
  121. /***/ "./legacy/legacy-mix.ts":
  122. /*!******************************!*\
  123. !*** ./legacy/legacy-mix.ts ***!
  124. \******************************/
  125. /*! no static exports found */
  126. /***/ (function(module, exports, __webpack_require__) {
  127. "use strict";
  128. /* WEBPACK VAR INJECTION */(function(global) {
  129. function __export(m) {
  130. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  131. }
  132. Object.defineProperty(exports, "__esModule", { value: true });
  133. var MatLib = __webpack_require__(/*! ../src/mix/index */ "./src/mix/index.ts");
  134. /**
  135. * This is the entry point for the UMD module.
  136. * The entry point for a future ESM package should be index.ts
  137. */
  138. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  139. if (typeof globalObject !== "undefined") {
  140. for (var key in MatLib) {
  141. globalObject.BABYLON[key] = MatLib[key];
  142. }
  143. }
  144. __export(__webpack_require__(/*! ../src/mix/index */ "./src/mix/index.ts"));
  145. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../node_modules/webpack/buildin/global.js */ "../node_modules/webpack/buildin/global.js")))
  146. /***/ }),
  147. /***/ "./src/mix/index.ts":
  148. /*!**************************!*\
  149. !*** ./src/mix/index.ts ***!
  150. \**************************/
  151. /*! no static exports found */
  152. /***/ (function(module, exports, __webpack_require__) {
  153. "use strict";
  154. function __export(m) {
  155. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  156. }
  157. Object.defineProperty(exports, "__esModule", { value: true });
  158. __export(__webpack_require__(/*! ./mixMaterial */ "./src/mix/mixMaterial.ts"));
  159. /***/ }),
  160. /***/ "./src/mix/mix.fragment.ts":
  161. /*!*********************************!*\
  162. !*** ./src/mix/mix.fragment.ts ***!
  163. \*********************************/
  164. /*! no static exports found */
  165. /***/ (function(module, exports, __webpack_require__) {
  166. "use strict";
  167. Object.defineProperty(exports, "__esModule", { value: true });
  168. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  169. var name = 'mixPixelShader';
  170. exports.name = name;
  171. var shader = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef DIFFUSE\nvarying vec2 vTextureUV;\nuniform sampler2D mixMap1Sampler;\nuniform vec2 vTextureInfos;\n#ifdef MIXMAP2\nuniform sampler2D mixMap2Sampler;\n#endif\nuniform sampler2D diffuse1Sampler;\nuniform sampler2D diffuse2Sampler;\nuniform sampler2D diffuse3Sampler;\nuniform sampler2D diffuse4Sampler;\nuniform vec2 diffuse1Infos;\nuniform vec2 diffuse2Infos;\nuniform vec2 diffuse3Infos;\nuniform vec2 diffuse4Infos;\n#ifdef MIXMAP2\nuniform sampler2D diffuse5Sampler;\nuniform sampler2D diffuse6Sampler;\nuniform sampler2D diffuse7Sampler;\nuniform sampler2D diffuse8Sampler;\nuniform vec2 diffuse5Infos;\nuniform vec2 diffuse6Infos;\nuniform vec2 diffuse7Infos;\nuniform vec2 diffuse8Infos;\n#endif\n#endif\n\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 finalMixColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n#ifdef MIXMAP2\nvec4 mixColor2=vec4(1.,1.,1.,1.);\n#endif\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n\nfloat alpha=vDiffuseColor.a;\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n#ifdef DIFFUSE\nvec4 mixColor=texture2D(mixMap1Sampler,vTextureUV);\n#include<depthPrePass>\nmixColor.rgb*=vTextureInfos.y;\nvec4 diffuse1Color=texture2D(diffuse1Sampler,vTextureUV*diffuse1Infos);\nvec4 diffuse2Color=texture2D(diffuse2Sampler,vTextureUV*diffuse2Infos);\nvec4 diffuse3Color=texture2D(diffuse3Sampler,vTextureUV*diffuse3Infos);\nvec4 diffuse4Color=texture2D(diffuse4Sampler,vTextureUV*diffuse4Infos);\ndiffuse1Color.rgb*=mixColor.r;\ndiffuse2Color.rgb=mix(diffuse1Color.rgb,diffuse2Color.rgb,mixColor.g);\ndiffuse3Color.rgb=mix(diffuse2Color.rgb,diffuse3Color.rgb,mixColor.b);\nfinalMixColor.rgb=mix(diffuse3Color.rgb,diffuse4Color.rgb,1.0-mixColor.a);\n#ifdef MIXMAP2\nmixColor=texture2D(mixMap2Sampler,vTextureUV);\nmixColor.rgb*=vTextureInfos.y;\nvec4 diffuse5Color=texture2D(diffuse5Sampler,vTextureUV*diffuse5Infos);\nvec4 diffuse6Color=texture2D(diffuse6Sampler,vTextureUV*diffuse6Infos);\nvec4 diffuse7Color=texture2D(diffuse7Sampler,vTextureUV*diffuse7Infos);\nvec4 diffuse8Color=texture2D(diffuse8Sampler,vTextureUV*diffuse8Infos);\ndiffuse5Color.rgb=mix(finalMixColor.rgb,diffuse5Color.rgb,mixColor.r);\ndiffuse6Color.rgb=mix(diffuse5Color.rgb,diffuse6Color.rgb,mixColor.g);\ndiffuse7Color.rgb=mix(diffuse6Color.rgb,diffuse7Color.rgb,mixColor.b);\nfinalMixColor.rgb=mix(diffuse7Color.rgb,diffuse8Color.rgb,1.0-mixColor.a);\n#endif\n#endif\n#ifdef VERTEXCOLOR\nfinalMixColor.rgb*=vColor.rgb;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor*finalMixColor.rgb,0.0,1.0);\n\nvec4 color=vec4(finalDiffuse+finalSpecular,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}\n";
  172. exports.shader = shader;
  173. babylonjs_1.Effect.ShadersStore[name] = shader;
  174. /***/ }),
  175. /***/ "./src/mix/mix.vertex.ts":
  176. /*!*******************************!*\
  177. !*** ./src/mix/mix.vertex.ts ***!
  178. \*******************************/
  179. /*! no static exports found */
  180. /***/ (function(module, exports, __webpack_require__) {
  181. "use strict";
  182. Object.defineProperty(exports, "__esModule", { value: true });
  183. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  184. var name = 'mixVertexShader';
  185. exports.name = name;
  186. var shader = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vTextureUV;\nuniform mat4 textureMatrix;\nuniform vec2 vTextureInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vTextureInfos.x == 0.)\n{\nvTextureUV=vec2(textureMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvTextureUV=vec2(textureMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  187. exports.shader = shader;
  188. babylonjs_1.Effect.ShadersStore[name] = shader;
  189. /***/ }),
  190. /***/ "./src/mix/mixMaterial.ts":
  191. /*!********************************!*\
  192. !*** ./src/mix/mixMaterial.ts ***!
  193. \********************************/
  194. /*! no static exports found */
  195. /***/ (function(module, exports, __webpack_require__) {
  196. "use strict";
  197. var __extends = (this && this.__extends) || (function () {
  198. var extendStatics = function (d, b) {
  199. extendStatics = Object.setPrototypeOf ||
  200. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  201. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  202. return extendStatics(d, b);
  203. }
  204. return function (d, b) {
  205. extendStatics(d, b);
  206. function __() { this.constructor = d; }
  207. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  208. };
  209. })();
  210. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  211. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  212. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  213. 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;
  214. return c > 3 && r && Object.defineProperty(target, key, r), r;
  215. };
  216. Object.defineProperty(exports, "__esModule", { value: true });
  217. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  218. __webpack_require__(/*! ./mix.fragment */ "./src/mix/mix.fragment.ts");
  219. __webpack_require__(/*! ./mix.vertex */ "./src/mix/mix.vertex.ts");
  220. var MixMaterialDefines = /** @class */ (function (_super) {
  221. __extends(MixMaterialDefines, _super);
  222. function MixMaterialDefines() {
  223. var _this = _super.call(this) || this;
  224. _this.DIFFUSE = false;
  225. _this.CLIPPLANE = false;
  226. _this.CLIPPLANE2 = false;
  227. _this.CLIPPLANE3 = false;
  228. _this.CLIPPLANE4 = false;
  229. _this.ALPHATEST = false;
  230. _this.DEPTHPREPASS = false;
  231. _this.POINTSIZE = false;
  232. _this.FOG = false;
  233. _this.SPECULARTERM = false;
  234. _this.NORMAL = false;
  235. _this.UV1 = false;
  236. _this.UV2 = false;
  237. _this.VERTEXCOLOR = false;
  238. _this.VERTEXALPHA = false;
  239. _this.NUM_BONE_INFLUENCERS = 0;
  240. _this.BonesPerMesh = 0;
  241. _this.INSTANCES = false;
  242. _this.MIXMAP2 = false;
  243. _this.rebuild();
  244. return _this;
  245. }
  246. return MixMaterialDefines;
  247. }(babylonjs_1.MaterialDefines));
  248. var MixMaterial = /** @class */ (function (_super) {
  249. __extends(MixMaterial, _super);
  250. function MixMaterial(name, scene) {
  251. var _this = _super.call(this, name, scene) || this;
  252. /**
  253. * Uniforms
  254. */
  255. _this.diffuseColor = new babylonjs_1.Color3(1, 1, 1);
  256. _this.specularColor = new babylonjs_1.Color3(0, 0, 0);
  257. _this.specularPower = 64;
  258. _this._disableLighting = false;
  259. _this._maxSimultaneousLights = 4;
  260. return _this;
  261. }
  262. MixMaterial.prototype.needAlphaBlending = function () {
  263. return (this.alpha < 1.0);
  264. };
  265. MixMaterial.prototype.needAlphaTesting = function () {
  266. return false;
  267. };
  268. MixMaterial.prototype.getAlphaTestTexture = function () {
  269. return null;
  270. };
  271. // Methods
  272. MixMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  273. if (this.isFrozen) {
  274. if (this._wasPreviouslyReady && subMesh.effect) {
  275. return true;
  276. }
  277. }
  278. if (!subMesh._materialDefines) {
  279. subMesh._materialDefines = new MixMaterialDefines();
  280. }
  281. var defines = subMesh._materialDefines;
  282. var scene = this.getScene();
  283. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  284. if (this._renderId === scene.getRenderId()) {
  285. return true;
  286. }
  287. }
  288. var engine = scene.getEngine();
  289. // Textures
  290. if (scene.texturesEnabled) {
  291. if (babylonjs_1.StandardMaterial.DiffuseTextureEnabled) {
  292. if (this._mixTexture1) {
  293. if (!this._mixTexture1.isReady()) {
  294. return false;
  295. }
  296. else {
  297. defines._needUVs = true;
  298. defines.DIFFUSE = true;
  299. }
  300. }
  301. if (this._mixTexture2) {
  302. if (!this._mixTexture2.isReady()) {
  303. return false;
  304. }
  305. else {
  306. defines.MIXMAP2 = true;
  307. }
  308. }
  309. }
  310. }
  311. // Misc.
  312. babylonjs_1.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  313. // Lights
  314. defines._needNormals = babylonjs_1.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  315. // Values that need to be evaluated on every frame
  316. babylonjs_1.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  317. // Attribs
  318. babylonjs_1.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  319. // Get correct effect
  320. if (defines.isDirty) {
  321. defines.markAsProcessed();
  322. scene.resetCachedMaterial();
  323. // Fallbacks
  324. var fallbacks = new babylonjs_1.EffectFallbacks();
  325. if (defines.FOG) {
  326. fallbacks.addFallback(1, "FOG");
  327. }
  328. babylonjs_1.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  329. if (defines.NUM_BONE_INFLUENCERS > 0) {
  330. fallbacks.addCPUSkinningFallback(0, mesh);
  331. }
  332. //Attributes
  333. var attribs = [babylonjs_1.VertexBuffer.PositionKind];
  334. if (defines.NORMAL) {
  335. attribs.push(babylonjs_1.VertexBuffer.NormalKind);
  336. }
  337. if (defines.UV1) {
  338. attribs.push(babylonjs_1.VertexBuffer.UVKind);
  339. }
  340. if (defines.UV2) {
  341. attribs.push(babylonjs_1.VertexBuffer.UV2Kind);
  342. }
  343. if (defines.VERTEXCOLOR) {
  344. attribs.push(babylonjs_1.VertexBuffer.ColorKind);
  345. }
  346. babylonjs_1.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  347. babylonjs_1.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  348. // Legacy browser patch
  349. var shaderName = "mix";
  350. var join = defines.toString();
  351. var uniforms = [
  352. "world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  353. "vFogInfos", "vFogColor", "pointSize",
  354. "vTextureInfos",
  355. "mBones",
  356. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "textureMatrix",
  357. "diffuse1Infos", "diffuse2Infos", "diffuse3Infos", "diffuse4Infos",
  358. "diffuse5Infos", "diffuse6Infos", "diffuse7Infos", "diffuse8Infos"
  359. ];
  360. var samplers = [
  361. "mixMap1Sampler", "mixMap2Sampler",
  362. "diffuse1Sampler", "diffuse2Sampler", "diffuse3Sampler", "diffuse4Sampler",
  363. "diffuse5Sampler", "diffuse6Sampler", "diffuse7Sampler", "diffuse8Sampler"
  364. ];
  365. var uniformBuffers = new Array();
  366. babylonjs_1.MaterialHelper.PrepareUniformsAndSamplersList({
  367. uniformsNames: uniforms,
  368. uniformBuffersNames: uniformBuffers,
  369. samplers: samplers,
  370. defines: defines,
  371. maxSimultaneousLights: this.maxSimultaneousLights
  372. });
  373. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  374. attributes: attribs,
  375. uniformsNames: uniforms,
  376. uniformBuffersNames: uniformBuffers,
  377. samplers: samplers,
  378. defines: join,
  379. fallbacks: fallbacks,
  380. onCompiled: this.onCompiled,
  381. onError: this.onError,
  382. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  383. }, engine), defines);
  384. }
  385. if (!subMesh.effect || !subMesh.effect.isReady()) {
  386. return false;
  387. }
  388. this._renderId = scene.getRenderId();
  389. this._wasPreviouslyReady = true;
  390. return true;
  391. };
  392. MixMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  393. var scene = this.getScene();
  394. var defines = subMesh._materialDefines;
  395. if (!defines) {
  396. return;
  397. }
  398. var effect = subMesh.effect;
  399. if (!effect) {
  400. return;
  401. }
  402. this._activeEffect = effect;
  403. // Matrices
  404. this.bindOnlyWorldMatrix(world);
  405. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  406. // Bones
  407. babylonjs_1.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  408. if (this._mustRebind(scene, effect)) {
  409. // Textures
  410. if (this._mixTexture1) {
  411. this._activeEffect.setTexture("mixMap1Sampler", this._mixTexture1);
  412. this._activeEffect.setFloat2("vTextureInfos", this._mixTexture1.coordinatesIndex, this._mixTexture1.level);
  413. this._activeEffect.setMatrix("textureMatrix", this._mixTexture1.getTextureMatrix());
  414. if (babylonjs_1.StandardMaterial.DiffuseTextureEnabled) {
  415. if (this._diffuseTexture1) {
  416. this._activeEffect.setTexture("diffuse1Sampler", this._diffuseTexture1);
  417. this._activeEffect.setFloat2("diffuse1Infos", this._diffuseTexture1.uScale, this._diffuseTexture1.vScale);
  418. }
  419. if (this._diffuseTexture2) {
  420. this._activeEffect.setTexture("diffuse2Sampler", this._diffuseTexture2);
  421. this._activeEffect.setFloat2("diffuse2Infos", this._diffuseTexture2.uScale, this._diffuseTexture2.vScale);
  422. }
  423. if (this._diffuseTexture3) {
  424. this._activeEffect.setTexture("diffuse3Sampler", this._diffuseTexture3);
  425. this._activeEffect.setFloat2("diffuse3Infos", this._diffuseTexture3.uScale, this._diffuseTexture3.vScale);
  426. }
  427. if (this._diffuseTexture4) {
  428. this._activeEffect.setTexture("diffuse4Sampler", this._diffuseTexture4);
  429. this._activeEffect.setFloat2("diffuse4Infos", this._diffuseTexture4.uScale, this._diffuseTexture4.vScale);
  430. }
  431. }
  432. }
  433. if (this._mixTexture2) {
  434. this._activeEffect.setTexture("mixMap2Sampler", this._mixTexture2);
  435. if (babylonjs_1.StandardMaterial.DiffuseTextureEnabled) {
  436. if (this._diffuseTexture5) {
  437. this._activeEffect.setTexture("diffuse5Sampler", this._diffuseTexture5);
  438. this._activeEffect.setFloat2("diffuse5Infos", this._diffuseTexture5.uScale, this._diffuseTexture5.vScale);
  439. }
  440. if (this._diffuseTexture6) {
  441. this._activeEffect.setTexture("diffuse6Sampler", this._diffuseTexture6);
  442. this._activeEffect.setFloat2("diffuse6Infos", this._diffuseTexture6.uScale, this._diffuseTexture6.vScale);
  443. }
  444. if (this._diffuseTexture7) {
  445. this._activeEffect.setTexture("diffuse7Sampler", this._diffuseTexture7);
  446. this._activeEffect.setFloat2("diffuse7Infos", this._diffuseTexture7.uScale, this._diffuseTexture7.vScale);
  447. }
  448. if (this._diffuseTexture8) {
  449. this._activeEffect.setTexture("diffuse8Sampler", this._diffuseTexture8);
  450. this._activeEffect.setFloat2("diffuse8Infos", this._diffuseTexture8.uScale, this._diffuseTexture8.vScale);
  451. }
  452. }
  453. }
  454. // Clip plane
  455. babylonjs_1.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  456. // Point size
  457. if (this.pointsCloud) {
  458. this._activeEffect.setFloat("pointSize", this.pointSize);
  459. }
  460. babylonjs_1.MaterialHelper.BindEyePosition(effect, scene);
  461. }
  462. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  463. if (defines.SPECULARTERM) {
  464. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  465. }
  466. if (scene.lightsEnabled && !this.disableLighting) {
  467. babylonjs_1.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  468. }
  469. // View
  470. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== babylonjs_1.Scene.FOGMODE_NONE) {
  471. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  472. }
  473. // Fog
  474. babylonjs_1.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  475. this._afterBind(mesh, this._activeEffect);
  476. };
  477. MixMaterial.prototype.getAnimatables = function () {
  478. var results = [];
  479. if (this._mixTexture1 && this._mixTexture1.animations && this._mixTexture1.animations.length > 0) {
  480. results.push(this._mixTexture1);
  481. }
  482. if (this._mixTexture2 && this._mixTexture2.animations && this._mixTexture2.animations.length > 0) {
  483. results.push(this._mixTexture2);
  484. }
  485. return results;
  486. };
  487. MixMaterial.prototype.getActiveTextures = function () {
  488. var activeTextures = _super.prototype.getActiveTextures.call(this);
  489. // Mix map 1
  490. if (this._mixTexture1) {
  491. activeTextures.push(this._mixTexture1);
  492. }
  493. if (this._diffuseTexture1) {
  494. activeTextures.push(this._diffuseTexture1);
  495. }
  496. if (this._diffuseTexture2) {
  497. activeTextures.push(this._diffuseTexture2);
  498. }
  499. if (this._diffuseTexture3) {
  500. activeTextures.push(this._diffuseTexture3);
  501. }
  502. if (this._diffuseTexture4) {
  503. activeTextures.push(this._diffuseTexture4);
  504. }
  505. // Mix map 2
  506. if (this._mixTexture2) {
  507. activeTextures.push(this._mixTexture2);
  508. }
  509. if (this._diffuseTexture5) {
  510. activeTextures.push(this._diffuseTexture5);
  511. }
  512. if (this._diffuseTexture6) {
  513. activeTextures.push(this._diffuseTexture6);
  514. }
  515. if (this._diffuseTexture7) {
  516. activeTextures.push(this._diffuseTexture7);
  517. }
  518. if (this._diffuseTexture8) {
  519. activeTextures.push(this._diffuseTexture8);
  520. }
  521. return activeTextures;
  522. };
  523. MixMaterial.prototype.hasTexture = function (texture) {
  524. if (_super.prototype.hasTexture.call(this, texture)) {
  525. return true;
  526. }
  527. // Mix map 1
  528. if (this._mixTexture1 === texture) {
  529. return true;
  530. }
  531. if (this._diffuseTexture1 === texture) {
  532. return true;
  533. }
  534. if (this._diffuseTexture2 === texture) {
  535. return true;
  536. }
  537. if (this._diffuseTexture3 === texture) {
  538. return true;
  539. }
  540. if (this._diffuseTexture4 === texture) {
  541. return true;
  542. }
  543. // Mix map 2
  544. if (this._mixTexture2 === texture) {
  545. return true;
  546. }
  547. if (this._diffuseTexture5 === texture) {
  548. return true;
  549. }
  550. if (this._diffuseTexture6 === texture) {
  551. return true;
  552. }
  553. if (this._diffuseTexture7 === texture) {
  554. return true;
  555. }
  556. if (this._diffuseTexture8 === texture) {
  557. return true;
  558. }
  559. return false;
  560. };
  561. MixMaterial.prototype.dispose = function (forceDisposeEffect) {
  562. if (this._mixTexture1) {
  563. this._mixTexture1.dispose();
  564. }
  565. _super.prototype.dispose.call(this, forceDisposeEffect);
  566. };
  567. MixMaterial.prototype.clone = function (name) {
  568. var _this = this;
  569. return babylonjs_1.SerializationHelper.Clone(function () { return new MixMaterial(name, _this.getScene()); }, this);
  570. };
  571. MixMaterial.prototype.serialize = function () {
  572. var serializationObject = babylonjs_1.SerializationHelper.Serialize(this);
  573. serializationObject.customType = "BABYLON.MixMaterial";
  574. return serializationObject;
  575. };
  576. MixMaterial.prototype.getClassName = function () {
  577. return "MixMaterial";
  578. };
  579. // Statics
  580. MixMaterial.Parse = function (source, scene, rootUrl) {
  581. return babylonjs_1.SerializationHelper.Parse(function () { return new MixMaterial(source.name, scene); }, source, scene, rootUrl);
  582. };
  583. __decorate([
  584. babylonjs_1.serializeAsTexture("mixTexture1")
  585. ], MixMaterial.prototype, "_mixTexture1", void 0);
  586. __decorate([
  587. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  588. ], MixMaterial.prototype, "mixTexture1", void 0);
  589. __decorate([
  590. babylonjs_1.serializeAsTexture("mixTexture2")
  591. ], MixMaterial.prototype, "_mixTexture2", void 0);
  592. __decorate([
  593. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  594. ], MixMaterial.prototype, "mixTexture2", void 0);
  595. __decorate([
  596. babylonjs_1.serializeAsTexture("diffuseTexture1")
  597. ], MixMaterial.prototype, "_diffuseTexture1", void 0);
  598. __decorate([
  599. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  600. ], MixMaterial.prototype, "diffuseTexture1", void 0);
  601. __decorate([
  602. babylonjs_1.serializeAsTexture("diffuseTexture2")
  603. ], MixMaterial.prototype, "_diffuseTexture2", void 0);
  604. __decorate([
  605. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  606. ], MixMaterial.prototype, "diffuseTexture2", void 0);
  607. __decorate([
  608. babylonjs_1.serializeAsTexture("diffuseTexture3")
  609. ], MixMaterial.prototype, "_diffuseTexture3", void 0);
  610. __decorate([
  611. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  612. ], MixMaterial.prototype, "diffuseTexture3", void 0);
  613. __decorate([
  614. babylonjs_1.serializeAsTexture("diffuseTexture4")
  615. ], MixMaterial.prototype, "_diffuseTexture4", void 0);
  616. __decorate([
  617. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  618. ], MixMaterial.prototype, "diffuseTexture4", void 0);
  619. __decorate([
  620. babylonjs_1.serializeAsTexture("diffuseTexture1")
  621. ], MixMaterial.prototype, "_diffuseTexture5", void 0);
  622. __decorate([
  623. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  624. ], MixMaterial.prototype, "diffuseTexture5", void 0);
  625. __decorate([
  626. babylonjs_1.serializeAsTexture("diffuseTexture2")
  627. ], MixMaterial.prototype, "_diffuseTexture6", void 0);
  628. __decorate([
  629. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  630. ], MixMaterial.prototype, "diffuseTexture6", void 0);
  631. __decorate([
  632. babylonjs_1.serializeAsTexture("diffuseTexture3")
  633. ], MixMaterial.prototype, "_diffuseTexture7", void 0);
  634. __decorate([
  635. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  636. ], MixMaterial.prototype, "diffuseTexture7", void 0);
  637. __decorate([
  638. babylonjs_1.serializeAsTexture("diffuseTexture4")
  639. ], MixMaterial.prototype, "_diffuseTexture8", void 0);
  640. __decorate([
  641. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  642. ], MixMaterial.prototype, "diffuseTexture8", void 0);
  643. __decorate([
  644. babylonjs_1.serializeAsColor3()
  645. ], MixMaterial.prototype, "diffuseColor", void 0);
  646. __decorate([
  647. babylonjs_1.serializeAsColor3()
  648. ], MixMaterial.prototype, "specularColor", void 0);
  649. __decorate([
  650. babylonjs_1.serialize()
  651. ], MixMaterial.prototype, "specularPower", void 0);
  652. __decorate([
  653. babylonjs_1.serialize("disableLighting")
  654. ], MixMaterial.prototype, "_disableLighting", void 0);
  655. __decorate([
  656. babylonjs_1.expandToProperty("_markAllSubMeshesAsLightsDirty")
  657. ], MixMaterial.prototype, "disableLighting", void 0);
  658. __decorate([
  659. babylonjs_1.serialize("maxSimultaneousLights")
  660. ], MixMaterial.prototype, "_maxSimultaneousLights", void 0);
  661. __decorate([
  662. babylonjs_1.expandToProperty("_markAllSubMeshesAsLightsDirty")
  663. ], MixMaterial.prototype, "maxSimultaneousLights", void 0);
  664. return MixMaterial;
  665. }(babylonjs_1.PushMaterial));
  666. exports.MixMaterial = MixMaterial;
  667. /***/ }),
  668. /***/ "babylonjs":
  669. /*!****************************************************************************************************!*\
  670. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  671. \****************************************************************************************************/
  672. /*! no static exports found */
  673. /***/ (function(module, exports) {
  674. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs__;
  675. /***/ })
  676. /******/ });
  677. });
  678. //# sourceMappingURL=babylon.mixMaterial.js.map