OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreShaderExLayeredBlending.h
Go to the documentation of this 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 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef _OgreShaderExLayeredBlending_
29 #define _OgreShaderExLayeredBlending_
30 
32 #ifdef RTSHADER_SYSTEM_BUILD_EXT_SHADERS
33 #include "OgreShaderFFPTexturing.h"
35 
36 namespace Ogre {
37 namespace RTShader {
38 
39 #define SGX_LIB_LAYEREDBLENDING "SGXLib_LayeredBlending"
40 
44 class _OgreRTSSExport LayeredBlending : public FFPTexturing
45 {
46 public:
47  enum BlendMode
48  {
49  LB_Invalid = -1,
50  LB_FFPBlend,
51  LB_BlendNormal,
52  LB_BlendLighten,
53  LB_BlendDarken,
54  LB_BlendMultiply,
55  LB_BlendAverage,
56  LB_BlendAdd,
57  LB_BlendSubtract,
58  LB_BlendDifference,
59  LB_BlendNegation,
60  LB_BlendExclusion,
61  LB_BlendScreen,
62  LB_BlendOverlay,
63  LB_BlendSoftLight,
64  LB_BlendHardLight,
65  LB_BlendColorDodge,
66  LB_BlendColorBurn,
67  LB_BlendLinearDodge,
68  LB_BlendLinearBurn,
69  LB_BlendLinearLight,
70  LB_BlendVividLight,
71  LB_BlendPinLight,
72  LB_BlendHardMix,
73  LB_BlendReflect,
74  LB_BlendGlow,
75  LB_BlendPhoenix,
76  LB_BlendSaturation,
77  LB_BlendColor,
78  LB_BlendLuminosity,
79  LB_MaxBlendModes
80  };
81 
82  enum SourceModifier
83  {
84  SM_Invalid = -1,
85  SM_None,
86  SM_Source1Modulate,
87  SM_Source2Modulate,
88  SM_Source1InvModulate,
89  SM_Source2InvModulate,
90  SM_MaxSourceModifiers
91  };
92 
93  struct TextureBlend
94  {
95  TextureBlend() : blendMode(LB_Invalid), sourceModifier(SM_Invalid), customNum(0) {}
96 
97  //The blend mode to use
98  BlendMode blendMode;
99  //The source modification to use
100  SourceModifier sourceModifier;
101  // The number of the custom param controlling the source modification
102  int customNum;
103  //The parameter controlling the source modification
104  ParameterPtr modControlParam;
105  };
106 
107 
109  LayeredBlending();
110 
114  virtual const Ogre::String& getType () const;
115 
116 
122  void setBlendMode(unsigned short index, BlendMode mode);
123 
127  BlendMode getBlendMode(unsigned short index) const;
128 
129 
130 
136  void setSourceModifier(unsigned short index, SourceModifier modType, int customNum);
137 
145  bool getSourceModifier(unsigned short index, SourceModifier& modType, int& customNum) const;
146 
150  virtual void copyFrom(const SubRenderState& rhs);
151 
152  static String Type;
153 
154 // Protected methods
155 protected:
156 
160  virtual bool resolveParameters(ProgramSet* programSet);
161 
165  virtual bool resolveDependencies(Ogre::RTShader::ProgramSet* programSet);
166 
167 
168  virtual void addPSBlendInvocations(Function* psMain,
169  ParameterPtr arg1,
170  ParameterPtr arg2,
171  ParameterPtr texel,
172  int samplerIndex,
173  const LayerBlendModeEx& blendMode,
174  const int groupOrder,
175  int& internalCounter,
176  int targetChannels);
181  void addPSModifierInvocation(Function* psMain,
182  int samplerIndex,
183  ParameterPtr arg1,
184  ParameterPtr arg2,
185  const int groupOrder,
186  int& internalCounter,
187  int targetChannels);
188 
189  // Attributes.
190 protected:
191  vector<TextureBlend>::type mTextureBlends;
192 
193 };
194 
195 
196 
201 class LayeredBlendingFactory : public SubRenderStateFactory
202 {
203 public:
204 
208  virtual const String& getType() const;
209 
213  virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, TextureUnitState* texState, SGScriptTranslator* translator);
214 
218  virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, const TextureUnitState* srcTextureUnit, const TextureUnitState* dstTextureUnit);
219 
220 
221 protected:
222 
226  virtual SubRenderState* createInstanceImpl();
227 
231  LayeredBlending::BlendMode stringToBlendMode(const String &strValue);
235  String blendModeToString(LayeredBlending::BlendMode blendMode);
236 
240  LayeredBlending::SourceModifier stringToSourceModifier(const String &strValue);
241 
245  String sourceModifierToString(LayeredBlending::SourceModifier modifier);
246 
252  LayeredBlending* createOrRetrieveSubRenderState(SGScriptTranslator* translator);
253 };
254 
255 } // namespace RTShader
256 } // namespace Ogre
257 
258 #endif // RTSHADER_SYSTEM_BUILD_EXT_SHADERS
259 #endif // _OgreShaderExLayeredBlending_
#define _OgreRTSSExport
SharedPtr< Parameter > ParameterPtr
_StringBase String
Definition: OgreCommon.h:53
Container class for shader based programs.