babylon.starfieldProceduralTexture.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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["PROCEDURALTEXTURESLIB"] = 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. /***/ "../Tools/Gulp/node_modules/webpack/buildin/global.js":
  99. /*!************************************************************!*\
  100. !*** ../Tools/Gulp/node_modules/webpack/buildin/global.js ***!
  101. \************************************************************/
  102. /*! no static exports found */
  103. /***/ (function(module, exports) {
  104. var g;
  105. // This works in non-strict mode
  106. g = (function() {
  107. return this;
  108. })();
  109. try {
  110. // This works if eval is allowed (see CSP)
  111. g = g || Function("return this")() || (1, eval)("this");
  112. } catch (e) {
  113. // This works if the window reference is available
  114. if (typeof window === "object") g = window;
  115. }
  116. // g can still be undefined, but nothing to do about it...
  117. // We return undefined, instead of nothing here, so it's
  118. // easier to handle this case. if(!global) { ...}
  119. module.exports = g;
  120. /***/ }),
  121. /***/ "./legacy/legacy-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__(/*! ./../../Tools/Gulp/node_modules/webpack/buildin/global.js */ "../Tools/Gulp/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.fx":
  161. /*!**************************************************************!*\
  162. !*** ./src/starfield/starfieldProceduralTexture.fragment.fx ***!
  163. \**************************************************************/
  164. /*! no static exports found */
  165. /***/ (function(module, exports) {
  166. module.exports = "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}"
  167. /***/ }),
  168. /***/ "./src/starfield/starfieldProceduralTexture.ts":
  169. /*!*****************************************************!*\
  170. !*** ./src/starfield/starfieldProceduralTexture.ts ***!
  171. \*****************************************************/
  172. /*! no static exports found */
  173. /***/ (function(module, exports, __webpack_require__) {
  174. "use strict";
  175. var __extends = (this && this.__extends) || (function () {
  176. var extendStatics = function (d, b) {
  177. extendStatics = Object.setPrototypeOf ||
  178. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  179. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  180. return extendStatics(d, b);
  181. }
  182. return function (d, b) {
  183. extendStatics(d, b);
  184. function __() { this.constructor = d; }
  185. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  186. };
  187. })();
  188. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  189. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  190. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  191. 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;
  192. return c > 3 && r && Object.defineProperty(target, key, r), r;
  193. };
  194. Object.defineProperty(exports, "__esModule", { value: true });
  195. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  196. babylonjs_1.Effect.ShadersStore["starfieldProceduralTexturePixelShader"] = __webpack_require__(/*! ./starfieldProceduralTexture.fragment.fx */ "./src/starfield/starfieldProceduralTexture.fragment.fx");
  197. var StarfieldProceduralTexture = /** @class */ (function (_super) {
  198. __extends(StarfieldProceduralTexture, _super);
  199. function StarfieldProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  200. var _this = _super.call(this, name, size, "starfieldProceduralTexture", scene, fallbackTexture, generateMipMaps) || this;
  201. _this._time = 1;
  202. _this._alpha = 0.5;
  203. _this._beta = 0.8;
  204. _this._zoom = 0.8;
  205. _this._formuparam = 0.53;
  206. _this._stepsize = 0.1;
  207. _this._tile = 0.850;
  208. _this._brightness = 0.0015;
  209. _this._darkmatter = 0.400;
  210. _this._distfading = 0.730;
  211. _this._saturation = 0.850;
  212. _this.updateShaderUniforms();
  213. return _this;
  214. }
  215. StarfieldProceduralTexture.prototype.updateShaderUniforms = function () {
  216. this.setFloat("time", this._time);
  217. this.setFloat("alpha", this._alpha);
  218. this.setFloat("beta", this._beta);
  219. this.setFloat("zoom", this._zoom);
  220. this.setFloat("formuparam", this._formuparam);
  221. this.setFloat("stepsize", this._stepsize);
  222. this.setFloat("tile", this._tile);
  223. this.setFloat("brightness", this._brightness);
  224. this.setFloat("darkmatter", this._darkmatter);
  225. this.setFloat("distfading", this._distfading);
  226. this.setFloat("saturation", this._saturation);
  227. };
  228. Object.defineProperty(StarfieldProceduralTexture.prototype, "time", {
  229. get: function () {
  230. return this._time;
  231. },
  232. set: function (value) {
  233. this._time = value;
  234. this.updateShaderUniforms();
  235. },
  236. enumerable: true,
  237. configurable: true
  238. });
  239. Object.defineProperty(StarfieldProceduralTexture.prototype, "alpha", {
  240. get: function () {
  241. return this._alpha;
  242. },
  243. set: function (value) {
  244. this._alpha = value;
  245. this.updateShaderUniforms();
  246. },
  247. enumerable: true,
  248. configurable: true
  249. });
  250. Object.defineProperty(StarfieldProceduralTexture.prototype, "beta", {
  251. get: function () {
  252. return this._beta;
  253. },
  254. set: function (value) {
  255. this._beta = value;
  256. this.updateShaderUniforms();
  257. },
  258. enumerable: true,
  259. configurable: true
  260. });
  261. Object.defineProperty(StarfieldProceduralTexture.prototype, "formuparam", {
  262. get: function () {
  263. return this._formuparam;
  264. },
  265. set: function (value) {
  266. this._formuparam = value;
  267. this.updateShaderUniforms();
  268. },
  269. enumerable: true,
  270. configurable: true
  271. });
  272. Object.defineProperty(StarfieldProceduralTexture.prototype, "stepsize", {
  273. get: function () {
  274. return this._stepsize;
  275. },
  276. set: function (value) {
  277. this._stepsize = value;
  278. this.updateShaderUniforms();
  279. },
  280. enumerable: true,
  281. configurable: true
  282. });
  283. Object.defineProperty(StarfieldProceduralTexture.prototype, "zoom", {
  284. get: function () {
  285. return this._zoom;
  286. },
  287. set: function (value) {
  288. this._zoom = value;
  289. this.updateShaderUniforms();
  290. },
  291. enumerable: true,
  292. configurable: true
  293. });
  294. Object.defineProperty(StarfieldProceduralTexture.prototype, "tile", {
  295. get: function () {
  296. return this._tile;
  297. },
  298. set: function (value) {
  299. this._tile = value;
  300. this.updateShaderUniforms();
  301. },
  302. enumerable: true,
  303. configurable: true
  304. });
  305. Object.defineProperty(StarfieldProceduralTexture.prototype, "brightness", {
  306. get: function () {
  307. return this._brightness;
  308. },
  309. set: function (value) {
  310. this._brightness = value;
  311. this.updateShaderUniforms();
  312. },
  313. enumerable: true,
  314. configurable: true
  315. });
  316. Object.defineProperty(StarfieldProceduralTexture.prototype, "darkmatter", {
  317. get: function () {
  318. return this._darkmatter;
  319. },
  320. set: function (value) {
  321. this._darkmatter = value;
  322. this.updateShaderUniforms();
  323. },
  324. enumerable: true,
  325. configurable: true
  326. });
  327. Object.defineProperty(StarfieldProceduralTexture.prototype, "distfading", {
  328. get: function () {
  329. return this._distfading;
  330. },
  331. set: function (value) {
  332. this._distfading = value;
  333. this.updateShaderUniforms();
  334. },
  335. enumerable: true,
  336. configurable: true
  337. });
  338. Object.defineProperty(StarfieldProceduralTexture.prototype, "saturation", {
  339. get: function () {
  340. return this._saturation;
  341. },
  342. set: function (value) {
  343. this._saturation = value;
  344. this.updateShaderUniforms();
  345. },
  346. enumerable: true,
  347. configurable: true
  348. });
  349. /**
  350. * Serializes this starfield procedural texture
  351. * @returns a serialized starfield procedural texture object
  352. */
  353. StarfieldProceduralTexture.prototype.serialize = function () {
  354. var serializationObject = babylonjs_1.SerializationHelper.Serialize(this, _super.prototype.serialize.call(this));
  355. serializationObject.customType = "BABYLON.StarfieldProceduralTexture";
  356. return serializationObject;
  357. };
  358. /**
  359. * Creates a Starfield Procedural Texture from parsed startfield procedural texture data
  360. * @param parsedTexture defines parsed texture data
  361. * @param scene defines the current scene
  362. * @param rootUrl defines the root URL containing startfield procedural texture information
  363. * @returns a parsed Starfield Procedural Texture
  364. */
  365. StarfieldProceduralTexture.Parse = function (parsedTexture, scene, rootUrl) {
  366. var texture = babylonjs_1.SerializationHelper.Parse(function () { return new StarfieldProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps); }, parsedTexture, scene, rootUrl);
  367. return texture;
  368. };
  369. __decorate([
  370. babylonjs_1.serialize()
  371. ], StarfieldProceduralTexture.prototype, "time", null);
  372. __decorate([
  373. babylonjs_1.serialize()
  374. ], StarfieldProceduralTexture.prototype, "alpha", null);
  375. __decorate([
  376. babylonjs_1.serialize()
  377. ], StarfieldProceduralTexture.prototype, "beta", null);
  378. __decorate([
  379. babylonjs_1.serialize()
  380. ], StarfieldProceduralTexture.prototype, "formuparam", null);
  381. __decorate([
  382. babylonjs_1.serialize()
  383. ], StarfieldProceduralTexture.prototype, "stepsize", null);
  384. __decorate([
  385. babylonjs_1.serialize()
  386. ], StarfieldProceduralTexture.prototype, "zoom", null);
  387. __decorate([
  388. babylonjs_1.serialize()
  389. ], StarfieldProceduralTexture.prototype, "tile", null);
  390. __decorate([
  391. babylonjs_1.serialize()
  392. ], StarfieldProceduralTexture.prototype, "brightness", null);
  393. __decorate([
  394. babylonjs_1.serialize()
  395. ], StarfieldProceduralTexture.prototype, "darkmatter", null);
  396. __decorate([
  397. babylonjs_1.serialize()
  398. ], StarfieldProceduralTexture.prototype, "distfading", null);
  399. __decorate([
  400. babylonjs_1.serialize()
  401. ], StarfieldProceduralTexture.prototype, "saturation", null);
  402. return StarfieldProceduralTexture;
  403. }(babylonjs_1.ProceduralTexture));
  404. exports.StarfieldProceduralTexture = StarfieldProceduralTexture;
  405. /***/ }),
  406. /***/ "babylonjs":
  407. /*!****************************************************************************************************!*\
  408. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  409. \****************************************************************************************************/
  410. /*! no static exports found */
  411. /***/ (function(module, exports) {
  412. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs__;
  413. /***/ })
  414. /******/ });
  415. });
  416. //# sourceMappingURL=babylon.starfieldProceduralTexture.js.map