babylon.starfieldProceduralTexture.js 11 KB

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