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
This commit is contained in:
Jonathan 2022-07-04 14:48:22 -04:00
parent 32f33fb4b3
commit defa4cafce
6 changed files with 42 additions and 102 deletions

View File

@ -145,7 +145,6 @@ struct lightsurf_t
the pvs at each of the sample points
*/
std::vector<uint8_t> pvs;
bool skyvisible;
/* for sphere culling */
qvec3d origin;
@ -542,8 +541,6 @@ std::vector<std::unique_ptr<lightsurf_t>> &LightSurfaces();
extern std::vector<surfflags_t> 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);

View File

@ -46,5 +46,6 @@ struct surfacelight_t
};
std::vector<surfacelight_t> &GetSurfaceLights();
std::optional<int32_t> IsSurfaceLitFace(const mbsp_t *bsp, const mface_t *face);
const std::vector<int> &SurfaceLightsForFaceNum(int facenum);
void MakeRadiositySurfaceLights(const settings::worldspawn_keys &cfg, const mbsp_t *bsp);

View File

@ -26,6 +26,7 @@
#include <light/light.hh>
#include <light/bounce.hh>
#include <light/ltface.hh>
#include <light/surflight.hh>
#include <common/polylib.hh>
#include <common/bsputils.hh>
@ -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;

View File

@ -767,61 +767,6 @@ static void ExportObj(const fs::path &filename, const mbsp_t *bsp)
logging::print("Wrote {}\n", filename);
}
// obj
static std::vector<std::vector<const mleaf_t *>> faceleafs;
static std::vector<bool> 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);

View File

@ -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_t> Lightsurf_Init(
@ -975,9 +961,7 @@ static std::unique_ptr<lightsurf_t> 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()) {

View File

@ -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<int32_t> 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<qvec3f> 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());
}
}