From defa4cafce1f13ecaf7ab6f2aa2dd64d5d3c2656 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 4 Jul 2022 14:48:22 -0400 Subject: [PATCH] remove sky visibility stuff; not necessary with the approx methods show sky hits in light points stats merge surface light stuff (minlight, etc) default surface lights with radiosity to spotlight, to match Q2 --- include/light/light.hh | 3 -- include/light/surflight.hh | 1 + light/bounce.cc | 8 ++---- light/light.cc | 58 +------------------------------------- light/ltface.cc | 31 ++++---------------- light/surflight.cc | 43 ++++++++++++++++++++-------- 6 files changed, 42 insertions(+), 102 deletions(-) diff --git a/include/light/light.hh b/include/light/light.hh index 38076b31..77f11bef 100644 --- a/include/light/light.hh +++ b/include/light/light.hh @@ -145,7 +145,6 @@ struct lightsurf_t the pvs at each of the sample points */ std::vector pvs; - bool skyvisible; /* for sphere culling */ qvec3d origin; @@ -542,8 +541,6 @@ std::vector> &LightSurfaces(); extern std::vector extended_texinfo_flags; -bool Leaf_HasSky(const mbsp_t *bsp, const mleaf_t *leaf); - // public functions void SetGlobalSetting(std::string name, std::string value, bool cmdline); diff --git a/include/light/surflight.hh b/include/light/surflight.hh index 300b342d..2646ef66 100644 --- a/include/light/surflight.hh +++ b/include/light/surflight.hh @@ -46,5 +46,6 @@ struct surfacelight_t }; std::vector &GetSurfaceLights(); +std::optional IsSurfaceLitFace(const mbsp_t *bsp, const mface_t *face); const std::vector &SurfaceLightsForFaceNum(int facenum); void MakeRadiositySurfaceLights(const settings::worldspawn_keys &cfg, const mbsp_t *bsp); diff --git a/light/bounce.cc b/light/bounce.cc index 281aeeb4..e6fb071d 100644 --- a/light/bounce.cc +++ b/light/bounce.cc @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -72,11 +73,8 @@ static bool Face_ShouldBounce(const mbsp_t *bsp, const mface_t *face) } // don't bounce *from* emission surfaces - // FIXME: better way that works for Q1 too - if (bsp->loadversion->game->id == GAME_QUAKE_II) { - if (bsp->texinfo[face->texinfo].flags.native & Q2_SURF_LIGHT) { - return false; - } + if (IsSurfaceLitFace(bsp, face)) { + return false; } return true; diff --git a/light/light.cc b/light/light.cc index 60c8487c..ee54d003 100644 --- a/light/light.cc +++ b/light/light.cc @@ -767,61 +767,6 @@ static void ExportObj(const fs::path &filename, const mbsp_t *bsp) logging::print("Wrote {}\n", filename); } -// obj -static std::vector> faceleafs; -static std::vector leafhassky; - -// index some stuff from the bsp -static void BuildPvsIndex(const mbsp_t *bsp) -{ - // build leafsForFace - faceleafs.resize(bsp->dfaces.size()); - for (size_t i = 0; i < bsp->dleafs.size(); i++) { - const mleaf_t &leaf = bsp->dleafs[i]; - for (int k = 0; k < leaf.nummarksurfaces; k++) { - const int facenum = bsp->dleaffaces[leaf.firstmarksurface + k]; - faceleafs.at(facenum).push_back(&leaf); - } - } - - // build leafhassky - leafhassky.resize(bsp->dleafs.size(), false); - for (size_t i = 0; i < bsp->dleafs.size(); i++) { - const bsp2_dleaf_t &leaf = bsp->dleafs[i]; - - // check for sky, contents check - if (bsp->loadversion->game->contents_are_sky({ leaf.contents })) { - leafhassky.at(i) = true; - continue; - } - - // search for sky faces - for (size_t k = 0; k < leaf.nummarksurfaces; k++) { - const mface_t &surf = bsp->dfaces[bsp->dleaffaces[leaf.firstmarksurface + k]]; - const mtexinfo_t &texinfo = bsp->texinfo[surf.texinfo]; - - if (bsp->loadversion->game->id == GAME_QUAKE_II) { - if (texinfo.flags.native & Q2_SURF_SKY) { - leafhassky.at(i) = true; - } - break; - } - - const char *texname = Face_TextureName(bsp, &surf); - if (!strncmp("sky", texname, 3)) { - leafhassky.at(i) = true; - break; - } - } - } -} - -bool Leaf_HasSky(const mbsp_t *bsp, const mleaf_t *leaf) -{ - const int leafnum = leaf - bsp->dleafs.data(); - return leafhassky.at(leafnum); -} - // returns the face with a centroid nearest the given point. static const mface_t *Face_NearestCentroid(const mbsp_t *bsp, const qvec3f &point) { @@ -1214,8 +1159,7 @@ int light_main(int argc, const char **argv) load_textures(&bsp); CacheTextures(bsp); - - BuildPvsIndex(&bsp); + LoadExtendedTexinfoFlags(source, &bsp); LoadEntities(options, &bsp); diff --git a/light/ltface.cc b/light/ltface.cc index 3d7dcbaf..bc44fd27 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -818,7 +818,6 @@ static void CalcPvs(const mbsp_t *bsp, lightsurf_t *lightsurf) // set defaults lightsurf->pvs.clear(); - lightsurf->skyvisible = true; if (!bsp->dvis.bits.size()) { return; @@ -845,19 +844,6 @@ static void CalcPvs(const mbsp_t *bsp, lightsurf_t *lightsurf) lightsurf->pvs[j] |= pointpvs[j]; } } - - // set lightsurf->skyvisible - lightsurf->skyvisible = false; - for (int i = 0; i < bsp->dleafs.size(); i++) { - const mleaf_t *leaf = &bsp->dleafs[i]; - if (Pvs_LeafVisible(bsp, lightsurf->pvs, leaf)) { - // we can see this leaf, search for sky faces in it - if (Leaf_HasSky(bsp, leaf)) { - lightsurf->skyvisible = true; - break; - } - } - } } static std::unique_ptr Lightsurf_Init( @@ -975,9 +961,7 @@ static std::unique_ptr Lightsurf_Init( lightsurf->occlusion_stream.resize(lightsurf->points.size()); /* Setup vis data */ - if (options.visapprox.value() == visapprox_t::VIS) { - CalcPvs(bsp, lightsurf.get()); - } + CalcPvs(bsp, lightsurf.get()); return lightsurf; } @@ -1547,11 +1531,6 @@ static void LightFace_Entity( */ static void LightFace_Sky(const sun_t *sun, lightsurf_t *lightsurf, lightmapdict_t *lightmaps) { - /* If vis data says we can't see any sky faces, skip raytracing */ - if (!lightsurf->skyvisible) { - return; - } - const settings::worldspawn_keys &cfg = *lightsurf->cfg; const modelinfo_t *modelinfo = lightsurf->modelinfo; const qplane3d *plane = &lightsurf->plane; @@ -1614,6 +1593,8 @@ static void LightFace_Sky(const sun_t *sun, lightsurf_t *lightsurf, lightmapdict lightmap_t *cached_lightmap = Lightmap_ForStyle(lightmaps, cached_style, lightsurf); const int N = rs.numPushedRays(); + total_light_rays += N; + for (int j = 0; j < N; j++) { if (rs.getPushedRayHitType(j) != hittype_t::SKY) { continue; @@ -1645,6 +1626,7 @@ static void LightFace_Sky(const sun_t *sun, lightsurf_t *lightsurf, lightmapdict sample.color += rs.getPushedRayColor(j); sample.direction += rs.getPushedRayNormalContrib(j); + total_light_ray_hits++; Lightmap_Save(lightmaps, lightsurf, cached_lightmap, cached_style); } @@ -3184,9 +3166,8 @@ void DirectLightFace(const mbsp_t *bsp, lightsurf_t &lightsurf, const settings:: } /* minlight - Use Q2 surface light, or the greater of global or model minlight. */ - const mtexinfo_t *texinfo = Face_Texinfo(bsp, face); // mxd. Surface lights... - if (texinfo != nullptr && texinfo->value > 0 && (texinfo->flags.native & Q2_SURF_LIGHT)) { - LightFace_Min(bsp, face, Face_LookupTextureColor(bsp, face), texinfo->value * 2.0f, &lightsurf, + if (auto value = IsSurfaceLitFace(bsp, face)) { + LightFace_Min(bsp, face, Face_LookupTextureColor(bsp, face), *value * 2.0f, &lightsurf, lightmaps); // Playing by the eye here... 2.0 == 256 / 128; 128 is the light value, at which the surface // is renered fullbright, when using arghrad3 } else if (lightsurf.minlight > cfg.minlight.value()) { diff --git a/light/surflight.cc b/light/surflight.cc index 9fa13e52..c41dd954 100644 --- a/light/surflight.cc +++ b/light/surflight.cc @@ -138,6 +138,26 @@ static void MakeSurfaceLight(const mbsp_t *bsp, const settings::worldspawn_keys surfacelightsByFacenum[Face_GetNum(bsp, face)].push_back(index); } +std::optional IsSurfaceLitFace(const mbsp_t *bsp, const mface_t *face) +{ + if (bsp->loadversion->game->id == GAME_QUAKE_II) { + // first, check if it's a Q2 surface + const mtexinfo_t *info = Face_Texinfo(bsp, face); + + if (info != nullptr && (info->flags.native & Q2_SURF_LIGHT) && info->value > 0) { + return info->value; + } + } + + for (const auto &surflight : GetSurfaceLightTemplates()) { + if (FaceMatchesSurfaceLightTemplate(bsp, face, *surflight, SURFLIGHT_RAD)) { + return surflight->light.value(); + } + } + + return std::nullopt; +} + static void MakeSurfaceLightsThread(const mbsp_t *bsp, const settings::worldspawn_keys &cfg, size_t i) { const mface_t *face = BSP_GetFace(bsp, i); @@ -148,18 +168,17 @@ static void MakeSurfaceLightsThread(const mbsp_t *bsp, const settings::worldspaw // first, check if it's a Q2 surface const mtexinfo_t *info = Face_Texinfo(bsp, face); - if (info == nullptr) - return; - - if (!(info->flags.native & Q2_SURF_LIGHT) || info->value == 0) { - if (info->flags.native & Q2_SURF_LIGHT) { - qvec3d wc = winding_t::from_face(bsp, face).center(); - logging::print("WARNING: surface light '{}' at [{}] has 0 intensity.\n", Face_TextureName(bsp, face), wc); + if (info != nullptr) + { + if (!(info->flags.native & Q2_SURF_LIGHT) || info->value == 0) { + if (info->flags.native & Q2_SURF_LIGHT) { + qvec3d wc = winding_t::from_face(bsp, face).center(); + logging::print("WARNING: surface light '{}' at [{}] has 0 intensity.\n", Face_TextureName(bsp, face), wc); + } + } else { + MakeSurfaceLight(bsp, cfg, face, std::nullopt, !(info->flags.native & Q2_SURF_SKY), (info->flags.native & Q2_SURF_SKY), 0, info->value); } - return; } - - MakeSurfaceLight(bsp, cfg, face, std::nullopt, !(info->flags.native & Q2_SURF_SKY), (info->flags.native & Q2_SURF_SKY), 0, info->value); } // check matching templates @@ -168,10 +187,10 @@ static void MakeSurfaceLightsThread(const mbsp_t *bsp, const settings::worldspaw std::optional texture_color; if (surflight->color.isChanged()) { - texture_color = surflight->color.value() / 255.f; + texture_color = surflight->color.value(); } - MakeSurfaceLight(bsp, cfg, face, texture_color, !!surflight->epairs->get_int("_surface_spotlight"), + MakeSurfaceLight(bsp, cfg, face, texture_color, !surflight->epairs->has("_surface_spotlight") ? true : !!surflight->epairs->get_int("_surface_spotlight"), surflight->epairs->get_int("_surface_is_sky"), surflight->epairs->get_int("style"), surflight->light.value()); } }