Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/ModelExtrasAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,5 +437,22 @@ float ME_GetSirenPointLightMul() {
return LightsConfig::Get().fSirenPointLightMul;
}

} // extern "C"
bool ME_GetLightShadowOffset(int modelIndex, const char *dummyName, float *outOffsetX, float *outOffsetY) {
const auto *pJson = DataMgr::Find(modelIndex);
if (!pJson || !pJson->contains("lights") || !dummyName) return false;
const auto &l = (*pJson)["lights"];
if (!l.contains(dummyName)) return false;
const auto &d = l[dummyName];
if (!d.contains("shadow")) return false;
const auto &sh = d["shadow"];
if (!sh.contains("offset") && !sh.contains("shadow_offset")) return false;
const auto &off = sh.contains("offset") ? sh["offset"] : sh["shadow_offset"];
if (off.is_array() && off.size() >= 2) {
if (outOffsetX) *outOffsetX = off[0].get<float>();
if (outOffsetY) *outOffsetY = off[1].get<float>();
return true;
}
return false;
}

} // extern "C"
1 change: 1 addition & 0 deletions src/ModelExtrasAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ extern "C"
// Visual & Render Configuration
ME_WRAPPER float ME_GetPointLightIntensity();
ME_WRAPPER float ME_GetSirenPointLightMul();
ME_WRAPPER bool ME_GetLightShadowOffset(int modelIndex, const char *dummyName, float *outOffsetX, float *outOffsetY);

#ifdef __cplusplus
}
Expand Down
37 changes: 31 additions & 6 deletions src/features/core/dummy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,21 @@ VehicleDummy::VehicleDummy(const DummyConfig& config)
if (jsonData.contains("lights"))
{
std::string newName(name.substr(0, name.find("_prm")));
const char* specKey = LightManager::GetLightSpecificKey(data.lightType);
const char* fallbackKey = LightManager::GetLightGroupKey(data.lightType);
const nlohmann::json* pLightsSec = nullptr;

if (jsonData["lights"].contains(newName))
{
pLightsSec = &jsonData["lights"][newName];
}
else
else if (specKey && jsonData["lights"].contains(specKey))
{
const char* fallbackKey = LightManager::GetLightGroupKey(data.lightType);
if (fallbackKey && jsonData["lights"].contains(fallbackKey))
{
pLightsSec = &jsonData["lights"][fallbackKey];
}
pLightsSec = &jsonData["lights"][specKey];
}
else if (fallbackKey && jsonData["lights"].contains(fallbackKey))
{
pLightsSec = &jsonData["lights"][fallbackKey];
}

if (pLightsSec)
Expand Down Expand Up @@ -125,6 +128,28 @@ VehicleDummy::VehicleDummy(const DummyConfig& config)
data.shadow.texture = shadow.value("texture", "");
data.shadow.rotationChecks = shadow.value("rotationchecks", true);

if (shadow.contains("offset"))
{
const auto &off = shadow["offset"];
if (off.is_number())
{
data.shadow.offset.y = off.get<float>();
}
else if (off.is_object())
{
data.shadow.offset.x = off.value("x", data.shadow.offset.x);
data.shadow.offset.y = off.value("y", data.shadow.offset.y);
}
else if (off.is_array() && off.size() >= 1)
{
data.shadow.offset.x = off[0].get<float>();
if (off.size() >= 2)
{
data.shadow.offset.y = off[1].get<float>();
}
}
}

// shadows will be force enabled if there is JSON data for it.
data.shadow.render = true;
}
Expand Down
7 changes: 5 additions & 2 deletions src/utils/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,11 @@ void RenderUtil::RegisterShadowDirectional(const DummyConfig *pConfig, const std
// Scale shadow size/thickness with inertia factor so it expands/contracts naturally
float currentShdwSz = shdwSz * (0.35f + 0.65f * std::clamp(alphaMul, 0.0f, 1.0f));

// Push shadow forward along light direction
CVector shdwCenter = worldPos + lightDir * (currentShdwSz * SHDW_SZ_MUL + 0.2f);
// Push shadow forward along light direction (with optional JSON shadow.offset: offset.y along lightDir, offset.x along rightDir)
float forwardPush = currentShdwSz * SHDW_SZ_MUL + 0.2f + pConfig->shadow.offset.y;
float sidePush = pConfig->shadow.offset.x;

CVector shdwCenter = worldPos + lightDir * forwardPush + rightDir * sidePush;

CVector2D shdwFront(lightDir.x * (currentShdwSz * SHDW_SZ_MUL), lightDir.y * (currentShdwSz * SHDW_SZ_MUL));
CVector2D shdwSide(rightDir.x * currentShdwSz, rightDir.y * currentShdwSz);
Expand Down