OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreShaderExHardwareSkinning.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 THE SOFTWARE.
25 -----------------------------------------------------------------------------
26 */
27 #ifndef _ShaderExHardwareSkinning_
28 #define _ShaderExHardwareSkinning_
29 
31 
32 #ifdef RTSHADER_SYSTEM_BUILD_EXT_SHADERS
34 
35 #define HS_MAX_WEIGHT_COUNT 4
36 
37 namespace Ogre {
38 namespace RTShader {
39 
40  class HardwareSkinningFactory;
41  class DualQuaternionSkinning;
42  class HardwareSkinningTechnique;
43  class LinearSkinning;
44 
56 class _OgreRTSSExport HardwareSkinning : public SubRenderState
57 {
58 public:
59  struct SkinningData
60  {
61  SkinningData() :
62  isValid(true), maxBoneCount(0), maxWeightCount(0), skinningType(ST_LINEAR), correctAntipodalityHandling(false), scalingShearingSupport(false)
63  {}
64 
65  bool isValid;
66  ushort maxBoneCount;
67  ushort maxWeightCount;
68  SkinningType skinningType;
69  bool correctAntipodalityHandling;
70  bool scalingShearingSupport;
71  };
72 
73 // Interface.
74 public:
76  HardwareSkinning();
77 
81  virtual const String& getType() const;
82 
86  virtual int getExecutionOrder() const;
87 
91  virtual void copyFrom(const SubRenderState& rhs);
92 
103  void setHardwareSkinningParam(ushort boneCount, ushort weightCount, SkinningType skinningType = ST_LINEAR, bool correctAntipodalityHandling = false, bool scalingShearingSupport = false);
104 
109  ushort getBoneCount();
110 
115  ushort getWeightCount();
116 
121  SkinningType getSkinningType();
122 
127  bool hasCorrectAntipodalityHandling();
128 
133  bool hasScalingShearingSupport();
134 
138  virtual bool preAddToRenderState(const RenderState* renderState, Pass* srcPass, Pass* dstPass);
139 
143  void _setCreator(const HardwareSkinningFactory* pCreator) { mCreator = pCreator; }
144 
145  static String Type;
146 
147 // Protected methods
148 protected:
152  virtual bool resolveParameters(ProgramSet* programSet);
153 
157  virtual bool resolveDependencies(ProgramSet* programSet);
158 
162  virtual bool addFunctionInvocations(ProgramSet* programSet);
163 
164  SharedPtr<LinearSkinning> mLinear;
165  SharedPtr<DualQuaternionSkinning> mDualQuat;
166  SharedPtr<HardwareSkinningTechnique> mActiveTechnique;
167 
169  const HardwareSkinningFactory* mCreator;
170  SkinningType mSkinningType;
171 };
172 
173 _OgreRTSSExport void operator<<(std::ostream& o, const HardwareSkinning::SkinningData& data);
174 
179 class _OgreRTSSExport HardwareSkinningFactory : public SubRenderStateFactory,
180  public Singleton<HardwareSkinningFactory>
181 {
182 public:
183  HardwareSkinningFactory();
184 
188  virtual const String& getType() const;
189 
193  virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator);
194 
198  virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
199 
203  virtual void setCustomShadowCasterMaterials(const SkinningType skinningType, const MaterialPtr& caster1Weight, const MaterialPtr& caster2Weight,
204  const MaterialPtr& caster3Weight, const MaterialPtr& caster4Weight);
205 
209  virtual void setCustomShadowReceiverMaterials(const SkinningType skinningType, const MaterialPtr& receiver1Weight, const MaterialPtr& receiver2Weight,
210  const MaterialPtr& receiver3Weight, const MaterialPtr& receiver4Weight);
211 
215  const MaterialPtr& getCustomShadowCasterMaterial(const SkinningType skinningType, ushort index) const;
216 
220  const MaterialPtr& getCustomShadowReceiverMaterial(const SkinningType skinningType, ushort index) const;
221 
237  void prepareEntityForSkinning(const Entity* pEntity, SkinningType skinningType = ST_LINEAR, bool correctAntidpodalityHandling = false, bool shearScale = false);
238 
249  ushort getMaxCalculableBoneCount() const {
250  return mMaxCalculableBoneCount; }
255  void setMaxCalculableBoneCount(ushort count) {
256  mMaxCalculableBoneCount = count; }
257 
275  static HardwareSkinningFactory& getSingleton(void);
276 
294  static HardwareSkinningFactory* getSingletonPtr(void);
295 
296 protected:
307  bool extractSkeletonData(const Entity* pEntity, unsigned int subEntityIndex,
308  ushort& boneCount, ushort& weightCount);
309 
320  bool imprintSkeletonData(const MaterialPtr& pMaterial, bool isValid,
321  ushort boneCount, ushort weightCount, SkinningType skinningType, bool correctAntidpodalityHandling, bool scalingShearingSupport);
322 
323 protected:
324 
328  virtual SubRenderState* createInstanceImpl();
329 
331  MaterialPtr mCustomShadowCasterMaterialsLinear[HS_MAX_WEIGHT_COUNT];
332  MaterialPtr mCustomShadowCasterMaterialsDualQuaternion[HS_MAX_WEIGHT_COUNT];
333 
335  MaterialPtr mCustomShadowReceiverMaterialsLinear[HS_MAX_WEIGHT_COUNT];
336  MaterialPtr mCustomShadowReceiverMaterialsDualQuaternion[HS_MAX_WEIGHT_COUNT];
337 
340  ushort mMaxCalculableBoneCount;
341 };
342 
347 }
348 }
349 
350 #endif
351 #endif
352 
#define _OgreRTSSExport
SharedPtr< Material > MaterialPtr
unsigned short ushort
std::ostream & operator<<(std::ostream &o, const TRect< T > &r)
Definition: OgreCommon.h:666
_StringBase String
Definition: OgreCommon.h:53