PS2GameMtlShaderDlg.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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 : Buccaneer Bay *
  23. * *
  24. * File name : PS2GameMtlShaderDlg.cpp *
  25. * *
  26. * Programmer : Mike Lytle *
  27. * *
  28. * Start date : 10/12/1999 *
  29. * *
  30. * Last update : 10/12/1999 *
  31. * *
  32. * Taken from GTH's GameMtlShaderDlg.cpp *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * PS2GameMtlShaderDlg -- Constructor. *
  36. * PGMSD::Dialog_Proc -- Respond to user selections. *
  37. * PGMSD::ReloadDialog -- Setup the dialog box. *
  38. * PGMSD::Apply_Preset -- Notify the material of the values for the selected setting. *
  39. * PGMSD::Set_Preset -- Sets the dialog to one of the presets or custom. *
  40. * PGMSD::CompareShaderToBlendPreset -- Determine if the settings conform to one of the prese*
  41. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  42. #include "PS2GameMtlShaderDlg.h"
  43. #include "GameMtlDlg.h"
  44. #include "GameMtl.h"
  45. #include "resource.h"
  46. #define NUM_PS2_SHADER_BLEND_PRESETS 7
  47. static char * _PS2ShaderBlendSettingPresetNames[NUM_PS2_SHADER_BLEND_PRESETS + 1] =
  48. {
  49. "Opaque",
  50. "Additive",
  51. "Source Subtracted",
  52. "Destination Subtracted",
  53. "Alpha Blend",
  54. "Alpha Test",
  55. "Alpha Test and Blend",
  56. "------ Custom -----"
  57. };
  58. struct PS2ShaderBlendSettingPreset
  59. {
  60. int A;
  61. int B;
  62. int C;
  63. int D;
  64. bool DepthMask;
  65. bool AlphaTest;
  66. };
  67. // (A - B) * C + D
  68. static const PS2ShaderBlendSettingPreset PS2ShaderBlendSettingPresets[NUM_PS2_SHADER_BLEND_PRESETS] = {
  69. {PSS_SRC, PSS_ZERO, PSS_ONE, PSS_ZERO, true, false}, // Opaque
  70. {PSS_SRC, PSS_ZERO, PSS_ONE, PSS_DEST, false, false}, // Additive
  71. {PSS_DEST, PSS_SRC, PSS_ONE, PSS_ZERO, false, false}, // Src subtracted
  72. {PSS_SRC, PSS_DEST, PSS_ONE, PSS_ZERO, false, false}, // Dest subtracted
  73. {PSS_SRC, PSS_DEST, PSS_SRC_ALPHA, PSS_DEST, false, false}, // Alpha blend
  74. {PSS_SRC, PSS_ZERO, PSS_ONE, PSS_ZERO, true, true}, // Alpha test
  75. {PSS_SRC, PSS_DEST, PSS_SRC_ALPHA, PSS_DEST, true, true}, // Alpha test & blend
  76. };
  77. /***********************************************************************************************
  78. * PS2GameMtlShaderDlg -- Constructor. *
  79. * *
  80. * *
  81. * *
  82. * *
  83. * HISTORY: *
  84. * 10/12/1999MLL: Created. *
  85. *=============================================================================================*/
  86. PS2GameMtlShaderDlg::PS2GameMtlShaderDlg
  87. (
  88. HWND parent,
  89. IMtlParams * imp,
  90. GameMtl * mtl,
  91. int pass
  92. ) : GameMtlFormClass(imp,mtl,pass)
  93. {
  94. Create_Form(parent, IDD_GAMEMTL_PS2_SHADER);
  95. }
  96. /***********************************************************************************************
  97. * PGMSD::Dialog_Proc -- Respond to user selections. *
  98. * *
  99. * *
  100. * *
  101. * *
  102. * HISTORY: *
  103. * 10/12/1999MLL: Created. *
  104. *=============================================================================================*/
  105. BOOL PS2GameMtlShaderDlg::Dialog_Proc (HWND dlg_wnd, UINT message, WPARAM wparam, LPARAM lparam)
  106. {
  107. int cursel;
  108. int i;
  109. int id = LOWORD(wparam);
  110. int code = HIWORD(wparam);
  111. switch (message)
  112. {
  113. case WM_INITDIALOG:
  114. for(i = 0; i <= NUM_PS2_SHADER_BLEND_PRESETS; i++) {
  115. SendDlgItemMessage(dlg_wnd,IDC_PS2_PRESET_COMBO,CB_ADDSTRING,0,(LONG)_PS2ShaderBlendSettingPresetNames[i]);
  116. }
  117. SendDlgItemMessage(dlg_wnd,IDC_PS2_PRESET_COMBO,CB_SETCURSEL,0,0);
  118. break;
  119. case WM_LBUTTONDOWN:
  120. case WM_LBUTTONUP:
  121. case WM_MOUSEMOVE:
  122. {
  123. IParams->RollupMouseMessage(dlg_wnd,message,wparam,lparam);
  124. }
  125. return FALSE;
  126. case WM_COMMAND:
  127. {
  128. if (code == CBN_SELCHANGE) {
  129. switch (id)
  130. {
  131. // Shared by both shaders.
  132. case IDC_DEPTHCOMPARE_COMBO:
  133. cursel = SendDlgItemMessage(dlg_wnd,IDC_DEPTHCOMPARE_COMBO,CB_GETCURSEL,0,0);
  134. TheMtl->Set_Depth_Compare(PassIndex,cursel);
  135. break;
  136. case IDC_PRIGRADIENT_COMBO:
  137. cursel = SendDlgItemMessage(dlg_wnd,IDC_PRIGRADIENT_COMBO,CB_GETCURSEL,0,0);
  138. TheMtl->Set_Pri_Gradient(PassIndex,cursel);
  139. TheMtl->Notify_Changed();
  140. break;
  141. case IDC_SECGRADIENT_COMBO:
  142. cursel = SendDlgItemMessage(dlg_wnd,IDC_SECGRADIENT_COMBO,CB_GETCURSEL,0,0);
  143. TheMtl->Set_Sec_Gradient(PassIndex,cursel);
  144. TheMtl->Notify_Changed();
  145. break;
  146. case IDC_DETAILCOLOR_COMBO:
  147. cursel = SendDlgItemMessage(dlg_wnd,IDC_DETAILCOLOR_COMBO,CB_GETCURSEL,0,0);
  148. TheMtl->Set_Detail_Color_Func(PassIndex,cursel);
  149. TheMtl->Notify_Changed();
  150. break;
  151. case IDC_DETAILALPHA_COMBO:
  152. cursel = SendDlgItemMessage(dlg_wnd,IDC_DETAILALPHA_COMBO,CB_GETCURSEL,0,0);
  153. TheMtl->Set_Detail_Alpha_Func(PassIndex,cursel);
  154. TheMtl->Notify_Changed();
  155. break;
  156. // Playstation 2 specific.
  157. case IDC_PS2_PRESET_COMBO:
  158. cursel = SendDlgItemMessage(dlg_wnd,IDC_PS2_PRESET_COMBO,CB_GETCURSEL,0,0);
  159. Apply_Preset(cursel);
  160. break;
  161. case IDC_A_COMBO:
  162. cursel = SendDlgItemMessage(dlg_wnd,IDC_A_COMBO,CB_GETCURSEL,0,0);
  163. TheMtl->Set_PS2_Shader_Param_A(PassIndex,cursel);
  164. TheMtl->Notify_Changed();
  165. Set_Preset();
  166. break;
  167. case IDC_B_COMBO:
  168. cursel = SendDlgItemMessage(dlg_wnd,IDC_B_COMBO,CB_GETCURSEL,0,0);
  169. TheMtl->Set_PS2_Shader_Param_B(PassIndex,cursel);
  170. TheMtl->Notify_Changed();
  171. Set_Preset();
  172. break;
  173. case IDC_C_COMBO:
  174. cursel = SendDlgItemMessage(dlg_wnd,IDC_C_COMBO,CB_GETCURSEL,0,0);
  175. TheMtl->Set_PS2_Shader_Param_C(PassIndex,cursel);
  176. TheMtl->Notify_Changed();
  177. Set_Preset();
  178. break;
  179. case IDC_D_COMBO:
  180. cursel = SendDlgItemMessage(dlg_wnd,IDC_D_COMBO,CB_GETCURSEL,0,0);
  181. TheMtl->Set_PS2_Shader_Param_D(PassIndex,cursel);
  182. TheMtl->Notify_Changed();
  183. Set_Preset();
  184. break;
  185. }
  186. } else {
  187. switch(id) {
  188. case IDC_DEPTHMASK_CHECK:
  189. if (SendDlgItemMessage(dlg_wnd,IDC_DEPTHMASK_CHECK,BM_GETCHECK,0,0)) {
  190. TheMtl->Set_Depth_Mask(PassIndex,W3DSHADER_DEPTHMASK_WRITE_ENABLE);
  191. } else {
  192. TheMtl->Set_Depth_Mask(PassIndex,W3DSHADER_DEPTHMASK_WRITE_DISABLE);
  193. }
  194. Set_Preset();
  195. break;
  196. case IDC_ALPHATEST_CHECK:
  197. if (SendDlgItemMessage(dlg_wnd,IDC_ALPHATEST_CHECK,BM_GETCHECK,0,0)) {
  198. TheMtl->Set_Alpha_Test(PassIndex,W3DSHADER_ALPHATEST_ENABLE);
  199. } else {
  200. TheMtl->Set_Alpha_Test(PassIndex,W3DSHADER_ALPHATEST_DISABLE);
  201. }
  202. Set_Preset();
  203. break;
  204. case IDC_SHADER_DEFAULTS_BUTTON:
  205. Set_Advanced_Defaults();
  206. break;
  207. }
  208. }
  209. }
  210. }
  211. return FALSE;
  212. }
  213. /***********************************************************************************************
  214. * PGMSD::ReloadDialog -- Setup the dialog box. *
  215. * *
  216. * *
  217. * *
  218. * *
  219. * HISTORY: *
  220. * 10/12/1999MLL: Created. *
  221. *=============================================================================================*/
  222. void PS2GameMtlShaderDlg::ReloadDialog(void)
  223. {
  224. DebugPrint("GameMtlShaderDlg::ReloadDialog\n");
  225. SendDlgItemMessage(m_hWnd, IDC_PRIGRADIENT_COMBO, CB_SETCURSEL, TheMtl->Get_Pri_Gradient(PassIndex), 0 );
  226. SendDlgItemMessage(m_hWnd, IDC_SECGRADIENT_COMBO, CB_SETCURSEL, TheMtl->Get_Sec_Gradient(PassIndex), 0 );
  227. SendDlgItemMessage(m_hWnd, IDC_DEPTHCOMPARE_COMBO, CB_SETCURSEL, TheMtl->Get_Depth_Compare(PassIndex), 0 );
  228. SendDlgItemMessage(m_hWnd, IDC_DETAILCOLOR_COMBO, CB_SETCURSEL, TheMtl->Get_Detail_Color_Func(PassIndex), 0 );
  229. SendDlgItemMessage(m_hWnd, IDC_DETAILALPHA_COMBO, CB_SETCURSEL, TheMtl->Get_Detail_Alpha_Func(PassIndex), 0 );
  230. SendDlgItemMessage(m_hWnd, IDC_A_COMBO, CB_SETCURSEL, TheMtl->Get_PS2_Shader_Param_A(PassIndex), 0);
  231. SendDlgItemMessage(m_hWnd, IDC_B_COMBO, CB_SETCURSEL, TheMtl->Get_PS2_Shader_Param_B(PassIndex), 0);
  232. SendDlgItemMessage(m_hWnd, IDC_C_COMBO, CB_SETCURSEL, TheMtl->Get_PS2_Shader_Param_C(PassIndex), 0);
  233. SendDlgItemMessage(m_hWnd, IDC_D_COMBO, CB_SETCURSEL, TheMtl->Get_PS2_Shader_Param_D(PassIndex), 0);
  234. Set_Preset();
  235. SetCheckBox(m_hWnd,IDC_DEPTHMASK_CHECK, TheMtl->Get_Depth_Mask(PassIndex));
  236. SetCheckBox(m_hWnd,IDC_ALPHATEST_CHECK, TheMtl->Get_Alpha_Test(PassIndex));
  237. }
  238. /***********************************************************************************************
  239. * PGMSD::Apply_Preset -- Notify the material of the values for the selected setting. *
  240. * *
  241. * *
  242. * *
  243. * *
  244. * HISTORY: *
  245. * 10/12/1999MLL: Created. *
  246. *=============================================================================================*/
  247. void PS2GameMtlShaderDlg::Apply_Preset(int preset_index)
  248. {
  249. if (preset_index < 0 || preset_index >= NUM_PS2_SHADER_BLEND_PRESETS) return;
  250. const PS2ShaderBlendSettingPreset &preset = PS2ShaderBlendSettingPresets[preset_index];
  251. int depth_mask = preset.DepthMask ? W3DSHADER_DEPTHMASK_WRITE_ENABLE : W3DSHADER_DEPTHMASK_WRITE_DISABLE;
  252. TheMtl->Set_Depth_Mask(PassIndex, depth_mask);
  253. int alpha_test = preset.AlphaTest ? W3DSHADER_ALPHATEST_ENABLE : W3DSHADER_ALPHATEST_DISABLE;
  254. TheMtl->Set_Alpha_Test(PassIndex, alpha_test);
  255. TheMtl->Set_PS2_Shader_Param_A(PassIndex, preset.A);
  256. TheMtl->Set_PS2_Shader_Param_B(PassIndex, preset.B);
  257. TheMtl->Set_PS2_Shader_Param_C(PassIndex, preset.C);
  258. TheMtl->Set_PS2_Shader_Param_D(PassIndex, preset.D);
  259. TheMtl->Notify_Changed();
  260. ReloadDialog();
  261. if (TheMtl->Compute_PC_Shader_From_PS2_Shader(PassIndex))
  262. SetWindowText(GetDlgItem(m_hWnd,IDC_COMPATIBLE), " Compatible");
  263. else
  264. SetWindowText(GetDlgItem(m_hWnd,IDC_COMPATIBLE), " NOT Compatible");
  265. }
  266. /***********************************************************************************************
  267. * PGMSD::Set_Preset -- Sets the dialog to one of the presets or custom. *
  268. * *
  269. * *
  270. * *
  271. * *
  272. * HISTORY: *
  273. * 10/12/1999MLL: Created. *
  274. *=============================================================================================*/
  275. void PS2GameMtlShaderDlg::Set_Preset(void)
  276. {
  277. for (int i = 0; i < NUM_PS2_SHADER_BLEND_PRESETS; i++) {
  278. if (CompareShaderToBlendPreset(PS2ShaderBlendSettingPresets[i])) break;
  279. }
  280. SendDlgItemMessage(m_hWnd, IDC_PS2_PRESET_COMBO, CB_SETCURSEL, i, 0);
  281. if (TheMtl->Compute_PC_Shader_From_PS2_Shader(PassIndex))
  282. SetWindowText(GetDlgItem(m_hWnd,IDC_COMPATIBLE), " Compatible");
  283. else
  284. SetWindowText(GetDlgItem(m_hWnd,IDC_COMPATIBLE), " NOT Compatible");
  285. }
  286. /***********************************************************************************************
  287. * PGMSD::CompareShaderToBlendPreset -- Determine if the settings conform to one of the presets*
  288. * *
  289. * *
  290. * *
  291. * *
  292. * HISTORY: *
  293. * 10/12/1999MLL: Created. *
  294. *=============================================================================================*/
  295. bool PS2GameMtlShaderDlg::CompareShaderToBlendPreset(const PS2ShaderBlendSettingPreset &blend_preset)
  296. {
  297. bool depthmask = TheMtl->Get_Depth_Mask(PassIndex) != W3DSHADER_DEPTHMASK_WRITE_DISABLE;
  298. if (depthmask != blend_preset.DepthMask) return false;
  299. bool alphatest = TheMtl->Get_Alpha_Test(PassIndex) != W3DSHADER_ALPHATEST_DISABLE;
  300. if (alphatest != blend_preset.AlphaTest) return false;
  301. if (TheMtl->Get_PS2_Shader_Param_A(PassIndex) != blend_preset.A) return false;
  302. if (TheMtl->Get_PS2_Shader_Param_B(PassIndex) != blend_preset.B) return false;
  303. if (TheMtl->Get_PS2_Shader_Param_C(PassIndex) != blend_preset.C) return false;
  304. if (TheMtl->Get_PS2_Shader_Param_D(PassIndex) != blend_preset.D) return false;
  305. return true;
  306. }
  307. /***********************************************************************************************
  308. * GameMtlShaderDlg::Set_Advanced_Defaults -- set advanced settings to defaults *
  309. * *
  310. * INPUT: *
  311. * *
  312. * OUTPUT: *
  313. * *
  314. * WARNINGS: *
  315. * *
  316. * HISTORY: *
  317. * 02/26/99 NH : Created. *
  318. *=============================================================================================*/
  319. void PS2GameMtlShaderDlg::Set_Advanced_Defaults(void)
  320. {
  321. TheMtl->Set_Pri_Gradient(PassIndex, PSS_PRIGRADIENT_MODULATE);
  322. TheMtl->Set_Depth_Compare(PassIndex, PSS_DEPTHCOMPARE_PASS_LEQUAL);
  323. TheMtl->Set_Detail_Color_Func(PassIndex, W3DSHADER_DETAILCOLORFUNC_DEFAULT);
  324. TheMtl->Set_Detail_Alpha_Func(PassIndex, W3DSHADER_DETAILALPHAFUNC_DEFAULT);
  325. TheMtl->Notify_Changed();
  326. ReloadDialog();
  327. }