babylon.starfieldProceduralTexture.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. "use strict";
  2. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3. var __extends = (this && this.__extends) || (function () {
  4. var 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 function (d, b) {
  8. extendStatics(d, b);
  9. function __() { this.constructor = d; }
  10. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  11. };
  12. })();
  13. var BABYLON;
  14. (function (BABYLON) {
  15. var StarfieldProceduralTexture = /** @class */ (function (_super) {
  16. __extends(StarfieldProceduralTexture, _super);
  17. function StarfieldProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  18. var _this = _super.call(this, name, size, "starfieldProceduralTexture", scene, fallbackTexture, generateMipMaps) || this;
  19. _this._time = 1;
  20. _this._alpha = 0.5;
  21. _this._beta = 0.8;
  22. _this._zoom = 0.8;
  23. _this._formuparam = 0.53;
  24. _this._stepsize = 0.1;
  25. _this._tile = 0.850;
  26. _this._brightness = 0.0015;
  27. _this._darkmatter = 0.400;
  28. _this._distfading = 0.730;
  29. _this._saturation = 0.850;
  30. _this.updateShaderUniforms();
  31. return _this;
  32. }
  33. StarfieldProceduralTexture.prototype.updateShaderUniforms = function () {
  34. this.setFloat("time", this._time);
  35. this.setFloat("alpha", this._alpha);
  36. this.setFloat("beta", this._beta);
  37. this.setFloat("zoom", this._zoom);
  38. this.setFloat("formuparam", this._formuparam);
  39. this.setFloat("stepsize", this._stepsize);
  40. this.setFloat("tile", this._tile);
  41. this.setFloat("brightness", this._brightness);
  42. this.setFloat("darkmatter", this._darkmatter);
  43. this.setFloat("distfading", this._distfading);
  44. this.setFloat("saturation", this._saturation);
  45. };
  46. Object.defineProperty(StarfieldProceduralTexture.prototype, "time", {
  47. get: function () {
  48. return this._time;
  49. },
  50. set: function (value) {
  51. this._time = value;
  52. this.updateShaderUniforms();
  53. },
  54. enumerable: true,
  55. configurable: true
  56. });
  57. Object.defineProperty(StarfieldProceduralTexture.prototype, "alpha", {
  58. get: function () {
  59. return this._alpha;
  60. },
  61. set: function (value) {
  62. this._alpha = value;
  63. this.updateShaderUniforms();
  64. },
  65. enumerable: true,
  66. configurable: true
  67. });
  68. Object.defineProperty(StarfieldProceduralTexture.prototype, "beta", {
  69. get: function () {
  70. return this._beta;
  71. },
  72. set: function (value) {
  73. this._beta = value;
  74. this.updateShaderUniforms();
  75. },
  76. enumerable: true,
  77. configurable: true
  78. });
  79. Object.defineProperty(StarfieldProceduralTexture.prototype, "formuparam", {
  80. get: function () {
  81. return this._formuparam;
  82. },
  83. set: function (value) {
  84. this._formuparam = value;
  85. this.updateShaderUniforms();
  86. },
  87. enumerable: true,
  88. configurable: true
  89. });
  90. Object.defineProperty(StarfieldProceduralTexture.prototype, "stepsize", {
  91. get: function () {
  92. return this._stepsize;
  93. },
  94. set: function (value) {
  95. this._stepsize = value;
  96. this.updateShaderUniforms();
  97. },
  98. enumerable: true,
  99. configurable: true
  100. });
  101. Object.defineProperty(StarfieldProceduralTexture.prototype, "zoom", {
  102. get: function () {
  103. return this._zoom;
  104. },
  105. set: function (value) {
  106. this._zoom = value;
  107. this.updateShaderUniforms();
  108. },
  109. enumerable: true,
  110. configurable: true
  111. });
  112. Object.defineProperty(StarfieldProceduralTexture.prototype, "tile", {
  113. get: function () {
  114. return this._tile;
  115. },
  116. set: function (value) {
  117. this._tile = value;
  118. this.updateShaderUniforms();
  119. },
  120. enumerable: true,
  121. configurable: true
  122. });
  123. Object.defineProperty(StarfieldProceduralTexture.prototype, "brightness", {
  124. get: function () {
  125. return this._brightness;
  126. },
  127. set: function (value) {
  128. this._brightness = value;
  129. this.updateShaderUniforms();
  130. },
  131. enumerable: true,
  132. configurable: true
  133. });
  134. Object.defineProperty(StarfieldProceduralTexture.prototype, "darkmatter", {
  135. get: function () {
  136. return this._darkmatter;
  137. },
  138. set: function (value) {
  139. this._darkmatter = value;
  140. this.updateShaderUniforms();
  141. },
  142. enumerable: true,
  143. configurable: true
  144. });
  145. Object.defineProperty(StarfieldProceduralTexture.prototype, "distfading", {
  146. get: function () {
  147. return this._distfading;
  148. },
  149. set: function (value) {
  150. this._distfading = value;
  151. this.updateShaderUniforms();
  152. },
  153. enumerable: true,
  154. configurable: true
  155. });
  156. Object.defineProperty(StarfieldProceduralTexture.prototype, "saturation", {
  157. get: function () {
  158. return this._saturation;
  159. },
  160. set: function (value) {
  161. this._saturation = value;
  162. this.updateShaderUniforms();
  163. },
  164. enumerable: true,
  165. configurable: true
  166. });
  167. return StarfieldProceduralTexture;
  168. }(BABYLON.ProceduralTexture));
  169. BABYLON.StarfieldProceduralTexture = StarfieldProceduralTexture;
  170. })(BABYLON || (BABYLON = {}));
  171. //# sourceMappingURL=babylon.starfieldProceduralTexture.js.map
  172. 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}";