Skip to content

Commit 210e362

Browse files
authored
Fix vehicle headlights not lighting other vehicles (multitheftauto#5074)
#### Summary Move the vehicle specular light from direct3d slot 1 to slot 7. Slot 1 is also used for the first temporary directional light, so the vehicle pipeline was overwriting the incoming headlights before render the vehicle. Slot 7 is also added in common `LIGHT*` shader parameters to not break custom shaders. #### Motivation Fixes multitheftauto#4636. #### Test plan I reproduced the same scenario as in the issue video. The video below shows the result after the fix. https://github.com/user-attachments/assets/01866dac-b1d3-43ee-b65c-5122e9c7f15b #### Checklist * [x] Your code should follow the [coding guidelines](https://wiki.multitheftauto.com/index.php?title=Coding_guidelines). * [x] Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit. Co-authored-by: Dryxio <215281400+Dryxio@users.noreply.github.com>
1 parent 6900903 commit 210e362

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

Client/core/Graphics/CRenderItem.EffectParameters.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,13 +579,17 @@ bool CEffectParameters::ApplyCommonHandles()
579579
D3DXCOLOR strongestDiffuse(0, 0, 0, 0);
580580
D3DXCOLOR strongestSpecular(0, 0, 0, 0);
581581
D3DXVECTOR3 strongestDirection(0, 0, -1);
582-
for (uint i = 0; i < 4; i++)
582+
// The vehicle pipeline reserves slot 7 for its specular directional
583+
// light. Include it without broadening the existing selection of GTA's
584+
// temporary world lights in slots 0 through 3.
585+
constexpr DWORD COMMON_EFFECT_LIGHT_SLOTS[] = {0, 1, 2, 3, 7};
586+
for (const DWORD lightSlot : COMMON_EFFECT_LIGHT_SLOTS)
583587
{
584588
BOOL bEnabled;
585-
if (SUCCEEDED(pDevice->GetLightEnable(i, &bEnabled)) && bEnabled)
589+
if (SUCCEEDED(pDevice->GetLightEnable(lightSlot, &bEnabled)) && bEnabled)
586590
{
587591
D3DLIGHT9 D3DLight;
588-
pDevice->GetLight(i, &D3DLight);
592+
pDevice->GetLight(lightSlot, &D3DLight);
589593
if (D3DLight.Type == D3DLIGHT_DIRECTIONAL)
590594
{
591595
totalAmbient += D3DLight.Ambient;

Client/multiplayer_sa/CMultiplayerSA_Rendering.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,15 @@ static void __declspec(naked) HOOK_CRenderer_EverythingBarRoads()
936936
//////////////////////////////////////////////////////////////////////////////////////////
937937
void CMultiplayerSA::InitHooks_Rendering()
938938
{
939+
// GTA assigns main-world temporary directional lights to slots 1 through 6,
940+
// but the vehicle env-map pipeline overwrites slot 1 with its specular light.
941+
// Reserve slot 7 for the specular light so headlights can illuminate vehicle
942+
// materials without being discarded immediately before the draw.
943+
constexpr BYTE VEHICLE_SPECULAR_LIGHT_SLOT = 7;
944+
MemPut<BYTE>(0x5D9A88, VEHICLE_SPECULAR_LIGHT_SLOT); // RwD3D9SetLight
945+
MemPut<BYTE>(0x5D9A91, VEHICLE_SPECULAR_LIGHT_SLOT); // RwD3D9EnableLight(TRUE)
946+
MemPut<BYTE>(0x5D9F1F, VEHICLE_SPECULAR_LIGHT_SLOT); // RwD3D9EnableLight(FALSE)
947+
939948
EZHookInstall(CallIdle);
940949
EZHookInstall(CEntity_Render);
941950
EZHookInstall(CEntity_RenderOneNonRoad);

0 commit comments

Comments
 (0)