Blender V4.3
COM_TextureOperation.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6#include "COM_WorkScheduler.h"
7
8#include "BKE_image.hh"
9#include "BKE_node.hh"
10#include "BKE_scene.hh"
11
12#include "NOD_texture.h"
13
14namespace blender::compositor {
15
17{
18 this->add_input_socket(DataType::Vector); // offset
20 texture_ = nullptr;
21 rd_ = nullptr;
22 pool_ = nullptr;
23 scene_color_manage_ = false;
24}
33
35{
36 pool_ = BKE_image_pool_new();
37 if (texture_ != nullptr && texture_->nodetree != nullptr && texture_->use_nodes) {
39 }
41}
43{
45 pool_ = nullptr;
46 if (texture_ != nullptr && texture_->use_nodes && texture_->nodetree != nullptr &&
47 texture_->nodetree->runtime->execdata != nullptr)
48 {
49 ntreeTexEndExecTree(texture_->nodetree->runtime->execdata);
50 }
52}
53
54void TextureBaseOperation::determine_canvas(const rcti &preferred_area, rcti &r_area)
55{
56 r_area = preferred_area;
57 if (BLI_rcti_is_empty(&preferred_area)) {
58 int width, height;
59 BKE_render_resolution(rd_, false, &width, &height);
60 r_area.xmax = preferred_area.xmin + width;
61 r_area.ymax = preferred_area.ymin + height;
62 }
63
64 /* Determine inputs. */
65 rcti temp = COM_AREA_NONE;
67}
68
70 const rcti &area,
72{
73 const float3 offset = inputs[0]->get_elem(0, 0);
74 const float3 scale = inputs[1]->get_elem(0, 0);
75 const int2 size = int2(this->get_width(), this->get_height());
76 for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
77 /* Compute the coordinates in the [-1, 1] range and add 0.5 to evaluate the texture at the
78 * center of pixels in case it was interpolated. */
79 const float2 pixel_coordinates = ((float2(it.x, it.y) + 0.5f) / float2(size)) * 2.0f - 1.0f;
80 /* Note that it is expected that the offset is scaled by the scale. */
81 const float3 coordinates = (float3(pixel_coordinates, 0.0f) + offset) * scale;
82
83 TexResult texture_result;
84 const int result_type = multitex_ext(texture_,
85 coordinates,
86 nullptr,
87 nullptr,
88 0,
89 &texture_result,
91 pool_,
92 scene_color_manage_,
93 false);
94
95 float4 color = float4(texture_result.trgba);
96 color.w = texture_result.talpha ? color.w : texture_result.tin;
97 if (!(result_type & TEX_RGB)) {
98 copy_v3_fl(color, color.w);
99 }
100 copy_v4_v4(it.out, color);
101 }
102}
103
105 const rcti &area,
107{
110 output->copy_from(&texture, area, 3, COM_DATA_TYPE_VALUE_CHANNELS, 0);
111}
112
113} // namespace blender::compositor
void BKE_image_pool_free(ImagePool *pool)
ImagePool * BKE_image_pool_new(void)
void BKE_render_resolution(const RenderData *r, const bool use_crop, int *r_width, int *r_height)
Definition scene.cc:2877
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE void copy_v3_fl(float r[3], float f)
bool BLI_rcti_is_empty(const struct rcti *rect)
@ TEX_RGB
void ntreeTexEndExecTree(struct bNodeTreeExec *exec)
struct bNodeTreeExec * ntreeTexBeginExecTree(struct bNodeTree *ntree)
a MemoryBuffer contains access to the data
void add_output_socket(DataType datatype)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
virtual void determine_canvas(const rcti &preferred_area, rcti &r_area)
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
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
local_group_size(16, 16) .push_constant(Type texture
@ Vector
Vector data type.
constexpr int COM_DATA_TYPE_VALUE_CHANNELS
Definition COM_defines.h:55
constexpr rcti COM_AREA_NONE
Definition COM_defines.h:89
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< float, 3 > float3
float tin
Definition RE_texture.h:87
float trgba[4]
Definition RE_texture.h:88
char use_nodes
struct bNodeTree * nodetree
bNodeTreeRuntimeHandle * runtime
int ymin
int ymax
int xmin
int xmax
int multitex_ext(Tex *tex, const float texvec[3], float dxt[3], float dyt[3], int osatex, TexResult *texres, const short thread, ImagePool *pool, bool scene_color_manage, const bool skip_load_image)