babylonjs.postProcess.js 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  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-post-process", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-post-process"] = factory(require("babylonjs"));
  8. else
  9. root["POSTPROCESSES"] = factory(root["BABYLON"]);
  10. })((typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : this), function(__WEBPACK_EXTERNAL_MODULE_babylonjs_Materials_Textures_texture__) {
  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.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../../node_modules/tslib/tslib.es6.js":
  99. /*!***********************************************************!*\
  100. !*** C:/Repos/Babylon.js/node_modules/tslib/tslib.es6.js ***!
  101. \***********************************************************/
  102. /*! exports provided: __extends, __assign, __rest, __decorate, __param, __metadata, __awaiter, __generator, __exportStar, __values, __read, __spread, __spreadArrays, __await, __asyncGenerator, __asyncDelegator, __asyncValues, __makeTemplateObject, __importStar, __importDefault */
  103. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  104. "use strict";
  105. __webpack_require__.r(__webpack_exports__);
  106. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__extends", function() { return __extends; });
  107. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__assign", function() { return __assign; });
  108. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__rest", function() { return __rest; });
  109. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__decorate", function() { return __decorate; });
  110. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__param", function() { return __param; });
  111. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__metadata", function() { return __metadata; });
  112. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__awaiter", function() { return __awaiter; });
  113. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__generator", function() { return __generator; });
  114. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__exportStar", function() { return __exportStar; });
  115. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__values", function() { return __values; });
  116. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__read", function() { return __read; });
  117. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spread", function() { return __spread; });
  118. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spreadArrays", function() { return __spreadArrays; });
  119. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__await", function() { return __await; });
  120. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncGenerator", function() { return __asyncGenerator; });
  121. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncDelegator", function() { return __asyncDelegator; });
  122. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncValues", function() { return __asyncValues; });
  123. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__makeTemplateObject", function() { return __makeTemplateObject; });
  124. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importStar", function() { return __importStar; });
  125. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importDefault", function() { return __importDefault; });
  126. /*! *****************************************************************************
  127. Copyright (c) Microsoft Corporation. All rights reserved.
  128. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  129. this file except in compliance with the License. You may obtain a copy of the
  130. License at http://www.apache.org/licenses/LICENSE-2.0
  131. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  132. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  133. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  134. MERCHANTABLITY OR NON-INFRINGEMENT.
  135. See the Apache Version 2.0 License for specific language governing permissions
  136. and limitations under the License.
  137. ***************************************************************************** */
  138. /* global Reflect, Promise */
  139. var extendStatics = function(d, b) {
  140. extendStatics = Object.setPrototypeOf ||
  141. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  142. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  143. return extendStatics(d, b);
  144. };
  145. function __extends(d, b) {
  146. extendStatics(d, b);
  147. function __() { this.constructor = d; }
  148. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  149. }
  150. var __assign = function() {
  151. __assign = Object.assign || function __assign(t) {
  152. for (var s, i = 1, n = arguments.length; i < n; i++) {
  153. s = arguments[i];
  154. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  155. }
  156. return t;
  157. }
  158. return __assign.apply(this, arguments);
  159. }
  160. function __rest(s, e) {
  161. var t = {};
  162. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  163. t[p] = s[p];
  164. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  165. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  166. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  167. t[p[i]] = s[p[i]];
  168. }
  169. return t;
  170. }
  171. function __decorate(decorators, target, key, desc) {
  172. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  173. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  174. 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;
  175. return c > 3 && r && Object.defineProperty(target, key, r), r;
  176. }
  177. function __param(paramIndex, decorator) {
  178. return function (target, key) { decorator(target, key, paramIndex); }
  179. }
  180. function __metadata(metadataKey, metadataValue) {
  181. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  182. }
  183. function __awaiter(thisArg, _arguments, P, generator) {
  184. return new (P || (P = Promise))(function (resolve, reject) {
  185. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  186. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  187. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  188. step((generator = generator.apply(thisArg, _arguments || [])).next());
  189. });
  190. }
  191. function __generator(thisArg, body) {
  192. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  193. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  194. function verb(n) { return function (v) { return step([n, v]); }; }
  195. function step(op) {
  196. if (f) throw new TypeError("Generator is already executing.");
  197. while (_) try {
  198. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  199. if (y = 0, t) op = [op[0] & 2, t.value];
  200. switch (op[0]) {
  201. case 0: case 1: t = op; break;
  202. case 4: _.label++; return { value: op[1], done: false };
  203. case 5: _.label++; y = op[1]; op = [0]; continue;
  204. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  205. default:
  206. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  207. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  208. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  209. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  210. if (t[2]) _.ops.pop();
  211. _.trys.pop(); continue;
  212. }
  213. op = body.call(thisArg, _);
  214. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  215. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  216. }
  217. }
  218. function __exportStar(m, exports) {
  219. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  220. }
  221. function __values(o) {
  222. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  223. if (m) return m.call(o);
  224. return {
  225. next: function () {
  226. if (o && i >= o.length) o = void 0;
  227. return { value: o && o[i++], done: !o };
  228. }
  229. };
  230. }
  231. function __read(o, n) {
  232. var m = typeof Symbol === "function" && o[Symbol.iterator];
  233. if (!m) return o;
  234. var i = m.call(o), r, ar = [], e;
  235. try {
  236. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  237. }
  238. catch (error) { e = { error: error }; }
  239. finally {
  240. try {
  241. if (r && !r.done && (m = i["return"])) m.call(i);
  242. }
  243. finally { if (e) throw e.error; }
  244. }
  245. return ar;
  246. }
  247. function __spread() {
  248. for (var ar = [], i = 0; i < arguments.length; i++)
  249. ar = ar.concat(__read(arguments[i]));
  250. return ar;
  251. }
  252. function __spreadArrays() {
  253. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  254. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  255. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  256. r[k] = a[j];
  257. return r;
  258. };
  259. function __await(v) {
  260. return this instanceof __await ? (this.v = v, this) : new __await(v);
  261. }
  262. function __asyncGenerator(thisArg, _arguments, generator) {
  263. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  264. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  265. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  266. function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
  267. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  268. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  269. function fulfill(value) { resume("next", value); }
  270. function reject(value) { resume("throw", value); }
  271. function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
  272. }
  273. function __asyncDelegator(o) {
  274. var i, p;
  275. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  276. function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
  277. }
  278. function __asyncValues(o) {
  279. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  280. var m = o[Symbol.asyncIterator], i;
  281. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  282. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  283. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  284. }
  285. function __makeTemplateObject(cooked, raw) {
  286. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  287. return cooked;
  288. };
  289. function __importStar(mod) {
  290. if (mod && mod.__esModule) return mod;
  291. var result = {};
  292. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  293. result.default = mod;
  294. return result;
  295. }
  296. function __importDefault(mod) {
  297. return (mod && mod.__esModule) ? mod : { default: mod };
  298. }
  299. /***/ }),
  300. /***/ "../../node_modules/webpack/buildin/global.js":
  301. /*!***********************************!*\
  302. !*** (webpack)/buildin/global.js ***!
  303. \***********************************/
  304. /*! no static exports found */
  305. /***/ (function(module, exports) {
  306. var g;
  307. // This works in non-strict mode
  308. g = (function() {
  309. return this;
  310. })();
  311. try {
  312. // This works if eval is allowed (see CSP)
  313. g = g || new Function("return this")();
  314. } catch (e) {
  315. // This works if the window reference is available
  316. if (typeof window === "object") g = window;
  317. }
  318. // g can still be undefined, but nothing to do about it...
  319. // We return undefined, instead of nothing here, so it's
  320. // easier to handle this case. if(!global) { ...}
  321. module.exports = g;
  322. /***/ }),
  323. /***/ "./asciiArt/asciiArtPostProcess.ts":
  324. /*!*****************************************!*\
  325. !*** ./asciiArt/asciiArtPostProcess.ts ***!
  326. \*****************************************/
  327. /*! exports provided: AsciiArtFontTexture, AsciiArtPostProcess */
  328. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  329. "use strict";
  330. __webpack_require__.r(__webpack_exports__);
  331. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AsciiArtFontTexture", function() { return AsciiArtFontTexture; });
  332. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AsciiArtPostProcess", function() { return AsciiArtPostProcess; });
  333. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  334. /* harmony import */ var babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Misc/decorators */ "babylonjs/Materials/Textures/texture");
  335. /* harmony import */ var babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__);
  336. /* harmony import */ var _asciiart_fragment__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./asciiart.fragment */ "./asciiArt/asciiart.fragment.ts");
  337. /**
  338. * AsciiArtFontTexture is the helper class used to easily create your ascii art font texture.
  339. *
  340. * It basically takes care rendering the font front the given font size to a texture.
  341. * This is used later on in the postprocess.
  342. */
  343. var AsciiArtFontTexture = /** @class */ (function (_super) {
  344. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(AsciiArtFontTexture, _super);
  345. /**
  346. * Create a new instance of the Ascii Art FontTexture class
  347. * @param name the name of the texture
  348. * @param font the font to use, use the W3C CSS notation
  349. * @param text the caracter set to use in the rendering.
  350. * @param scene the scene that owns the texture
  351. */
  352. function AsciiArtFontTexture(name, font, text, scene) {
  353. if (scene === void 0) { scene = null; }
  354. var _this = _super.call(this, scene) || this;
  355. scene = _this.getScene();
  356. if (!scene) {
  357. return _this;
  358. }
  359. _this.name = name;
  360. _this._text == text;
  361. _this._font == font;
  362. _this.wrapU = babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Texture"].CLAMP_ADDRESSMODE;
  363. _this.wrapV = babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Texture"].CLAMP_ADDRESSMODE;
  364. //this.anisotropicFilteringLevel = 1;
  365. // Get the font specific info.
  366. var maxCharHeight = _this.getFontHeight(font);
  367. var maxCharWidth = _this.getFontWidth(font);
  368. _this._charSize = Math.max(maxCharHeight.height, maxCharWidth);
  369. // This is an approximate size, but should always be able to fit at least the maxCharCount.
  370. var textureWidth = Math.ceil(_this._charSize * text.length);
  371. var textureHeight = _this._charSize;
  372. // Create the texture that will store the font characters.
  373. _this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_SAMPLINGMODE);
  374. //scene.getEngine().setclamp
  375. var textureSize = _this.getSize();
  376. // Create a canvas with the final size: the one matching the texture.
  377. var canvas = document.createElement("canvas");
  378. canvas.width = textureSize.width;
  379. canvas.height = textureSize.height;
  380. var context = canvas.getContext("2d");
  381. context.textBaseline = "top";
  382. context.font = font;
  383. context.fillStyle = "white";
  384. context.imageSmoothingEnabled = false;
  385. // Sets the text in the texture.
  386. for (var i = 0; i < text.length; i++) {
  387. context.fillText(text[i], i * _this._charSize, -maxCharHeight.offset);
  388. }
  389. // Flush the text in the dynamic texture.
  390. scene.getEngine().updateDynamicTexture(_this._texture, canvas, false, true);
  391. return _this;
  392. }
  393. Object.defineProperty(AsciiArtFontTexture.prototype, "charSize", {
  394. /**
  395. * Gets the size of one char in the texture (each char fits in size * size space in the texture).
  396. */
  397. get: function () {
  398. return this._charSize;
  399. },
  400. enumerable: true,
  401. configurable: true
  402. });
  403. /**
  404. * Gets the max char width of a font.
  405. * @param font the font to use, use the W3C CSS notation
  406. * @return the max char width
  407. */
  408. AsciiArtFontTexture.prototype.getFontWidth = function (font) {
  409. var fontDraw = document.createElement("canvas");
  410. var ctx = fontDraw.getContext('2d');
  411. ctx.fillStyle = 'white';
  412. ctx.font = font;
  413. return ctx.measureText("W").width;
  414. };
  415. // More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/
  416. /**
  417. * Gets the max char height of a font.
  418. * @param font the font to use, use the W3C CSS notation
  419. * @return the max char height
  420. */
  421. AsciiArtFontTexture.prototype.getFontHeight = function (font) {
  422. var fontDraw = document.createElement("canvas");
  423. var ctx = fontDraw.getContext('2d');
  424. ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);
  425. ctx.textBaseline = 'top';
  426. ctx.fillStyle = 'white';
  427. ctx.font = font;
  428. ctx.fillText('jH|', 0, 0);
  429. var pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;
  430. var start = -1;
  431. var end = -1;
  432. for (var row = 0; row < fontDraw.height; row++) {
  433. for (var column = 0; column < fontDraw.width; column++) {
  434. var index = (row * fontDraw.width + column) * 4;
  435. if (pixels[index] === 0) {
  436. if (column === fontDraw.width - 1 && start !== -1) {
  437. end = row;
  438. row = fontDraw.height;
  439. break;
  440. }
  441. continue;
  442. }
  443. else {
  444. if (start === -1) {
  445. start = row;
  446. }
  447. break;
  448. }
  449. }
  450. }
  451. return { height: (end - start) + 1, offset: start - 1 };
  452. };
  453. /**
  454. * Clones the current AsciiArtTexture.
  455. * @return the clone of the texture.
  456. */
  457. AsciiArtFontTexture.prototype.clone = function () {
  458. return new AsciiArtFontTexture(this.name, this._font, this._text, this.getScene());
  459. };
  460. /**
  461. * Parses a json object representing the texture and returns an instance of it.
  462. * @param source the source JSON representation
  463. * @param scene the scene to create the texture for
  464. * @return the parsed texture
  465. */
  466. AsciiArtFontTexture.Parse = function (source, scene) {
  467. var texture = babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["SerializationHelper"].Parse(function () { return new AsciiArtFontTexture(source.name, source.font, source.text, scene); }, source, scene, null);
  468. return texture;
  469. };
  470. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"])([
  471. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])("font")
  472. ], AsciiArtFontTexture.prototype, "_font", void 0);
  473. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"])([
  474. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])("text")
  475. ], AsciiArtFontTexture.prototype, "_text", void 0);
  476. return AsciiArtFontTexture;
  477. }(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["BaseTexture"]));
  478. /**
  479. * AsciiArtPostProcess helps rendering everithing in Ascii Art.
  480. *
  481. * Simmply add it to your scene and let the nerd that lives in you have fun.
  482. * Example usage: var pp = new AsciiArtPostProcess("myAscii", "20px Monospace", camera);
  483. */
  484. var AsciiArtPostProcess = /** @class */ (function (_super) {
  485. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(AsciiArtPostProcess, _super);
  486. /**
  487. * Instantiates a new Ascii Art Post Process.
  488. * @param name the name to give to the postprocess
  489. * @camera the camera to apply the post process to.
  490. * @param options can either be the font name or an option object following the IAsciiArtPostProcessOptions format
  491. */
  492. function AsciiArtPostProcess(name, camera, options) {
  493. var _this = _super.call(this, name, 'asciiart', ['asciiArtFontInfos', 'asciiArtOptions'], ['asciiArtFont'], {
  494. width: camera.getEngine().getRenderWidth(),
  495. height: camera.getEngine().getRenderHeight()
  496. }, camera, babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Texture"].TRILINEAR_SAMPLINGMODE, camera.getEngine(), true) || this;
  497. /**
  498. * This defines the amount you want to mix the "tile" or caracter space colored in the ascii art.
  499. * This number is defined between 0 and 1;
  500. */
  501. _this.mixToTile = 0;
  502. /**
  503. * This defines the amount you want to mix the normal rendering pass in the ascii art.
  504. * This number is defined between 0 and 1;
  505. */
  506. _this.mixToNormal = 0;
  507. // Default values.
  508. var font = "40px Monospace";
  509. var characterSet = " `-.'_:,\"=^;<+!*?/cL\\zrs7TivJtC{3F)Il(xZfY5S2eajo14[nuyE]P6V9kXpKwGhqAUbOd8#HRDB0$mgMW&Q%N@";
  510. // Use options.
  511. if (options) {
  512. if (typeof (options) === "string") {
  513. font = options;
  514. }
  515. else {
  516. font = options.font || font;
  517. characterSet = options.characterSet || characterSet;
  518. _this.mixToTile = options.mixToTile || _this.mixToTile;
  519. _this.mixToNormal = options.mixToNormal || _this.mixToNormal;
  520. }
  521. }
  522. _this._asciiArtFontTexture = new AsciiArtFontTexture(name, font, characterSet, camera.getScene());
  523. var textureSize = _this._asciiArtFontTexture.getSize();
  524. _this.onApply = function (effect) {
  525. effect.setTexture("asciiArtFont", _this._asciiArtFontTexture);
  526. effect.setFloat4("asciiArtFontInfos", _this._asciiArtFontTexture.charSize, characterSet.length, textureSize.width, textureSize.height);
  527. effect.setFloat4("asciiArtOptions", _this.width, _this.height, _this.mixToNormal, _this.mixToTile);
  528. };
  529. return _this;
  530. }
  531. return AsciiArtPostProcess;
  532. }(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["PostProcess"]));
  533. /***/ }),
  534. /***/ "./asciiArt/asciiart.fragment.ts":
  535. /*!***************************************!*\
  536. !*** ./asciiArt/asciiart.fragment.ts ***!
  537. \***************************************/
  538. /*! exports provided: asciiartPixelShader */
  539. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  540. "use strict";
  541. __webpack_require__.r(__webpack_exports__);
  542. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "asciiartPixelShader", function() { return asciiartPixelShader; });
  543. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/effect */ "babylonjs/Materials/Textures/texture");
  544. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__);
  545. var name = 'asciiartPixelShader';
  546. var shader = "\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D asciiArtFont;\n\nuniform vec4 asciiArtFontInfos;\nuniform vec4 asciiArtOptions;\n\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);\n}\n\nvoid main(void)\n{\nfloat caracterSize=asciiArtFontInfos.x;\nfloat numChar=asciiArtFontInfos.y-1.0;\nfloat fontx=asciiArtFontInfos.z;\nfloat fonty=asciiArtFontInfos.w;\nfloat screenx=asciiArtOptions.x;\nfloat screeny=asciiArtOptions.y;\nfloat tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;\nfloat tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;\nvec2 tileUV=vec2(tileX,tileY);\nvec4 tileColor=texture2D(textureSampler,tileUV);\nvec4 baseColor=texture2D(textureSampler,vUV);\nfloat tileLuminance=getLuminance(tileColor.rgb);\nfloat offsetx=(float(floor(tileLuminance*numChar)))*caracterSize/fontx;\nfloat offsety=0.0;\nfloat x=float(mod(gl_FragCoord.x,caracterSize))/fontx;\nfloat y=float(mod(gl_FragCoord.y,caracterSize))/fonty;\nvec4 finalColor=texture2D(asciiArtFont,vec2(offsetx+x,offsety+(caracterSize/fonty-y)));\nfinalColor.rgb*=tileColor.rgb;\nfinalColor.a=1.0;\nfinalColor=mix(finalColor,tileColor,asciiArtOptions.w);\nfinalColor=mix(finalColor,baseColor,asciiArtOptions.z);\ngl_FragColor=finalColor;\n}";
  547. babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__["Effect"].ShadersStore[name] = shader;
  548. /** @hidden */
  549. var asciiartPixelShader = { name: name, shader: shader };
  550. /***/ }),
  551. /***/ "./asciiArt/index.ts":
  552. /*!***************************!*\
  553. !*** ./asciiArt/index.ts ***!
  554. \***************************/
  555. /*! exports provided: AsciiArtFontTexture, AsciiArtPostProcess */
  556. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  557. "use strict";
  558. __webpack_require__.r(__webpack_exports__);
  559. /* harmony import */ var _asciiArtPostProcess__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./asciiArtPostProcess */ "./asciiArt/asciiArtPostProcess.ts");
  560. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AsciiArtFontTexture", function() { return _asciiArtPostProcess__WEBPACK_IMPORTED_MODULE_0__["AsciiArtFontTexture"]; });
  561. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AsciiArtPostProcess", function() { return _asciiArtPostProcess__WEBPACK_IMPORTED_MODULE_0__["AsciiArtPostProcess"]; });
  562. /***/ }),
  563. /***/ "./digitalRain/digitalRainPostProcess.ts":
  564. /*!***********************************************!*\
  565. !*** ./digitalRain/digitalRainPostProcess.ts ***!
  566. \***********************************************/
  567. /*! exports provided: DigitalRainFontTexture, DigitalRainPostProcess */
  568. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  569. "use strict";
  570. __webpack_require__.r(__webpack_exports__);
  571. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DigitalRainFontTexture", function() { return DigitalRainFontTexture; });
  572. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DigitalRainPostProcess", function() { return DigitalRainPostProcess; });
  573. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  574. /* harmony import */ var babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Misc/decorators */ "babylonjs/Materials/Textures/texture");
  575. /* harmony import */ var babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__);
  576. /* harmony import */ var _digitalrain_fragment__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./digitalrain.fragment */ "./digitalRain/digitalrain.fragment.ts");
  577. /**
  578. * DigitalRainFontTexture is the helper class used to easily create your digital rain font texture.
  579. *
  580. * It basically takes care rendering the font front the given font size to a texture.
  581. * This is used later on in the postprocess.
  582. */
  583. var DigitalRainFontTexture = /** @class */ (function (_super) {
  584. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(DigitalRainFontTexture, _super);
  585. /**
  586. * Create a new instance of the Digital Rain FontTexture class
  587. * @param name the name of the texture
  588. * @param font the font to use, use the W3C CSS notation
  589. * @param text the caracter set to use in the rendering.
  590. * @param scene the scene that owns the texture
  591. */
  592. function DigitalRainFontTexture(name, font, text, scene) {
  593. if (scene === void 0) { scene = null; }
  594. var _this = _super.call(this, scene) || this;
  595. scene = _this.getScene();
  596. if (!scene) {
  597. return _this;
  598. }
  599. _this.name = name;
  600. _this._text == text;
  601. _this._font == font;
  602. _this.wrapU = babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Texture"].CLAMP_ADDRESSMODE;
  603. _this.wrapV = babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Texture"].CLAMP_ADDRESSMODE;
  604. // Get the font specific info.
  605. var maxCharHeight = _this.getFontHeight(font);
  606. var maxCharWidth = _this.getFontWidth(font);
  607. _this._charSize = Math.max(maxCharHeight.height, maxCharWidth);
  608. // This is an approximate size, but should always be able to fit at least the maxCharCount.
  609. var textureWidth = _this._charSize;
  610. var textureHeight = Math.ceil(_this._charSize * text.length);
  611. // Create the texture that will store the font characters.
  612. _this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_SAMPLINGMODE);
  613. //scene.getEngine().setclamp
  614. var textureSize = _this.getSize();
  615. // Create a canvas with the final size: the one matching the texture.
  616. var canvas = document.createElement("canvas");
  617. canvas.width = textureSize.width;
  618. canvas.height = textureSize.height;
  619. var context = canvas.getContext("2d");
  620. context.textBaseline = "top";
  621. context.font = font;
  622. context.fillStyle = "white";
  623. context.imageSmoothingEnabled = false;
  624. // Sets the text in the texture.
  625. for (var i = 0; i < text.length; i++) {
  626. context.fillText(text[i], 0, i * _this._charSize - maxCharHeight.offset);
  627. }
  628. // Flush the text in the dynamic texture.
  629. scene.getEngine().updateDynamicTexture(_this._texture, canvas, false, true);
  630. return _this;
  631. }
  632. Object.defineProperty(DigitalRainFontTexture.prototype, "charSize", {
  633. /**
  634. * Gets the size of one char in the texture (each char fits in size * size space in the texture).
  635. */
  636. get: function () {
  637. return this._charSize;
  638. },
  639. enumerable: true,
  640. configurable: true
  641. });
  642. /**
  643. * Gets the max char width of a font.
  644. * @param font the font to use, use the W3C CSS notation
  645. * @return the max char width
  646. */
  647. DigitalRainFontTexture.prototype.getFontWidth = function (font) {
  648. var fontDraw = document.createElement("canvas");
  649. var ctx = fontDraw.getContext('2d');
  650. ctx.fillStyle = 'white';
  651. ctx.font = font;
  652. return ctx.measureText("W").width;
  653. };
  654. // More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/
  655. /**
  656. * Gets the max char height of a font.
  657. * @param font the font to use, use the W3C CSS notation
  658. * @return the max char height
  659. */
  660. DigitalRainFontTexture.prototype.getFontHeight = function (font) {
  661. var fontDraw = document.createElement("canvas");
  662. var ctx = fontDraw.getContext('2d');
  663. ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);
  664. ctx.textBaseline = 'top';
  665. ctx.fillStyle = 'white';
  666. ctx.font = font;
  667. ctx.fillText('jH|', 0, 0);
  668. var pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;
  669. var start = -1;
  670. var end = -1;
  671. for (var row = 0; row < fontDraw.height; row++) {
  672. for (var column = 0; column < fontDraw.width; column++) {
  673. var index = (row * fontDraw.width + column) * 4;
  674. if (pixels[index] === 0) {
  675. if (column === fontDraw.width - 1 && start !== -1) {
  676. end = row;
  677. row = fontDraw.height;
  678. break;
  679. }
  680. continue;
  681. }
  682. else {
  683. if (start === -1) {
  684. start = row;
  685. }
  686. break;
  687. }
  688. }
  689. }
  690. return { height: (end - start) + 1, offset: start - 1 };
  691. };
  692. /**
  693. * Clones the current DigitalRainFontTexture.
  694. * @return the clone of the texture.
  695. */
  696. DigitalRainFontTexture.prototype.clone = function () {
  697. return new DigitalRainFontTexture(this.name, this._font, this._text, this.getScene());
  698. };
  699. /**
  700. * Parses a json object representing the texture and returns an instance of it.
  701. * @param source the source JSON representation
  702. * @param scene the scene to create the texture for
  703. * @return the parsed texture
  704. */
  705. DigitalRainFontTexture.Parse = function (source, scene) {
  706. var texture = babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["SerializationHelper"].Parse(function () { return new DigitalRainFontTexture(source.name, source.font, source.text, scene); }, source, scene, null);
  707. return texture;
  708. };
  709. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"])([
  710. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])("font")
  711. ], DigitalRainFontTexture.prototype, "_font", void 0);
  712. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"])([
  713. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])("text")
  714. ], DigitalRainFontTexture.prototype, "_text", void 0);
  715. return DigitalRainFontTexture;
  716. }(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["BaseTexture"]));
  717. /**
  718. * DigitalRainPostProcess helps rendering everithing in digital rain.
  719. *
  720. * Simmply add it to your scene and let the nerd that lives in you have fun.
  721. * Example usage: var pp = new DigitalRainPostProcess("digitalRain", "20px Monospace", camera);
  722. */
  723. var DigitalRainPostProcess = /** @class */ (function (_super) {
  724. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(DigitalRainPostProcess, _super);
  725. /**
  726. * Instantiates a new Digital Rain Post Process.
  727. * @param name the name to give to the postprocess
  728. * @camera the camera to apply the post process to.
  729. * @param options can either be the font name or an option object following the IDigitalRainPostProcessOptions format
  730. */
  731. function DigitalRainPostProcess(name, camera, options) {
  732. var _this = _super.call(this, name, 'digitalrain', ['digitalRainFontInfos', 'digitalRainOptions', 'cosTimeZeroOne', 'matrixSpeed'], ['digitalRainFont'], {
  733. width: camera.getEngine().getRenderWidth(),
  734. height: camera.getEngine().getRenderHeight()
  735. }, camera, babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Texture"].TRILINEAR_SAMPLINGMODE, camera.getEngine(), true) || this;
  736. /**
  737. * This defines the amount you want to mix the "tile" or caracter space colored in the digital rain.
  738. * This number is defined between 0 and 1;
  739. */
  740. _this.mixToTile = 0;
  741. /**
  742. * This defines the amount you want to mix the normal rendering pass in the digital rain.
  743. * This number is defined between 0 and 1;
  744. */
  745. _this.mixToNormal = 0;
  746. // Default values.
  747. var font = "15px Monospace";
  748. var characterSet = "古池や蛙飛び込む水の音ふるいけやかわずとびこむみずのおと初しぐれ猿も小蓑をほしげ也はつしぐれさるもこみのをほしげなり江戸の雨何石呑んだ時鳥えどのあめなんごくのんだほととぎす";
  749. // Use options.
  750. if (options) {
  751. if (typeof (options) === "string") {
  752. font = options;
  753. }
  754. else {
  755. font = options.font || font;
  756. _this.mixToTile = options.mixToTile || _this.mixToTile;
  757. _this.mixToNormal = options.mixToNormal || _this.mixToNormal;
  758. }
  759. }
  760. _this._digitalRainFontTexture = new DigitalRainFontTexture(name, font, characterSet, camera.getScene());
  761. var textureSize = _this._digitalRainFontTexture.getSize();
  762. var alpha = 0.0;
  763. var cosTimeZeroOne = 0.0;
  764. var matrix = babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromValues(Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random());
  765. _this.onApply = function (effect) {
  766. effect.setTexture("digitalRainFont", _this._digitalRainFontTexture);
  767. effect.setFloat4("digitalRainFontInfos", _this._digitalRainFontTexture.charSize, characterSet.length, textureSize.width, textureSize.height);
  768. effect.setFloat4("digitalRainOptions", _this.width, _this.height, _this.mixToNormal, _this.mixToTile);
  769. effect.setMatrix("matrixSpeed", matrix);
  770. alpha += 0.003;
  771. cosTimeZeroOne = alpha;
  772. effect.setFloat('cosTimeZeroOne', cosTimeZeroOne);
  773. };
  774. return _this;
  775. }
  776. return DigitalRainPostProcess;
  777. }(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["PostProcess"]));
  778. /***/ }),
  779. /***/ "./digitalRain/digitalrain.fragment.ts":
  780. /*!*********************************************!*\
  781. !*** ./digitalRain/digitalrain.fragment.ts ***!
  782. \*********************************************/
  783. /*! exports provided: digitalrainPixelShader */
  784. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  785. "use strict";
  786. __webpack_require__.r(__webpack_exports__);
  787. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "digitalrainPixelShader", function() { return digitalrainPixelShader; });
  788. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/effect */ "babylonjs/Materials/Textures/texture");
  789. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__);
  790. var name = 'digitalrainPixelShader';
  791. var shader = "\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D digitalRainFont;\n\nuniform vec4 digitalRainFontInfos;\nuniform vec4 digitalRainOptions;\nuniform mat4 matrixSpeed;\nuniform float cosTimeZeroOne;\n\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);\n}\n\nvoid main(void)\n{\nfloat caracterSize=digitalRainFontInfos.x;\nfloat numChar=digitalRainFontInfos.y-1.0;\nfloat fontx=digitalRainFontInfos.z;\nfloat fonty=digitalRainFontInfos.w;\nfloat screenx=digitalRainOptions.x;\nfloat screeny=digitalRainOptions.y;\nfloat ratio=screeny/fonty;\nfloat columnx=float(floor((gl_FragCoord.x)/caracterSize));\nfloat tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;\nfloat tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;\nvec2 tileUV=vec2(tileX,tileY);\nvec4 tileColor=texture2D(textureSampler,tileUV);\nvec4 baseColor=texture2D(textureSampler,vUV);\nfloat tileLuminance=getLuminance(tileColor.rgb);\nint st=int(mod(columnx,4.0));\nfloat speed=cosTimeZeroOne*(sin(tileX*314.5)*0.5+0.6);\nfloat x=float(mod(gl_FragCoord.x,caracterSize))/fontx;\nfloat y=float(mod(speed+gl_FragCoord.y/screeny,1.0));\ny*=ratio;\nvec4 finalColor=texture2D(digitalRainFont,vec2(x,1.0-y));\nvec3 high=finalColor.rgb*(vec3(1.2,1.2,1.2)*pow(1.0-y,30.0));\nfinalColor.rgb*=vec3(pow(tileLuminance,5.0),pow(tileLuminance,1.5),pow(tileLuminance,3.0));\nfinalColor.rgb+=high;\nfinalColor.rgb=clamp(finalColor.rgb,0.,1.);\nfinalColor.a=1.0;\nfinalColor=mix(finalColor,tileColor,digitalRainOptions.w);\nfinalColor=mix(finalColor,baseColor,digitalRainOptions.z);\ngl_FragColor=finalColor;\n}";
  792. babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__["Effect"].ShadersStore[name] = shader;
  793. /** @hidden */
  794. var digitalrainPixelShader = { name: name, shader: shader };
  795. /***/ }),
  796. /***/ "./digitalRain/index.ts":
  797. /*!******************************!*\
  798. !*** ./digitalRain/index.ts ***!
  799. \******************************/
  800. /*! exports provided: DigitalRainFontTexture, DigitalRainPostProcess */
  801. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  802. "use strict";
  803. __webpack_require__.r(__webpack_exports__);
  804. /* harmony import */ var _digitalRainPostProcess__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./digitalRainPostProcess */ "./digitalRain/digitalRainPostProcess.ts");
  805. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DigitalRainFontTexture", function() { return _digitalRainPostProcess__WEBPACK_IMPORTED_MODULE_0__["DigitalRainFontTexture"]; });
  806. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DigitalRainPostProcess", function() { return _digitalRainPostProcess__WEBPACK_IMPORTED_MODULE_0__["DigitalRainPostProcess"]; });
  807. /***/ }),
  808. /***/ "./index.ts":
  809. /*!******************!*\
  810. !*** ./index.ts ***!
  811. \******************/
  812. /*! exports provided: AsciiArtFontTexture, AsciiArtPostProcess, DigitalRainFontTexture, DigitalRainPostProcess, OceanPostProcess */
  813. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  814. "use strict";
  815. __webpack_require__.r(__webpack_exports__);
  816. /* harmony import */ var _asciiArt__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./asciiArt */ "./asciiArt/index.ts");
  817. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AsciiArtFontTexture", function() { return _asciiArt__WEBPACK_IMPORTED_MODULE_0__["AsciiArtFontTexture"]; });
  818. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AsciiArtPostProcess", function() { return _asciiArt__WEBPACK_IMPORTED_MODULE_0__["AsciiArtPostProcess"]; });
  819. /* harmony import */ var _digitalRain__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./digitalRain */ "./digitalRain/index.ts");
  820. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DigitalRainFontTexture", function() { return _digitalRain__WEBPACK_IMPORTED_MODULE_1__["DigitalRainFontTexture"]; });
  821. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DigitalRainPostProcess", function() { return _digitalRain__WEBPACK_IMPORTED_MODULE_1__["DigitalRainPostProcess"]; });
  822. /* harmony import */ var _ocean__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./ocean */ "./ocean/index.ts");
  823. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OceanPostProcess", function() { return _ocean__WEBPACK_IMPORTED_MODULE_2__["OceanPostProcess"]; });
  824. /***/ }),
  825. /***/ "./legacy/legacy.ts":
  826. /*!**************************!*\
  827. !*** ./legacy/legacy.ts ***!
  828. \**************************/
  829. /*! exports provided: AsciiArtFontTexture, AsciiArtPostProcess, DigitalRainFontTexture, DigitalRainPostProcess, OceanPostProcess */
  830. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  831. "use strict";
  832. __webpack_require__.r(__webpack_exports__);
  833. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../index */ "./index.ts");
  834. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AsciiArtFontTexture", function() { return _index__WEBPACK_IMPORTED_MODULE_0__["AsciiArtFontTexture"]; });
  835. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AsciiArtPostProcess", function() { return _index__WEBPACK_IMPORTED_MODULE_0__["AsciiArtPostProcess"]; });
  836. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DigitalRainFontTexture", function() { return _index__WEBPACK_IMPORTED_MODULE_0__["DigitalRainFontTexture"]; });
  837. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DigitalRainPostProcess", function() { return _index__WEBPACK_IMPORTED_MODULE_0__["DigitalRainPostProcess"]; });
  838. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OceanPostProcess", function() { return _index__WEBPACK_IMPORTED_MODULE_0__["OceanPostProcess"]; });
  839. /**
  840. *
  841. * This is the entry point for the UMD module.
  842. * The entry point for a future ESM package should be index.ts
  843. */
  844. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  845. if (typeof globalObject !== "undefined") {
  846. for (var key in _index__WEBPACK_IMPORTED_MODULE_0__) {
  847. globalObject.BABYLON[key] = _index__WEBPACK_IMPORTED_MODULE_0__[key];
  848. }
  849. }
  850. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  851. /***/ }),
  852. /***/ "./ocean/index.ts":
  853. /*!************************!*\
  854. !*** ./ocean/index.ts ***!
  855. \************************/
  856. /*! exports provided: OceanPostProcess */
  857. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  858. "use strict";
  859. __webpack_require__.r(__webpack_exports__);
  860. /* harmony import */ var _oceanPostProcess__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./oceanPostProcess */ "./ocean/oceanPostProcess.ts");
  861. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OceanPostProcess", function() { return _oceanPostProcess__WEBPACK_IMPORTED_MODULE_0__["OceanPostProcess"]; });
  862. /***/ }),
  863. /***/ "./ocean/oceanPostProcess.fragment.ts":
  864. /*!********************************************!*\
  865. !*** ./ocean/oceanPostProcess.fragment.ts ***!
  866. \********************************************/
  867. /*! exports provided: oceanPostProcessPixelShader */
  868. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  869. "use strict";
  870. __webpack_require__.r(__webpack_exports__);
  871. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "oceanPostProcessPixelShader", function() { return oceanPostProcessPixelShader; });
  872. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/effect */ "babylonjs/Materials/Textures/texture");
  873. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__);
  874. var name = 'oceanPostProcessPixelShader';
  875. var shader = "\n\nuniform sampler2D textureSampler;\nuniform sampler2D positionSampler;\n#ifdef REFLECTION_ENABLED\nuniform sampler2D reflectionSampler;\n#endif\n#ifdef REFRACTION_ENABLED\nuniform sampler2D refractionSampler;\n#endif\nuniform float time;\nuniform vec2 resolution;\nuniform vec3 cameraRotation;\nuniform vec3 cameraPosition;\n\nvarying vec2 vUV;\n\nconst int NUM_STEPS=8;\nconst float PI=3.141592;\nconst float EPSILON=1e-3;\n#define EPSILON_NRM (0.1/resolution.x)\n\nconst int ITER_GEOMETRY=8;\nconst int ITER_FRAGMENT=5;\nconst float SEA_HEIGHT=0.6;\nconst float SEA_CHOPPY=4.0;\nconst float SEA_SPEED=0.8;\nconst float SEA_FREQ=0.16;\nconst vec3 SEA_BASE=vec3(0.1,0.19,0.22);\nconst vec3 SEA_WATER_COLOR=vec3(0.8,0.9,0.6);\n#define SEA_TIME (1.0+time*SEA_SPEED)\nconst mat2 octave_m=mat2(1.6,1.2,-1.2,1.6);\n\nmat3 fromEuler(vec3 ang)\n{\nvec2 a1=vec2(sin(ang.x),cos(ang.x));\nvec2 a2=vec2(sin(ang.y),cos(ang.y));\nvec2 a3=vec2(sin(ang.z),cos(ang.z));\nmat3 m;\nm[0]=vec3(a1.y*a3.y+a1.x*a2.x*a3.x,a1.y*a2.x*a3.x+a3.y*a1.x,-a2.y*a3.x);\nm[1]=vec3(-a2.y*a1.x,a1.y*a2.y,a2.x);\nm[2]=vec3(a3.y*a1.x*a2.x+a1.y*a3.x,a1.x*a3.x-a1.y*a3.y*a2.x,a2.y*a3.y);\nreturn m;\n}\nfloat hash( vec2 p )\n{\nfloat h=dot(p,vec2(127.1,311.7));\nreturn fract(sin(h)*43758.5453123);\n}\nfloat noise( in vec2 p )\n{\nvec2 i=floor( p );\nvec2 f=fract( p );\nvec2 u=f*f*(3.0-2.0*f);\nreturn -1.0+2.0*mix( mix( hash( i+vec2(0.0,0.0) ),\nhash( i+vec2(1.0,0.0) ),u.x),\nmix( hash( i+vec2(0.0,1.0) ),\nhash( i+vec2(1.0,1.0) ),u.x),u.y);\n}\n\nfloat diffuse(vec3 n,vec3 l,float p)\n{\nreturn pow(dot(n,l)*0.4+0.6,p);\n}\nfloat specular(vec3 n,vec3 l,vec3 e,float s)\n{\nfloat nrm=(s+8.0)/(PI*8.0);\nreturn pow(max(dot(reflect(e,n),l),0.0),s)*nrm;\n}\n\nfloat sea_octave(vec2 uv,float choppy)\n{\nuv+=noise(uv);\nvec2 wv=1.0-abs(sin(uv));\nvec2 swv=abs(cos(uv));\nwv=mix(wv,swv,wv);\nreturn pow(1.0-pow(wv.x*wv.y,0.65),choppy);\n}\nfloat map(vec3 p)\n{\nfloat freq=SEA_FREQ;\nfloat amp=SEA_HEIGHT;\nfloat choppy=SEA_CHOPPY;\nvec2 uv=p.xz; uv.x*=0.75;\nfloat d,h=0.0;\nfor(int i=0; i<ITER_GEOMETRY; i++)\n{\nd=sea_octave((uv+SEA_TIME)*freq,choppy);\nd+=sea_octave((uv-SEA_TIME)*freq,choppy);\nh+=d*amp;\nuv*=octave_m; freq*=1.9; amp*=0.22;\nchoppy=mix(choppy,1.0,0.2);\n}\nreturn p.y-h;\n}\nfloat map_detailed(vec3 p)\n{\nfloat freq=SEA_FREQ;\nfloat amp=SEA_HEIGHT;\nfloat choppy=SEA_CHOPPY;\nvec2 uv=p.xz; uv.x*=0.75;\nfloat d,h=0.0;\nfor(int i=0; i<ITER_FRAGMENT; i++)\n{\nd=sea_octave((uv+SEA_TIME)*freq,choppy);\nd+=sea_octave((uv-SEA_TIME)*freq,choppy);\nh+=d*amp;\nuv*=octave_m; freq*=1.9; amp*=0.22;\nchoppy=mix(choppy,1.0,0.2);\n}\nreturn p.y-h;\n}\nvec3 getSeaColor(vec3 p,vec3 n,vec3 l,vec3 eye,vec3 dist)\n{\nfloat fresnel=clamp(1.0-dot(n,-eye),0.0,1.0);\nfresnel=pow(fresnel,3.0)*0.65;\n#if defined(REFLECTION_ENABLED) || defined(REFRACTION_ENABLED)\nvec2 reflectionUv=vec2(vUV.x,vUV.y+normalize(n).y);\n#endif\n#ifdef REFLECTION_ENABLED\nvec3 reflected=texture2D(reflectionSampler,reflectionUv).rgb*(1.0-fresnel);\n#else\nvec3 eyeNormal=reflect(eye,n);\neyeNormal.y=max(eyeNormal.y,0.0);\nvec3 reflected=vec3(pow(1.0-eyeNormal.y,2.0),1.0-eyeNormal.y,0.6+(1.0-eyeNormal.y)*0.4);\n#endif\n#ifdef REFRACTION_ENABLED\nvec3 refracted=SEA_BASE+diffuse(n,l,80.0)*SEA_WATER_COLOR*0.12;\nrefracted+=(texture2D(refractionSampler,reflectionUv).rgb*fresnel);\n#else\nvec3 refracted=SEA_BASE+diffuse(n,l,80.0)*SEA_WATER_COLOR*0.12;\n#endif\nvec3 color=mix(refracted,reflected,fresnel);\nfloat atten=max(1.0-dot(dist,dist)*0.001,0.0);\ncolor+=SEA_WATER_COLOR*(p.y-SEA_HEIGHT)*0.18*atten;\ncolor+=vec3(specular(n,l,eye,60.0));\nreturn color;\n}\n\nvec3 getNormal(vec3 p,float eps)\n{\nvec3 n;\nn.y=map_detailed(p);\nn.x=map_detailed(vec3(p.x+eps,p.y,p.z))-n.y;\nn.z=map_detailed(vec3(p.x,p.y,p.z+eps))-n.y;\nn.y=eps;\nreturn normalize(n);\n}\nfloat heightMapTracing(vec3 ori,vec3 dir,out vec3 p)\n{\nfloat tm=0.0;\nfloat tx=1000.0;\nfloat hx=map(ori+dir*tx);\nif(hx>0.0) return tx;\nfloat hm=map(ori+dir*tm);\nfloat tmid=0.0;\nfor(int i=0; i<NUM_STEPS; i++)\n{\ntmid=mix(tm,tx,hm/(hm-hx));\np=ori+dir*tmid;\nfloat hmid=map(p);\nif(hmid<0.0)\n{\ntx=tmid;\nhx=hmid;\n}\nelse\n{\ntm=tmid;\nhm=hmid;\n}\n}\nreturn tmid;\n}\n\nvoid main()\n{\n#ifdef NOT_SUPPORTED\n\ngl_FragColor=texture2D(textureSampler,vUV);\n#else\nvec2 uv=vUV;\nuv=uv*2.0-1.0;\nuv.x*=resolution.x/resolution.y;\n\nvec3 ang=vec3(cameraRotation.z,cameraRotation.x,cameraRotation.y);\nvec3 ori=vec3(cameraPosition.x,cameraPosition.y,-cameraPosition.z);\nvec3 dir=normalize(vec3(uv.xy,-3.0));\ndir=normalize(dir)*fromEuler(ang);\n\nvec3 p;\nheightMapTracing(ori,dir,p);\nvec3 dist=p-ori;\nvec3 n=getNormal(p,dot(dist,dist)*EPSILON_NRM);\nvec3 light=normalize(vec3(0.0,1.0,0.8));\n\nfloat seaFact=clamp(max(ori.y,0.0),0.0,1.0);\nvec3 position=texture2D(positionSampler,vUV).rgb;\nvec3 baseColor=texture2D(textureSampler,vUV).rgb;\nvec3 color=baseColor;\nif (max(position.y,0.0)<p.y)\n{\n\ncolor=mix(\nbaseColor,\ngetSeaColor(p,n,light,dir,dist),\npow(smoothstep(0.0,-0.05,dir.y),0.3)\n)*seaFact;\n}\ncolor=mix(\ncolor,\nbaseColor*SEA_BASE+diffuse(n,n,80.0)*SEA_WATER_COLOR*0.12,\n1.0-seaFact\n);\n\ngl_FragColor=vec4(pow(color,vec3(0.75)),1.0);\n#endif\n}\n";
  876. babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__["Effect"].ShadersStore[name] = shader;
  877. /** @hidden */
  878. var oceanPostProcessPixelShader = { name: name, shader: shader };
  879. /***/ }),
  880. /***/ "./ocean/oceanPostProcess.ts":
  881. /*!***********************************!*\
  882. !*** ./ocean/oceanPostProcess.ts ***!
  883. \***********************************/
  884. /*! exports provided: OceanPostProcess */
  885. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  886. "use strict";
  887. __webpack_require__.r(__webpack_exports__);
  888. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "OceanPostProcess", function() { return OceanPostProcess; });
  889. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  890. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Materials/Textures/texture */ "babylonjs/Materials/Textures/texture");
  891. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_1__);
  892. /* harmony import */ var _oceanPostProcess_fragment__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./oceanPostProcess.fragment */ "./ocean/oceanPostProcess.fragment.ts");
  893. /**
  894. * OceanPostProcess helps rendering an infinite ocean surface that can reflect and refract environment.
  895. *
  896. * Simmply add it to your scene and let the nerd that lives in you have fun.
  897. * Example usage:
  898. * var pp = new OceanPostProcess("myOcean", camera);
  899. * pp.reflectionEnabled = true;
  900. * pp.refractionEnabled = true;
  901. */
  902. var OceanPostProcess = /** @class */ (function (_super) {
  903. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(OceanPostProcess, _super);
  904. /**
  905. * Instantiates a new Ocean Post Process.
  906. * @param name the name to give to the postprocess.
  907. * @camera the camera to apply the post process to.
  908. * @param options optional object following the IOceanPostProcessOptions format used to customize reflection and refraction render targets sizes.
  909. */
  910. function OceanPostProcess(name, camera, options) {
  911. if (options === void 0) { options = {}; }
  912. var _this = _super.call(this, name, "oceanPostProcess", ["time", "resolution", "cameraPosition", "cameraRotation"], ["positionSampler", "reflectionSampler", "refractionSampler"], {
  913. width: camera.getEngine().getRenderWidth(),
  914. height: camera.getEngine().getRenderHeight()
  915. }, camera, babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_1__["Texture"].TRILINEAR_SAMPLINGMODE, camera.getEngine(), true) || this;
  916. _this._time = 0;
  917. _this._cameraRotation = babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  918. _this._cameraViewMatrix = babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Identity();
  919. _this._reflectionEnabled = false;
  920. _this._refractionEnabled = false;
  921. // Get geometry shader
  922. _this._geometryRenderer = camera.getScene().enableGeometryBufferRenderer(1.0);
  923. if (_this._geometryRenderer && _this._geometryRenderer.isSupported) {
  924. // Eanble position buffer
  925. _this._geometryRenderer.enablePosition = true;
  926. // Create mirror textures
  927. _this.reflectionTexture = new babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_1__["MirrorTexture"]("oceanPostProcessReflection", options.reflectionSize || { width: 512, height: 512 }, camera.getScene());
  928. _this.reflectionTexture.mirrorPlane = babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_1__["Plane"].FromPositionAndNormal(babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), new babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, -1, 0));
  929. _this.refractionTexture = new babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_1__["RenderTargetTexture"]("oceanPostProcessRefraction", options.refractionSize || { width: 512, height: 512 }, camera.getScene());
  930. }
  931. else {
  932. _this.updateEffect("#define NOT_SUPPORTED\n");
  933. }
  934. // On apply the post-process
  935. _this.onApply = function (effect) {
  936. if (!_this._geometryRenderer || !_this._geometryRenderer.isSupported) {
  937. return;
  938. }
  939. var engine = camera.getEngine();
  940. var scene = camera.getScene();
  941. _this._time += engine.getDeltaTime() * 0.001;
  942. effect.setFloat("time", _this._time);
  943. effect.setVector2("resolution", new babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_1__["Vector2"](engine.getRenderWidth(), engine.getRenderHeight()));
  944. if (scene) {
  945. // Position
  946. effect.setVector3("cameraPosition", camera.globalPosition);
  947. // Rotation
  948. _this._computeCameraRotation(camera);
  949. effect.setVector3("cameraRotation", _this._cameraRotation);
  950. // Samplers
  951. effect.setTexture("positionSampler", _this._geometryRenderer.getGBuffer().textures[2]);
  952. if (_this._reflectionEnabled) {
  953. effect.setTexture("reflectionSampler", _this.reflectionTexture);
  954. }
  955. if (_this._refractionEnabled) {
  956. effect.setTexture("refractionSampler", _this.refractionTexture);
  957. }
  958. }
  959. };
  960. return _this;
  961. }
  962. Object.defineProperty(OceanPostProcess.prototype, "reflectionEnabled", {
  963. /**
  964. * Gets a boolean indicating if the real-time reflection is enabled on the ocean.
  965. */
  966. get: function () {
  967. return this._reflectionEnabled;
  968. },
  969. /**
  970. * Sets weither or not the real-time reflection is enabled on the ocean.
  971. * Is set to true, the reflection mirror texture will be used as reflection texture.
  972. */
  973. set: function (enabled) {
  974. if (this._reflectionEnabled === enabled) {
  975. return;
  976. }
  977. this._reflectionEnabled = enabled;
  978. this.updateEffect(this._getDefines());
  979. // Remove or add custom render target
  980. var customRenderTargets = this.getCamera().getScene().customRenderTargets;
  981. if (!enabled) {
  982. var index = customRenderTargets.indexOf(this.reflectionTexture);
  983. if (index !== -1) {
  984. customRenderTargets.splice(index, 1);
  985. }
  986. }
  987. else {
  988. customRenderTargets.push(this.reflectionTexture);
  989. }
  990. },
  991. enumerable: true,
  992. configurable: true
  993. });
  994. Object.defineProperty(OceanPostProcess.prototype, "refractionEnabled", {
  995. /**
  996. * Gets a boolean indicating if the real-time refraction is enabled on the ocean.
  997. */
  998. get: function () {
  999. return this._refractionEnabled;
  1000. },
  1001. /**
  1002. * Sets weither or not the real-time refraction is enabled on the ocean.
  1003. * Is set to true, the refraction render target texture will be used as refraction texture.
  1004. */
  1005. set: function (enabled) {
  1006. if (this._refractionEnabled === enabled) {
  1007. return;
  1008. }
  1009. this._refractionEnabled = enabled;
  1010. this.updateEffect(this._getDefines());
  1011. // Remove or add custom render target
  1012. var customRenderTargets = this.getCamera().getScene().customRenderTargets;
  1013. if (!enabled) {
  1014. var index = customRenderTargets.indexOf(this.refractionTexture);
  1015. if (index !== -1) {
  1016. customRenderTargets.splice(index, 1);
  1017. }
  1018. }
  1019. else {
  1020. customRenderTargets.push(this.refractionTexture);
  1021. }
  1022. },
  1023. enumerable: true,
  1024. configurable: true
  1025. });
  1026. Object.defineProperty(OceanPostProcess.prototype, "isSupported", {
  1027. /**
  1028. * Gets wether or not the post-processes is supported by the running hardware.
  1029. * This requires draw buffer supports.
  1030. */
  1031. get: function () {
  1032. return this._geometryRenderer !== null && this._geometryRenderer.isSupported;
  1033. },
  1034. enumerable: true,
  1035. configurable: true
  1036. });
  1037. /**
  1038. * Returns the appropriate defines according to the current configuration.
  1039. */
  1040. OceanPostProcess.prototype._getDefines = function () {
  1041. var defines = [];
  1042. if (this._reflectionEnabled) {
  1043. defines.push("#define REFLECTION_ENABLED");
  1044. }
  1045. if (this._refractionEnabled) {
  1046. defines.push("#define REFRACTION_ENABLED");
  1047. }
  1048. return defines.join("\n");
  1049. };
  1050. /**
  1051. * Computes the current camera rotation as the shader requires a camera rotation.
  1052. */
  1053. OceanPostProcess.prototype._computeCameraRotation = function (camera) {
  1054. camera.upVector.normalize();
  1055. var target = camera.getTarget();
  1056. camera._initialFocalDistance = target.subtract(camera.position).length();
  1057. if (camera.position.z === target.z) {
  1058. camera.position.z += babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_1__["Epsilon"];
  1059. }
  1060. var direction = target.subtract(camera.position);
  1061. camera._viewMatrix.invertToRef(this._cameraViewMatrix);
  1062. this._cameraRotation.x = Math.atan(this._cameraViewMatrix.m[6] / this._cameraViewMatrix.m[10]);
  1063. if (direction.x >= 0.0) {
  1064. this._cameraRotation.y = (-Math.atan(direction.z / direction.x) + Math.PI / 2.0);
  1065. }
  1066. else {
  1067. this._cameraRotation.y = (-Math.atan(direction.z / direction.x) - Math.PI / 2.0);
  1068. }
  1069. this._cameraRotation.z = 0;
  1070. if (isNaN(this._cameraRotation.x)) {
  1071. this._cameraRotation.x = 0;
  1072. }
  1073. if (isNaN(this._cameraRotation.y)) {
  1074. this._cameraRotation.y = 0;
  1075. }
  1076. if (isNaN(this._cameraRotation.z)) {
  1077. this._cameraRotation.z = 0;
  1078. }
  1079. };
  1080. return OceanPostProcess;
  1081. }(babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_1__["PostProcess"]));
  1082. /***/ }),
  1083. /***/ "babylonjs/Materials/Textures/texture":
  1084. /*!****************************************************************************************************!*\
  1085. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  1086. \****************************************************************************************************/
  1087. /*! no static exports found */
  1088. /***/ (function(module, exports) {
  1089. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Materials_Textures_texture__;
  1090. /***/ })
  1091. /******/ });
  1092. });
  1093. //# sourceMappingURL=babylonjs.postProcess.js.map