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 BlendMode blendMode; //The blend mode to use 00101 SourceModifier sourceModifier; //The source modification to use 00102 int customNum; // The number of the custom param controlling the source modification 00103 ParameterPtr modControlParam; //The parameter controlling the source modification 00104 }; 00105 00106 00108 LayeredBlending(); 00109 00113 virtual const Ogre::String& getType () const; 00114 00115 00121 void setBlendMode(unsigned short index, BlendMode mode); 00122 00126 BlendMode getBlendMode(unsigned short index) const; 00127 00128 00129 00135 void setSourceModifier(unsigned short index, SourceModifier modType, int customNum); 00136 00143 bool getSourceModifier(unsigned short index, SourceModifier& , int& customNum) const; 00144 00148 virtual void copyFrom (const SubRenderState& rhs); 00149 00150 static String Type; 00151 00152 // Protected methods 00153 protected: 00154 00158 virtual bool resolveParameters(ProgramSet* programSet); 00159 00163 virtual bool resolveDependencies(Ogre::RTShader::ProgramSet* programSet); 00164 00165 00166 virtual void addPSBlendInvocations(Function* psMain, 00167 ParameterPtr arg1, 00168 ParameterPtr arg2, 00169 ParameterPtr texel, 00170 int samplerIndex, 00171 const LayerBlendModeEx& blendMode, 00172 const int groupOrder, 00173 int& internalCounter, 00174 int targetChannels); 00179 void addPSModifierInvocation(Function* psMain, 00180 int samplerIndex, 00181 ParameterPtr arg1, 00182 ParameterPtr arg2, 00183 const int groupOrder, 00184 int& internalCounter, 00185 int targetChannels); 00186 00187 // Attributes. 00188 protected: 00189 vector<TextureBlend>::type mTextureBlends; 00190 00191 }; 00192 00193 00194 00199 class LayeredBlendingFactory : public SubRenderStateFactory 00200 { 00201 public: 00202 00206 virtual const String& getType () const; 00207 00211 virtual SubRenderState* createInstance (ScriptCompiler* compiler, PropertyAbstractNode* prop, TextureUnitState* texState, SGScriptTranslator* translator); 00212 00216 virtual void writeInstance (MaterialSerializer* ser, SubRenderState* subRenderState, const TextureUnitState* srcTextureUnit, const TextureUnitState* dstTextureUnit); 00217 00218 00219 protected: 00220 00224 virtual SubRenderState* createInstanceImpl (); 00225 00229 LayeredBlending::BlendMode stringToBlendMode(const String &strValue); 00233 String blendModeToString(LayeredBlending::BlendMode blendMode); 00234 00238 LayeredBlending::SourceModifier stringToSourceModifier(const String &strValue); 00239 00243 String sourceModifierToString(LayeredBlending::SourceModifier modifier); 00244 00250 LayeredBlending* createOrRetrieveSubRenderState(SGScriptTranslator* translator); 00251 }; 00252 00253 } 00254 } 00255 00256 #endif 00257 #endif
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:26 2012