fix _cone in Q2

This commit is contained in:
Jonathan 2023-01-08 20:03:06 -05:00
parent ff09b4c31e
commit df5f894726
3 changed files with 27 additions and 9 deletions

View File

@ -73,6 +73,7 @@ public:
settings::setting_scalar light;
settings::setting_scalar atten;
settings::setting_enum<light_formula_t> formula;
settings::setting_scalar cone; // Q2
settings::setting_scalar spotangle;
settings::setting_scalar spotangle2;
settings::setting_numeric<int32_t> style;

View File

@ -80,7 +80,8 @@ light_t::light_t() :
formula{this, "delay", LF_LINEAR,
{{"linear", LF_LINEAR}, {"inverse", LF_INVERSE}, {"inverse2", LF_INVERSE2}, {"infinite", LF_INFINITE},
{"localmin", LF_LOCALMIN}, {"inverse2a", LF_INVERSE2A}}},
spotangle{this, {"angle", "cone"}, 40.0},
cone{this, {"cone"}, 10.f},
spotangle{this, "angle", 40.0},
spotangle2{this, "softangle", 0.0},
style{this, "style", 0, 0, INVALID_LIGHTSTYLE - 1},
anglescale{this, {"anglesense", "anglescale"}, -1.0},
@ -106,7 +107,7 @@ light_t::light_t() :
suntexture{this, "suntexture", ""},
nostaticlight{this, "nostaticlight", false},
surflight_group{this, "surflight_group", 0},
surface_minlight_scale{this, "surface_minlight_scale", 64},
surface_minlight_scale{this, "surface_minlight_scale", 64.f},
light_channel_mask{this, "light_channel_mask", CHANNEL_MASK_DEFAULT},
shadow_channel_mask{this, "shadow_channel_mask", CHANNEL_MASK_DEFAULT},
nonudge{this, "nonudge", false}
@ -246,17 +247,33 @@ static void SetupSpotlights(const settings::worldspawn_keys &cfg)
entity->spotlight = true;
}
if (entity->spotlight) {
const vec_t angle = (entity->spotangle.value() > 0) ? entity->spotangle.value() : 40;
entity->spotfalloff = -cos(angle / 2 * Q_PI / 180);
vec_t base_angle;
if (entity->cone.isChanged()) {
base_angle = entity->cone.value() * 2.f;
if (!base_angle) {
base_angle = 10.f;
}
} else {
base_angle = entity->spotangle.value();
if (!base_angle) {
base_angle = 40.f;
}
}
entity->spotfalloff = -cos(base_angle / 2 * Q_PI / 180);
vec_t angle2 = entity->spotangle2.value();
if (angle2 <= 0 || angle2 > angle)
angle2 = angle;
if (angle2 <= 0 || angle2 > base_angle)
angle2 = base_angle;
entity->spotfalloff2 = -cos(angle2 / 2 * Q_PI / 180);
// mxd. Apply autofalloff?
if (targetdist > 0.0f && entity->falloff.value() == 0 && cfg.spotlightautofalloff.value()) {
const vec_t coneradius = targetdist * tan(angle / 2 * Q_PI / 180);
const vec_t coneradius = targetdist * tan(base_angle / 2 * Q_PI / 180);
entity->falloff.setValue(targetdist + coneradius, settings::source::MAP);
}
}
@ -308,7 +325,7 @@ static void CheckEntityFields(const mbsp_t *bsp, const settings::worldspawn_keys
if (!entity->surface_minlight_scale.isChanged()) {
if (bsp->loadversion->game->id != GAME_QUAKE_II) {
// TODO: also use 1.0 for Q2?
entity->surface_minlight_scale.setValue(1.0, settings::source::DEFAULT);
entity->surface_minlight_scale.setValue(64.f, settings::source::DEFAULT);
}
}
}

View File

@ -3016,7 +3016,7 @@ void DirectLightFace(const mbsp_t *bsp, lightsurf_t &lightsurf, const settings::
if (auto value = IsSurfaceLitFace(bsp, face)) {
auto *entity = std::get<3>(value.value());
const float surface_minlight_scale = entity ? entity->surface_minlight_scale.value() : 64.0f;
const float surface_minlight_scale = entity ? entity->surface_minlight_scale.value() : 64.f;
minlight = std::get<0>(value.value()) * surface_minlight_scale;
minlight_color = std::get<2>(value.value());
LightFace_Min(bsp, face, minlight_color, minlight, &lightsurf, lightmaps, std::get<1>(value.value()));