OgreShaderExLayeredBlending.h
Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004 (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 #ifndef _OgreShaderExLayeredBlending_
00029 #define _OgreShaderExLayeredBlending_
00030 
00031 #include "OgreShaderPrerequisites.h"
00032 #ifdef RTSHADER_SYSTEM_BUILD_EXT_SHADERS
00033 #include "OgreShaderFFPTexturing.h"
00034 #include "OgreShaderProgramSet.h"
00035 #include "OgreShaderParameter.h"
00036 #include "OgreShaderFunction.h"
00037 #include "OgreShaderSubRenderState.h"
00038 
00039 namespace Ogre {
00040 namespace RTShader {
00041 
00042 #define SGX_LIB_LAYEREDBLENDING     "SGXLib_LayeredBlending"
00043 
00047 class _OgreRTSSExport LayeredBlending : public FFPTexturing
00048 {
00049 public:
00050     enum BlendMode
00051     {
00052         LB_Invalid = -1,
00053         LB_FFPBlend,
00054         LB_BlendNormal,
00055         LB_BlendLighten,            
00056         LB_BlendDarken,     
00057         LB_BlendMultiply,
00058         LB_BlendAverage,    
00059         LB_BlendAdd,
00060         LB_BlendSubtract,
00061         LB_BlendDifference,
00062         LB_BlendNegation,
00063         LB_BlendExclusion,
00064         LB_BlendScreen,
00065         LB_BlendOverlay,
00066         LB_BlendSoftLight,
00067         LB_BlendHardLight,
00068         LB_BlendColorDodge,
00069         LB_BlendColorBurn, 
00070         LB_BlendLinearDodge,
00071         LB_BlendLinearBurn,
00072         LB_BlendLinearLight,
00073         LB_BlendVividLight,
00074         LB_BlendPinLight,
00075         LB_BlendHardMix,
00076         LB_BlendReflect,
00077         LB_BlendGlow,
00078         LB_BlendPhoenix,
00079         LB_BlendSaturation,
00080         LB_BlendColor,
00081         LB_BlendLuminosity,
00082         LB_MaxBlendModes
00083     };
00084 
00085     enum SourceModifier
00086     {
00087         SM_Invalid = -1,
00088         SM_None,
00089         SM_Source1Modulate,
00090         SM_Source2Modulate,
00091         SM_Source1InvModulate,
00092         SM_Source2InvModulate,
00093         SM_MaxSourceModifiers
00094     };
00095 
00096     struct TextureBlend
00097     {
00098         TextureBlend() : blendMode(LB_Invalid), sourceModifier(SM_Invalid), customNum(0) {}
00099 
00100         //The blend mode to use
00101         BlendMode blendMode;
00102         //The source modification to use
00103         SourceModifier sourceModifier;
00104         // The number of the custom param controlling the source modification
00105         int customNum;
00106         //The parameter controlling the source modification
00107         ParameterPtr modControlParam;
00108     };
00109 
00110 
00112     LayeredBlending();
00113 
00117     virtual const Ogre::String& getType                 () const;
00118 
00119 
00125     void setBlendMode(unsigned short index, BlendMode mode);
00126 
00130     BlendMode getBlendMode(unsigned short index) const;
00131 
00132     
00133 
00139     void setSourceModifier(unsigned short index, SourceModifier modType, int customNum);
00140 
00147     bool getSourceModifier(unsigned short index, SourceModifier& , int& customNum) const;
00148 
00152     virtual void copyFrom(const SubRenderState& rhs);
00153 
00154     static String Type;
00155 
00156 // Protected methods
00157 protected:
00158     
00162     virtual bool resolveParameters(ProgramSet* programSet);
00163 
00167     virtual bool resolveDependencies(Ogre::RTShader::ProgramSet* programSet);
00168 
00169 
00170     virtual void addPSBlendInvocations(Function* psMain, 
00171                                     ParameterPtr arg1,
00172                                     ParameterPtr arg2,
00173                                     ParameterPtr texel,
00174                                     int samplerIndex,
00175                                     const LayerBlendModeEx& blendMode,
00176                                     const int groupOrder, 
00177                                     int& internalCounter,
00178                                     int targetChannels);
00183     void addPSModifierInvocation(Function* psMain, 
00184                                 int samplerIndex, 
00185                                 ParameterPtr arg1,
00186                                 ParameterPtr arg2,
00187                                 const int groupOrder, 
00188                                 int& internalCounter,
00189                                 int targetChannels);
00190 
00191     // Attributes.
00192 protected:
00193     vector<TextureBlend>::type mTextureBlends;
00194 
00195 };
00196 
00197 
00198 
00203 class LayeredBlendingFactory : public SubRenderStateFactory
00204 {
00205 public:
00206 
00210     virtual const String& getType() const;
00211 
00215     virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, TextureUnitState* texState, SGScriptTranslator* translator);
00216 
00220     virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, const TextureUnitState* srcTextureUnit, const TextureUnitState* dstTextureUnit);
00221 
00222     
00223 protected:
00224 
00228     virtual SubRenderState* createInstanceImpl();
00229 
00233     LayeredBlending::BlendMode stringToBlendMode(const String &strValue);
00237     String blendModeToString(LayeredBlending::BlendMode blendMode);
00238 
00242     LayeredBlending::SourceModifier stringToSourceModifier(const String &strValue);
00243     
00247     String sourceModifierToString(LayeredBlending::SourceModifier modifier);
00248 
00254     LayeredBlending* createOrRetrieveSubRenderState(SGScriptTranslator* translator);
00255 };
00256 
00257 }
00258 }
00259 
00260 #endif
00261 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:23