babylon.fireProceduralTexture.min.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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-procedural-textures", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-procedural-textures"] = factory(require("babylonjs"));
  8. else
  9. root["BABYLON"] = 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-fire.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-fire.ts":
  122. /*!*******************************!*\
  123. !*** ./legacy/legacy-fire.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 proceduralTexture = __webpack_require__(/*! ../src/fire */ "./src/fire/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 proceduralTexture) {
  141. globalObject.BABYLON[key] = proceduralTexture[key];
  142. }
  143. }
  144. __export(__webpack_require__(/*! ../src/fire */ "./src/fire/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/fire/fireProceduralTexture.fragment.fx":
  148. /*!****************************************************!*\
  149. !*** ./src/fire/fireProceduralTexture.fragment.fx ***!
  150. \****************************************************/
  151. /*! no static exports found */
  152. /***/ (function(module, exports) {
  153. module.exports = "precision highp float;\nuniform float time;\nuniform vec3 c1;\nuniform vec3 c2;\nuniform vec3 c3;\nuniform vec3 c4;\nuniform vec3 c5;\nuniform vec3 c6;\nuniform vec2 speed;\nuniform float shift;\nuniform float alphaThreshold;\nvarying vec2 vUV;\nfloat rand(vec2 n) {\nreturn fract(cos(dot(n,vec2(12.9898,4.1414)))*43758.5453);\n}\nfloat noise(vec2 n) {\nconst vec2 d=vec2(0.0,1.0);\nvec2 b=floor(n),f=smoothstep(vec2(0.0),vec2(1.0),fract(n));\nreturn mix(mix(rand(b),rand(b+d.yx),f.x),mix(rand(b+d.xy),rand(b+d.yy),f.x),f.y);\n}\nfloat fbm(vec2 n) {\nfloat total=0.0,amplitude=1.0;\nfor (int i=0; i<4; i++) {\ntotal+=noise(n)*amplitude;\nn+=n;\namplitude*=0.5;\n}\nreturn total;\n}\nvoid main() {\nvec2 p=vUV*8.0;\nfloat q=fbm(p-time*0.1);\nvec2 r=vec2(fbm(p+q+time*speed.x-p.x-p.y),fbm(p+q-time*speed.y));\nvec3 c=mix(c1,c2,fbm(p+r))+mix(c3,c4,r.x)-mix(c5,c6,r.y);\nvec3 color=c*cos(shift*vUV.y);\nfloat luminance=dot(color.rgb,vec3(0.3,0.59,0.11));\ngl_FragColor=vec4(color,luminance*alphaThreshold+(1.0-alphaThreshold));\n}"
  154. /***/ }),
  155. /***/ "./src/fire/fireProceduralTexture.ts":
  156. /*!*******************************************!*\
  157. !*** ./src/fire/fireProceduralTexture.ts ***!
  158. \*******************************************/
  159. /*! no static exports found */
  160. /***/ (function(module, exports, __webpack_require__) {
  161. "use strict";
  162. var __extends = (this && this.__extends) || (function () {
  163. var extendStatics = function (d, b) {
  164. extendStatics = Object.setPrototypeOf ||
  165. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  166. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  167. return extendStatics(d, b);
  168. }
  169. return function (d, b) {
  170. extendStatics(d, b);
  171. function __() { this.constructor = d; }
  172. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  173. };
  174. })();
  175. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  176. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  177. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  178. 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;
  179. return c > 3 && r && Object.defineProperty(target, key, r), r;
  180. };
  181. Object.defineProperty(exports, "__esModule", { value: true });
  182. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  183. babylonjs_1.Effect.ShadersStore["fireProceduralTexturePixelShader"] = __webpack_require__(/*! ./fireProceduralTexture.fragment.fx */ "./src/fire/fireProceduralTexture.fragment.fx");
  184. var FireProceduralTexture = /** @class */ (function (_super) {
  185. __extends(FireProceduralTexture, _super);
  186. function FireProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  187. var _this = _super.call(this, name, size, "fireProceduralTexture", scene, fallbackTexture, generateMipMaps) || this;
  188. _this._time = 0.0;
  189. _this._speed = new babylonjs_1.Vector2(0.5, 0.3);
  190. _this._autoGenerateTime = true;
  191. _this._alphaThreshold = 0.5;
  192. _this._fireColors = FireProceduralTexture.RedFireColors;
  193. _this.updateShaderUniforms();
  194. return _this;
  195. }
  196. FireProceduralTexture.prototype.updateShaderUniforms = function () {
  197. this.setFloat("time", this._time);
  198. this.setVector2("speed", this._speed);
  199. this.setColor3("c1", this._fireColors[0]);
  200. this.setColor3("c2", this._fireColors[1]);
  201. this.setColor3("c3", this._fireColors[2]);
  202. this.setColor3("c4", this._fireColors[3]);
  203. this.setColor3("c5", this._fireColors[4]);
  204. this.setColor3("c6", this._fireColors[5]);
  205. this.setFloat("alphaThreshold", this._alphaThreshold);
  206. };
  207. FireProceduralTexture.prototype.render = function (useCameraPostProcess) {
  208. var scene = this.getScene();
  209. if (this._autoGenerateTime && scene) {
  210. this._time += scene.getAnimationRatio() * 0.03;
  211. this.updateShaderUniforms();
  212. }
  213. _super.prototype.render.call(this, useCameraPostProcess);
  214. };
  215. Object.defineProperty(FireProceduralTexture, "PurpleFireColors", {
  216. get: function () {
  217. return [
  218. new babylonjs_1.Color3(0.5, 0.0, 1.0),
  219. new babylonjs_1.Color3(0.9, 0.0, 1.0),
  220. new babylonjs_1.Color3(0.2, 0.0, 1.0),
  221. new babylonjs_1.Color3(1.0, 0.9, 1.0),
  222. new babylonjs_1.Color3(0.1, 0.1, 1.0),
  223. new babylonjs_1.Color3(0.9, 0.9, 1.0)
  224. ];
  225. },
  226. enumerable: true,
  227. configurable: true
  228. });
  229. Object.defineProperty(FireProceduralTexture, "GreenFireColors", {
  230. get: function () {
  231. return [
  232. new babylonjs_1.Color3(0.5, 1.0, 0.0),
  233. new babylonjs_1.Color3(0.5, 1.0, 0.0),
  234. new babylonjs_1.Color3(0.3, 0.4, 0.0),
  235. new babylonjs_1.Color3(0.5, 1.0, 0.0),
  236. new babylonjs_1.Color3(0.2, 0.0, 0.0),
  237. new babylonjs_1.Color3(0.5, 1.0, 0.0)
  238. ];
  239. },
  240. enumerable: true,
  241. configurable: true
  242. });
  243. Object.defineProperty(FireProceduralTexture, "RedFireColors", {
  244. get: function () {
  245. return [
  246. new babylonjs_1.Color3(0.5, 0.0, 0.1),
  247. new babylonjs_1.Color3(0.9, 0.0, 0.0),
  248. new babylonjs_1.Color3(0.2, 0.0, 0.0),
  249. new babylonjs_1.Color3(1.0, 0.9, 0.0),
  250. new babylonjs_1.Color3(0.1, 0.1, 0.1),
  251. new babylonjs_1.Color3(0.9, 0.9, 0.9)
  252. ];
  253. },
  254. enumerable: true,
  255. configurable: true
  256. });
  257. Object.defineProperty(FireProceduralTexture, "BlueFireColors", {
  258. get: function () {
  259. return [
  260. new babylonjs_1.Color3(0.1, 0.0, 0.5),
  261. new babylonjs_1.Color3(0.0, 0.0, 0.5),
  262. new babylonjs_1.Color3(0.1, 0.0, 0.2),
  263. new babylonjs_1.Color3(0.0, 0.0, 1.0),
  264. new babylonjs_1.Color3(0.1, 0.2, 0.3),
  265. new babylonjs_1.Color3(0.0, 0.2, 0.9)
  266. ];
  267. },
  268. enumerable: true,
  269. configurable: true
  270. });
  271. Object.defineProperty(FireProceduralTexture.prototype, "autoGenerateTime", {
  272. get: function () {
  273. return this._autoGenerateTime;
  274. },
  275. set: function (value) {
  276. this._autoGenerateTime = value;
  277. },
  278. enumerable: true,
  279. configurable: true
  280. });
  281. Object.defineProperty(FireProceduralTexture.prototype, "fireColors", {
  282. get: function () {
  283. return this._fireColors;
  284. },
  285. set: function (value) {
  286. this._fireColors = value;
  287. this.updateShaderUniforms();
  288. },
  289. enumerable: true,
  290. configurable: true
  291. });
  292. Object.defineProperty(FireProceduralTexture.prototype, "time", {
  293. get: function () {
  294. return this._time;
  295. },
  296. set: function (value) {
  297. this._time = value;
  298. this.updateShaderUniforms();
  299. },
  300. enumerable: true,
  301. configurable: true
  302. });
  303. Object.defineProperty(FireProceduralTexture.prototype, "speed", {
  304. get: function () {
  305. return this._speed;
  306. },
  307. set: function (value) {
  308. this._speed = value;
  309. this.updateShaderUniforms();
  310. },
  311. enumerable: true,
  312. configurable: true
  313. });
  314. Object.defineProperty(FireProceduralTexture.prototype, "alphaThreshold", {
  315. get: function () {
  316. return this._alphaThreshold;
  317. },
  318. set: function (value) {
  319. this._alphaThreshold = value;
  320. this.updateShaderUniforms();
  321. },
  322. enumerable: true,
  323. configurable: true
  324. });
  325. /**
  326. * Serializes this fire procedural texture
  327. * @returns a serialized fire procedural texture object
  328. */
  329. FireProceduralTexture.prototype.serialize = function () {
  330. var serializationObject = babylonjs_1.SerializationHelper.Serialize(this, _super.prototype.serialize.call(this));
  331. serializationObject.customType = "BABYLON.FireProceduralTexture";
  332. serializationObject.fireColors = [];
  333. for (var i = 0; i < this._fireColors.length; i++) {
  334. serializationObject.fireColors.push(this._fireColors[i].asArray());
  335. }
  336. return serializationObject;
  337. };
  338. /**
  339. * Creates a Fire Procedural Texture from parsed fire procedural texture data
  340. * @param parsedTexture defines parsed texture data
  341. * @param scene defines the current scene
  342. * @param rootUrl defines the root URL containing fire procedural texture information
  343. * @returns a parsed Fire Procedural Texture
  344. */
  345. FireProceduralTexture.Parse = function (parsedTexture, scene, rootUrl) {
  346. var texture = babylonjs_1.SerializationHelper.Parse(function () { return new FireProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps); }, parsedTexture, scene, rootUrl);
  347. var colors = [];
  348. for (var i = 0; i < parsedTexture.fireColors.length; i++) {
  349. colors.push(babylonjs_1.Color3.FromArray(parsedTexture.fireColors[i]));
  350. }
  351. texture.fireColors = colors;
  352. return texture;
  353. };
  354. __decorate([
  355. babylonjs_1.serialize()
  356. ], FireProceduralTexture.prototype, "autoGenerateTime", null);
  357. __decorate([
  358. babylonjs_1.serialize()
  359. ], FireProceduralTexture.prototype, "time", null);
  360. __decorate([
  361. babylonjs_1.serializeAsVector2()
  362. ], FireProceduralTexture.prototype, "speed", null);
  363. __decorate([
  364. babylonjs_1.serialize()
  365. ], FireProceduralTexture.prototype, "alphaThreshold", null);
  366. return FireProceduralTexture;
  367. }(babylonjs_1.ProceduralTexture));
  368. exports.FireProceduralTexture = FireProceduralTexture;
  369. /***/ }),
  370. /***/ "./src/fire/index.ts":
  371. /*!***************************!*\
  372. !*** ./src/fire/index.ts ***!
  373. \***************************/
  374. /*! no static exports found */
  375. /***/ (function(module, exports, __webpack_require__) {
  376. "use strict";
  377. function __export(m) {
  378. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  379. }
  380. Object.defineProperty(exports, "__esModule", { value: true });
  381. __export(__webpack_require__(/*! ./fireProceduralTexture */ "./src/fire/fireProceduralTexture.ts"));
  382. /***/ }),
  383. /***/ "babylonjs":
  384. /*!****************************************************************************************************!*\
  385. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  386. \****************************************************************************************************/
  387. /*! no static exports found */
  388. /***/ (function(module, exports) {
  389. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs__;
  390. /***/ })
  391. /******/ });
  392. });
  393. //# sourceMappingURL=babylon.fireProceduralTexture.min.js.map