Skip to content

Commit

Permalink
Add ability to configure live shader parameters (dx9 alt -> Hardfx ->…
Browse files Browse the repository at this point in the history
… settings).

see HardFXConfigs[] in src/intf/video/win32/vid_directx9.cpp
float4 user_settings; in hlsl shader
  • Loading branch information
dinkc64 committed Oct 29, 2024
1 parent 9d9e52d commit ddc5fde
Show file tree
Hide file tree
Showing 9 changed files with 368 additions and 23 deletions.
27 changes: 27 additions & 0 deletions src/burner/win32/app.rc
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,32 @@ BEGIN
PUSHBUTTON "Cancel",IDCANCEL,105,40,50,14
END

IDD_HARDFXSETTINGS DIALOGEX 0, 0, 214, 169
STYLE DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "HardFX shader options"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
GROUPBOX "Option #1", IDC_SPRITE1, 3, 36*0, 208, 35
CONTROL "Value",IDC_HARDFX_SLIDER1,"msctls_trackbar32", WS_TABSTOP, 5, 36*0+10, 160, 18
EDITTEXT IDC_HARDFX_SLIDER_EDIT1,167,36*0+10,35,14,SS_CENTERIMAGE

GROUPBOX "Option #2", IDC_SPRITE2, 3, 36*1, 208, 35
CONTROL "Value",IDC_HARDFX_SLIDER2,"msctls_trackbar32", WS_TABSTOP, 5, 36*1+10, 160, 18
EDITTEXT IDC_HARDFX_SLIDER_EDIT2,167,36*1+10,35,14,SS_CENTERIMAGE

GROUPBOX "Option #3", IDC_SPRITE3, 3, 36*2, 208, 35
CONTROL "Value",IDC_HARDFX_SLIDER3,"msctls_trackbar32", WS_TABSTOP, 5, 36*2+10, 160, 18
EDITTEXT IDC_HARDFX_SLIDER_EDIT3,167,36*2+10,35,14,SS_CENTERIMAGE

GROUPBOX "Option #4", IDC_SPRITE4, 3, 36*3, 208, 35
CONTROL "Value",IDC_HARDFX_SLIDER4,"msctls_trackbar32", WS_TABSTOP, 5, 36*3+10, 160, 18
EDITTEXT IDC_HARDFX_SLIDER_EDIT4,167,36*3+10,35,14,SS_CENTERIMAGE

PUSHBUTTON "Defaults",IDRETRY,52,150,50,14
DEFPUSHBUTTON "OK",IDOK,158,150,50,14
PUSHBUTTON "Cancel",IDCANCEL,105,150,50,14
END

IDD_SCANLINE DIALOGEX 0, 0, 214, 59
STYLE DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Select desired scanline intensity"
Expand Down Expand Up @@ -1455,6 +1481,7 @@ BEGIN
MENUITEM "CRT Bicubic", MENU_DX9_ALT_HARD_FX_CRT_BICUBIC
MENUITEM "CRT Retro Scanlines", MENU_DX9_ALT_HARD_FX_CRT_RETROSL
MENUITEM "CRT CGA", MENU_DX9_ALT_HARD_FX_CRT_CGA
MENUITEM "Selected Shader's Settings", MENU_DX9_ALT_HARD_FX_SETTINGS
END
POPUP "SoftFX algorithm"
BEGIN
Expand Down
1 change: 1 addition & 0 deletions src/burner/win32/burner_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ int StatedSave(int nSlot);
// numdial.cpp
int NumDialCreate(int bDial);
void GammaDialog();
void HardFXShaderSettingsDialog();
void ScanlineDialog();
void PhosphorDialog();
void ScreenAngleDialog();
Expand Down
39 changes: 39 additions & 0 deletions src/burner/win32/cona.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ struct VidPresetDataVer VidPresetVer[4] = {
// last one set at desktop resolution
};

static void HardFXLoadDefaults()
{
int totalHardFX = MENU_DX9_ALT_HARD_FX_LAST - MENU_DX9_ALT_HARD_FX_NONE;

for (int thfx = 0; thfx < totalHardFX; thfx++) {
HardFXConfigs[thfx].hardfx_config_load_defaults();
}
}

static void CreateConfigName(TCHAR* szConfig)
{
_stprintf(szConfig, _T("config/%s.ini"), szAppExeName);
Expand All @@ -40,6 +49,8 @@ int ConfigAppLoad()
setlocale(LC_ALL, "");
#endif

HardFXLoadDefaults();

CreateConfigName(szConfig);

if ((h = _tfopen(szConfig, _T("rt"))) == NULL) {
Expand Down Expand Up @@ -165,6 +176,21 @@ int ConfigAppLoad()
VAR(bVidMotionBlur);
VAR(bVidForce16bitDx9Alt);

{
int totalHardFX = MENU_DX9_ALT_HARD_FX_LAST - MENU_DX9_ALT_HARD_FX_NONE;

for (int thfx = 0; thfx < totalHardFX; thfx++) {
// for each fx, check if it has settings that needs to be saved
for (int thfx_option = 0; thfx_option < HardFXConfigs[thfx].nOptions; thfx_option++) {
TCHAR szLabel[64];
_stprintf(szLabel, _T("HardFXOption[%d][%d]"), thfx, thfx_option);

TCHAR* szValue = LabelCheck(szLine, szLabel);
if (szValue) HardFXConfigs[thfx].fOptions[thfx_option] = _tcstod(szValue, NULL);
}
}
}

// Sound
VAR(nAudSelect);
VAR(nAudVolume);
Expand Down Expand Up @@ -519,6 +545,19 @@ int ConfigAppSave()
_ftprintf(h, _T("\n// If non-zero, force 16 bit emulation even in 32-bit screenmodes\n"));
VAR(bVidForce16bitDx9Alt);

_ftprintf(h, _T("\n// HardFX shader options\n"));

{
int totalHardFX = MENU_DX9_ALT_HARD_FX_LAST - MENU_DX9_ALT_HARD_FX_NONE;

for (int thfx = 0; thfx < totalHardFX; thfx++) {
// for each fx, check if it has settings that needs to be saved
for (int thfx_option = 0; thfx_option < HardFXConfigs[thfx].nOptions; thfx_option++) {
_ftprintf(h, _T("HardFXOption[%d][%d] %lf\n"), thfx, thfx_option, HardFXConfigs[thfx].fOptions[thfx_option]);
}
}
}

_ftprintf(h, _T("\n\n\n"));
_ftprintf(h, _T("// --- Sound ------------------------------------------------------------------\n"));
_ftprintf(h, _T("\n// The selected audio plugin\n"));
Expand Down
5 changes: 5 additions & 0 deletions src/burner/win32/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,11 @@ void MenuUpdate()
CheckMenuItem(hMenu, MENU_DX9_ALT_HARDWAREVERTEX, (bVidHardwareVertex) ? MF_CHECKED : MF_UNCHECKED);
CheckMenuItem(hMenu, MENU_DX9_ALT_MOTIONBLUR, (bVidMotionBlur) ? MF_CHECKED : MF_UNCHECKED);
CheckMenuRadioItem(hMenu, MENU_DX9_ALT_HARD_FX_NONE, MENU_DX9_ALT_HARD_FX_LAST, MENU_DX9_ALT_HARD_FX_NONE + nVidDX9HardFX, MF_BYCOMMAND);

// Enable HardFX Settings if we have options!
bool hFXDisabled = (nVidDX9HardFX == 0) || (HardFXConfigs[nVidDX9HardFX].nOptions == 0);
EnableMenuItem(hMenu, MENU_DX9_ALT_HARD_FX_SETTINGS, hFXDisabled ? (MF_GRAYED | MF_BYCOMMAND) : (MF_ENABLED | MF_BYCOMMAND));

CheckMenuItem(hMenu, MENU_DX9_ALT_FORCE_16BIT, bVidForce16bitDx9Alt ? MF_CHECKED : MF_UNCHECKED);
break;
}
Expand Down
220 changes: 220 additions & 0 deletions src/burner/win32/numdial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@ const double RADTODEG = 57.29577951308232286465f; // Radians to Degrees

static int nExitStatus;

static bool bIsProperFloatString(TCHAR *szText)
{
bool bValid = 1;
bool bPoint = 0;

if (_tcslen(szText) == 0) return 0;

// Scan string in the edit control for illegal characters
for (int i = 0; szText[i]; i++) {
if (szText[i] == _T('.')) {
if (bPoint) {
bValid = 0;
break;
}
} else {
if (!_istdigit(szText[i])) {
bValid = 0;
break;
}
}
}

return bValid;
}

// -----------------------------------------------------------------------------

static INT_PTR CALLBACK DefInpProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM)
Expand Down Expand Up @@ -49,6 +74,201 @@ int NumDialCreate(int)
return 1;
}

// -----------------------------------------------------------------------------
// HardFX Shader Settings dialog

static void HardFXUpdateValues(HWND hDlg)
{
for (int i = 0; i < 4; i++) { // 4 edit controls!
TCHAR szText[18];
int SLIDER_ID = IDC_HARDFX_SLIDER1 + i;
int SLIDER_EDIT_ID = IDC_HARDFX_SLIDER_EDIT1 + i;
int f2i = HardFXConfigs[nVidDX9HardFX].fOptions[i] * 10000;
float temp = HardFXConfigs[nVidDX9HardFX].fOptions[i];

SendDlgItemMessage(hDlg, SLIDER_ID, TBM_SETPOS, (WPARAM)true, (LPARAM)f2i);

_stprintf(szText, _T("%0.2f"), temp);
SendDlgItemMessage(hDlg, SLIDER_EDIT_ID, WM_SETTEXT, (WPARAM)0, (LPARAM)szText);
}
}

static INT_PTR CALLBACK HardFXShaderSettingsProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam) // LPARAM lParam
{
static float nPrevSettings[4]; // for the "Cancel" button
int SLIDER_ID;
int SLIDER_ID_RAW;
int SLIDER_EDIT_ID;

switch (Msg) {
case WM_INITDIALOG: {
// back-up settings for "cancel" option
nPrevSettings[0] = HardFXConfigs[nVidDX9HardFX].fOptions[0];
nPrevSettings[1] = HardFXConfigs[nVidDX9HardFX].fOptions[1];
nPrevSettings[2] = HardFXConfigs[nVidDX9HardFX].fOptions[2];
nPrevSettings[3] = HardFXConfigs[nVidDX9HardFX].fOptions[3];

nExitStatus = 0;

WndInMid(hDlg, hScrnWnd);

for (int i = 0; i < 4; i++) { // 4 edit controls!
// Initialise option
SLIDER_ID = IDC_HARDFX_SLIDER1 + i;
SLIDER_EDIT_ID = IDC_HARDFX_SLIDER_EDIT1 + i;

SendDlgItemMessage(hDlg, SLIDER_ID, TBM_SETRANGE, (WPARAM)0, (LPARAM)MAKELONG(1, 20000));
SendDlgItemMessage(hDlg, SLIDER_ID, TBM_SETLINESIZE, (WPARAM)0, (LPARAM)200);
SendDlgItemMessage(hDlg, SLIDER_ID, TBM_SETPAGESIZE, (WPARAM)0, (LPARAM)250);
SendDlgItemMessage(hDlg, SLIDER_ID, TBM_SETTIC, (WPARAM)0, (LPARAM)7500);
SendDlgItemMessage(hDlg, SLIDER_ID, TBM_SETTIC, (WPARAM)0, (LPARAM)10001);
SendDlgItemMessage(hDlg, SLIDER_ID, TBM_SETTIC, (WPARAM)0, (LPARAM)12500);

// Set Controlbox heading
TCHAR szHeading[255] = _T("Not Available");
HWND hHeading = GetDlgItem(hDlg, IDC_SPRITE1 + i);
SetWindowText(hHeading, (i < HardFXConfigs[nVidDX9HardFX].nOptions) ? ANSIToTCHAR(HardFXConfigs[nVidDX9HardFX].szOptions[i], NULL, 0) : szHeading);
if (i >= HardFXConfigs[nVidDX9HardFX].nOptions) {
EnableWindow(hHeading, FALSE);
HWND hSlider = GetDlgItem(hDlg, SLIDER_ID);
HWND hSliderEdit = GetDlgItem(hDlg, SLIDER_EDIT_ID);
EnableWindow(hSlider, FALSE);
EnableWindow(hSliderEdit, FALSE);
}
}

HardFXUpdateValues(hDlg);

// Update the screen
if (bVidOkay) {
VidRedraw();
VidPaint(0);
}

return TRUE;
}
case WM_COMMAND: {
switch (HIWORD(wParam)) {
case BN_CLICKED: {
if (LOWORD(wParam) == IDOK) {
nExitStatus = 1;
SendMessage(hDlg, WM_CLOSE, 0, 0);
}
if (LOWORD(wParam) == IDCANCEL) {
nExitStatus = -1;
SendMessage(hDlg, WM_CLOSE, 0, 0);
}
if (LOWORD(wParam) == IDRETRY) { // [Defaults] Button is here!
HardFXConfigs[nVidDX9HardFX].hardfx_config_load_defaults();
HardFXUpdateValues(hDlg);
}
break;
}
case EN_UPDATE: {
SLIDER_ID = -1;
SLIDER_EDIT_ID = -1;
switch (LOWORD(wParam)) {
case IDC_HARDFX_SLIDER_EDIT1:
case IDC_HARDFX_SLIDER_EDIT2:
case IDC_HARDFX_SLIDER_EDIT3:
case IDC_HARDFX_SLIDER_EDIT4:
SLIDER_EDIT_ID = LOWORD(wParam);
SLIDER_ID = IDC_HARDFX_SLIDER1 + (SLIDER_EDIT_ID - IDC_HARDFX_SLIDER_EDIT1);
SLIDER_ID_RAW = SLIDER_ID - IDC_HARDFX_SLIDER1;
break;
}
if (nExitStatus == 0 && SLIDER_ID != -1) {
TCHAR szText[18] = _T("");
bool bValid = 1;

if (SendDlgItemMessage(hDlg, SLIDER_EDIT_ID, WM_GETTEXTLENGTH, (WPARAM)0, (LPARAM)0) < 16) {
SendDlgItemMessage(hDlg, SLIDER_EDIT_ID, WM_GETTEXT, (WPARAM)16, (LPARAM)szText);
}

bValid = bIsProperFloatString(szText);

if (bValid) {
float fTemp = _tcstod(szText, NULL);
int nPos = fTemp * 10000;

HardFXConfigs[nVidDX9HardFX].fOptions[SLIDER_ID_RAW] = fTemp;

SendDlgItemMessage(hDlg, SLIDER_ID, TBM_SETPOS, (WPARAM)true, (LPARAM)nPos);

if (bVidOkay) {
VidRedraw();
VidPaint(0);
}
}
}
break;
}
break;
}
}

case WM_HSCROLL: {
switch (LOWORD(wParam)) {
case TB_BOTTOM:
case TB_ENDTRACK:
case TB_LINEDOWN:
case TB_LINEUP:
case TB_PAGEDOWN:
case TB_PAGEUP:
case TB_THUMBPOSITION:
case TB_THUMBTRACK:
case TB_TOP: {
if (nExitStatus == 0) {
// Update the contents of the edit control
SLIDER_ID = -1;
SLIDER_EDIT_ID = -1;
switch (GetDlgCtrlID((HWND)lParam)) {
case IDC_HARDFX_SLIDER1:
case IDC_HARDFX_SLIDER2:
case IDC_HARDFX_SLIDER3:
case IDC_HARDFX_SLIDER4:
SLIDER_ID = GetDlgCtrlID((HWND)lParam);// - IDC_HARDFX_SLIDER1;
SLIDER_EDIT_ID = IDC_HARDFX_SLIDER_EDIT1 + (SLIDER_ID - IDC_HARDFX_SLIDER1);
SLIDER_ID_RAW = SLIDER_ID - IDC_HARDFX_SLIDER1;

// Update the contents of the edit control
int nPos = SendDlgItemMessage(hDlg, SLIDER_ID, TBM_GETPOS, (WPARAM)0, (LPARAM)0);
float fTemp = (float)nPos / 10000;
HardFXConfigs[nVidDX9HardFX].fOptions[SLIDER_ID_RAW] = fTemp;

HardFXUpdateValues(hDlg);

if (bVidOkay) {
VidRedraw();
VidPaint(0);
}
}
break;
}
}
break;
}
break;
}

case WM_CLOSE:
if (nExitStatus != 1) {
// cancel pressed, restore backed-up settings
HardFXConfigs[nVidDX9HardFX].fOptions[0] = nPrevSettings[0];
HardFXConfigs[nVidDX9HardFX].fOptions[1] = nPrevSettings[1];
HardFXConfigs[nVidDX9HardFX].fOptions[2] = nPrevSettings[2];
HardFXConfigs[nVidDX9HardFX].fOptions[3] = nPrevSettings[3];
}
EndDialog(hDlg, 0);
}

return 0;
}

void HardFXShaderSettingsDialog()
{
FBADialogBox(hAppInst, MAKEINTRESOURCE(IDD_HARDFXSETTINGS), hScrnWnd, (DLGPROC)HardFXShaderSettingsProc);
}
// -----------------------------------------------------------------------------
// Gamma dialog

Expand Down
14 changes: 13 additions & 1 deletion src/burner/win32/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#define IDD_GAMEINFO 81
#define IDD_DOWNLOAD_LOCAL 82
#define IDD_CHOOSEMONITOR 83
#define IDD_HARDFXSETTINGS 84

#define IDR_MENU 100
#define IDR_MENU_BLITTER_1 110
Expand Down Expand Up @@ -203,6 +204,16 @@
#define IDC_CHOOSE_MONITOR_VER_LIST 20144
#define IDC_CHOOSE_MONITOR_TEXT 20145
#define IDC_LIST3 20146
#define IDC_HARDFX_SLIDER1 20147
#define IDC_HARDFX_SLIDER2 20148
#define IDC_HARDFX_SLIDER3 20149
#define IDC_HARDFX_SLIDER4 20150
#define IDC_HARDFX_SLIDER5 20151
#define IDC_HARDFX_SLIDER_EDIT1 20152
#define IDC_HARDFX_SLIDER_EDIT2 20153
#define IDC_HARDFX_SLIDER_EDIT3 20154
#define IDC_HARDFX_SLIDER_EDIT4 20155
#define IDC_HARDFX_SLIDER_EDIT5 20156

#define IDC_DRVCOUNT 20200
#define IDC_TREE2 20201
Expand Down Expand Up @@ -897,7 +908,8 @@
#define MENU_DX9_ALT_HARD_FX_CRT_BICUBIC 11456
#define MENU_DX9_ALT_HARD_FX_CRT_RETROSL 11457
#define MENU_DX9_ALT_HARD_FX_CRT_CGA 11458
#define MENU_DX9_ALT_HARD_FX_LAST 11458 // last one
#define MENU_DX9_ALT_HARD_FX_LAST 11458 // last one (same id as previous line!)
#define MENU_DX9_ALT_HARD_FX_SETTINGS 11470
#define MENU_DX9_ALT_SOFT_AUTOSIZE 11490
#define MENU_DX9_ALT_FORCE_16BIT 11491

Expand Down
Loading

0 comments on commit ddc5fde

Please sign in to comment.