Blender  V3.3
COM_TextureOperation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
4 #include "COM_TextureOperation.h"
5 #include "COM_WorkScheduler.h"
6 
7 #include "BKE_image.h"
8 #include "BKE_node.h"
9 #include "BKE_scene.h"
10 
11 #include "NOD_texture.h"
12 
13 namespace blender::compositor {
14 
16 {
17  this->add_input_socket(DataType::Vector); // offset
18  this->add_input_socket(DataType::Vector); // size
19  texture_ = nullptr;
20  input_size_ = nullptr;
21  input_offset_ = nullptr;
22  rd_ = nullptr;
23  pool_ = nullptr;
24  scene_color_manage_ = false;
25  flags_.complex = true;
26 }
28 {
30 }
32 {
34 }
35 
37 {
38  input_offset_ = get_input_socket_reader(0);
39  input_size_ = get_input_socket_reader(1);
40  pool_ = BKE_image_pool_new();
41  if (texture_ != nullptr && texture_->nodetree != nullptr && texture_->use_nodes) {
43  }
45 }
47 {
48  input_size_ = nullptr;
49  input_offset_ = nullptr;
50  BKE_image_pool_free(pool_);
51  pool_ = nullptr;
52  if (texture_ != nullptr && texture_->use_nodes && texture_->nodetree != nullptr &&
53  texture_->nodetree->execdata != nullptr) {
55  }
57 }
58 
59 void TextureBaseOperation::determine_canvas(const rcti &preferred_area, rcti &r_area)
60 {
61  r_area = preferred_area;
62  if (BLI_rcti_is_empty(&preferred_area)) {
63  int width, height;
64  BKE_render_resolution(rd_, false, &width, &height);
65  r_area.xmax = preferred_area.xmin + width;
66  r_area.ymax = preferred_area.ymin + height;
67  }
68 
70  /* Determine inputs. */
71  rcti temp = COM_AREA_NONE;
72  NodeOperation::determine_canvas(r_area, temp);
73  }
74 }
75 
77  float x,
78  float y,
80 {
81  float color[4];
83  output[0] = color[3];
84 }
85 
87  float x,
88  float y,
90 {
91  TexResult texres = {0.0f};
92  float texture_size[4];
93  float texture_offset[4];
94  float vec[3];
95  int retval;
96  const float cx = this->get_width() / 2;
97  const float cy = this->get_height() / 2;
98  float u = (x - cx) / this->get_width() * 2;
99  float v = (y - cy) / this->get_height() * 2;
100 
101  /* When no interpolation/filtering happens in multitex() force nearest interpolation.
102  * We do it here because (a) we can't easily say multitex() that we want nearest
103  * interpolation and (b) in such configuration multitex() simply floor's the value
104  * which often produces artifacts.
105  */
106  if (texture_ != nullptr && (texture_->imaflag & TEX_INTERPOL) == 0) {
107  u += 0.5f / cx;
108  v += 0.5f / cy;
109  }
110 
111  input_size_->read_sampled(texture_size, x, y, sampler);
112  input_offset_->read_sampled(texture_offset, x, y, sampler);
113 
114  vec[0] = texture_size[0] * (u + texture_offset[0]);
115  vec[1] = texture_size[1] * (v + texture_offset[1]);
116  vec[2] = texture_size[2] * texture_offset[2];
117 
119  retval = multitex_ext(
120  texture_, vec, nullptr, nullptr, 0, &texres, thread_id, pool_, scene_color_manage_, false);
121 
122  output[3] = texres.talpha ? texres.trgba[3] : texres.tin;
123  if (retval & TEX_RGB) {
124  copy_v3_v3(output, texres.trgba);
125  }
126  else {
127  output[0] = output[1] = output[2] = output[3];
128  }
129 }
130 
132  const rcti &area,
134 {
135  const int op_width = this->get_width();
136  const int op_height = this->get_height();
137  const float center_x = op_width / 2;
138  const float center_y = op_height / 2;
139  TexResult tex_result = {0};
140  float vec[3];
142  for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
143  const float *tex_offset = it.in(0);
144  const float *tex_size = it.in(1);
145  float u = (it.x - center_x) / op_width * 2;
146  float v = (it.y - center_y) / op_height * 2;
147 
148  /* When no interpolation/filtering happens in multitex() force nearest interpolation.
149  * We do it here because (a) we can't easily say multitex() that we want nearest
150  * interpolation and (b) in such configuration multitex() simply floor's the value
151  * which often produces artifacts.
152  */
153  if (texture_ != nullptr && (texture_->imaflag & TEX_INTERPOL) == 0) {
154  u += 0.5f / center_x;
155  v += 0.5f / center_y;
156  }
157 
158  vec[0] = tex_size[0] * (u + tex_offset[0]);
159  vec[1] = tex_size[1] * (v + tex_offset[1]);
160  vec[2] = tex_size[2] * tex_offset[2];
161 
162  const int retval = multitex_ext(texture_,
163  vec,
164  nullptr,
165  nullptr,
166  0,
167  &tex_result,
168  thread_id,
169  pool_,
170  scene_color_manage_,
171  false);
172 
173  it.out[3] = tex_result.talpha ? tex_result.trgba[3] : tex_result.tin;
174  if (retval & TEX_RGB) {
175  copy_v3_v3(it.out, tex_result.trgba);
176  }
177  else {
178  it.out[0] = it.out[1] = it.out[2] = it.out[3];
179  }
180  }
181 }
182 
184  const rcti &area,
186 {
189  output->copy_from(&texture, area, 3, COM_DATA_TYPE_VALUE_CHANNELS, 0);
190 }
191 
192 } // namespace blender::compositor
struct ImagePool * BKE_image_pool_new(void)
void BKE_image_pool_free(struct ImagePool *pool)
void BKE_render_resolution(const struct RenderData *r, const bool use_crop, int *r_width, int *r_height)
Definition: scene.cc:2960
MINLINE void copy_v3_v3(float r[3], const float a[3])
bool BLI_rcti_is_empty(const struct rcti *rect)
#define TEX_RGB
#define TEX_INTERPOL
_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
void ntreeTexEndExecTree(struct bNodeTreeExec *exec)
struct bNodeTreeExec * ntreeTexBeginExecTree(struct bNodeTree *ntree)
ATTR_WARN_UNUSED_RESULT const BMVert * v
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)
virtual void determine_canvas(const rcti &preferred_area, rcti &r_area)
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
calculate a single pixel
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
void determine_canvas(const rcti &preferred_area, rcti &r_area) override
depth_tx sampler(1, ImageType::FLOAT_2D, "combined_tx") .sampler(2
@ Vector
Vector data type.
ccl_global KernelShaderEvalInput ccl_global float * output
static void area(int d1, int d2, int e1, int e2, float weights[2])
constexpr int COM_DATA_TYPE_VALUE_CHANNELS
Definition: COM_defines.h:60
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
constexpr rcti COM_AREA_NONE
Definition: COM_defines.h:112
static bNodeSocketTemplate inputs[]
int talpha
Definition: RE_texture.h:89
float tin
Definition: RE_texture.h:86
float trgba[4]
Definition: RE_texture.h:87
short imaflag
char use_nodes
struct bNodeTree * nodetree
struct bNodeTreeExec * execdata
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
int multitex_ext(Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, TexResult *texres, const short thread, struct ImagePool *pool, bool scene_color_manage, const bool skip_load_image)