From 384f441ad171ed9878a1aec8d44e3857edcb0d6f Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Mon, 25 Apr 2022 00:19:26 +0100 Subject: Fix dark L4D2 rendering on Intel integrated GPUs Thanks Aciidz for helping test this. --- compile.bat | 2 +- src/fixes.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/compile.bat b/compile.bat index 0f88cee..c8e2d40 100644 --- a/compile.bat +++ b/compile.bat @@ -68,7 +68,7 @@ if "%dbg%"=="1" ( set clibs=-lmsvcrt -lvcruntime -lucrt ) %CC% -shared -flto %ldflags% -Wl,/IMPLIB:.build/sst.lib,/Brepro,/nodefaultlib:libcmt ^ --L.build %clibs% -luser32 -ladvapi32 -lshlwapi -ltier0 -lvstdlib -o sst.dll%objs% .build/dll.res || exit /b +-L.build %clibs% -luser32 -ladvapi32 -lshlwapi -ld3d9 -ltier0 -lvstdlib -o sst.dll%objs% .build/dll.res || exit /b :: get rid of another useless file (can we just not create this???) del .build\sst.lib diff --git a/src/fixes.c b/src/fixes.c index eeac1c3..4f40183 100644 --- a/src/fixes.c +++ b/src/fixes.c @@ -18,7 +18,12 @@ #include #include +#ifdef _WIN32 +#include +#endif + #include "con_.h" +#include "factory.h" #include "gametype.h" static void chflags(const char *name, int unset, int set) { @@ -92,6 +97,28 @@ void fixes_apply(void) { } } +#ifdef _WIN32 + // L4D2 has broken (dark) rendering on Intel iGPUs unless + // mat_tonemapping_occlusion_use_stencil is enabled. Supposedly Valve used + // to detect device IDs to enable it on, but new devices are still broken, + // so just blanket enable it if the primary adapter is Intel, since it + // doesn't seem to break anything else anyway. + if (GAMETYPE_MATCHES(L4D2x)) { + struct con_var *v = con_findvar("mat_tonemapping_occlusion_use_stencil"); + if (!v || con_getvari(v)) goto e; + // considered getting d3d9 object from actual game, but it's way easier + // to just create another one + IDirect3D9 *d3d9 = Direct3DCreate9(D3D_SDK_VERSION); + if (!d3d9) goto e; + D3DADAPTER_IDENTIFIER9 ident; + if (IDirect3D9_GetAdapterIdentifier(d3d9, 0, 0, &ident) == D3D_OK && + ident.VendorId == 0x8086) { // neat vendor id, btw! + con_setvari(v, 1); + } + IDirect3D9_Release(d3d9); +e:; } +#endif + // For some reason, L4D1 hides mat_monitorgamma and doesn't archive it. // This means on every startup it's necessary to manually set non-default // values via the menu. This change here brings it in line with pretty much -- cgit v1.2.3