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/modes/shaders/paint_texture_frag.glsl
Jeroen Bakker fed6c1a970 Fix T62876: Camera Background Images
Migrate old legacy code to the draw mamager/object mode. The old legacy
version did not work with wireframe. By migrating the code
to modern draw manager code we have mode control on the drawing process.

Still background images do not work with OIT, the cause seems to be that the transparent pixels are treated as background pixels.
Also There are some artifacts when working with Holdouts and DoF, this
is because the draw engines do not pass the correct alpha values.

Reviewers: fclem, brecht

Differential Revision: https://developer.blender.org/D4638
2019-06-21 09:53:51 +02:00

45 lines
1020 B
GLSL

in vec2 uv_interp;
#ifdef TEXTURE_PAINT_MASK
in vec2 masking_uv_interp;
#endif
out vec4 fragColor;
uniform sampler2D image;
uniform bool imagePremultiplied;
uniform float alpha = 1.0;
uniform bool nearestInterp;
#ifdef TEXTURE_PAINT_MASK
uniform sampler2D maskingImage;
uniform bool maskingImagePremultiplied;
uniform vec3 maskingColor;
uniform bool maskingInvertStencil;
#endif
void main()
{
vec2 uv = uv_interp;
if (nearestInterp) {
vec2 tex_size = vec2(textureSize(image, 0).xy);
uv = (floor(uv_interp * tex_size) + 0.5) / tex_size;
}
vec4 color = texture_read_as_srgb(image, imagePremultiplied, uv);
color.a *= alpha;
#ifdef TEXTURE_PAINT_MASK
vec4 mask = vec4(
texture_read_as_srgb(maskingImage, maskingImagePremultiplied, masking_uv_interp).rgb, 1.0);
if (maskingInvertStencil) {
mask.rgb = 1.0 - mask.rgb;
}
float mask_step = smoothstep(0, 3.0, mask.r + mask.g + mask.b);
mask.rgb *= maskingColor;
color = mix(color, mask, mask_step);
#endif
fragColor = color;
}