babylon.starfieldProceduralTexture.js 7.6 KB

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