feat(shader): ShaderHandler — SM3.0 body shaders + runtime [Shader] config#5
feat(shader): ShaderHandler — SM3.0 body shaders + runtime [Shader] config#5ALM-OND-S wants to merge 1 commit into
Conversation
b1421fd to
73d14dd
Compare
| HeadlightHotspot=0.15 ; Darkens creases, panel gaps, and concave areas on the car mesh. | ||
| SpecularIntensity=1.0 ; Scales the Blinn-Phong specular highlight from the three directional lights in the game. | ||
| MaskScale=3.75 ; Overall brightness multiplier for the entire overlay. This scales everything together � environment reflection, rim, specular, and headlight contribution. | ||
| ShaderEnable=1 ; Shader toggle. (1 = On, 0 = Off. Default: 1) |
There was a problem hiding this comment.
I wonder if we should have this disabled by default or not.
There was a problem hiding this comment.
Yeah, I think you're right. Should be disabled by default. Will fix it later
| SpecularIntensity=1.0 ; Scales the Blinn-Phong specular highlight from the three directional lights in the game. | ||
| MaskScale=3.75 ; Overall brightness multiplier for the entire overlay. This scales everything together � environment reflection, rim, specular, and headlight contribution. | ||
| ShaderEnable=1 ; Shader toggle. (1 = On, 0 = Off. Default: 1) | ||
| FresnelScale=1 ; Multiplier for the Fresnel reflection effect. A value of 1 provides an accurate Schlick approximation. (Default: 1) |
There was a problem hiding this comment.
Most likely it's tied to the way I did conservation of energy. Mind sharing the exact config?
There was a problem hiding this comment.
Also FYI the value set to 1 = schlick's approximation
There was a problem hiding this comment.
Addressed in c274c90.
On the edge-darkening you flagged: that was the Fresnel being double-counted on top of a flat energy split — the rework moves to a single Fresnel term with a proper kD/kS split, so the rim reads as a reflection gain rather than a darkening.
The bigger picture: I did a fairly large rework and got the body shader pair upgraded to SM3.0, which let me fix a pile of latent issues along the way. I deliberately left the settings open so the community can dial the look in to taste rather than baking my preference in.
The next big step for fuller Physically Based Rendering (PBR) is wiring the specular vector out of the model UVs — but that only pays off if the specular data actually exists in them, which it doesn't today. Doing it properly means re-authoring the specular maps for every model in the game: a massive content pass, not just a shader change. So I've scoped that out for now — but the rework opens the door to it.
Upgrade the in-game vehicle BODY shader pair (0x6486F8 VS / 0x648B38 PS)
from stock SM1.1 to vs_3_0 / ps_3_0, migrating lighting from per-vertex
(VS / fixed-function) to per-pixel (PS). The VS now does geometry + material
only (incl. world incident ray); the PS owns lighting.
Lighting & material:
- Real SM3.0 rep-i0 dynamic light loop (data-driven count); directional
cap bumped 2 -> 3 in sub_5198C0 when the loop consumes a 3rd light.
- PBR-lite: albedo x material, Schlick Fresnel (F0=0.04), kD/kS energy
split, Cook-Torrance direct specular.
- Per-pixel IBL: split-sum + EnvBRDFApprox, texCUBElod roughness LOD,
world-anchored reflection, single-Fresnel. MAX_MIP resolved at runtime
from the bound env cube.
- Projected headlight mask modulates the PBR body.
- Manual in-shader fog (ps_3_0 disables fixed-function fog), fed from a
captured D3DRS_FOGCOLOR.
Engine plumbing:
- Live per-vehicle light forwarding (fixes traffic colour staleness);
CPU-computed world-space light dirs per draw.
- Per-material Specular reaches the PS via a scoped dword_85B34C callback
shim (mode-3 body pass only) instead of a global engine patch.
- Neutralise stale material Diffuse (c11) on body bind for textured bodies.
- Partial light-gather fix (jnz->jz at 0x5181CE).
Other:
- Chrome CubeMapFresnel pair (0x675DF0 / 0x676088) reverted to vanilla
(bytecode stubbed); swap infra retained. Road pixel shaders unchanged.
- [Shader] ini section: ShaderEnable, Reflectance, EnvmapStrength,
MaskScale, SpecularIntensity, HeadlightIntensity.
- Comment cleanup: strip internal version tags / RE-doc references.
73d14dd to
c274c90
Compare

Summary
Adds the
ShaderHandlerand brings the in-game vehicle body shader pair (0x6486F8VS /0x648B38PS) up to Shader Model 3.0, with all visual parameters exposed through a new[Shader]ini section.Shader work
i0light count, and manual fog (ps_3_0 disables fixed-function fog) fed from a capturedD3DRS_FOGCOLOR.c0-c3/ materialc11/ world-space light dirs so the upgraded PS is fed without GPU-flushingGet*ConstantFreads.CubeMapFresnelpair (0x675DF0/0x676088) reverted to vanilla (bytecode stubbed) so the garage/menu preview isn't blown out by the in-game[Shader]params. Re-enable by un-stubbing + re-adding to config.Config (
[Shader]ini section)ShaderEnable,FresnelScale,EnvironmentScale,MaskScale,SpecularIntensity,BodyMaskProjection— all runtime-tunable.Notes
OutputFilepath inmc2hook.vcxprojintentionally left untouched (matchescommunity).