Allow auto-probe grid size to be set on the command line

This commit is contained in:
nashmuhandes 2021-10-14 16:56:04 +08:00
parent af83883b40
commit f67852c9a8
2 changed files with 15 additions and 5 deletions

View file

@ -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<std::vector<LightProbeSample>> 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;

View file

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