babylonjs.postProcess.js 66 KB

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