GameMtlShaderDlg.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. /*
  2. ** Command & Conquer Generals(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. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Max2W3d *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/max2w3d/GameMtlShaderDlg.cpp $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 2/26/99 7:23p $*
  29. * *
  30. * $Revision:: 13 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * GameMtlShaderDlg::GameMtlShaderDlg -- constructor *
  35. * GameMtlShaderDlg::~GameMtlShaderDlg -- destructor *
  36. * GameMtlShaderDlg::Dialog_Proc -- windows message handler *
  37. * GameMtlShaderDlg::ReloadDialog -- reload the contents of all of the controls *
  38. * GameMtlShaderDlg::ActivateDlg -- activate/deactivate the dialog *
  39. * GameMtlShaderDlg::Apply_Preset -- apply a preset shader setting *
  40. * GameMtlShaderDlg::Set_Preset -- determine preset shader setting from game material *
  41. * GameMtlShaderDlg::CompareShaderToBlendPreset -- compare preset to game material shader *
  42. * GameMtlShaderDlg::Set_Advanced_Defaults -- set advanced settings to defaults *
  43. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  44. #include "GameMtlShaderDlg.h"
  45. #include "GameMtlDlg.h"
  46. #include "GameMtl.h"
  47. #include "resource.h"
  48. /*
  49. ** Shader Blend Setting Presets
  50. */
  51. // Note: the array has NUM_SHADER_BLEND_PRESETS + 1 entries (due to the 'Custom' entry).
  52. #define NUM_SHADER_BLEND_PRESETS 8
  53. static char * _ShaderBlendSettingPresetNames[NUM_SHADER_BLEND_PRESETS + 1] =
  54. {
  55. "Opaque",
  56. "Add",
  57. "Multiply",
  58. "Multiply and Add",
  59. "Screen",
  60. "Alpha Blend",
  61. "Alpha Test",
  62. "Alpha Test and Blend",
  63. "------ Custom -----"
  64. };
  65. struct ShaderBlendSettingPreset
  66. {
  67. int SrcBlend;
  68. int DestBlend;
  69. bool DepthMask;
  70. bool AlphaTest;
  71. };
  72. static const ShaderBlendSettingPreset ShaderBlendSettingPresets[NUM_SHADER_BLEND_PRESETS] = {
  73. {W3DSHADER_SRCBLENDFUNC_ONE, W3DSHADER_DESTBLENDFUNC_ZERO, true, false}, // Opaque
  74. {W3DSHADER_SRCBLENDFUNC_ONE, W3DSHADER_DESTBLENDFUNC_ONE, false, false}, // Add
  75. {W3DSHADER_SRCBLENDFUNC_ZERO, W3DSHADER_DESTBLENDFUNC_SRC_COLOR, false, false}, // Multiply
  76. {W3DSHADER_SRCBLENDFUNC_ONE, W3DSHADER_DESTBLENDFUNC_SRC_COLOR, false, false}, // Multiply and Add
  77. {W3DSHADER_SRCBLENDFUNC_ONE, W3DSHADER_DESTBLENDFUNC_ONE_MINUS_SRC_COLOR, false, false}, // Screen
  78. {W3DSHADER_SRCBLENDFUNC_SRC_ALPHA, W3DSHADER_DESTBLENDFUNC_ONE_MINUS_SRC_ALPHA, false, false}, // Alpha Blend
  79. {W3DSHADER_SRCBLENDFUNC_ONE, W3DSHADER_DESTBLENDFUNC_ZERO, true, true}, // Alpha Test
  80. {W3DSHADER_SRCBLENDFUNC_SRC_ALPHA, W3DSHADER_DESTBLENDFUNC_ONE_MINUS_SRC_ALPHA, true, true} // Alpha Test and Blend
  81. };
  82. /***********************************************************************************************
  83. * GameMtlShaderDlg::GameMtlShaderDlg -- constructor *
  84. * *
  85. * INPUT: *
  86. * *
  87. * OUTPUT: *
  88. * *
  89. * WARNINGS: *
  90. * *
  91. * HISTORY: *
  92. * 11/23/98 GTH : Created. *
  93. *=============================================================================================*/
  94. GameMtlShaderDlg::GameMtlShaderDlg
  95. (
  96. HWND parent,
  97. IMtlParams * imp,
  98. GameMtl * mtl,
  99. int pass
  100. ) :
  101. GameMtlFormClass(imp,mtl,pass)
  102. {
  103. Create_Form(parent,IDD_GAMEMTL_SHADER);
  104. }
  105. /***********************************************************************************************
  106. * GameMtlShaderDlg::~GameMtlShaderDlg -- destructor *
  107. * *
  108. * INPUT: *
  109. * *
  110. * OUTPUT: *
  111. * *
  112. * WARNINGS: *
  113. * *
  114. * HISTORY: *
  115. *=============================================================================================*/
  116. GameMtlShaderDlg::~GameMtlShaderDlg()
  117. {
  118. }
  119. /***********************************************************************************************
  120. * GameMtlShaderDlg::Dialog_Proc -- windows message handler *
  121. * *
  122. * INPUT: *
  123. * *
  124. * OUTPUT: *
  125. * *
  126. * WARNINGS: *
  127. * *
  128. * HISTORY: *
  129. * 11/23/98 GTH : Created. *
  130. *=============================================================================================*/
  131. BOOL GameMtlShaderDlg::Dialog_Proc (HWND dlg_wnd, UINT message, WPARAM wparam, LPARAM lparam)
  132. {
  133. int cursel;
  134. int i;
  135. int id = LOWORD(wparam);
  136. int code = HIWORD(wparam);
  137. switch (message)
  138. {
  139. case WM_INITDIALOG:
  140. for(i = 0; i <= NUM_SHADER_BLEND_PRESETS; i++) {
  141. SendDlgItemMessage(dlg_wnd,IDC_PRESET_COMBO,CB_ADDSTRING,0,(LONG)_ShaderBlendSettingPresetNames[i]);
  142. }
  143. SendDlgItemMessage(dlg_wnd,IDC_PRESET_COMBO,CB_SETCURSEL,0,0);
  144. break;
  145. case WM_LBUTTONDOWN:
  146. case WM_LBUTTONUP:
  147. case WM_MOUSEMOVE:
  148. {
  149. IParams->RollupMouseMessage(dlg_wnd,message,wparam,lparam);
  150. }
  151. return FALSE;
  152. case WM_COMMAND:
  153. {
  154. if (code == CBN_SELCHANGE) {
  155. switch (id)
  156. {
  157. case IDC_DEPTHCOMPARE_COMBO:
  158. cursel = SendDlgItemMessage(dlg_wnd,IDC_DEPTHCOMPARE_COMBO,CB_GETCURSEL,0,0);
  159. TheMtl->Set_Depth_Compare(PassIndex,cursel);
  160. break;
  161. case IDC_DESTBLEND_COMBO:
  162. cursel = SendDlgItemMessage(dlg_wnd,IDC_DESTBLEND_COMBO,CB_GETCURSEL,0,0);
  163. TheMtl->Set_Dest_Blend(PassIndex,cursel);
  164. TheMtl->Notify_Changed();
  165. Set_Preset();
  166. break;
  167. case IDC_PRIGRADIENT_COMBO:
  168. cursel = SendDlgItemMessage(dlg_wnd,IDC_PRIGRADIENT_COMBO,CB_GETCURSEL,0,0);
  169. TheMtl->Set_Pri_Gradient(PassIndex,cursel);
  170. TheMtl->Notify_Changed();
  171. break;
  172. case IDC_SECGRADIENT_COMBO:
  173. cursel = SendDlgItemMessage(dlg_wnd,IDC_SECGRADIENT_COMBO,CB_GETCURSEL,0,0);
  174. TheMtl->Set_Sec_Gradient(PassIndex,cursel);
  175. TheMtl->Notify_Changed();
  176. break;
  177. case IDC_SRCBLEND_COMBO:
  178. cursel = SendDlgItemMessage(dlg_wnd,IDC_SRCBLEND_COMBO,CB_GETCURSEL,0,0);
  179. TheMtl->Set_Src_Blend(PassIndex,cursel);
  180. TheMtl->Notify_Changed();
  181. Set_Preset();
  182. break;
  183. case IDC_DETAILCOLOR_COMBO:
  184. cursel = SendDlgItemMessage(dlg_wnd,IDC_DETAILCOLOR_COMBO,CB_GETCURSEL,0,0);
  185. TheMtl->Set_Detail_Color_Func(PassIndex,cursel);
  186. TheMtl->Notify_Changed();
  187. break;
  188. case IDC_DETAILALPHA_COMBO:
  189. cursel = SendDlgItemMessage(dlg_wnd,IDC_DETAILALPHA_COMBO,CB_GETCURSEL,0,0);
  190. TheMtl->Set_Detail_Alpha_Func(PassIndex,cursel);
  191. TheMtl->Notify_Changed();
  192. break;
  193. case IDC_PRESET_COMBO:
  194. cursel = SendDlgItemMessage(dlg_wnd,IDC_PRESET_COMBO,CB_GETCURSEL,0,0);
  195. Apply_Preset(cursel);
  196. break;
  197. }
  198. } else {
  199. switch(id) {
  200. case IDC_DEPTHMASK_CHECK:
  201. if (SendDlgItemMessage(dlg_wnd,IDC_DEPTHMASK_CHECK,BM_GETCHECK,0,0)) {
  202. TheMtl->Set_Depth_Mask(PassIndex,W3DSHADER_DEPTHMASK_WRITE_ENABLE);
  203. } else {
  204. TheMtl->Set_Depth_Mask(PassIndex,W3DSHADER_DEPTHMASK_WRITE_DISABLE);
  205. }
  206. Set_Preset();
  207. break;
  208. case IDC_ALPHATEST_CHECK:
  209. if (SendDlgItemMessage(dlg_wnd,IDC_ALPHATEST_CHECK,BM_GETCHECK,0,0)) {
  210. TheMtl->Set_Alpha_Test(PassIndex,W3DSHADER_ALPHATEST_ENABLE);
  211. } else {
  212. TheMtl->Set_Alpha_Test(PassIndex,W3DSHADER_ALPHATEST_DISABLE);
  213. }
  214. Set_Preset();
  215. break;
  216. case IDC_SHADER_DEFAULTS_BUTTON:
  217. Set_Advanced_Defaults();
  218. break;
  219. }
  220. }
  221. }
  222. }
  223. return FALSE;
  224. }
  225. /***********************************************************************************************
  226. * GameMtlShaderDlg::ReloadDialog -- reload the contents of all of the controls *
  227. * *
  228. * INPUT: *
  229. * *
  230. * OUTPUT: *
  231. * *
  232. * WARNINGS: *
  233. * *
  234. * HISTORY: *
  235. * 11/23/98 GTH : Created. *
  236. *=============================================================================================*/
  237. void GameMtlShaderDlg::ReloadDialog(void)
  238. {
  239. DebugPrint("GameMtlShaderDlg::ReloadDialog\n");
  240. SendDlgItemMessage(m_hWnd, IDC_DESTBLEND_COMBO, CB_SETCURSEL, TheMtl->Get_Dest_Blend(PassIndex), 0 );
  241. SendDlgItemMessage(m_hWnd, IDC_SRCBLEND_COMBO, CB_SETCURSEL, TheMtl->Get_Src_Blend(PassIndex), 0 );
  242. SendDlgItemMessage(m_hWnd, IDC_PRIGRADIENT_COMBO, CB_SETCURSEL, TheMtl->Get_Pri_Gradient(PassIndex), 0 );
  243. SendDlgItemMessage(m_hWnd, IDC_SECGRADIENT_COMBO, CB_SETCURSEL, TheMtl->Get_Sec_Gradient(PassIndex), 0 );
  244. SendDlgItemMessage(m_hWnd, IDC_DEPTHCOMPARE_COMBO, CB_SETCURSEL, TheMtl->Get_Depth_Compare(PassIndex), 0 );
  245. SendDlgItemMessage(m_hWnd, IDC_DETAILCOLOR_COMBO, CB_SETCURSEL, TheMtl->Get_Detail_Color_Func(PassIndex), 0 );
  246. SendDlgItemMessage(m_hWnd, IDC_DETAILALPHA_COMBO, CB_SETCURSEL, TheMtl->Get_Detail_Alpha_Func(PassIndex), 0 );
  247. Set_Preset();
  248. SetCheckBox(m_hWnd,IDC_DEPTHMASK_CHECK, TheMtl->Get_Depth_Mask(PassIndex));
  249. SetCheckBox(m_hWnd,IDC_ALPHATEST_CHECK, TheMtl->Get_Alpha_Test(PassIndex));
  250. }
  251. /***********************************************************************************************
  252. * GameMtlShaderDlg::ActivateDlg -- activate/deactivate the dialog *
  253. * *
  254. * INPUT: *
  255. * *
  256. * OUTPUT: *
  257. * *
  258. * WARNINGS: *
  259. * *
  260. * HISTORY: *
  261. * 11/23/98 GTH : Created. *
  262. *=============================================================================================*/
  263. void GameMtlShaderDlg::ActivateDlg(BOOL onoff)
  264. {
  265. // shader has no color swatches which need to be activated...
  266. }
  267. /***********************************************************************************************
  268. * GameMtlShaderDlg::Apply_Preset -- apply a preset shader setting *
  269. * *
  270. * INPUT: *
  271. * *
  272. * OUTPUT: *
  273. * *
  274. * WARNINGS: *
  275. * *
  276. * HISTORY: *
  277. * 11/23/98 GTH : Created. *
  278. *=============================================================================================*/
  279. void GameMtlShaderDlg::Apply_Preset(int preset_index)
  280. {
  281. if (preset_index < 0 || preset_index >= NUM_SHADER_BLEND_PRESETS) return;
  282. const ShaderBlendSettingPreset &preset = ShaderBlendSettingPresets[preset_index];
  283. TheMtl->Set_Src_Blend(PassIndex, preset.SrcBlend);
  284. TheMtl->Set_Dest_Blend(PassIndex, preset.DestBlend);
  285. int depth_mask = preset.DepthMask ? W3DSHADER_DEPTHMASK_WRITE_ENABLE : W3DSHADER_DEPTHMASK_WRITE_DISABLE;
  286. TheMtl->Set_Depth_Mask(PassIndex, depth_mask);
  287. int alpha_test = preset.AlphaTest ? W3DSHADER_ALPHATEST_ENABLE : W3DSHADER_ALPHATEST_DISABLE;
  288. TheMtl->Set_Alpha_Test(PassIndex, alpha_test);
  289. TheMtl->Notify_Changed();
  290. ReloadDialog();
  291. }
  292. /***********************************************************************************************
  293. * GameMtlShaderDlg::Set_Preset -- determine preset shader setting from game material *
  294. * *
  295. * INPUT: *
  296. * *
  297. * OUTPUT: *
  298. * *
  299. * WARNINGS: *
  300. * *
  301. * HISTORY: *
  302. * 02/26/99 NH : Created. *
  303. *=============================================================================================*/
  304. void GameMtlShaderDlg::Set_Preset(void)
  305. {
  306. for (int i = 0; i < NUM_SHADER_BLEND_PRESETS; i++) {
  307. if (CompareShaderToBlendPreset(ShaderBlendSettingPresets[i])) break;
  308. }
  309. SendDlgItemMessage(m_hWnd, IDC_PRESET_COMBO, CB_SETCURSEL, i, 0);
  310. }
  311. /***********************************************************************************************
  312. * GameMtlShaderDlg::CompareShaderToBlendPreset -- compare preset to game material shader *
  313. * *
  314. * INPUT: *
  315. * *
  316. * OUTPUT: *
  317. * *
  318. * WARNINGS: *
  319. * *
  320. * HISTORY: *
  321. * 02/26/99 NH : Created. *
  322. *=============================================================================================*/
  323. bool GameMtlShaderDlg::CompareShaderToBlendPreset(const ShaderBlendSettingPreset &blend_preset)
  324. {
  325. if (TheMtl->Get_Src_Blend(PassIndex) != blend_preset.SrcBlend) return false;
  326. if (TheMtl->Get_Dest_Blend(PassIndex) != blend_preset.DestBlend) return false;
  327. bool depthmask = TheMtl->Get_Depth_Mask(PassIndex) != W3DSHADER_DEPTHMASK_WRITE_DISABLE;
  328. if (depthmask != blend_preset.DepthMask) return false;
  329. bool alphatest = TheMtl->Get_Alpha_Test(PassIndex) != W3DSHADER_ALPHATEST_DISABLE;
  330. if (alphatest != blend_preset.AlphaTest) return false;
  331. return true;
  332. }
  333. /***********************************************************************************************
  334. * GameMtlShaderDlg::Set_Advanced_Defaults -- set advanced settings to defaults *
  335. * *
  336. * INPUT: *
  337. * *
  338. * OUTPUT: *
  339. * *
  340. * WARNINGS: *
  341. * *
  342. * HISTORY: *
  343. * 02/26/99 NH : Created. *
  344. *=============================================================================================*/
  345. void GameMtlShaderDlg::Set_Advanced_Defaults(void)
  346. {
  347. TheMtl->Set_Pri_Gradient(PassIndex, W3DSHADER_PRIGRADIENT_DEFAULT);
  348. TheMtl->Set_Sec_Gradient(PassIndex, W3DSHADER_SECGRADIENT_DEFAULT);
  349. TheMtl->Set_Depth_Compare(PassIndex, W3DSHADER_DEPTHCOMPARE_DEFAULT);
  350. TheMtl->Set_Detail_Color_Func(PassIndex, W3DSHADER_DETAILCOLORFUNC_DEFAULT);
  351. TheMtl->Set_Detail_Alpha_Func(PassIndex, W3DSHADER_DETAILALPHAFUNC_DEFAULT);
  352. TheMtl->Notify_Changed();
  353. ReloadDialog();
  354. }