Skip to content

feat(shader): ShaderHandler — SM3.0 body shaders + runtime [Shader] config#5

Open
ALM-OND-S wants to merge 1 commit into
jtxredline:communityfrom
ALM-OND-S:feat/shader-handler
Open

feat(shader): ShaderHandler — SM3.0 body shaders + runtime [Shader] config#5
ALM-OND-S wants to merge 1 commit into
jtxredline:communityfrom
ALM-OND-S:feat/shader-handler

Conversation

@ALM-OND-S

@ALM-OND-S ALM-OND-S commented Jun 17, 2026

Copy link
Copy Markdown

Summary

Adds the ShaderHandler and brings the in-game vehicle body shader pair (0x6486F8 VS / 0x648B38 PS) up to Shader Model 3.0, with all visual parameters exposed through a new [Shader] ini section.

Shader work

  • Body VS/PS → vs_3_0 / ps_3_0 with world-anchored IBL (single-Fresnel), a real per-light loop driven by the engine's i0 light count, and manual fog (ps_3_0 disables fixed-function fog) fed from a captured D3DRS_FOGCOLOR.
  • Caches VS c0-c3 / material c11 / world-space light dirs so the upgraded PS is fed without GPU-flushing Get*ConstantF reads.
  • Chrome CubeMapFresnel pair (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

  • Bytecode swaps happen at shader-creation time → zero per-frame overhead for the swap itself.
  • Local build OutputFile path in mc2hook.vcxproj intentionally left untouched (matches community).

@ALM-OND-S ALM-OND-S force-pushed the feat/shader-handler branch from b1421fd to 73d14dd Compare June 17, 2026 20:11
Comment thread mc2hook/mc2hook/mc2hook.ini Outdated
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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should have this disabled by default or not.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think you're right. Should be disabled by default. Will fix it later

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in c274c90

Comment thread mc2hook/mc2hook/mc2hook.ini Outdated
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)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumping this up just to see the effect in-game, it seems to darken the edges instead of brighten, unless this was your intent?

Image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely it's tied to the way I did conservation of energy. Mind sharing the exact config?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also FYI the value set to 1 = schlick's approximation

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@ALM-OND-S ALM-OND-S force-pushed the feat/shader-handler branch from 73d14dd to c274c90 Compare June 28, 2026 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants