1 /********************************************************************** 2 *< 3 FILE: normalrender.h 4 5 DESCRIPTION: Includes for Plugins 6 7 CREATED BY: Ben Lipman 8 9 HISTORY: 10 11 *> Copyright (c) 2003, All Rights Reserved. 12 **********************************************************************/ 13 14 #ifndef __NORMALRENDER__H 15 #define __NORMALRENDER__H 16 17 #include "Max.h" 18 #include "resource.h" 19 #include "istdplug.h" 20 #include "iparamb2.h" 21 #include "iparamm2.h" 22 23 #include "stdmat.h" 24 #include "imtl.h" 25 #include "macrorec.h" 26 #include "plugapi.h" 27 28 #define ALIGN_DWORD __declspec(align(4)) 29 30 #define CATALYST 31 32 #ifdef CATALYST 33 #include <IMtlRender_Compatibility.h> 34 #include <mentalray\mentalrayInMax.h> 35 #include <mentalray\imrShader.h> 36 #include <mentalray\imrShaderTranslation.h> 37 #endif 38 39 extern TCHAR *GetString(int id); 40 41 extern HINSTANCE hInstance; 42 43 #define SCANLINERENDERER_CLASS_ID Class_ID(SREND_CLASS_ID,0) 44 45 46 47 //=========================================================================== 48 // 49 // Class Gnormal 50 // 51 //=========================================================================== 52 53 #define GNORMAL_CLASS_ID Class_ID(0x243e22c6, 0x63f6a014) 54 #define NSUBTEX 2 55 #define PBLOCK_REF 0 56 57 #define MTL_HDR_CHUNK 0x4000 58 #define PARAM2_CHUNK 0x2030 59 60 // Values for Gnormal::method 61 #define TANGENTUV_SPACE 0 62 #define TANGENTLOCAL_SPACE 4 63 #define SCREEN_SPACE 2 64 #define WORLDXYZ_SPACE 3 65 #define LOCALXYZ_SPACE 1 66 67 68 class Gnormal : public Texmap 69 #ifdef CATALYST 70 , private imrShaderTranslation 71 #endif 72 { 73 public: 74 Gnormal(); 75 ~Gnormal(); 76 77 //-- UI and Param Block 78 enum { gnormal_params }; 79 enum { 80 gn_mult_spin, gn_bmult_spin, 81 gn_map_normal, gn_map_bump, 82 gn_map1on, gn_map2on, 83 gn_method, 84 gn_flip_red, gn_flip_green, gn_swap_rg, 85 }; 86 87 void Reset(); 88 void Init(); 89 void InvalidateUI(); 90 91 inline void Reorder(AColor &s); 92 inline void Reorder(Point3& p); 93 94 95 //-- From Animatable DeleteThis()96 void DeleteThis() { delete this; } 97 #ifdef LOCALIZED_APL // For some reason multibyte data is invalid here -- LOCALIZATION_TODO GetClassName(TSTR & s)98 void GetClassName(TSTR& s) { s = _T("Normal Bump"); } 99 #else GetClassName(TSTR & s)100 void GetClassName(TSTR& s) { s = GetString(IDS_CLASS_NAME); } 101 #endif // LOCALIZED_APL ClassID()102 Class_ID ClassID() { return GNORMAL_CLASS_ID;} SuperClassID()103 SClass_ID SuperClassID() { return TEXMAP_CLASS_ID; } 104 NumSubs()105 int NumSubs() { return 1+NSUBTEX; } 106 Animatable* SubAnim(int i); 107 TSTR SubAnimName(int i); SubNumToRefNum(int subNum)108 int SubNumToRefNum(int subNum) { return subNum; } 109 110 int RenderBegin(TimeValue t, ULONG flags=0); 111 int RenderEnd(TimeValue t); 112 NumParamBlocks()113 int NumParamBlocks() { return 1; } // return number of ParamBlocks in this instance GetParamBlock(int i)114 IParamBlock2* GetParamBlock(int i) { return pblock; } // return i'th ParamBlock GetParamBlockByID(BlockID id)115 IParamBlock2* GetParamBlockByID(BlockID id) { return (pblock->ID() == id) ? pblock : NULL; } // return id'd ParamBlock 116 117 //-- From ReferenceMaker 118 IOResult Load(ILoad *iload); 119 IOResult Save(ISave *isave); 120 NumRefs()121 int NumRefs() { return 1+NSUBTEX; } 122 RefTargetHandle GetReference(int i); 123 void SetReference(int i, RefTargetHandle rtarg); 124 125 RefResult NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget, 126 PartID& partID, RefMessage message); 127 128 //-- From ReferenceTarget 129 RefTargetHandle Clone( RemapDir &remap ); 130 131 //-- From ISubMap NumSubTexmaps()132 int NumSubTexmaps() { return NSUBTEX; } GetSubTexmap(int i)133 Texmap* GetSubTexmap(int i) { return subTex[i]; } 134 void SetSubTexmap(int i, Texmap *m); 135 TSTR GetSubTexmapSlotName(int i); 136 137 //-- From MtlBase 138 ULONG LocalRequirements(int subMtlNum); 139 void LocalMappingsRequired(int subMtlNum, BitArray & mapreq, BitArray &bumpreq); 140 141 void Update(TimeValue t, Interval& valid); Validity(TimeValue t)142 Interval Validity(TimeValue t) {Interval v; Update(t,v); return ivalid;} 143 ParamDlg* CreateParamDlg(HWND hwMtlEdit, IMtlParams *imp); 144 SupportTexDisplay()145 BOOL SupportTexDisplay() { return FALSE; } 146 DWORD_PTR GetActiveTexHandle(TimeValue t, TexHandleMaker& thmaker); 147 void ActivateTexDisplay(BOOL onoff); 148 149 //-- From Texmap 150 AColor EvalColor(ShadeContext& sc); 151 float EvalMono(ShadeContext& sc); 152 Point3 EvalNormalPerturb(ShadeContext& sc); 153 154 //-- Mental Ray support 155 #ifdef CATALYST 156 private: 157 // -- from InterfaceServer 158 BaseInterface* GetInterface(Interface_ID id); 159 // -- from imrShaderTranslation 160 imrShader* GetMRShader(imrShaderCreation& shaderCreation); 161 void ReleaseMRShader(); 162 bool NeedsAutomaticParamBlock2Translation(); 163 void TranslateParameters(imrTranslation& translationInterface, imrShader* shader, TimeValue t, Interval& valid); 164 void GetAdditionalReferenceDependencies(AdditionalDependencyTable& refTargets); 165 virtual bool HasRequirement(Requirement, TimeValue t, Interval& valid, void* arg); 166 #endif 167 168 protected: 169 //user 170 float gnMult, gnBMult; 171 BOOL flip_red, flip_green, swap_rg; 172 BOOL map1on, map2on; 173 174 // Parameter block 175 IParamBlock2 *pblock; //ref 0 176 Texmap *subTex[NSUBTEX]; //array of sub-materials 177 Interval ivalid; 178 int method; 179 }; 180 181 182 //=========================================================================== 183 // 184 // Class ReaderWriterLock 185 // 186 //=========================================================================== 187 188 class ReaderWriterLock { 189 public: ReaderWriterLock()190 ReaderWriterLock() {bits=0;} 191 void EnterRead(); 192 void ExitRead(); 193 void EnterWrite(); 194 void ExitWrite(); 195 protected: 196 // Lower bits [30..0] is the reader count, upper bit [31] is the writer 197 ALIGN_DWORD DWORD bits; 198 }; 199 200 #endif // __NORMALRENDER__H 201