gamemtl.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* $Header: /Commando/Code/Tools/max2w3d/gamemtl.h 46 3/01/02 6:43p Moumine_ballo $ */
  19. /***********************************************************************************************
  20. *** Confidential - Westwood Studios ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Commando / G 3D engine *
  24. * *
  25. * File Name : GAMEMTL.H *
  26. * *
  27. * Programmer : Greg Hjelstrom *
  28. * *
  29. * Start Date : 06/26/97 *
  30. * *
  31. * Last Update : June 26, 1997 [GH] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #ifndef GAMEMTL_H
  37. #define GAMEMTL_H
  38. #include <Max.h>
  39. #include "w3dmtl.h"
  40. #include "w3d_file.h"
  41. // GameMtl flags values
  42. #define GAMEMTL_CONVERTED_TO_NOLOD (1<<0) // this material has been converted to use the NO_LOD flag on textures
  43. #define GAMEMTL_DISPLACEMENT_ROLLUP_OPEN (1<<25)
  44. #define GAMEMTL_SURFACE_ROLLUP_OPEN (1<<26)
  45. #define GAMEMTL_PASSCOUNT_ROLLUP_OPEN (1<<27)
  46. #define GAMEMTL_PASS0_ROLLUP_OPEN (1<<28)
  47. #define GAMEMTL_PASS1_ROLLUP_OPEN (1<<29)
  48. #define GAMEMTL_PASS2_ROLLUP_OPEN (1<<30)
  49. #define GAMEMTL_PASS3_ROLLUP_OPEN (1<<31)
  50. #define GAMEMTL_ROLLUP_FLAGS ( GAMEMTL_SURFACE_ROLLUP_OPEN | \
  51. GAMEMTL_DISPLACEMENT_ROLLUP_OPEN | \
  52. GAMEMTL_PASSCOUNT_ROLLUP_OPEN | \
  53. GAMEMTL_PASS0_ROLLUP_OPEN | \
  54. GAMEMTL_PASS1_ROLLUP_OPEN | \
  55. GAMEMTL_PASS2_ROLLUP_OPEN | \
  56. GAMEMTL_PASS3_ROLLUP_OPEN )
  57. #define GAMEMTL_ID_PARTA 0x29397211
  58. #define GAMEMTL_ID_PARTB 0x28c016c2
  59. ///////////////////////////////////////////////////////////////////////////
  60. //
  61. // Mapping types
  62. //
  63. ///////////////////////////////////////////////////////////////////////////
  64. #define GAMEMTL_MAPPING_UV 0
  65. #define GAMEMTL_MAPPING_ENV 1
  66. #define GAMEMTL_MAPPING_CHEAP_ENV 2
  67. #define GAMEMTL_MAPPING_SCREEN 3
  68. #define GAMEMTL_MAPPING_LINEAR_OFFSET 4
  69. #define GAMEMTL_MAPPING_SILHOUETTE 5
  70. #define GAMEMTL_MAPPING_SCALE 6
  71. #define GAMEMTL_MAPPING_GRID 7
  72. #define GAMEMTL_MAPPING_ROTATE 8
  73. #define GAMEMTL_MAPPING_SINE_LINEAR_OFFSET 9
  74. #define GAMEMTL_MAPPING_STEP_LINEAR_OFFSET 10
  75. #define GAMEMTL_MAPPING_ZIGZAG_LINEAR_OFFSET 11
  76. #define GAMEMTL_MAPPING_WS_CLASSIC_ENV 12
  77. #define GAMEMTL_MAPPING_WS_ENVIRONMENT 13
  78. #define GAMEMTL_MAPPING_GRID_CLASSIC_ENV 14
  79. #define GAMEMTL_MAPPING_GRID_ENVIRONMENT 15
  80. #define GAMEMTL_MAPPING_RANDOM 16
  81. #define GAMEMTL_MAPPING_EDGE 17
  82. #define GAMEMTL_MAPPING_BUMPENV 18
  83. ///////////////////////////////////////////////////////////////////////////
  84. //
  85. // PSX Translucency Type
  86. //
  87. ///////////////////////////////////////////////////////////////////////////
  88. #define GAMEMTL_PSX_TRANS_NONE 0
  89. #define GAMEMTL_PSX_TRANS_100 1
  90. #define GAMEMTL_PSX_TRANS_50 2
  91. #define GAMEMTL_PSX_TRANS_25 3
  92. #define GAMEMTL_PSX_TRANS_MINUS_100 4
  93. class GameMtlDlg;
  94. class GMaxMtlDlg;
  95. class GameMapsClass;
  96. extern Class_ID GameMaterialClassID;
  97. extern ClassDesc * Get_Game_Material_Desc();
  98. // MLL
  99. // For Playstation 2 materials.
  100. extern Class_ID PS2GameMaterialClassID;
  101. extern ClassDesc * Get_PS2_Game_Material_Desc();
  102. extern Class_ID PCToPS2MaterialClassID;
  103. extern ClassDesc * Get_PS2_Material_Conversion();
  104. ///////////////////////////////////////////////////////////////////////////
  105. //
  106. // Game Material
  107. // This is a plugin-material which attempts to emulate the material
  108. // used in our in-game 3D engine. It has varying degrees of success
  109. // at making Max render things like our game but it gives us the
  110. // ability to have control over all parameters in our material.
  111. //
  112. ///////////////////////////////////////////////////////////////////////////
  113. class GameMtl: public Mtl
  114. {
  115. public:
  116. enum ShaderTypeEnum
  117. {
  118. STE_PC_SHADER,
  119. STE_PS2_SHADER,
  120. };
  121. GameMtl(BOOL loading = FALSE);
  122. ~GameMtl(void);
  123. Class_ID ClassID();
  124. SClass_ID SuperClassID();
  125. // From Animatable
  126. void GetClassName(TSTR& s);
  127. void DeleteThis() { delete this; }
  128. int NumSubs();
  129. Animatable * SubAnim(int i);
  130. TSTR SubAnimName(int i);
  131. // References
  132. int NumRefs() { return REF_COUNT; }
  133. RefTargetHandle Clone(RemapDir &remap = NoRemap());
  134. RefResult NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget, PartID& partID, RefMessage message);
  135. void SetReference(int i, RefTargetHandle rtarg);
  136. RefTargetHandle GetReference(int i);
  137. // From MtlBase and Mtl
  138. void SetAmbient(Color c, TimeValue t) { Set_Ambient(0,t,c); }
  139. void SetDiffuse(Color c, TimeValue t) { Set_Diffuse(0,t,c); }
  140. void SetSpecular(Color c, TimeValue t) { Set_Specular(0,t,c); }
  141. void SetShininess(float v, TimeValue t) { Set_Shininess(0,t,v); }
  142. Color GetAmbient(int mtlNum=0, BOOL backFace=FALSE) { return Get_Ambient(0,0); }
  143. Color GetDiffuse(int mtlNum=0, BOOL backFace=FALSE) { return Get_Diffuse(0,0); }
  144. Color GetSpecular(int mtlNum=0, BOOL backFace=FALSE) { return Get_Specular(0,0); }
  145. float GetXParency(int mtlNum=0, BOOL backFace=FALSE) { return 0.0f; }
  146. float GetShininess(int mtlNum=0, BOOL backFace=FALSE) { return Get_Shininess(0,0); }
  147. float GetShinStr(int mtlNum=0, BOOL backFace=FALSE) { return 1.0f; }
  148. void Reset(void);
  149. void Update(TimeValue t, Interval& validr);
  150. Interval Validity(TimeValue t);
  151. int NumSubTexmaps(void);
  152. void SetSubTexmap(int i, Texmap * m);
  153. Texmap * GetSubTexmap(int i);
  154. float EvalDisplacement(ShadeContext& sc);
  155. Interval DisplacementValidity(TimeValue t);
  156. // Rendering
  157. void Shade(ShadeContext& sc);
  158. ULONG Requirements(int subMtlNum);
  159. //ULONG LocalRequirements(int subMtlNum);
  160. // Material editor
  161. #if defined W3D_GMAXDEV
  162. void SetParamDlg(GMaxMtlDlg * pd) { MaterialDialog = pd; }
  163. #else
  164. void SetParamDlg(GameMtlDlg * pd) { MaterialDialog = pd; }
  165. #endif
  166. ParamDlg* CreateParamDlg(HWND hwMtlEdit, IMtlParams *imp);
  167. // IO stuff
  168. IOResult Save(ISave* iSave);
  169. IOResult Load(ILoad* iLoad);
  170. // Accessors...
  171. void Set_Flag(ULONG f, ULONG val) { if (val) Flags|=f; else Flags &= ~f; }
  172. int Get_Flag(ULONG f) { return ((Flags&f) ? 1 : 0); }
  173. void Set_Surface_Type(unsigned int type) { SurfaceType = type; }
  174. unsigned int Get_Surface_Type(void) const { return SurfaceType; }
  175. void Set_Sort_Level(int level) { SortLevel = level; }
  176. int Get_Sort_Level(void) const { return SortLevel; }
  177. void Set_Pass_Count(int passcount);
  178. int Get_Pass_Count(void);
  179. IParamBlock * Get_Parameter_Block(int pass);
  180. int Get_Current_Page(int pass) { return CurPage[pass]; }
  181. Color Get_Ambient(int pass,TimeValue t);
  182. Color Get_Diffuse(int pass,TimeValue t);
  183. Color Get_Specular(int pass,TimeValue t);
  184. Color Get_Emissive(int pass,TimeValue t);
  185. float Get_Shininess(int pass,TimeValue t);
  186. float Get_Opacity(int pass,TimeValue t);
  187. float Get_Translucency(int pass,TimeValue t);
  188. int Get_Copy_Specular_To_Diffuse(int pass);
  189. int Get_Mapping_Type(int pass, int stage=0);
  190. int Get_PSX_Translucency(int pass);
  191. int Get_PSX_Lighting(int pass);
  192. int Get_Depth_Compare(int pass);
  193. int Get_Depth_Mask(int pass);
  194. int Get_Alpha_Test(int pass);
  195. int Get_Dest_Blend(int pass);
  196. int Get_Pri_Gradient(int pass);
  197. int Get_Sec_Gradient(int pass);
  198. int Get_Src_Blend(int pass);
  199. int Get_Detail_Color_Func(int pass);
  200. int Get_Detail_Alpha_Func(int pass);
  201. int Get_PS2_Shader_Param_A(int pass);
  202. int Get_PS2_Shader_Param_B(int pass);
  203. int Get_PS2_Shader_Param_C(int pass);
  204. int Get_PS2_Shader_Param_D(int pass);
  205. int Get_Texture_Enable(int pass,int stage);
  206. int Get_Texture_Publish(int pass,int stage);
  207. int Get_Texture_Resize(int pass,int stage); // NOTE: obsolete, replaced by Get_Texture_No_LOD
  208. int Get_Texture_No_Mipmap(int pass,int stage); // NOTE: obsolete, replaced by Get_Texture_No_LOD
  209. int Get_Texture_Clamp_U(int pass,int stage);
  210. int Get_Texture_Clamp_V(int pass,int stage);
  211. int Get_Texture_No_LOD(int pass,int stage);
  212. int Get_Texture_Alpha_Bitmap(int pass,int stage);
  213. int Get_Texture_Hint(int pass,int stage);
  214. int Get_Texture_Display(int pass,int stage);
  215. float Get_Texture_Frame_Rate(int pass,int stage);
  216. int Get_Texture_Frame_Count(int pass,int stage);
  217. int Get_Texture_Anim_Type(int pass,int stage);
  218. Texmap * Get_Texture(int pass,int stage);
  219. Texmap * Get_Displacement_Map(void) const { return DisplacementMap; }
  220. float Get_Displacement_Amount(void) const { return DisplacementAmt; }
  221. int Get_Displacement_Map_Index(void) const;
  222. int Get_Map_Channel(int pass,int stage);
  223. void Set_Current_Page(int pass,int page) { CurPage[pass] = page; }
  224. void Set_Ambient(int pass,TimeValue t,Color color);
  225. void Set_Diffuse(int pass,TimeValue t,Color color);
  226. void Set_Specular(int pass,TimeValue t,Color color);
  227. void Set_Emissive(int pass,TimeValue t,Color color);
  228. void Set_Shininess(int pass,TimeValue t,float val);
  229. void Set_Opacity(int pass,TimeValue t,float val);
  230. void Set_Translucency(int pass,TimeValue t,float val);
  231. void Set_Copy_Specular_To_Diffuse(int pass,bool val);
  232. void Set_Mapping_Type(int pass,int stage,int val);
  233. void Set_PSX_Translucency(int pass,int val);
  234. void Set_PSX_Lighting(int pass,bool val);
  235. void Set_Depth_Compare(int pass,int val);
  236. void Set_Depth_Mask(int pass,int val);
  237. void Set_Alpha_Test(int pass,int val);
  238. void Set_Dest_Blend(int pass,int val);
  239. void Set_Pri_Gradient(int pass,int val);
  240. void Set_Sec_Gradient(int pass,int val);
  241. void Set_Src_Blend(int pass,int val);
  242. void Set_Detail_Color_Func(int pass,int val);
  243. void Set_Detail_Alpha_Func(int pass,int val);
  244. void Set_PS2_Shader_Param_A(int pass,int val);
  245. void Set_PS2_Shader_Param_B(int pass,int val);
  246. void Set_PS2_Shader_Param_C(int pass,int val);
  247. void Set_PS2_Shader_Param_D(int pass,int val);
  248. void Set_Texture_Enable(int pass,int stage,bool val);
  249. void Set_Texture_Publish(int pass,int stage,bool val);
  250. void Set_Texture_Resize(int pass,int stage,bool val); // NOTE: obsolete: replaced by Set_Texture_No_LOD
  251. void Set_Texture_No_Mipmap(int pass,int stage,bool val); // NOTE: obsolete: replaced by Set_Texture_No_LOD
  252. void Set_Texture_Clamp_U(int pass,int stage,bool val);
  253. void Set_Texture_Clamp_V(int pass,int stage,bool val);
  254. void Set_Texture_No_LOD(int pass,int stage,bool val);
  255. void Set_Texture_Alpha_Bitmap(int pass,int stage,bool val);
  256. void Set_Texture_Hint(int pass,int stage,int val);
  257. void Set_Texture_Display(int pass,int stage,bool val);
  258. void Set_Texture_Frame_Rate(int pass,int stage,float val);
  259. void Set_Texture_Frame_Count(int pass,int stage,int val);
  260. void Set_Texture_Anim_Type(int pass,int stage,int val);
  261. void Set_Texture(int pass,int stage,Texmap * tex);
  262. void Set_Displacement_Amount(float amount) { DisplacementAmt = amount; Notify_Changed (); }
  263. void Set_Map_Channel(int pass,int stage,int channel);
  264. void Notify_Changed(void);
  265. // This returns the mapping args string buffer for that pass after
  266. // assuring that it is at least of length 'len'.
  267. char * Get_Mapping_Arg_Buffer(int pass, int stage=0, unsigned int len = 0U);
  268. int pass_stage_to_texmap_index(int pass,int stage);
  269. void texmap_index_to_pass_stage(int index,int * set_pass,int * set_stage);
  270. // Set and get the type of shader, PC or PS2.
  271. // MLL
  272. int Get_Shader_Type() {return (ShaderType);}
  273. void Set_Shader_Type(int shadertype) {ShaderType = shadertype;}
  274. // Approximate the PS2 shader on the PC.
  275. int Compute_PC_Shader_From_PS2_Shader(int pass);
  276. int Compute_PS2_Shader_From_PC_Shader(int pass);
  277. // IML: Get/set substitute material.
  278. Mtl* Substitute_Material() {return (SubstituteMaterial);}
  279. void Set_Substitute_Material (Mtl *m) {SubstituteMaterial = m;}
  280. #if defined W3D_MAX4
  281. //BOOL SupportsMultiMapsInViewport(){return TRUE;}
  282. //virtual int VPDisplaySubMtl(){return -1;}
  283. //MtlBase *MtlInSlotOne;
  284. #endif
  285. private:
  286. int texture_ref_index(int pass,int stage) { return REF_TEXTURE + pass*W3dMaterialClass::MAX_STAGES + stage; }
  287. int pass_ref_index(int pass) { return REF_PASS_PARAMETERS + pass; }
  288. void update_viewport_display();
  289. // Do the shade functions specific to the Playstation 2.
  290. void ps2_shade(ShadeContext& sc);
  291. unsigned int SurfaceType;
  292. int SortLevel;
  293. Interval Ivalid; // Valid interval
  294. #if defined W3D_GMAXDEV
  295. GMaxMtlDlg * MaterialDialog; // Dialog
  296. #else
  297. GameMtlDlg * MaterialDialog; // Dialog
  298. #endif
  299. ULONG Flags; // Flags
  300. int RollScroll; // Rollup scroll position
  301. int CurPage[W3dMaterialClass::MAX_PASSES]; // which page was last open for each pass
  302. GameMapsClass * Maps; // ref 0 (obsolete...)
  303. IParamBlock * MainParameterBlock;
  304. IParamBlock * PassParameterBlock[W3dMaterialClass::MAX_PASSES];
  305. Texmap * Texture[W3dMaterialClass::MAX_PASSES][W3dMaterialClass::MAX_STAGES];
  306. char * MapperArg[W3dMaterialClass::MAX_PASSES][W3dMaterialClass::MAX_STAGES];
  307. unsigned int MapperArgLen[W3dMaterialClass::MAX_PASSES][W3dMaterialClass::MAX_STAGES];
  308. Texmap * DisplacementMap;
  309. float DisplacementAmt;
  310. // MLL
  311. int ShaderType;
  312. enum
  313. {
  314. REF_MAPS = 0, // obsolete, gamemaps object
  315. REF_MAIN = 1, // main parameter block is ref 1
  316. REF_PASS_PARAMETERS = 2, // pass parameter blocks are refs 2,3,4,5
  317. REF_TEXTURE = 6, // textures are refs 6,7,8,9,10,11,12,13,14 (14 is the displacement map)
  318. REF_COUNT = 15,
  319. };
  320. Mtl *SubstituteMaterial; // IML: Temporary material used during game to standard material conversion and vice-versa.
  321. friend class GameMtlDlg;
  322. friend class GameMtlPostLoad;
  323. };
  324. #if defined W3D_GMAXDEV
  325. GameMtl* CreateNewGameMtl();
  326. const ActionTableId kGameMtlActions = 0x7ea7bca5;
  327. const ActionContextId kGameMtlContext = 0x7ea7bca5;
  328. #define NumElements(array) (sizeof(array) / sizeof(array[0]))
  329. class GameMtlActionCB : public ActionCallback {
  330. public:
  331. GameMtl* game_mtl;
  332. GameMtlActionCB(GameMtl *var_mtl) { game_mtl = var_mtl; }
  333. ~GameMtlActionCB(){delete game_mtl;}
  334. BOOL GameMtlActionCB::IsEnabled(int cmdID) { return TRUE;}
  335. BOOL ExecuteAction(int id);
  336. };
  337. #endif
  338. Mtl * CreateGameMtl();
  339. #endif