25 b.use_custom_socket_order();
26 b.allow_any_socket_order();
29 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
32 b.add_output<
decl::Color>(
"Image").structure_type(StructureType::Dynamic).align_with_previous();
35 "The number of samples used to compute the blur. The more samples the smoother the "
36 "result, but at the expense of more compute time. The actual number of samples is two "
37 "to the power of this input, so it increases exponentially");
41 .default_value({0.5f, 0.5f})
45 "The position at which the transformations pivot around. Defined in normalized "
46 "coordinates, so 0 means lower left corner and 1 means upper right corner of the image");
51 .description(
"The amount of rotation that the blur spans");
53 "The amount of scaling that the blur spans");
62 "The amount of translation that the blur spans in the specified direction relative to "
63 "the size of the image. Negative values indicate translation in the opposite direction");
67 .description(
"The angle that defines the direction of the translation");
85 if (this->
context().use_gpu()) {
141 output.allocate_texture(domain);
147 float current_sin = 0.0f;
148 float current_cos = 1.0f;
149 float current_scale = 1.0f;
155 for (
int i = 0;
i < iterations;
i++) {
159 float2 transformed_coordinates = coordinates;
160 transformed_coordinates -= origin;
161 transformed_coordinates /= current_scale;
162 transformed_coordinates -= current_translation;
163 transformed_coordinates = transformed_coordinates *
165 float2(-current_sin, current_cos));
166 transformed_coordinates += origin;
168 accumulated_color +=
input.sample_bilinear_zero(transformed_coordinates /
float2(
size));
170 current_scale += delta_scale;
171 current_translation += delta_translation;
175 float new_sin = current_sin * delta_rotation_cos + current_cos * delta_rotation_sin;
176 current_cos = current_cos * delta_rotation_cos - current_sin * delta_rotation_sin;
177 current_sin = new_sin;
180 output.store_pixel(texel, accumulated_color / iterations);
194 const float2 translation = rotation *
222 const int iterations = 2 << (this->
get_samples() - 1);
224 return math::min(iterations, upper_limit);
264 this->
get_input(
"Translation Amount").get_single_value_default(0.0f), -1.0f, 1.0f);
297 ntype.
ui_name =
"Directional Blur";
301 ntype.
declare = file_ns::cmp_node_directional_blur_declare;
#define NODE_CLASS_OP_FILTER
void GPU_shader_uniform_1f(blender::gpu::Shader *sh, const char *name, float value)
void GPU_shader_bind(blender::gpu::Shader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_shader_uniform_1i(blender::gpu::Shader *sh, const char *name, int value)
void GPU_shader_uniform_2fv(blender::gpu::Shader *sh, const char *name, const float data[2])
void GPU_texture_extend_mode(blender::gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
@ GPU_SAMPLER_EXTEND_MODE_CLAMP_TO_BORDER
void GPU_texture_filter_mode(blender::gpu::Texture *texture, bool use_filter)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
gpu::Shader * get_shader(const char *info_name, ResultPrecision precision)
NodeOperation(Context &context, DNode node)
Result & get_result(StringRef identifier)
Context & context() const
Result & get_input(StringRef identifier) const
virtual Domain compute_domain()
void share_data(const Result &source)
T get_single_value_default(const T &default_value) const
void allocate_texture(const Domain domain, const bool from_pool=true, const std::optional< ResultStorageType > storage_type=std::nullopt)
void unbind_as_texture() const
void bind_as_texture(gpu::Shader *shader, const char *texture_name) const
void unbind_as_image() const
void bind_as_image(gpu::Shader *shader, const char *image_name, bool read=false) const
bool is_single_value() const
DeclType::Builder & add_input(StringRef name, StringRef identifier="")
StructureType structure_type
float get_translation_direction()
float get_delta_rotation()
float get_translation_amount()
float2 get_delta_translation()
NodeOperation(Context &context, DNode node)
void node_register_type(bNodeType &ntype)
void compute_dispatch_threads_at_least(gpu::Shader *shader, int2 threads_range, int2 local_size=int2(16))
void parallel_for(const int2 range, const Function &function)
AngleRadianBase< float > AngleRadian
T cos(const AngleRadianBase< T > &a)
T clamp(const T &a, const T &min, const T &max)
T length(const VecBase< T, Size > &a)
T min(const T &a, const T &b)
T sin(const AngleRadianBase< T > &a)
T max(const T &a, const T &b)
MatT from_rotation(const RotationT &rotation)
static void cmp_node_directional_blur_declare(NodeDeclarationBuilder &b)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
MatBase< float, 2, 2 > float2x2
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
static void register_node_type_cmp_dblur()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
std::string ui_description
NodeGetCompositorOperationFunction get_compositor_operation
const char * enum_name_legacy
NodeDeclareFunction declare