[SOLVED] Implementing ForceAlphaToCoverage (KOTOR)

  • Niko of Death
  • Topic Author
More
6 years 2 months ago - 6 years 2 months ago #1 by Niko of Death Implementing ForceAlphaToCoverage (KOTOR) was created by Niko of Death
I am using reshade with Star Wars: Knights of The Old Republic. As some of you may know, modern AMD gpus (and their drivers) do not play nicely with this game, requiring the soft shadows, frame buffer effects, and grass effects to be disabled, though there are workarounds. The workaround for the last one (grass appearing invisible, causing the game to look like this ) is to use GLOverride enabling the ForceAlphaToCoverage option. However, this uses opengl32.dll for hooking just like reshade, leaving me stuck between the two. Is there any way to implement this effect through reshade?
Last edit: 6 years 2 months ago by Niko of Death.

Please Log in or Create an account to join the conversation.

  • crosire
More
6 years 2 months ago #2 by crosire Replied by crosire on topic Implementing ForceAlphaToCoverage (KOTOR)
Yes. But it's not going to happen in the official build because it's outside the scope of ReShade.

The alpha to coverage test is specific to multisampling, so you could just disable MSAA. Anyway, it's really trivial to implement this in ReShade. You can do it yourself even. Clone the source code for ReShade from github.com/crosire/reshade using Git, open the file "source/opengl/stubs_gl.cpp" and search for the following lines:
HOOK_EXPORT void WINAPI glEnable(GLenum cap)
{
	static const auto trampoline = reshade::hooks::call(&glEnable);

	trampoline(cap);
}
HOOK_EXPORT void WINAPI glDisable(GLenum cap)
{
	static const auto trampoline = reshade::hooks::call(&glDisable);

	trampoline(cap);
}
Now simply replace them with the following and build the project in Visual Studio to get a custom ReShade build which forces alpha to coverage sampling. Instructions on how to build can be found in the readme at github.com/crosire/reshade . It's pretty trivial for the most part.
HOOK_EXPORT void WINAPI glEnable(GLenum cap)
{
	static const auto trampoline = reshade::hooks::call(&glEnable);

	if (cap == GL_ALPHA_TEST)
		trampoline(0x809E); // GL_SAMPLE_ALPHA_TO_COVERAGE
	else
		trampoline(cap);
}
HOOK_EXPORT void WINAPI glDisable(GLenum cap)
{
	static const auto trampoline = reshade::hooks::call(&glDisable);

	if (cap == GL_ALPHA_TEST)
		trampoline(0x809E); // GL_SAMPLE_ALPHA_TO_COVERAGE
	else
		trampoline(cap);
}

Please Log in or Create an account to join the conversation.

  • Niko of Death
  • Topic Author
More
6 years 2 months ago #3 by Niko of Death Replied by Niko of Death on topic Implementing ForceAlphaToCoverage (KOTOR)
Thank you for the help!

I should note that the process was made a little more complicated by glcorearb.h not including a definition for GL_ALPHA_TEST (presumably this is due to the cap being deprecated as of opengl 3.1), so I had to look up the proper definition (found at www.khronos.org/registry/OpenGL/api/GLES/1.0/gl.h , it is
#define GL_ALPHA_TEST                     0x0BC0
), build gl3w, add that to glcorearb.h, then disable gl3w from the solution build (so glcorearb.h does not get overwritten), then build the solution.

I uploaded this custom version in case anyone else needs it. mega.nz/#!A5liTKjQ!dqeeNAIdO3OgLFw2-NORQQZz9Cizan4c-AnIoQoxf3Q

Thanks again!

Please Log in or Create an account to join the conversation.

  • Sin31
More
4 years 11 months ago #4 by Sin31 Replied by Sin31 on topic Implementing ForceAlphaToCoverage (KOTOR)
Hi, Im trying to do this in reshade 4.2.1 with the source code as it is now april/2019, and in the directory "source/opengl" isn't any file named "stubs_gl.cpp"
When i try to use the "opengl32.dll" provided by "Niko of Death" the grassfix works fine but the version of reshade is downgraded to 3.1.1.17 and when i run the game reshade pops an error log window saying that cannot load a lot of the shaders (.fx)

Please Log in or Create an account to join the conversation.

  • crosire
More
4 years 11 months ago #5 by crosire Replied by crosire on topic Implementing ForceAlphaToCoverage (KOTOR)
source/opengl/opengl_hooks.cpp
The following user(s) said Thank You: Mack94

Please Log in or Create an account to join the conversation.

  • Mack94
More
3 years 1 day ago #6 by Mack94 Replied by Mack94 on topic Implementing ForceAlphaToCoverage (KOTOR)
Hey Crosire, so I'm playing KOTOR and trying to do exactly what Niko Of Death did in regards to building a custom Reshade through visual studio which forces alpha to coverage sampling . I've followed your tutorial on this page and in the read me on github. I've already edited the source/opengl/opengl_hooks.cpp after uploading reshade into the VS via the source code on github. But I'm running into some problems while building. Here are my errors:
Severity Code Description Project File Line Suppression State
Warning CMake Warning (dev) at C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.19/Modules/GNUInstallDirs.cmake:223 (message):
Unable to determine default CMAKE_INSTALL_LIBDIR directory because no
target architecture is known. Please enable at least one language before
including GNUInstallDirs. C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.19/Modules/GNUInstallDirs.cmake 223
Severity Code Description Project File Line Suppression State
Error C1083 Cannot open include file: 'GL/gl3w.h': No such file or directory ReShade C:\Users\mackm\source\repos\reshade\source\opengl\opengl.hpp 6
Severity Code Description Project File Line Suppression State
Error MSB3073 The command "python gl3w_gen.py" exited with code 9009. gl3w C:\Users\mackm\source\repos\reshade\deps\gl3w.vcxproj 87

So I get these errors when I first attempt to release build. Also one thing I'm confused on is: When I first start building (the reshade dll) what do I select in the solution explorer? reshade snl? Any help would be greatly appreciated, really love your work BTW.

Please Log in or Create an account to join the conversation.

We use cookies
We use cookies on our website. Some of them are essential for the operation of the forum. You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.