Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/include/OgreBlendMode.h @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

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