/OgreMain/include/OgreBlendMode.h

https://bitbucket.org/ZCube/ogre-android/ · C++ Header · 266 lines · 118 code · 21 blank · 127 comment · 20 complexity · 5a48c6b97de286fe40284ab133257d93 MD5 · raw file

  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __BLENDMODE_H__
  25. #define __BLENDMODE_H__
  26. #include "OgrePrerequisites.h"
  27. #include "OgreColourValue.h"
  28. namespace Ogre {
  29. /** \addtogroup Core
  30. * @{
  31. */
  32. /** \addtogroup Materials
  33. * @{
  34. */
  35. /** Type of texture blend mode.
  36. */
  37. enum LayerBlendType
  38. {
  39. LBT_COLOUR,
  40. LBT_ALPHA
  41. };
  42. /** List of valid texture blending operations, for use with TextureUnitState::setColourOperation.
  43. @remarks
  44. This list is a more limited list than LayerBlendOperationEx because it only
  45. includes operations that are supportable in both multipass and multitexture
  46. rendering and thus provides automatic fallback if multitexture hardware
  47. is lacking or insufficient.
  48. */
  49. enum LayerBlendOperation {
  50. /// Replace all colour with texture with no adjustment
  51. LBO_REPLACE,
  52. /// Add colour components together.
  53. LBO_ADD,
  54. /// Multiply colour components together.
  55. LBO_MODULATE,
  56. /// Blend based on texture alpha
  57. LBO_ALPHA_BLEND
  58. };
  59. /** Expert list of valid texture blending operations, for use with TextureUnitState::setColourOperationEx
  60. and TextureUnitState::setAlphaOperation, and internally in the LayerBlendModeEx class. It's worth
  61. noting that these operations are for blending <i>between texture layers</i> and not between rendered objects
  62. and the existing scene. Because all of these modes are only supported in multitexture hardware it may be
  63. required to set up a fallback operation where this hardware is not available.
  64. */
  65. enum LayerBlendOperationEx {
  66. /// use source1 without modification
  67. LBX_SOURCE1,
  68. /// use source2 without modification
  69. LBX_SOURCE2,
  70. /// multiply source1 and source2 together
  71. LBX_MODULATE,
  72. /// as LBX_MODULATE but brighten afterwards (x2)
  73. LBX_MODULATE_X2,
  74. /// as LBX_MODULATE but brighten more afterwards (x4)
  75. LBX_MODULATE_X4,
  76. /// add source1 and source2 together
  77. LBX_ADD,
  78. /// as LBX_ADD, but subtract 0.5 from the result
  79. LBX_ADD_SIGNED,
  80. /// as LBX_ADD, but subtract product from the sum
  81. LBX_ADD_SMOOTH,
  82. /// subtract source2 from source1
  83. LBX_SUBTRACT,
  84. /// use interpolated alpha value from vertices to scale source1, then add source2 scaled by (1-alpha)
  85. LBX_BLEND_DIFFUSE_ALPHA,
  86. /// as LBX_BLEND_DIFFUSE_ALPHA, but use alpha from texture
  87. LBX_BLEND_TEXTURE_ALPHA,
  88. /// as LBX_BLEND_DIFFUSE_ALPHA, but use current alpha from previous stages
  89. LBX_BLEND_CURRENT_ALPHA,
  90. /// as LBX_BLEND_DIFFUSE_ALPHA but use a constant manual blend value (0.0-1.0)
  91. LBX_BLEND_MANUAL,
  92. /// dot product of color1 and color2
  93. LBX_DOTPRODUCT,
  94. /// use interpolated color values from vertices to scale source1, then add source2 scaled by (1-color)
  95. LBX_BLEND_DIFFUSE_COLOUR
  96. };
  97. /** List of valid sources of values for blending operations used
  98. in TextureUnitState::setColourOperation and TextureUnitState::setAlphaOperation,
  99. and internally in the LayerBlendModeEx class.
  100. */
  101. enum LayerBlendSource
  102. {
  103. /// the colour as built up from previous stages
  104. LBS_CURRENT,
  105. /// the colour derived from the texture assigned to this layer
  106. LBS_TEXTURE,
  107. /// the interpolated diffuse colour from the vertices
  108. LBS_DIFFUSE,
  109. /// the interpolated specular colour from the vertices
  110. LBS_SPECULAR,
  111. /// a colour supplied manually as a separate argument
  112. LBS_MANUAL
  113. };
  114. /** Class which manages blending of both colour and alpha components.
  115. @remarks
  116. This class is a utility class used by both TextureUnitState and
  117. RenderSystem to wrap up the details of a blending operation. This blending
  118. operation could be used for blending colour or alpha in a texture layer.
  119. This class is really only for use by OGRE, since apps can deal with
  120. blending modes through the TextureUnitState class methods
  121. setColourOperation and setAlphaOperation.
  122. @par
  123. It's worth noting that these operations are for blending <i>between texture
  124. layers</i> and not between rendered objects and the existing scene. If
  125. you wish to make an object blend with others in the scene, e.g. to make
  126. transparent objects etc, use the Material::setSceneBlending method.
  127. */
  128. class _OgreExport LayerBlendModeEx
  129. {
  130. public:
  131. /// The type of blending (colour or alpha)
  132. LayerBlendType blendType;
  133. /// The operation to be applied
  134. LayerBlendOperationEx operation;
  135. /// The first source of colour/alpha
  136. LayerBlendSource source1;
  137. /// The second source of colour/alpha
  138. LayerBlendSource source2;
  139. /// Manual colour value for manual source1
  140. ColourValue colourArg1;
  141. /// Manual colour value for manual source2
  142. ColourValue colourArg2;
  143. /// Manual alpha value for manual source1
  144. Real alphaArg1;
  145. /// Manual alpha value for manual source2
  146. Real alphaArg2;
  147. /// Manual blending factor
  148. Real factor;
  149. bool operator==(const LayerBlendModeEx& rhs) const
  150. {
  151. if (blendType != rhs.blendType) return false;
  152. if (blendType == LBT_COLOUR)
  153. {
  154. if (operation == rhs.operation &&
  155. source1 == rhs.source1 &&
  156. source2 == rhs.source2 &&
  157. colourArg1 == rhs.colourArg1 &&
  158. colourArg2 == rhs.colourArg2 &&
  159. factor == rhs.factor)
  160. {
  161. return true;
  162. }
  163. }
  164. else // if (blendType == LBT_ALPHA)
  165. {
  166. if (operation == rhs.operation &&
  167. source1 == rhs.source1 &&
  168. source2 == rhs.source2 &&
  169. alphaArg1 == rhs.alphaArg1 &&
  170. alphaArg2 == rhs.alphaArg2 &&
  171. factor == rhs.factor)
  172. {
  173. return true;
  174. }
  175. }
  176. return false;
  177. }
  178. bool operator!=(const LayerBlendModeEx& rhs) const
  179. {
  180. return !(*this == rhs);
  181. }
  182. };
  183. /** Types of blending that you can specify between an object and the existing contents of the scene.
  184. @remarks
  185. As opposed to the LayerBlendType, which classifies blends between texture layers, these blending
  186. types blend between the output of the texture units and the pixels already in the viewport,
  187. allowing for object transparency, glows, etc.
  188. @par
  189. These types are provided to give quick and easy access to common effects. You can also use
  190. the more manual method of supplying source and destination blending factors.
  191. See Material::setSceneBlending for more details.
  192. @see
  193. Material::setSceneBlending
  194. */
  195. enum SceneBlendType
  196. {
  197. /// Make the object transparent based on the final alpha values in the texture
  198. SBT_TRANSPARENT_ALPHA,
  199. /// Make the object transparent based on the colour values in the texture (brighter = more opaque)
  200. SBT_TRANSPARENT_COLOUR,
  201. /// Add the texture values to the existing scene content
  202. SBT_ADD,
  203. /// Multiply the 2 colours together
  204. SBT_MODULATE,
  205. /// The default blend mode where source replaces destination
  206. SBT_REPLACE
  207. // TODO : more
  208. };
  209. /** Blending factors for manually blending objects with the scene. If there isn't a predefined
  210. SceneBlendType that you like, then you can specify the blending factors directly to affect the
  211. combination of object and the existing scene. See Material::setSceneBlending for more details.
  212. */
  213. enum SceneBlendFactor
  214. {
  215. SBF_ONE,
  216. SBF_ZERO,
  217. SBF_DEST_COLOUR,
  218. SBF_SOURCE_COLOUR,
  219. SBF_ONE_MINUS_DEST_COLOUR,
  220. SBF_ONE_MINUS_SOURCE_COLOUR,
  221. SBF_DEST_ALPHA,
  222. SBF_SOURCE_ALPHA,
  223. SBF_ONE_MINUS_DEST_ALPHA,
  224. SBF_ONE_MINUS_SOURCE_ALPHA
  225. };
  226. /** Blending operations controls how objects are blended into the scene. The default operation
  227. is add (+) but by changing this you can change how drawn objects are blended into the
  228. existing scene.
  229. */
  230. enum SceneBlendOperation
  231. {
  232. SBO_ADD,
  233. SBO_SUBTRACT,
  234. SBO_REVERSE_SUBTRACT,
  235. SBO_MIN,
  236. SBO_MAX
  237. };
  238. /** @} */
  239. /** @} */
  240. }
  241. #endif