Fix lightmaps bake on D3D12

This commit is contained in:
Wojtek Figat
2021-06-08 15:21:37 +02:00
parent 4c6fd783e1
commit 39f50726a6
5 changed files with 22 additions and 9 deletions

BIN
Content/Shaders/BakeLightmap.flax (Stored with Git LFS)

Binary file not shown.

View File

@@ -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;
}

View File

@@ -78,6 +78,8 @@ void ShadowsOfMordor::Builder::generateHemispheres()
// Fill cache
if (runStage(RenderCache))
return;
if (waitForJobDataSync())
return;
// Post-process cache
if (runStage(PostprocessCache))

View File

@@ -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)
{

View File

@@ -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<float4> InputBuffer : register(t0);
Buffer<float4> InputBuffer : register(t0);
RWBuffer<float4> 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;