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-2013 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 
00108     void setHardwareSkinningParam(ushort boneCount, ushort weightCount, SkinningType skinningType = ST_LINEAR,  bool correctAntipodalityHandling = false, bool scalingShearingSupport = false);
00109 
00114     ushort getBoneCount();
00115 
00120     ushort getWeightCount();
00121 
00126     SkinningType getSkinningType();
00127 
00132     bool hasCorrectAntipodalityHandling();
00133 
00138     bool hasScalingShearingSupport();
00139 
00143     virtual bool preAddToRenderState(const RenderState* renderState, Pass* srcPass, Pass* dstPass);
00144 
00148     void _setCreator(const HardwareSkinningFactory* pCreator) { mCreator = pCreator; }
00149 
00150     static String Type;
00151 
00152 // Protected methods
00153 protected:
00157     virtual bool resolveParameters(ProgramSet* programSet);
00158 
00162     virtual bool resolveDependencies(ProgramSet* programSet);
00163 
00167     virtual bool addFunctionInvocations(ProgramSet* programSet);
00168 
00169     SharedPtr<LinearSkinning> mLinear;
00170     SharedPtr<DualQuaternionSkinning> mDualQuat;
00171     SharedPtr<HardwareSkinningTechnique> mActiveTechnique;
00172     
00174     const HardwareSkinningFactory* mCreator;
00175     SkinningType mSkinningType;
00176 };
00177 
00178 _OgreRTSSExport void operator<<(std::ostream& o, const HardwareSkinning::SkinningData& data);
00179 
00184 class _OgreRTSSExport HardwareSkinningFactory : public SubRenderStateFactory, 
00185     public Singleton<HardwareSkinningFactory>
00186 {
00187 public:
00188     HardwareSkinningFactory();
00189     
00193     virtual const String& getType() const;
00194 
00198     virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator);
00199 
00203     virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
00204 
00208     virtual void setCustomShadowCasterMaterials(const SkinningType skinningType, const MaterialPtr& caster1Weight, const MaterialPtr& caster2Weight,
00209         const MaterialPtr& caster3Weight, const MaterialPtr& caster4Weight);
00210     
00214     virtual void setCustomShadowReceiverMaterials(const SkinningType skinningType, const MaterialPtr& receiver1Weight, const MaterialPtr& receiver2Weight,
00215         const MaterialPtr& receiver3Weight, const MaterialPtr& receiver4Weight);
00216 
00220     const MaterialPtr& getCustomShadowCasterMaterial(const SkinningType skinningType, ushort index) const;
00221 
00225     const MaterialPtr& getCustomShadowReceiverMaterial(const SkinningType skinningType, ushort index) const;
00226 
00242     void prepareEntityForSkinning(const Entity* pEntity, SkinningType skinningType = ST_LINEAR, bool correctAntidpodalityHandling = false, bool shearScale = false);
00243 
00254     ushort getMaxCalculableBoneCount() const {
00255         return mMaxCalculableBoneCount; }
00260     void setMaxCalculableBoneCount(ushort count) {
00261         mMaxCalculableBoneCount = count; }
00262 
00280     static HardwareSkinningFactory& getSingleton(void);
00281     
00299     static HardwareSkinningFactory* getSingletonPtr(void);
00300 
00301 protected:
00312     bool extractSkeletonData(const Entity* pEntity, unsigned int subEntityIndex,
00313         ushort& boneCount, ushort& weightCount);
00314 
00325     bool imprintSkeletonData(const MaterialPtr& pMaterial, bool isValid, 
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 Mon Jul 27 2020 13:40:45