diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-04 18:03:09 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-04 18:03:09 +0100 |
| commit | ccd5256bfacf27ed81fbf13087ba04978d6913f8 (patch) | |
| tree | 8729b2e3e9bc7a43c1babb0376ea8b67fb5c9af5 | |
| parent | Chams: material fallbacks and FindMaterial diagnostics (diff) | |
| download | hl2h-ccd5256bfacf27ed81fbf13087ba04978d6913f8.tar.gz hl2h-ccd5256bfacf27ed81fbf13087ba04978d6913f8.zip | |
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.
| -rw-r--r-- | CONTEXT.md | 13 | ||||
| -rw-r--r-- | src/studio.cpp | 25 | ||||
| -rw-r--r-- | src/world.cpp | 4 |
3 files changed, 31 insertions, 11 deletions
| @@ -287,11 +287,16 @@ vocabulary / decisions. | |||
| 287 | - Uses `IVModelRender::ForcedMaterialOverride` (slot 1) with | 287 | - Uses `IVModelRender::ForcedMaterialOverride` (slot 1) with |
| 288 | `models/debug/debugwhite` and draws twice: first with | 288 | `models/debug/debugwhite` and draws twice: first with |
| 289 | `MATERIAL_VAR_IGNOREZ` (1 << 15) set through `IMaterial::SetMaterialVarFlag` | 289 | `MATERIAL_VAR_IGNOREZ` (1 << 15) set through `IMaterial::SetMaterialVarFlag` |
| 290 | (slot 29) for the through-wall pass, then without it. `IMaterial:: | 290 | (slot 29) for the through-wall pass, then without it. Colour is applied via |
| 291 | ColorModulate` (slot 28) applies the configured colour. The shared material's | 291 | `IMaterial::ColorModulate` (slot 28) **and** the shader's `$color`/`$color2` |
| 292 | flag and colour are restored to (false, white) after the draw. | 292 | vars (IMaterialVar slot 11, SetVecValue 3-float slot 11), because some forced |
| 293 | materials ignore ColorModulate. The shared material's flag and colour are | ||
| 294 | restored to (false, white) after the draw. | ||
| 293 | - Material lookup walks the `IMaterialSystem` list (`world_find_material`), with | 295 | - Material lookup walks the `IMaterialSystem` list (`world_find_material`), with |
| 294 | `FindMaterial` (slot 71) as the fallback for a not-yet-resident material. | 296 | `FindMaterial` (slot 71) as the fallback. Candidates, in order: |
| 297 | `models/debug/debugwhite{2,3}`, `vgui/white`, | ||
| 298 | `debug/debugtranslucentsinglecolor`, `debug/debugwireframevertexcolorignorez`. | ||
| 299 | The chosen material name is logged. | ||
| 295 | - Feature is off by default; `[chams] active/bind/walls/r/g/b`, with a | 300 | - Feature is off by default; `[chams] active/bind/walls/r/g/b`, with a |
| 296 | "Through walls" toggle and colour picker in the Visuals card. | 301 | "Through walls" toggle and colour picker in the Visuals card. |
| 297 | - This is a flat material override, not stencil outlines; depth handling is | 302 | - 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() { | |||
| 211 | return g_chams_mat; | 211 | return g_chams_mat; |
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | void chams_apply(void *mat, bool ignorez) { | 214 | void chams_color(void *mat, float r, float g, float b) { |
| 215 | using ColorFn = void (*)(void *, float, float, float); | 215 | using ColorFn = void (*)(void *, float, float, float); |
| 216 | using FindVarFn = void *(*)(void *, const char *, bool *, bool); | ||
| 217 | using SetVec3Fn = void (*)(void *, float, float, float); | ||
| 218 | bool found = false; | ||
| 219 | void *var = vfunc<FindVarFn>(mat, 11)(mat, "$color", &found, false); | ||
| 220 | if (var) | ||
| 221 | vfunc<SetVec3Fn>(var, 11)(var, r, g, b); | ||
| 222 | found = false; | ||
| 223 | var = vfunc<FindVarFn>(mat, 11)(mat, "$color2", &found, false); | ||
| 224 | if (var) | ||
| 225 | vfunc<SetVec3Fn>(var, 11)(var, r, g, b); | ||
| 226 | vfunc<ColorFn>(mat, 28)(mat, r, g, b); | ||
| 227 | } | ||
| 228 | |||
| 229 | void chams_apply(void *mat, bool ignorez) { | ||
| 216 | using FlagFn = void (*)(void *, int, bool); | 230 | using FlagFn = void (*)(void *, int, bool); |
| 217 | vfunc<ColorFn>(mat, 28)(mat, (float)g_chams_rgb[0] / 255.0f, | 231 | chams_color(mat, (float)g_chams_rgb[0] / 255.0f, |
| 218 | (float)g_chams_rgb[1] / 255.0f, | 232 | (float)g_chams_rgb[1] / 255.0f, |
| 219 | (float)g_chams_rgb[2] / 255.0f); | 233 | (float)g_chams_rgb[2] / 255.0f); |
| 220 | vfunc<FlagFn>(mat, 29)(mat, 1 << 15 /* MATERIAL_VAR_IGNOREZ */, ignorez); | 234 | vfunc<FlagFn>(mat, 29)(mat, 1 << 15 /* MATERIAL_VAR_IGNOREZ */, ignorez); |
| 221 | } | 235 | } |
| 222 | 236 | ||
| @@ -240,10 +254,9 @@ void hkdModelExecute(void *self, const void *state, const void *info, | |||
| 240 | g_orig_model_exec(self, state, info, bone); | 254 | g_orig_model_exec(self, state, info, bone); |
| 241 | g_force_override(self, nullptr, 0); | 255 | g_force_override(self, nullptr, 0); |
| 242 | // debugwhite is shared: restore colour and depth behaviour. | 256 | // debugwhite is shared: restore colour and depth behaviour. |
| 243 | using ColorFn = void (*)(void *, float, float, float); | ||
| 244 | using FlagFn = void (*)(void *, int, bool); | 257 | using FlagFn = void (*)(void *, int, bool); |
| 245 | vfunc<FlagFn>(mat, 29)(mat, 1 << 15, false); | 258 | vfunc<FlagFn>(mat, 29)(mat, 1 << 15, false); |
| 246 | vfunc<ColorFn>(mat, 28)(mat, 1.0f, 1.0f, 1.0f); | 259 | chams_color(mat, 1.0f, 1.0f, 1.0f); |
| 247 | return; | 260 | return; |
| 248 | } | 261 | } |
| 249 | } | 262 | } |
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) { | |||
| 1038 | const char *n = mat_name(mat); | 1038 | const char *n = mat_name(mat); |
| 1039 | if (n) { | 1039 | if (n) { |
| 1040 | for (int c = 0; candidates[c]; c++) | 1040 | for (int c = 0; candidates[c]; c++) |
| 1041 | if (strcmp(n, candidates[c]) == 0) | 1041 | if (strcmp(n, candidates[c]) == 0) { |
| 1042 | logf("chams: material %s = %p", n, mat); | ||
| 1042 | return mat; | 1043 | return mat; |
| 1044 | } | ||
| 1043 | } | 1045 | } |
| 1044 | } | 1046 | } |
| 1045 | h = next(ms, h); | 1047 | h = next(ms, h); |
