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. --- CONTEXT.md | 13 +++++++++---- src/studio.cpp | 25 +++++++++++++++++++------ src/world.cpp | 4 +++- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/CONTEXT.md b/CONTEXT.md index 1fe24a0..60a5a91 100644 --- a/CONTEXT.md +++ b/CONTEXT.md @@ -287,11 +287,16 @@ vocabulary / decisions. - Uses `IVModelRender::ForcedMaterialOverride` (slot 1) with `models/debug/debugwhite` and draws twice: first with `MATERIAL_VAR_IGNOREZ` (1 << 15) set through `IMaterial::SetMaterialVarFlag` - (slot 29) for the through-wall pass, then without it. `IMaterial:: - ColorModulate` (slot 28) applies the configured colour. The shared material's - flag and colour are restored to (false, white) after the draw. + (slot 29) for the through-wall pass, then without it. Colour is applied via + `IMaterial::ColorModulate` (slot 28) **and** the shader's `$color`/`$color2` + vars (IMaterialVar slot 11, SetVecValue 3-float slot 11), because some forced + materials ignore ColorModulate. The shared material's flag and colour are + restored to (false, white) after the draw. - Material lookup walks the `IMaterialSystem` list (`world_find_material`), with - `FindMaterial` (slot 71) as the fallback for a not-yet-resident material. + `FindMaterial` (slot 71) as the fallback. Candidates, in order: + `models/debug/debugwhite{2,3}`, `vgui/white`, + `debug/debugtranslucentsinglecolor`, `debug/debugwireframevertexcolorignorez`. + The chosen material name is logged. - Feature is off by default; `[chams] active/bind/walls/r/g/b`, with a "Through walls" toggle and colour picker in the Visuals card. - This is a flat material override, not stencil outlines; depth handling is 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