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
    00176     const HardwareSkinningFactory* mCreator;
    00177     SkinningType mSkinningType;
    00178 };
    00179
    00180 _OgreRTSSExport void operator<<(std::ostream& o, const HardwareSkinning::SkinningData& data);
    00181
    00186 class _OgreRTSSExport HardwareSkinningFactory : public SubRenderStateFactory,
    00187     public Singleton<HardwareSkinningFactory>
    00188 {
    00189 public:
    00190     HardwareSkinningFactory();
    00191
    00195     virtual const String& getType() const;
    00196
    00200     virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator);
    00201
    00205     virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
    00206
    00210     virtual void setCustomShadowCasterMaterials(const SkinningType skinningType, const MaterialPtr& caster1Weight, const MaterialPtr& caster2Weight,
    00211         const MaterialPtr& caster3Weight, const MaterialPtr& caster4Weight);
    00212
    00216     virtual void setCustomShadowReceiverMaterials(const SkinningType skinningType, const MaterialPtr& receiver1Weight, const MaterialPtr& receiver2Weight,
    00217         const MaterialPtr& receiver3Weight, const MaterialPtr& receiver4Weight);
    00218
    00222     const MaterialPtr& getCustomShadowCasterMaterial(const SkinningType skinningType, ushort index) const;
    00223
    00227     const MaterialPtr& getCustomShadowReceiverMaterial(const SkinningType skinningType, ushort index) const;
    00228
    00244     void prepareEntityForSkinning(const Entity* pEntity, SkinningType skinningType = ST_LINEAR, bool correctAntidpodalityHandling = false, bool shearScale = false);
    00245
    00256     ushort getMaxCalculableBoneCount() const {
    00257         return mMaxCalculableBoneCount; }
    00262     void setMaxCalculableBoneCount(ushort count) {
    00263         mMaxCalculableBoneCount = count; }
    00264
    00282     static HardwareSkinningFactory& getSingleton(void);
    00283
    00301     static HardwareSkinningFactory* getSingletonPtr(void);
    00302
    00303 protected:
    00313     bool extractSkeletonData(const Entity* pEntity, ushort& boneCount,
    00314         ushort& weightCount);
    00315
    00326     bool imprintSkeletonData(const MaterialPtr& pMaterial, bool isVaild,
    00327         ushort boneCount, ushort weightCount, SkinningType skinningType, bool correctAntidpodalityHandling, bool scalingShearingSupport);
    00328
    00329 protected:
    00330
    00334     virtual SubRenderState* createInstanceImpl();
    00335
    00337     MaterialPtr mCustomShadowCasterMaterialsLinear[HS_MAX_WEIGHT_COUNT];
    00338     MaterialPtr mCustomShadowCasterMaterialsDualQuaternion[HS_MAX_WEIGHT_COUNT];
    00339
    00341     MaterialPtr mCustomShadowReceiverMaterialsLinear[HS_MAX_WEIGHT_COUNT];
    00342     MaterialPtr mCustomShadowReceiverMaterialsDualQuaternion[HS_MAX_WEIGHT_COUNT];
    00343
    00346     ushort mMaxCalculableBoneCount;
    00347 };
    00348
    00353 }
    00354 }
    00355
    00356 #endif
    00357 #endif
    00358

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