Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix night vision in SOCOM games (in fact, fix the CLUT8 effect properly) #17317

Merged
merged 2 commits into from
Apr 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions GPU/Common/DepalettizeShaderCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ void GenerateDepalShader300(ShaderWriter &writer, const DepalConfig &config) {
writer.C(" int index = (b << 11) | (g << 5) | (r);\n");
break;
case GE_FORMAT_5551:
if (config.textureFormat == GE_TFMT_CLUT8) {
// SOCOM case. We need to make sure the next few lines load the right bits, see below.
shiftedMask <<= 8;
}
if (shiftedMask & 0x1F) writer.C(" int r = int(color.r * 31.99);\n"); else writer.C(" int r = 0;\n");
if (shiftedMask & 0x3E0) writer.C(" int g = int(color.g * 31.99);\n"); else writer.C(" int g = 0;\n");
if (shiftedMask & 0x7C00) writer.C(" int b = int(color.b * 31.99);\n"); else writer.C(" int b = 0;\n");
Expand Down Expand Up @@ -245,7 +249,7 @@ void GenerateDepalShaderFloat(ShaderWriter &writer, const DepalConfig &config) {
break;
case GE_FORMAT_5551:
if (config.textureFormat == GE_TFMT_CLUT8 && mask == 0xFF && shift == 0) {
sprintf(lookupMethod, "index.b * 64.0 + index.g * 4.0"); // we just skip A.
sprintf(lookupMethod, "(index.a * 128.0 + index.b * 64.0 + index.g * 4.0)"); // we just skip A.
index_multiplier = 1.0f / 256.0f;
// SOCOM case. #16210
} else if ((mask & (mask + 1)) == 0 && shift < 16) {
Expand Down Expand Up @@ -318,10 +322,7 @@ void GenerateDepalShaderFloat(ShaderWriter &writer, const DepalConfig &config) {
// Seems to need a half-pixel offset fix? Might mean it was rendered wrong...
texel_offset += 0.5f / texturePixels;
}
char offset[128] = "";
sprintf(offset, " + %f", texel_offset);

writer.F(" float coord = (%s * %f)%s;\n", lookupMethod, index_multiplier, offset);
writer.F(" float coord = (%s * %f) + %f;\n", lookupMethod, index_multiplier, texel_offset);
writer.C(" vec4 outColor = ").SampleTexture2D("pal", "vec2(coord, 0.0)").C(";\n");
}

Expand Down