OGRE  1.9.0
OgreShaderExLayeredBlending.h
Go to the documentation of this file.
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-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef _OgreShaderExLayeredBlending_
29#define _OgreShaderExLayeredBlending_
30
32#ifdef RTSHADER_SYSTEM_BUILD_EXT_SHADERS
35#include "OgreShaderParameter.h"
36#include "OgreShaderFunction.h"
38
39namespace Ogre {
40namespace RTShader {
41
42#define SGX_LIB_LAYEREDBLENDING "SGXLib_LayeredBlending"
43
47class _OgreRTSSExport LayeredBlending : public FFPTexturing
48{
49public:
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
148 bool getSourceModifier(unsigned short index, SourceModifier& modType, int& customNum) const;
149
153 virtual void copyFrom(const SubRenderState& rhs);
154
155 static String Type;
156
157// Protected methods
158protected:
159
163 virtual bool resolveParameters(ProgramSet* programSet);
164
168 virtual bool resolveDependencies(Ogre::RTShader::ProgramSet* programSet);
169
170
171 virtual void addPSBlendInvocations(Function* psMain,
172 ParameterPtr arg1,
173 ParameterPtr arg2,
174 ParameterPtr texel,
175 int samplerIndex,
176 const LayerBlendModeEx& blendMode,
177 const int groupOrder,
178 int& internalCounter,
179 int targetChannels);
184 void addPSModifierInvocation(Function* psMain,
185 int samplerIndex,
186 ParameterPtr arg1,
187 ParameterPtr arg2,
188 const int groupOrder,
189 int& internalCounter,
190 int targetChannels);
191
192 // Attributes.
193protected:
194 vector<TextureBlend>::type mTextureBlends;
195
196};
197
198
199
204class LayeredBlendingFactory : public SubRenderStateFactory
205{
206public:
207
211 virtual const String& getType() const;
212
216 virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, TextureUnitState* texState, SGScriptTranslator* translator);
217
221 virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, const TextureUnitState* srcTextureUnit, const TextureUnitState* dstTextureUnit);
222
223
224protected:
225
229 virtual SubRenderState* createInstanceImpl();
230
234 LayeredBlending::BlendMode stringToBlendMode(const String &strValue);
238 String blendModeToString(LayeredBlending::BlendMode blendMode);
239
243 LayeredBlending::SourceModifier stringToSourceModifier(const String &strValue);
244
248 String sourceModifierToString(LayeredBlending::SourceModifier modifier);
249
255 LayeredBlending* createOrRetrieveSubRenderState(SGScriptTranslator* translator);
256};
257
258} // namespace RTShader
259} // namespace Ogre
260
261#endif // RTSHADER_SYSTEM_BUILD_EXT_SHADERS
262#endif // _OgreShaderExLayeredBlending_
#define _OgreRTSSExport
Container class for shader based programs.
SharedPtr< Parameter > ParameterPtr
_StringBase String