source: GTP/trunk/App/Demos/Geom/OgreStuff/include/OgreBlendMode.h @ 1092

Revision 1092, 9.2 KB checked in by gumbau, 18 years ago (diff)

LodStrips? and LODTrees demos

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://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
31namespace 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    };
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
140        /// Manual colour value for manual source1
141        ColourValue colourArg1;
142        /// Manual colour value for manual source2
143        ColourValue colourArg2;
144        /// Manual alpha value for manual source1
145        Real alphaArg1;
146        /// Manual colour value for manual source1
147        Real alphaArg2;
148        /// Manual blending factor
149        Real factor;
150
151        bool operator==(const LayerBlendModeEx& rhs) const
152        {
153            if (blendType != rhs.blendType) return false;
154
155            if (blendType == LBT_COLOUR)
156            {
157
158                if (operation == rhs.operation &&
159                    source1 == rhs.source1 &&
160                    source2 == rhs.source2 &&
161                    colourArg1 == rhs.colourArg1 &&
162                    colourArg2 == rhs.colourArg2 &&
163                    factor == rhs.factor)
164                {
165                    return true;
166                }
167            }
168            else // if (blendType == LBT_ALPHA)
169            {
170                if (operation == rhs.operation &&
171                    source1 == rhs.source1 &&
172                    source2 == rhs.source2 &&
173                    alphaArg1 == rhs.alphaArg1 &&
174                    alphaArg2 == rhs.alphaArg2 &&
175                    factor == rhs.factor)
176                {
177                    return true;
178                }
179            }
180            return false;
181        }
182
183        bool operator!=(const LayerBlendModeEx& rhs) const
184        {
185            return !(*this == rhs);
186        }
187
188
189
190    };
191
192    /** Types of blending that you can specify between an object and the existing contents of the scene.
193        @remarks
194            As opposed to the LayerBlendType, which classifies blends between texture layers, these blending
195            types blend between the output of the texture units and the pixels already in the viewport,
196            allowing for object transparency, glows, etc.
197        @par
198            These types are provided to give quick and easy access to common effects. You can also use
199            the more manual method of supplying source and destination blending factors.
200            See Material::setSceneBlending for more details.
201        @see
202            Material::setSceneBlending
203    */
204    enum SceneBlendType
205    {
206        /// Make the object transparent based on the final alpha values in the texture
207        SBT_TRANSPARENT_ALPHA,
208        /// Make the object transparent based on the colour values in the texture (brighter = more opaque)
209        SBT_TRANSPARENT_COLOUR,
210        /// Add the texture values to the existing scene content
211        SBT_ADD,
212                /// Multiply the 2 colours together
213                SBT_MODULATE
214        // TODO : more
215    };
216
217    /** Blending factors for manually blending objects with the scene. If there isn't a predefined
218        SceneBlendType that you like, then you can specify the blending factors directly to affect the
219        combination of object and the existing scene. See Material::setSceneBlending for more details.
220    */
221    enum SceneBlendFactor
222    {
223        SBF_ONE,
224        SBF_ZERO,
225        SBF_DEST_COLOUR,
226        SBF_SOURCE_COLOUR,
227        SBF_ONE_MINUS_DEST_COLOUR,
228        SBF_ONE_MINUS_SOURCE_COLOUR,
229        SBF_DEST_ALPHA,
230        SBF_SOURCE_ALPHA,
231        SBF_ONE_MINUS_DEST_ALPHA,
232        SBF_ONE_MINUS_SOURCE_ALPHA
233
234    };
235}
236
237#endif
Note: See TracBrowser for help on using the repository browser.