Blender  V2.93
COM_ZCombineOperation.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2011, Blender Foundation.
17  */
18 
19 #include "COM_ZCombineOperation.h"
20 #include "BLI_utildefines.h"
21 
22 namespace blender::compositor {
23 
25 {
31 
32  this->m_image1Reader = nullptr;
33  this->m_depth1Reader = nullptr;
34  this->m_image2Reader = nullptr;
35  this->m_depth2Reader = nullptr;
36 }
37 
39 {
40  this->m_image1Reader = this->getInputSocketReader(0);
41  this->m_depth1Reader = this->getInputSocketReader(1);
42  this->m_image2Reader = this->getInputSocketReader(2);
43  this->m_depth2Reader = this->getInputSocketReader(3);
44 }
45 
47  float x,
48  float y,
49  PixelSampler sampler)
50 {
51  float depth1[4];
52  float depth2[4];
53 
54  this->m_depth1Reader->readSampled(depth1, x, y, sampler);
55  this->m_depth2Reader->readSampled(depth2, x, y, sampler);
56  if (depth1[0] < depth2[0]) {
57  this->m_image1Reader->readSampled(output, x, y, sampler);
58  }
59  else {
60  this->m_image2Reader->readSampled(output, x, y, sampler);
61  }
62 }
63 void ZCombineAlphaOperation::executePixelSampled(float output[4],
64  float x,
65  float y,
66  PixelSampler sampler)
67 {
68  float depth1[4];
69  float depth2[4];
70  float color1[4];
71  float color2[4];
72 
73  this->m_depth1Reader->readSampled(depth1, x, y, sampler);
74  this->m_depth2Reader->readSampled(depth2, x, y, sampler);
75  if (depth1[0] <= depth2[0]) {
76  this->m_image1Reader->readSampled(color1, x, y, sampler);
77  this->m_image2Reader->readSampled(color2, x, y, sampler);
78  }
79  else {
80  this->m_image1Reader->readSampled(color2, x, y, sampler);
81  this->m_image2Reader->readSampled(color1, x, y, sampler);
82  }
83  float fac = color1[3];
84  float ifac = 1.0f - fac;
85  output[0] = fac * color1[0] + ifac * color2[0];
86  output[1] = fac * color1[1] + ifac * color2[1];
87  output[2] = fac * color1[2] + ifac * color2[2];
88  output[3] = MAX2(color1[3], color2[3]);
89 }
90 
92 {
93  this->m_image1Reader = nullptr;
94  this->m_depth1Reader = nullptr;
95  this->m_image2Reader = nullptr;
96  this->m_depth2Reader = nullptr;
97 }
98 
99 // MASK combine
101 {
102  this->addInputSocket(DataType::Value); // mask
106 
107  this->m_maskReader = nullptr;
108  this->m_image1Reader = nullptr;
109  this->m_image2Reader = nullptr;
110 }
111 
113 {
114  this->m_maskReader = this->getInputSocketReader(0);
115  this->m_image1Reader = this->getInputSocketReader(1);
116  this->m_image2Reader = this->getInputSocketReader(2);
117 }
118 
120  float x,
121  float y,
122  PixelSampler sampler)
123 {
124  float mask[4];
125  float color1[4];
126  float color2[4];
127 
128  this->m_maskReader->readSampled(mask, x, y, sampler);
129  this->m_image1Reader->readSampled(color1, x, y, sampler);
130  this->m_image2Reader->readSampled(color2, x, y, sampler);
131 
132  interp_v4_v4v4(output, color1, color2, 1.0f - mask[0]);
133 }
134 
135 void ZCombineMaskAlphaOperation::executePixelSampled(float output[4],
136  float x,
137  float y,
138  PixelSampler sampler)
139 {
140  float mask[4];
141  float color1[4];
142  float color2[4];
143 
144  this->m_maskReader->readSampled(mask, x, y, sampler);
145  this->m_image1Reader->readSampled(color1, x, y, sampler);
146  this->m_image2Reader->readSampled(color2, x, y, sampler);
147 
148  float fac = (1.0f - mask[0]) * (1.0f - color1[3]) + mask[0] * color2[3];
149  float mfac = 1.0f - fac;
150 
151  output[0] = color1[0] * mfac + color2[0] * fac;
152  output[1] = color1[1] * mfac + color2[1] * fac;
153  output[2] = color1[2] * mfac + color2[2] * fac;
154  output[3] = MAX2(color1[3], color2[3]);
155 }
156 
158 {
159  this->m_image1Reader = nullptr;
160  this->m_maskReader = nullptr;
161  this->m_image2Reader = nullptr;
162 }
163 
164 } // namespace blender::compositor
void interp_v4_v4v4(float r[4], const float a[4], const float b[4], const float t)
Definition: math_vector.c:58
#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
#define output
void readSampled(float result[4], float x, float y, PixelSampler sampler)
void addInputSocket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
void addOutputSocket(DataType datatype)
SocketReader * getInputSocketReader(unsigned int inputSocketindex)
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)