engine.alpha.ts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import { ThinEngine } from "../../Engines/thinEngine";
  2. import { Constants } from '../constants';
  3. declare module "../../Engines/thinEngine" {
  4. export interface ThinEngine {
  5. /**
  6. * Sets alpha constants used by some alpha blending modes
  7. * @param r defines the red component
  8. * @param g defines the green component
  9. * @param b defines the blue component
  10. * @param a defines the alpha component
  11. */
  12. setAlphaConstants(r: number, g: number, b: number, a: number): void;
  13. /**
  14. * Sets the current alpha mode
  15. * @param mode defines the mode to use (one of the Engine.ALPHA_XXX)
  16. * @param noDepthWriteChange defines if depth writing state should remains unchanged (false by default)
  17. * @see https://doc.babylonjs.com/resources/transparency_and_how_meshes_are_rendered
  18. */
  19. setAlphaMode(mode: number, noDepthWriteChange?: boolean): void;
  20. /**
  21. * Gets the current alpha mode
  22. * @see https://doc.babylonjs.com/resources/transparency_and_how_meshes_are_rendered
  23. * @returns the current alpha mode
  24. */
  25. getAlphaMode(): number;
  26. /**
  27. * Sets the current alpha equation
  28. * @param equation defines the equation to use (one of the Engine.ALPHA_EQUATION_XXX)
  29. */
  30. setAlphaEquation(equation: number): void;
  31. /**
  32. * Gets the current alpha equation.
  33. * @returns the current alpha equation
  34. */
  35. getAlphaEquation(): number;
  36. }
  37. }
  38. ThinEngine.prototype.setAlphaConstants = function(r: number, g: number, b: number, a: number) {
  39. this._alphaState.setAlphaBlendConstants(r, g, b, a);
  40. };
  41. ThinEngine.prototype.setAlphaMode = function(mode: number, noDepthWriteChange: boolean = false): void {
  42. if (this._alphaMode === mode) {
  43. return;
  44. }
  45. switch (mode) {
  46. case Constants.ALPHA_DISABLE:
  47. this._alphaState.alphaBlend = false;
  48. break;
  49. case Constants.ALPHA_PREMULTIPLIED:
  50. this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE);
  51. this._alphaState.alphaBlend = true;
  52. break;
  53. case Constants.ALPHA_PREMULTIPLIED_PORTERDUFF:
  54. this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA);
  55. this._alphaState.alphaBlend = true;
  56. break;
  57. case Constants.ALPHA_COMBINE:
  58. this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE);
  59. this._alphaState.alphaBlend = true;
  60. break;
  61. case Constants.ALPHA_ONEONE:
  62. this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE, this._gl.ZERO, this._gl.ONE);
  63. this._alphaState.alphaBlend = true;
  64. break;
  65. case Constants.ALPHA_ADD:
  66. this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA, this._gl.ONE, this._gl.ZERO, this._gl.ONE);
  67. this._alphaState.alphaBlend = true;
  68. break;
  69. case Constants.ALPHA_SUBTRACT:
  70. this._alphaState.setAlphaBlendFunctionParameters(this._gl.ZERO, this._gl.ONE_MINUS_SRC_COLOR, this._gl.ONE, this._gl.ONE);
  71. this._alphaState.alphaBlend = true;
  72. break;
  73. case Constants.ALPHA_MULTIPLY:
  74. this._alphaState.setAlphaBlendFunctionParameters(this._gl.DST_COLOR, this._gl.ZERO, this._gl.ONE, this._gl.ONE);
  75. this._alphaState.alphaBlend = true;
  76. break;
  77. case Constants.ALPHA_MAXIMIZED:
  78. this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA, this._gl.ONE_MINUS_SRC_COLOR, this._gl.ONE, this._gl.ONE);
  79. this._alphaState.alphaBlend = true;
  80. break;
  81. case Constants.ALPHA_INTERPOLATE:
  82. this._alphaState.setAlphaBlendFunctionParameters(this._gl.CONSTANT_COLOR, this._gl.ONE_MINUS_CONSTANT_COLOR, this._gl.CONSTANT_ALPHA, this._gl.ONE_MINUS_CONSTANT_ALPHA);
  83. this._alphaState.alphaBlend = true;
  84. break;
  85. case Constants.ALPHA_SCREENMODE:
  86. this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE_MINUS_SRC_COLOR, this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA);
  87. this._alphaState.alphaBlend = true;
  88. break;
  89. case Constants.ALPHA_ONEONE_ONEONE:
  90. this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE, this._gl.ONE, this._gl.ONE);
  91. this._alphaState.alphaBlend = true;
  92. break;
  93. case Constants.ALPHA_ALPHATOCOLOR:
  94. this._alphaState.setAlphaBlendFunctionParameters(this._gl.DST_ALPHA, this._gl.ONE, this._gl.ZERO, this._gl.ZERO);
  95. this._alphaState.alphaBlend = true;
  96. break;
  97. case Constants.ALPHA_REVERSEONEMINUS:
  98. this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE_MINUS_DST_COLOR, this._gl.ONE_MINUS_SRC_COLOR, this._gl.ONE_MINUS_DST_ALPHA, this._gl.ONE_MINUS_SRC_ALPHA);
  99. this._alphaState.alphaBlend = true;
  100. break;
  101. case Constants.ALPHA_SRC_DSTONEMINUSSRCALPHA:
  102. this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA);
  103. this._alphaState.alphaBlend = true;
  104. break;
  105. case Constants.ALPHA_ONEONE_ONEZERO:
  106. this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE, this._gl.ONE, this._gl.ZERO);
  107. this._alphaState.alphaBlend = true;
  108. break;
  109. case Constants.ALPHA_EXCLUSION:
  110. this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE_MINUS_DST_COLOR, this._gl.ONE_MINUS_SRC_COLOR, this._gl.ZERO, this._gl.ONE);
  111. this._alphaState.alphaBlend = true;
  112. break;
  113. }
  114. if (!noDepthWriteChange) {
  115. this.depthCullingState.depthMask = (mode === Constants.ALPHA_DISABLE);
  116. }
  117. this._alphaMode = mode;
  118. };
  119. ThinEngine.prototype.getAlphaMode = function(): number {
  120. return this._alphaMode;
  121. };
  122. ThinEngine.prototype.setAlphaEquation = function(equation: number): void {
  123. if (this._alphaEquation === equation) {
  124. return;
  125. }
  126. switch (equation) {
  127. case Constants.ALPHA_EQUATION_ADD:
  128. this._alphaState.setAlphaEquationParameters(this._gl.FUNC_ADD, this._gl.FUNC_ADD);
  129. break;
  130. case Constants.ALPHA_EQUATION_SUBSTRACT:
  131. this._alphaState.setAlphaEquationParameters(this._gl.FUNC_SUBTRACT, this._gl.FUNC_SUBTRACT);
  132. break;
  133. case Constants.ALPHA_EQUATION_REVERSE_SUBTRACT:
  134. this._alphaState.setAlphaEquationParameters(this._gl.FUNC_REVERSE_SUBTRACT, this._gl.FUNC_REVERSE_SUBTRACT);
  135. break;
  136. case Constants.ALPHA_EQUATION_MAX:
  137. this._alphaState.setAlphaEquationParameters(this._gl.MAX, this._gl.MAX);
  138. break;
  139. case Constants.ALPHA_EQUATION_MIN:
  140. this._alphaState.setAlphaEquationParameters(this._gl.MIN, this._gl.MIN);
  141. break;
  142. case Constants.ALPHA_EQUATION_DARKEN:
  143. this._alphaState.setAlphaEquationParameters(this._gl.MIN, this._gl.FUNC_ADD);
  144. break;
  145. }
  146. this._alphaEquation = equation;
  147. };
  148. ThinEngine.prototype.getAlphaEquation = function() {
  149. return this._alphaEquation;
  150. };