1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-14 22:03:27 +01:00

add d3d9 lanczos2 shader

This commit is contained in:
FunkyFr3sh 2023-08-23 16:44:14 +02:00
parent 2a5bd91629
commit e2ed1930c3
4 changed files with 1094 additions and 190 deletions

File diff suppressed because it is too large Load Diff

View File

@ -39,6 +39,7 @@ HRESULT dd_CreateEx(GUID* lpGuid, LPVOID* lplpDD, REFIID iid, IUnknown* pUnkOute
#define FILTER_NEAREST 0
#define FILTER_LINEAR 1
#define FILTER_CUBIC 2
#define FILTER_LANCZOS 3
#define SDM_MODE_SET_BY_GAME 0x00000001l
#define SDM_LEAVE_WINDOWED 0x00000002l

View File

@ -298,7 +298,7 @@ static void cfg_create_ini()
"resizable=true\n"
"\n"
"; Upscaling filter for the direct3d9* renderers\n"
"; Possible values: 0 = nearest-neighbor, 1 = bilinear, 2 = bicubic (16/32bit color depth games only)\n"
"; Possible values: 0 = nearest-neighbor, 1 = bilinear, 2 = bicubic, 3 = lanczos (bicubic/lanczos only support 16/32bit color depth games)\n"
"d3d9_filter=2\n"
"\n"
"; Enable upscale hack for high resolution patches (Supports C&C1, Red Alert 1 and KKND Xtreme)\n"

View File

@ -318,10 +318,27 @@ static BOOL d3d9_create_resources()
}
else
{
IDirect3DDevice9_CreatePixelShader(
g_d3d9.device,
(DWORD*)D3D9_CATMULL_ROM_SHADER,
&g_d3d9.pixel_shader_upscale);
if (g_ddraw->d3d9_filter == FILTER_LANCZOS)
{
BOOL error = FAILED(
IDirect3DDevice9_CreatePixelShader(
g_d3d9.device,
(DWORD*)D3D9_LANCZOS2_SHADER,
&g_d3d9.pixel_shader_upscale));
if (error || !g_d3d9.pixel_shader_upscale)
{
g_ddraw->d3d9_filter = FILTER_CUBIC;
}
}
if (g_ddraw->d3d9_filter == FILTER_CUBIC)
{
IDirect3DDevice9_CreatePixelShader(
g_d3d9.device,
(DWORD*)D3D9_CATMULL_ROM_SHADER,
&g_d3d9.pixel_shader_upscale);
}
}
return g_d3d9.vertex_buf && (g_d3d9.pixel_shader || g_ddraw->bpp == 16 || g_ddraw->bpp == 32) && !err;
@ -359,11 +376,22 @@ static BOOL d3d9_set_states()
{
if (g_ddraw->d3d9_filter)
{
if (SUCCEEDED(IDirect3DDevice9_SetSamplerState(g_d3d9.device, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR)) &&
if (g_ddraw->d3d9_filter == FILTER_LANCZOS &&
g_d3d9.pixel_shader_upscale &&
(g_ddraw->render.viewport.width != g_ddraw->width ||
g_ddraw->render.viewport.height != g_ddraw->height) &&
SUCCEEDED(IDirect3DDevice9_SetPixelShader(g_d3d9.device, g_d3d9.pixel_shader_upscale)))
{
float texture_size[4] = { (float)g_d3d9.tex_width, (float)g_d3d9.tex_height, 0, 0 };
err = err || FAILED(IDirect3DDevice9_SetPixelShaderConstantF(g_d3d9.device, 0, texture_size, 1));
}
else if (
SUCCEEDED(IDirect3DDevice9_SetSamplerState(g_d3d9.device, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR)) &&
SUCCEEDED(IDirect3DDevice9_SetSamplerState(g_d3d9.device, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR)) &&
g_ddraw->d3d9_filter == FILTER_CUBIC &&
g_d3d9.pixel_shader_upscale &&
(g_ddraw->render.viewport.width != g_ddraw->width || g_ddraw->render.viewport.height != g_ddraw->height) &&
(g_ddraw->render.viewport.width != g_ddraw->width ||
g_ddraw->render.viewport.height != g_ddraw->height) &&
SUCCEEDED(IDirect3DDevice9_SetPixelShader(g_d3d9.device, g_d3d9.pixel_shader_upscale)))
{
float texture_size[4] = { (float)g_d3d9.tex_width, (float)g_d3d9.tex_height, 0, 0 };