babylon.fireProceduralTexture.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. }
  14. public updateShaderUniforms() {
  15. this.setFloat("time", this._time);
  16. this.setVector2("speed", this._speed);
  17. this.setColor3("c1", this._fireColors[0]);
  18. this.setColor3("c2", this._fireColors[1]);
  19. this.setColor3("c3", this._fireColors[2]);
  20. this.setColor3("c4", this._fireColors[3]);
  21. this.setColor3("c5", this._fireColors[4]);
  22. this.setColor3("c6", this._fireColors[5]);
  23. this.setFloat("alphaThreshold", this._alphaThreshold);
  24. }
  25. public render(useCameraPostProcess?: boolean) {
  26. if (this._autoGenerateTime) {
  27. this._time += this.getScene().getAnimationRatio() * 0.03;
  28. this.updateShaderUniforms();
  29. }
  30. super.render(useCameraPostProcess);
  31. }
  32. public static get PurpleFireColors(): Color3[] {
  33. return [
  34. new Color3(0.5, 0.0, 1.0),
  35. new Color3(0.9, 0.0, 1.0),
  36. new Color3(0.2, 0.0, 1.0),
  37. new Color3(1.0, 0.9, 1.0),
  38. new Color3(0.1, 0.1, 1.0),
  39. new Color3(0.9, 0.9, 1.0)
  40. ];
  41. }
  42. public static get GreenFireColors(): Color3[] {
  43. return [
  44. new Color3(0.5, 1.0, 0.0),
  45. new Color3(0.5, 1.0, 0.0),
  46. new Color3(0.3, 0.4, 0.0),
  47. new Color3(0.5, 1.0, 0.0),
  48. new Color3(0.2, 0.0, 0.0),
  49. new Color3(0.5, 1.0, 0.0)
  50. ];
  51. }
  52. public static get RedFireColors(): Color3[] {
  53. return [
  54. new Color3(0.5, 0.0, 0.1),
  55. new Color3(0.9, 0.0, 0.0),
  56. new Color3(0.2, 0.0, 0.0),
  57. new Color3(1.0, 0.9, 0.0),
  58. new Color3(0.1, 0.1, 0.1),
  59. new Color3(0.9, 0.9, 0.9)
  60. ];
  61. }
  62. public static get BlueFireColors(): Color3[] {
  63. return [
  64. new Color3(0.1, 0.0, 0.5),
  65. new Color3(0.0, 0.0, 0.5),
  66. new Color3(0.1, 0.0, 0.2),
  67. new Color3(0.0, 0.0, 1.0),
  68. new Color3(0.1, 0.2, 0.3),
  69. new Color3(0.0, 0.2, 0.9)
  70. ];
  71. }
  72. public get fireColors(): Color3[] {
  73. return this._fireColors;
  74. }
  75. public set fireColors(value: Color3[]) {
  76. this._fireColors = value;
  77. this.updateShaderUniforms();
  78. }
  79. public get time(): number {
  80. return this._time;
  81. }
  82. public set time(value: number) {
  83. this._time = value;
  84. this.updateShaderUniforms();
  85. }
  86. public get speed(): Vector2 {
  87. return this._speed;
  88. }
  89. public set speed(value: Vector2) {
  90. this._speed = value;
  91. this.updateShaderUniforms();
  92. }
  93. public get alphaThreshold(): number {
  94. return this._alphaThreshold;
  95. }
  96. public set alphaThreshold(value: number) {
  97. this._alphaThreshold = value;
  98. this.updateShaderUniforms();
  99. }
  100. }
  101. }