Blender  V3.3
COM_ZCombineOperation.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 {
15 
16  image1Reader_ = nullptr;
17  depth1Reader_ = nullptr;
18  image2Reader_ = nullptr;
19  depth2Reader_ = nullptr;
20  flags_.can_be_constant = true;
21 }
22 
24 {
29 }
30 
32  float x,
33  float y,
35 {
36  float depth1[4];
37  float depth2[4];
38 
39  depth1Reader_->read_sampled(depth1, x, y, sampler);
40  depth2Reader_->read_sampled(depth2, x, y, sampler);
41  if (depth1[0] < depth2[0]) {
43  }
44  else {
46  }
47 }
48 
50  const rcti &area,
52 {
53  for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
54  const float depth1 = *it.in(1);
55  const float depth2 = *it.in(3);
56  const float *color = (depth1 < depth2) ? it.in(0) : it.in(2);
57  copy_v4_v4(it.out, color);
58  }
59 }
60 
61 void ZCombineAlphaOperation::execute_pixel_sampled(float output[4],
62  float x,
63  float y,
65 {
66  float depth1[4];
67  float depth2[4];
68  float color1[4];
69  float color2[4];
70 
71  depth1Reader_->read_sampled(depth1, x, y, sampler);
72  depth2Reader_->read_sampled(depth2, x, y, sampler);
73  if (depth1[0] <= depth2[0]) {
74  image1Reader_->read_sampled(color1, x, y, sampler);
75  image2Reader_->read_sampled(color2, x, y, sampler);
76  }
77  else {
78  image1Reader_->read_sampled(color2, x, y, sampler);
79  image2Reader_->read_sampled(color1, x, y, sampler);
80  }
81  float fac = color1[3];
82  float ifac = 1.0f - fac;
83  output[0] = fac * color1[0] + ifac * color2[0];
84  output[1] = fac * color1[1] + ifac * color2[1];
85  output[2] = fac * color1[2] + ifac * color2[2];
86  output[3] = MAX2(color1[3], color2[3]);
87 }
88 
89 void ZCombineAlphaOperation::update_memory_buffer_partial(MemoryBuffer *output,
90  const rcti &area,
91  Span<MemoryBuffer *> inputs)
92 {
93  for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
94  const float depth1 = *it.in(1);
95  const float depth2 = *it.in(3);
96  const float *color1;
97  const float *color2;
98  if (depth1 <= depth2) {
99  color1 = it.in(0);
100  color2 = it.in(2);
101  }
102  else {
103  color1 = it.in(2);
104  color2 = it.in(0);
105  }
106  const float fac = color1[3];
107  const float ifac = 1.0f - fac;
108  it.out[0] = fac * color1[0] + ifac * color2[0];
109  it.out[1] = fac * color1[1] + ifac * color2[1];
110  it.out[2] = fac * color1[2] + ifac * color2[2];
111  it.out[3] = MAX2(color1[3], color2[3]);
112  }
113 }
114 
116 {
117  image1Reader_ = nullptr;
118  depth1Reader_ = nullptr;
119  image2Reader_ = nullptr;
120  depth2Reader_ = nullptr;
121 }
122 
123 // MASK combine
125 {
126  this->add_input_socket(DataType::Value); // mask
130 
131  mask_reader_ = nullptr;
132  image1Reader_ = nullptr;
133  image2Reader_ = nullptr;
134 }
135 
137 {
141 }
142 
144  float x,
145  float y,
147 {
148  float mask[4];
149  float color1[4];
150  float color2[4];
151 
153  image1Reader_->read_sampled(color1, x, y, sampler);
154  image2Reader_->read_sampled(color2, x, y, sampler);
155 
156  interp_v4_v4v4(output, color1, color2, 1.0f - mask[0]);
157 }
158 
160  const rcti &area,
162 {
163  for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
164  const float mask = *it.in(0);
165  const float *color1 = it.in(1);
166  const float *color2 = it.in(2);
167  interp_v4_v4v4(it.out, color1, color2, 1.0f - mask);
168  }
169 }
170 
171 void ZCombineMaskAlphaOperation::execute_pixel_sampled(float output[4],
172  float x,
173  float y,
175 {
176  float mask[4];
177  float color1[4];
178  float color2[4];
179 
181  image1Reader_->read_sampled(color1, x, y, sampler);
182  image2Reader_->read_sampled(color2, x, y, sampler);
183 
184  float fac = (1.0f - mask[0]) * (1.0f - color1[3]) + mask[0] * color2[3];
185  float mfac = 1.0f - fac;
186 
187  output[0] = color1[0] * mfac + color2[0] * fac;
188  output[1] = color1[1] * mfac + color2[1] * fac;
189  output[2] = color1[2] * mfac + color2[2] * fac;
190  output[3] = MAX2(color1[3], color2[3]);
191 }
192 
193 void ZCombineMaskAlphaOperation::update_memory_buffer_partial(MemoryBuffer *output,
194  const rcti &area,
196 {
197  for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
198  const float mask = *it.in(0);
199  const float *color1 = it.in(1);
200  const float *color2 = it.in(2);
201  const float fac = (1.0f - mask) * (1.0f - color1[3]) + mask * color2[3];
202  const float mfac = 1.0f - fac;
203 
204  it.out[0] = color1[0] * mfac + color2[0] * fac;
205  it.out[1] = color1[1] * mfac + color2[1] * fac;
206  it.out[2] = color1[2] * mfac + color2[2] * fac;
207  it.out[3] = MAX2(color1[3], color2[3]);
208  }
209 }
210 
212 {
213  image1Reader_ = nullptr;
214  mask_reader_ = nullptr;
215  image2Reader_ = nullptr;
216 }
217 
218 } // namespace blender::compositor
MINLINE void copy_v4_v4(float r[4], const float a[4])
void interp_v4_v4v4(float r[4], const float a[4], const float b[4], float t)
Definition: math_vector.c:38
#define MAX2(a, b)
_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
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
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)
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
calculate a single pixel
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
depth_tx sampler(1, ImageType::FLOAT_2D, "combined_tx") .sampler(2
ccl_global KernelShaderEvalInput ccl_global float * output
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
static void area(int d1, int d2, int e1, int e2, float weights[2])
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
static bNodeSocketTemplate inputs[]