babylon.starfieldProceduralTexture.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("babylonjs"));
  4. else if(typeof define === 'function' && define.amd)
  5. define("babylonjs-procedural-textures", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-procedural-textures"] = factory(require("babylonjs"));
  8. else
  9. root["PTLIB"] = factory(root["BABYLON"]);
  10. })(window, function(__WEBPACK_EXTERNAL_MODULE_babylonjs__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = "./legacy/legacy-starfield.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../node_modules/webpack/buildin/global.js":
  99. /*!*************************************************!*\
  100. !*** ../node_modules/webpack/buildin/global.js ***!
  101. \*************************************************/
  102. /*! no static exports found */
  103. /***/ (function(module, exports) {
  104. var g;
  105. // This works in non-strict mode
  106. g = (function() {
  107. return this;
  108. })();
  109. try {
  110. // This works if eval is allowed (see CSP)
  111. g = g || Function("return this")() || (1, eval)("this");
  112. } catch (e) {
  113. // This works if the window reference is available
  114. if (typeof window === "object") g = window;
  115. }
  116. // g can still be undefined, but nothing to do about it...
  117. // We return undefined, instead of nothing here, so it's
  118. // easier to handle this case. if(!global) { ...}
  119. module.exports = g;
  120. /***/ }),
  121. /***/ "./legacy/legacy-starfield.ts":
  122. /*!************************************!*\
  123. !*** ./legacy/legacy-starfield.ts ***!
  124. \************************************/
  125. /*! no static exports found */
  126. /***/ (function(module, exports, __webpack_require__) {
  127. "use strict";
  128. /* WEBPACK VAR INJECTION */(function(global) {
  129. function __export(m) {
  130. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  131. }
  132. Object.defineProperty(exports, "__esModule", { value: true });
  133. var proceduralTexture = __webpack_require__(/*! ../src/starfield */ "./src/starfield/index.ts");
  134. /**
  135. * This is the entry point for the UMD module.
  136. * The entry point for a future ESM package should be index.ts
  137. */
  138. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  139. if (typeof globalObject !== "undefined") {
  140. for (var key in proceduralTexture) {
  141. globalObject.BABYLON[key] = proceduralTexture[key];
  142. }
  143. }
  144. __export(__webpack_require__(/*! ../src/starfield */ "./src/starfield/index.ts"));
  145. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../node_modules/webpack/buildin/global.js */ "../node_modules/webpack/buildin/global.js")))
  146. /***/ }),
  147. /***/ "./src/starfield/index.ts":
  148. /*!********************************!*\
  149. !*** ./src/starfield/index.ts ***!
  150. \********************************/
  151. /*! no static exports found */
  152. /***/ (function(module, exports, __webpack_require__) {
  153. "use strict";
  154. function __export(m) {
  155. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  156. }
  157. Object.defineProperty(exports, "__esModule", { value: true });
  158. __export(__webpack_require__(/*! ./starfieldProceduralTexture */ "./src/starfield/starfieldProceduralTexture.ts"));
  159. /***/ }),
  160. /***/ "./src/starfield/starfieldProceduralTexture.fragment.ts":
  161. /*!**************************************************************!*\
  162. !*** ./src/starfield/starfieldProceduralTexture.fragment.ts ***!
  163. \**************************************************************/
  164. /*! no static exports found */
  165. /***/ (function(module, exports, __webpack_require__) {
  166. "use strict";
  167. Object.defineProperty(exports, "__esModule", { value: true });
  168. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  169. var name = 'starfieldProceduralTexturePixelShader';
  170. exports.name = name;
  171. var shader = "precision highp float;\n\n#define volsteps 20\n#define iterations 15\nvarying vec2 vPosition;\nvarying vec2 vUV;\nuniform float time;\nuniform float alpha;\nuniform float beta;\nuniform float zoom;\nuniform float formuparam;\nuniform float stepsize;\nuniform float tile;\nuniform float brightness;\nuniform float darkmatter;\nuniform float distfading;\nuniform float saturation;\nvoid main()\n{\nvec3 dir=vec3(vUV*zoom,1.);\nfloat localTime=time*0.0001;\n\nmat2 rot1=mat2(cos(alpha),sin(alpha),-sin(alpha),cos(alpha));\nmat2 rot2=mat2(cos(beta),sin(beta),-sin(beta),cos(beta));\ndir.xz*=rot1;\ndir.xy*=rot2;\nvec3 from=vec3(1.,.5,0.5);\nfrom+=vec3(-2.,localTime*2.,localTime);\nfrom.xz*=rot1;\nfrom.xy*=rot2;\n\nfloat s=0.1,fade=1.;\nvec3 v=vec3(0.);\nfor (int r=0; r<volsteps; r++) {\nvec3 p=from+s*dir*.5;\np=abs(vec3(tile)-mod(p,vec3(tile*2.)));\nfloat pa,a=pa=0.;\nfor (int i=0; i<iterations; i++) {\np=abs(p)/dot(p,p)-formuparam;\na+=abs(length(p)-pa);\npa=length(p);\n}\nfloat dm=max(0.,darkmatter-a*a*.001);\na*=a*a;\nif (r>6) fade*=1.-dm;\n\nv+=fade;\nv+=vec3(s,s*s,s*s*s*s)*a*brightness*fade;\nfade*=distfading;\ns+=stepsize;\n}\nv=mix(vec3(length(v)),v,saturation);\ngl_FragColor=vec4(v*.01,1.);\n}";
  172. exports.shader = shader;
  173. babylonjs_1.Effect.ShadersStore[name] = shader;
  174. /***/ }),
  175. /***/ "./src/starfield/starfieldProceduralTexture.ts":
  176. /*!*****************************************************!*\
  177. !*** ./src/starfield/starfieldProceduralTexture.ts ***!
  178. \*****************************************************/
  179. /*! no static exports found */
  180. /***/ (function(module, exports, __webpack_require__) {
  181. "use strict";
  182. var __extends = (this && this.__extends) || (function () {
  183. var extendStatics = function (d, b) {
  184. extendStatics = Object.setPrototypeOf ||
  185. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  186. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  187. return extendStatics(d, b);
  188. }
  189. return function (d, b) {
  190. extendStatics(d, b);
  191. function __() { this.constructor = d; }
  192. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  193. };
  194. })();
  195. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  196. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  197. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  198. 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;
  199. return c > 3 && r && Object.defineProperty(target, key, r), r;
  200. };
  201. Object.defineProperty(exports, "__esModule", { value: true });
  202. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  203. __webpack_require__(/*! ./starfieldProceduralTexture.fragment */ "./src/starfield/starfieldProceduralTexture.fragment.ts");
  204. var StarfieldProceduralTexture = /** @class */ (function (_super) {
  205. __extends(StarfieldProceduralTexture, _super);
  206. function StarfieldProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  207. var _this = _super.call(this, name, size, "starfieldProceduralTexture", scene, fallbackTexture, generateMipMaps) || this;
  208. _this._time = 1;
  209. _this._alpha = 0.5;
  210. _this._beta = 0.8;
  211. _this._zoom = 0.8;
  212. _this._formuparam = 0.53;
  213. _this._stepsize = 0.1;
  214. _this._tile = 0.850;
  215. _this._brightness = 0.0015;
  216. _this._darkmatter = 0.400;
  217. _this._distfading = 0.730;
  218. _this._saturation = 0.850;
  219. _this.updateShaderUniforms();
  220. return _this;
  221. }
  222. StarfieldProceduralTexture.prototype.updateShaderUniforms = function () {
  223. this.setFloat("time", this._time);
  224. this.setFloat("alpha", this._alpha);
  225. this.setFloat("beta", this._beta);
  226. this.setFloat("zoom", this._zoom);
  227. this.setFloat("formuparam", this._formuparam);
  228. this.setFloat("stepsize", this._stepsize);
  229. this.setFloat("tile", this._tile);
  230. this.setFloat("brightness", this._brightness);
  231. this.setFloat("darkmatter", this._darkmatter);
  232. this.setFloat("distfading", this._distfading);
  233. this.setFloat("saturation", this._saturation);
  234. };
  235. Object.defineProperty(StarfieldProceduralTexture.prototype, "time", {
  236. get: function () {
  237. return this._time;
  238. },
  239. set: function (value) {
  240. this._time = value;
  241. this.updateShaderUniforms();
  242. },
  243. enumerable: true,
  244. configurable: true
  245. });
  246. Object.defineProperty(StarfieldProceduralTexture.prototype, "alpha", {
  247. get: function () {
  248. return this._alpha;
  249. },
  250. set: function (value) {
  251. this._alpha = value;
  252. this.updateShaderUniforms();
  253. },
  254. enumerable: true,
  255. configurable: true
  256. });
  257. Object.defineProperty(StarfieldProceduralTexture.prototype, "beta", {
  258. get: function () {
  259. return this._beta;
  260. },
  261. set: function (value) {
  262. this._beta = value;
  263. this.updateShaderUniforms();
  264. },
  265. enumerable: true,
  266. configurable: true
  267. });
  268. Object.defineProperty(StarfieldProceduralTexture.prototype, "formuparam", {
  269. get: function () {
  270. return this._formuparam;
  271. },
  272. set: function (value) {
  273. this._formuparam = value;
  274. this.updateShaderUniforms();
  275. },
  276. enumerable: true,
  277. configurable: true
  278. });
  279. Object.defineProperty(StarfieldProceduralTexture.prototype, "stepsize", {
  280. get: function () {
  281. return this._stepsize;
  282. },
  283. set: function (value) {
  284. this._stepsize = value;
  285. this.updateShaderUniforms();
  286. },
  287. enumerable: true,
  288. configurable: true
  289. });
  290. Object.defineProperty(StarfieldProceduralTexture.prototype, "zoom", {
  291. get: function () {
  292. return this._zoom;
  293. },
  294. set: function (value) {
  295. this._zoom = value;
  296. this.updateShaderUniforms();
  297. },
  298. enumerable: true,
  299. configurable: true
  300. });
  301. Object.defineProperty(StarfieldProceduralTexture.prototype, "tile", {
  302. get: function () {
  303. return this._tile;
  304. },
  305. set: function (value) {
  306. this._tile = value;
  307. this.updateShaderUniforms();
  308. },
  309. enumerable: true,
  310. configurable: true
  311. });
  312. Object.defineProperty(StarfieldProceduralTexture.prototype, "brightness", {
  313. get: function () {
  314. return this._brightness;
  315. },
  316. set: function (value) {
  317. this._brightness = value;
  318. this.updateShaderUniforms();
  319. },
  320. enumerable: true,
  321. configurable: true
  322. });
  323. Object.defineProperty(StarfieldProceduralTexture.prototype, "darkmatter", {
  324. get: function () {
  325. return this._darkmatter;
  326. },
  327. set: function (value) {
  328. this._darkmatter = value;
  329. this.updateShaderUniforms();
  330. },
  331. enumerable: true,
  332. configurable: true
  333. });
  334. Object.defineProperty(StarfieldProceduralTexture.prototype, "distfading", {
  335. get: function () {
  336. return this._distfading;
  337. },
  338. set: function (value) {
  339. this._distfading = value;
  340. this.updateShaderUniforms();
  341. },
  342. enumerable: true,
  343. configurable: true
  344. });
  345. Object.defineProperty(StarfieldProceduralTexture.prototype, "saturation", {
  346. get: function () {
  347. return this._saturation;
  348. },
  349. set: function (value) {
  350. this._saturation = value;
  351. this.updateShaderUniforms();
  352. },
  353. enumerable: true,
  354. configurable: true
  355. });
  356. /**
  357. * Serializes this starfield procedural texture
  358. * @returns a serialized starfield procedural texture object
  359. */
  360. StarfieldProceduralTexture.prototype.serialize = function () {
  361. var serializationObject = babylonjs_1.SerializationHelper.Serialize(this, _super.prototype.serialize.call(this));
  362. serializationObject.customType = "BABYLON.StarfieldProceduralTexture";
  363. return serializationObject;
  364. };
  365. /**
  366. * Creates a Starfield Procedural Texture from parsed startfield procedural texture data
  367. * @param parsedTexture defines parsed texture data
  368. * @param scene defines the current scene
  369. * @param rootUrl defines the root URL containing startfield procedural texture information
  370. * @returns a parsed Starfield Procedural Texture
  371. */
  372. StarfieldProceduralTexture.Parse = function (parsedTexture, scene, rootUrl) {
  373. var texture = babylonjs_1.SerializationHelper.Parse(function () { return new StarfieldProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps); }, parsedTexture, scene, rootUrl);
  374. return texture;
  375. };
  376. __decorate([
  377. babylonjs_1.serialize()
  378. ], StarfieldProceduralTexture.prototype, "time", null);
  379. __decorate([
  380. babylonjs_1.serialize()
  381. ], StarfieldProceduralTexture.prototype, "alpha", null);
  382. __decorate([
  383. babylonjs_1.serialize()
  384. ], StarfieldProceduralTexture.prototype, "beta", null);
  385. __decorate([
  386. babylonjs_1.serialize()
  387. ], StarfieldProceduralTexture.prototype, "formuparam", null);
  388. __decorate([
  389. babylonjs_1.serialize()
  390. ], StarfieldProceduralTexture.prototype, "stepsize", null);
  391. __decorate([
  392. babylonjs_1.serialize()
  393. ], StarfieldProceduralTexture.prototype, "zoom", null);
  394. __decorate([
  395. babylonjs_1.serialize()
  396. ], StarfieldProceduralTexture.prototype, "tile", null);
  397. __decorate([
  398. babylonjs_1.serialize()
  399. ], StarfieldProceduralTexture.prototype, "brightness", null);
  400. __decorate([
  401. babylonjs_1.serialize()
  402. ], StarfieldProceduralTexture.prototype, "darkmatter", null);
  403. __decorate([
  404. babylonjs_1.serialize()
  405. ], StarfieldProceduralTexture.prototype, "distfading", null);
  406. __decorate([
  407. babylonjs_1.serialize()
  408. ], StarfieldProceduralTexture.prototype, "saturation", null);
  409. return StarfieldProceduralTexture;
  410. }(babylonjs_1.ProceduralTexture));
  411. exports.StarfieldProceduralTexture = StarfieldProceduralTexture;
  412. /***/ }),
  413. /***/ "babylonjs":
  414. /*!****************************************************************************************************!*\
  415. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  416. \****************************************************************************************************/
  417. /*! no static exports found */
  418. /***/ (function(module, exports) {
  419. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs__;
  420. /***/ })
  421. /******/ });
  422. });
  423. //# sourceMappingURL=babylon.starfieldProceduralTexture.js.map