OGRE  1.8
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-2013 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"
34 #include "OgreShaderProgramSet.h"
35 #include "OgreShaderParameter.h"
36 #include "OgreShaderFunction.h"
38 
39 namespace Ogre {
40 namespace RTShader {
41 
42 #define SGX_LIB_LAYEREDBLENDING "SGXLib_LayeredBlending"
43 
47 class _OgreRTSSExport LayeredBlending : public FFPTexturing
48 {
49 public:
50  enum BlendMode
51  {
52  LB_Invalid = -1,
53  LB_FFPBlend,
54  LB_BlendNormal,
55  LB_BlendLighten,
56  LB_BlendDarken,
57  LB_BlendMultiply,
58  LB_BlendAverage,
59  LB_BlendAdd,
60  LB_BlendSubtract,
61  LB_BlendDifference,
62  LB_BlendNegation,
63  LB_BlendExclusion,
64  LB_BlendScreen,
65  LB_BlendOverlay,
66  LB_BlendSoftLight,
67  LB_BlendHardLight,
68  LB_BlendColorDodge,
69  LB_BlendColorBurn,
70  LB_BlendLinearDodge,
71  LB_BlendLinearBurn,
72  LB_BlendLinearLight,
73  LB_BlendVividLight,
74  LB_BlendPinLight,
75  LB_BlendHardMix,
76  LB_BlendReflect,
77  LB_BlendGlow,
78  LB_BlendPhoenix,
79  LB_BlendSaturation,
80  LB_BlendColor,
81  LB_BlendLuminosity,
82  LB_MaxBlendModes
83  };
84 
85  enum SourceModifier
86  {
87  SM_Invalid = -1,
88  SM_None,
89  SM_Source1Modulate,
90  SM_Source2Modulate,
91  SM_Source1InvModulate,
92  SM_Source2InvModulate,
93  SM_MaxSourceModifiers
94  };
95 
96  struct TextureBlend
97  {
98  TextureBlend() : blendMode(LB_Invalid), sourceModifier(SM_Invalid), customNum(0) {}
99 
100  //The blend mode to use
101  BlendMode blendMode;
102  //The source modification to use
103  SourceModifier sourceModifier;
104  // The number of the custom param controlling the source modification
105  int customNum;
106  //The parameter controlling the source modification
107  ParameterPtr modControlParam;
108  };
109 
110 
112  LayeredBlending();
113 
117  virtual const Ogre::String& getType () const;
118 
119 
125  void setBlendMode(unsigned short index, BlendMode mode);
126 
130  BlendMode getBlendMode(unsigned short index) const;
131 
132 
133 
139  void setSourceModifier(unsigned short index, SourceModifier modType, int customNum);
140 
147  bool getSourceModifier(unsigned short index, SourceModifier& , int& customNum) const;
148 
152  virtual void copyFrom(const SubRenderState& rhs);
153 
154  static String Type;
155 
156 // Protected methods
157 protected:
158 
162  virtual bool resolveParameters(ProgramSet* programSet);
163 
167  virtual bool resolveDependencies(Ogre::RTShader::ProgramSet* programSet);
168 
169 
170  virtual void addPSBlendInvocations(Function* psMain,
171  ParameterPtr arg1,
172  ParameterPtr arg2,
173  ParameterPtr texel,
174  int samplerIndex,
175  const LayerBlendModeEx& blendMode,
176  const int groupOrder,
177  int& internalCounter,
178  int targetChannels);
183  void addPSModifierInvocation(Function* psMain,
184  int samplerIndex,
185  ParameterPtr arg1,
186  ParameterPtr arg2,
187  const int groupOrder,
188  int& internalCounter,
189  int targetChannels);
190 
191  // Attributes.
192 protected:
193  vector<TextureBlend>::type mTextureBlends;
194 
195 };
196 
197 
198 
203 class LayeredBlendingFactory : public SubRenderStateFactory
204 {
205 public:
206 
210  virtual const String& getType() const;
211 
215  virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, TextureUnitState* texState, SGScriptTranslator* translator);
216 
220  virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, const TextureUnitState* srcTextureUnit, const TextureUnitState* dstTextureUnit);
221 
222 
223 protected:
224 
228  virtual SubRenderState* createInstanceImpl();
229 
233  LayeredBlending::BlendMode stringToBlendMode(const String &strValue);
237  String blendModeToString(LayeredBlending::BlendMode blendMode);
238 
242  LayeredBlending::SourceModifier stringToSourceModifier(const String &strValue);
243 
247  String sourceModifierToString(LayeredBlending::SourceModifier modifier);
248 
254  LayeredBlending* createOrRetrieveSubRenderState(SGScriptTranslator* translator);
255 };
256 
257 }
258 }
259 
260 #endif
261 #endif
SharedPtr< Parameter > ParameterPtr
#define _OgreRTSSExport
_StringBase String
Container class for shader based programs.