IndirectPhotonSearchDistance
IndirectPhotonSearchDistance
#Overview
name: IndirectPhotonSearchDistance
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 8
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of IndirectPhotonSearchDistance is to define the maximum distance for searching indirect photons during the photon mapping process in Unreal Engine’s lightmass system. This setting is crucial for the global illumination and lighting calculations in static lighting.
IndirectPhotonSearchDistance is primarily used in the Lightmass subsystem, which is responsible for precomputing static lighting in Unreal Engine. It’s specifically utilized in the photon mapping module of Lightmass.
The value of this variable is typically set in the Lightmass configuration file (LightmassSettings.ini). It’s read from the configuration file in the FLightmassExporter::WriteSceneSettings function.
This variable interacts with other photon mapping settings such as IndirectPhotonDensity, IndirectIrradiancePhotonDensity, and PhotonSearchAngleThreshold. It’s also used in conjunction with DirectPhotonSearchDistance when finding the nearest irradiance photon.
Developers should be aware that:
- This setting directly affects the quality and performance of indirect lighting calculations.
- A larger value will increase the search radius, potentially improving lighting quality but at the cost of increased computation time.
- It’s scaled by the static lighting level scale, so changes in level scale will affect this distance.
Best practices when using this variable include:
- Balancing the value to achieve desired lighting quality without excessive computation time.
- Adjusting it in conjunction with other photon mapping settings for optimal results.
- Testing different values to find the best balance between quality and performance for your specific scene.
- Considering the scale of your level when setting this value, as it’s affected by the static lighting level scale.
#Setting Variables
#References In INI files
Location: <Workspace>/Engine/Config/BaseLightmass.ini:199, section: [DevOptions.PhotonMapping]
- INI Section:
DevOptions.PhotonMapping
- Raw value:
200
- 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:2387
Scope (from outer to inner):
file
function void FLightmassExporter::WriteSceneSettings
Source code excerpt:
VERIFYLIGHTMASSINI(GConfig->GetFloat(TEXT("DevOptions.PhotonMapping"), TEXT("IndirectPhotonDensity"), Scene.PhotonMappingSettings.IndirectPhotonDensity, GLightmassIni));
VERIFYLIGHTMASSINI(GConfig->GetFloat(TEXT("DevOptions.PhotonMapping"), TEXT("IndirectIrradiancePhotonDensity"), Scene.PhotonMappingSettings.IndirectIrradiancePhotonDensity, GLightmassIni));
VERIFYLIGHTMASSINI(GConfig->GetFloat(TEXT("DevOptions.PhotonMapping"), TEXT("IndirectPhotonSearchDistance"), Scene.PhotonMappingSettings.IndirectPhotonSearchDistance, GLightmassIni));
VERIFYLIGHTMASSINI(GConfig->GetFloat(TEXT("DevOptions.PhotonMapping"), TEXT("PhotonSearchAngleThreshold"), Scene.PhotonMappingSettings.PhotonSearchAngleThreshold, GLightmassIni));
float IrradiancePhotonSearchConeAngle;
VERIFYLIGHTMASSINI(GConfig->GetFloat(TEXT("DevOptions.PhotonMapping"), TEXT("IrradiancePhotonSearchConeAngle"), IrradiancePhotonSearchConeAngle, GLightmassIni));
Scene.PhotonMappingSettings.MinCosIrradiancePhotonSearchCone = FMath::Cos((90.0f - FMath::Clamp(IrradiancePhotonSearchConeAngle, 1.0f, 90.0f)) * (float)PI / 180.0f);
VERIFYLIGHTMASSINI(GConfig->GetBool(TEXT("DevOptions.PhotonMapping"), TEXT("bUsePhotonSegmentsForVolumeLighting"), Scene.PhotonMappingSettings.bUsePhotonSegmentsForVolumeLighting, GLightmassIni));
VERIFYLIGHTMASSINI(GConfig->GetFloat(TEXT("DevOptions.PhotonMapping"), TEXT("PhotonSegmentMaxLength"), Scene.PhotonMappingSettings.PhotonSegmentMaxLength, GLightmassIni));
#Loc: <Workspace>/Engine/Source/Programs/UnrealLightmass/Private/ImportExport/LightmassScene.cpp:542
Scope (from outer to inner):
file
namespace Lightmass
function void FScene::ApplyStaticLightingScale
Source code excerpt:
PhotonMappingSettings.IndirectPhotonDensity /= ScaleSquared;
PhotonMappingSettings.IndirectIrradiancePhotonDensity /= ScaleSquared;
PhotonMappingSettings.IndirectPhotonSearchDistance *= SceneConstants.StaticLightingLevelScale;
*/
}
//----------------------------------------------------------------------------
// Light base class
//----------------------------------------------------------------------------
void FLight::Import( FLightmassImporter& Importer )
{
Importer.ImportData( (FLightData*)this );
Importer.ImportArray( LightTextureProfileData, FLightData::LightProfileTextureDataSize );
// The read above stomps on CachedLightSurfaceSamples since that memory is padding in FLightData
FMemory::Memzero(&CachedLightSurfaceSamples, sizeof(CachedLightSurfaceSamples));
// Precalculate the light's indirect color
IndirectColor = FLinearColorUtils::AdjustSaturation(FLinearColor(Color), IndirectLightingSaturation) * IndirectLightingScale;
}
/**
#Loc: <Workspace>/Engine/Source/Programs/UnrealLightmass/Private/Lighting/FinalGather.cpp:1517
Scope (from outer to inner):
file
namespace Lightmass
function FFinalGatherSample FStaticLightingSystem::CachePointIncomingRadiance
Source code excerpt:
// Use the photons deposited on surfaces to estimate indirect lighting
const bool bDebugFirstBouncePhotonGather = bDebugThisTexel && GeneralSettings.ViewSingleBounceNumber == BounceNumber;
const FGatheredLightSample FirstBounceLighting = CalculatePhotonIncidentRadiance(FirstBouncePhotonMap, NumPhotonsEmittedFirstBounce, PhotonMappingSettings.IndirectPhotonSearchDistance, Vertex, bDebugFirstBouncePhotonGather);
if (GeneralSettings.ViewSingleBounceNumber < 0 || GeneralSettings.ViewSingleBounceNumber == BounceNumber)
{
IndirectLighting.AddWeighted(FirstBounceLighting, 1.0f);
}
if (GeneralSettings.NumIndirectLightingBounces > 1)
{
const bool bDebugSecondBouncePhotonGather = bDebugThisTexel && GeneralSettings.ViewSingleBounceNumber > BounceNumber;
const FGatheredLightSample SecondBounceLighting = CalculatePhotonIncidentRadiance(SecondBouncePhotonMap, NumPhotonsEmittedSecondBounce, PhotonMappingSettings.IndirectPhotonSearchDistance, Vertex, bDebugSecondBouncePhotonGather);
if (GeneralSettings.ViewSingleBounceNumber < 0 || GeneralSettings.ViewSingleBounceNumber > BounceNumber)
{
IndirectLighting.AddWeighted(SecondBounceLighting, 1.0f);
}
}
}
#Loc: <Workspace>/Engine/Source/Programs/UnrealLightmass/Private/Lighting/PhotonMapping.cpp:1548
Scope (from outer to inner):
file
namespace Lightmass
function void FStaticLightingSystem::CalculateIrradiancePhotonsWorkRange
Source code excerpt:
NumPhotonsEmittedFirstBounce,
PhotonMappingSettings.NumIrradianceCalculationPhotons,
PhotonMappingSettings.IndirectPhotonSearchDistance,
CurrentIrradiancePhoton,
bDebugThisPhoton && GeneralSettings.ViewSingleBounceNumber == 1,
TempFoundPhotons,
OutStats);
checkSlow(FLinearColorUtils::AreFloatsValid(FirstBouncePhotonIrradiance));
#Loc: <Workspace>/Engine/Source/Programs/UnrealLightmass/Private/Lighting/PhotonMapping.cpp:1572
Scope (from outer to inner):
file
namespace Lightmass
function void FStaticLightingSystem::CalculateIrradiancePhotonsWorkRange
Source code excerpt:
NumPhotonsEmittedSecondBounce,
PhotonMappingSettings.NumIrradianceCalculationPhotons,
PhotonMappingSettings.IndirectPhotonSearchDistance,
CurrentIrradiancePhoton,
bDebugThisPhoton && GeneralSettings.ViewSingleBounceNumber > 1,
TempFoundPhotons,
OutStats);
checkSlow(FLinearColorUtils::AreFloatsValid(SecondBouncePhotonIrradiance));
#Loc: <Workspace>/Engine/Source/Programs/UnrealLightmass/Private/Lighting/PhotonMapping.cpp:2224
Scope (from outer to inner):
file
namespace Lightmass
function FIrradiancePhoton* FStaticLightingSystem::FindNearestIrradiancePhoton
Source code excerpt:
FIrradiancePhoton* ClosestPhoton = NULL;
// Traverse the octree with the maximum distance required
const float SearchDistance = FMath::Max(PhotonMappingSettings.DirectPhotonSearchDistance, PhotonMappingSettings.IndirectPhotonSearchDistance);
float ClosestDistanceSquared = FMath::Square(SearchDistance);
// Empty the temporary array without reallocating
TempIrradiancePhotons.Empty(TempIrradiancePhotons.Num() + TempIrradiancePhotons.GetSlack());
const FBox3f SearchBox = FBox3f::BuildAABB(Vertex.WorldPosition, FVector4f(SearchDistance, SearchDistance, SearchDistance));
{
#Loc: <Workspace>/Engine/Source/Programs/UnrealLightmass/Private/Lighting/PhotonMapping.cpp:2266
Scope (from outer to inner):
file
function FIrradiancePhoton* FStaticLightingSystem::FindNearestIrradiancePhoton
Source code excerpt:
// And closer to the search position than the max search distance.
&& ((CurrentPhoton.HasDirectContribution() && (DistanceSquared < FMath::Square(PhotonMappingSettings.DirectPhotonSearchDistance)))
|| (!CurrentPhoton.HasDirectContribution() && (DistanceSquared < FMath::Square(PhotonMappingSettings.IndirectPhotonSearchDistance)))))
{
// Only accept irradiance photons within an angle of the plane defined by the vertex normal
// This avoids expensive visibility traces to photons that are probably not on the same surface
const float DirectionDotNormal = Dot3(CurrentPhoton.GetSurfaceNormal(), PhotonToVertexVector.GetSafeNormal());
if (FMath::Abs(DirectionDotNormal) < PhotonMappingSettings.MinCosIrradiancePhotonSearchCone)
{
#Loc: <Workspace>/Engine/Source/Programs/UnrealLightmass/Public/SceneExport.h:691
Scope (from outer to inner):
file
namespace Lightmass
class class FPhotonMappingSettings
Source code excerpt:
/** Distance to use when searching for indirect photons. */
float IndirectPhotonSearchDistance;
/** Maximum cosine of the angle between the search normal and the surface normal of a candidate photon for that photon to be a valid search result. */
float PhotonSearchAngleThreshold;
/** Cosine of the angle from the search normal that defines a cone which irradiance photons must be outside of to be valid for that search. */
float MinCosIrradiancePhotonSearchCone;