Open Reality Reference Guide
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
110  FB_FORWARD( FBShader );
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 
343 
345  {
346  public:
347  FBRenderOptions(HKRenderOptions pOptions);
348 
350  FBCamera* GetRenderingCamera();
351 
355  int GetRenderFrameId() const;
356 
360  bool IsIDBufferRendering() const;
361 
365  float GetIDBufferPickingAlphaThreshold() const;
366 
370  bool IsOfflineRendering() const;
371 
372  FBViewingOptions* GetViewerOptions() const;
373 
374 #ifndef DOXYGEN_SHOULD_SKIP_THIS
375 
376  HKRenderOptions mRenderOptions;
377 #endif
378  };
379 
381 
386  kFBPassPreRender = 1 << 0,
387  kFBPassFlat = 1 << 1,
388  kFBPassLighted = 1 << 2,
389  kFBPassMatte = 1 << 3,
393  kFBPassAddColor = 1 << 7,
396  };
397  FB_DEFINE_ENUM( FBSDK_DLL, RenderingPass );
398 
404  {
412  };
413  FB_DEFINE_ENUM( FBSDK_DLL, AlphaSource );
414 
418  {
419  kFBShaderCapacityNone = 0,
424  };
425  FB_DEFINE_ENUM( FBSDK_DLL, ShaderCapacity );
426 
431  {
432  kFBShaderPassActionNone = 0,
433  kFBShaderPassTypeBegin = 1 << 0,
434  kFBShaderPassTypeEnd = 1 << 1,
435  kFBShaderPassInstanceBegin = 1 << 2,
436  kFBShaderPassInstanceEnd = 1 << 3,
437  kFBShaderPassMaterialBegin = 1 << 4,
438  kFBShaderPassMaterialEnd = 1 << 5,
439  kFBShaderPassGeometryBegin = 1 << 6,
440  kFBShaderPassGeometryEnd = 1 << 7,
441  kFBShaderPassModelsDraw = 1 << 8,
442  kFBShaderPassModelDraw = 1 << 9
443  };
444  FB_DEFINE_ENUM( FBSDK_DLL, ShaderPassActionCallback );
445 
448  FB_DEFINE_COMPONENT ( FBSDK_DLL, Shader );
449  FB_DEFINE_LIST ( FBSDK_DLL, Shader );
450 
452  class FBSDK_DLL FBShader : public FBBox
453  {
454  //--- Open Reality declaration.
456 
457  public:
462  FBShader( const char* pName, HIObject pObject=NULL);
463 
464  IObject_Declare(K_IMPLEMENTATION); // Interface to IObject.
465 
471  virtual FBShaderModelInfo* NewShaderModelInfo(HKModelRenderInfo pModelRenderInfo, int pSubRegionIndex);
472 
477  virtual void UpdateModelShaderInfo( FBRenderOptions* pOptions, FBShaderModelInfo* pInfo );
478 
483  virtual void DestroyShaderModelInfo( FBRenderOptions* pOptions, FBShaderModelInfo* pInfo );
484 
488  virtual void ReplaceAll( FBModel* pModel );
489 
493  virtual void Append( FBModel* pModel );
494 
498  virtual bool ShaderNeedBeginRender();
499 
505  virtual void ShaderBeginRender( FBRenderOptions* pOptions, FBShaderModelInfo* pInfo );
506 
512  virtual void ShadeModel( FBRenderOptions* pOptions, FBShaderModelInfo* pInfo, FBRenderingPass pPass );
513 
518  virtual void ShadeModelShadow(FBRenderOptions* pRenderOptions, FBShaderModelInfo* pInfo);
519 
524 
529  virtual void ShaderPassTypeBegin ( FBRenderOptions* pRenderOptions, FBRenderingPass pPass);
530 
535  virtual void ShaderPassTypeEnd ( FBRenderOptions* pRenderOptions, FBRenderingPass pPass);
536 
541  virtual void ShaderPassInstanceBegin( FBRenderOptions* pRenderOptions, FBRenderingPass pPass);
542 
547  virtual void ShaderPassInstanceEnd ( FBRenderOptions* pRenderOptions, FBRenderingPass pPass);
548 
554  virtual void ShaderPassMaterialBegin( FBRenderOptions* pRenderOptions, FBRenderingPass pPass, FBShaderModelInfo* pInfo);
555 
561  virtual void ShaderPassMaterialEnd ( FBRenderOptions* pRenderOptions, FBRenderingPass pPass, FBShaderModelInfo* pInfo);
562 
568  virtual void ShaderPassGeometryBegin( FBRenderOptions* pRenderOptions, FBRenderingPass pPass, FBShaderModelInfo* pInfo);
569 
575  virtual void ShaderPassGeometryEnd ( FBRenderOptions* pRenderOptions, FBRenderingPass pPass, FBShaderModelInfo* pInfo);
576 
582  virtual void ShaderPassModelsDraw ( FBRenderOptions* pRenderOptions, FBRenderingPass pPass, const FBArrayTemplate<FBShaderModelInfo*>& pInfoArray);
583 
589  virtual void ShaderPassModelDraw ( FBRenderOptions* pRenderOptions, FBRenderingPass pPass, FBShaderModelInfo* pInfo);
590 
594  virtual void ShaderPassDrawShadowBegin( FBRenderOptions* pRenderOptions);
595 
599  virtual void ShaderPassDrawShadowEnd ( FBRenderOptions* pRenderOptions);
600 
602  FBShaderPassActionCallback GetShaderPassActionCallback() const;
604  void SetShaderPassActionCallback( FBShaderPassActionCallback pCallback);
605 
607 
611  virtual void CloneShaderParameter( FBShader* pNewShader );
612 
617  virtual void DetachDisplayContext( FBRenderOptions* pOptions, FBShaderModelInfo* pInfo );
618 
623  virtual bool FbxStore (FBFbxObject* pFbxObject);
624 
630  virtual bool FbxRetrieve(FBFbxObject* pFbxObject, FBRenderer* pRenderer);
631 
632  const char* ShaderDescription;
633 
635  void InvalidateShaderVersion ();
636 
638  int GetShaderVersion () const;
639 
641  FBShaderCapacity GetShaderCapacity( ) const;
642 
644  bool HasShaderCapacity (FBShaderCapacity pCapacity);
645 
649  void SetShaderCapacity (FBShaderCapacity pCapacity, bool pOn);
650 
652  int GetDrawInstancedMaximumSize() const;
653 
655  void SetDrawInstancedMaximumSize(int pMaxSize);
656 
661  virtual void UploadModelViewMatrixArrayForDrawInstanced(const double* pModelViewMatrixArray, int pCount);
662 
663 
664  public:
668 
674  FBPropertyRenderingPass RenderingPass;
675 
676  protected:
683  static FBRenderingPass GetRenderingPassNeededForAlpha(FBAlphaSource pTransparency);
684  };
685 
687  // FBPropertyListShader - List of shaders
691  {
692  public:
698  FBShader* operator[](int pIndex);
699  };
700 
702  // FBShaderLighted
705  FB_DEFINE_COMPONENT( FBSDK_DLL, ShaderLighted );
706 
774  {
775  //--- Open Reality declaration.
777 
778  public:
783  FBShaderLighted( const char* pName, HIObject pObject=NULL );
784 
787 
790 
793 
794  FBPropertyAlphaSource Transparency;
796  };
797 
798 
800  // FBShaderShadowLive
803  FB_DEFINE_COMPONENT( FBSDK_DLL, ShaderShadowLive );
804 
809  {
816  };
817  FB_DEFINE_ENUM( FBSDK_DLL, ShadowType );
818 
822  {
826  };
827  FB_DEFINE_ENUM( FBSDK_DLL, ShadowFrameType );
828 
829 
879  {
880  //--- Open Reality declaration.
882 
883  public:
888  FBShaderShadowLive( const char* pName, HIObject pObject=NULL );
889 
890  FBPropertyShadowType ShadowType;
895  FBPropertyShadowFrameType ShadowFrameType;
896 
899 
900  };
901 
902 
903 #ifdef FBSDKUseNamespace
904 }
905 #endif
906 #endif /* _FB_SHADER_H_ */
Before anything.
Definition: fbshader.h:386
class K_DLLIMPORT FBPropertyBase< double, kFBPT_double > FBPropertyDouble
Property: double
Similar to the Projective Shadow, except that it uses a boolean algorithm to create a self-shadow...
Definition: fbshader.h:813
#define __FBClassDeclare(Name, Parent)
For internal use only.
Definition: fbcomponent.h:132
FBPropertyBool LocalShadow
Read Write Property: Creates an accurate projection of a shadow for each object.
Definition: fbshader.h:892
FBX file interface.
Definition: fbfbx.h:80
Writes to depth buffer.
Definition: fbshader.h:390
Open Reality renderer interface.
Definition: fbrenderer.h:445
Material class.
Definition: fbmaterial.h:87
#define FB_DEFINE_LIST(DllTag, Type)
Define a component list.
Definition: fbproperties.h:161
PropertyList: Concrete class for PropertyList of component
Definition: fbcomponent.h:549
FBPropertyBool Enable
Read Write Property: Is the shader Enabled
Definition: fbshader.h:667
FB_DEFINE_COMPONENT(K_DLLIMPORT, AnimationNode)
Animation node class.
Lighted shader class.
Definition: fbshader.h:773
Lighting off.
Definition: fbshader.h:387
Template class to contain an array of items.
Definition: fbarray.h:77
FBPropertyShadowFrameType ShadowFrameType
Read Write Property: Used to select the shadow calculation method.
Definition: fbshader.h:895
FBPropertyBool UseSpecular
Read Write Property: Activate the Specularity option.
Definition: fbshader.h:791
This shader is acting as a material effect, should sitting behind the material central network...
Definition: fbshader.h:420
Uses a texture projection to create a shadow.
Definition: fbshader.h:811
This shader will able to draw additional texture layer (for example, live shadow or reflection)...
Definition: fbshader.h:423
FBPropertyListObject Lights
List: List of light object which will produce shadows.
Definition: fbshader.h:897
Bases the shadow calculation on the shadow of the caster.
Definition: fbshader.h:824
Use this shadow type to create darkened shadow areas only on planar surfaces.
Definition: fbshader.h:810
Contains definitions for devices, boxes and models.
FBPropertyBool UseLuminosity
Read Write Property: Activate the Luminosity option.
Definition: fbshader.h:788
FBStringList ShaderTypeNamesLocalized
List of available shaders.
Definition: fbshader.h:291
#define FB_DEFINE_ENUM(DllTag, Type)
Define an enum and give it the ability to be a property.
Definition: fbproperties.h:148
Viewing options for rendering.
Definition: fbrenderer.h:175
Shader manager.
Definition: fbshader.h:221
FBModel * GetFBModel()
Get Model.
Definition: fbshader.h:310
Creates custom cameras and manages system cameras.
Definition: fbcamera.h:206
FBPropertyDouble ShadowZOffset
Read Write Property: Specifies the offset of the Live Shadow shader&#39;s plane from the original selecte...
Definition: fbshader.h:894
class K_DLLIMPORT FBPropertyBase< bool, kFBPT_bool > FBPropertyBool
Property: bool
FB_FORWARD(FBViewingOptions)
FBRenderOptions.
const char * ShaderDescription
Description.
Definition: fbshader.h:632
Uses a texture projection as a shadow.
Definition: fbshader.h:812
FBPropertyDouble Contrast
Read Write Property: Changes the contrast of the object when it reflects light.
Definition: fbshader.h:786
Models are blended.
Definition: fbshader.h:392
FBStringList ShaderTypeNames
List of available shaders.
Definition: fbshader.h:268
FBShaderPassActionCallback
Shader Pass Action Callback.
Definition: fbshader.h:430
Bases the shadow calculation on the shadow of the receiver.
Definition: fbshader.h:823
Translucent(Models Z Sort).
Definition: fbshader.h:411
FBPropertyDouble Specular
Read Write Property: Changes an object&#39;s level of shininess when it reflects light by affecting the s...
Definition: fbshader.h:792
FBPropertyBool UseContrast
Read Write Property: Activate the Contrast option.
Definition: fbshader.h:785
FBPropertyAnimatableDouble Alpha
Read Write Property: Controls the actual effect of the shader on the object. At 0.0 it does nothing, and at 1.0 it fully affects the object.
Definition: fbshader.h:795
FBAlphaSource
Shader transparency computation.
Definition: fbshader.h:403
Lighting on.
Definition: fbshader.h:388
KShaderModelInfo * GetShaderModelInfo() const
Get Internal ShaderModelInfo object.
Definition: fbshader.h:318
Writes to depth buffer where Alpha > 0.5.
Definition: fbshader.h:391
FBPropertyListObject Models
List: List of object which when lighted will cast a shadow.
Definition: fbshader.h:898
FBShadowFrameType
Shadow calculation methods.
Definition: fbshader.h:821
Undocumented or unsupported.
Definition: fbshader.h:825
#define __FB_FORWARD(ClassName)
Forwarding of class and typedef declaration.
Definition: fbtypes.h:68
PropertyList: Shader
Definition: fbshader.h:690
Models are blended additively.
Definition: fbshader.h:393
List of scene objects.
Definition: fbcomponent.h:569
FBShadowType
Shadow types.
Definition: fbshader.h:808
String list.
Definition: fbstring.h:201
#define FBSDKNamespace
FBSDKNamespace define.
Definition: fbversion.h:64
This shader can support GL_ARB_draw_instanced extension, and thus could benefit from Geometry instanc...
Definition: fbshader.h:421
Basic class definitions.
2D Transparency.
Definition: fbshader.h:409
#define FBSDK_DLL
Be sure that FBSDK_DLL is defined only once...
Definition: fbshader.h:50
Model class.
Definition: fbmodel.h:273
This shader will able to draw different shape thus generate different shadow than original solid geom...
Definition: fbshader.h:422
FBRenderingPass
Rendering Pass.
Definition: fbshader.h:384
A box is a fundamental building block in the application architecture.
Definition: fbcore.h:218
FBPropertyAlphaSource Transparency
Read Write Property: Indicates the computation method of the transparency.
Definition: fbshader.h:794
Additive Transparency.
Definition: fbshader.h:410
class K_DLLIMPORT FBPropertyBaseAnimatable< double, kFBPT_double > FBPropertyAnimatableDouble
FBPropertyBaseAnimatableDouble type definition.
FBPropertyAnimatableDouble ShadowIntensity
Read Write Property: Controls the darkness of shadows cast by a selected object.
Definition: fbshader.h:891
After everything.
Definition: fbshader.h:395
Similar to the Planar Shadow, except that it treats all objects as opaque.
Definition: fbshader.h:815
Models are sorted and blended.
Definition: fbshader.h:394
Shader Shadow Live class.
Definition: fbshader.h:878
#define FBClassDeclare(Name, Parent)
Class declaration.
Definition: fbdefines.h:85
Accurate Transparency.
Definition: fbshader.h:406
FBPropertyRenderingPass RenderingPass
Read Write Property: Rendering pass object are shaded in.
Definition: fbshader.h:674
Alpha > 0.5 will show up.
Definition: fbshader.h:389
No transparency.
Definition: fbshader.h:405
FBPropertyShadowType ShadowType
Read Write Property: Indicate which shadow type is desired.
Definition: fbshader.h:890
No pass selected.
Definition: fbshader.h:385
FBShaderCapacity
Shader Capacity.
Definition: fbshader.h:417
Shader class.
Definition: fbshader.h:452
Similar to the Projective Light Map except that it uses a boolean algorithm to create a self-shadow...
Definition: fbshader.h:814
FBPropertyBool UseGobo
Read Write Property: Includes the gobo in the shadow map calculation.
Definition: fbshader.h:893
FBPropertyDouble Luminosity
Read Write Property: Changes the brightness of the object when reflecting light.
Definition: fbshader.h:789