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

gpu_shader_compositor_color_matte.glsl « library « compositor « shaders « gpu « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 038471bc1bc0d48cedc970e729482ccc541a96c4 (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
#pragma BLENDER_REQUIRE(gpu_shader_common_color_utils.glsl)

void node_composite_color_matte(vec4 color,
                                vec4 key,
                                float hue_epsilon,
                                float saturation_epsilon,
                                float value_epsilon,
                                out vec4 result,
                                out float matte)

{
  vec4 color_hsva;
  rgb_to_hsv(color, color_hsva);
  vec4 key_hsva;
  rgb_to_hsv(key, key_hsva);

  bool is_within_saturation = distance(color_hsva.y, key_hsva.y) < saturation_epsilon;
  bool is_within_value = distance(color_hsva.z, key_hsva.z) < value_epsilon;
  bool is_within_hue = distance(color_hsva.x, key_hsva.x) < hue_epsilon;
  /* Hue wraps around, so check the distance around the boundary. */
  float min_hue = min(color_hsva.x, key_hsva.x);
  float max_hue = max(color_hsva.x, key_hsva.x);
  is_within_hue = is_within_hue || ((min_hue + (1.0 - max_hue)) < hue_epsilon);

  matte = (is_within_hue && is_within_saturation && is_within_value) ? 0.0 : color.a;
  result = color * matte;
}