From ccd5256bfacf27ed81fbf13087ba04978d6913f8 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 4 Nov 2026 18:03:09 +0100 Subject: Chams: tint through $color/$color2 and log the chosen material ColorModulate alone left the forced material white. Also set the shader's $color and $color2 vars (IMaterialVar SetVecValue 3-float) and restore them to white after the draw. Log which fallback material was selected. --- src/studio.cpp | 25 +++++++++++++++++++------ src/world.cpp | 4 +++- 2 files changed, 22 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/studio.cpp b/src/studio.cpp index 1b7b77d..d472fbc 100644 --- a/src/studio.cpp +++ b/src/studio.cpp @@ -211,12 +211,26 @@ void *chams_material() { return g_chams_mat; } -void chams_apply(void *mat, bool ignorez) { +void chams_color(void *mat, float r, float g, float b) { using ColorFn = void (*)(void *, float, float, float); + using FindVarFn = void *(*)(void *, const char *, bool *, bool); + using SetVec3Fn = void (*)(void *, float, float, float); + bool found = false; + void *var = vfunc(mat, 11)(mat, "$color", &found, false); + if (var) + vfunc(var, 11)(var, r, g, b); + found = false; + var = vfunc(mat, 11)(mat, "$color2", &found, false); + if (var) + vfunc(var, 11)(var, r, g, b); + vfunc(mat, 28)(mat, r, g, b); +} + +void chams_apply(void *mat, bool ignorez) { using FlagFn = void (*)(void *, int, bool); - vfunc(mat, 28)(mat, (float)g_chams_rgb[0] / 255.0f, - (float)g_chams_rgb[1] / 255.0f, - (float)g_chams_rgb[2] / 255.0f); + chams_color(mat, (float)g_chams_rgb[0] / 255.0f, + (float)g_chams_rgb[1] / 255.0f, + (float)g_chams_rgb[2] / 255.0f); vfunc(mat, 29)(mat, 1 << 15 /* MATERIAL_VAR_IGNOREZ */, ignorez); } @@ -240,10 +254,9 @@ void hkdModelExecute(void *self, const void *state, const void *info, g_orig_model_exec(self, state, info, bone); g_force_override(self, nullptr, 0); // debugwhite is shared: restore colour and depth behaviour. - using ColorFn = void (*)(void *, float, float, float); using FlagFn = void (*)(void *, int, bool); vfunc(mat, 29)(mat, 1 << 15, false); - vfunc(mat, 28)(mat, 1.0f, 1.0f, 1.0f); + chams_color(mat, 1.0f, 1.0f, 1.0f); return; } } diff --git a/src/world.cpp b/src/world.cpp index 15a93ec..284e64e 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -1038,8 +1038,10 @@ void *world_find_material(const char *name) { const char *n = mat_name(mat); if (n) { for (int c = 0; candidates[c]; c++) - if (strcmp(n, candidates[c]) == 0) + if (strcmp(n, candidates[c]) == 0) { + logf("chams: material %s = %p", n, mat); return mat; + } } } h = next(ms, h); -- cgit v1.2.3