This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/draw/engines/overlay/shaders/image_frag.glsl
Clément Foucault 0961ce04cb Fix T78124 Overlay: Image: Camera background image transparency not working
This changes to premultiplied blending for all cases and put the premult
in the shader.
2020-07-03 01:48:39 +02:00

33 lines
636 B
GLSL

uniform sampler2D imgTexture;
uniform bool imgPremultiplied;
uniform bool imgAlphaBlend;
uniform vec4 color;
in vec2 uvs;
out vec4 fragColor;
void main()
{
vec2 uvs_clamped = clamp(uvs, 0.0, 1.0);
vec4 tex_color;
tex_color = texture_read_as_linearrgb(imgTexture, imgPremultiplied, uvs_clamped);
fragColor = tex_color * color;
if (!imgAlphaBlend) {
/* Arbitrary discard anything below 5% opacity.
* Note that this could be exposed to the User. */
if (tex_color.a < 0.05) {
discard;
}
else {
fragColor.a = 1.0;
}
}
/* Pre-multiplied blending. */
fragColor.rgb *= fragColor.a;
}