babylon.standardProceduralTexture.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. var __extends = (this && 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. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5. };
  6. var BABYLON;
  7. (function (BABYLON) {
  8. var WoodProceduralTexture = (function (_super) {
  9. __extends(WoodProceduralTexture, _super);
  10. function WoodProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  11. _super.call(this, name, size, "woodtexture", scene, fallbackTexture, generateMipMaps);
  12. this._ampScale = 100.0;
  13. this._woodColor = new BABYLON.Color3(0.32, 0.17, 0.09);
  14. this.updateShaderUniforms();
  15. this.refreshRate = 0;
  16. }
  17. WoodProceduralTexture.prototype.updateShaderUniforms = function () {
  18. this.setFloat("ampScale", this._ampScale);
  19. this.setColor3("woodColor", this._woodColor);
  20. };
  21. Object.defineProperty(WoodProceduralTexture.prototype, "ampScale", {
  22. get: function () {
  23. return this._ampScale;
  24. },
  25. set: function (value) {
  26. this._ampScale = value;
  27. this.updateShaderUniforms();
  28. },
  29. enumerable: true,
  30. configurable: true
  31. });
  32. Object.defineProperty(WoodProceduralTexture.prototype, "woodColor", {
  33. get: function () {
  34. return this._woodColor;
  35. },
  36. set: function (value) {
  37. this._woodColor = value;
  38. this.updateShaderUniforms();
  39. },
  40. enumerable: true,
  41. configurable: true
  42. });
  43. return WoodProceduralTexture;
  44. })(BABYLON.ProceduralTexture);
  45. BABYLON.WoodProceduralTexture = WoodProceduralTexture;
  46. var FireProceduralTexture = (function (_super) {
  47. __extends(FireProceduralTexture, _super);
  48. function FireProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  49. _super.call(this, name, size, "firetexture", scene, fallbackTexture, generateMipMaps);
  50. this._time = 0.0;
  51. this._speed = new BABYLON.Vector2(0.5, 0.3);
  52. this._autoGenerateTime = true;
  53. this._alphaThreshold = 0.5;
  54. this._fireColors = FireProceduralTexture.RedFireColors;
  55. this.updateShaderUniforms();
  56. this.refreshRate = 1;
  57. }
  58. FireProceduralTexture.prototype.updateShaderUniforms = function () {
  59. this.setFloat("time", this._time);
  60. this.setVector2("speed", this._speed);
  61. this.setColor3("c1", this._fireColors[0]);
  62. this.setColor3("c2", this._fireColors[1]);
  63. this.setColor3("c3", this._fireColors[2]);
  64. this.setColor3("c4", this._fireColors[3]);
  65. this.setColor3("c5", this._fireColors[4]);
  66. this.setColor3("c6", this._fireColors[5]);
  67. this.setFloat("alphaThreshold", this._alphaThreshold);
  68. };
  69. FireProceduralTexture.prototype.render = function (useCameraPostProcess) {
  70. if (this._autoGenerateTime) {
  71. this._time += this.getScene().getAnimationRatio() * 0.03;
  72. this.updateShaderUniforms();
  73. }
  74. _super.prototype.render.call(this, useCameraPostProcess);
  75. };
  76. Object.defineProperty(FireProceduralTexture, "PurpleFireColors", {
  77. get: function () {
  78. return [
  79. new BABYLON.Color3(0.5, 0.0, 1.0),
  80. new BABYLON.Color3(0.9, 0.0, 1.0),
  81. new BABYLON.Color3(0.2, 0.0, 1.0),
  82. new BABYLON.Color3(1.0, 0.9, 1.0),
  83. new BABYLON.Color3(0.1, 0.1, 1.0),
  84. new BABYLON.Color3(0.9, 0.9, 1.0)
  85. ];
  86. },
  87. enumerable: true,
  88. configurable: true
  89. });
  90. Object.defineProperty(FireProceduralTexture, "GreenFireColors", {
  91. get: function () {
  92. return [
  93. new BABYLON.Color3(0.5, 1.0, 0.0),
  94. new BABYLON.Color3(0.5, 1.0, 0.0),
  95. new BABYLON.Color3(0.3, 0.4, 0.0),
  96. new BABYLON.Color3(0.5, 1.0, 0.0),
  97. new BABYLON.Color3(0.2, 0.0, 0.0),
  98. new BABYLON.Color3(0.5, 1.0, 0.0)
  99. ];
  100. },
  101. enumerable: true,
  102. configurable: true
  103. });
  104. Object.defineProperty(FireProceduralTexture, "RedFireColors", {
  105. get: function () {
  106. return [
  107. new BABYLON.Color3(0.5, 0.0, 0.1),
  108. new BABYLON.Color3(0.9, 0.0, 0.0),
  109. new BABYLON.Color3(0.2, 0.0, 0.0),
  110. new BABYLON.Color3(1.0, 0.9, 0.0),
  111. new BABYLON.Color3(0.1, 0.1, 0.1),
  112. new BABYLON.Color3(0.9, 0.9, 0.9)
  113. ];
  114. },
  115. enumerable: true,
  116. configurable: true
  117. });
  118. Object.defineProperty(FireProceduralTexture, "BlueFireColors", {
  119. get: function () {
  120. return [
  121. new BABYLON.Color3(0.1, 0.0, 0.5),
  122. new BABYLON.Color3(0.0, 0.0, 0.5),
  123. new BABYLON.Color3(0.1, 0.0, 0.2),
  124. new BABYLON.Color3(0.0, 0.0, 1.0),
  125. new BABYLON.Color3(0.1, 0.2, 0.3),
  126. new BABYLON.Color3(0.0, 0.2, 0.9)
  127. ];
  128. },
  129. enumerable: true,
  130. configurable: true
  131. });
  132. Object.defineProperty(FireProceduralTexture.prototype, "fireColors", {
  133. get: function () {
  134. return this._fireColors;
  135. },
  136. set: function (value) {
  137. this._fireColors = value;
  138. this.updateShaderUniforms();
  139. },
  140. enumerable: true,
  141. configurable: true
  142. });
  143. Object.defineProperty(FireProceduralTexture.prototype, "time", {
  144. get: function () {
  145. return this._time;
  146. },
  147. set: function (value) {
  148. this._time = value;
  149. this.updateShaderUniforms();
  150. },
  151. enumerable: true,
  152. configurable: true
  153. });
  154. Object.defineProperty(FireProceduralTexture.prototype, "speed", {
  155. get: function () {
  156. return this._speed;
  157. },
  158. set: function (value) {
  159. this._speed = value;
  160. this.updateShaderUniforms();
  161. },
  162. enumerable: true,
  163. configurable: true
  164. });
  165. Object.defineProperty(FireProceduralTexture.prototype, "alphaThreshold", {
  166. get: function () {
  167. return this._alphaThreshold;
  168. },
  169. set: function (value) {
  170. this._alphaThreshold = value;
  171. this.updateShaderUniforms();
  172. },
  173. enumerable: true,
  174. configurable: true
  175. });
  176. return FireProceduralTexture;
  177. })(BABYLON.ProceduralTexture);
  178. BABYLON.FireProceduralTexture = FireProceduralTexture;
  179. var CloudProceduralTexture = (function (_super) {
  180. __extends(CloudProceduralTexture, _super);
  181. function CloudProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  182. _super.call(this, name, size, "cloudtexture", scene, fallbackTexture, generateMipMaps);
  183. this._skyColor = new BABYLON.Color4(0.15, 0.68, 1.0, 1.0);
  184. this._cloudColor = new BABYLON.Color4(1, 1, 1, 1.0);
  185. this.updateShaderUniforms();
  186. this.refreshRate = 0;
  187. }
  188. CloudProceduralTexture.prototype.updateShaderUniforms = function () {
  189. this.setColor4("skyColor", this._skyColor);
  190. this.setColor4("cloudColor", this._cloudColor);
  191. };
  192. Object.defineProperty(CloudProceduralTexture.prototype, "skyColor", {
  193. get: function () {
  194. return this._skyColor;
  195. },
  196. set: function (value) {
  197. this._skyColor = value;
  198. this.updateShaderUniforms();
  199. },
  200. enumerable: true,
  201. configurable: true
  202. });
  203. Object.defineProperty(CloudProceduralTexture.prototype, "cloudColor", {
  204. get: function () {
  205. return this._cloudColor;
  206. },
  207. set: function (value) {
  208. this._cloudColor = value;
  209. this.updateShaderUniforms();
  210. },
  211. enumerable: true,
  212. configurable: true
  213. });
  214. return CloudProceduralTexture;
  215. })(BABYLON.ProceduralTexture);
  216. BABYLON.CloudProceduralTexture = CloudProceduralTexture;
  217. var GrassProceduralTexture = (function (_super) {
  218. __extends(GrassProceduralTexture, _super);
  219. function GrassProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  220. _super.call(this, name, size, "grasstexture", scene, fallbackTexture, generateMipMaps);
  221. this._herb1 = new BABYLON.Color3(0.29, 0.38, 0.02);
  222. this._herb2 = new BABYLON.Color3(0.36, 0.49, 0.09);
  223. this._herb3 = new BABYLON.Color3(0.51, 0.6, 0.28);
  224. this._groundColor = new BABYLON.Color3(1, 1, 1);
  225. this._grassColors = [
  226. new BABYLON.Color3(0.29, 0.38, 0.02),
  227. new BABYLON.Color3(0.36, 0.49, 0.09),
  228. new BABYLON.Color3(0.51, 0.6, 0.28)
  229. ];
  230. this.updateShaderUniforms();
  231. this.refreshRate = 0;
  232. }
  233. GrassProceduralTexture.prototype.updateShaderUniforms = function () {
  234. this.setColor3("herb1Color", this._grassColors[0]);
  235. this.setColor3("herb2Color", this._grassColors[1]);
  236. this.setColor3("herb3Color", this._grassColors[2]);
  237. this.setColor3("groundColor", this._groundColor);
  238. };
  239. Object.defineProperty(GrassProceduralTexture.prototype, "grassColors", {
  240. get: function () {
  241. return this._grassColors;
  242. },
  243. set: function (value) {
  244. this._grassColors = value;
  245. this.updateShaderUniforms();
  246. },
  247. enumerable: true,
  248. configurable: true
  249. });
  250. Object.defineProperty(GrassProceduralTexture.prototype, "groundColor", {
  251. get: function () {
  252. return this._groundColor;
  253. },
  254. set: function (value) {
  255. this.groundColor = value;
  256. this.updateShaderUniforms();
  257. },
  258. enumerable: true,
  259. configurable: true
  260. });
  261. return GrassProceduralTexture;
  262. })(BABYLON.ProceduralTexture);
  263. BABYLON.GrassProceduralTexture = GrassProceduralTexture;
  264. var RoadProceduralTexture = (function (_super) {
  265. __extends(RoadProceduralTexture, _super);
  266. function RoadProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  267. _super.call(this, name, size, "roadtexture", scene, fallbackTexture, generateMipMaps);
  268. this._roadColor = new BABYLON.Color3(0.53, 0.53, 0.53);
  269. this.updateShaderUniforms();
  270. this.refreshRate = 0;
  271. }
  272. RoadProceduralTexture.prototype.updateShaderUniforms = function () {
  273. this.setColor3("roadColor", this._roadColor);
  274. };
  275. Object.defineProperty(RoadProceduralTexture.prototype, "roadColor", {
  276. get: function () {
  277. return this._roadColor;
  278. },
  279. set: function (value) {
  280. this._roadColor = value;
  281. this.updateShaderUniforms();
  282. },
  283. enumerable: true,
  284. configurable: true
  285. });
  286. return RoadProceduralTexture;
  287. })(BABYLON.ProceduralTexture);
  288. BABYLON.RoadProceduralTexture = RoadProceduralTexture;
  289. var BrickProceduralTexture = (function (_super) {
  290. __extends(BrickProceduralTexture, _super);
  291. function BrickProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  292. _super.call(this, name, size, "bricktexture", scene, fallbackTexture, generateMipMaps);
  293. this._numberOfBricksHeight = 15;
  294. this._numberOfBricksWidth = 5;
  295. this._jointColor = new BABYLON.Color3(0.72, 0.72, 0.72);
  296. this._brickColor = new BABYLON.Color3(0.77, 0.47, 0.40);
  297. this.updateShaderUniforms();
  298. this.refreshRate = 0;
  299. }
  300. BrickProceduralTexture.prototype.updateShaderUniforms = function () {
  301. this.setFloat("numberOfBricksHeight", this._numberOfBricksHeight);
  302. this.setFloat("numberOfBricksWidth", this._numberOfBricksWidth);
  303. this.setColor3("brickColor", this._brickColor);
  304. this.setColor3("jointColor", this._jointColor);
  305. };
  306. Object.defineProperty(BrickProceduralTexture.prototype, "numberOfBricksHeight", {
  307. get: function () {
  308. return this._numberOfBricksHeight;
  309. },
  310. set: function (value) {
  311. this._numberOfBricksHeight = value;
  312. this.updateShaderUniforms();
  313. },
  314. enumerable: true,
  315. configurable: true
  316. });
  317. Object.defineProperty(BrickProceduralTexture.prototype, "numberOfBricksWidth", {
  318. get: function () {
  319. return this._numberOfBricksWidth;
  320. },
  321. set: function (value) {
  322. this._numberOfBricksWidth = value;
  323. this.updateShaderUniforms();
  324. },
  325. enumerable: true,
  326. configurable: true
  327. });
  328. Object.defineProperty(BrickProceduralTexture.prototype, "jointColor", {
  329. get: function () {
  330. return this._jointColor;
  331. },
  332. set: function (value) {
  333. this._jointColor = value;
  334. this.updateShaderUniforms();
  335. },
  336. enumerable: true,
  337. configurable: true
  338. });
  339. Object.defineProperty(BrickProceduralTexture.prototype, "brickColor", {
  340. get: function () {
  341. return this._brickColor;
  342. },
  343. set: function (value) {
  344. this._brickColor = value;
  345. this.updateShaderUniforms();
  346. },
  347. enumerable: true,
  348. configurable: true
  349. });
  350. return BrickProceduralTexture;
  351. })(BABYLON.ProceduralTexture);
  352. BABYLON.BrickProceduralTexture = BrickProceduralTexture;
  353. var MarbleProceduralTexture = (function (_super) {
  354. __extends(MarbleProceduralTexture, _super);
  355. function MarbleProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  356. _super.call(this, name, size, "marbletexture", scene, fallbackTexture, generateMipMaps);
  357. this._numberOfTilesHeight = 3;
  358. this._numberOfTilesWidth = 3;
  359. this._amplitude = 9.0;
  360. this._marbleColor = new BABYLON.Color3(0.77, 0.47, 0.40);
  361. this._jointColor = new BABYLON.Color3(0.72, 0.72, 0.72);
  362. this.updateShaderUniforms();
  363. this.refreshRate = 0;
  364. }
  365. MarbleProceduralTexture.prototype.updateShaderUniforms = function () {
  366. this.setFloat("numberOfTilesHeight", this._numberOfTilesHeight);
  367. this.setFloat("numberOfTilesWidth", this._numberOfTilesWidth);
  368. this.setFloat("amplitude", this._amplitude);
  369. this.setColor3("marbleColor", this._marbleColor);
  370. this.setColor3("jointColor", this._jointColor);
  371. };
  372. Object.defineProperty(MarbleProceduralTexture.prototype, "numberOfTilesHeight", {
  373. get: function () {
  374. return this._numberOfTilesHeight;
  375. },
  376. set: function (value) {
  377. this._numberOfTilesHeight = value;
  378. this.updateShaderUniforms();
  379. },
  380. enumerable: true,
  381. configurable: true
  382. });
  383. Object.defineProperty(MarbleProceduralTexture.prototype, "numberOfTilesWidth", {
  384. get: function () {
  385. return this._numberOfTilesWidth;
  386. },
  387. set: function (value) {
  388. this._numberOfTilesWidth = value;
  389. this.updateShaderUniforms();
  390. },
  391. enumerable: true,
  392. configurable: true
  393. });
  394. Object.defineProperty(MarbleProceduralTexture.prototype, "jointColor", {
  395. get: function () {
  396. return this._jointColor;
  397. },
  398. set: function (value) {
  399. this._jointColor = value;
  400. this.updateShaderUniforms();
  401. },
  402. enumerable: true,
  403. configurable: true
  404. });
  405. Object.defineProperty(MarbleProceduralTexture.prototype, "marbleColor", {
  406. get: function () {
  407. return this._marbleColor;
  408. },
  409. set: function (value) {
  410. this._marbleColor = value;
  411. this.updateShaderUniforms();
  412. },
  413. enumerable: true,
  414. configurable: true
  415. });
  416. return MarbleProceduralTexture;
  417. })(BABYLON.ProceduralTexture);
  418. BABYLON.MarbleProceduralTexture = MarbleProceduralTexture;
  419. })(BABYLON || (BABYLON = {}));