babylon.terrainMaterial.min.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  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-terrain.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../Tools/Gulp/node_modules/webpack/buildin/global.js":
  99. /*!************************************************************!*\
  100. !*** ../Tools/Gulp/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-terrain.ts":
  122. /*!**********************************!*\
  123. !*** ./legacy/legacy-terrain.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/terrain */ "./src/terrain/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/terrain */ "./src/terrain/index.ts"));
  145. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../Tools/Gulp/node_modules/webpack/buildin/global.js */ "../Tools/Gulp/node_modules/webpack/buildin/global.js")))
  146. /***/ }),
  147. /***/ "./src/terrain/index.ts":
  148. /*!******************************!*\
  149. !*** ./src/terrain/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__(/*! ./terrainMaterial */ "./src/terrain/terrainMaterial.ts"));
  159. /***/ }),
  160. /***/ "./src/terrain/terrain.fragment.fx":
  161. /*!*****************************************!*\
  162. !*** ./src/terrain/terrain.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 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#include<clipPlaneFragment>\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"
  167. /***/ }),
  168. /***/ "./src/terrain/terrain.vertex.fx":
  169. /*!***************************************!*\
  170. !*** ./src/terrain/terrain.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/terrain/terrainMaterial.ts":
  177. /*!****************************************!*\
  178. !*** ./src/terrain/terrainMaterial.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["terrainPixelShader"] = __webpack_require__(/*! ./terrain.fragment.fx */ "./src/terrain/terrain.fragment.fx");
  205. babylonjs_1.Effect.ShadersStore["terrainVertexShader"] = __webpack_require__(/*! ./terrain.vertex.fx */ "./src/terrain/terrain.vertex.fx");
  206. var TerrainMaterialDefines = /** @class */ (function (_super) {
  207. __extends(TerrainMaterialDefines, _super);
  208. function TerrainMaterialDefines() {
  209. var _this = _super.call(this) || this;
  210. _this.DIFFUSE = false;
  211. _this.BUMP = false;
  212. _this.CLIPPLANE = false;
  213. _this.CLIPPLANE2 = false;
  214. _this.CLIPPLANE3 = false;
  215. _this.CLIPPLANE4 = false;
  216. _this.ALPHATEST = false;
  217. _this.DEPTHPREPASS = false;
  218. _this.POINTSIZE = false;
  219. _this.FOG = false;
  220. _this.SPECULARTERM = false;
  221. _this.NORMAL = false;
  222. _this.UV1 = false;
  223. _this.UV2 = false;
  224. _this.VERTEXCOLOR = false;
  225. _this.VERTEXALPHA = false;
  226. _this.NUM_BONE_INFLUENCERS = 0;
  227. _this.BonesPerMesh = 0;
  228. _this.INSTANCES = false;
  229. _this.rebuild();
  230. return _this;
  231. }
  232. return TerrainMaterialDefines;
  233. }(babylonjs_1.MaterialDefines));
  234. var TerrainMaterial = /** @class */ (function (_super) {
  235. __extends(TerrainMaterial, _super);
  236. function TerrainMaterial(name, scene) {
  237. var _this = _super.call(this, name, scene) || this;
  238. _this.diffuseColor = new babylonjs_1.Color3(1, 1, 1);
  239. _this.specularColor = new babylonjs_1.Color3(0, 0, 0);
  240. _this.specularPower = 64;
  241. _this._disableLighting = false;
  242. _this._maxSimultaneousLights = 4;
  243. return _this;
  244. }
  245. TerrainMaterial.prototype.needAlphaBlending = function () {
  246. return (this.alpha < 1.0);
  247. };
  248. TerrainMaterial.prototype.needAlphaTesting = function () {
  249. return false;
  250. };
  251. TerrainMaterial.prototype.getAlphaTestTexture = function () {
  252. return null;
  253. };
  254. // Methods
  255. TerrainMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  256. if (this.isFrozen) {
  257. if (this._wasPreviouslyReady && subMesh.effect) {
  258. return true;
  259. }
  260. }
  261. if (!subMesh._materialDefines) {
  262. subMesh._materialDefines = new TerrainMaterialDefines();
  263. }
  264. var defines = subMesh._materialDefines;
  265. var scene = this.getScene();
  266. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  267. if (this._renderId === scene.getRenderId()) {
  268. return true;
  269. }
  270. }
  271. var engine = scene.getEngine();
  272. // Textures
  273. if (scene.texturesEnabled) {
  274. if (this.mixTexture && babylonjs_1.StandardMaterial.DiffuseTextureEnabled) {
  275. if (!this.mixTexture.isReady()) {
  276. return false;
  277. }
  278. else {
  279. defines._needUVs = true;
  280. defines.DIFFUSE = true;
  281. }
  282. }
  283. if ((this.bumpTexture1 || this.bumpTexture2 || this.bumpTexture3) && babylonjs_1.StandardMaterial.BumpTextureEnabled) {
  284. defines._needUVs = true;
  285. defines._needNormals = true;
  286. defines.BUMP = true;
  287. }
  288. }
  289. // Misc.
  290. babylonjs_1.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  291. // Lights
  292. defines._needNormals = babylonjs_1.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  293. // Values that need to be evaluated on every frame
  294. babylonjs_1.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  295. // Attribs
  296. babylonjs_1.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  297. // Get correct effect
  298. if (defines.isDirty) {
  299. defines.markAsProcessed();
  300. scene.resetCachedMaterial();
  301. // Fallbacks
  302. var fallbacks = new babylonjs_1.EffectFallbacks();
  303. if (defines.FOG) {
  304. fallbacks.addFallback(1, "FOG");
  305. }
  306. babylonjs_1.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  307. if (defines.NUM_BONE_INFLUENCERS > 0) {
  308. fallbacks.addCPUSkinningFallback(0, mesh);
  309. }
  310. //Attributes
  311. var attribs = [babylonjs_1.VertexBuffer.PositionKind];
  312. if (defines.NORMAL) {
  313. attribs.push(babylonjs_1.VertexBuffer.NormalKind);
  314. }
  315. if (defines.UV1) {
  316. attribs.push(babylonjs_1.VertexBuffer.UVKind);
  317. }
  318. if (defines.UV2) {
  319. attribs.push(babylonjs_1.VertexBuffer.UV2Kind);
  320. }
  321. if (defines.VERTEXCOLOR) {
  322. attribs.push(babylonjs_1.VertexBuffer.ColorKind);
  323. }
  324. babylonjs_1.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  325. babylonjs_1.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  326. // Legacy browser patch
  327. var shaderName = "terrain";
  328. var join = defines.toString();
  329. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  330. "vFogInfos", "vFogColor", "pointSize",
  331. "vTextureInfos",
  332. "mBones",
  333. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "textureMatrix",
  334. "diffuse1Infos", "diffuse2Infos", "diffuse3Infos"
  335. ];
  336. var samplers = ["textureSampler", "diffuse1Sampler", "diffuse2Sampler", "diffuse3Sampler",
  337. "bump1Sampler", "bump2Sampler", "bump3Sampler"
  338. ];
  339. var uniformBuffers = new Array();
  340. babylonjs_1.MaterialHelper.PrepareUniformsAndSamplersList({
  341. uniformsNames: uniforms,
  342. uniformBuffersNames: uniformBuffers,
  343. samplers: samplers,
  344. defines: defines,
  345. maxSimultaneousLights: this.maxSimultaneousLights
  346. });
  347. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  348. attributes: attribs,
  349. uniformsNames: uniforms,
  350. uniformBuffersNames: uniformBuffers,
  351. samplers: samplers,
  352. defines: join,
  353. fallbacks: fallbacks,
  354. onCompiled: this.onCompiled,
  355. onError: this.onError,
  356. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  357. }, engine), defines);
  358. }
  359. if (!subMesh.effect || !subMesh.effect.isReady()) {
  360. return false;
  361. }
  362. this._renderId = scene.getRenderId();
  363. this._wasPreviouslyReady = true;
  364. return true;
  365. };
  366. TerrainMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  367. var scene = this.getScene();
  368. var defines = subMesh._materialDefines;
  369. if (!defines) {
  370. return;
  371. }
  372. var effect = subMesh.effect;
  373. if (!effect) {
  374. return;
  375. }
  376. this._activeEffect = effect;
  377. // Matrices
  378. this.bindOnlyWorldMatrix(world);
  379. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  380. // Bones
  381. babylonjs_1.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  382. if (this._mustRebind(scene, effect)) {
  383. // Textures
  384. if (this.mixTexture) {
  385. this._activeEffect.setTexture("textureSampler", this._mixTexture);
  386. this._activeEffect.setFloat2("vTextureInfos", this._mixTexture.coordinatesIndex, this._mixTexture.level);
  387. this._activeEffect.setMatrix("textureMatrix", this._mixTexture.getTextureMatrix());
  388. if (babylonjs_1.StandardMaterial.DiffuseTextureEnabled) {
  389. if (this._diffuseTexture1) {
  390. this._activeEffect.setTexture("diffuse1Sampler", this._diffuseTexture1);
  391. this._activeEffect.setFloat2("diffuse1Infos", this._diffuseTexture1.uScale, this._diffuseTexture1.vScale);
  392. }
  393. if (this._diffuseTexture2) {
  394. this._activeEffect.setTexture("diffuse2Sampler", this._diffuseTexture2);
  395. this._activeEffect.setFloat2("diffuse2Infos", this._diffuseTexture2.uScale, this._diffuseTexture2.vScale);
  396. }
  397. if (this._diffuseTexture3) {
  398. this._activeEffect.setTexture("diffuse3Sampler", this._diffuseTexture3);
  399. this._activeEffect.setFloat2("diffuse3Infos", this._diffuseTexture3.uScale, this._diffuseTexture3.vScale);
  400. }
  401. }
  402. if (babylonjs_1.StandardMaterial.BumpTextureEnabled && scene.getEngine().getCaps().standardDerivatives) {
  403. if (this._bumpTexture1) {
  404. this._activeEffect.setTexture("bump1Sampler", this._bumpTexture1);
  405. }
  406. if (this._bumpTexture2) {
  407. this._activeEffect.setTexture("bump2Sampler", this._bumpTexture2);
  408. }
  409. if (this._bumpTexture3) {
  410. this._activeEffect.setTexture("bump3Sampler", this._bumpTexture3);
  411. }
  412. }
  413. }
  414. // Clip plane
  415. babylonjs_1.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  416. // Point size
  417. if (this.pointsCloud) {
  418. this._activeEffect.setFloat("pointSize", this.pointSize);
  419. }
  420. babylonjs_1.MaterialHelper.BindEyePosition(effect, scene);
  421. }
  422. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  423. if (defines.SPECULARTERM) {
  424. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  425. }
  426. if (scene.lightsEnabled && !this.disableLighting) {
  427. babylonjs_1.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  428. }
  429. // View
  430. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== babylonjs_1.Scene.FOGMODE_NONE) {
  431. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  432. }
  433. // Fog
  434. babylonjs_1.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  435. this._afterBind(mesh, this._activeEffect);
  436. };
  437. TerrainMaterial.prototype.getAnimatables = function () {
  438. var results = [];
  439. if (this.mixTexture && this.mixTexture.animations && this.mixTexture.animations.length > 0) {
  440. results.push(this.mixTexture);
  441. }
  442. return results;
  443. };
  444. TerrainMaterial.prototype.getActiveTextures = function () {
  445. var activeTextures = _super.prototype.getActiveTextures.call(this);
  446. if (this._mixTexture) {
  447. activeTextures.push(this._mixTexture);
  448. }
  449. if (this._diffuseTexture1) {
  450. activeTextures.push(this._diffuseTexture1);
  451. }
  452. if (this._diffuseTexture2) {
  453. activeTextures.push(this._diffuseTexture2);
  454. }
  455. if (this._diffuseTexture3) {
  456. activeTextures.push(this._diffuseTexture3);
  457. }
  458. if (this._bumpTexture1) {
  459. activeTextures.push(this._bumpTexture1);
  460. }
  461. if (this._bumpTexture2) {
  462. activeTextures.push(this._bumpTexture2);
  463. }
  464. if (this._bumpTexture3) {
  465. activeTextures.push(this._bumpTexture3);
  466. }
  467. return activeTextures;
  468. };
  469. TerrainMaterial.prototype.hasTexture = function (texture) {
  470. if (_super.prototype.hasTexture.call(this, texture)) {
  471. return true;
  472. }
  473. if (this._mixTexture === texture) {
  474. return true;
  475. }
  476. if (this._diffuseTexture1 === texture) {
  477. return true;
  478. }
  479. if (this._diffuseTexture2 === texture) {
  480. return true;
  481. }
  482. if (this._diffuseTexture3 === texture) {
  483. return true;
  484. }
  485. if (this._bumpTexture1 === texture) {
  486. return true;
  487. }
  488. if (this._bumpTexture2 === texture) {
  489. return true;
  490. }
  491. if (this._bumpTexture3 === texture) {
  492. return true;
  493. }
  494. return false;
  495. };
  496. TerrainMaterial.prototype.dispose = function (forceDisposeEffect) {
  497. if (this.mixTexture) {
  498. this.mixTexture.dispose();
  499. }
  500. _super.prototype.dispose.call(this, forceDisposeEffect);
  501. };
  502. TerrainMaterial.prototype.clone = function (name) {
  503. var _this = this;
  504. return babylonjs_1.SerializationHelper.Clone(function () { return new TerrainMaterial(name, _this.getScene()); }, this);
  505. };
  506. TerrainMaterial.prototype.serialize = function () {
  507. var serializationObject = babylonjs_1.SerializationHelper.Serialize(this);
  508. serializationObject.customType = "BABYLON.TerrainMaterial";
  509. return serializationObject;
  510. };
  511. TerrainMaterial.prototype.getClassName = function () {
  512. return "TerrainMaterial";
  513. };
  514. // Statics
  515. TerrainMaterial.Parse = function (source, scene, rootUrl) {
  516. return babylonjs_1.SerializationHelper.Parse(function () { return new TerrainMaterial(source.name, scene); }, source, scene, rootUrl);
  517. };
  518. __decorate([
  519. babylonjs_1.serializeAsTexture("mixTexture")
  520. ], TerrainMaterial.prototype, "_mixTexture", void 0);
  521. __decorate([
  522. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  523. ], TerrainMaterial.prototype, "mixTexture", void 0);
  524. __decorate([
  525. babylonjs_1.serializeAsTexture("diffuseTexture1")
  526. ], TerrainMaterial.prototype, "_diffuseTexture1", void 0);
  527. __decorate([
  528. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  529. ], TerrainMaterial.prototype, "diffuseTexture1", void 0);
  530. __decorate([
  531. babylonjs_1.serializeAsTexture("diffuseTexture2")
  532. ], TerrainMaterial.prototype, "_diffuseTexture2", void 0);
  533. __decorate([
  534. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  535. ], TerrainMaterial.prototype, "diffuseTexture2", void 0);
  536. __decorate([
  537. babylonjs_1.serializeAsTexture("diffuseTexture3")
  538. ], TerrainMaterial.prototype, "_diffuseTexture3", void 0);
  539. __decorate([
  540. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  541. ], TerrainMaterial.prototype, "diffuseTexture3", void 0);
  542. __decorate([
  543. babylonjs_1.serializeAsTexture("bumpTexture1")
  544. ], TerrainMaterial.prototype, "_bumpTexture1", void 0);
  545. __decorate([
  546. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  547. ], TerrainMaterial.prototype, "bumpTexture1", void 0);
  548. __decorate([
  549. babylonjs_1.serializeAsTexture("bumpTexture2")
  550. ], TerrainMaterial.prototype, "_bumpTexture2", void 0);
  551. __decorate([
  552. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  553. ], TerrainMaterial.prototype, "bumpTexture2", void 0);
  554. __decorate([
  555. babylonjs_1.serializeAsTexture("bumpTexture3")
  556. ], TerrainMaterial.prototype, "_bumpTexture3", void 0);
  557. __decorate([
  558. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  559. ], TerrainMaterial.prototype, "bumpTexture3", void 0);
  560. __decorate([
  561. babylonjs_1.serializeAsColor3()
  562. ], TerrainMaterial.prototype, "diffuseColor", void 0);
  563. __decorate([
  564. babylonjs_1.serializeAsColor3()
  565. ], TerrainMaterial.prototype, "specularColor", void 0);
  566. __decorate([
  567. babylonjs_1.serialize()
  568. ], TerrainMaterial.prototype, "specularPower", void 0);
  569. __decorate([
  570. babylonjs_1.serialize("disableLighting")
  571. ], TerrainMaterial.prototype, "_disableLighting", void 0);
  572. __decorate([
  573. babylonjs_1.expandToProperty("_markAllSubMeshesAsLightsDirty")
  574. ], TerrainMaterial.prototype, "disableLighting", void 0);
  575. __decorate([
  576. babylonjs_1.serialize("maxSimultaneousLights")
  577. ], TerrainMaterial.prototype, "_maxSimultaneousLights", void 0);
  578. __decorate([
  579. babylonjs_1.expandToProperty("_markAllSubMeshesAsLightsDirty")
  580. ], TerrainMaterial.prototype, "maxSimultaneousLights", void 0);
  581. return TerrainMaterial;
  582. }(babylonjs_1.PushMaterial));
  583. exports.TerrainMaterial = TerrainMaterial;
  584. /***/ }),
  585. /***/ "babylonjs":
  586. /*!****************************************************************************************************!*\
  587. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  588. \****************************************************************************************************/
  589. /*! no static exports found */
  590. /***/ (function(module, exports) {
  591. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs__;
  592. /***/ })
  593. /******/ });
  594. });
  595. //# sourceMappingURL=babylon.terrainMaterial.min.js.map