diff --git a/Client/game_sa/CRendererSA.cpp b/Client/game_sa/CRendererSA.cpp index bad607d5ba2..04face62482 100644 --- a/Client/game_sa/CRendererSA.cpp +++ b/Client/game_sa/CRendererSA.cpp @@ -15,6 +15,9 @@ #include "CMatrix.h" #include "gamesa_renderware.h" +#define SetLightColoursForPedsCarsAndObjects(fMult) ((RpLight*(__cdecl*)(float))0x735D90)(fMult) +#define SetAmbientColours() ((RpLight*(__cdecl*)())0x735D30)() + CRendererSA::CRendererSA() { } @@ -23,7 +26,7 @@ CRendererSA::~CRendererSA() { } -void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix) +void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting) { CBaseModelInfoSAInterface* pModelInfoSAInterface = pModelInfo->GetInterface(); if (!pModelInfoSAInterface) @@ -40,7 +43,10 @@ void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix) rwMatrix.up = (RwV3d&)matrix.vFront; rwMatrix.at = (RwV3d&)matrix.vUp; rwMatrix.pos = (RwV3d&)matrix.vPos; - RwFrameTransform(pFrame, &rwMatrix, rwCOMBINEREPLACE); + RwFrameTransform(pFrame, &rwMatrix, rwCOMBINEREPLACE); + + // Setup ambient light multiplier + SetLightColoursForPedsCarsAndObjects(lighting); if (pRwObject->type == RP_TYPE_ATOMIC) { @@ -52,4 +58,7 @@ void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix) RpClump* pClump = reinterpret_cast(pRwObject); RpClumpRender(pClump); } + + // Restore ambient light + SetAmbientColours(); } diff --git a/Client/game_sa/CRendererSA.h b/Client/game_sa/CRendererSA.h index e71a83665ed..eb09edae721 100644 --- a/Client/game_sa/CRendererSA.h +++ b/Client/game_sa/CRendererSA.h @@ -19,5 +19,5 @@ class CRendererSA : public CRenderer CRendererSA(); ~CRendererSA(); - void RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix) override; + void RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting) override; }; diff --git a/Client/mods/deathmatch/logic/CModelRenderer.cpp b/Client/mods/deathmatch/logic/CModelRenderer.cpp index 2f06c836ec8..ed05fa4ae42 100644 --- a/Client/mods/deathmatch/logic/CModelRenderer.cpp +++ b/Client/mods/deathmatch/logic/CModelRenderer.cpp @@ -13,14 +13,14 @@ #include "game\CRenderer.h" #include "game\CVisibilityPlugins.h" -bool CModelRenderer::EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix) +bool CModelRenderer::EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting) { if (g_pCore->IsWindowMinimized()) return false; if (pModelInfo && pModelInfo->IsLoaded()) { - m_Queue.emplace_back(pModelInfo, matrix); + m_Queue.emplace_back(pModelInfo, matrix, lighting); return true; } @@ -54,7 +54,7 @@ void CModelRenderer::Render() for (auto& modelDesc : m_Queue) { if (modelDesc.pModelInfo->IsLoaded() && !modelDesc.pModelInfo->GetIdeFlag(eModelIdeFlag::DRAW_LAST)) - pRenderer->RenderModel(modelDesc.pModelInfo, modelDesc.matrix); + pRenderer->RenderModel(modelDesc.pModelInfo, modelDesc.matrix, modelDesc.lighting); } m_Queue.clear(); @@ -68,5 +68,5 @@ void CModelRenderer::RenderEntity(SModelToRender* modelDesc, float distance) CRenderer* pRenderer = g_pGame->GetRenderer(); assert(pRenderer); - pRenderer->RenderModel(modelDesc->pModelInfo, modelDesc->matrix); + pRenderer->RenderModel(modelDesc->pModelInfo, modelDesc->matrix, modelDesc->lighting); } diff --git a/Client/mods/deathmatch/logic/CModelRenderer.h b/Client/mods/deathmatch/logic/CModelRenderer.h index d923db6c7f8..a2dba3030b0 100644 --- a/Client/mods/deathmatch/logic/CModelRenderer.h +++ b/Client/mods/deathmatch/logic/CModelRenderer.h @@ -18,15 +18,17 @@ class CModelRenderer final { CModelInfo* pModelInfo; CMatrix matrix; + float lighting; - SModelToRender(CModelInfo* pModelInfo, const CMatrix& matrix) : + SModelToRender(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting = 0.0f) : pModelInfo(pModelInfo), - matrix(matrix) + matrix(matrix), + lighting(lighting) { } }; - bool EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix); + bool EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting); void Update(); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp index f54378944de..adc83a12249 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp @@ -2123,7 +2123,7 @@ bool CLuaDrawingDefs::DxDrawWiredSphere(lua_State* const luaVM, const CVector po return true; } -bool CLuaDrawingDefs::DxDrawModel3D(std::uint32_t modelID, CVector position, CVector rotation, const std::optional scale) +bool CLuaDrawingDefs::DxDrawModel3D(std::uint32_t modelID, CVector position, CVector rotation, const std::optional scale, const std::optional lighting) { CModelInfo* pModelInfo = g_pGame->GetModelInfo(modelID); if (!pModelInfo) @@ -2138,5 +2138,5 @@ bool CLuaDrawingDefs::DxDrawModel3D(std::uint32_t modelID, CVector position, CVe ConvertDegreesToRadians(rotation); return g_pClientGame->GetModelRenderer()->EnqueueModel(pModelInfo, - CMatrix{position, rotation, scale.value_or(CVector{1.0f, 1.0f, 1.0f})}); + CMatrix{position, rotation, scale.value_or(CVector{1.0f, 1.0f, 1.0f})}, lighting.value_or(0.0f)); } diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.h index 55dc3adda17..d01d6ec214b 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.h @@ -82,7 +82,7 @@ class CLuaDrawingDefs : public CLuaDefs static bool DxDrawWiredSphere(lua_State* const luaVM, const CVector position, const float radius, const std::optional color, const std::optional lineWidth, const std::optional iterations); - static bool DxDrawModel3D(std::uint32_t modelID, CVector position, CVector rotation, const std::optional scale); + static bool DxDrawModel3D(std::uint32_t modelID, CVector position, CVector rotation, const std::optional scale, const std::optional lighting); private: static void AddDxMaterialClass(lua_State* luaVM); diff --git a/Client/sdk/game/CRenderer.h b/Client/sdk/game/CRenderer.h index 65d6a8bdcaf..19a94652249 100644 --- a/Client/sdk/game/CRenderer.h +++ b/Client/sdk/game/CRenderer.h @@ -19,5 +19,5 @@ class CRenderer public: virtual ~CRenderer() {} - virtual void RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix) = 0; + virtual void RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting) = 0; };