babylonjs.postProcess.js 67 KB

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