[1809] | 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 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 | #ifndef __BLENDMODE_H__
|
---|
| 26 | #define __BLENDMODE_H__
|
---|
| 27 |
|
---|
| 28 | #include "OgrePrerequisites.h"
|
---|
| 29 | #include "OgreColourValue.h"
|
---|
| 30 |
|
---|
| 31 | namespace Ogre {
|
---|
| 32 |
|
---|
| 33 | /** Type of texture blend mode.
|
---|
| 34 | */
|
---|
| 35 | enum LayerBlendType
|
---|
| 36 | {
|
---|
| 37 | LBT_COLOUR,
|
---|
| 38 | LBT_ALPHA
|
---|
| 39 | };
|
---|
| 40 |
|
---|
| 41 | /** List of valid texture blending operations, for use with TextureUnitState::setColourOperation.
|
---|
| 42 | @remarks
|
---|
| 43 | This list is a more limited list than LayerBlendOperationEx because it only
|
---|
| 44 | includes operations that are supportable in both multipass and multitexture
|
---|
| 45 | rendering and thus provides automatic fallback if multitexture hardware
|
---|
| 46 | is lacking or insufficient.
|
---|
| 47 | */
|
---|
| 48 | enum LayerBlendOperation {
|
---|
| 49 | /// Replace all colour with texture with no adjustment
|
---|
| 50 | LBO_REPLACE,
|
---|
| 51 | /// Add colour components together.
|
---|
| 52 | LBO_ADD,
|
---|
| 53 | /// Multiply colour components together.
|
---|
| 54 | LBO_MODULATE,
|
---|
| 55 | /// Blend based on texture alpha
|
---|
| 56 | LBO_ALPHA_BLEND
|
---|
| 57 |
|
---|
| 58 | };
|
---|
| 59 |
|
---|
| 60 | /** Expert list of valid texture blending operations, for use with TextureUnitState::setColourOperationEx
|
---|
| 61 | and TextureUnitState::setAlphaOperation, and internally in the LayerBlendModeEx class. It's worth
|
---|
| 62 | noting that these operations are for blending <i>between texture layers</i> and not between rendered objects
|
---|
| 63 | and the existing scene. Because all of these modes are only supported in multitexture hardware it may be
|
---|
| 64 | required to set up a fallback operation where this hardware is not available.
|
---|
| 65 | */
|
---|
| 66 | enum LayerBlendOperationEx {
|
---|
| 67 | /// use source1 without modification
|
---|
| 68 | LBX_SOURCE1,
|
---|
| 69 | /// use source2 without modification
|
---|
| 70 | LBX_SOURCE2,
|
---|
| 71 | /// multiply source1 and source2 together
|
---|
| 72 | LBX_MODULATE,
|
---|
| 73 | /// as LBX_MODULATE but brighten afterwards (x2)
|
---|
| 74 | LBX_MODULATE_X2,
|
---|
| 75 | /// as LBX_MODULATE but brighten more afterwards (x4)
|
---|
| 76 | LBX_MODULATE_X4,
|
---|
| 77 | /// add source1 and source2 together
|
---|
| 78 | LBX_ADD,
|
---|
| 79 | /// as LBX_ADD, but subtract 0.5 from the result
|
---|
| 80 | LBX_ADD_SIGNED,
|
---|
| 81 | /// as LBX_ADD, but subtract product from the sum
|
---|
| 82 | LBX_ADD_SMOOTH,
|
---|
| 83 | /// subtract source2 from source1
|
---|
| 84 | LBX_SUBTRACT,
|
---|
| 85 | /// use interpolated alpha value from vertices to scale source1, then add source2 scaled by (1-alpha)
|
---|
| 86 | LBX_BLEND_DIFFUSE_ALPHA,
|
---|
| 87 | /// as LBX_BLEND_DIFFUSE_ALPHA, but use alpha from texture
|
---|
| 88 | LBX_BLEND_TEXTURE_ALPHA,
|
---|
| 89 | /// as LBX_BLEND_DIFFUSE_ALPHA, but use current alpha from previous stages
|
---|
| 90 | LBX_BLEND_CURRENT_ALPHA,
|
---|
| 91 | /// as LBX_BLEND_DIFFUSE_ALPHA but use a constant manual blend value (0.0-1.0)
|
---|
| 92 | LBX_BLEND_MANUAL,
|
---|
| 93 | /// dotproduct of color1 and color2
|
---|
| 94 | LBX_DOTPRODUCT,
|
---|
| 95 | /// use interpolated color values from vertices to scale source1, then add source2 scaled by (1-color)
|
---|
| 96 | LBX_BLEND_DIFFUSE_COLOUR
|
---|
| 97 | };
|
---|
| 98 |
|
---|
| 99 | /** List of valid sources of values for blending operations used
|
---|
| 100 | in TextureUnitState::setColourOperation and TextureUnitState::setAlphaOperation,
|
---|
| 101 | and internally in the LayerBlendModeEx class.
|
---|
| 102 | */
|
---|
| 103 | enum LayerBlendSource
|
---|
| 104 | {
|
---|
| 105 | /// the colour as built up from previous stages
|
---|
| 106 | LBS_CURRENT,
|
---|
| 107 | /// the colour derived from the texture assigned to this layer
|
---|
| 108 | LBS_TEXTURE,
|
---|
| 109 | /// the interpolated diffuse colour from the vertices
|
---|
| 110 | LBS_DIFFUSE,
|
---|
| 111 | /// the interpolated specular colour from the vertices
|
---|
| 112 | LBS_SPECULAR,
|
---|
| 113 | /// a colour supplied manually as a separate argument
|
---|
| 114 | LBS_MANUAL
|
---|
| 115 | };
|
---|
| 116 | /** Class which manages blending of both colour and alpha components.
|
---|
| 117 | @remarks
|
---|
| 118 | This class is a utility class used by both TextureUnitState and
|
---|
| 119 | RenderSystem to wrap up the details of a blending operation. This blending
|
---|
| 120 | operation could be used for blending colour or alpha in a texture layer.
|
---|
| 121 | This class is really only for use by OGRE, since apps can deal with
|
---|
| 122 | blending modes through the TextureUnitState class methods
|
---|
| 123 | setColourOperation and setAlphaOperation.
|
---|
| 124 | @par
|
---|
| 125 | It's worth noting that these operations are for blending <i>between texture
|
---|
| 126 | layers</i> and not between rendered objects and the existing scene. If
|
---|
| 127 | you wish to make an object blend with others in the scene, e.g. to make
|
---|
| 128 | transparent objects etc, use the Material::setSceneBlending method.
|
---|
| 129 | */
|
---|
| 130 | class _OgreExport LayerBlendModeEx
|
---|
| 131 | {
|
---|
| 132 | public:
|
---|
| 133 | /// The type of blending (colour or alpha)
|
---|
| 134 | LayerBlendType blendType;
|
---|
| 135 | /// The operation to be applied
|
---|
| 136 | LayerBlendOperationEx operation;
|
---|
| 137 | /// The first source of colour/alpha
|
---|
| 138 | LayerBlendSource source1;
|
---|
| 139 | /// The second source of colour/alpha
|
---|
| 140 | LayerBlendSource source2;
|
---|
| 141 |
|
---|
| 142 | /// Manual colour value for manual source1
|
---|
| 143 | ColourValue colourArg1;
|
---|
| 144 | /// Manual colour value for manual source2
|
---|
| 145 | ColourValue colourArg2;
|
---|
| 146 | /// Manual alpha value for manual source1
|
---|
| 147 | Real alphaArg1;
|
---|
| 148 | /// Manual alpha value for manual source2
|
---|
| 149 | Real alphaArg2;
|
---|
| 150 | /// Manual blending factor
|
---|
| 151 | Real factor;
|
---|
| 152 |
|
---|
| 153 | bool operator==(const LayerBlendModeEx& rhs) const
|
---|
| 154 | {
|
---|
| 155 | if (blendType != rhs.blendType) return false;
|
---|
| 156 |
|
---|
| 157 | if (blendType == LBT_COLOUR)
|
---|
| 158 | {
|
---|
| 159 |
|
---|
| 160 | if (operation == rhs.operation &&
|
---|
| 161 | source1 == rhs.source1 &&
|
---|
| 162 | source2 == rhs.source2 &&
|
---|
| 163 | colourArg1 == rhs.colourArg1 &&
|
---|
| 164 | colourArg2 == rhs.colourArg2 &&
|
---|
| 165 | factor == rhs.factor)
|
---|
| 166 | {
|
---|
| 167 | return true;
|
---|
| 168 | }
|
---|
| 169 | }
|
---|
| 170 | else // if (blendType == LBT_ALPHA)
|
---|
| 171 | {
|
---|
| 172 | if (operation == rhs.operation &&
|
---|
| 173 | source1 == rhs.source1 &&
|
---|
| 174 | source2 == rhs.source2 &&
|
---|
| 175 | alphaArg1 == rhs.alphaArg1 &&
|
---|
| 176 | alphaArg2 == rhs.alphaArg2 &&
|
---|
| 177 | factor == rhs.factor)
|
---|
| 178 | {
|
---|
| 179 | return true;
|
---|
| 180 | }
|
---|
| 181 | }
|
---|
| 182 | return false;
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | bool operator!=(const LayerBlendModeEx& rhs) const
|
---|
| 186 | {
|
---|
| 187 | return !(*this == rhs);
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 |
|
---|
| 192 | };
|
---|
| 193 |
|
---|
| 194 | /** Types of blending that you can specify between an object and the existing contents of the scene.
|
---|
| 195 | @remarks
|
---|
| 196 | As opposed to the LayerBlendType, which classifies blends between texture layers, these blending
|
---|
| 197 | types blend between the output of the texture units and the pixels already in the viewport,
|
---|
| 198 | allowing for object transparency, glows, etc.
|
---|
| 199 | @par
|
---|
| 200 | These types are provided to give quick and easy access to common effects. You can also use
|
---|
| 201 | the more manual method of supplying source and destination blending factors.
|
---|
| 202 | See Material::setSceneBlending for more details.
|
---|
| 203 | @see
|
---|
| 204 | Material::setSceneBlending
|
---|
| 205 | */
|
---|
| 206 | enum SceneBlendType
|
---|
| 207 | {
|
---|
| 208 | /// Make the object transparent based on the final alpha values in the texture
|
---|
| 209 | SBT_TRANSPARENT_ALPHA,
|
---|
| 210 | /// Make the object transparent based on the colour values in the texture (brighter = more opaque)
|
---|
| 211 | SBT_TRANSPARENT_COLOUR,
|
---|
| 212 | /// Add the texture values to the existing scene content
|
---|
| 213 | SBT_ADD,
|
---|
| 214 | /// Multiply the 2 colours together
|
---|
| 215 | SBT_MODULATE,
|
---|
| 216 | /// The default blend mode where source replaces destination
|
---|
| 217 | SBT_REPLACE
|
---|
| 218 | // TODO : more
|
---|
| 219 | };
|
---|
| 220 |
|
---|
| 221 | /** Blending factors for manually blending objects with the scene. If there isn't a predefined
|
---|
| 222 | SceneBlendType that you like, then you can specify the blending factors directly to affect the
|
---|
| 223 | combination of object and the existing scene. See Material::setSceneBlending for more details.
|
---|
| 224 | */
|
---|
| 225 | enum SceneBlendFactor
|
---|
| 226 | {
|
---|
| 227 | SBF_ONE,
|
---|
| 228 | SBF_ZERO,
|
---|
| 229 | SBF_DEST_COLOUR,
|
---|
| 230 | SBF_SOURCE_COLOUR,
|
---|
| 231 | SBF_ONE_MINUS_DEST_COLOUR,
|
---|
| 232 | SBF_ONE_MINUS_SOURCE_COLOUR,
|
---|
| 233 | SBF_DEST_ALPHA,
|
---|
| 234 | SBF_SOURCE_ALPHA,
|
---|
| 235 | SBF_ONE_MINUS_DEST_ALPHA,
|
---|
| 236 | SBF_ONE_MINUS_SOURCE_ALPHA
|
---|
| 237 |
|
---|
| 238 | };
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | #endif
|
---|