Blender  V3.3
COM_ProjectorLensDistortionOperation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
6 
7 namespace blender::compositor {
8 
10 {
14  flags_.complex = true;
15  input_program_ = nullptr;
16  dispersion_available_ = false;
17  dispersion_ = 0.0f;
18 }
19 
21 {
23  NodeOperation *dispersion_input = get_input_operation(1);
24  if (dispersion_input->get_flags().is_constant_operation) {
25  dispersion_ = static_cast<ConstantOperation *>(dispersion_input)->get_constant_elem()[0];
26  }
27  kr_ = 0.25f * max_ff(min_ff(dispersion_, 1.0f), 0.0f);
28  kr2_ = kr_ * 20;
29  }
30 }
31 
33 {
34  this->init_mutex();
35  input_program_ = this->get_input_socket_reader(0);
36 }
37 
39 {
41  void *buffer = input_program_->initialize_tile_data(nullptr);
42  return buffer;
43 }
44 
46 {
47  float input_value[4];
48  const float height = this->get_height();
49  const float width = this->get_width();
50  const float v = (y + 0.5f) / height;
51  const float u = (x + 0.5f) / width;
52  MemoryBuffer *input_buffer = (MemoryBuffer *)data;
53  input_buffer->read_bilinear(input_value, (u * width + kr2_) - 0.5f, v * height - 0.5f);
54  output[0] = input_value[0];
55  input_buffer->read(input_value, x, y);
56  output[1] = input_value[1];
57  input_buffer->read_bilinear(input_value, (u * width - kr2_) - 0.5f, v * height - 0.5f);
58  output[2] = input_value[2];
59  output[3] = 1.0f;
60 }
61 
63 {
64  this->deinit_mutex();
65  input_program_ = nullptr;
66 }
67 
69  rcti *input, ReadBufferOperation *read_operation, rcti *output)
70 {
71  rcti new_input;
72  if (dispersion_available_) {
73  new_input.ymax = input->ymax;
74  new_input.ymin = input->ymin;
75  new_input.xmin = input->xmin - kr2_ - 2;
76  new_input.xmax = input->xmax + kr2_ + 2;
77  }
78  else {
79  rcti disp_input;
80  BLI_rcti_init(&disp_input, 0, 5, 0, 5);
82  &disp_input, read_operation, output)) {
83  return true;
84  }
85  new_input.xmin = input->xmin - 7; /* (0.25f * 20 * 1) + 2 == worse case dispersion */
86  new_input.ymin = input->ymin;
87  new_input.ymax = input->ymax;
88  new_input.xmax = input->xmax + 7; /* (0.25f * 20 * 1) + 2 == worse case dispersion */
89  }
91  &new_input, read_operation, output)) {
92  return true;
93  }
94  return false;
95 }
96 
97 /* TODO(manzanilla): to be removed with tiled implementation. */
99 {
100  if (dispersion_available_) {
101  return;
102  }
103  this->lock_mutex();
104  if (!dispersion_available_) {
105  float result[4];
107  dispersion_ = result[0];
108  kr_ = 0.25f * max_ff(min_ff(dispersion_, 1.0f), 0.0f);
109  kr2_ = kr_ * 20;
110  dispersion_available_ = true;
111  }
112  this->unlock_mutex();
113 }
114 
116 {
117  switch (execution_model_) {
119  set_determined_canvas_modifier([=](rcti &canvas) {
120  /* Ensure screen space. */
121  BLI_rcti_translate(&canvas, -canvas.xmin, -canvas.ymin);
122  });
123  break;
124  }
125  default:
126  break;
127  }
128 
129  NodeOperation::determine_canvas(preferred_area, r_area);
130 }
131 
133  const rcti &output_area,
134  rcti &r_input_area)
135 {
136  if (input_idx == 1) {
137  /* Dispersion input is used as constant only. */
139  return;
140  }
141 
142  r_input_area.ymax = output_area.ymax;
143  r_input_area.ymin = output_area.ymin;
144  r_input_area.xmin = output_area.xmin - kr2_ - 2;
145  r_input_area.xmax = output_area.xmax + kr2_ + 2;
146 }
147 
149  const rcti &area,
151 {
152  const MemoryBuffer *input_image = inputs[0];
153  const float height = this->get_height();
154  const float width = this->get_width();
155  float color[4];
156  for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
157  const float v = (it.y + 0.5f) / height;
158  const float u = (it.x + 0.5f) / width;
159  input_image->read_elem_bilinear((u * width + kr2_) - 0.5f, v * height - 0.5f, color);
160  it.out[0] = color[0];
161  input_image->read_elem(it.x, it.y, color);
162  it.out[1] = color[1];
163  input_image->read_elem_bilinear((u * width - kr2_) - 0.5f, v * height - 0.5f, color);
164  it.out[2] = color[2];
165  it.out[3] = 1.0f;
166  }
167 }
168 
169 } // namespace blender::compositor
MINLINE float max_ff(float a, float b)
MINLINE float min_ff(float a, float b)
void BLI_rcti_translate(struct rcti *rect, int x, int y)
Definition: rct.c:559
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition: rct.c:417
_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 a value between a minimum and a maximum Vector Perform vector math operation Invert a color
ATTR_WARN_UNUSED_RESULT const BMVert * v
a MemoryBuffer contains access to the data of a chunk
void read(float *result, int x, int y, MemoryBufferExtend extend_x=MemoryBufferExtend::Clip, MemoryBufferExtend extend_y=MemoryBufferExtend::Clip)
void read_elem_bilinear(float x, float y, float *out) const
void read_elem(int x, int y, float *out) const
void read_bilinear(float *result, float x, float y, MemoryBufferExtend extend_x=MemoryBufferExtend::Clip, MemoryBufferExtend extend_y=MemoryBufferExtend::Clip) const
NodeOperation contains calculation logic.
void add_output_socket(DataType datatype)
const NodeOperationFlags get_flags() const
SocketReader * get_input_socket_reader(unsigned int index)
NodeOperation * get_input_operation(int index)
void read_sampled(float result[4], float x, float y, PixelSampler sampler)
void set_determined_canvas_modifier(std::function< void(rcti &canvas)> fn)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
virtual void * initialize_tile_data(rcti *)
virtual void determine_canvas(const rcti &preferred_area, rcti &r_area)
void execute_pixel(float output[4], int x, int y, void *data) override
void determine_canvas(const rcti &preferred_area, rcti &r_area) override
bool determine_depending_area_of_interest(rcti *input, ReadBufferOperation *read_operation, rcti *output) override
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) 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.
ccl_global float * buffer
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
constexpr rcti COM_CONSTANT_INPUT_AREA_OF_INTEREST
Definition: COM_defines.h:113
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