From 5a5c8d4bde52ee1849a5913df68fbda1fa41a186 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 20 May 2025 03:20:46 +0200 Subject: [PATCH] Use the game palette to find the material color --- src/common/rendering/vulkan/textures/vk_texture.cpp | 12 ++++++++---- wadsrc/static/shaders/scene/lightmode.glsl | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/common/rendering/vulkan/textures/vk_texture.cpp b/src/common/rendering/vulkan/textures/vk_texture.cpp index 79f25f12d..53a5949d5 100644 --- a/src/common/rendering/vulkan/textures/vk_texture.cpp +++ b/src/common/rendering/vulkan/textures/vk_texture.cpp @@ -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(stagingBuffer->Map(0, 256 * 32 * sizeof(uint32_t))); + uint32_t* data = static_cast(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, ®ion); fb->GetCommands()->TransferDeleteList->Add(std::move(stagingBuffer)); diff --git a/wadsrc/static/shaders/scene/lightmode.glsl b/wadsrc/static/shaders/scene/lightmode.glsl index da920daa9..cae0fda37 100644 --- a/wadsrc/static/shaders/scene/lightmode.glsl +++ b/wadsrc/static/shaders/scene/lightmode.glsl @@ -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;