babylon.fireProceduralTexture.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. module BABYLON {
  3. export class FireProceduralTexture extends ProceduralTexture {
  4. private _time: number = 0.0;
  5. private _speed = new Vector2(0.5, 0.3);
  6. private _autoGenerateTime: boolean = true;
  7. private _fireColors: Color3[];
  8. private _alphaThreshold: number = 0.5;
  9. constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean) {
  10. super(name, size, "fireProceduralTexture", scene, fallbackTexture, generateMipMaps);
  11. this._fireColors = FireProceduralTexture.RedFireColors;
  12. this.updateShaderUniforms();
  13. this.refreshRate = 1;
  14. }
  15. public updateShaderUniforms() {
  16. this.setFloat("time", this._time);
  17. this.setVector2("speed", this._speed);
  18. this.setColor3("c1", this._fireColors[0]);
  19. this.setColor3("c2", this._fireColors[1]);
  20. this.setColor3("c3", this._fireColors[2]);
  21. this.setColor3("c4", this._fireColors[3]);
  22. this.setColor3("c5", this._fireColors[4]);
  23. this.setColor3("c6", this._fireColors[5]);
  24. this.setFloat("alphaThreshold", this._alphaThreshold);
  25. }
  26. public render(useCameraPostProcess?: boolean) {
  27. if (this._autoGenerateTime) {
  28. this._time += this.getScene().getAnimationRatio() * 0.03;
  29. this.updateShaderUniforms();
  30. }
  31. super.render(useCameraPostProcess);
  32. }
  33. public static get PurpleFireColors(): Color3[] {
  34. return [
  35. new Color3(0.5, 0.0, 1.0),
  36. new Color3(0.9, 0.0, 1.0),
  37. new Color3(0.2, 0.0, 1.0),
  38. new Color3(1.0, 0.9, 1.0),
  39. new Color3(0.1, 0.1, 1.0),
  40. new Color3(0.9, 0.9, 1.0)
  41. ];
  42. }
  43. public static get GreenFireColors(): Color3[] {
  44. return [
  45. new Color3(0.5, 1.0, 0.0),
  46. new Color3(0.5, 1.0, 0.0),
  47. new Color3(0.3, 0.4, 0.0),
  48. new Color3(0.5, 1.0, 0.0),
  49. new Color3(0.2, 0.0, 0.0),
  50. new Color3(0.5, 1.0, 0.0)
  51. ];
  52. }
  53. public static get RedFireColors(): Color3[] {
  54. return [
  55. new Color3(0.5, 0.0, 0.1),
  56. new Color3(0.9, 0.0, 0.0),
  57. new Color3(0.2, 0.0, 0.0),
  58. new Color3(1.0, 0.9, 0.0),
  59. new Color3(0.1, 0.1, 0.1),
  60. new Color3(0.9, 0.9, 0.9)
  61. ];
  62. }
  63. public static get BlueFireColors(): Color3[] {
  64. return [
  65. new Color3(0.1, 0.0, 0.5),
  66. new Color3(0.0, 0.0, 0.5),
  67. new Color3(0.1, 0.0, 0.2),
  68. new Color3(0.0, 0.0, 1.0),
  69. new Color3(0.1, 0.2, 0.3),
  70. new Color3(0.0, 0.2, 0.9)
  71. ];
  72. }
  73. public get fireColors(): Color3[] {
  74. return this._fireColors;
  75. }
  76. public set fireColors(value: Color3[]) {
  77. this._fireColors = value;
  78. this.updateShaderUniforms();
  79. }
  80. public get time(): number {
  81. return this._time;
  82. }
  83. public set time(value: number) {
  84. this._time = value;
  85. this.updateShaderUniforms();
  86. }
  87. public get speed(): Vector2 {
  88. return this._speed;
  89. }
  90. public set speed(value: Vector2) {
  91. this._speed = value;
  92. this.updateShaderUniforms();
  93. }
  94. public get alphaThreshold(): number {
  95. return this._alphaThreshold;
  96. }
  97. public set alphaThreshold(value: number) {
  98. this._alphaThreshold = value;
  99. this.updateShaderUniforms();
  100. }
  101. }
  102. }