Compositor: Unify Variable Size Bokeh Blur node #117947

Merged
Omar Emara merged 4 commits from OmarEmaraDev/blender:unify-variable-size-bokeh into main 2024-02-09 11:52:50 +01:00
Member

This patch adjusts the Variable Size Bokeh Blur node such that it
matches between CPU and GPU. The GPU implementation is mostly followed
for the reasons stated below.

The first difference is a bug in the CPU implementation, where the upper
limit of the blur window is not considered, but the lower limit is.

The second difference is due to CPU ignoring outside pixels instead of
clamping them to border, which is done until an option is added to the
node to control the boundary condition.

The third difference is due to CPU ignoring the bounding box input.

The fourth difference is that CPU doesn't allow zero maximum blur
radius, which is a valid option.

The fifth difference is that the threshold option, which is only used
for the Defocus node, was considered in a greater than manner, while it
should be greater than or equal. Since the default threshold of one
should allow a blur size of one.

The GPU implementation now considers the maximum size of its input,
following the CPU implementation.

This patch adjusts the Variable Size Bokeh Blur node such that it matches between CPU and GPU. The GPU implementation is mostly followed for the reasons stated below. The first difference is a bug in the CPU implementation, where the upper limit of the blur window is not considered, but the lower limit is. The second difference is due to CPU ignoring outside pixels instead of clamping them to border, which is done until an option is added to the node to control the boundary condition. The third difference is due to CPU ignoring the bounding box input. The fourth difference is that CPU doesn't allow zero maximum blur radius, which is a valid option. The fifth difference is that the threshold option, which is only used for the Defocus node, was considered in a greater than manner, while it should be greater than or equal. Since the default threshold of one should allow a blur size of one. The GPU implementation now considers the maximum size of its input, following the CPU implementation.
Omar Emara added the
Interest
Compositing
Module
VFX & Video
labels 2024-02-07 16:47:59 +01:00
Omar Emara added 1 commit 2024-02-07 16:48:08 +01:00
f77f5e232f Compositor: Unify Variable Size Bokeh Blur node
This patch adjusts the Variable Size Bokeh Blur node such that it
matches between CPU and GPU. The GPU implementation is mostly followed
for the reasons stated below.

The first difference is a bug in the CPU implementation, where the upper
limit of the blur window is not considered, but the lower limit is.

The second difference is due to CPU ignoring outside pixels instead of
clamping them to border, which is done until an option is added to the
node to control the boundary condition.

The third difference is due to CPU ignoring the bounding box input.

The fourth difference is that CPU doesn't allow zero maximum blur
radius, which is a valid option.

The fifth difference is that the threshold option, which is only used
for the Defocus node, was considered in a greater than manner, while it
should be greater than or equal. Since the default threshold of one
should allow a blur size of one.

The GPU implementation now considers the maximum size of its input,
following the CPU implementation.
Omar Emara requested review from Sergey Sharybin 2024-02-07 16:49:02 +01:00
Author
Member

@Sergey This is still WIP, because the bounding box input doesn't work for the tiled compositor yet. I spent too much time investigating it and yet to figure it out, but the rest of the patch should be ready.

@Sergey This is still WIP, because the bounding box input doesn't work for the tiled compositor yet. I spent too much time investigating it and yet to figure it out, but the rest of the patch should be ready.

@OmarEmaraDev Unfortunately, it does not compile here:

blender/source/blender/blenlib/BLI_math_base.hh:86:13: error: use of overloaded operator '!=' is ambiguous (with operand types 'const blender::VecBase<float, 4>' and 'int')

I guess you'd expect a per-component safe_divide. Not sure if we have utility for it already.

As for the tiled compositor, if this fix is is not essential for 4.1, we can delay it for after the Tiled compositor is removed.

@OmarEmaraDev Unfortunately, it does not compile here: ``` blender/source/blender/blenlib/BLI_math_base.hh:86:13: error: use of overloaded operator '!=' is ambiguous (with operand types 'const blender::VecBase<float, 4>' and 'int') ``` I guess you'd expect a per-component `safe_divide`. Not sure if we have utility for it already. As for the tiled compositor, if this fix is is not essential for 4.1, we can delay it for after the Tiled compositor is removed.
Omar Emara added 1 commit 2024-02-07 17:11:46 +01:00
Author
Member

@Sergey Where is that error is coming from exactly? Because we do have component-wise safe division, as far as I can see. I added missing includes, maybe that fixes it.

It is indeed not essential, so delaying it will be great.

@Sergey Where is that error is coming from exactly? Because we do have component-wise safe division, as far as I can see. I added missing includes, maybe that fixes it. It is indeed not essential, so delaying it will be great.

@OmarEmaraDev The include seems have fixed the issue, thanks!

@OmarEmaraDev The include seems have fixed the issue, thanks!
Omar Emara changed title from WIP: Compositor: Unify Variable Size Bokeh Blur node to Compositor: Unify Variable Size Bokeh Blur node 2024-02-08 11:09:22 +01:00

In the current patch the VariableSizeBokehBlurOperation::determine_depending_area_of_interest needs adjustment for the COM_DEFOCUS_SEARCH code path of it: the defocus input node index changed from 3 to 4, and determine_depending_area_of_interest does not use the mnemonic and use hard-coded values instead.

It also seems that the determine_depending_area_of_interest is what causes the uninitialized values of the mask input in the execute_pixel . Can't say i fully understand the logic there, but it feels a bit weird to mix AoI of bokeh image with the actual image. Not sure if this is more correct, but this seems to be more clear, and solves the issue:

bool VariableSizeBokehBlurOperation::determine_depending_area_of_interest(
    rcti *input, ReadBufferOperation *read_operation, rcti *output)
{
  if (read_operation == (ReadBufferOperation *)get_input_operation(BOKEH_INPUT_INDEX)) {
    rcti bokeh_input;
    bokeh_input.xmax = COM_BLUR_BOKEH_PIXELS;
    bokeh_input.xmin = 0;
    bokeh_input.ymax = COM_BLUR_BOKEH_PIXELS;
    bokeh_input.ymin = 0;

    NodeOperation *operation = get_input_operation(BOKEH_INPUT_INDEX);
    return operation->determine_depending_area_of_interest(&bokeh_input, read_operation, output);
  }

  const float max_dim = std::max(get_width(), get_height());
  const float scalar = do_size_scale_ ? (max_dim / 100.0f) : 1.0f;
  int max_blur_scalar = max_blur_ * scalar;

  rcti new_input;
  new_input.xmax = input->xmax + max_blur_scalar + 2;
  new_input.xmin = input->xmin - max_blur_scalar + 2;
  new_input.ymax = input->ymax + max_blur_scalar - 2;
  new_input.ymin = input->ymin - max_blur_scalar - 2;

  NodeOperation *operation = get_input_operation(SIZE_INPUT_INDEX);
  if (operation->determine_depending_area_of_interest(&new_input, read_operation, output)) {
    return true;
  }
#ifdef COM_DEFOCUS_SEARCH
  rcti search_input;
  search_input.xmax = (input->xmax / InverseSearchRadiusOperation::DIVIDER) + 1;
  search_input.xmin = (input->xmin / InverseSearchRadiusOperation::DIVIDER) - 1;
  search_input.ymax = (input->ymax / InverseSearchRadiusOperation::DIVIDER) + 1;
  search_input.ymin = (input->ymin / InverseSearchRadiusOperation::DIVIDER) - 1;
  operation = get_input_operation(DEFOCUS_INPUT_INDEX);
  if (operation->determine_depending_area_of_interest(&search_input, read_operation, output)) {
    return true;
  }
#endif
  operation = get_input_operation(IMAGE_INPUT_INDEX);
  if (operation->determine_depending_area_of_interest(&new_input, read_operation, output)) {
    return true;
  }

  operation = get_input_operation(BOUNDING_BOX_INPUT_INDEX);
  if (operation->determine_depending_area_of_interest(&new_input, read_operation, output)) {
    return true;
  }

  return false;
}

What i still don't understand is why the operation = get_input_operation(BOUNDING_BOX_INPUT_INDEX); block is needed in cases where the Image input in plugged to an image. One would expect it to define the AoT and return true. Maybe you can have a second pair of quick looking eyes. Maybe it is correct/acceptable. But we should not spend too much time on it now.

If we can't make sense of this determine_depending_area_of_interest, then just ignore the tiled compositor as the Bounds input was never supported there, do the index tweaks in the determine_depending_area_of_interest, and move on with the patch.

In the current patch the `VariableSizeBokehBlurOperation::determine_depending_area_of_interest` needs adjustment for the `COM_DEFOCUS_SEARCH` code path of it: the defocus input node index changed from 3 to 4, and `determine_depending_area_of_interest` does not use the mnemonic and use hard-coded values instead. It also seems that the `determine_depending_area_of_interest` is what causes the uninitialized values of the mask input in the `execute_pixel `. Can't say i fully understand the logic there, but it feels a bit weird to mix AoI of bokeh image with the actual image. Not sure if this is more correct, but this seems to be more clear, and solves the issue: ``` bool VariableSizeBokehBlurOperation::determine_depending_area_of_interest( rcti *input, ReadBufferOperation *read_operation, rcti *output) { if (read_operation == (ReadBufferOperation *)get_input_operation(BOKEH_INPUT_INDEX)) { rcti bokeh_input; bokeh_input.xmax = COM_BLUR_BOKEH_PIXELS; bokeh_input.xmin = 0; bokeh_input.ymax = COM_BLUR_BOKEH_PIXELS; bokeh_input.ymin = 0; NodeOperation *operation = get_input_operation(BOKEH_INPUT_INDEX); return operation->determine_depending_area_of_interest(&bokeh_input, read_operation, output); } const float max_dim = std::max(get_width(), get_height()); const float scalar = do_size_scale_ ? (max_dim / 100.0f) : 1.0f; int max_blur_scalar = max_blur_ * scalar; rcti new_input; new_input.xmax = input->xmax + max_blur_scalar + 2; new_input.xmin = input->xmin - max_blur_scalar + 2; new_input.ymax = input->ymax + max_blur_scalar - 2; new_input.ymin = input->ymin - max_blur_scalar - 2; NodeOperation *operation = get_input_operation(SIZE_INPUT_INDEX); if (operation->determine_depending_area_of_interest(&new_input, read_operation, output)) { return true; } #ifdef COM_DEFOCUS_SEARCH rcti search_input; search_input.xmax = (input->xmax / InverseSearchRadiusOperation::DIVIDER) + 1; search_input.xmin = (input->xmin / InverseSearchRadiusOperation::DIVIDER) - 1; search_input.ymax = (input->ymax / InverseSearchRadiusOperation::DIVIDER) + 1; search_input.ymin = (input->ymin / InverseSearchRadiusOperation::DIVIDER) - 1; operation = get_input_operation(DEFOCUS_INPUT_INDEX); if (operation->determine_depending_area_of_interest(&search_input, read_operation, output)) { return true; } #endif operation = get_input_operation(IMAGE_INPUT_INDEX); if (operation->determine_depending_area_of_interest(&new_input, read_operation, output)) { return true; } operation = get_input_operation(BOUNDING_BOX_INPUT_INDEX); if (operation->determine_depending_area_of_interest(&new_input, read_operation, output)) { return true; } return false; } ``` What i still don't understand is why the `operation = get_input_operation(BOUNDING_BOX_INPUT_INDEX);` block is needed in cases where the `Image` input in plugged to an image. One would expect it to define the AoT and return true. Maybe you can have a second pair of quick looking eyes. Maybe it is correct/acceptable. But we should not spend too much time on it now. If we can't make sense of this `determine_depending_area_of_interest`, then just ignore the tiled compositor as the Bounds input was never supported there, do the index tweaks in the `determine_depending_area_of_interest`, and move on with the patch.
Omar Emara added 1 commit 2024-02-08 12:29:43 +01:00
Author
Member

@Sergey I am not sure why the image input doesn't define the area of interest to be honest.
Anyway, I am a fool for only updating get_area_of_interest but not determine_depending_area_of_interest. I updated the code now.

The code now allows sizes other than COM_BLUR_BOKEH_PIXELS, so we can remove it as well, but maybe in a separate patch.

@Sergey I am not sure why the image input doesn't define the area of interest to be honest. Anyway, I am a fool for only updating `get_area_of_interest` but not `determine_depending_area_of_interest`. I updated the code now. The code now allows sizes other than `COM_BLUR_BOKEH_PIXELS`, so we can remove it as well, but maybe in a separate patch.

@OmarEmaraDev Thanks for the update. On the quality of the result side it seems to be very well aligned, at least on simple setups.

In a bit more complicated setup something unexpected happens. With the attached file the Tiled compositor takes almost no time, GPU takes a long time, and Full-Frame I hasn't been able to wait for the comp to finish.

Is the Tiled compositor missing something that makes it fast, or something suboptimal happens in GPU/full-frame?

@OmarEmaraDev Thanks for the update. On the quality of the result side it seems to be very well aligned, at least on simple setups. In a bit more complicated setup something unexpected happens. With the attached file the Tiled compositor takes almost no time, GPU takes a long time, and Full-Frame I hasn't been able to wait for the comp to finish. Is the Tiled compositor missing something that makes it fast, or something suboptimal happens in GPU/full-frame?
Sergey Sharybin reviewed 2024-02-08 17:29:30 +01:00
@ -395,0 +289,4 @@
const float max_dim = std::max(get_width(), get_height());
const float base_size = do_size_scale_ ? (max_dim / 100.0f) : 1.0f;
const float maximum_size = size_buffer->get_max_value();
const int search_radius = math::clamp(0, int(maximum_size * base_size), max_blur_);

const int search_radius = math::clamp(int(maximum_size * base_size), 0, max_blur_);

`const int search_radius = math::clamp(int(maximum_size * base_size), 0, max_blur_);`
@ -153,0 +159,4 @@
const float maximum_size = maximum_float(context(), input_size.texture());
const float base_size = compute_blur_radius();
return math::clamp(0, int(maximum_size * base_size), get_max_size());

return math::clamp(int(maximum_size * base_size), 0, get_max_size());

`return math::clamp(int(maximum_size * base_size), 0, get_max_size());`
Omar Emara added 1 commit 2024-02-08 18:41:38 +01:00
Sergey Sharybin approved these changes 2024-02-09 10:07:44 +01:00
Omar Emara merged commit 9743d6992c into main 2024-02-09 11:52:50 +01:00
Omar Emara deleted branch unify-variable-size-bokeh 2024-02-09 11:52:52 +01:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#117947
No description provided.