Welcome to mirror list, hosted at ThFree Co, Russian Federation.

paint_texture_frag.glsl « shaders « modes « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5d74213a44563c284e9c86cde2185adf17826105 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

in vec2 uv_interp;
#ifdef TEXTURE_PAINT_MASK
in vec2 masking_uv_interp;
#endif

out vec4 fragColor;

uniform sampler2D image;
uniform float alpha = 1.0;
uniform bool nearestInterp;

#ifdef TEXTURE_PAINT_MASK
uniform sampler2D maskingImage;
uniform vec3 maskingColor;
uniform bool maskingInvertStencil;
#endif

float linearrgb_to_srgb(float c)
{
  if (c < 0.0031308) {
    return (c < 0.0) ? 0.0 : c * 12.92;
  }
  else {
    return 1.055 * pow(c, 1.0 / 2.4) - 0.055;
  }
}

vec4 texture_read_as_srgb(sampler2D tex, vec2 co)
{
  /* By convention image textures return scene linear colors, but
   * overlays still assume srgb. */
  vec4 color = texture2D(tex, co);
  color.r = linearrgb_to_srgb(color.r);
  color.g = linearrgb_to_srgb(color.g);
  color.b = linearrgb_to_srgb(color.b);
  return color;
}

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, uv);
  color.a *= alpha;

#ifdef TEXTURE_PAINT_MASK
  vec4 mask = vec4(texture(maskingImage, 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;
}