Fix surface index passed to glsl
This commit is contained in:
parent
3386b6ad1a
commit
6ccb92ef60
8 changed files with 67 additions and 30 deletions
|
|
@ -41,49 +41,78 @@ ADD_STAT(lightmapper)
|
|||
return out;
|
||||
}
|
||||
|
||||
void VkLightmap::Raytrace(LevelMesh* level, const TArray<LevelMeshSurface*>& surfaces)
|
||||
#include <set>
|
||||
|
||||
void VkLightmap::Raytrace(LevelMesh* level, const TArray<int>& surfaceIndices)
|
||||
{
|
||||
bool newLevel = (mesh != level);
|
||||
mesh = level;
|
||||
|
||||
if (newLevel)
|
||||
{
|
||||
UpdateAccelStructDescriptors();
|
||||
CreateAtlasImages();
|
||||
|
||||
lightmapRaytrace.Reset();
|
||||
lightmapRaytraceLast.Reset();
|
||||
}
|
||||
|
||||
lightmapRaytrace.active = true;
|
||||
lightmapRaytraceLast.active = true;
|
||||
|
||||
lightmapRaytrace.Clock();
|
||||
lightmapRaytraceLast.ResetAndClock();
|
||||
|
||||
if (newLevel)
|
||||
#if 0
|
||||
TArray<int> allSurfaces;
|
||||
|
||||
std::set<int> s;
|
||||
|
||||
for (auto& surface : surfaceIndices)
|
||||
{
|
||||
UpdateAccelStructDescriptors();
|
||||
CreateAtlasImages();
|
||||
s.insert(mesh->GetSurface(surface)->smoothingGroupIndex);
|
||||
}
|
||||
|
||||
for (auto surface : surfaces)
|
||||
for (int i = 0, count = level->GetSurfaceCount(); i < count; ++i)
|
||||
{
|
||||
surface->needsUpdate = false;
|
||||
auto surface = level->GetSurface(i);
|
||||
|
||||
if (s.find(surface->smoothingGroupIndex) != s.end())
|
||||
{
|
||||
allSurfaces.Push(i);
|
||||
surface->needsUpdate = false;
|
||||
}
|
||||
}
|
||||
#else
|
||||
for (auto& surface : surfaceIndices)
|
||||
{
|
||||
mesh->GetSurface(surface)->needsUpdate = false;
|
||||
}
|
||||
|
||||
const auto& allSurfaces = surfaceIndices;
|
||||
#endif
|
||||
|
||||
UploadUniforms();
|
||||
|
||||
lastSurfaceCount = surfaces.Size();
|
||||
lastSurfaceCount = allSurfaces.Size();
|
||||
|
||||
for (size_t pageIndex = 0; pageIndex < atlasImages.size(); pageIndex++)
|
||||
{
|
||||
RenderAtlasImage(pageIndex, surfaces);
|
||||
RenderAtlasImage(pageIndex, allSurfaces);
|
||||
}
|
||||
|
||||
for (size_t pageIndex = 0; pageIndex < atlasImages.size(); pageIndex++)
|
||||
{
|
||||
ResolveAtlasImage(pageIndex);
|
||||
BlurAtlasImage(pageIndex);
|
||||
CopyAtlasImageResult(pageIndex, surfaces);
|
||||
CopyAtlasImageResult(pageIndex, allSurfaces);
|
||||
}
|
||||
|
||||
lightmapRaytrace.Unclock();
|
||||
lightmapRaytraceLast.Unclock();
|
||||
}
|
||||
|
||||
void VkLightmap::RenderAtlasImage(size_t pageIndex, const TArray<LevelMeshSurface*>& surfaces)
|
||||
void VkLightmap::RenderAtlasImage(size_t pageIndex, const TArray<int>& surfaceIndices)
|
||||
{
|
||||
LightmapImage& img = atlasImages[pageIndex];
|
||||
|
||||
|
|
@ -105,9 +134,9 @@ void VkLightmap::RenderAtlasImage(size_t pageIndex, const TArray<LevelMeshSurfac
|
|||
cmdbuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, raytrace.pipelineLayout.get(), 1, raytrace.descriptorSet1.get());
|
||||
}
|
||||
|
||||
for (int i = 0, count = surfaces.Size(); i < count; i++)
|
||||
for (int i = 0, count = surfaceIndices.Size(); i < count; i++)
|
||||
{
|
||||
LevelMeshSurface* targetSurface = surfaces[i];
|
||||
LevelMeshSurface* targetSurface = mesh->GetSurface(surfaceIndices[i]);
|
||||
if (targetSurface->lightmapperAtlasPage != pageIndex)
|
||||
continue;
|
||||
|
||||
|
|
@ -186,7 +215,7 @@ void VkLightmap::RenderAtlasImage(size_t pageIndex, const TArray<LevelMeshSurfac
|
|||
LightmapPushConstants pc;
|
||||
pc.LightStart = firstLight;
|
||||
pc.LightEnd = firstLight + lightCount;
|
||||
pc.SurfaceIndex = (int32_t)i;
|
||||
pc.SurfaceIndex = (int32_t)std::distance((char*)mesh->GetSurface(0), (char*)targetSurface) / 288;
|
||||
pc.LightmapOrigin = targetSurface->worldOrigin - targetSurface->worldStepX - targetSurface->worldStepY;
|
||||
pc.LightmapStepX = targetSurface->worldStepX * viewport.width;
|
||||
pc.LightmapStepY = targetSurface->worldStepY * viewport.height;
|
||||
|
|
@ -401,14 +430,14 @@ void VkLightmap::BlurAtlasImage(size_t pageIndex)
|
|||
}
|
||||
}
|
||||
|
||||
void VkLightmap::CopyAtlasImageResult(size_t pageIndex, const TArray<LevelMeshSurface*>& surfaces)
|
||||
void VkLightmap::CopyAtlasImageResult(size_t pageIndex, const TArray<int>& surfaceIndices)
|
||||
{
|
||||
LightmapImage& img = atlasImages[pageIndex];
|
||||
|
||||
std::vector<VkImageCopy> regions;
|
||||
for (int i = 0, count = surfaces.Size(); i < count; i++)
|
||||
for (int i = 0, count = surfaceIndices.Size(); i < count; i++)
|
||||
{
|
||||
LevelMeshSurface* surface = surfaces[i];
|
||||
LevelMeshSurface* surface = mesh->GetSurface(surfaceIndices[i]);
|
||||
if (surface->lightmapperAtlasPage != pageIndex)
|
||||
continue;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue