OgreShaderExHardwareSkinning.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 Permission is hereby granted, free of charge, to any person obtaining a copy
00009 of this software and associated documentation files (the "Software"), to deal
00010 in the Software without restriction, including without limitation the rights
00011 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00012 copies of the Software, and to permit persons to whom the Software is
00013 furnished to do so, subject to the following conditions:
00014 
00015 The above copyright notice and this permission notice shall be included in
00016 all copies or substantial portions of the Software.
00017 
00018 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00019 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00021 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00022 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00023 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00024 THE SOFTWARE.
00025 -----------------------------------------------------------------------------
00026 */
00027 #ifndef _ShaderExHardwareSkinning_
00028 #define _ShaderExHardwareSkinning_
00029 
00030 #include "OgreShaderPrerequisites.h"
00031 
00032 #ifdef RTSHADER_SYSTEM_BUILD_EXT_SHADERS
00033 #include "OgreShaderSubRenderState.h"
00034 #include "OgreShaderParameter.h"
00035 #include "OgreRenderSystem.h"
00036 #include "OgreShaderFunctionAtom.h"
00037 #include "OgreShaderExLinearSkinning.h"
00038 #include "OgreShaderExHardwareSkinningTechnique.h"
00039 #include "OgreShaderExDualQuaternionSkinning.h"
00040 #include "OgreShaderExLinearSkinning.h"
00041 
00042 #define HS_MAX_WEIGHT_COUNT 4
00043 
00044 namespace Ogre {
00045 namespace RTShader {
00046 
00047 
00048 class HardwareSkinningFactory;
00049 
00061 class _OgreRTSSExport HardwareSkinning : public SubRenderState
00062 {
00063 public:
00064     struct SkinningData
00065     {
00066         SkinningData() :
00067             isValid(true), maxBoneCount(0), maxWeightCount(0), skinningType(ST_LINEAR), correctAntipodalityHandling(false), scalingShearingSupport(false)
00068         {}
00069 
00070         bool isValid;
00071         ushort maxBoneCount;
00072         ushort maxWeightCount;
00073         SkinningType skinningType;
00074         bool correctAntipodalityHandling;
00075         bool scalingShearingSupport;
00076     };
00077 
00078 // Interface.
00079 public:
00081     HardwareSkinning();
00082 
00086     virtual const String& getType() const;
00087 
00091     virtual int getExecutionOrder() const;
00092 
00096     virtual void copyFrom(const SubRenderState& rhs);
00097 
00110     void setHardwareSkinningParam(ushort boneCount, ushort weightCount, SkinningType skinningType = ST_LINEAR,  bool correctAntipodalityHandling = false, bool scalingShearingSupport = false);
00111 
00116     ushort getBoneCount();
00117 
00122     ushort getWeightCount();
00123 
00128     SkinningType getSkinningType();
00129 
00134     bool hasCorrectAntipodalityHandling();
00135 
00140     bool hasScalingShearingSupport();
00141 
00145     virtual bool preAddToRenderState(const RenderState* renderState, Pass* srcPass, Pass* dstPass);
00146 
00150     void _setCreator(const HardwareSkinningFactory* pCreator) { mCreator = pCreator; }
00151 
00152     static String Type;
00153 
00154 // Protected methods
00155 protected:
00159     virtual bool resolveParameters (ProgramSet* programSet);
00160 
00164     virtual bool resolveDependencies (ProgramSet* programSet);
00165 
00169     virtual bool addFunctionInvocations (ProgramSet* programSet);
00170 
00171     SharedPtr<LinearSkinning> mLinear;
00172     SharedPtr<DualQuaternionSkinning> mDualQuat;
00173     SharedPtr<HardwareSkinningTechnique> mActiveTechnique;
00174     
00175     const HardwareSkinningFactory* mCreator; 
00176     SkinningType mSkinningType;
00177 };
00178 
00179 _OgreRTSSExport void operator<<(std::ostream& o, const HardwareSkinning::SkinningData& data);
00180 
00185 class _OgreRTSSExport HardwareSkinningFactory : public SubRenderStateFactory, 
00186     public Singleton<HardwareSkinningFactory>
00187 {
00188 public:
00189     HardwareSkinningFactory();
00190     
00194     virtual const String& getType() const;
00195 
00199     virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator);
00200 
00204     virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
00205 
00209     virtual void setCustomShadowCasterMaterials(const SkinningType skinningType, const MaterialPtr& caster1Weight, const MaterialPtr& caster2Weight,
00210         const MaterialPtr& caster3Weight, const MaterialPtr& caster4Weight);
00211     
00215     virtual void setCustomShadowReceiverMaterials(const SkinningType skinningType, const MaterialPtr& receiver1Weight, const MaterialPtr& receiver2Weight,
00216         const MaterialPtr& receiver3Weight, const MaterialPtr& receiver4Weight);
00217 
00221     const MaterialPtr& getCustomShadowCasterMaterial(const SkinningType skinningType, ushort index) const;
00222 
00226     const MaterialPtr& getCustomShadowReceiverMaterial(const SkinningType skinningType, ushort index) const;
00227 
00243     void prepareEntityForSkinning(const Entity* pEntity, SkinningType skinningType = ST_LINEAR, bool correctAntidpodalityHandling = false, bool shearScale = false);
00244 
00255     ushort getMaxCalculableBoneCount() const {
00256         return mMaxCalculableBoneCount; }
00261     void setMaxCalculableBoneCount(ushort count) {
00262         mMaxCalculableBoneCount = count; }
00263 
00281     static HardwareSkinningFactory& getSingleton(void);
00282     
00300     static HardwareSkinningFactory* getSingletonPtr(void);
00301 
00302 protected:
00312     bool extractSkeletonData(const Entity* pEntity, ushort& boneCount,
00313         ushort& weightCount);
00314 
00325     bool imprintSkeletonData(const MaterialPtr& pMaterial, bool isVaild, 
00326         ushort boneCount, ushort weightCount, SkinningType skinningType, bool correctAntidpodalityHandling, bool scalingShearingSupport);
00327 
00328 protected:
00329 
00333     virtual SubRenderState* createInstanceImpl();
00334 
00336     MaterialPtr mCustomShadowCasterMaterialsLinear[HS_MAX_WEIGHT_COUNT];
00337     MaterialPtr mCustomShadowCasterMaterialsDualQuaternion[HS_MAX_WEIGHT_COUNT];
00338 
00340     MaterialPtr mCustomShadowReceiverMaterialsLinear[HS_MAX_WEIGHT_COUNT];
00341     MaterialPtr mCustomShadowReceiverMaterialsDualQuaternion[HS_MAX_WEIGHT_COUNT];
00342 
00345     ushort mMaxCalculableBoneCount;
00346 };
00347 
00352 }
00353 }
00354 
00355 #endif
00356 #endif
00357 

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 Fri May 25 23:36:26 2012