Blender  V3.3
COM_DistanceRGBMatteOperation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
5 
6 namespace blender::compositor {
7 
9 {
13 
14  input_image_program_ = nullptr;
15  input_key_program_ = nullptr;
16  flags_.can_be_constant = true;
17 }
18 
20 {
23 }
24 
26 {
27  input_image_program_ = nullptr;
28  input_key_program_ = nullptr;
29 }
30 
31 float DistanceRGBMatteOperation::calculate_distance(const float key[4], const float image[4])
32 {
33  return len_v3v3(key, image);
34 }
35 
37  float x,
38  float y,
40 {
41  float in_key[4];
42  float in_image[4];
43 
44  const float tolerance = settings_->t1;
45  const float falloff = settings_->t2;
46 
47  float distance;
48  float alpha;
49 
52 
53  distance = this->calculate_distance(in_key, in_image);
54 
55  /* Store matte(alpha) value in [0] to go with
56  * COM_SetAlphaMultiplyOperation and the Value output.
57  */
58 
59  /* Make 100% transparent. */
60  if (distance < tolerance) {
61  output[0] = 0.0f;
62  }
63  /* In the falloff region, make partially transparent. */
64  else if (distance < falloff + tolerance) {
65  distance = distance - tolerance;
66  alpha = distance / falloff;
67  /* Only change if more transparent than before. */
68  if (alpha < in_image[3]) {
69  output[0] = alpha;
70  }
71  else { /* leave as before */
72  output[0] = in_image[3];
73  }
74  }
75  else {
76  /* leave as before */
77  output[0] = in_image[3];
78  }
79 }
80 
82  const rcti &area,
84 {
85  for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
86  const float *in_image = it.in(0);
87  const float *in_key = it.in(1);
88 
89  float distance = this->calculate_distance(in_key, in_image);
90  const float tolerance = settings_->t1;
91  const float falloff = settings_->t2;
92 
93  /* Store matte(alpha) value in [0] to go with
94  * COM_SetAlphaMultiplyOperation and the Value output.
95  */
96 
97  /* Make 100% transparent. */
98  if (distance < tolerance) {
99  it.out[0] = 0.0f;
100  }
101  /* In the falloff region, make partially transparent. */
102  else if (distance < falloff + tolerance) {
103  distance = distance - tolerance;
104  const float alpha = distance / falloff;
105  /* Only change if more transparent than before. */
106  if (alpha < in_image[3]) {
107  it.out[0] = alpha;
108  }
109  else { /* Leave as before. */
110  it.out[0] = in_image[3];
111  }
112  }
113  else {
114  /* Leave as before. */
115  it.out[0] = in_image[3];
116  }
117  }
118 }
119 
120 } // namespace blender::compositor
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
virtual float calculate_distance(const float key[4], const float image[4])
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override
a MemoryBuffer contains access to the data of a chunk
void add_output_socket(DataType datatype)
SocketReader * get_input_socket_reader(unsigned int index)
void read_sampled(float result[4], float x, float y, PixelSampler sampler)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
depth_tx sampler(1, ImageType::FLOAT_2D, "combined_tx") .sampler(2
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img image(1, GPU_R32F, Qualifier::WRITE, ImageType::FLOAT_2D_ARRAY, "out_weight_img") .image(3
ccl_global KernelShaderEvalInput ccl_global float * output
static void area(int d1, int d2, int e1, int e2, float weights[2])
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
T distance(const T &a, const T &b)
static bNodeSocketTemplate inputs[]