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 /src | |
| 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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/studio.cpp | 25 | ||||
| -rw-r--r-- | src/world.cpp | 4 |
2 files changed, 22 insertions, 7 deletions
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); |
