Skip to content

Instantly share code, notes, and snippets.

@ikrima
Created May 1, 2017 20:23
Show Gist options
  • Save ikrima/f1af560de5f9c8063dfdc3dc65633ea9 to your computer and use it in GitHub Desktop.
Save ikrima/f1af560de5f9c8063dfdc3dc65633ea9 to your computer and use it in GitHub Desktop.
Selective Light Baking UE4 4.15
From e79d15122ffd2ac59170385afc858e90f9996eed Mon Sep 17 00:00:00 2001
From: ikrima <[email protected]>
Date: Thu, 16 Mar 2017 07:03:25 -0700
Subject: [PATCH] Adding selective lightbaking
-Mainly just piggybacked off existing functionality using FLightingBuildOptions
-Main thing was adding ability to pipe that data struct to the EditorBuildLighting command
& augmenting the ShouldOperateOnLevel() call to take into account FLightingBuildOptions
---
.../Editor/UnrealEd/Private/EditorBuildUtils.cpp | 49 ++++++++++++++--------
.../StaticLightingSystem/StaticLightingPrivate.h | 4 +-
.../StaticLightingSystem/StaticLightingSystem.cpp | 4 +-
.../Editor/UnrealEd/Public/EditorBuildUtils.h | 3 ++
4 files changed, 41 insertions(+), 19 deletions(-)
diff --git a/Engine/Source/Editor/UnrealEd/Private/EditorBuildUtils.cpp b/Engine/Source/Editor/UnrealEd/Private/EditorBuildUtils.cpp
index 35df25a..6d48fc4 100644
--- a/Engine/Source/Editor/UnrealEd/Private/EditorBuildUtils.cpp
+++ b/Engine/Source/Editor/UnrealEd/Private/EditorBuildUtils.cpp
@@ -218,6 +218,31 @@ static bool IsBuildCancelled()
return GEditor->GetMapBuildCancelled();
}
+
+// @third party code - BEGIN Bebylon - Adding Selective Level Light Baking
+//Adding ability to pass in LightingBuildOptions directly but keeping this shim for existing engine code path
+bool FEditorBuildUtils::EditorBuild( UWorld* InWorld, FName Id, const bool bAllowLightingDialog )
+{
+ // Show option dialog first, before showing the DlgBuildProgress window.
+ FLightingBuildOptions LightingBuildOptions;
+ if ( Id == FBuildOptions::BuildLighting )
+ {
+ // Retrieve settings from ini.
+ GConfig->GetBool( TEXT("LightingBuildOptions"), TEXT("OnlyBuildSelected"), LightingBuildOptions.bOnlyBuildSelected, GEditorPerProjectIni );
+ GConfig->GetBool( TEXT("LightingBuildOptions"), TEXT("OnlyBuildCurrentLevel"), LightingBuildOptions.bOnlyBuildCurrentLevel, GEditorPerProjectIni );
+ GConfig->GetBool( TEXT("LightingBuildOptions"), TEXT("OnlyBuildSelectedLevels"),LightingBuildOptions.bOnlyBuildSelectedLevels, GEditorPerProjectIni );
+ GConfig->GetBool( TEXT("LightingBuildOptions"), TEXT("OnlyBuildVisibility"), LightingBuildOptions.bOnlyBuildVisibility, GEditorPerProjectIni );
+ GConfig->GetBool( TEXT("LightingBuildOptions"), TEXT("UseErrorColoring"), LightingBuildOptions.bUseErrorColoring, GEditorPerProjectIni );
+ GConfig->GetBool( TEXT("LightingBuildOptions"), TEXT("ShowLightingBuildInfo"), LightingBuildOptions.bShowLightingBuildInfo, GEditorPerProjectIni );
+ int32 QualityLevel;
+ GConfig->GetInt( TEXT("LightingBuildOptions"), TEXT("QualityLevel"), QualityLevel, GEditorPerProjectIni );
+ QualityLevel = FMath::Clamp<int32>(QualityLevel, Quality_Preview, Quality_Production);
+ LightingBuildOptions.QualityLevel = (ELightingBuildQuality)QualityLevel;
+ }
+
+ return EditorBuild(InWorld, Id, LightingBuildOptions, bAllowLightingDialog);
+}
+
/**
* Perform an editor build with behavior dependent upon the specified id
*
@@ -225,7 +250,8 @@ static bool IsBuildCancelled()
*
* @return true if the build completed successfully; false if it did not (or was manually canceled)
*/
-bool FEditorBuildUtils::EditorBuild( UWorld* InWorld, FName Id, const bool bAllowLightingDialog )
+bool FEditorBuildUtils::EditorBuild(UWorld* InWorld, FName Id, const FLightingBuildOptions& LightingBuildOptions, const bool bAllowLightingDialog /*= true*/)
+// @third party code - END Bebylon
{
FMessageLog("MapCheck").NewPage(LOCTEXT("MapCheckNewPage", "Map Check"));
@@ -244,22 +270,7 @@ bool FEditorBuildUtils::EditorBuild( UWorld* InWorld, FName Id, const bool bAllo
// bat when opening a map you will get incorrect values in them.
GSwarmDebugOptions.Touch();
- // Show option dialog first, before showing the DlgBuildProgress window.
- FLightingBuildOptions LightingBuildOptions;
- if ( Id == FBuildOptions::BuildLighting )
- {
- // Retrieve settings from ini.
- GConfig->GetBool( TEXT("LightingBuildOptions"), TEXT("OnlyBuildSelected"), LightingBuildOptions.bOnlyBuildSelected, GEditorPerProjectIni );
- GConfig->GetBool( TEXT("LightingBuildOptions"), TEXT("OnlyBuildCurrentLevel"), LightingBuildOptions.bOnlyBuildCurrentLevel, GEditorPerProjectIni );
- GConfig->GetBool( TEXT("LightingBuildOptions"), TEXT("OnlyBuildSelectedLevels"),LightingBuildOptions.bOnlyBuildSelectedLevels, GEditorPerProjectIni );
- GConfig->GetBool( TEXT("LightingBuildOptions"), TEXT("OnlyBuildVisibility"), LightingBuildOptions.bOnlyBuildVisibility, GEditorPerProjectIni );
- GConfig->GetBool( TEXT("LightingBuildOptions"), TEXT("UseErrorColoring"), LightingBuildOptions.bUseErrorColoring, GEditorPerProjectIni );
- GConfig->GetBool( TEXT("LightingBuildOptions"), TEXT("ShowLightingBuildInfo"), LightingBuildOptions.bShowLightingBuildInfo, GEditorPerProjectIni );
- int32 QualityLevel;
- GConfig->GetInt( TEXT("LightingBuildOptions"), TEXT("QualityLevel"), QualityLevel, GEditorPerProjectIni );
- QualityLevel = FMath::Clamp<int32>(QualityLevel, Quality_Preview, Quality_Production);
- LightingBuildOptions.QualityLevel = (ELightingBuildQuality)QualityLevel;
- }
+
// Show the build progress dialog.
SBuildProgressWidget::EBuildType BuildType = SBuildProgressWidget::BUILDTYPE_Geometry;
@@ -358,6 +369,10 @@ bool FEditorBuildUtils::EditorBuild( UWorld* InWorld, FName Id, const bool bAllo
GUnrealEd->Exec( InWorld, TEXT("MAP REBUILD ALLVISIBLE") );
}
+ // @third party code - BEGIN Bebylon - Adding Selective Level Light Baking
+ //Should not mark persistent level as dirty if we're not selectively baking lighting for it
+ bDirtyPersistentLevel = LightingBuildOptions.ShouldBuildLightingForLevel(GWorld->PersistentLevel);
+ // @third party code - END Bebylon
GUnrealEd->BuildLighting( LightingBuildOptions );
bShouldMapCheck = false;
}
diff --git a/Engine/Source/Editor/UnrealEd/Private/StaticLightingSystem/StaticLightingPrivate.h b/Engine/Source/Editor/UnrealEd/Private/StaticLightingSystem/StaticLightingPrivate.h
index 66b1b9c..b682b1b 100644
--- a/Engine/Source/Editor/UnrealEd/Private/StaticLightingSystem/StaticLightingPrivate.h
+++ b/Engine/Source/Editor/UnrealEd/Private/StaticLightingSystem/StaticLightingPrivate.h
@@ -293,7 +293,9 @@ public:
bool ShouldOperateOnLevel(ULevel* InLevel) const
{
- return !InLevel->bIsLightingScenario || InLevel == LightingScenario;
+ // @third party code - BEGIN Bebylon - Adding Selective Level Light Baking
+ return (!InLevel->bIsLightingScenario || InLevel == LightingScenario) && Options.ShouldBuildLightingForLevel(InLevel);
+ // @third party code - END Bebylon
}
private:
diff --git a/Engine/Source/Editor/UnrealEd/Private/StaticLightingSystem/StaticLightingSystem.cpp b/Engine/Source/Editor/UnrealEd/Private/StaticLightingSystem/StaticLightingSystem.cpp
index a7ddab8..29cff7b 100644
--- a/Engine/Source/Editor/UnrealEd/Private/StaticLightingSystem/StaticLightingSystem.cpp
+++ b/Engine/Source/Editor/UnrealEd/Private/StaticLightingSystem/StaticLightingSystem.cpp
@@ -532,7 +532,9 @@ bool FStaticLightingSystem::BeginLightmassProcess()
for( int32 LevelIndex = 0 ; LevelIndex < World->StreamingLevels.Num() ; ++LevelIndex )
{
ULevelStreaming* CurStreamingLevel = World->StreamingLevels[ LevelIndex ];
- if (CurStreamingLevel && CurStreamingLevel->GetLoadedLevel() && !CurStreamingLevel->bShouldBeVisibleInEditor)
+ // @third party code - BEGIN Bebylon - Adding Selective Level Light Baking
+ if (CurStreamingLevel && CurStreamingLevel->GetLoadedLevel() && Options.ShouldBuildLightingForLevel(CurStreamingLevel->GetLoadedLevel()) && !CurStreamingLevel->bShouldBeVisibleInEditor)
+ // @third party code - END Bebylon
{
if (SkippedLevels.Len() > 0)
{
diff --git a/Engine/Source/Editor/UnrealEd/Public/EditorBuildUtils.h b/Engine/Source/Editor/UnrealEd/Public/EditorBuildUtils.h
index db0f43b..7a935f4 100644
--- a/Engine/Source/Editor/UnrealEd/Public/EditorBuildUtils.h
+++ b/Engine/Source/Editor/UnrealEd/Public/EditorBuildUtils.h
@@ -122,6 +122,9 @@ public:
* @return true if the build completed successfully; false if it did not (or was manually canceled)
*/
static UNREALED_API bool EditorBuild( UWorld* InWorld, FName Id, const bool bAllowLightingDialog = true );
+ // @third party code - BEGIN Bebylon - Adding Selective Level Light Baking
+ static UNREALED_API bool EditorBuild(UWorld* InWorld, FName Id, const FLightingBuildOptions& LightingBuildOptions, const bool bAllowLightingDialog);
+ // @third party code - END Bebylon
/**
* Perform an editor build for texture streaming
--
2.6.1.windows.1
@ObiwanWS
Copy link

ObiwanWS commented Oct 7, 2020

Dude! This is amazing! I tried to implement this on UE4 4.25 without any luck, could you detail a little bit more how to apply this patch to the Engine source? Thank you very much.

@ikrima
Copy link
Author

ikrima commented Oct 8, 2020

Not sure about 4.25 but iirc, we were using this up to 4.22 so likely that feature still works

All this patch is doing is exposing the feature already in the engine but disabled since it doesn't play nicely with all scenarios (gpu light volumes for instance need more involved changes)

You can check out the lightmass notes i put in https://github.com/ikrima/gamedevguide or live version https://bebylon.dev/ue4guide/graphics-development/lightmass-lightmapping/using-lightmass/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment