Blender  V3.3
COM_DisplaceSimpleOperation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2012 Blender Foundation. */
3 
5 
6 namespace blender::compositor {
7 
9 {
15 
16  input_color_program_ = nullptr;
17  input_vector_program_ = nullptr;
18  input_scale_xprogram_ = nullptr;
19  input_scale_yprogram_ = nullptr;
20 }
21 
23 {
24  input_color_program_ = this->get_input_socket_reader(0);
25  input_vector_program_ = this->get_input_socket_reader(1);
26  input_scale_xprogram_ = this->get_input_socket_reader(2);
27  input_scale_yprogram_ = this->get_input_socket_reader(3);
28 
29  width_x4_ = this->get_width() * 4;
30  height_x4_ = this->get_height() * 4;
31 }
32 
33 /* minimum distance (in pixels) a pixel has to be displaced
34  * in order to take effect */
35 // #define DISPLACE_EPSILON 0.01f
36 
38  float x,
39  float y,
41 {
42  float in_vector[4];
43  float in_scale[4];
44 
45  float p_dx, p_dy; /* main displacement in pixel space */
46  float u, v;
47 
48  input_scale_xprogram_->read_sampled(in_scale, x, y, sampler);
49  float xs = in_scale[0];
50  input_scale_yprogram_->read_sampled(in_scale, x, y, sampler);
51  float ys = in_scale[0];
52 
53  /* clamp x and y displacement to triple image resolution -
54  * to prevent hangs from huge values mistakenly plugged in eg. z buffers */
55  CLAMP(xs, -width_x4_, width_x4_);
56  CLAMP(ys, -height_x4_, height_x4_);
57 
58  input_vector_program_->read_sampled(in_vector, x, y, sampler);
59  p_dx = in_vector[0] * xs;
60  p_dy = in_vector[1] * ys;
61 
62  /* displaced pixel in uv coords, for image sampling */
63  /* clamp nodes to avoid glitches */
64  u = x - p_dx + 0.5f;
65  v = y - p_dy + 0.5f;
66  CLAMP(u, 0.0f, this->get_width() - 1.0f);
67  CLAMP(v, 0.0f, this->get_height() - 1.0f);
68 
69  input_color_program_->read_sampled(output, u, v, sampler);
70 }
71 
73 {
74  input_color_program_ = nullptr;
75  input_vector_program_ = nullptr;
76  input_scale_xprogram_ = nullptr;
77  input_scale_yprogram_ = nullptr;
78 }
79 
81  rcti *input, ReadBufferOperation *read_operation, rcti *output)
82 {
83  rcti color_input;
84  NodeOperation *operation = nullptr;
85 
86  /* the vector buffer only needs a 2x2 buffer. The image needs whole buffer */
87  /* image */
88  operation = get_input_operation(0);
89  color_input.xmax = operation->get_width();
90  color_input.xmin = 0;
91  color_input.ymax = operation->get_height();
92  color_input.ymin = 0;
93  if (operation->determine_depending_area_of_interest(&color_input, read_operation, output)) {
94  return true;
95  }
96 
97  /* vector */
98  if (operation->determine_depending_area_of_interest(input, read_operation, output)) {
99  return true;
100  }
101 
102  /* scale x */
103  operation = get_input_operation(2);
104  if (operation->determine_depending_area_of_interest(input, read_operation, output)) {
105  return true;
106  }
107 
108  /* scale y */
109  operation = get_input_operation(3);
110  if (operation->determine_depending_area_of_interest(input, read_operation, output)) {
111  return true;
112  }
113 
114  return false;
115 }
116 
118  const rcti &output_area,
119  rcti &r_input_area)
120 {
121  switch (input_idx) {
122  case 0: {
123  r_input_area = get_input_operation(input_idx)->get_canvas();
124  break;
125  }
126  default: {
127  r_input_area = output_area;
128  break;
129  }
130  }
131 }
132 
134  const rcti &area,
136 {
137  const float width = this->get_width();
138  const float height = this->get_height();
139  const MemoryBuffer *input_color = inputs[0];
140  for (BuffersIterator<float> it = output->iterate_with(inputs.drop_front(1), area); !it.is_end();
141  ++it) {
142  float scale_x = *it.in(1);
143  float scale_y = *it.in(2);
144 
145  /* Clamp x and y displacement to triple image resolution -
146  * to prevent hangs from huge values mistakenly plugged in eg. z buffers. */
147  CLAMP(scale_x, -width_x4_, width_x4_);
148  CLAMP(scale_y, -height_x4_, height_x4_);
149 
150  /* Main displacement in pixel space. */
151  const float *vector = it.in(0);
152  const float p_dx = vector[0] * scale_x;
153  const float p_dy = vector[1] * scale_y;
154 
155  /* Displaced pixel in uv coords, for image sampling. */
156  /* Clamp nodes to avoid glitches. */
157  float u = it.x - p_dx + 0.5f;
158  float v = it.y - p_dy + 0.5f;
159  CLAMP(u, 0.0f, width - 1.0f);
160  CLAMP(v, 0.0f, height - 1.0f);
161 
162  input_color->read_elem_checked(u, v, it.out);
163  }
164 }
165 
166 } // namespace blender::compositor
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_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
_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 GLsizei width
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
ATTR_WARN_UNUSED_RESULT const BMVert * v
bool determine_depending_area_of_interest(rcti *input, ReadBufferOperation *read_operation, rcti *output) override
void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override
void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override
Get input operation area being read by this operation on rendering given output area.
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
a MemoryBuffer contains access to the data of a chunk
void read_elem_checked(int x, int y, float *out) const
NodeOperation contains calculation logic.
void add_output_socket(DataType datatype)
SocketReader * get_input_socket_reader(unsigned int index)
NodeOperation * get_input_operation(int index)
virtual bool determine_depending_area_of_interest(rcti *input, ReadBufferOperation *read_operation, rcti *output)
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
@ Vector
Vector data type.
ccl_global KernelShaderEvalInput ccl_global float * output
ccl_global KernelShaderEvalInput * input
static void area(int d1, int d2, int e1, int e2, float weights[2])
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
static bNodeSocketTemplate inputs[]
int ymin
Definition: DNA_vec_types.h:64
int ymax
Definition: DNA_vec_types.h:64
int xmin
Definition: DNA_vec_types.h:63
int xmax
Definition: DNA_vec_types.h:63