Welcome, Guest.
Username: Password: Remember me

TOPIC: [SOLVED] Implementing ForceAlphaToCoverage (KOTOR)

Implementing ForceAlphaToCoverage (KOTOR) 9 months 3 weeks ago #1

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: 9 months 3 weeks ago by Niko of Death.
The administrator has disabled public write access.

Implementing ForceAlphaToCoverage (KOTOR) 9 months 3 weeks ago #2

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);
}
Cheers, crosire =)
The administrator has disabled public write access.

Implementing ForceAlphaToCoverage (KOTOR) 9 months 3 weeks ago #3

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!
The administrator has disabled public write access.