19 b.use_custom_socket_order();
20 b.allow_any_socket_order();
22 .default_value({0.8f, 0.8f, 0.8f, 1.0f})
25 b.add_output<
decl::Color>(
"Image").structure_type(StructureType::Dynamic).align_with_previous();
28 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
32 StructureType::Dynamic);
34 StructureType::Dynamic);
35 b.add_input<
decl::Bool>(
"Extend Bounds").default_value(
false);
89 if (
size.is_single_value()) {
99 if (this->
context().use_gpu()) {
131 input.unbind_as_texture();
151 float mask = mask_image.load_pixel<float, true>(texel);
153 output.store_pixel(texel, input.load_pixel<float4>(texel));
161 for (
int y = -radius;
y <= radius;
y++) {
162 for (
int x = -radius;
x <= radius;
x++) {
164 accumulated_color +=
input.load_pixel_extended<
float4>(texel +
int2(
x,
y)) * weight;
165 accumulated_weight += weight;
172 blur_kernel.release();
177 if (this->
context().use_gpu()) {
189 gpu::Shader *shader = this->
context().get_shader(
"compositor_bokeh_blur_variable_size");
194 input.bind_as_texture(shader,
"input_tx");
199 size.bind_as_texture(shader,
"size_tx");
213 input.unbind_as_texture();
215 size.unbind_as_texture();
228 output.allocate_texture(domain);
242 auto load_weight = [&](
const int2 &texel,
const float radius) {
246 if (texel.x == 0 && texel.y == 0) {
256 1.0f - ((
float2(texel) +
float2(radius + 0.5f)) / (radius * 2.0f + 1.0f)));
262 float mask = mask_image.load_pixel<float, true>(texel);
264 output.store_pixel(texel, input.load_pixel<float4>(texel));
276 for (
int y = -search_radius;
y <= search_radius;
y++) {
277 for (
int x = -search_radius;
x <= search_radius;
x++) {
290 accumulated_color +=
input.load_pixel_extended<
float4>(texel +
int2(
x,
y)) * weight;
291 accumulated_weight += weight;
314 const int2 kernel_size =
int2(radius * 2 + 1);
321 const float2 weight_coordinates = 1.0f - ((
float2(texel) + 0.5f) /
float2(kernel_size));
322 float4 weight =
bokeh.sample_bilinear_extended(weight_coordinates);
361 return this->
get_input(
"Extend Bounds").get_single_value_default(
false);
381 "Generate a bokeh type blur similar to Defocus. Unlike defocus an in-focus region is "
382 "defined in the compositor";
385 ntype.
declare = file_ns::cmp_node_bokehblur_declare;
constexpr int NODE_DEFAULT_MAX_WIDTH
#define NODE_CLASS_OP_FILTER
#define CMP_NODE_BOKEHBLUR
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)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
int pad[32 - sizeof(int)]
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Result create_result(ResultType type, ResultPrecision precision)
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
void share_data(const Result &source)
void store_pixel(const int2 &texel, const T &pixel_value)
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
T load_pixel_extended(const int2 &texel) const
T load_pixel(const int2 &texel) const
void unbind_as_image() const
float4 sample_bilinear_extended(const float2 &coordinates) const
void bind_as_image(gpu::Shader *shader, const char *image_name, bool read=false) const
bool is_single_value() const
StructureType structure_type
int compute_extended_boundary_size(const Result &size)
Result compute_blur_kernel(const int radius)
void execute_variable_size_gpu(const Result &input, const Result &size)
void execute_variable_size(const Result &input, const Result &size)
void execute_variable_size_cpu(const Result &input, const Result &size_input)
int compute_variable_size_search_radius()
void execute_blur(const Result &input, const Result &size)
void execute_constant_size_cpu(const Result &input)
NodeOperation(Context &context, DNode node)
void execute_constant_size_gpu(const Result &input)
void execute_constant_size(const Result &input)
VecBase< float, 2 > float2
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
void node_type_size(bNodeType &ntype, int width, int minwidth, int maxwidth)
void node_register_type(bNodeType &ntype)
void compute_dispatch_threads_at_least(gpu::Shader *shader, int2 threads_range, int2 local_size=int2(16))
static float bokeh(const float2 point, const float circumradius, const float exterior_angle, const float rotation, const float roundness, const float catadioptric)
float maximum_float(Context &context, const Result &result)
void parallel_for(const int2 range, const Function &function)
T safe_divide(const T &a, const T &b)
T min(const T &a, const T &b)
T max(const T &a, const T &b)
static void cmp_node_bokehblur_declare(NodeDeclarationBuilder &b)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
static void register_node_type_cmp_bokehblur()
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
static pxr::UsdShadeInput get_input(const pxr::UsdShadeShader &usd_shader, const pxr::TfToken &input_name)