MCPcopy Create free account
hub / github.com/TheRealMJP/BakingLab / BakeDriver

Function BakeDriver

BakingLab/MeshBaker.cpp:468–663  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

466// Otherwise, it will completely bake a single texel within a bake group and flood fill
467// its unbaked neighbors within the thread group.
468template<typename TBaker> static bool BakeDriver(BakeThreadContext& context, TBaker& baker)
469{
470 if(context.CurrNumBatches == 0)
471 return false;
472
473 const uint64 batchIdx = InterlockedIncrement64(context.CurrBatch) - 1;
474 if(batchIdx >= context.CurrNumBatches)
475 return false;
476
477 // Are we baking one sample per texel and progessively integrating, or are we going to
478 // fully compute the final baked texel value and flood fill the neighbors?
479 const bool progressiveintegration = AppSettings::SupportsProgressiveIntegration(context.CurrBakeMode, context.CurrSolveMode);
480
481 // Figure out which 8x8 group we're working on
482 const uint64 numGroupsX = (context.CurrLightMapSize + (BakeGroupSizeX - 1)) / BakeGroupSizeX;
483 const uint64 numGroupsY = (context.CurrLightMapSize + (BakeGroupSizeY - 1)) / BakeGroupSizeY;
484 const uint64 numBakeGroups = numGroupsX * numGroupsY;
485
486 const uint64 groupIdx = batchIdx % numBakeGroups;
487 const uint64 groupIdxX = groupIdx % numGroupsX;
488 const uint64 groupIdxY = groupIdx / numGroupsX;
489
490 const uint64 sqrtNumSamples = context.CurrNumSamples;
491 const uint64 numSamplesPerTexel = sqrtNumSamples * sqrtNumSamples;
492
493 Random& random = context.RandomGenerator;
494
495 const bool addAreaLight = AppSettings::EnableAreaLight && AppSettings::BakeDirectAreaLight;
496
497 // Get the set of integration samples to use, which is tiled across threads
498 const uint64 numThreads = context.Samples->size();
499 const IntegrationSamples& integrationSamples = (*context.Samples)[groupIdx % numThreads];
500
501 PathTracerParams params;
502 params.EnableDirectAreaLight = false;
503 params.EnableDirectSun = false;
504 params.EnableDiffuse = true;
505 params.EnableSpecular = false;
506 params.EnableBounceSpecular = false;
507 params.MaxPathLength = AppSettings::MaxBakePathLength;
508 params.RussianRouletteDepth = AppSettings::BakeRussianRouletteDepth;
509 params.RussianRouletteProbability = AppSettings::BakeRussianRouletteProbability;
510 params.RayLen = FLT_MAX;
511 params.SceneBVH = context.SceneBVH;
512 params.SkyCache = &context.SkyCache;
513 params.EnvMaps = context.EnvMaps;
514
515 if(progressiveintegration)
516 {
517 const uint64 sampleIdx = batchIdx / numBakeGroups;
518
519 // Loop over all texels in the 8x8 group, and compute 1 sample for each
520 for(uint64 groupTexelIdxX = 0; groupTexelIdxX < BakeGroupSizeX; ++groupTexelIdxX)
521 {
522 for(uint64 groupTexelIdxY = 0; groupTexelIdxY < BakeGroupSizeY; ++groupTexelIdxY)
523 {
524 const uint64 groupTexelIdx = groupTexelIdxY * BakeGroupSizeX + groupTexelIdxX;
525

Callers

nothing calls this directly

Calls 15

PathTraceFunction · 0.85
SampleAreaLightFunction · 0.85
SetXBasisMethod · 0.80
SetYBasisMethod · 0.80
SetZBasisMethod · 0.80
PixelMethod · 0.80
LensMethod · 0.80
ToFloat4Method · 0.80
TransformClass · 0.50
sizeMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected