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-2013 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 
00148     bool getSourceModifier(unsigned short index, SourceModifier& modType, int& customNum) const;
00149 
00153     virtual void copyFrom(const SubRenderState& rhs);
00154 
00155     static String Type;
00156 
00157 // Protected methods
00158 protected:
00159     
00163     virtual bool resolveParameters(ProgramSet* programSet);
00164 
00168     virtual bool resolveDependencies(Ogre::RTShader::ProgramSet* programSet);
00169 
00170 
00171     virtual void addPSBlendInvocations(Function* psMain, 
00172                                        ParameterPtr arg1,
00173                                        ParameterPtr arg2,
00174                                        ParameterPtr texel,
00175                                        int samplerIndex,
00176                                        const LayerBlendModeEx& blendMode,
00177                                        const int groupOrder, 
00178                                        int& internalCounter,
00179                                        int targetChannels);
00184     void addPSModifierInvocation(Function* psMain, 
00185                                  int samplerIndex, 
00186                                  ParameterPtr arg1,
00187                                  ParameterPtr arg2,
00188                                  const int groupOrder, 
00189                                  int& internalCounter,
00190                                  int targetChannels);
00191 
00192     // Attributes.
00193 protected:
00194     vector<TextureBlend>::type mTextureBlends;
00195 
00196 };
00197 
00198 
00199 
00204 class LayeredBlendingFactory : public SubRenderStateFactory
00205 {
00206 public:
00207 
00211     virtual const String& getType() const;
00212 
00216     virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, TextureUnitState* texState, SGScriptTranslator* translator);
00217 
00221     virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, const TextureUnitState* srcTextureUnit, const TextureUnitState* dstTextureUnit);
00222 
00223     
00224 protected:
00225 
00229     virtual SubRenderState* createInstanceImpl();
00230 
00234     LayeredBlending::BlendMode stringToBlendMode(const String &strValue);
00238     String blendModeToString(LayeredBlending::BlendMode blendMode);
00239 
00243     LayeredBlending::SourceModifier stringToSourceModifier(const String &strValue);
00244     
00248     String sourceModifierToString(LayeredBlending::SourceModifier modifier);
00249 
00255     LayeredBlending* createOrRetrieveSubRenderState(SGScriptTranslator* translator);
00256 };
00257 
00258 } // namespace RTShader
00259 } // namespace Ogre
00260 
00261 #endif // RTSHADER_SYSTEM_BUILD_EXT_SHADERS
00262 #endif // _OgreShaderExLayeredBlending_

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 Mon Jul 27 2020 13:40:45