Harden the model custom color check

This commit is contained in:
yvt 2019-05-25 12:18:32 +09:00
parent 4ffd817056
commit b10c943eed
No known key found for this signature in database
GPG Key ID: 48F2768FA8D07C92

View File

@ -18,7 +18,9 @@
*/
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include "CTFGameMode.h"
@ -106,15 +108,31 @@ namespace spades {
}
}
void RenderModel(IModel *model, const ModelRenderParam &p) {
void RenderModel(IModel *model, const ModelRenderParam &_p) {
ModelRenderParam p = _p;
if (!model) {
SPInvalidArgument("model");
return;
}
if (p.depthHack && !allowDepthHack) {
OnProhibitedAction();
return;
}
// Overbright surfaces bypass the fog
p.customColor.x = std::max(std::min(p.customColor.x, 1.0f), 0.0f);
p.customColor.y = std::max(std::min(p.customColor.y, 1.0f), 0.0f);
p.customColor.z = std::max(std::min(p.customColor.z, 1.0f), 0.0f);
// NaN values bypass the fog
if (std::isnan(p.customColor.x) || std::isnan(p.customColor.y) ||
std::isnan(p.customColor.z)) {
OnProhibitedAction();
return;
}
auto bounds = (p.matrix * OBB3(model->GetBoundingBox())).GetBoundingAABB();
if (CheckVisibility(bounds)) {
base->RenderModel(model, p);