veloren/assets/voxygen/shaders/premultiply-alpha-frag.glsl
Imbris 63096b2042 Complete GPU based alpha premultiplication impl and make the CPU version
even faster.

* GPU based version started in previous commit, but this fixes errors
  and bugs and gets it actually compiling and running.
* Add a way to batch together images to use the same render pass for GPU
  premultiplication if they all target the same texture.
* Pending premultiplication uploads are automatically done when calling
  `Drawer::third_pass`.
* `fast-srgb8` dep removed, we no longer convert to `f32`s to do the
  premultiplication. Two `[u16; 256]` tables are combined to compute the
  alpa premultiplied color within the same error bounds used by the
  `fast-srgb8` crate. We also no longer use explicit simd.
* Remove explicit lifetimes from `PlayState::render` since `&self` and
  `Drawer<'_>` don't need to have the same lifetime.
* Fix existing bug where invalidated cache entries were never set to
  valid when reusing them.
* `prepare_graphic` now runs some heuristics to determine whether
  premultiplication should be executed CPU side or GPU side and then
  returns a bool indicating if GPU premultiplication is needed.
2023-04-08 00:28:31 -04:00

18 lines
589 B
GLSL

#version 420 core
#extension GL_EXT_samplerless_texture_functions : enable
layout(set = 0, binding = 0)
uniform texture2D source_texture;
layout(location = 0) in vec2 source_coords;
layout(location = 0) out vec4 target_color;
void main() {
// We get free nonlinear -> linear conversion when sampling from srgb texture;
vec4 linear = texelFetch(source_texture, ivec2(source_coords), 0);
vec4 premultiplied_linear = vec4(linear.rgb * linear.a, linear.a);
// We get free linear -> nonlinear conversion rendering to srgb texture.
target_color = premultiplied_linear;
}