MaxMeshSamples
MaxMeshSamples
#Overview
name: MaxMeshSamples
The value of this variable can be defined or overridden in .ini config files. 1
.ini config file referencing this setting variable.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of MaxMeshSamples is to control the maximum number of samples taken on a mesh when calculating precomputed visibility in Unreal Engine 5. This setting is part of the precomputed visibility system, which is used to optimize rendering performance by determining which objects are visible from different locations in the game world.
MaxMeshSamples is primarily used by the Lightmass subsystem, which is responsible for global illumination and visibility calculations in Unreal Engine. Specifically, it’s used in the precomputed visibility calculations performed by UnrealLightmass, a separate program that runs as part of the lighting build process.
The value of this variable is set in the Lightmass configuration file (Lightmass.ini). It’s read from the config file in the WriteSceneSettings function in Lightmass.cpp.
MaxMeshSamples interacts with other visibility-related variables such as MinMeshSamples, NumCellSamples, and NumImportanceSamples. The actual number of samples used for a particular mesh is calculated based on the mesh’s size and distance from the sampling point, clamped between MinMeshSamples and MaxMeshSamples.
Developers should be aware that increasing MaxMeshSamples can improve the accuracy of visibility calculations, especially for large meshes or meshes with complex geometry. However, it also increases the time and memory required for lightmass calculations.
Best practices when using this variable include:
- Balancing accuracy with build time: Higher values give more accurate results but increase build times.
- Adjusting based on project needs: Projects with large, complex environments might benefit from higher values.
- Using in conjunction with other visibility settings: Adjust MinMeshSamples and MaxMeshSamples together to fine-tune the range of samples used.
- Considering performance impact: Remember that while this affects build times, it doesn’t directly impact runtime performance.
- Testing different values: The optimal value can vary depending on the specific geometry and lighting in your scene.
#Setting Variables
#References In INI files
Location: <Workspace>/Engine/Config/BaseLightmass.ini:115, section: [DevOptions.PrecomputedVisibility]
- INI Section:
DevOptions.PrecomputedVisibility
- Raw value:
40
- Is Array:
False
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Lightmass/Lightmass.cpp:2285
Scope (from outer to inner):
file
function void FLightmassExporter::WriteSceneSettings
Source code excerpt:
VERIFYLIGHTMASSINI(GConfig->GetFloat(TEXT("DevOptions.PrecomputedVisibility"), TEXT("MeshBoundsScale"), Scene.PrecomputedVisibilitySettings.MeshBoundsScale, GLightmassIni));
VERIFYLIGHTMASSINI(GConfig->GetInt(TEXT("DevOptions.PrecomputedVisibility"), TEXT("MinMeshSamples"), Scene.PrecomputedVisibilitySettings.MinMeshSamples, GLightmassIni));
VERIFYLIGHTMASSINI(GConfig->GetInt(TEXT("DevOptions.PrecomputedVisibility"), TEXT("MaxMeshSamples"), Scene.PrecomputedVisibilitySettings.MaxMeshSamples, GLightmassIni));
VERIFYLIGHTMASSINI(GConfig->GetInt(TEXT("DevOptions.PrecomputedVisibility"), TEXT("NumCellSamples"), Scene.PrecomputedVisibilitySettings.NumCellSamples, GLightmassIni));
VERIFYLIGHTMASSINI(GConfig->GetInt(TEXT("DevOptions.PrecomputedVisibility"), TEXT("NumImportanceSamples"), Scene.PrecomputedVisibilitySettings.NumImportanceSamples, GLightmassIni));
}
if (World->GetWorldSettings()->VisibilityAggressiveness != VIS_LeastAggressive)
{
const TCHAR* AggressivenessSectionNames[VIS_Max] = {
#Loc: <Workspace>/Engine/Source/Programs/UnrealLightmass/Private/Lighting/PrecomputedVisibility.cpp:783
Scope (from outer to inner):
file
namespace Lightmass
function bool ComputeBoxVisibility
Source code excerpt:
const float MeshSize = MeshBox.GetExtent().Size();
const float SizeRatio = MeshSize / Distance;
// Use MaxMeshSamples for meshes with a large projected angle, and MinMeshSamples for meshes with a small projected angle
// Meshes with a large projected angle require more samples to determine visibility accurately
const int32 NumMeshSamples = FMath::Clamp(FMath::TruncToInt(SizeRatio * PrecomputedVisibilitySettings.MaxMeshSamples), PrecomputedVisibilitySettings.MinMeshSamples, PrecomputedVisibilitySettings.MaxMeshSamples);
// Treat meshes whose projected angle is greater than 90 degrees as visible, since it becomes overly costly to determine if these are visible
// (consider a large close mesh that only has a tiny part visible)
bool bVisible = SizeRatio > 1.0f;
if (bVisible)
#Loc: <Workspace>/Engine/Source/Programs/UnrealLightmass/Public/SceneExport.h:406
Scope (from outer to inner):
file
namespace Lightmass
class class FPrecomputedVisibilitySettings
Source code excerpt:
/** Maximum number of samples on the mesh for each cell - mesh query. Small meshes use less samples. */
int32 MaxMeshSamples;
/** Number of samples on each cell for each cell - mesh query. */
int32 NumCellSamples;
/** Number of samples to use when importance sampling each cell - mesh query. */
int32 NumImportanceSamples;