babylon.starfieldProceduralTexture.js 7.3 KB

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