Use the game palette to find the material color

This commit is contained in:
Magnus Norddahl 2025-05-20 03:20:46 +02:00
commit 5a5c8d4bde
2 changed files with 9 additions and 5 deletions

View file

@ -309,7 +309,7 @@ VulkanImageView* VkTextureManager::GetSWColormapView(FSWColormap* colormap)
tex.Texture = ImageBuilder()
.Format(VK_FORMAT_B8G8R8A8_UNORM)
.Size(256, 32)
.Size(256, 33)
.Usage(VK_IMAGE_USAGE_SAMPLED_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT)
.DebugName("VkDescriptorSetManager.SWColormap")
.Create(fb->GetDevice());
@ -326,17 +326,21 @@ VulkanImageView* VkTextureManager::GetSWColormapView(FSWColormap* colormap)
.Execute(cmdbuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
auto stagingBuffer = BufferBuilder()
.Size(256 * 32 * sizeof(uint32_t))
.Size(256 * 33 * sizeof(uint32_t))
.Usage(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VMA_MEMORY_USAGE_CPU_ONLY)
.DebugName("VkDescriptorSetManager.SWColormapStagingBuffer")
.Create(fb->GetDevice());
const uint8_t* src = colormap->Maps;
uint32_t* data = static_cast<uint32_t*>(stagingBuffer->Map(0, 256 * 32 * sizeof(uint32_t)));
uint32_t* data = static_cast<uint32_t*>(stagingBuffer->Map(0, 256 * 33 * sizeof(uint32_t)));
for (int i = 0; i < 256 * 32; i++)
{
data[i] = GPalette.BaseColors[src[i]].d;
}
// Always include the game palette as we need it for dynlights (they ignore the fog for stupid reasons)
memcpy(data + 256 * 32, GPalette.BaseColors, 256 * sizeof(uint32_t));
stagingBuffer->Unmap();
VkBufferImageCopy region = {};
@ -344,7 +348,7 @@ VulkanImageView* VkTextureManager::GetSWColormapView(FSWColormap* colormap)
region.imageSubresource.layerCount = 1;
region.imageExtent.depth = 1;
region.imageExtent.width = 256;
region.imageExtent.height = 32;
region.imageExtent.height = 33;
cmdbuffer->copyBufferToImage(stagingBuffer->buffer, tex.Texture->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
fb->GetCommands()->TransferDeleteList->Add(std::move(stagingBuffer));

View file

@ -47,7 +47,7 @@ vec4 getLightColor(Material material)
float shade = 2.0 - (L + 12.0) / 128.0;
int light = clamp(int((shade - vis) * 32), 0, 31);
vec3 matColor = texelFetch(textures[uColormapIndex], ivec2(color, 0), 0).rgb;
vec3 matColor = texelFetch(textures[uColormapIndex], ivec2(color, 32), 0).rgb;
vec4 frag = vec4(texelFetch(textures[uColormapIndex], ivec2(color, light), 0).rgb, 1.0);
vec4 dynlight = uDynLightColor;