mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-04-25 04:01:43 +00:00
Use lightmapper output
This commit is contained in:
parent
8d2b03b7ef
commit
b5678d5f86
2 changed files with 20 additions and 33 deletions
|
@ -106,6 +106,11 @@ struct Surface
|
||||||
|
|
||||||
// Output lightmap for the surface
|
// Output lightmap for the surface
|
||||||
std::vector<FVector3> texPixels;
|
std::vector<FVector3> texPixels;
|
||||||
|
|
||||||
|
// Lightmapper has a lot of additional padding around the borders
|
||||||
|
int lightmapperAtlasPage = -1;
|
||||||
|
int lightmapperAtlasX = -1;
|
||||||
|
int lightmapperAtlasY = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -223,29 +228,6 @@ public:
|
||||||
FVector3 end = start + direction * std::max(maxDist - 10.0f, 0.0f);
|
FVector3 end = start + direction * std::max(maxDist - 10.0f, 0.0f);
|
||||||
return !TriangleMeshShape::find_any_hit(Collision.get(), start, end);
|
return !TriangleMeshShape::find_any_hit(Collision.get(), start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void FinishSurface(int lightmapTextureWidth, int lightmapTextureHeight, RectPacker& packer, Surface& surface)
|
|
||||||
{
|
|
||||||
int sampleWidth = surface.texWidth;
|
|
||||||
int sampleHeight = surface.texHeight;
|
|
||||||
|
|
||||||
auto result = packer.insert(sampleWidth, sampleHeight);
|
|
||||||
int x = result.pos.x, y = result.pos.y;
|
|
||||||
surface.atlasPageIndex = (int)result.pageIndex;
|
|
||||||
|
|
||||||
// calculate final texture coordinates
|
|
||||||
for (unsigned i = 0; i < surface.uvs.Size(); i++)
|
|
||||||
{
|
|
||||||
auto& u = surface.uvs[i].X;
|
|
||||||
auto& v = surface.uvs[i].Y;
|
|
||||||
u = (u + x) / (float)lightmapTextureWidth;
|
|
||||||
v = (v + y) / (float)lightmapTextureHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
surface.atlasX = x;
|
|
||||||
surface.atlasY = y;
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -50,6 +50,11 @@ void VkLightmap::Raytrace(hwrenderer::LevelMesh* level)
|
||||||
}
|
}
|
||||||
|
|
||||||
FinishCommands();
|
FinishCommands();
|
||||||
|
|
||||||
|
for (size_t pageIndex = 0; pageIndex < atlasImages.size(); pageIndex++)
|
||||||
|
{
|
||||||
|
DownloadAtlasImage(pageIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VkLightmap::BeginCommands()
|
void VkLightmap::BeginCommands()
|
||||||
|
@ -97,13 +102,13 @@ void VkLightmap::RenderAtlasImage(size_t pageIndex)
|
||||||
for (unsigned int i = 0; i < mesh->Surfaces.Size(); i++)
|
for (unsigned int i = 0; i < mesh->Surfaces.Size(); i++)
|
||||||
{
|
{
|
||||||
hwrenderer::Surface* targetSurface = &mesh->Surfaces[i];
|
hwrenderer::Surface* targetSurface = &mesh->Surfaces[i];
|
||||||
if (targetSurface->atlasPageIndex != pageIndex)
|
if (targetSurface->lightmapperAtlasPage != pageIndex)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
VkViewport viewport = {};
|
VkViewport viewport = {};
|
||||||
viewport.maxDepth = 1;
|
viewport.maxDepth = 1;
|
||||||
viewport.x = (float)targetSurface->atlasX - 1;
|
viewport.x = (float)targetSurface->lightmapperAtlasX - 1;
|
||||||
viewport.y = (float)targetSurface->atlasY - 1;
|
viewport.y = (float)targetSurface->lightmapperAtlasY - 1;
|
||||||
viewport.width = (float)(targetSurface->texWidth + 2);
|
viewport.width = (float)(targetSurface->texWidth + 2);
|
||||||
viewport.height = (float)(targetSurface->texHeight + 2);
|
viewport.height = (float)(targetSurface->texHeight + 2);
|
||||||
cmdbuffer->setViewport(0, 1, &viewport);
|
cmdbuffer->setViewport(0, 1, &viewport);
|
||||||
|
@ -200,9 +205,9 @@ void VkLightmap::CreateAtlasImages()
|
||||||
hwrenderer::Surface* surface = &mesh->Surfaces[i];
|
hwrenderer::Surface* surface = &mesh->Surfaces[i];
|
||||||
|
|
||||||
auto result = packer.insert(surface->texWidth + 2, surface->texHeight + 2);
|
auto result = packer.insert(surface->texWidth + 2, surface->texHeight + 2);
|
||||||
surface->atlasX = result.pos.x + 1;
|
surface->lightmapperAtlasX = result.pos.x + 1;
|
||||||
surface->atlasY = result.pos.y + 1;
|
surface->lightmapperAtlasY = result.pos.y + 1;
|
||||||
surface->atlasPageIndex = (int)result.pageIndex;
|
surface->lightmapperAtlasPage = (int)result.pageIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t pageIndex = 0; pageIndex < packer.getNumPages(); pageIndex++)
|
for (size_t pageIndex = 0; pageIndex < packer.getNumPages(); pageIndex++)
|
||||||
|
@ -307,18 +312,18 @@ void VkLightmap::DownloadAtlasImage(size_t pageIndex)
|
||||||
for (unsigned int i = 0; i < mesh->Surfaces.Size(); i++)
|
for (unsigned int i = 0; i < mesh->Surfaces.Size(); i++)
|
||||||
{
|
{
|
||||||
hwrenderer::Surface* surface = &mesh->Surfaces[i];
|
hwrenderer::Surface* surface = &mesh->Surfaces[i];
|
||||||
if (surface->atlasPageIndex != pageIndex)
|
if (surface->lightmapperAtlasPage != pageIndex)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int atlasX = surface->atlasX;
|
int lightmapperAtlasX = surface->lightmapperAtlasX;
|
||||||
int atlasY = surface->atlasY;
|
int lightmapperAtlasY = surface->lightmapperAtlasY;
|
||||||
int sampleWidth = surface->texWidth;
|
int sampleWidth = surface->texWidth;
|
||||||
int sampleHeight = surface->texHeight;
|
int sampleHeight = surface->texHeight;
|
||||||
|
|
||||||
for (int y = 0; y < sampleHeight; y++)
|
for (int y = 0; y < sampleHeight; y++)
|
||||||
{
|
{
|
||||||
FVector3* dest = &surface->texPixels[y * sampleWidth];
|
FVector3* dest = &surface->texPixels[y * sampleWidth];
|
||||||
hvec4* src = &pixels[atlasX + (atlasY + y) * atlasImageSize];
|
hvec4* src = &pixels[lightmapperAtlasX + (lightmapperAtlasY + y) * atlasImageSize];
|
||||||
for (int x = 0; x < sampleWidth; x++)
|
for (int x = 0; x < sampleWidth; x++)
|
||||||
{
|
{
|
||||||
dest[x] = src[x].xyz();
|
dest[x] = src[x].xyz();
|
||||||
|
|
Loading…
Reference in a new issue