diff --git a/Content/Shaders/BakeLightmap.flax b/Content/Shaders/BakeLightmap.flax index fac992469..37ae66747 100644 --- a/Content/Shaders/BakeLightmap.flax +++ b/Content/Shaders/BakeLightmap.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cc4b141137661d995ff571191150c5997fa6f6576572b5c2281c395a12772d7c -size 16095 +oid sha256:6f3f83f05ee829a7981dc8b832f5b1160f23cf779aa84a7838c63aa7ff0bb336 +size 16284 diff --git a/Source/Engine/ShadowsOfMordor/Builder.DoWork.cpp b/Source/Engine/ShadowsOfMordor/Builder.DoWork.cpp index b144a0d5a..fcacc9de8 100644 --- a/Source/Engine/ShadowsOfMordor/Builder.DoWork.cpp +++ b/Source/Engine/ShadowsOfMordor/Builder.DoWork.cpp @@ -188,7 +188,12 @@ bool ShadowsOfMordor::Builder::doWorkInner(DateTime buildStart) tempDesc.Format = HemispheresFormatToPixelFormat[CACHE_NORMALS_FORMAT]; _cacheNormals = RenderTargetPool::Get(tempDesc); if (_cachePositions == nullptr || _cacheNormals == nullptr) + { + LOG(Warning, "Failed to get textures for cache."); + _wasBuildCalled = false; + _isActive = false; return true; + } generateHemispheres(); @@ -228,6 +233,8 @@ bool ShadowsOfMordor::Builder::doWorkInner(DateTime buildStart) if (bounceCount <= 0 || hemispheresCount <= 0) { LOG(Warning, "No data to render"); + _wasBuildCalled = false; + _isActive = false; return true; } @@ -284,8 +291,8 @@ bool ShadowsOfMordor::Builder::doWorkInner(DateTime buildStart) reportProgress(BuildProgressStep::RenderHemispheres, 1.0f); #if DEBUG_EXPORT_HEMISPHERES_PREVIEW - for (int32 sceneIndex = 0; sceneIndex < _scenes.Count(); sceneIndex++) - downloadDebugHemisphereAtlases(_scenes[sceneIndex]); + for (int32 sceneIndex = 0; sceneIndex < _scenes.Count(); sceneIndex++) + downloadDebugHemisphereAtlases(_scenes[sceneIndex]); #endif // References: @@ -391,6 +398,7 @@ int32 ShadowsOfMordor::Builder::doWork() buildFailed = doWorkInner(buildStart); if (buildFailed && !checkBuildCancelled()) { + IsBakingLightmaps = false; OnBuildFinished(buildFailed); return 0; } diff --git a/Source/Engine/ShadowsOfMordor/Builder.Hemispheres.cpp b/Source/Engine/ShadowsOfMordor/Builder.Hemispheres.cpp index 560d922b9..f04d790a8 100644 --- a/Source/Engine/ShadowsOfMordor/Builder.Hemispheres.cpp +++ b/Source/Engine/ShadowsOfMordor/Builder.Hemispheres.cpp @@ -78,6 +78,8 @@ void ShadowsOfMordor::Builder::generateHemispheres() // Fill cache if (runStage(RenderCache)) return; + if (waitForJobDataSync()) + return; // Post-process cache if (runStage(PostprocessCache)) diff --git a/Source/Engine/ShadowsOfMordor/Builder.cpp b/Source/Engine/ShadowsOfMordor/Builder.cpp index 5d90a4ec8..dbbc8e14b 100644 --- a/Source/Engine/ShadowsOfMordor/Builder.cpp +++ b/Source/Engine/ShadowsOfMordor/Builder.cpp @@ -521,7 +521,7 @@ void ShadowsOfMordor::Builder::releaseResources() bool ShadowsOfMordor::Builder::waitForJobDataSync() { bool wasCancelled = false; - const int32 framesToSyncCount = 3; + const int32 framesToSyncCount = 4; while (!wasCancelled) { diff --git a/Source/Shaders/BakeLightmap.shader b/Source/Shaders/BakeLightmap.shader index 14f99b4f4..a1dc90f73 100644 --- a/Source/Shaders/BakeLightmap.shader +++ b/Source/Shaders/BakeLightmap.shader @@ -325,6 +325,8 @@ META_CS(true, FEATURE_LEVEL_SM5) [numthreads(1, 1, 1)] void CS_BlurEmpty(uint3 GroupID : SV_GroupID, uint3 GroupThreadID : SV_GroupThreadID) { + if (GroupID.x >= AtlasSize || GroupID.y > AtlasSize) + return; const int2 location = int2(GroupID.x, GroupID.y); const uint texelAdress = (location.y * AtlasSize + location.x) * NUM_SH_TARGETS; @@ -396,7 +398,7 @@ void CS_BlurEmpty(uint3 GroupID : SV_GroupID, uint3 GroupThreadID : SV_GroupThre #elif defined(_CS_Dilate) -Buffer InputBuffer : register(t0); +Buffer InputBuffer : register(t0); RWBuffer OutputBuffer : register(u0); // Fills the empty lightmap texels with blurred data of the surroundings texels (uses only valid ones) @@ -404,6 +406,8 @@ META_CS(true, FEATURE_LEVEL_SM5) [numthreads(1, 1, 1)] void CS_Dilate(uint3 GroupID : SV_GroupID, uint3 GroupThreadID : SV_GroupThreadID) { + if (GroupID.x >= AtlasSize || GroupID.y > AtlasSize) + return; const int2 location = int2(GroupID.x, GroupID.y); const uint texelAdress = (location.y * AtlasSize + location.x) * NUM_SH_TARGETS; @@ -431,11 +435,9 @@ void CS_Dilate(uint3 GroupID : SV_GroupID, uint3 GroupThreadID : SV_GroupThreadI for (int sampleIndex = 0; sampleIndex < 9; sampleIndex++) { int2 sampleLocation = location + int2(OffsetX[sampleIndex], OffsetY[sampleIndex]); - if (sampleLocation.x >= 0 && sampleLocation.x < AtlasSize && sampleLocation.y >= 0 && sampleLocation.y < AtlasSize) { uint sampleAdress = (sampleLocation.y * AtlasSize + sampleLocation.x) * NUM_SH_TARGETS; - float4 sample0 = InputBuffer[sampleAdress + 0]; float4 sample1 = InputBuffer[sampleAdress + 1]; float4 sample2 = InputBuffer[sampleAdress + 2]; @@ -454,7 +456,6 @@ void CS_Dilate(uint3 GroupID : SV_GroupID, uint3 GroupThreadID : SV_GroupThreadI if (total > 0) { total = 1.0f / total; - OutputBuffer[texelAdress + 0] = total0 * total; OutputBuffer[texelAdress + 1] = total1 * total; OutputBuffer[texelAdress + 2] = total2 * total; @@ -470,6 +471,8 @@ META_CS(true, FEATURE_LEVEL_SM5) [numthreads(1, 1, 1)] void CS_Finalize(uint3 GroupID : SV_GroupID, uint3 GroupThreadID : SV_GroupThreadID) { + if (GroupID.x >= AtlasSize || GroupID.y > AtlasSize) + return; const int2 location = int2(GroupID.x, GroupID.y); const uint texelAdress = (location.y * AtlasSize + location.x) * NUM_SH_TARGETS;