Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Resources/Shaders/Vulkan/BasicImage.frag
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,25 @@ layout(location = 1) in vec2 texCoord;

layout(location = 0) out vec4 fragColor;

// The swapchain attachment is VK_FORMAT_B8G8R8A8_SRGB: the hardware
// sRGB-ENCODES whatever this shader writes. But 2D UI textures are
// uploaded as UNORM (raw sRGB bytes sampled verbatim) and the GL
// renderer writes those bytes straight to a non-sRGB framebuffer.
// Without correction the value gets sRGB-encoded a second time ->
// washed-out minimap/UI. Fix: do all math in sRGB space exactly like
// GL, then DECODE to linear so the attachment's encode restores the
// original bytes.
vec3 srgbToLinear(vec3 c) {
bvec3 lo = lessThanEqual(c, vec3(0.04045));
vec3 linLo = c / 12.92;
vec3 linHi = pow((c + 0.055) / 1.055, vec3(2.4));
return mix(linHi, linLo, vec3(lo));
}

void main() {
vec2 flippedTexCoord = vec2(texCoord.x, 1.0 - texCoord.y);
vec4 col = texture(mainTexture, flippedTexCoord);
col.xyz *= col.w;
col *= color;
fragColor = col;
fragColor = vec4(srgbToLinear(col.xyz), col.w);
}
9 changes: 9 additions & 0 deletions Sources/Draw/Vulkan/VulkanFlatMapRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "VulkanFlatMapRenderer.h"
#include "VulkanRenderer.h"
#include "VulkanImage.h"
#include "VulkanImageWrapper.h"
#include <Gui/SDLVulkanDevice.h>
#include <Client/GameMap.h>
#include <Client/IImage.h>
Expand All @@ -39,6 +41,13 @@ namespace spades {

Handle<Bitmap> bmp(GenerateBitmap(0, 0, m.Width(), m.Height()), false);
image = renderer.CreateImage(*bmp);

auto* wrapper = dynamic_cast<VulkanImageWrapper*>(image.GetPointerOrNull());
if (wrapper && wrapper->GetVulkanImage()) {
wrapper->GetVulkanImage()->CreateSampler(
VK_FILTER_NEAREST, VK_FILTER_NEAREST,
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, false);
}
}

VulkanFlatMapRenderer::~VulkanFlatMapRenderer() {}
Expand Down
4 changes: 4 additions & 0 deletions Sources/Draw/Vulkan/VulkanImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ namespace spades {

void VulkanImage::CreateSampler(VkFilter magFilter, VkFilter minFilter,
VkSamplerAddressMode addressMode, bool enableAnisotropy) {
if (sampler != VK_NULL_HANDLE) {
vkDestroySampler(device->GetDevice(), sampler, nullptr);
sampler = VK_NULL_HANDLE;
}
VkSamplerCreateInfo samplerInfo{};
samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
samplerInfo.magFilter = magFilter;
Expand Down
Loading