babylon.mixMaterial.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  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.fx":
  161. /*!*********************************!*\
  162. !*** ./src/mix/mix.fragment.fx ***!
  163. \*********************************/
  164. /*! no static exports found */
  165. /***/ (function(module, exports) {
  166. module.exports = "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"
  167. /***/ }),
  168. /***/ "./src/mix/mix.vertex.fx":
  169. /*!*******************************!*\
  170. !*** ./src/mix/mix.vertex.fx ***!
  171. \*******************************/
  172. /*! no static exports found */
  173. /***/ (function(module, exports) {
  174. module.exports = "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"
  175. /***/ }),
  176. /***/ "./src/mix/mixMaterial.ts":
  177. /*!********************************!*\
  178. !*** ./src/mix/mixMaterial.ts ***!
  179. \********************************/
  180. /*! no static exports found */
  181. /***/ (function(module, exports, __webpack_require__) {
  182. "use strict";
  183. var __extends = (this && this.__extends) || (function () {
  184. var extendStatics = function (d, b) {
  185. extendStatics = Object.setPrototypeOf ||
  186. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  187. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  188. return extendStatics(d, b);
  189. }
  190. return function (d, b) {
  191. extendStatics(d, b);
  192. function __() { this.constructor = d; }
  193. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  194. };
  195. })();
  196. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  197. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  198. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  199. 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;
  200. return c > 3 && r && Object.defineProperty(target, key, r), r;
  201. };
  202. Object.defineProperty(exports, "__esModule", { value: true });
  203. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  204. babylonjs_1.Effect.ShadersStore["mixPixelShader"] = __webpack_require__(/*! ./mix.fragment.fx */ "./src/mix/mix.fragment.fx");
  205. babylonjs_1.Effect.ShadersStore["mixVertexShader"] = __webpack_require__(/*! ./mix.vertex.fx */ "./src/mix/mix.vertex.fx");
  206. var MixMaterialDefines = /** @class */ (function (_super) {
  207. __extends(MixMaterialDefines, _super);
  208. function MixMaterialDefines() {
  209. var _this = _super.call(this) || this;
  210. _this.DIFFUSE = false;
  211. _this.CLIPPLANE = false;
  212. _this.CLIPPLANE2 = false;
  213. _this.CLIPPLANE3 = false;
  214. _this.CLIPPLANE4 = false;
  215. _this.ALPHATEST = false;
  216. _this.DEPTHPREPASS = false;
  217. _this.POINTSIZE = false;
  218. _this.FOG = false;
  219. _this.SPECULARTERM = false;
  220. _this.NORMAL = false;
  221. _this.UV1 = false;
  222. _this.UV2 = false;
  223. _this.VERTEXCOLOR = false;
  224. _this.VERTEXALPHA = false;
  225. _this.NUM_BONE_INFLUENCERS = 0;
  226. _this.BonesPerMesh = 0;
  227. _this.INSTANCES = false;
  228. _this.MIXMAP2 = false;
  229. _this.rebuild();
  230. return _this;
  231. }
  232. return MixMaterialDefines;
  233. }(babylonjs_1.MaterialDefines));
  234. var MixMaterial = /** @class */ (function (_super) {
  235. __extends(MixMaterial, _super);
  236. function MixMaterial(name, scene) {
  237. var _this = _super.call(this, name, scene) || this;
  238. /**
  239. * Uniforms
  240. */
  241. _this.diffuseColor = new babylonjs_1.Color3(1, 1, 1);
  242. _this.specularColor = new babylonjs_1.Color3(0, 0, 0);
  243. _this.specularPower = 64;
  244. _this._disableLighting = false;
  245. _this._maxSimultaneousLights = 4;
  246. return _this;
  247. }
  248. MixMaterial.prototype.needAlphaBlending = function () {
  249. return (this.alpha < 1.0);
  250. };
  251. MixMaterial.prototype.needAlphaTesting = function () {
  252. return false;
  253. };
  254. MixMaterial.prototype.getAlphaTestTexture = function () {
  255. return null;
  256. };
  257. // Methods
  258. MixMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  259. if (this.isFrozen) {
  260. if (this._wasPreviouslyReady && subMesh.effect) {
  261. return true;
  262. }
  263. }
  264. if (!subMesh._materialDefines) {
  265. subMesh._materialDefines = new MixMaterialDefines();
  266. }
  267. var defines = subMesh._materialDefines;
  268. var scene = this.getScene();
  269. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  270. if (this._renderId === scene.getRenderId()) {
  271. return true;
  272. }
  273. }
  274. var engine = scene.getEngine();
  275. // Textures
  276. if (scene.texturesEnabled) {
  277. if (babylonjs_1.StandardMaterial.DiffuseTextureEnabled) {
  278. if (this._mixTexture1) {
  279. if (!this._mixTexture1.isReady()) {
  280. return false;
  281. }
  282. else {
  283. defines._needUVs = true;
  284. defines.DIFFUSE = true;
  285. }
  286. }
  287. if (this._mixTexture2) {
  288. if (!this._mixTexture2.isReady()) {
  289. return false;
  290. }
  291. else {
  292. defines.MIXMAP2 = true;
  293. }
  294. }
  295. }
  296. }
  297. // Misc.
  298. babylonjs_1.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  299. // Lights
  300. defines._needNormals = babylonjs_1.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  301. // Values that need to be evaluated on every frame
  302. babylonjs_1.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  303. // Attribs
  304. babylonjs_1.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  305. // Get correct effect
  306. if (defines.isDirty) {
  307. defines.markAsProcessed();
  308. scene.resetCachedMaterial();
  309. // Fallbacks
  310. var fallbacks = new babylonjs_1.EffectFallbacks();
  311. if (defines.FOG) {
  312. fallbacks.addFallback(1, "FOG");
  313. }
  314. babylonjs_1.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  315. if (defines.NUM_BONE_INFLUENCERS > 0) {
  316. fallbacks.addCPUSkinningFallback(0, mesh);
  317. }
  318. //Attributes
  319. var attribs = [babylonjs_1.VertexBuffer.PositionKind];
  320. if (defines.NORMAL) {
  321. attribs.push(babylonjs_1.VertexBuffer.NormalKind);
  322. }
  323. if (defines.UV1) {
  324. attribs.push(babylonjs_1.VertexBuffer.UVKind);
  325. }
  326. if (defines.UV2) {
  327. attribs.push(babylonjs_1.VertexBuffer.UV2Kind);
  328. }
  329. if (defines.VERTEXCOLOR) {
  330. attribs.push(babylonjs_1.VertexBuffer.ColorKind);
  331. }
  332. babylonjs_1.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  333. babylonjs_1.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  334. // Legacy browser patch
  335. var shaderName = "mix";
  336. var join = defines.toString();
  337. var uniforms = [
  338. "world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  339. "vFogInfos", "vFogColor", "pointSize",
  340. "vTextureInfos",
  341. "mBones",
  342. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "textureMatrix",
  343. "diffuse1Infos", "diffuse2Infos", "diffuse3Infos", "diffuse4Infos",
  344. "diffuse5Infos", "diffuse6Infos", "diffuse7Infos", "diffuse8Infos"
  345. ];
  346. var samplers = [
  347. "mixMap1Sampler", "mixMap2Sampler",
  348. "diffuse1Sampler", "diffuse2Sampler", "diffuse3Sampler", "diffuse4Sampler",
  349. "diffuse5Sampler", "diffuse6Sampler", "diffuse7Sampler", "diffuse8Sampler"
  350. ];
  351. var uniformBuffers = new Array();
  352. babylonjs_1.MaterialHelper.PrepareUniformsAndSamplersList({
  353. uniformsNames: uniforms,
  354. uniformBuffersNames: uniformBuffers,
  355. samplers: samplers,
  356. defines: defines,
  357. maxSimultaneousLights: this.maxSimultaneousLights
  358. });
  359. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  360. attributes: attribs,
  361. uniformsNames: uniforms,
  362. uniformBuffersNames: uniformBuffers,
  363. samplers: samplers,
  364. defines: join,
  365. fallbacks: fallbacks,
  366. onCompiled: this.onCompiled,
  367. onError: this.onError,
  368. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  369. }, engine), defines);
  370. }
  371. if (!subMesh.effect || !subMesh.effect.isReady()) {
  372. return false;
  373. }
  374. this._renderId = scene.getRenderId();
  375. this._wasPreviouslyReady = true;
  376. return true;
  377. };
  378. MixMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  379. var scene = this.getScene();
  380. var defines = subMesh._materialDefines;
  381. if (!defines) {
  382. return;
  383. }
  384. var effect = subMesh.effect;
  385. if (!effect) {
  386. return;
  387. }
  388. this._activeEffect = effect;
  389. // Matrices
  390. this.bindOnlyWorldMatrix(world);
  391. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  392. // Bones
  393. babylonjs_1.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  394. if (this._mustRebind(scene, effect)) {
  395. // Textures
  396. if (this._mixTexture1) {
  397. this._activeEffect.setTexture("mixMap1Sampler", this._mixTexture1);
  398. this._activeEffect.setFloat2("vTextureInfos", this._mixTexture1.coordinatesIndex, this._mixTexture1.level);
  399. this._activeEffect.setMatrix("textureMatrix", this._mixTexture1.getTextureMatrix());
  400. if (babylonjs_1.StandardMaterial.DiffuseTextureEnabled) {
  401. if (this._diffuseTexture1) {
  402. this._activeEffect.setTexture("diffuse1Sampler", this._diffuseTexture1);
  403. this._activeEffect.setFloat2("diffuse1Infos", this._diffuseTexture1.uScale, this._diffuseTexture1.vScale);
  404. }
  405. if (this._diffuseTexture2) {
  406. this._activeEffect.setTexture("diffuse2Sampler", this._diffuseTexture2);
  407. this._activeEffect.setFloat2("diffuse2Infos", this._diffuseTexture2.uScale, this._diffuseTexture2.vScale);
  408. }
  409. if (this._diffuseTexture3) {
  410. this._activeEffect.setTexture("diffuse3Sampler", this._diffuseTexture3);
  411. this._activeEffect.setFloat2("diffuse3Infos", this._diffuseTexture3.uScale, this._diffuseTexture3.vScale);
  412. }
  413. if (this._diffuseTexture4) {
  414. this._activeEffect.setTexture("diffuse4Sampler", this._diffuseTexture4);
  415. this._activeEffect.setFloat2("diffuse4Infos", this._diffuseTexture4.uScale, this._diffuseTexture4.vScale);
  416. }
  417. }
  418. }
  419. if (this._mixTexture2) {
  420. this._activeEffect.setTexture("mixMap2Sampler", this._mixTexture2);
  421. if (babylonjs_1.StandardMaterial.DiffuseTextureEnabled) {
  422. if (this._diffuseTexture5) {
  423. this._activeEffect.setTexture("diffuse5Sampler", this._diffuseTexture5);
  424. this._activeEffect.setFloat2("diffuse5Infos", this._diffuseTexture5.uScale, this._diffuseTexture5.vScale);
  425. }
  426. if (this._diffuseTexture6) {
  427. this._activeEffect.setTexture("diffuse6Sampler", this._diffuseTexture6);
  428. this._activeEffect.setFloat2("diffuse6Infos", this._diffuseTexture6.uScale, this._diffuseTexture6.vScale);
  429. }
  430. if (this._diffuseTexture7) {
  431. this._activeEffect.setTexture("diffuse7Sampler", this._diffuseTexture7);
  432. this._activeEffect.setFloat2("diffuse7Infos", this._diffuseTexture7.uScale, this._diffuseTexture7.vScale);
  433. }
  434. if (this._diffuseTexture8) {
  435. this._activeEffect.setTexture("diffuse8Sampler", this._diffuseTexture8);
  436. this._activeEffect.setFloat2("diffuse8Infos", this._diffuseTexture8.uScale, this._diffuseTexture8.vScale);
  437. }
  438. }
  439. }
  440. // Clip plane
  441. babylonjs_1.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  442. // Point size
  443. if (this.pointsCloud) {
  444. this._activeEffect.setFloat("pointSize", this.pointSize);
  445. }
  446. babylonjs_1.MaterialHelper.BindEyePosition(effect, scene);
  447. }
  448. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  449. if (defines.SPECULARTERM) {
  450. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  451. }
  452. if (scene.lightsEnabled && !this.disableLighting) {
  453. babylonjs_1.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  454. }
  455. // View
  456. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== babylonjs_1.Scene.FOGMODE_NONE) {
  457. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  458. }
  459. // Fog
  460. babylonjs_1.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  461. this._afterBind(mesh, this._activeEffect);
  462. };
  463. MixMaterial.prototype.getAnimatables = function () {
  464. var results = [];
  465. if (this._mixTexture1 && this._mixTexture1.animations && this._mixTexture1.animations.length > 0) {
  466. results.push(this._mixTexture1);
  467. }
  468. if (this._mixTexture2 && this._mixTexture2.animations && this._mixTexture2.animations.length > 0) {
  469. results.push(this._mixTexture2);
  470. }
  471. return results;
  472. };
  473. MixMaterial.prototype.getActiveTextures = function () {
  474. var activeTextures = _super.prototype.getActiveTextures.call(this);
  475. // Mix map 1
  476. if (this._mixTexture1) {
  477. activeTextures.push(this._mixTexture1);
  478. }
  479. if (this._diffuseTexture1) {
  480. activeTextures.push(this._diffuseTexture1);
  481. }
  482. if (this._diffuseTexture2) {
  483. activeTextures.push(this._diffuseTexture2);
  484. }
  485. if (this._diffuseTexture3) {
  486. activeTextures.push(this._diffuseTexture3);
  487. }
  488. if (this._diffuseTexture4) {
  489. activeTextures.push(this._diffuseTexture4);
  490. }
  491. // Mix map 2
  492. if (this._mixTexture2) {
  493. activeTextures.push(this._mixTexture2);
  494. }
  495. if (this._diffuseTexture5) {
  496. activeTextures.push(this._diffuseTexture5);
  497. }
  498. if (this._diffuseTexture6) {
  499. activeTextures.push(this._diffuseTexture6);
  500. }
  501. if (this._diffuseTexture7) {
  502. activeTextures.push(this._diffuseTexture7);
  503. }
  504. if (this._diffuseTexture8) {
  505. activeTextures.push(this._diffuseTexture8);
  506. }
  507. return activeTextures;
  508. };
  509. MixMaterial.prototype.hasTexture = function (texture) {
  510. if (_super.prototype.hasTexture.call(this, texture)) {
  511. return true;
  512. }
  513. // Mix map 1
  514. if (this._mixTexture1 === texture) {
  515. return true;
  516. }
  517. if (this._diffuseTexture1 === texture) {
  518. return true;
  519. }
  520. if (this._diffuseTexture2 === texture) {
  521. return true;
  522. }
  523. if (this._diffuseTexture3 === texture) {
  524. return true;
  525. }
  526. if (this._diffuseTexture4 === texture) {
  527. return true;
  528. }
  529. // Mix map 2
  530. if (this._mixTexture2 === texture) {
  531. return true;
  532. }
  533. if (this._diffuseTexture5 === texture) {
  534. return true;
  535. }
  536. if (this._diffuseTexture6 === texture) {
  537. return true;
  538. }
  539. if (this._diffuseTexture7 === texture) {
  540. return true;
  541. }
  542. if (this._diffuseTexture8 === texture) {
  543. return true;
  544. }
  545. return false;
  546. };
  547. MixMaterial.prototype.dispose = function (forceDisposeEffect) {
  548. if (this._mixTexture1) {
  549. this._mixTexture1.dispose();
  550. }
  551. _super.prototype.dispose.call(this, forceDisposeEffect);
  552. };
  553. MixMaterial.prototype.clone = function (name) {
  554. var _this = this;
  555. return babylonjs_1.SerializationHelper.Clone(function () { return new MixMaterial(name, _this.getScene()); }, this);
  556. };
  557. MixMaterial.prototype.serialize = function () {
  558. var serializationObject = babylonjs_1.SerializationHelper.Serialize(this);
  559. serializationObject.customType = "BABYLON.MixMaterial";
  560. return serializationObject;
  561. };
  562. MixMaterial.prototype.getClassName = function () {
  563. return "MixMaterial";
  564. };
  565. // Statics
  566. MixMaterial.Parse = function (source, scene, rootUrl) {
  567. return babylonjs_1.SerializationHelper.Parse(function () { return new MixMaterial(source.name, scene); }, source, scene, rootUrl);
  568. };
  569. __decorate([
  570. babylonjs_1.serializeAsTexture("mixTexture1")
  571. ], MixMaterial.prototype, "_mixTexture1", void 0);
  572. __decorate([
  573. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  574. ], MixMaterial.prototype, "mixTexture1", void 0);
  575. __decorate([
  576. babylonjs_1.serializeAsTexture("mixTexture2")
  577. ], MixMaterial.prototype, "_mixTexture2", void 0);
  578. __decorate([
  579. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  580. ], MixMaterial.prototype, "mixTexture2", void 0);
  581. __decorate([
  582. babylonjs_1.serializeAsTexture("diffuseTexture1")
  583. ], MixMaterial.prototype, "_diffuseTexture1", void 0);
  584. __decorate([
  585. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  586. ], MixMaterial.prototype, "diffuseTexture1", void 0);
  587. __decorate([
  588. babylonjs_1.serializeAsTexture("diffuseTexture2")
  589. ], MixMaterial.prototype, "_diffuseTexture2", void 0);
  590. __decorate([
  591. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  592. ], MixMaterial.prototype, "diffuseTexture2", void 0);
  593. __decorate([
  594. babylonjs_1.serializeAsTexture("diffuseTexture3")
  595. ], MixMaterial.prototype, "_diffuseTexture3", void 0);
  596. __decorate([
  597. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  598. ], MixMaterial.prototype, "diffuseTexture3", void 0);
  599. __decorate([
  600. babylonjs_1.serializeAsTexture("diffuseTexture4")
  601. ], MixMaterial.prototype, "_diffuseTexture4", void 0);
  602. __decorate([
  603. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  604. ], MixMaterial.prototype, "diffuseTexture4", void 0);
  605. __decorate([
  606. babylonjs_1.serializeAsTexture("diffuseTexture1")
  607. ], MixMaterial.prototype, "_diffuseTexture5", void 0);
  608. __decorate([
  609. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  610. ], MixMaterial.prototype, "diffuseTexture5", void 0);
  611. __decorate([
  612. babylonjs_1.serializeAsTexture("diffuseTexture2")
  613. ], MixMaterial.prototype, "_diffuseTexture6", void 0);
  614. __decorate([
  615. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  616. ], MixMaterial.prototype, "diffuseTexture6", void 0);
  617. __decorate([
  618. babylonjs_1.serializeAsTexture("diffuseTexture3")
  619. ], MixMaterial.prototype, "_diffuseTexture7", void 0);
  620. __decorate([
  621. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  622. ], MixMaterial.prototype, "diffuseTexture7", void 0);
  623. __decorate([
  624. babylonjs_1.serializeAsTexture("diffuseTexture4")
  625. ], MixMaterial.prototype, "_diffuseTexture8", void 0);
  626. __decorate([
  627. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  628. ], MixMaterial.prototype, "diffuseTexture8", void 0);
  629. __decorate([
  630. babylonjs_1.serializeAsColor3()
  631. ], MixMaterial.prototype, "diffuseColor", void 0);
  632. __decorate([
  633. babylonjs_1.serializeAsColor3()
  634. ], MixMaterial.prototype, "specularColor", void 0);
  635. __decorate([
  636. babylonjs_1.serialize()
  637. ], MixMaterial.prototype, "specularPower", void 0);
  638. __decorate([
  639. babylonjs_1.serialize("disableLighting")
  640. ], MixMaterial.prototype, "_disableLighting", void 0);
  641. __decorate([
  642. babylonjs_1.expandToProperty("_markAllSubMeshesAsLightsDirty")
  643. ], MixMaterial.prototype, "disableLighting", void 0);
  644. __decorate([
  645. babylonjs_1.serialize("maxSimultaneousLights")
  646. ], MixMaterial.prototype, "_maxSimultaneousLights", void 0);
  647. __decorate([
  648. babylonjs_1.expandToProperty("_markAllSubMeshesAsLightsDirty")
  649. ], MixMaterial.prototype, "maxSimultaneousLights", void 0);
  650. return MixMaterial;
  651. }(babylonjs_1.PushMaterial));
  652. exports.MixMaterial = MixMaterial;
  653. /***/ }),
  654. /***/ "babylonjs":
  655. /*!****************************************************************************************************!*\
  656. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  657. \****************************************************************************************************/
  658. /*! no static exports found */
  659. /***/ (function(module, exports) {
  660. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs__;
  661. /***/ })
  662. /******/ });
  663. });
  664. //# sourceMappingURL=babylon.mixMaterial.js.map