babylon.standardProceduralTexture.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. var __extends = this.__extends || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. __.prototype = b.prototype;
  5. d.prototype = new __();
  6. };
  7. var BABYLON;
  8. (function (BABYLON) {
  9. var WoodProceduralTexture = (function (_super) {
  10. __extends(WoodProceduralTexture, _super);
  11. function WoodProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  12. _super.call(this, name, size, "wood", scene, fallbackTexture, generateMipMaps);
  13. this._ampScale = 100.0;
  14. this._woodColor = new BABYLON.Color3(0.32, 0.17, 0.09);
  15. this.updateShaderUniforms();
  16. // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
  17. this.refreshRate = 0;
  18. }
  19. WoodProceduralTexture.prototype.updateShaderUniforms = function () {
  20. this.setFloat("ampScale", this._ampScale);
  21. this.setColor3("woodColor", this._woodColor);
  22. };
  23. Object.defineProperty(WoodProceduralTexture.prototype, "ampScale", {
  24. get: function () {
  25. return this._ampScale;
  26. },
  27. set: function (value) {
  28. this._ampScale = value;
  29. this.updateShaderUniforms();
  30. },
  31. enumerable: true,
  32. configurable: true
  33. });
  34. Object.defineProperty(WoodProceduralTexture.prototype, "woodColor", {
  35. get: function () {
  36. return this._woodColor;
  37. },
  38. set: function (value) {
  39. this._woodColor = value;
  40. this.updateShaderUniforms();
  41. },
  42. enumerable: true,
  43. configurable: true
  44. });
  45. return WoodProceduralTexture;
  46. })(BABYLON.ProceduralTexture);
  47. BABYLON.WoodProceduralTexture = WoodProceduralTexture;
  48. var FireProceduralTexture = (function (_super) {
  49. __extends(FireProceduralTexture, _super);
  50. function FireProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  51. _super.call(this, name, size, "fire", scene, fallbackTexture, generateMipMaps);
  52. this._time = 0.0;
  53. this._speed = new BABYLON.Vector2(0.5, 0.3);
  54. this._shift = 1.6;
  55. this._alpha = 1.0;
  56. this._autoGenerateTime = true;
  57. this._fireColors = FireProceduralTexture.RedFireColors;
  58. this.updateShaderUniforms();
  59. // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
  60. this.refreshRate = 1;
  61. }
  62. FireProceduralTexture.prototype.updateShaderUniforms = function () {
  63. this.setFloat("iGlobalTime", this._time);
  64. this.setVector2("speed", this._speed);
  65. this.setFloat("shift", this._shift);
  66. this.setFloat("alpha", this._alpha);
  67. this.setColor3("c1", new BABYLON.Color3(this._fireColors[0][0], this._fireColors[0][1], this._fireColors[0][2]));
  68. this.setColor3("c2", new BABYLON.Color3(this._fireColors[1][0], this._fireColors[1][1], this._fireColors[1][2]));
  69. this.setColor3("c3", new BABYLON.Color3(this._fireColors[2][0], this._fireColors[2][1], this._fireColors[2][2]));
  70. this.setColor3("c4", new BABYLON.Color3(this._fireColors[3][0], this._fireColors[3][1], this._fireColors[3][2]));
  71. this.setColor3("c5", new BABYLON.Color3(this._fireColors[4][0], this._fireColors[4][1], this._fireColors[4][2]));
  72. this.setColor3("c6", new BABYLON.Color3(this._fireColors[5][0], this._fireColors[5][1], this._fireColors[5][2]));
  73. };
  74. FireProceduralTexture.prototype.render = function (useCameraPostProcess) {
  75. if (this._autoGenerateTime) {
  76. this._time += this.getScene().getAnimationRatio() * 0.03;
  77. this.updateShaderUniforms();
  78. }
  79. _super.prototype.render.call(this, useCameraPostProcess);
  80. };
  81. Object.defineProperty(FireProceduralTexture, "PurpleFireColors", {
  82. get: function () {
  83. return [
  84. [0.5, 0.0, 1.0],
  85. [0.9, 0.0, 1.0],
  86. [0.2, 0.0, 1.0],
  87. [1.0, 0.9, 1.0],
  88. [0.1, 0.1, 1.0],
  89. [0.9, 0.9, 1.0]
  90. ];
  91. },
  92. enumerable: true,
  93. configurable: true
  94. });
  95. Object.defineProperty(FireProceduralTexture, "GreenFireColors", {
  96. get: function () {
  97. return [
  98. [0.5, 1.0, 0.0],
  99. [0.5, 1.0, 0.0],
  100. [0.3, 0.4, 0.0],
  101. [0.5, 1.0, 0.0],
  102. [0.2, 0.0, 0.0],
  103. [0.5, 1.0, 0.0]
  104. ];
  105. },
  106. enumerable: true,
  107. configurable: true
  108. });
  109. Object.defineProperty(FireProceduralTexture, "RedFireColors", {
  110. get: function () {
  111. return [
  112. [0.5, 0.0, 0.1],
  113. [0.9, 0.0, 0.0],
  114. [0.2, 0.0, 0.0],
  115. [1.0, 0.9, 0.0],
  116. [0.1, 0.1, 0.1],
  117. [0.9, 0.9, 0.9]
  118. ];
  119. },
  120. enumerable: true,
  121. configurable: true
  122. });
  123. Object.defineProperty(FireProceduralTexture, "BlueFireColors", {
  124. get: function () {
  125. return [
  126. [0.1, 0.0, 0.5],
  127. [0.0, 0.0, 0.5],
  128. [0.1, 0.0, 0.2],
  129. [0.0, 0.0, 1.0],
  130. [0.1, 0.2, 0.3],
  131. [0.0, 0.2, 0.9]
  132. ];
  133. },
  134. enumerable: true,
  135. configurable: true
  136. });
  137. Object.defineProperty(FireProceduralTexture.prototype, "fireColors", {
  138. get: function () {
  139. return this._fireColors;
  140. },
  141. set: function (value) {
  142. this._fireColors = value;
  143. this.updateShaderUniforms();
  144. },
  145. enumerable: true,
  146. configurable: true
  147. });
  148. Object.defineProperty(FireProceduralTexture.prototype, "time", {
  149. get: function () {
  150. return this._time;
  151. },
  152. set: function (value) {
  153. this._time = value;
  154. this.updateShaderUniforms();
  155. },
  156. enumerable: true,
  157. configurable: true
  158. });
  159. Object.defineProperty(FireProceduralTexture.prototype, "speed", {
  160. get: function () {
  161. return this._speed;
  162. },
  163. set: function (value) {
  164. this._speed = value;
  165. this.updateShaderUniforms();
  166. },
  167. enumerable: true,
  168. configurable: true
  169. });
  170. Object.defineProperty(FireProceduralTexture.prototype, "shift", {
  171. get: function () {
  172. return this._shift;
  173. },
  174. set: function (value) {
  175. this._shift = value;
  176. this.updateShaderUniforms();
  177. },
  178. enumerable: true,
  179. configurable: true
  180. });
  181. Object.defineProperty(FireProceduralTexture.prototype, "alpha", {
  182. get: function () {
  183. return this._alpha;
  184. },
  185. set: function (value) {
  186. this._alpha = value;
  187. this.updateShaderUniforms();
  188. },
  189. enumerable: true,
  190. configurable: true
  191. });
  192. return FireProceduralTexture;
  193. })(BABYLON.ProceduralTexture);
  194. BABYLON.FireProceduralTexture = FireProceduralTexture;
  195. var CloudProceduralTexture = (function (_super) {
  196. __extends(CloudProceduralTexture, _super);
  197. function CloudProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  198. _super.call(this, name, size, "cloud", scene, fallbackTexture, generateMipMaps);
  199. this._skyColor = new BABYLON.Color3(0.15, 0.68, 1.0);
  200. this._cloudColor = new BABYLON.Color3(1, 1, 1);
  201. this.updateShaderUniforms();
  202. // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
  203. this.refreshRate = 0;
  204. // https://www.shadertoy.com/view/XsjSRt
  205. }
  206. CloudProceduralTexture.prototype.updateShaderUniforms = function () {
  207. this.setColor3("skyColor", this._skyColor);
  208. this.setColor3("cloudColor", this._cloudColor);
  209. };
  210. Object.defineProperty(CloudProceduralTexture.prototype, "skyColor", {
  211. get: function () {
  212. return this._skyColor;
  213. },
  214. set: function (value) {
  215. this._skyColor = value;
  216. this.updateShaderUniforms();
  217. },
  218. enumerable: true,
  219. configurable: true
  220. });
  221. Object.defineProperty(CloudProceduralTexture.prototype, "cloudColor", {
  222. get: function () {
  223. return this._cloudColor;
  224. },
  225. set: function (value) {
  226. this._cloudColor = value;
  227. this.updateShaderUniforms();
  228. },
  229. enumerable: true,
  230. configurable: true
  231. });
  232. return CloudProceduralTexture;
  233. })(BABYLON.ProceduralTexture);
  234. BABYLON.CloudProceduralTexture = CloudProceduralTexture;
  235. var GrassProceduralTexture = (function (_super) {
  236. __extends(GrassProceduralTexture, _super);
  237. function GrassProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  238. _super.call(this, name, size, "grass", scene, fallbackTexture, generateMipMaps);
  239. // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
  240. this.refreshRate = 0;
  241. }
  242. return GrassProceduralTexture;
  243. })(BABYLON.ProceduralTexture);
  244. BABYLON.GrassProceduralTexture = GrassProceduralTexture;
  245. var RockProceduralTexture = (function (_super) {
  246. __extends(RockProceduralTexture, _super);
  247. function RockProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  248. _super.call(this, name, size, "rock", scene, fallbackTexture, generateMipMaps);
  249. // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
  250. this.refreshRate = 0;
  251. }
  252. return RockProceduralTexture;
  253. })(BABYLON.ProceduralTexture);
  254. BABYLON.RockProceduralTexture = RockProceduralTexture;
  255. var RoadProceduralTexture = (function (_super) {
  256. __extends(RoadProceduralTexture, _super);
  257. function RoadProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  258. _super.call(this, name, size, "road", scene, fallbackTexture, generateMipMaps);
  259. // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
  260. this.refreshRate = 0;
  261. }
  262. return RoadProceduralTexture;
  263. })(BABYLON.ProceduralTexture);
  264. BABYLON.RoadProceduralTexture = RoadProceduralTexture;
  265. var BrickProceduralTexture = (function (_super) {
  266. __extends(BrickProceduralTexture, _super);
  267. function BrickProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  268. _super.call(this, name, size, "brick", scene, fallbackTexture, generateMipMaps);
  269. this._numberOfBricksHeight = 15;
  270. this._numberOfBricksWidth = 5;
  271. this.updateShaderUniforms();
  272. // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
  273. this.refreshRate = 0;
  274. }
  275. BrickProceduralTexture.prototype.updateShaderUniforms = function () {
  276. this.setFloat("numberOfBricksHeight", this._numberOfBricksHeight);
  277. this.setFloat("numberOfBricksWidth", this._numberOfBricksWidth);
  278. };
  279. Object.defineProperty(BrickProceduralTexture.prototype, "numberOfBricksHeight", {
  280. get: function () {
  281. return this._numberOfBricksHeight;
  282. },
  283. enumerable: true,
  284. configurable: true
  285. });
  286. Object.defineProperty(BrickProceduralTexture.prototype, "cloudColor", {
  287. set: function (value) {
  288. this._numberOfBricksHeight = value;
  289. this.updateShaderUniforms();
  290. },
  291. enumerable: true,
  292. configurable: true
  293. });
  294. Object.defineProperty(BrickProceduralTexture.prototype, "numberOfBricksWidth", {
  295. get: function () {
  296. return this._numberOfBricksWidth;
  297. },
  298. set: function (value) {
  299. this._numberOfBricksHeight = value;
  300. this.updateShaderUniforms();
  301. },
  302. enumerable: true,
  303. configurable: true
  304. });
  305. return BrickProceduralTexture;
  306. })(BABYLON.ProceduralTexture);
  307. BABYLON.BrickProceduralTexture = BrickProceduralTexture;
  308. var MarbleProceduralTexture = (function (_super) {
  309. __extends(MarbleProceduralTexture, _super);
  310. function MarbleProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  311. _super.call(this, name, size, "marble", scene, fallbackTexture, generateMipMaps);
  312. this._numberOfBricksHeight = 3;
  313. this._numberOfBricksWidth = 3;
  314. this.updateShaderUniforms();
  315. // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
  316. this.refreshRate = 0;
  317. }
  318. MarbleProceduralTexture.prototype.updateShaderUniforms = function () {
  319. this.setFloat("numberOfBricksHeight", this._numberOfBricksHeight);
  320. this.setFloat("numberOfBricksWidth", this._numberOfBricksWidth);
  321. };
  322. Object.defineProperty(MarbleProceduralTexture.prototype, "numberOfBricksHeight", {
  323. get: function () {
  324. return this._numberOfBricksHeight;
  325. },
  326. enumerable: true,
  327. configurable: true
  328. });
  329. Object.defineProperty(MarbleProceduralTexture.prototype, "cloudColor", {
  330. set: function (value) {
  331. this._numberOfBricksHeight = value;
  332. this.updateShaderUniforms();
  333. },
  334. enumerable: true,
  335. configurable: true
  336. });
  337. Object.defineProperty(MarbleProceduralTexture.prototype, "numberOfBricksWidth", {
  338. get: function () {
  339. return this._numberOfBricksWidth;
  340. },
  341. set: function (value) {
  342. this._numberOfBricksHeight = value;
  343. this.updateShaderUniforms();
  344. },
  345. enumerable: true,
  346. configurable: true
  347. });
  348. return MarbleProceduralTexture;
  349. })(BABYLON.ProceduralTexture);
  350. BABYLON.MarbleProceduralTexture = MarbleProceduralTexture;
  351. })(BABYLON || (BABYLON = {}));
  352. //# sourceMappingURL=babylon.standardProceduralTexture.js.map