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. --- src/studio.cpp | 53 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 19 deletions(-) (limited to 'src/studio.cpp') 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