Blender  V2.93
COM_DisplaceSimpleOperation.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 2012, Blender Foundation.
17  */
18 
20 #include "BLI_math.h"
21 #include "BLI_utildefines.h"
22 
23 namespace blender::compositor {
24 
26 {
32 
33  this->m_inputColorProgram = nullptr;
34  this->m_inputVectorProgram = nullptr;
35  this->m_inputScaleXProgram = nullptr;
36  this->m_inputScaleYProgram = nullptr;
37 }
38 
40 {
41  this->m_inputColorProgram = this->getInputSocketReader(0);
42  this->m_inputVectorProgram = this->getInputSocketReader(1);
43  this->m_inputScaleXProgram = this->getInputSocketReader(2);
44  this->m_inputScaleYProgram = this->getInputSocketReader(3);
45 
46  this->m_width_x4 = this->getWidth() * 4;
47  this->m_height_x4 = this->getHeight() * 4;
48 }
49 
50 /* minimum distance (in pixels) a pixel has to be displaced
51  * in order to take effect */
52 // #define DISPLACE_EPSILON 0.01f
53 
55  float x,
56  float y,
57  PixelSampler sampler)
58 {
59  float inVector[4];
60  float inScale[4];
61 
62  float p_dx, p_dy; /* main displacement in pixel space */
63  float u, v;
64 
65  this->m_inputScaleXProgram->readSampled(inScale, x, y, sampler);
66  float xs = inScale[0];
67  this->m_inputScaleYProgram->readSampled(inScale, x, y, sampler);
68  float ys = inScale[0];
69 
70  /* clamp x and y displacement to triple image resolution -
71  * to prevent hangs from huge values mistakenly plugged in eg. z buffers */
72  CLAMP(xs, -this->m_width_x4, this->m_width_x4);
73  CLAMP(ys, -this->m_height_x4, this->m_height_x4);
74 
75  this->m_inputVectorProgram->readSampled(inVector, x, y, sampler);
76  p_dx = inVector[0] * xs;
77  p_dy = inVector[1] * ys;
78 
79  /* displaced pixel in uv coords, for image sampling */
80  /* clamp nodes to avoid glitches */
81  u = x - p_dx + 0.5f;
82  v = y - p_dy + 0.5f;
83  CLAMP(u, 0.0f, this->getWidth() - 1.0f);
84  CLAMP(v, 0.0f, this->getHeight() - 1.0f);
85 
86  this->m_inputColorProgram->readSampled(output, u, v, sampler);
87 }
88 
90 {
91  this->m_inputColorProgram = nullptr;
92  this->m_inputVectorProgram = nullptr;
93  this->m_inputScaleXProgram = nullptr;
94  this->m_inputScaleYProgram = nullptr;
95 }
96 
98  ReadBufferOperation *readOperation,
99  rcti *output)
100 {
101  rcti colorInput;
102  NodeOperation *operation = nullptr;
103 
104  /* the vector buffer only needs a 2x2 buffer. The image needs whole buffer */
105  /* image */
106  operation = getInputOperation(0);
107  colorInput.xmax = operation->getWidth();
108  colorInput.xmin = 0;
109  colorInput.ymax = operation->getHeight();
110  colorInput.ymin = 0;
111  if (operation->determineDependingAreaOfInterest(&colorInput, readOperation, output)) {
112  return true;
113  }
114 
115  /* vector */
116  if (operation->determineDependingAreaOfInterest(input, readOperation, output)) {
117  return true;
118  }
119 
120  /* scale x */
121  operation = getInputOperation(2);
122  if (operation->determineDependingAreaOfInterest(input, readOperation, output)) {
123  return true;
124  }
125 
126  /* scale y */
127  operation = getInputOperation(3);
128  if (operation->determineDependingAreaOfInterest(input, readOperation, output)) {
129  return true;
130  }
131 
132  return false;
133 }
134 
135 } // namespace blender::compositor
_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 RGB to Bright Vector Camera CLAMP
ATTR_WARN_UNUSED_RESULT const BMVert * v
#define output
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) override
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override
NodeOperation contains calculation logic.
void readSampled(float result[4], float x, float y, PixelSampler sampler)
void addInputSocket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
NodeOperation * getInputOperation(unsigned int inputSocketindex)
void addOutputSocket(DataType datatype)
SocketReader * getInputSocketReader(unsigned int inputSocketindex)
virtual bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
@ Vector
Vector data type.
int ymin
Definition: DNA_vec_types.h:80
int ymax
Definition: DNA_vec_types.h:80
int xmin
Definition: DNA_vec_types.h:79
int xmax
Definition: DNA_vec_types.h:79