OGRE  1.9
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 #include "OgreShaderParameter.h"
35 #include "OgreRenderSystem.h"
36 #include "OgreShaderFunctionAtom.h"
41 
42 #define HS_MAX_WEIGHT_COUNT 4
43 
44 namespace Ogre {
45 namespace RTShader {
46 
47 
48 class HardwareSkinningFactory;
49 
61 class _OgreRTSSExport HardwareSkinning : public SubRenderState
62 {
63 public:
64  struct SkinningData
65  {
66  SkinningData() :
67  isValid(true), maxBoneCount(0), maxWeightCount(0), skinningType(ST_LINEAR), correctAntipodalityHandling(false), scalingShearingSupport(false)
68  {}
69 
70  bool isValid;
71  ushort maxBoneCount;
72  ushort maxWeightCount;
73  SkinningType skinningType;
74  bool correctAntipodalityHandling;
75  bool scalingShearingSupport;
76  };
77 
78 // Interface.
79 public:
81  HardwareSkinning();
82 
86  virtual const String& getType() const;
87 
91  virtual int getExecutionOrder() const;
92 
96  virtual void copyFrom(const SubRenderState& rhs);
97 
108  void setHardwareSkinningParam(ushort boneCount, ushort weightCount, SkinningType skinningType = ST_LINEAR, bool correctAntipodalityHandling = false, bool scalingShearingSupport = false);
109 
114  ushort getBoneCount();
115 
120  ushort getWeightCount();
121 
126  SkinningType getSkinningType();
127 
132  bool hasCorrectAntipodalityHandling();
133 
138  bool hasScalingShearingSupport();
139 
143  virtual bool preAddToRenderState(const RenderState* renderState, Pass* srcPass, Pass* dstPass);
144 
148  void _setCreator(const HardwareSkinningFactory* pCreator) { mCreator = pCreator; }
149 
150  static String Type;
151 
152 // Protected methods
153 protected:
157  virtual bool resolveParameters(ProgramSet* programSet);
158 
162  virtual bool resolveDependencies(ProgramSet* programSet);
163 
167  virtual bool addFunctionInvocations(ProgramSet* programSet);
168 
169  SharedPtr<LinearSkinning> mLinear;
170  SharedPtr<DualQuaternionSkinning> mDualQuat;
171  SharedPtr<HardwareSkinningTechnique> mActiveTechnique;
172 
174  const HardwareSkinningFactory* mCreator;
175  SkinningType mSkinningType;
176 };
177 
178 _OgreRTSSExport void operator<<(std::ostream& o, const HardwareSkinning::SkinningData& data);
179 
184 class _OgreRTSSExport HardwareSkinningFactory : public SubRenderStateFactory,
185  public Singleton<HardwareSkinningFactory>
186 {
187 public:
188  HardwareSkinningFactory();
189 
193  virtual const String& getType() const;
194 
198  virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator);
199 
203  virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
204 
208  virtual void setCustomShadowCasterMaterials(const SkinningType skinningType, const MaterialPtr& caster1Weight, const MaterialPtr& caster2Weight,
209  const MaterialPtr& caster3Weight, const MaterialPtr& caster4Weight);
210 
214  virtual void setCustomShadowReceiverMaterials(const SkinningType skinningType, const MaterialPtr& receiver1Weight, const MaterialPtr& receiver2Weight,
215  const MaterialPtr& receiver3Weight, const MaterialPtr& receiver4Weight);
216 
220  const MaterialPtr& getCustomShadowCasterMaterial(const SkinningType skinningType, ushort index) const;
221 
225  const MaterialPtr& getCustomShadowReceiverMaterial(const SkinningType skinningType, ushort index) const;
226 
242  void prepareEntityForSkinning(const Entity* pEntity, SkinningType skinningType = ST_LINEAR, bool correctAntidpodalityHandling = false, bool shearScale = false);
243 
254  ushort getMaxCalculableBoneCount() const {
255  return mMaxCalculableBoneCount; }
260  void setMaxCalculableBoneCount(ushort count) {
261  mMaxCalculableBoneCount = count; }
262 
280  static HardwareSkinningFactory& getSingleton(void);
281 
299  static HardwareSkinningFactory* getSingletonPtr(void);
300 
301 protected:
312  bool extractSkeletonData(const Entity* pEntity, unsigned int subEntityIndex,
313  ushort& boneCount, ushort& weightCount);
314 
325  bool imprintSkeletonData(const MaterialPtr& pMaterial, bool isValid,
326  ushort boneCount, ushort weightCount, SkinningType skinningType, bool correctAntidpodalityHandling, bool scalingShearingSupport);
327 
328 protected:
329 
333  virtual SubRenderState* createInstanceImpl();
334 
336  MaterialPtr mCustomShadowCasterMaterialsLinear[HS_MAX_WEIGHT_COUNT];
337  MaterialPtr mCustomShadowCasterMaterialsDualQuaternion[HS_MAX_WEIGHT_COUNT];
338 
340  MaterialPtr mCustomShadowReceiverMaterialsLinear[HS_MAX_WEIGHT_COUNT];
341  MaterialPtr mCustomShadowReceiverMaterialsDualQuaternion[HS_MAX_WEIGHT_COUNT];
342 
345  ushort mMaxCalculableBoneCount;
346 };
347 
352 }
353 }
354 
355 #endif
356 #endif
357 
#define _OgreRTSSExport
SharedPtr< Material > MaterialPtr
unsigned short ushort
std::ostream & operator<<(std::ostream &o, const TRect< T > &r)
Definition: OgreCommon.h:636
_StringBase String