From 8e6efa22610be51391459238a2c5e16d1ff1a060 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 4 Nov 2026 18:37:04 +0100 Subject: Chams: style flags on the resident debug material The base game only has debug/debugtranslucentsinglecolor resident, so the other debug VMTs silently fell back to it and every style looked flat. Use that material for every style and apply material flags instead: FLAT, WIREFRAME, ADDITIVE, and FLAT|SELFILLUM for fullbright; white forces the colour. Flags are cleared after the draw. --- CONTEXT.md | 21 +++++++++------------ src/studio.cpp | 53 ++++++++++++++++++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/CONTEXT.md b/CONTEXT.md index ce79800..72559ac 100644 --- a/CONTEXT.md +++ b/CONTEXT.md @@ -296,20 +296,17 @@ vocabulary / decisions. 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. The **exact requested style** is - tried first (resident, then loaded on demand), and only if that fails does it - fall back to `debug/debugtranslucentsinglecolor`/debugwhite/vgui white. - Styles: 0 Flat (`models/debug/debugwhite`), 1 Wireframe - (`debug/debugwireframe`), 2 Additive (`debug/additivevertexcolorvertexalpha`), - 3 Solid (`debug/debugtranslucentsinglecolor`), 4 White - (`debug/debugtranslucentvertexcolor`), 5 Fullbright - (`debug/debugmrmfullbright2`). The chosen material name is logged. +- The base game does not have the other debug VMTs resident and `FindMaterial` + does not make them available reliably, so all styles use the resident + `debug/debugtranslucentsinglecolor` and differ by material flags: + 0 Flat (`FLAT`), 1 Wireframe (`WIREFRAME`), 2 Additive (`ADDITIVE`), + 3 Solid (none), 4 White (colour forced to white), 5 Fullbright + (`FLAT|SELFILLUM`). Flags are reset after the draw. - `Viewmodel (hands/weapon)` applies the override to entities whose class contains `viewmodel` or whose model path is `.../v_...`. Viewmodels always - use the model-safe solid material (`debug/debugtranslucentsinglecolor`); - VGUI/white materials do not draw skinned models and made the hands/weapon - disappear. Only the normal-depth pass is used. + use the solid style (no style flags) with the selected colour; VGUI/white + materials do not draw skinned models and made the hands/weapon disappear. + Only the normal-depth pass is used. - Feature is off by default; `[chams] active/bind/walls/viewmodel/material/r/g/b`, with Through walls, Viewmodel, a Material dropdown and colour in the Visuals card. diff --git a/src/studio.cpp b/src/studio.cpp index f67936c..1ca8ad7 100644 --- a/src/studio.cpp +++ b/src/studio.cpp @@ -200,14 +200,11 @@ void *g_chams_mat = nullptr; int g_chams_mat_idx = -1; const char *chams_material_name(int idx) { - switch (idx) { - case 1: return "debug/debugwireframe"; - case 2: return "debug/additivevertexcolorvertexalpha"; - case 3: return "debug/debugtranslucentsinglecolor"; - case 4: return "debug/debugtranslucentvertexcolor"; - case 5: return "debug/debugmrmfullbright2"; - default: return "models/debug/debugwhite"; - } + (void)idx; + // Only this debug material is reliably resident in the base game; the other + // debug VMTs are not loaded and FindMaterial does not make them available. + // Visual styles are applied as material flags instead. + return "debug/debugtranslucentsinglecolor"; } void *chams_material() { @@ -248,12 +245,29 @@ void chams_color(void *mat, float r, float g, float b) { vfunc(mat, 28)(mat, r, g, b); } -void chams_apply(void *mat, bool ignorez) { +void chams_apply(void *mat, bool ignorez, int style, bool force_white) { + using FlagFn = void (*)(void *, int, bool); + float r = force_white ? 1.0f : (float)g_chams_rgb[0] / 255.0f; + float g = force_white ? 1.0f : (float)g_chams_rgb[1] / 255.0f; + float b = force_white ? 1.0f : (float)g_chams_rgb[2] / 255.0f; + chams_color(mat, r, g, b); + // 0 Flat, 1 Wireframe, 2 Additive, 3 Solid, 4 White, 5 Fullbright. + vfunc(mat, 29)(mat, 1 << 15 /* IGNOREZ */, ignorez); + vfunc(mat, 29)(mat, 1 << 28 /* WIREFRAME */, style == 1); + vfunc(mat, 29)(mat, 1 << 7 /* ADDITIVE */, style == 2); + vfunc(mat, 29)(mat, 1 << 12 /* FLAT */, + style == 0 || style == 5); + vfunc(mat, 29)(mat, 1 << 6 /* SELFILLUM */, style == 5); +} + +void chams_reset(void *mat) { using FlagFn = void (*)(void *, int, bool); - 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); + vfunc(mat, 29)(mat, 1 << 15, false); + vfunc(mat, 29)(mat, 1 << 28, false); + vfunc(mat, 29)(mat, 1 << 7, false); + vfunc(mat, 29)(mat, 1 << 12, false); + vfunc(mat, 29)(mat, 1 << 6, false); + chams_color(mat, 1.0f, 1.0f, 1.0f); } void hkdModelExecute(void *self, const void *state, const void *info, @@ -269,19 +283,20 @@ void hkdModelExecute(void *self, const void *state, const void *info, if (is_npc || is_vm) { void *mat = is_vm ? viewmodel_material() : chams_material(); if (mat) { + int style = is_vm ? 3 : g_chams_mat_index; + if (style < 0) style = 0; + if (style > 5) style = 5; + bool white = !is_vm && style == 4; if (g_chams_walls && !is_vm) { - chams_apply(mat, true); + chams_apply(mat, true, style, white); g_force_override(self, mat, 0 /* OVERRIDE_NORMAL */); g_orig_model_exec(self, state, info, bone); } - chams_apply(mat, false); + chams_apply(mat, false, style, white); g_force_override(self, mat, 0); g_orig_model_exec(self, state, info, bone); g_force_override(self, nullptr, 0); - // debugwhite is shared: restore colour and depth behaviour. - using FlagFn = void (*)(void *, int, bool); - vfunc(mat, 29)(mat, 1 << 15, false); - chams_color(mat, 1.0f, 1.0f, 1.0f); + chams_reset(mat); return; } } -- cgit v1.2.3