diff --git a/src/integration.rs b/src/integration.rs index de7917c..601ef80 100644 --- a/src/integration.rs +++ b/src/integration.rs @@ -885,7 +885,7 @@ impl Integration { .array_layers(1) .extent(extent) .flags(vk::ImageCreateFlags::empty()) - .format(vk::Format::R8G8B8A8_UNORM) + .format(vk::Format::R8G8B8A8_SRGB) .image_type(vk::ImageType::TYPE_2D) .initial_layout(vk::ImageLayout::UNDEFINED) .mip_levels(1) @@ -920,7 +920,7 @@ impl Integration { let create_info = vk::ImageViewCreateInfo::builder() .components(vk::ComponentMapping::default()) .flags(vk::ImageViewCreateFlags::empty()) - .format(vk::Format::R8G8B8A8_UNORM) + .format(vk::Format::R8G8B8A8_SRGB) .image(texture_image) .subresource_range( vk::ImageSubresourceRange::builder() diff --git a/src/shaders/spv/frag.spv b/src/shaders/spv/frag.spv index 594c914..f080f07 100644 Binary files a/src/shaders/spv/frag.spv and b/src/shaders/spv/frag.spv differ diff --git a/src/shaders/spv/vert.spv b/src/shaders/spv/vert.spv index fe6942a..a8b917a 100644 Binary files a/src/shaders/spv/vert.spv and b/src/shaders/spv/vert.spv differ diff --git a/src/shaders/src/frag.frag b/src/shaders/src/frag.frag index 674db6f..817d033 100644 --- a/src/shaders/src/frag.frag +++ b/src/shaders/src/frag.frag @@ -7,4 +7,17 @@ layout(location = 0) out vec4 outColor; layout(binding = 0, set = 0) uniform sampler2D font_texture; -void main() { outColor = inColor * texture(font_texture, inUV); } +// 0-1 sRGB gamma from 0-1 linear +vec3 srgb_gamma_from_linear(vec3 rgb) { + bvec3 cutoff = lessThan(rgb, vec3(0.0031308)); + vec3 lower = rgb * vec3(12.92); + vec3 higher = vec3(1.055) * pow(rgb, vec3(1.0 / 2.4)) - vec3(0.055); + return mix(higher, lower, vec3(cutoff)); +} + +// 0-1 sRGBA gamma from 0-1 linear +vec4 srgba_gamma_from_linear(vec4 rgba) { + return vec4(srgb_gamma_from_linear(rgba.rgb), rgba.a); +} + +void main() { outColor = inColor * srgba_gamma_from_linear(texture(font_texture, inUV)); } diff --git a/src/shaders/src/vert.vert b/src/shaders/src/vert.vert index e1e025a..d67cc6e 100644 --- a/src/shaders/src/vert.vert +++ b/src/shaders/src/vert.vert @@ -10,17 +10,11 @@ layout(location = 1) out vec2 outUV; layout(push_constant) uniform PushConstants { vec2 screen_size; } pushConstants; -vec3 srgb_to_linear(vec3 srgb) { - bvec3 cutoff = lessThan(srgb, vec3(0.04045)); - vec3 lower = srgb / vec3(12.92); - vec3 higher = pow((srgb + vec3(0.055)) / vec3(1.055), vec3(2.4)); - return mix(higher, lower, cutoff); -} void main() { gl_Position = vec4(2.0 * inPos.x / pushConstants.screen_size.x - 1.0, 2.0 * inPos.y / pushConstants.screen_size.y - 1.0, 0.0, 1.0); - outColor = vec4(srgb_to_linear(inColor.rgb), inColor.a); + outColor = inColor; outUV = inUV; }