fbsdk/fbshader.h Source File

fbshader.h
Go to the documentation of this file.
1 #ifndef _FB_SHADER_H_
2 #define _FB_SHADER_H_
3 /**************************************************************************
4 Copyright (c) 1994 - 2009 Autodesk, Inc. and/or its licensors.
5 All Rights Reserved.
6 
7 The coded instructions, statements, computer programs, and/or related
8 material (collectively the "Data") in these files contain unpublished
9 information proprietary to Autodesk, Inc. and/or its licensors, which is
10 protected by Canada and United States of America federal copyright law
11 and by international treaties.
12 
13 The Data may not be disclosed or distributed to third parties, in whole
14 or in part, without the prior written consent of Autodesk, Inc.
15 ("Autodesk").
16 
17 THE DATA IS PROVIDED "AS IS" AND WITHOUT WARRANTY.
18 ALL WARRANTIES ARE EXPRESSLY EXCLUDED AND DISCLAIMED. AUTODESK MAKES NO
19 WARRANTY OF ANY KIND WITH RESPECT TO THE DATA, EXPRESS, IMPLIED OR
20 ARISING BY CUSTOM OR TRADE USAGE, AND DISCLAIMS ANY IMPLIED WARRANTIES
21 OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
22 PURPOSE OR USE. WITHOUT LIMITING THE FOREGOING, AUTODESK DOES NOT
23 WARRANT THAT THE OPERATION OF THE DATA WILL BE UNINTERRUPTED OR ERROR
24 FREE.
25 
26 IN NO EVENT SHALL AUTODESK, ITS AFFILIATES, PARENT COMPANIES, LICENSORS
27 OR SUPPLIERS ("AUTODESK GROUP") BE LIABLE FOR ANY LOSSES, DAMAGES OR
28 EXPENSES OF ANY KIND (INCLUDING WITHOUT LIMITATION PUNITIVE OR MULTIPLE
29 DAMAGES OR OTHER SPECIAL, DIRECT, INDIRECT, EXEMPLARY, INCIDENTAL, LOSS
30 OF PROFITS, REVENUE OR DATA, COST OF COVER OR CONSEQUENTIAL LOSSES OR
31 DAMAGES OF ANY KIND), HOWEVER CAUSED, AND REGARDLESS OF THE THEORY OF
32 LIABILITY, WHETHER DERIVED FROM CONTRACT, TORT (INCLUDING, BUT NOT
33 LIMITED TO, NEGLIGENCE), OR OTHERWISE, ARISING OUT OF OR RELATING TO THE
34 DATA OR ITS USE OR ANY OTHER PERFORMANCE, WHETHER OR NOT AUTODESK HAS
35 BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE.
36 
37 **************************************************************************/
38 
45 #include <kaydaradef.h>
46 #ifndef FBSDK_DLL
47 
50 #define FBSDK_DLL K_DLLIMPORT
51 #endif
52 
53 #include <fbsdk/fbcomponent.h>
54 #include <fbsdk/fbcore.h>
55 
56 K_FORWARD( KRenderOptions );
57 K_FORWARD( KModelRenderInfo );
58 K_FORWARD( KShaderModelInfo );
59 
60 #ifdef FBSDKUseNamespace
61 namespace FBSDKNamespace {
62 #endif
63 
71 #define FBRegisterShader( UniqueNameStr, ClassName, Label, Description, IconFilename ) \
72  HIObject RegisterShader##ClassName( HIObject /*pOwner*/,const char* pName,void * /*pData*/) \
73  { \
74  ClassName *Class = new ClassName( pName ); \
75  Class->UniqueName = UniqueNameStr; \
76  Class->ShaderDescription = Description; \
77  if (Class->FBCreate()) { \
78  return Class->GetHIObject(); \
79  } else { \
80  delete Class; \
81  return NULL; \
82  } \
83 } \
84  FBLibraryModule( ClassName ) \
85  { \
86  FBRegisterObject( ClassName##R1,"renderer/usershader/ogl",Label,Description,RegisterShader##ClassName,true, IconFilename ); \
87  FBRegisterObject( ClassName##R2,"FbxStorable/Shader",UniqueNameStr,Description,RegisterShader##ClassName,true, IconFilename ); \
88 }
89 
94 #define FBShaderDeclare( ClassName, Parent ) \
95  FBClassDeclare( ClassName,Parent); \
96 public: \
97  ClassName(const char* pName):Parent(pName) { FBClassInit; } \
98 private:
99 
103 #define FBShaderImplementation( ThisComponent ) \
104  FBClassImplementation( ThisComponent )
105 
107  // FBShaderManager
109  FB_FORWARD( FBShaderManager );
110  FB_FORWARD( FBShader );
111  FB_FORWARD( FBMaterial );
112  FB_FORWARD( FBCamera );
113 
222  {
228 
233  FBShaderManager& operator=( const FBShaderManager& );
234 
235  public:
236 
238  FBShaderManager();
239 
245  ~FBShaderManager();
246 
258  FBShader* CreateShader( const char* pShaderTypeName );
259 
269 
292  };
293 
294 
296  // FBShader - Shader layer on top of internals.
298 
301  {
302  public:
303  FBShaderModelInfo(FBShader* pShader, HKModelRenderInfo pInfo, int pSubRegionIndex);
304  virtual ~FBShaderModelInfo();
305 
307  virtual void UpdateModelShaderInfo(int pShader_Version);
308 
310  FBModel* GetFBModel() { return mFBModel; }
311 
313  FBMaterial* GetFBMaterial();
314 
315  int GetSubRegionIndex();
316 
318  KShaderModelInfo* GetShaderModelInfo() const { return mLocalPtr; }
319 
321  int GetModelVersion() const;
322 
324  int GetShaderVersion() const;
325 
327  bool GetOriginalTextureFlag() const;
328 
330  unsigned int GetGeometryArrayIds() const;
331 
333  void SetGeometryArrayIds(unsigned int pArrayIds);
334 
335  private:
336  KShaderModelInfo* mLocalPtr;
337  FBModel* mFBModel;
338  };
339 
341  FB_FORWARD( FBViewingOptions );
342  FB_FORWARD( FBRenderOptions );
343 
345  {
346  public:
348 
350  FBCamera* GetRenderingCamera();
351 
355  int GetRenderFrameId() const;
356 
361  K_DEPRECATED_2014 bool IsIDBufferPicking() const;
362 
366  bool IsIDBufferRendering() const;
367 
371  float GetIDBufferPickingAlphaThreshold() const;
372 
376  bool IsOfflineRendering() const;
377 
378  FBViewingOptions* GetViewerOptions() const;
379 
380 #ifndef DOXYGEN_SHOULD_SKIP_THIS
381 
382  HKRenderOptions mRenderOptions;
383 #endif
384  };
385 
387 
392  kFBPassPreRender = 1 << 0,
393  kFBPassFlat = 1 << 1,
394  kFBPassLighted = 1 << 2,
395  kFBPassMatte = 1 << 3,
399  kFBPassAddColor = 1 << 7,
402  };
403  FB_DEFINE_ENUM( FBSDK_DLL, RenderingPass );
404 
410  {
418  };
419  FB_DEFINE_ENUM( FBSDK_DLL, AlphaSource );
420 
424  {
430  };
431  FB_DEFINE_ENUM( FBSDK_DLL, ShaderCapacity );
432 
437  {
449  };
450  FB_DEFINE_ENUM( FBSDK_DLL, ShaderPassActionCallback );
451 
456 
458  class FBSDK_DLL FBShader : public FBBox
459  {
460  //--- Open Reality declaration.
462 
463  public:
468  FBShader( const char* pName, HIObject pObject=NULL);
469 
470  IObject_Declare(K_IMPLEMENTATION); // Interface to IObject.
471 
477  virtual FBShaderModelInfo* NewShaderModelInfo(HKModelRenderInfo pModelRenderInfo, int pSubRegionIndex);
478 
483  virtual void UpdateModelShaderInfo( FBRenderOptions* pOptions, FBShaderModelInfo* pInfo );
484 
489  virtual void DestroyShaderModelInfo( FBRenderOptions* pOptions, FBShaderModelInfo* pInfo );
490 
494  virtual void ReplaceAll( FBModel* pModel );
495 
499  virtual void Append( FBModel* pModel );
500 
504  virtual bool ShaderNeedBeginRender();
505 
511  virtual void ShaderBeginRender( FBRenderOptions* pOptions, FBShaderModelInfo* pInfo );
512 
518  virtual void ShadeModel( FBRenderOptions* pOptions, FBShaderModelInfo* pInfo, FBRenderingPass pPass );
519 
524  virtual void ShadeModelShadow(FBRenderOptions* pRenderOptions, FBShaderModelInfo* pInfo);
525 
530 
535  virtual void ShaderPassTypeBegin ( FBRenderOptions* pRenderOptions, FBRenderingPass pPass);
536 
541  virtual void ShaderPassTypeEnd ( FBRenderOptions* pRenderOptions, FBRenderingPass pPass);
542 
547  virtual void ShaderPassInstanceBegin( FBRenderOptions* pRenderOptions, FBRenderingPass pPass);
548 
553  virtual void ShaderPassInstanceEnd ( FBRenderOptions* pRenderOptions, FBRenderingPass pPass);
554 
560  virtual void ShaderPassMaterialBegin( FBRenderOptions* pRenderOptions, FBRenderingPass pPass, FBShaderModelInfo* pInfo);
561 
567  virtual void ShaderPassMaterialEnd ( FBRenderOptions* pRenderOptions, FBRenderingPass pPass, FBShaderModelInfo* pInfo);
568 
574  virtual void ShaderPassGeometryBegin( FBRenderOptions* pRenderOptions, FBRenderingPass pPass, FBShaderModelInfo* pInfo);
575 
581  virtual void ShaderPassGeometryEnd ( FBRenderOptions* pRenderOptions, FBRenderingPass pPass, FBShaderModelInfo* pInfo);
582 
588  virtual void ShaderPassModelsDraw ( FBRenderOptions* pRenderOptions, FBRenderingPass pPass, const FBArrayTemplate<FBShaderModelInfo*>& pInfoArray);
589 
595  virtual void ShaderPassModelDraw ( FBRenderOptions* pRenderOptions, FBRenderingPass pPass, FBShaderModelInfo* pInfo);
596 
600  virtual void ShaderPassDrawShadowBegin( FBRenderOptions* pRenderOptions);
601 
605  virtual void ShaderPassDrawShadowEnd ( FBRenderOptions* pRenderOptions);
606 
608  FBShaderPassActionCallback GetShaderPassActionCallback() const;
610  void SetShaderPassActionCallback( FBShaderPassActionCallback pCallback);
611 
613 
617  virtual void CloneShaderParameter( FBShader* pNewShader );
618 
623  virtual void DetachDisplayContext( FBRenderOptions* pOptions, FBShaderModelInfo* pInfo );
624 
629  virtual bool FbxStore (FBFbxObject* pFbxObject);
630 
636  virtual bool FbxRetrieve(FBFbxObject* pFbxObject, FBRenderer* pRenderer);
637 
638  const char* ShaderDescription;
639 
641  void InvalidateShaderVersion ();
642 
644  int GetShaderVersion () const;
645 
647  FBShaderCapacity GetShaderCapacity( ) const;
648 
650  bool HasShaderCapacity (FBShaderCapacity pCapacity);
651 
655  void SetShaderCapacity (FBShaderCapacity pCapacity, bool pOn);
656 
658  int GetDrawInstancedMaximumSize() const;
659 
661  void SetDrawInstancedMaximumSize(int pMaxSize);
662 
667  virtual void UploadModelViewMatrixArrayForDrawInstanced(const double* pModelViewMatrixArray, int pCount);
668 
669 
670  public:
674 
681 
682  protected:
689  static FBRenderingPass GetRenderingPassNeededForAlpha(FBAlphaSource pTransparency);
690  };
691 
693  // FBPropertyListShader - List of shaders
697  {
698  public:
704  FBShader* operator[](int pIndex);
705  };
706 
708  // FBShaderLighted
711  FB_DEFINE_COMPONENT( FBSDK_DLL, ShaderLighted );
712 
780  {
781  //--- Open Reality declaration.
783 
784  public:
789  FBShaderLighted( const char* pName, HIObject pObject=NULL );
790 
793 
796 
799 
802  };
803 
804 
806  // FBShaderShadowLive
809  FB_DEFINE_COMPONENT( FBSDK_DLL, ShaderShadowLive );
810 
815  {
822  };
823  FB_DEFINE_ENUM( FBSDK_DLL, ShadowType );
824 
828  {
832  };
833  FB_DEFINE_ENUM( FBSDK_DLL, ShadowFrameType );
834 
835 
885  {
886  //--- Open Reality declaration.
888 
889  public:
894  FBShaderShadowLive( const char* pName, HIObject pObject=NULL );
895 
902 
905 
906  };
907 
908 
909 #ifdef FBSDKUseNamespace
910 }
911 #endif
912 #endif /* _FB_SHADER_H_ */
FBPropertyAnimatableDouble ShadowIntensity
Read Write Property: Controls the darkness of shadows cast by a selected object.
Definition: fbshader.h:897
FBPropertyDouble Specular
Read Write Property: Changes an object's level of shininess when it reflects light by affecting the s...
Definition: fbshader.h:798
This shader will able to draw additional texture layer (for example, live shadow or reflection)...
Definition: fbshader.h:429
FBPropertyDouble ShadowZOffset
Read Write Property: Specifies the offset of the Live Shadow shader's plane from the original selecte...
Definition: fbshader.h:900
Model class.
Definition: fbmodel.h:273
#define __FBClassDeclare(Name, Parent)
For internal use only.
Definition: fbcomponent.h:132
class FBPropertyBaseEnum< enum FBAlphaSource > FBPropertyAlphaSource
Definition: fbshader.h:419
After everything.
Definition: fbshader.h:401
FBRenderingPass
Rendering Pass.
Definition: fbshader.h:390
FBAlphaSource
Shader transparency computation.
Definition: fbshader.h:409
Open Reality renderer interface.
Definition: fbrenderer.h:450
K_FORWARD(KStringList)
FBStringList ShaderTypeNamesLocalized
List of available shaders.
Definition: fbshader.h:291
Accurate Transparency.
Definition: fbshader.h:412
#define FB_DEFINE_COMPONENT(DllTag, Type)
Define a component and give it the ability to be a property.
Definition: fbproperties.h:139
#define FB_DEFINE_LIST(DllTag, Type)
Define a component list.
Definition: fbproperties.h:161
FBPropertyBool UseLuminosity
Read Write Property: Activate the Luminosity option.
Definition: fbshader.h:794
FBPropertyAnimatableDouble Alpha
Read Write Property: Controls the actual effect of the shader on the object.
Definition: fbshader.h:801
class FBPropertyBase< double, kFBPT_double > FBPropertyDouble
Property: double
class FBPropertyBaseAnimatable< double, kFBPT_double > FBPropertyAnimatableDouble
FBPropertyBaseAnimatableDouble type definition.
List of scene objects.
Definition: fbcomponent.h:573
Creates custom cameras and manages system cameras.
Definition: fbcamera.h:206
FBModel * GetFBModel()
Get Model.
Definition: fbshader.h:310
#define NULL
Definition: kaydara.h:169
FBPropertyShadowType ShadowType
Read Write Property: Indicate which shadow type is desired.
Definition: fbshader.h:896
Viewing options for rendering.
Definition: fbrenderer.h:175
Shader class.
Definition: fbshader.h:458
Before anything.
Definition: fbshader.h:392
#define K_IMPLEMENTATION
Definition: iobject.h:53
Shader manager.
Definition: fbshader.h:221
Lighted shader class.
Definition: fbshader.h:779
This shader is acting as a material effect, should sitting behind the material central network...
Definition: fbshader.h:426
Contains definitions for devices, boxes and models.
Similar to the Projective Shadow, except that it uses a boolean algorithm to create a self-shadow...
Definition: fbshader.h:819
#define IObject_Declare(IsPure)
Definition: iobject.h:75
FBPropertyBool UseContrast
Read Write Property: Activate the Contrast option.
Definition: fbshader.h:791
Writes to depth buffer where Alpha > 0.5.
Definition: fbshader.h:397
#define FB_DEFINE_ENUM(DllTag, Type)
Define an enum and give it the ability to be a property.
Definition: fbproperties.h:148
FBX file interface.
Definition: fbfbx.h:80
FBShadowFrameType
Shadow calculation methods.
Definition: fbshader.h:827
Uses a texture projection to create a shadow.
Definition: fbshader.h:817
class FBPropertyBase< bool, kFBPT_bool > FBPropertyBool
Property: bool
FBPropertyRenderingPass RenderingPass
Read Write Property: Rendering pass object are shaded in.
Definition: fbshader.h:680
FBPropertyShadowFrameType ShadowFrameType
Read Write Property: Used to select the shadow calculation method.
Definition: fbshader.h:901
FBPropertyListObject Lights
List: List of light object which will produce shadows.
Definition: fbshader.h:903
Models are blended additively.
Definition: fbshader.h:399
This shader will able to draw different shape thus generate different shadow than original solid geom...
Definition: fbshader.h:428
Shader Shadow Live class.
Definition: fbshader.h:884
Alpha > 0.5 will show up.
Definition: fbshader.h:395
class FBPropertyBaseEnum< enum FBShadowFrameType > FBPropertyShadowFrameType
Definition: fbshader.h:833
FBShaderCapacity
Shader Capacity.
Definition: fbshader.h:423
PropertyList: Concrete class for PropertyList of component
Definition: fbcomponent.h:553
FBStringList ShaderTypeNames
List of available shaders.
Definition: fbshader.h:268
FBPropertyDouble Luminosity
Read Write Property: Changes the brightness of the object when reflecting light.
Definition: fbshader.h:795
#define __FB_FORWARD(ClassName)
Forwarding of class and typedef declaration.
Definition: fbtypes.h:68
Similar to the Projective Light Map except that it uses a boolean algorithm to create a self-shadow...
Definition: fbshader.h:820
Template class to contain an array of items.
Definition: fbarray.h:77
FBPropertyBool UseGobo
Read Write Property: Includes the gobo in the shadow map calculation.
Definition: fbshader.h:899
KModelRenderInfo * HKModelRenderInfo
Definition: fbshader.h:57
FBPropertyListObject Models
List: List of object which when lighted will cast a shadow.
Definition: fbshader.h:904
#define FBSDKNamespace
FBSDKNamespace define.
Definition: fbversion.h:64
PropertyList: Shader
Definition: fbshader.h:696
Bases the shadow calculation on the shadow of the receiver.
Definition: fbshader.h:829
FBPropertyBool LocalShadow
Read Write Property: Creates an accurate projection of a shadow for each object.
Definition: fbshader.h:898
No pass selected.
Definition: fbshader.h:391
FBShaderPassActionCallback
Shader Pass Action Callback.
Definition: fbshader.h:436
Similar to the Planar Shadow, except that it treats all objects as opaque.
Definition: fbshader.h:821
Basic class definitions.
Material class.
Definition: fbmaterial.h:87
#define FBSDK_DLL
Be sure that FBSDK_DLL is defined only once...
Definition: fbshader.h:50
Uses a texture projection as a shadow.
Definition: fbshader.h:818
A box is a fundamental building block in the application architecture.
Definition: fbcore.h:218
FBPropertyBool UseSpecular
Read Write Property: Activate the Specularity option.
Definition: fbshader.h:797
KShaderModelInfo * GetShaderModelInfo() const
Get Internal ShaderModelInfo object.
Definition: fbshader.h:318
#define K_DEPRECATED_2014
Definition: kaydara.h:412
Use this shadow type to create darkened shadow areas only on planar surfaces.
Definition: fbshader.h:816
This shader can support GL_ARB_draw_instanced extension, and thus could benefit from Geometry instanc...
Definition: fbshader.h:427
class FBPropertyBaseEnum< enum FBShadowType > FBPropertyShadowType
Definition: fbshader.h:823
#define FB_FORWARD(ClassName)
Forwarding of class and typedef declaration.
Definition: fbtypes.h:62
class FBPropertyBaseEnum< enum FBRenderingPass > FBPropertyRenderingPass
Definition: fbshader.h:403
String list.
Definition: fbstring.h:201
KRenderOptions * HKRenderOptions
Definition: fbshader.h:56
FBPropertyBool Enable
Read Write Property: Is the shader Enabled
Definition: fbshader.h:673
Models are sorted and blended.
Definition: fbshader.h:400
const char * ShaderDescription
Description.
Definition: fbshader.h:638
Writes to depth buffer.
Definition: fbshader.h:396
FBShadowType
Shadow types.
Definition: fbshader.h:814
Lighting off.
Definition: fbshader.h:393
Models are blended.
Definition: fbshader.h:398
#define FBClassDeclare(Name, Parent)
Class declaration.
Definition: fbdefines.h:85
Undocumented or unsupported.
Definition: fbshader.h:831
Additive Transparency.
Definition: fbshader.h:416
FBPropertyAlphaSource Transparency
Read Write Property: Indicates the computation method of the transparency.
Definition: fbshader.h:800
FBPropertyDouble Contrast
Read Write Property: Changes the contrast of the object when it reflects light.
Definition: fbshader.h:792
Bases the shadow calculation on the shadow of the caster.
Definition: fbshader.h:830