babylon.starfieldProceduralTexture.js 7.3 KB

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