32 mask_func = [](
const bool is_inside,
const float *
mask,
const float *value) {
33 return is_inside ? std::max(mask[0], value[0]) : mask[0];
37 mask_func = [](
const bool is_inside,
const float *
mask,
const float *value) {
38 return is_inside ? std::clamp(mask[0] - value[0], 0.0f, 1.0f) : mask[0];
42 mask_func = [](
const bool is_inside,
const float *
mask,
const float *value) {
43 return is_inside ? mask[0] * value[0] : 0;
47 mask_func = [](
const bool is_inside,
const float *
mask,
const float *value) {
49 return mask[0] > 0.0f ? 0.0f : value[0];
55 apply_mask(output, area, inputs, mask_func);
58void EllipseMaskOperation::apply_mask(
MemoryBuffer *output,
65 const float op_last_x = std::max(this->
get_width() - 1.0f, FLT_EPSILON);
66 const float op_last_y = std::max(this->
get_height() - 1.0f, FLT_EPSILON);
67 const float half_w = data_->
width / 2.0f;
68 const float half_h = data_->
height / 2.0f;
69 const float tx = half_w * half_w;
70 const float ty = half_h * half_h;
71 for (
int y = area.ymin; y < area.ymax; y++) {
72 const float op_ry = y / op_last_y;
73 const float dy = (op_ry - data_->
y) / aspect_ratio_;
74 float *out = output->get_elem(area.xmin, y);
75 const float *mask = input_mask->
get_elem(area.xmin, y);
76 const float *value = input_value->
get_elem(area.xmin, y);
77 for (
int x = area.xmin; x < area.xmax; x++) {
78 const float op_rx = x / op_last_x;
79 const float dx = op_rx - data_->
x;
80 const float rx = data_->
x + (cosine_ * dx + sine_ * dy);
81 const float ry = data_->
y + (-sine_ * dx + cosine_ * dy);
82 float sx = rx - data_->
x;
84 float sy = ry - data_->
y;
86 const bool inside = ((sx / tx) + (sy / ty)) <= (1.0f + FLT_EPSILON);
87 out[0] = mask_func(inside, mask, value);
91 out += output->elem_stride;
typedef double(DMatrix)[4][4]
@ CMP_NODE_MASKTYPE_SUBTRACT
@ CMP_NODE_MASKTYPE_MULTIPLY
void init_execution() override
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
a MemoryBuffer contains access to the data
float * get_elem(int x, int y)
unsigned int get_height() const
void add_output_socket(DataType datatype)
unsigned int get_width() const
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
draw_view in_light_buf[] float
static bool is_inside(int x, int y, int cols, int rows)
ccl_device_inline float3 cos(float3 v)
ccl_device_inline float4 mask(const int4 mask, const float4 a)