allow individual brush chop control

allow passing _surflight_targetname to set targetnames for switchable lights on bmodels
This commit is contained in:
Jonathan 2023-05-08 17:44:32 -04:00
parent b994bb750d
commit 1548f25daf
10 changed files with 43 additions and 6 deletions

View File

@ -1803,7 +1803,7 @@ static auto as_tuple(const surfflags_t &flags)
{
return std::tie(flags.native, flags.is_nodraw, flags.is_hintskip, flags.is_hint, flags.no_dirt, flags.no_shadow,
flags.no_bounce, flags.no_minlight, flags.no_expand, flags.no_phong, flags.light_ignore,
flags.surflight_rescale, flags.surflight_style, flags.surflight_color, flags.surflight_minlight_scale, flags.phong_angle, flags.phong_angle_concave, flags.phong_group, flags.minlight,
flags.surflight_rescale, flags.surflight_style, flags.surflight_targetname, flags.surflight_color, flags.surflight_minlight_scale, flags.phong_angle, flags.phong_angle_concave, flags.phong_group, flags.minlight,
flags.minlight_color, flags.light_alpha, flags.maxlight, flags.lightcolorscale, flags.surflight_group,
flags.world_units_per_luxel, flags.object_channel_mask);
}

View File

@ -195,6 +195,9 @@ struct surfflags_t
// override surface lighting style
std::optional<int32_t> surflight_style;
// override surface lighting targetname
std::optional<std::string> surflight_targetname;
// override the textures' surflight color
std::optional<qvec3b> surflight_color;

View File

@ -107,6 +107,7 @@ public:
int16_t lmshift = 0; /* lightmap scaling (qu/lightmap pixel), passed to the light util */
mapentity_t *func_areaportal = nullptr;
bool is_hint = false; // whether we are a hint brush or not (at least one side is "hint" or SURF_HINT)
bool no_chop = false; // don't chop this
};
struct lumpdata

View File

@ -160,7 +160,7 @@ entdict_t &WorldEnt()
*
* Pass an empty string to generate a new unique lightstyle.
*/
static int LightStyleForTargetname(const settings::worldspawn_keys &cfg, const std::string &targetname)
int LightStyleForTargetname(const settings::worldspawn_keys &cfg, const std::string &targetname)
{
// check if already assigned
for (const auto &pr : lightstyleForTargetname) {

View File

@ -1123,6 +1123,9 @@ static void LoadExtendedTexinfoFlags(const fs::path &sourcefilename, const mbsp_
if (val.contains("surflight_style")) {
flags.surflight_style = val.at("surflight_style").get<int32_t>();
}
if (val.contains("surflight_targetname")) {
flags.surflight_targetname = val.at("surflight_targetname").get<std::string>();
}
if (val.contains("surflight_color")) {
flags.surflight_color = val.at("surflight_color").get<qvec3b>();
}

View File

@ -59,6 +59,8 @@ size_t GetSurflightPoints()
return total_surflight_points;
}
int LightStyleForTargetname(const settings::worldspawn_keys &cfg, const std::string &targetname);
static void MakeSurfaceLight(const mbsp_t *bsp, const settings::worldspawn_keys &cfg, const mface_t *face,
std::optional<qvec3f> texture_color, bool is_directional, bool is_sky, int32_t style, int32_t light_value)
{
@ -138,7 +140,9 @@ static void MakeSurfaceLight(const mbsp_t *bsp, const settings::worldspawn_keys
l.surfnormal = facenormal;
l.omnidirectional = !is_directional;
l.points = std::move(points);
if (extended_flags.surflight_style) {
if (extended_flags.surflight_targetname) {
l.style = LightStyleForTargetname(cfg, extended_flags.surflight_targetname.value());
} else if (extended_flags.surflight_style) {
l.style = extended_flags.surflight_style.value();
} else {
l.style = style;

View File

@ -1434,9 +1434,17 @@ newlist:
auto &b1 = *b1_it;
if (b1->mapbrush->no_chop) {
continue;
}
for (auto b2_it = next; b2_it != list.end(); b2_it++) {
auto &b2 = *b2_it;
if (b2->mapbrush->no_chop) {
continue;
}
if (BrushesDisjoint(*b1, *b2)) {
continue;
}

View File

@ -677,6 +677,8 @@ static surfflags_t SurfFlagsForEntity(
}
if (entity.epairs.has("_surflight_style") && entity.epairs.get_int("_surflight_style") != 0)
flags.surflight_style = entity.epairs.get_int("_surflight_style");
if (entity.epairs.has("_surflight_targetname"))
flags.surflight_targetname = entity.epairs.get("_surflight_targetname");
if (entity.epairs.has("_surflight_minlight_scale"))
flags.surflight_minlight_scale = entity.epairs.get_float("_surflight_minlight_scale");
@ -2931,6 +2933,10 @@ void ProcessAreaPortal(mapentity_t &entity)
}
}
if (map.antiregions.size() || map.region) {
return;
}
entity.areaportalnum = ++map.numareaportals;
// set the portal number as "style"
entity.epairs.set("style", std::to_string(map.numareaportals));
@ -3114,6 +3120,10 @@ void ProcessMapBrushes()
brush.func_areaportal = areaportal;
brush.is_hint = MapBrush_IsHint(brush);
if (entity.epairs.has("_chop") && !entity.epairs.get_int("_chop")) {
brush.no_chop = true;
}
// calculate brush bounds
CalculateBrushBounds(brush);

View File

@ -410,7 +410,7 @@ static void CalcTreeBounds_r(node_t *node, logging::percent_clock &clock)
}
if (node->bounds.mins()[0] >= node->bounds.maxs()[0]) {
logging::print("WARNING: {} without a volume\n", node->is_leaf ? "leaf" : "node");
//logging::print("WARNING: {} without a volume\n", node->is_leaf ? "leaf" : "node");
// fixme-brushbsp: added this to work around leafs with no portals showing up in "qbspfeatures.map" among other
// test maps. Not sure if correct or there's another underlying problem.
@ -615,8 +615,8 @@ static void FloodAreas_r(node_t *node)
// note the current area as bounding the portal
if (entity->portalareas[1]) {
logging::print("WARNING: areaportal entity {} touches > 2 areas\n Entity Bounds: {} -> {}\n",
entity - map.entities.data(), entity->bounds.mins(), entity->bounds.maxs());
logging::print("WARNING: {}: areaportal touches > 2 areas\n Entity Bounds: {} -> {}\n",
entity->location, entity->bounds.mins(), entity->bounds.maxs());
return;
}
@ -924,6 +924,11 @@ void EmitAreaPortals(node_t *headnode)
return;
}
if (map.antiregions.size() || map.region) {
map.bsp.dareas.emplace_back();
return;
}
FindAreas_r(headnode);
SetAreaPortalAreas_r(headnode);

View File

@ -387,6 +387,9 @@ static void WriteExtendedTexinfoFlags(void)
if (tx.flags.surflight_style.has_value()) {
t["surflight_style"] = tx.flags.surflight_style.value();
}
if (tx.flags.surflight_targetname.has_value()) {
t["surflight_targetname"] = tx.flags.surflight_targetname.value();
}
if (tx.flags.surflight_color.has_value()) {
t["surflight_color"] = tx.flags.surflight_color.value();
}