babylon.starfieldProceduralTexture.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = Object.setPrototypeOf ||
  4. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6. return function (d, b) {
  7. extendStatics(d, b);
  8. function __() { this.constructor = d; }
  9. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10. };
  11. })();
  12. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  13. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  15. 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;
  16. return c > 3 && r && Object.defineProperty(target, key, r), r;
  17. };
  18. var BABYLON;
  19. (function (BABYLON) {
  20. var StarfieldProceduralTexture = /** @class */ (function (_super) {
  21. __extends(StarfieldProceduralTexture, _super);
  22. function StarfieldProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  23. var _this = _super.call(this, name, size, "starfieldProceduralTexture", scene, fallbackTexture, generateMipMaps) || this;
  24. _this._time = 1;
  25. _this._alpha = 0.5;
  26. _this._beta = 0.8;
  27. _this._zoom = 0.8;
  28. _this._formuparam = 0.53;
  29. _this._stepsize = 0.1;
  30. _this._tile = 0.850;
  31. _this._brightness = 0.0015;
  32. _this._darkmatter = 0.400;
  33. _this._distfading = 0.730;
  34. _this._saturation = 0.850;
  35. _this.updateShaderUniforms();
  36. return _this;
  37. }
  38. StarfieldProceduralTexture.prototype.updateShaderUniforms = function () {
  39. this.setFloat("time", this._time);
  40. this.setFloat("alpha", this._alpha);
  41. this.setFloat("beta", this._beta);
  42. this.setFloat("zoom", this._zoom);
  43. this.setFloat("formuparam", this._formuparam);
  44. this.setFloat("stepsize", this._stepsize);
  45. this.setFloat("tile", this._tile);
  46. this.setFloat("brightness", this._brightness);
  47. this.setFloat("darkmatter", this._darkmatter);
  48. this.setFloat("distfading", this._distfading);
  49. this.setFloat("saturation", this._saturation);
  50. };
  51. Object.defineProperty(StarfieldProceduralTexture.prototype, "time", {
  52. get: function () {
  53. return this._time;
  54. },
  55. set: function (value) {
  56. this._time = value;
  57. this.updateShaderUniforms();
  58. },
  59. enumerable: true,
  60. configurable: true
  61. });
  62. Object.defineProperty(StarfieldProceduralTexture.prototype, "alpha", {
  63. get: function () {
  64. return this._alpha;
  65. },
  66. set: function (value) {
  67. this._alpha = value;
  68. this.updateShaderUniforms();
  69. },
  70. enumerable: true,
  71. configurable: true
  72. });
  73. Object.defineProperty(StarfieldProceduralTexture.prototype, "beta", {
  74. get: function () {
  75. return this._beta;
  76. },
  77. set: function (value) {
  78. this._beta = value;
  79. this.updateShaderUniforms();
  80. },
  81. enumerable: true,
  82. configurable: true
  83. });
  84. Object.defineProperty(StarfieldProceduralTexture.prototype, "formuparam", {
  85. get: function () {
  86. return this._formuparam;
  87. },
  88. set: function (value) {
  89. this._formuparam = value;
  90. this.updateShaderUniforms();
  91. },
  92. enumerable: true,
  93. configurable: true
  94. });
  95. Object.defineProperty(StarfieldProceduralTexture.prototype, "stepsize", {
  96. get: function () {
  97. return this._stepsize;
  98. },
  99. set: function (value) {
  100. this._stepsize = value;
  101. this.updateShaderUniforms();
  102. },
  103. enumerable: true,
  104. configurable: true
  105. });
  106. Object.defineProperty(StarfieldProceduralTexture.prototype, "zoom", {
  107. get: function () {
  108. return this._zoom;
  109. },
  110. set: function (value) {
  111. this._zoom = value;
  112. this.updateShaderUniforms();
  113. },
  114. enumerable: true,
  115. configurable: true
  116. });
  117. Object.defineProperty(StarfieldProceduralTexture.prototype, "tile", {
  118. get: function () {
  119. return this._tile;
  120. },
  121. set: function (value) {
  122. this._tile = value;
  123. this.updateShaderUniforms();
  124. },
  125. enumerable: true,
  126. configurable: true
  127. });
  128. Object.defineProperty(StarfieldProceduralTexture.prototype, "brightness", {
  129. get: function () {
  130. return this._brightness;
  131. },
  132. set: function (value) {
  133. this._brightness = value;
  134. this.updateShaderUniforms();
  135. },
  136. enumerable: true,
  137. configurable: true
  138. });
  139. Object.defineProperty(StarfieldProceduralTexture.prototype, "darkmatter", {
  140. get: function () {
  141. return this._darkmatter;
  142. },
  143. set: function (value) {
  144. this._darkmatter = value;
  145. this.updateShaderUniforms();
  146. },
  147. enumerable: true,
  148. configurable: true
  149. });
  150. Object.defineProperty(StarfieldProceduralTexture.prototype, "distfading", {
  151. get: function () {
  152. return this._distfading;
  153. },
  154. set: function (value) {
  155. this._distfading = value;
  156. this.updateShaderUniforms();
  157. },
  158. enumerable: true,
  159. configurable: true
  160. });
  161. Object.defineProperty(StarfieldProceduralTexture.prototype, "saturation", {
  162. get: function () {
  163. return this._saturation;
  164. },
  165. set: function (value) {
  166. this._saturation = value;
  167. this.updateShaderUniforms();
  168. },
  169. enumerable: true,
  170. configurable: true
  171. });
  172. /**
  173. * Serializes this starfield procedural texture
  174. * @returns a serialized starfield procedural texture object
  175. */
  176. StarfieldProceduralTexture.prototype.serialize = function () {
  177. var serializationObject = BABYLON.SerializationHelper.Serialize(this, _super.prototype.serialize.call(this));
  178. serializationObject.customType = "BABYLON.StarfieldProceduralTexture";
  179. return serializationObject;
  180. };
  181. /**
  182. * Creates a Starfield Procedural Texture from parsed startfield procedural texture data
  183. * @param parsedTexture defines parsed texture data
  184. * @param scene defines the current scene
  185. * @param rootUrl defines the root URL containing startfield procedural texture information
  186. * @returns a parsed Starfield Procedural Texture
  187. */
  188. StarfieldProceduralTexture.Parse = function (parsedTexture, scene, rootUrl) {
  189. var texture = BABYLON.SerializationHelper.Parse(function () { return new StarfieldProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps); }, parsedTexture, scene, rootUrl);
  190. return texture;
  191. };
  192. __decorate([
  193. BABYLON.serialize()
  194. ], StarfieldProceduralTexture.prototype, "time", null);
  195. __decorate([
  196. BABYLON.serialize()
  197. ], StarfieldProceduralTexture.prototype, "alpha", null);
  198. __decorate([
  199. BABYLON.serialize()
  200. ], StarfieldProceduralTexture.prototype, "beta", null);
  201. __decorate([
  202. BABYLON.serialize()
  203. ], StarfieldProceduralTexture.prototype, "formuparam", null);
  204. __decorate([
  205. BABYLON.serialize()
  206. ], StarfieldProceduralTexture.prototype, "stepsize", null);
  207. __decorate([
  208. BABYLON.serialize()
  209. ], StarfieldProceduralTexture.prototype, "zoom", null);
  210. __decorate([
  211. BABYLON.serialize()
  212. ], StarfieldProceduralTexture.prototype, "tile", null);
  213. __decorate([
  214. BABYLON.serialize()
  215. ], StarfieldProceduralTexture.prototype, "brightness", null);
  216. __decorate([
  217. BABYLON.serialize()
  218. ], StarfieldProceduralTexture.prototype, "darkmatter", null);
  219. __decorate([
  220. BABYLON.serialize()
  221. ], StarfieldProceduralTexture.prototype, "distfading", null);
  222. __decorate([
  223. BABYLON.serialize()
  224. ], StarfieldProceduralTexture.prototype, "saturation", null);
  225. return StarfieldProceduralTexture;
  226. }(BABYLON.ProceduralTexture));
  227. BABYLON.StarfieldProceduralTexture = StarfieldProceduralTexture;
  228. })(BABYLON || (BABYLON = {}));
  229. //# sourceMappingURL=babylon.starfieldProceduralTexture.js.map
  230. BABYLON.Effect.ShadersStore['starfieldProceduralTexturePixelShader'] = "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}";