shaders.h

Go to the documentation of this file.
00001 //
00002 // Copyright 2010 Autodesk, Inc.  All rights reserved.
00003 //
00004 // Use of this software is subject to the terms of the Autodesk license
00005 // agreement provided at the time of installation or download, or which
00006 // otherwise accompanies this software in either electronic or hard copy form.  
00007 //
00008 //
00009 
00010 #pragma once
00011 
00012 #include "iparamb2.h"
00013 #include "stdmat.h"
00014 #include "buildver.h"
00015 
00016 #define     N_ID_CHANNELS   16      //!< Number of IDs in stdMat
00017 class Shader;
00018 #define OPACITY_PARAM   0
00019 #define DEFAULT_SOFTEN  0.1f
00020 
00025 class ShaderParamDlg : public ParamDlg {
00026     public:
00028         virtual Class_ID ClassID()=0;
00029         
00034         virtual void SetThing(ReferenceTarget *m)=0;
00035 
00041         virtual void SetThings( StdMat2* pMtl, Shader* pShader )=0;
00042         
00048         virtual ReferenceTarget* GetThing()=0;
00049 
00051         virtual Shader* GetShader()=0;
00052         
00058         virtual void SetTime(TimeValue t) { UNUSED_PARAM(t); }  
00059         
00067         virtual void DeleteThis()=0;        
00068         
00082         virtual INT_PTR PanelProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam )=0; 
00083         
00087         virtual void LoadDialog( int draw )=0;
00088         virtual void UpdateDialog( ParamID paramId )=0;
00089 
00091         virtual HWND GetHWnd()=0;
00092 
00099         virtual int  FindSubTexFromHWND(HWND hw)=0;
00100         
00102         virtual void UpdateOpacity()=0;
00103         
00108         virtual void UpdateMapButtons()=0;
00109 };
00110  
00111 // Can be or'd w/ mtl, not sure it's necessary
00112 #define SELFILLUM_CLR_ON    (1<<16) 
00113 
00120 #define HAS_BUMPS               0x01L       //!< Indicates that the bump mapping is present.
00121 #define HAS_REFLECT             0x02L       //!< Indicates that there is any kind of reflection (raytraced, etc).
00122 #define HAS_REFRACT             0x04L       //!< Indicates that there is any kind of refraction.
00123 #define HAS_OPACITY             0x08L       //!< Indicates that opacity mapping is used.
00124 
00128 #define HAS_REFLECT_MAP         0x10L
00129 #define HAS_REFRACT_MAP         0x20L       //!< Indicates that there is a refraction map only.
00130 #define HAS_MATTE_MTL           0x40L
00131 
00132 
00133 
00144 #define UNSUPPORTED_CHANNEL     0x01L       //!< Indicates that the channel is not supported (is not used).
00145 #define CLR_CHANNEL             0x02L       //!< A color channel. The Color.r, Color.g and Color.b parameters are used.
00146 #define MONO_CHANNEL            0x04L       //!< A monochrome channel. Only the Color.r is used.
00147 #define BUMP_CHANNEL            0x08L       //!< The bump mapping channel.
00148 #define REFL_CHANNEL            0x10L       //!< The reflection channel.
00149 #define REFR_CHANNEL            0x20L       //!< The refraction channel.
00150 #define DISP_CHANNEL            0x40L       //!< The displacement channel.
00151 #define SLEV_CHANNEL            0x80L       
00152 
00158 #define ELIMINATE_CHANNEL       0x8000L
00159 
00160 #define SKIP_CHANNELS   (UNSUPPORTED_CHANNEL+BUMP_CHANNEL+REFL_CHANNEL+REFR_CHANNEL) 
00161 
00162 
00163 
00164 #define  DEFAULT_SHADER_CLASS_ID BLINNClassID //!< Class Id upper half for loading the Pre 3.0 shaders
00165 
00166 #ifndef USE_LIMITED_STDMTL // orb 01-14-2002
00167 #define  PHONGClassID (STDSHADERS_CLASS_ID+2)
00168 #define  METALClassID (STDSHADERS_CLASS_ID+4)
00169 #endif // USE_LIMITED_STDMTL
00170 
00171 
00172 #define  BLINNClassID (STDSHADERS_CLASS_ID+3)               //!< For Blinn Shader
00173 static Class_ID BlinnClassID(STDSHADERS_CLASS_ID + 3,0);    
00174 
00175 #define ANISOSHADER_CLASS_ID 0x2857f460                         //!< For Anisotropic Shader
00176 static Class_ID AnisoShaderClassID( ANISOSHADER_CLASS_ID, 0);   
00177 static Class_ID AnisoShaderDlgClassID( ANISOSHADER_CLASS_ID, 0);
00178 
00180 enum Shader_Anisotropic_Shader_BlockID
00181 {
00182     aniso_params
00183 };
00184 
00186 enum Shader_Anisotropic_Shader_ParamIDs
00187 { 
00188     an_ambient, an_diffuse, an_specular, an_self_illum_color,
00189     an_diffuse_level, an_specular_level, an_self_illum_amnt, 
00190     an_glossiness, an_anisotropy, an_orientation, 
00191     an_map_channel, an_ad_texlock, an_ad_lock, an_ds_lock, an_use_self_illum_color, 
00192 };
00193 
00194 
00195 #define NEWSHADERS_CLASS_ID      0x2857f420                                 //!< For Oren/Nayar/Blinn Shader
00196 static Class_ID OrenNayarBlinnShaderClassID( NEWSHADERS_CLASS_ID + 1, 0);   
00197 static Class_ID OrenNayarShaderDlgClassID( NEWSHADERS_CLASS_ID + 2, 0);     
00198 
00200 enum Shader_Oren_Nayar_Blinn_BlockID
00201 {
00202     onb_params
00203 };
00205 enum Shader_Oren_Nayar_Blinn_ParamIDs
00206 { 
00207     onb_ambient, onb_diffuse, onb_specular,
00208     onb_self_illum_color, onb_self_illum_amnt,
00209     onb_glossiness, onb_specular_level, onb_soften,
00210     onb_diffuse_level, onb_roughness, 
00211     onb_ad_texlock, onb_ad_lock, onb_ds_lock, onb_use_self_illum_color, 
00212 };
00213 
00214 
00215 
00216 #define STRAUSS_SHADER_CLASS_ID     0x2857f450                      //!< For Strauss Shader
00217 static Class_ID StraussShaderClassID( STRAUSS_SHADER_CLASS_ID, 0);  
00218 
00220 enum Shader_Strauss_BlockID
00221 {
00222     strauss_params
00223 };
00224 
00226 enum Shader_Strauss_ParamIDs
00227 { 
00228     st_diffuse, st_glossiness, st_metalness, 
00229 };
00230 
00231 class ParamBlockDescID;
00232 class IParamBlock;
00233 
00266 class BaseShader : public SpecialFX {
00267     public:
00268         #pragma warning(push)
00269         #pragma warning(disable:4100)
00270         RefResult NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget, 
00271              PartID& partID,  RefMessage message) {return REF_SUCCEED;}
00272 
00273         SClass_ID SuperClassID() {return SHADER_CLASS_ID;}
00274 
00276         BOOL BypassPropertyLevel() { return TRUE; }  
00277 
00287         virtual ULONG GetRequirements(int subMtlNum)=0;
00288 
00302         virtual ShaderParamDlg* CreateParamDialog(
00303             HWND hOldRollup, 
00304             HWND hwMtlEdit, 
00305             IMtlParams *imp, 
00306             StdMat2* theMtl, 
00307             int rollupOpen, 
00308             int n=0) = 0;
00309 
00311         virtual int NParamDlgs(){ return 1; }
00312 
00318         virtual ShaderParamDlg* GetParamDlg(int n=0 )=0;
00319         
00326         virtual void SetParamDlg( ShaderParamDlg* newDlg, int n=0 )=0;
00327 
00332         IOResult Save(ISave *isave) { return SpecialFX::Save(isave); }
00333         
00337         IOResult Load(ILoad *iload) { return SpecialFX::Load(iload); }
00338 
00344         virtual ULONG SupportStdParams()=0;
00345 
00352         virtual void ConvertParamBlk( ParamBlockDescID *descOld, int oldCount, IParamBlock *oldPB ){};
00353 
00362         virtual void GetIllumParams( ShadeContext &sc, IllumParams& ip )=0;
00363 
00607         virtual void Illum(ShadeContext &sc, IllumParams &ip)=0;
00608 
00609 // begin - ke/mjm - 03.16.00 - merge reshading code
00610         // these support the pre-shade/reshade protocol
00611 //      virtual void PreIllum(ShadeContext &sc, IReshadeFragment* pFrag){}
00612 //      virtual void PostIllum(ShadeContext &sc, IllumParams &ip, IReshadeFragment* pFrag ){ Illum(sc,ip); }
00613 
00614         // >>>> new for V4, one call superceded, 2 new ones added
00625         virtual void ShadeReflection(ShadeContext &sc, IllumParams &ip, Color &mapClr){}
00626         
00637         virtual void ShadeTransmission(ShadeContext &sc, IllumParams &ip, Color &mapClr, float amount){}
00638             
00671         virtual void AffectReflection(ShadeContext &sc, IllumParams &ip, Color &rcol){}
00672 
00685         virtual void CombineComponents( ShadeContext &sc, IllumParams& ip ){};
00686         #pragma warning(pop)
00687         
00690         virtual long nTexChannelsSupported()=0;
00691         
00695         virtual MSTR GetTexChannelName( long nTextureChan )=0;
00696         
00702         virtual MSTR GetTexChannelInternalName( long nTextureChan ) { return GetTexChannelName(nTextureChan); }
00703         
00716         virtual long ChannelType( long nTextureChan )=0;
00717         
00741         virtual long StdIDToChannel( long stdID )=0;
00742 
00744         virtual long nUserIllumOut(){ return 0; } 
00745 
00747         virtual MCHAR** UserIllumNameArray(){ return NULL; } 
00748 
00753         virtual void Reset()=0; 
00754 
00755     };
00756 
00758 
00759 #define SHADERBASE_CHUNK    0x39bf
00760 #define SHADERNAME_CHUNK    0x0100
00761 
00762 
00768 #define STD_PARAM_NONE          (0)             //!< Indicates that none of the flags in the Standard_Parameters is used
00769 #define STD_PARAM_ALL           (0xffffffffL)   //!< Indicates that all of the flags in the Standard_Parameters are used
00770 #define STD_PARAM_METAL         (1)             //!< Only used by the Metal shader
00771 #define STD_PARAM_LOCKDS        (1<<1)          //!< Indicates support for the Diffuse/Specular lock.
00772 #define STD_PARAM_LOCKAD        (1<<2)          //!< Indicates support for the Ambient/Diffuse lock.
00773 #define STD_PARAM_LOCKADTEX     (1<<3)          //!< Indicates support for the Ambient/Diffuse texture lock.
00774 #define STD_PARAM_SELFILLUM     (1<<4)          //!< Indicates support for the Self Illumination parameter.
00775 #define STD_PARAM_SELFILLUM_CLR (1<<5)          //!< Indicates support for the Self Illumination color parameter.
00776 #define STD_PARAM_AMBIENT_CLR   (1<<6)          //!< Indicates support for the Ambient color parameter.
00777 #define STD_PARAM_DIFFUSE_CLR   (1<<7)          //!< Indicates support for the Diffuse color parameter.
00778 #define STD_PARAM_SPECULAR_CLR  (1<<8)          //!< Indicates support for the Specular color parameter.
00779 #define STD_PARAM_FILTER_CLR    (1<<9)          //!< Indicates support for the Filter color parameter.
00780 #define STD_PARAM_GLOSSINESS    (1<<10)         //!< Indicates support for the Glossiness parameter.
00781 #define STD_PARAM_SOFTEN_LEV    (1<<11)         //!< Indicates support for the Soften Level parameter.
00782 #define STD_PARAM_SPECULAR_LEV  (1<<12)         //!< Indicates support for the Specular Level parameter.
00783 #define STD_PARAM_DIFFUSE_LEV   (1<<13)         //!< Indicates support for the Diffuse Level parameter.
00784 #define STD_PARAM_DIFFUSE_RHO   (1<<14)         //!< Indicates support for the Roughness parameter.
00785 #define STD_PARAM_ANISO         (1<<15)         //!< Indicates support for the Specular Highlight Anisotropy parameter.
00786 #define STD_PARAM_ORIENTATION   (1<<16)         //!< Indicates support for the Specular Highlight Orientation parameter.
00787 #define STD_PARAM_REFL_LEV      (1<<17)         //!< This is reserved for future use.
00788 #define STD_PARAM_SELFILLUM_CLR_ON      (1<<18) //!< Indicates support for the Self Illumination Color On/Off checkbox.
00789 
00793 #define STD_BASIC2_DLG          (1<<20)          
00794 
00798 #define STD_EXTRA_DLG           (1<<21)         
00799 
00802 #define STD_EXTRA_REFLECTION    (1<<22)         
00803 
00806 #define STD_EXTRA_REFRACTION    (1<<23)         
00807 
00811 #define STD_EXTRA_OPACITY       (1<<24)         
00812 
00813 
00814 
00815 
00816 #define STD_EXTRA   (STD_EXTRA_DLG \
00817                     +STD_EXTRA_REFLECTION+STD_EXTRA_REFRACTION \
00818                     +STD_EXTRA_OPACITY )
00819 
00820 #define STD_BASIC   (0x00021ffeL | STD_BASIC2_DLG)
00821 
00822 #ifndef USE_LIMITED_STDMTL // orb 01-14-2002
00823 #define STD_BASIC_METAL (0x00021fffL | STD_BASIC2_DLG)
00824 #define STD_ANISO   (0x0002cffe)
00825 #define STD_MULTILAYER  (0x0002fffe)
00826 #define STD_ONB     (0x00023ffe)
00827 #define STD_WARD    (0x00000bce)
00828 #endif // USE_LIMITED_STDMTL
00829 
00830 
00831 
00850 class Shader : public BaseShader, public IReshading
00851 {
00852     public:
00853     #pragma warning(push)
00854     #pragma warning(disable:4100)
00855 
00861     virtual void CopyStdParams( Shader* pFrom )=0;
00862     
00863     // these are the standard shader params
00864 
00868     virtual void SetLockDS(BOOL lock)=0;
00869     
00872     virtual BOOL GetLockDS()=0;
00873 
00877     virtual void SetLockAD(BOOL lock)=0;
00878 
00881     virtual BOOL GetLockAD()=0;
00882     
00886     virtual void SetLockADTex(BOOL lock)=0;
00887 
00890     virtual BOOL GetLockADTex()=0;
00891 
00897     virtual void SetSelfIllum(float v, TimeValue t)=0;      
00898 
00902     virtual void SetSelfIllumClrOn( BOOL on )=0;
00903 
00908     virtual void SetSelfIllumClr(Color c, TimeValue t)=0;       
00909 
00914     virtual void SetAmbientClr(Color c, TimeValue t)=0;     
00915 
00920     virtual void SetDiffuseClr(Color c, TimeValue t)=0;     
00921 
00925     virtual void SetSpecularClr(Color c, TimeValue t)=0;
00926 
00931     virtual void SetGlossiness(float v, TimeValue t)=0;     
00932 
00937     virtual void SetSpecularLevel(float v, TimeValue t)=0;      
00938 
00943     virtual void SetSoftenLevel(float v, TimeValue t)=0;
00944         
00950     virtual BOOL IsSelfIllumClrOn(int mtlNum, BOOL backFace)=0;
00951 
00955     virtual Color GetAmbientClr(int mtlNum, BOOL backFace)=0;       
00956     
00960     virtual Color GetDiffuseClr(int mtlNum, BOOL backFace)=0;       
00961 
00965     virtual Color GetSpecularClr(int mtlNum, BOOL backFace)=0;
00966     
00970     virtual Color GetSelfIllumClr(int mtlNum, BOOL backFace)=0;
00971     
00975     virtual float GetSelfIllum(int mtlNum, BOOL backFace)=0;
00976     
00980     virtual float GetGlossiness(int mtlNum, BOOL backFace)=0;   
00981     
00985     virtual float GetSpecularLevel(int mtlNum, BOOL backFace)=0;
00986     
00990     virtual float GetSoftenLevel(int mtlNum, BOOL backFace)=0;
00991 
00995     virtual BOOL IsSelfIllumClrOn()=0;
00996     
00999     virtual Color GetAmbientClr(TimeValue t)=0;     
01000     
01003     virtual Color GetDiffuseClr(TimeValue t)=0;     
01004     
01007     virtual Color GetSpecularClr(TimeValue t)=0;
01008     
01012     virtual float GetGlossiness( TimeValue t)=0;        
01015     virtual float GetSpecularLevel(TimeValue t)=0;
01016     
01020     virtual float GetSoftenLevel(TimeValue t)=0;
01021     
01024     virtual float GetSelfIllum(TimeValue t)=0;      
01025     
01028     virtual Color GetSelfIllumClr(TimeValue t)=0;       
01029 
01038     virtual float EvalHiliteCurve(float x){ return 0.0f; }
01039 
01048     virtual float EvalHiliteCurve2(float x, float y, int level = 0 ){ return 0.0f; }
01049 
01051     CoreExport void ShadeReflection(ShadeContext &sc, IllumParams &ip, Color &mapClr);
01053     CoreExport void ShadeTransmission(ShadeContext &sc, IllumParams &ip, Color &mapClr, float amount);
01054 
01055     // Reshading
01056     void PreShade(ShadeContext& sc, IReshadeFragment* pFrag){}
01057     void PostShade(ShadeContext& sc, IReshadeFragment* pFrag, int& nextTexIndex, IllumParams* ip){ Illum( sc, *ip ); }
01058     #pragma warning(pop)
01059     // [dl | 13march2003] Adding this inlined definition to resolve compile errors
01060     BaseInterface* GetInterface(Interface_ID id) { return BaseShader::GetInterface(id); }
01061     void* GetInterface(ULONG id){
01062         if( id == IID_IReshading )
01063             return (IReshading*)( this );
01064     //  else if ( id == IID_IValidityToken )
01065     //      return (IValidityToken*)( this );
01066         else
01067             return BaseShader::GetInterface(id);
01068     }
01069 };
01070 
01071 
01072