From f67852c9a810a18b81617283b8edd674485bb5ad Mon Sep 17 00:00:00 2001 From: nashmuhandes Date: Thu, 14 Oct 2021 16:56:04 +0800 Subject: [PATCH] Allow auto-probe grid size to be set on the command line --- src/lightmap/lightmap.cpp | 10 +++++----- src/main.cpp | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/lightmap/lightmap.cpp b/src/lightmap/lightmap.cpp index 78f20c2..0a210f3 100644 --- a/src/lightmap/lightmap.cpp +++ b/src/lightmap/lightmap.cpp @@ -46,6 +46,7 @@ extern int Multisample; extern int LightBounce; +extern float GridSize; LightmapBuilder::LightmapBuilder() { @@ -644,16 +645,15 @@ void LightmapBuilder::CreateLightProbes() float maxX = std::floor(map->MaxX / 65536.0f) + 1.0f; float maxY = std::floor(map->MaxY / 65536.0f) + 1.0f; - float gridSize = 32.0f; - float halfGridSize = gridSize * 0.5f; + float halfGridSize = GridSize * 0.5f; std::vector> probes; // order probes by subsector probes.resize(map->NumGLSubsectors); size_t totalProbes = 0; - for (float y = minY; y < maxY; y += gridSize) + for (float y = minY; y < maxY; y += GridSize) { - for (float x = minX; x < maxX; x += gridSize) + for (float x = minX; x < maxX; x += GridSize) { MapSubsectorEx* ssec = map->PointInSubSector((int)x, (int)y); IntSector* sec = ssec ? map->GetSectorFromSubSector(ssec) : nullptr; @@ -662,7 +662,7 @@ void LightmapBuilder::CreateLightProbes() float z0 = sec->floorplane.zAt(x, y); float z1 = sec->ceilingplane.zAt(x, y); float startZ = (z1 - z0 < halfGridSize) ? (z0 + z1) * 0.5f : z0 + halfGridSize; - for (float z = startZ; z < z1; z += gridSize) + for (float z = startZ; z < z1; z += GridSize) { LightProbeSample probe; probe.Position.x = x; diff --git a/src/main.cpp b/src/main.cpp index 6654c15..1abf9ab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -118,6 +118,7 @@ int LMDims = 1024; int Samples = 8; int Multisample = 1; int LightBounce = 0; +float GridSize = 32.0f; // PRIVATE DATA DEFINITIONS ------------------------------------------------ @@ -157,6 +158,7 @@ static option long_opts[] = {"size", required_argument, 0, 'S'}, {"multisample", required_argument, 0, 'M'}, {"bounce", required_argument, 0, 'B'}, + {"gridsize", required_argument, 0, 'i'}, {0,0,0,0} }; @@ -457,6 +459,10 @@ static void ParseArgs(int argc, char **argv) if (LightBounce < 0) LightBounce = 0; if (LightBounce > 1) LightBounce = 1; break; + case 'i': + GridSize = std::stof(optarg); + if (GridSize < 0.f) GridSize = 0.f; + break; case 1000: ShowUsage(); exit(0); @@ -505,6 +511,9 @@ static void ShowUsage() " must be in powers of two (1, 2, 4, 8, 16, etc)\n" " -M, --multisample=NNN Number of samples to use per texel (default %d)\n" " -B, --bounce=NNN Number of indirect light bounces (default %d, max 1)\n" + " -i, --gridsize=NNN Automatic light probe grid size, floating point\n" + " Lower values increase granularity at the expense of performance\n" + " Recommended: 32.0, 64.0, 128.0, etc (default %.1f)\n" " -w, --warn Show warning messages\n" #if HAVE_TIMING " -t, --no-timing Suppress timing information\n" @@ -520,6 +529,7 @@ static void ShowUsage() , (int)std::thread::hardware_concurrency() , Multisample , LightBounce + , GridSize ); }