38 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
39 .compositor_domain_priority(0);
102 if (input.is_single_value() || node_storage(
bnode()).maxblur < 1.0f) {
103 input.pass_through(output);
113 const bool is_circle = node_storage(
bnode()).bktype == 0;
114 const int2 kernel_size =
int2(maximum_defocus_radius * 2 + 1);
115 const int sides = is_circle ? 3 : node_storage(
bnode()).bktype;
116 const float rotation = node_storage(
bnode()).rotation;
117 const float roundness = is_circle ? 1.0f : 0.0f;
119 context(), kernel_size, sides, rotation, roundness, 0.0f, 0.0f);
127 input.bind_as_texture(shader,
"input_tx");
129 radius.bind_as_texture(shader,
"radius_tx");
135 output.allocate_texture(domain);
136 output.bind_as_image(shader,
"output_img");
141 input.unbind_as_texture();
142 radius.unbind_as_texture();
144 output.unbind_as_image();
151 if (node_storage(
bnode()).no_zbuf) {
181 return output_radius;
219 return eroded_radius;
225 if (node_storage(
bnode()).no_zbuf) {
226 return node_storage(
bnode()).maxblur;
231 const float radius = (maximum_diameter / 2.0f) * pixels_per_meter;
249 return math::abs((distance_to_image_of_focus / (f_stop * focal_length)) -
250 (focal_length / f_stop));
262 return (focal_length * focus_distance) / (focus_distance - focal_length);
270 return camera ?
math::max(1e-6f, camera->lens / 1000.0f) : 50.0f / 1000.0f;
278 if (!camera_object) {
293 return default_value;
296 switch (camera->sensor_fit) {
298 return size.x / (camera->sensor_x / 1000.0f);
300 return size.y / (camera->sensor_y / 1000.0f);
302 return size.x > size.y ? size.x / (camera->sensor_x / 1000.0f) :
303 size.y / (camera->sensor_y / 1000.0f);
309 return default_value;
325 return reinterpret_cast<Camera *
>(camera_object->
data);
353 ntype.
declare = file_ns::cmp_node_defocus_declare;
354 ntype.
draw_buttons = file_ns::node_composit_buts_defocus;
355 ntype.
initfunc = file_ns::node_composit_init_defocus;
Camera data-block and utility functions.
float BKE_camera_object_dof_distance(const struct Object *ob)
#define NODE_STORAGE_FUNCS(StorageT)
#define NODE_CLASS_OP_FILTER
#define DEFAULT_SENSOR_WIDTH
Object is a sort of wrapper for general info.
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value)
void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value)
void GPU_shader_bind(GPUShader *shader)
void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value)
void GPU_texture_filter_mode(GPUTexture *texture, bool use_filter)
void uiLayoutSetActive(uiLayout *layout, bool active)
void uiItemL(uiLayout *layout, const char *name, int icon)
void uiTemplateID(uiLayout *layout, const bContext *C, PointerRNA *ptr, const char *propname, const char *newop, const char *openop, const char *unlinkop, int filter=UI_TEMPLATE_ID_FILTER_ALL, bool live_icon=false, const char *text=nullptr)
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
struct GPUShader GPUShader
int compositor_domain_priority() const
float compute_maximum_defocus_radius()
float compute_distance_to_image_of_focus()
const Scene * get_scene()
float compute_focus_distance()
float compute_pixels_per_meter()
float compute_maximum_diameter_of_circle_of_confusion()
const Camera * get_camera()
const Object * get_camera_object()
Result compute_defocus_radius()
Result compute_defocus_radius_from_depth()
Result compute_defocus_radius_from_scale()
Result & get(Context &context, int2 size, int sides, float rotation, float roundness, float catadioptric, float lens_shift)
StaticCacheManager & cache_manager()
virtual const Scene & get_scene() const =0
GPUShader * get_shader(const char *info_name, ResultPrecision precision)
Result create_result(ResultType type, ResultPrecision precision)
NodeOperation(Context &context, DNode node)
const bNode & bnode() const
Result & get_input(StringRef identifier) const
Result & get_result(StringRef identifier)
Context & context() const
virtual Domain compute_domain()
void bind_as_image(GPUShader *shader, const char *image_name, bool read=false) const
void unbind_as_texture() const
const Domain & domain() const
void unbind_as_image() const
void allocate_texture(Domain domain, bool from_pool=true)
void bind_as_texture(GPUShader *shader, const char *texture_name) const
BokehKernelContainer bokeh_kernels
local_group_size(16, 16) .push_constant(Type b
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
void node_register_type(bNodeType *ntype)
T min(const T &a, const T &b)
T max(const T &a, const T &b)
static void node_composit_buts_defocus(uiLayout *layout, bContext *C, PointerRNA *ptr)
static void cmp_node_defocus_declare(NodeDeclarationBuilder &b)
static void node_composit_init_defocus(bNodeTree *, bNode *node)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
void morphological_blur(Context &context, Result &input, Result &output, float2 radius, MorphologicalBlurOperation operation=MorphologicalBlurOperation::Erode, int filter_type=R_FILTER_GAUSS)
void compute_dispatch_threads_at_least(GPUShader *shader, int2 threads_range, int2 local_size=int2(16))
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void register_node_type_cmp_defocus()
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void node_free_standard_storage(bNode *node)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
NodeGetCompositorOperationFunction get_compositor_operation
void(* initfunc)(bNodeTree *ntree, bNode *node)
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
NodeDeclareFunction declare