sfx.h

Go to the documentation of this file.
00001 /* -----------------------------------------------------------------------------
00002 // -----------------------------------------------------------------------------
00003 
00004    FILE: sfx.h
00005 
00006      DESCRIPTION: class declarations for the special effect class hierarchy
00007 
00008      CREATED BY: michael malone (mjm)
00009 
00010      HISTORY: created June 30, 2000
00011 
00012      Copyright (c) 2000, All Rights Reserved
00013 
00014 // -----------------------------------------------------------------------------
00015 // -------------------------------------------------------------------------- */
00016 #pragma once
00017 
00018 #include "iFnPub.h"
00019 #include "plugapi.h"
00020 #include "GetCOREInterface.h"
00021 #include "ref.h"
00022 
00023 // forward declarations
00024 class Bitmap;
00025 class IRendParams;
00026 class ShadeContext;
00027 class RenderGlobalContext;
00028 class IReshadeFragment;
00029 
00030 #pragma warning(push)
00031 #pragma warning(disable:4100)
00032 
00033 
00034 // ------------------------------
00035 //
00036 // check abort callback class
00037 //
00038 // used to check for abort during
00039 // an extended operation
00040 // and to update progress
00041 //
00042 // ------------------------------
00043 
00044 #define CAC_INTERFACE Interface_ID(0x666534, 0x50101) 
00045 
00053 class CheckAbortCallback : public FPMixinInterface
00054 {
00055 public:
00057     virtual BOOL Check()=0;  // returns TRUE if user has done something to cause an abort.
00068     virtual BOOL Progress(int done, int total)=0;
00071     virtual void SetTitle(const MCHAR *title)=0;
00072 
00073     // FPInterface stuff
00074     enum { cac_check, cac_progress, cac_setTitle, };
00075 
00076     BEGIN_FUNCTION_MAP  
00077       FN_0(cac_check, TYPE_BOOL, Check); 
00078       FN_2(cac_progress, TYPE_BOOL, Progress, TYPE_INT, TYPE_INT); 
00079       VFN_1(cac_setTitle, SetTitle, TYPE_STRING); 
00080     END_FUNCTION_MAP 
00081 
00082     FPInterfaceDesc* GetDesc() { return (FPInterfaceDesc*)GetCOREInterface(CAC_INTERFACE); }
00083 };
00084 
00085 // -------------------------------------------------------------
00086 //
00087 // special effect plug-in base class
00088 //
00089 // base class for Atmospherics, Effects, RenderElements, Shaders
00090 //
00091 // -------------------------------------------------------------
00092 
00099 class SFXParamDlg : public InterfaceServer
00100 {
00101 public:
00103     virtual Class_ID ClassID()=0;
00110     virtual void SetThing(ReferenceTarget *m)=0;
00113     virtual ReferenceTarget* GetThing()=0;
00122     virtual void SetTime(TimeValue t) { }       
00124     virtual void DeleteThis()=0;        
00142     virtual INT_PTR Execute(int cmd, ULONG_PTR arg1=0, ULONG_PTR arg2=0, ULONG_PTR arg3=0) { return 0; } 
00143     virtual void InvalidateUI() { } 
00144 };
00145 
00146 
00155 class SpecialFX: public ReferenceTarget
00156 {
00157 public:
00158     MSTR name;
00159     // This name will appear in the track view and the list of current atmospheric effects.
00163     virtual MSTR GetName() { return _M(""); }       
00164 
00165     // Is effect active 
00172     virtual BOOL Active(TimeValue t) { return !TestAFlag(A_ATMOS_DISABLED); }
00173 
00174     // Called when the render steps to a new frame
00185     virtual void Update(TimeValue t, Interval& valid) { }
00186 
00187     // Saves and loads name. These should be called at the start of
00188     // a plug-in's save and load methods.
00193     CoreExport IOResult Save(ISave *isave);
00198     CoreExport IOResult Load(ILoad *iload);
00199 
00200     // Put up a dialog that lets the user edit the plug-ins parameters.
00210     virtual SFXParamDlg *CreateParamDialog(IRendParams *ip) { return NULL; }
00211     // Implement this if you are using the ParamMap2 AUTO_UI system and the 
00212     // effect has secondary dialogs that don't have the effect as their 'thing'.
00213     // Called once for each secondary dialog for you to install the correct thing.
00214     // Return TRUE if you process the dialog, false otherwise.
00229     virtual BOOL SetDlgThing(SFXParamDlg* dlg) { return FALSE; }
00230 
00231     // If an atmospheric has references to gizmos or other objects in the scene it can optionally 
00232     // provide access to the object list.
00238     virtual int NumGizmos() { return 0; }
00245     virtual INode *GetGizmo(int i) { return NULL; }
00252     virtual void DeleteGizmo(int i) { }
00260     virtual void AppendGizmo(INode *node) { }
00268     virtual BOOL OKGizmo(INode *node) { return FALSE; } // approve a node for possible use as gizmo
00282     virtual void EditGizmo(INode *node) { } // selects this gizmo & displays params for it if any
00293     virtual void InsertGizmo(int i, INode *node) { assert(0); } // must be defined to use DeleteGizmoRestore
00294 
00295     // Animatable overides...
00296     CoreExport SvGraphNodeReference SvTraverseAnimGraph(IGraphObjectManager *gom, Animatable *owner, int id, DWORD flags);
00297 };
00298 
00299 #define SFXBASE_CHUNK   0x39bf
00300 #define SFXNAME_CHUNK   0x0100
00301 
00302 
00303 // Classes used for implementing UNDO in Atmosphere and Effects classes.
00321 class AppendGizmoRestore : public RestoreObj
00322 {
00323 public:
00324     SpecialFX *fx;
00325     INode *node;
00328     AppendGizmoRestore(SpecialFX *f, INode *n) { fx= f; node = n; }
00329     void Redo() { fx->AppendGizmo(node); }
00330     void Restore(int isUndo) { fx->DeleteGizmo(fx->NumGizmos()-1); } 
00331     MSTR Description() { return MSTR("AppendGizmoRestore"); }
00332 };
00333 
00353 class DeleteGizmoRestore: public RestoreObj
00354 {
00355 public:
00356     SpecialFX *fx;
00357     INode *node;
00358     int num;
00361     DeleteGizmoRestore(SpecialFX *a, INode *n, int i) { fx = a; node = n; num = i;  }
00362     void Redo() { fx->DeleteGizmo(num); }
00363     void Restore(int isUndo) { fx->InsertGizmo(num,node); } 
00364     MSTR Description() { return MSTR("DeleteGizmoRestore"); }
00365 };
00366 
00367 // ------------------------------
00368 // atmospheric plug-in base class
00369 // ------------------------------
00370 
00371 // Returned by an Atmospheric when it is asked to put up its rollup page.
00372 typedef SFXParamDlg AtmosParamDlg;
00373 
00384 class Atmospheric : public SpecialFX
00385 {
00386 public:
00387     RefResult NotifyRefChanged(Interval changeInt,
00388                                RefTargetHandle hTarget,
00389                                PartID& partID,
00390                                RefMessage message) { return REF_SUCCEED; }
00391     SClass_ID SuperClassID() { return ATMOSPHERIC_CLASS_ID; }
00392     
00393     // Saves and loads name. These should be called at the start of
00394     // a plug-in's save and load methods.
00399     IOResult Save(ISave *isave) { return SpecialFX::Save(isave); }
00404     IOResult Load(ILoad *iload) { return SpecialFX::Load(iload); }
00405 
00406     // Put up a modal dialog that lets the user edit the plug-ins parameters.
00418     virtual AtmosParamDlg *CreateParamDialog(IRendParams *ip) { return NULL; }
00419     // Implement this if you are using the ParamMap2 AUTO_UI system and the 
00420     // atmosphere has secondary dialogs that don't have the effect as their 'thing'.
00421     // Called once for each secondary dialog for you to install the correct thing.
00422     // Return TRUE if you process the dialog, false otherwise.
00439     virtual BOOL SetDlgThing(AtmosParamDlg* dlg) { return FALSE; }
00440 
00441     // This is the function that is called to apply the effect.
00486     virtual void Shade(ShadeContext& sc,const Point3& p0,const Point3& p1,Color& color, Color& trans, BOOL isBG=FALSE)=0;
00487 // begin - ke/mjm - 03.16.00 - merge reshading code
00488 //  virtual void PreShade(ShadeContext& sc,const Point3& p0,const Point3& p1,Color& color, Color& trans, IReshadeFragment* pFrag, BOOL isBG=FALSE) { }
00489 //  virtual void ReShade(ShadeContext& sc,const Point3& p0,const Point3& p1,Color& color, Color& trans, IReshadeFragment* pFrag, BOOL isBG=FALSE) { Shade(sc,p0,p1,color,trans,isBG); }
00490 // end - ke/mjm - 03.16.00 - merge reshading code
00491 };
00492 
00493 // Chunk IDs saved by base class
00494 #define ATMOSHPERICBASE_CHUNK   SFXBASE_CHUNK
00495 #define ATMOSHPERICNAME_CHUNK   SFXNAME_CHUNK
00496 
00497 
00498 // --------------------------------
00499 // render effect plug-in base class
00500 // --------------------------------
00501 
00502 // Returned by an  effect when it is asked to put up its rollup page.
00503 typedef SFXParamDlg EffectParamDlg;
00504 
00524 class Effect : public SpecialFX
00525 {
00526 public:
00527     RefResult NotifyRefChanged(Interval changeInt,
00528                                RefTargetHandle hTarget,
00529                                PartID& partID,
00530                                RefMessage message) {return REF_SUCCEED;}
00531     SClass_ID SuperClassID() { return RENDER_EFFECT_CLASS_ID; }
00532 
00533     // Saves and loads name. These should be called at the start of
00534     // a plug-in's save and load methods.
00542     IOResult Save(ISave *isave) { return SpecialFX::Save(isave); }
00550     IOResult Load(ILoad *iload) { return SpecialFX::Load(iload); }
00551 
00552     // Put up a dialog that lets the user edit the plug-ins parameters.
00564     virtual EffectParamDlg *CreateParamDialog(IRendParams *ip) { return NULL; }
00565     // Implement this if you are using the ParamMap2 AUTO_UI system and the 
00566     // effect has secondary dialogs that don't have the effect as their 'thing'.
00567     // Called once for each secondary dialog for you to install the correct thing.
00568     // Return TRUE if you process the dialog, false otherwise.
00585     virtual BOOL SetDlgThing(EffectParamDlg* dlg) { return FALSE; }
00586 
00587     // What G-buffer channels does this Effect require in the output bitmap?
00596     virtual DWORD GBufferChannelsRequired(TimeValue t) { return 0; }
00597 
00598     // This is the function that is called to apply the effect.
00612     virtual void Apply(TimeValue t, Bitmap* bm, RenderGlobalContext* gc, CheckAbortCallback* cb )=0;
00613 
00614 };
00615 
00616 
00617 //==============================================================================
00618 // Class Effect8
00619 //
00630 class Effect8 : public Effect, public BaseInterface {
00631 public:
00632 
00635     CoreExport static const Interface_ID m_kEffect8_Interface_ID;
00636 
00641     CoreExport static Effect8* GetEffect8(Effect& effect);
00642 
00651     CoreExport static bool SupportsBitmap(Effect& effect, Bitmap& bitmap);
00652 
00669     virtual bool SupportsBitmap(Bitmap& bitmap) = 0;
00670 
00671     // -- from InterfaceServer
00673     CoreExport virtual BaseInterface* GetInterface(Interface_ID id);
00674 
00675     // -- from Animatable
00677     CoreExport virtual void* GetInterface(ULONG id);
00678 };
00679 
00680 // Chunk IDs saved by base class
00681 #define EFFECTBASE_CHUNK    SFXBASE_CHUNK
00682 #define EFFECTNAME_CHUNK    SFXNAME_CHUNK
00683 
00684 
00685 // --------------------------------
00686 // filter kernel plug-in base class
00687 // --------------------------------
00688 
00689 #define AREA_KERNEL_CLASS_ID            0x77912301
00690 #define DEFAULT_KERNEL_CLASS_ID         AREA_KERNEL_CLASS_ID
00691 
00692 // Returned by a kernel when it is asked to put up its rollup page.
00693 typedef SFXParamDlg FilterKernelParamDlg;
00694 
00732 class FilterKernel : public SpecialFX
00733 {
00734 public:
00735     RefResult NotifyRefChanged(Interval changeInt, 
00736                                RefTargetHandle hTarget, 
00737                                PartID& partID, 
00738                                RefMessage message ) { return REF_SUCCEED; }
00739 
00740     SClass_ID SuperClassID() { return FILTER_KERNEL_CLASS_ID; }
00741     
00742     // Saves and loads name. These should be called at the start of
00743     // a plug-in's save and load methods.
00746     IOResult Save(ISave *isave) { return SpecialFX::Save(isave); }
00749     IOResult Load(ILoad *iload) { return SpecialFX::Load(iload); }
00750 
00751     // Put up a dialog that lets the user edit the plug-ins parameters.
00752     virtual FilterKernelParamDlg *CreateParamDialog( IRendParams *ip ) { return NULL; }
00753 
00754     // filter kernel section
00755     // This is the function that is called to sample kernel values.
00764     virtual double KernelFn( double x, double y = 0.0 )=0;
00765 
00766     // integer number of pixels from center to filter 0 edge, must not truncate filter
00767     // x dimension for 2D filters
00775     virtual long GetKernelSupport()=0;
00776     // for 2d returns y support, for 1d returns 0
00779     virtual long GetKernelSupportY()=0;
00780 
00789     virtual bool Is2DKernel()=0;
00796     virtual bool IsVariableSz()=0;
00797     // 1-D filters ignore the y parameter
00805     virtual void SetKernelSz( double x, double y = 0.0 )=0;
00813     virtual void GetKernelSz( double& x, double& y )=0;
00814 
00815     // returning true will disable the built-in normalizer
00829     virtual bool IsNormalized(){ return FALSE; }
00830 
00831     // this is for possible future optimizations, not sure its needed
00835     virtual bool HasNegativeLobes()=0;
00836 
00839     virtual MCHAR* GetDefaultComment()=0;
00840 
00841     // there are 2 optional 0.0 ...1.0 parameters, for whatever
00849     virtual long GetNFilterParams(){ return 0; }
00855     virtual MCHAR * GetFilterParamName( long nParam ){ return _M(""); }
00856     virtual double GetFilterParamMax( long nParam ){ return 1.0; }
00861     virtual double GetFilterParam( long nParam ){ return 0.0; }
00868     virtual void SetFilterParam( long nParam, double val ){};
00869 };
00870 
00871 #pragma warning(pop)
00872 
00873 // Chunk IDs saved by base class
00874 #define FILTERKERNELBASE_CHUNK  0x39bf
00875 #define FILTERKERNELNAME_CHUNK  0x0100
00876 
00877